Fix forge mixin loading class prematurely

This commit is contained in:
tom lee
2022-02-12 23:45:08 +08:00
parent 66f169bd78
commit b8aabc59cd
4 changed files with 31 additions and 6 deletions
@@ -9,18 +9,27 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.seibel.lod.common.wrappers.DependencySetupDoneCheck;
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.lod.core.util.SingletonHandler;
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
import net.minecraft.Util;
@Mixin(Util.class)
public class MixinUtilBackgroudThread
{
private static boolean doTriggerOverride() {
try {
return DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get();
} catch (NullPointerException e) {
return false;
}
}
@Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/lang/Runnable;)Ljava/lang/Runnable;",
at = @At("HEAD"), cancellable = true)
private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable<Runnable> ci)
{
if (DependencySetupDoneCheck.isDone && BatchGenerationEnvironment.isCurrentThreadDistantGeneratorThread())
if (DependencySetupDoneCheck.isDone && doTriggerOverride())
{
// ClientApi.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered");
ci.setReturnValue(r);
@@ -30,7 +39,7 @@ public class MixinUtilBackgroudThread
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<Executor> ci)
{
if (DependencySetupDoneCheck.isDone && BatchGenerationEnvironment.isCurrentThreadDistantGeneratorThread())
if (DependencySetupDoneCheck.isDone && doTriggerOverride())
{
// ClientApi.LOGGER.info("util backgroundExecutor triggered");
ci.setReturnValue(Runnable::run);