diff --git a/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java b/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java index caf0fa1a7..a21d86d74 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java +++ b/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.lib.task; import com.jozufozu.flywheel.api.task.Plan; import com.jozufozu.flywheel.api.task.TaskExecutor; +import com.mojang.blaze3d.systems.RenderSystem; public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan { public static Plan of(Runnable task) { @@ -10,7 +11,12 @@ public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan { @Override public void execute(TaskExecutor taskExecutor, Runnable onCompletion) { - // TODO: detect if we're already on the render thread and just run the task directly + if (RenderSystem.isOnRenderThread()) { + task.run(); + onCompletion.run(); + return; + } + taskExecutor.scheduleForMainThread(() -> { task.run(); onCompletion.run();