replace and simplify WorldGenThreadCheck

This commit is contained in:
James Seibel
2025-11-22 09:25:55 -06:00
parent af8dea9d9f
commit 91da0bf252
15 changed files with 118 additions and 153 deletions
@@ -30,8 +30,7 @@ import java.util.function.Supplier;
#if MC_VER < MC_1_20_6
import net.neoforged.neoforge.event.TickEvent;
#else
import net.neoforged.neoforge.event.tick.ServerTickEvent;
#else
#endif
@@ -52,7 +51,7 @@ public class NeoforgeServerProxy implements AbstractModInitializer.IEventProxy
public NeoforgeServerProxy(boolean isDedicated)
{
this.isDedicated = isDedicated;
isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread;
isGenerationThreadChecker = BatchGenerationEnvironment::isThisDhWorldGenThread;
}
@Override
@@ -13,7 +13,7 @@ public class MixinLevelTicks<T>
#else
import com.seibel.distanthorizons.common.wrappers.WorldGenThreadCheck;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import net.minecraft.world.ticks.LevelTicks;
import net.minecraft.world.ticks.ScheduledTick;
import org.spongepowered.asm.mixin.Mixin;
@@ -24,18 +24,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(LevelTicks.class) // available in 1.18.2+, but only needed in 1.21.4+
public class MixinLevelTicks<T>
{
// TODO put in a common location
private static boolean isWorldGenThread()
{ return WorldGenThreadCheck.isSetup && WorldGenThreadCheck.isCurrentThreadDhWorldGenThread.get(); }
@Inject(method = "schedule", at = @At(value = "HEAD"), cancellable = true)
private void onChunkSave(ScheduledTick<T> tick, CallbackInfo ci)
{
// In MC 1.21.4 an error check was added to log attempting to schedule ticks for unloaded chunks
// this caused a lot of unnecessary errors when generating sand (FallingBlock.class).
if (isWorldGenThread())
if (BatchGenerationEnvironment.isThisDhWorldGenThread())
{
ci.cancel();
}
@@ -35,7 +35,7 @@ public class MixinTracingExecutor
}
#else
import com.seibel.distanthorizons.common.wrappers.WorldGenThreadCheck;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.distanthorizons.core.util.objects.RunOnThisThreadExecutorService;
import net.minecraft.TracingExecutor;
import org.spongepowered.asm.mixin.Mixin;
@@ -55,11 +55,6 @@ import java.util.concurrent.Executor;
@Mixin(TracingExecutor.class)
public class MixinTracingExecutor
{
// TODO put in a common location
private static boolean isWorldGenThread()
{ return WorldGenThreadCheck.isSetup && WorldGenThreadCheck.isCurrentThreadDhWorldGenThread.get(); }
// Util.backgroundExecutor().forName("init_biomes")
// needed for world gen
@@ -67,7 +62,7 @@ public class MixinTracingExecutor
@Inject(method = "forName(Ljava/lang/String;)Ljava/util/concurrent/Executor;", at = @At("HEAD"), cancellable = true)
private void forName(String executorName, CallbackInfoReturnable<Executor> ci)
{
if (isWorldGenThread())
if (BatchGenerationEnvironment.isThisDhWorldGenThread())
{
// run this task on the current DH thread instead of a new MC thread
ci.setReturnValue(new RunOnThisThreadExecutorService());
@@ -19,11 +19,10 @@
package com.seibel.distanthorizons.neoforge.mixins.server;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.distanthorizons.core.util.objects.RunOnThisThreadExecutorService;
import org.spongepowered.asm.mixin.Mixin;
import com.seibel.distanthorizons.common.wrappers.WorldGenThreadCheck;
import net.minecraft.Util;
/**
@@ -36,16 +35,13 @@ import net.minecraft.Util;
@Mixin(Util.class)
public class MixinUtilBackgroundThread
{
private static boolean isWorldGenThread()
{ return WorldGenThreadCheck.isSetup && WorldGenThreadCheck.isCurrentThreadDhWorldGenThread.get(); }
#if MC_VER < MC_1_21_3
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
{
if (isWorldGenThread())
if (BatchGenerationEnvironment.isThisDhWorldGenThread())
{
// run this task on the current DH thread instead of a new MC thread
ci.setReturnValue(new RunOnThisThreadExecutorService());
@@ -61,7 +57,7 @@ public class MixinUtilBackgroundThread
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable<Runnable> ci)
{
if (isWorldGenThread())
if (BatchGenerationEnvironment.isThisDhWorldGenThread())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered");
ci.setReturnValue(r);
@@ -77,7 +73,7 @@ public class MixinUtilBackgroundThread
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier<?> r, CallbackInfoReturnable<Supplier<?>> ci)
{
if (isWorldGenThread())
if (BatchGenerationEnvironment.isThisDhWorldGenThread())
{
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered");
ci.setReturnValue(r);