From e928fe3ecd2663377f8fa4ad7ff3f6517a4dfb20 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 25 Dec 2024 08:23:33 -0600 Subject: [PATCH] Fix not loaded tick schedule warning in world gen "Trying to schedule tick in not loaded position" can log in MC 1.21.4 when sand or other FallingBlock.class blocks attempt to generate in a DH context (IE the chunk isn't loaded in the server). --- .../fabric/mixins/server/MixinLevelTicks.java | 33 +++++++++++++++++++ .../DistantHorizons.fabric.mixins.json | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinLevelTicks.java diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinLevelTicks.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinLevelTicks.java new file mode 100644 index 000000000..87dbe7ad7 --- /dev/null +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinLevelTicks.java @@ -0,0 +1,33 @@ +package com.seibel.distanthorizons.fabric.mixins.server; + +import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck; + +import net.minecraft.world.ticks.LevelTicks; +import net.minecraft.world.ticks.ScheduledTick; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LevelTicks.class) +public class MixinLevelTicks +{ + // TODO put in a common location + private static boolean isWorldGenThread() + { return DependencySetupDoneCheck.isDone && DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread.get(); } + + + + @Inject(method = "schedule", at = @At(value = "HEAD"), cancellable = true) + private void onChunkSave(ScheduledTick 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()) + { + ci.cancel(); + } + } + +} diff --git a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json index 487bb1ee9..df08e5f99 100644 --- a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json +++ b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json @@ -8,7 +8,8 @@ "server.MixinEntity", "server.MixinServerPlayer", "server.MixinTracingExecutor", - "server.MixinUtilBackgroundThread" + "server.MixinUtilBackgroundThread", + "server.MixinLevelTicks" ], "client": [ "client.MixinClientLevel",