Reimplement runLater without relying on MC's renderTaskQueue

Cause it's gone in 1.21.9, and really not necessary to begin with since
we have our own executor already.
This commit is contained in:
Jonas Herzig
2025-10-12 15:34:48 +02:00
parent 4d644a44c3
commit f299644254
2 changed files with 8 additions and 13 deletions

View File

@@ -8,8 +8,6 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Queue;
//#if MC>=11800
//$$ import java.util.function.Supplier;
//#endif
@@ -25,6 +23,7 @@ import java.util.concurrent.CompletableFuture;
//#if MC<11400
//$$ import net.minecraft.client.resources.IResourcePack;
//$$ import java.util.List;
//$$ import java.util.Queue;
//#endif
@Mixin(MinecraftClient.class)
@@ -53,8 +52,6 @@ public interface MinecraftAccessor {
//#endif
//#if MC>=11400
@Accessor
Queue<Runnable> getRenderTaskQueue();
//#else
//$$ @Accessor
//$$ Queue<FutureTask<?>> getScheduledTasks();

View File

@@ -5,6 +5,8 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.thread.ReentrantThreadExecutor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -82,10 +84,13 @@ public class SchedulerImpl implements Scheduler {
}
}
public final ReplayModExecutor executor = new ReplayModExecutor("Client/ReplayMod");
private final List<Runnable> delayedTasks = new ArrayList<>();
@Override
public void runTasks() {
executor.runTasks();
delayedTasks.forEach(executor::send);
delayedTasks.clear();
}
@Override
@@ -100,15 +105,8 @@ public class SchedulerImpl implements Scheduler {
}
private void runLater(Runnable runnable, Runnable defer) {
if (mc.isOnThread() && inRunLater && !inRenderTaskQueue) {
((MinecraftAccessor) mc).getRenderTaskQueue().offer(() -> {
inRenderTaskQueue = true;
try {
defer.run();
} finally {
inRenderTaskQueue = false;
}
});
if (mc.isOnThread() && inRunLater) {
delayedTasks.add(defer);
} else {
executor.send(() -> {
inRunLater = true;