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
@@ -13,8 +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;
@@ -26,18 +25,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();
}
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.fabric.mixins.server;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import org.spongepowered.asm.mixin.Mixin;
#if MC_VER < MC_1_21_3
@@ -35,7 +36,6 @@ public class MixinTracingExecutor
}
#else
import com.seibel.distanthorizons.common.wrappers.WorldGenThreadCheck;
import com.seibel.distanthorizons.core.util.objects.RunOnThisThreadExecutorService;
import net.minecraft.TracingExecutor;
import org.spongepowered.asm.mixin.injection.At;
@@ -54,16 +54,11 @@ 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(); }
// replaced with TracingExecutor in MC 1.21.3+
@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,14 +19,19 @@
package com.seibel.distanthorizons.fabric.mixins.server;
import com.seibel.distanthorizons.common.wrappers.WorldGenThreadCheck;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.distanthorizons.core.util.objects.RunOnThisThreadExecutorService;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.Util;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
#if MC_VER < MC_1_16_5
#elif MC_VER < MC_1_21_3
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
#else
#endif
@@ -41,15 +46,11 @@ import java.util.function.Supplier;
@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());
@@ -65,7 +66,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);
@@ -81,7 +82,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);