From 63acd94fd4ca776e4b8dd2d56d285310902b7f9d Mon Sep 17 00:00:00 2001 From: Acuadragon100 <8165958-acuadragon100@users.noreply.gitlab.com> Date: Thu, 6 Nov 2025 15:19:20 +0100 Subject: [PATCH 1/3] Fix /dh command being deleted after reloading. --- .../common/AbstractModInitializer.java | 6 +-- .../common/commands/CommandInitializer.java | 37 ++++++++++++++----- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/AbstractModInitializer.java b/common/src/main/java/com/seibel/distanthorizons/common/AbstractModInitializer.java index f8eeb62c6..367fd5289 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/AbstractModInitializer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/AbstractModInitializer.java @@ -115,8 +115,8 @@ public abstract class AbstractModInitializer this.initializeModCompat(); LOGGER.info(ModInfo.READABLE_NAME + " server Initialized, adding event subscribers..."); - - this.subscribeRegisterCommandsEvent(dispatcher -> { this.commandInitializer = new CommandInitializer(dispatcher); }); + this.commandInitializer = new CommandInitializer(); + this.subscribeRegisterCommandsEvent(dispatcher -> { commandInitializer.initCommands(dispatcher); }); this.subscribeServerStartingEvent(server -> { @@ -124,7 +124,7 @@ public abstract class AbstractModInitializer this.initConfig(); this.postInit(); - this.commandInitializer.initCommands(); + this.commandInitializer.onServerReady(); this.checkForUpdates(); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java index 0cf47d98d..d38e7ebab 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java @@ -12,25 +12,42 @@ import static net.minecraft.commands.Commands.literal; */ public class CommandInitializer { - private final CommandDispatcher commandDispatcher; + private boolean serverReady = false; + + private CommandDispatcher commandDispatcher; /** * Constructs a new instance of this class. - * - * @param commandDispatcher The dispatcher to use for registering commands. */ - public CommandInitializer(CommandDispatcher commandDispatcher) - { - this.commandDispatcher = commandDispatcher; + public CommandInitializer() {} + + /** + * Notify the command initializer that the game is ready to accept commands. + * If {@link CommandInitializer#initCommands(CommandDispatcher)} has been fired before it was ready, it will also initialize the commands. + */ + public void onServerReady() { + serverReady = true; + if (commandDispatcher != null) + { + initCommands(commandDispatcher); + commandDispatcher = null; + } } - - /** * Initializes all available commands. + * If the game is not ready yet, it stores the dispatcher to initialize the commands later. + * + * @param commandDispatcher The command dispatcher to register commands to. */ - public void initCommands() + public void initCommands(CommandDispatcher commandDispatcher) { + if (!serverReady) + { + this.commandDispatcher = commandDispatcher; + return; + } + LiteralArgumentBuilder builder = literal("dh") .requires(source -> source.hasPermission(4)); @@ -43,7 +60,7 @@ public class CommandInitializer builder.then(new CrashCommand().buildCommand()); } - this.commandDispatcher.register(builder); + commandDispatcher.register(builder); } } From aec28854a3b30aa15be74fc003f8afbe96caa6b2 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Sat, 8 Nov 2025 16:10:15 +0500 Subject: [PATCH 2/3] Clean up code a bit --- .../common/commands/CommandInitializer.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java index d38e7ebab..23f9ccab4 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java @@ -3,6 +3,7 @@ package com.seibel.distanthorizons.common.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.commands.CommandSourceStack; +import org.jetbrains.annotations.Nullable; import static com.seibel.distanthorizons.core.network.messages.MessageRegistry.DEBUG_CODEC_CRASH_MESSAGE; import static net.minecraft.commands.Commands.literal; @@ -14,35 +15,35 @@ public class CommandInitializer { private boolean serverReady = false; - private CommandDispatcher commandDispatcher; - /** - * Constructs a new instance of this class. + * A received command dispatcher, which is held until the server is ready to initialize the commands. */ - public CommandInitializer() {} + @Nullable + private CommandDispatcher commandDispatcher; /** * Notify the command initializer that the game is ready to accept commands. * If {@link CommandInitializer#initCommands(CommandDispatcher)} has been fired before it was ready, it will also initialize the commands. */ - public void onServerReady() { - serverReady = true; - if (commandDispatcher != null) + public void onServerReady() + { + this.serverReady = true; + if (this.commandDispatcher != null) { - initCommands(commandDispatcher); - commandDispatcher = null; + this.initCommands(this.commandDispatcher); + this.commandDispatcher = null; } } /** * Initializes all available commands. * If the game is not ready yet, it stores the dispatcher to initialize the commands later. - * + * * @param commandDispatcher The command dispatcher to register commands to. */ public void initCommands(CommandDispatcher commandDispatcher) { - if (!serverReady) + if (!this.serverReady) { this.commandDispatcher = commandDispatcher; return; From 8d9b5f66fa7cea8306745468f64a36e40687c3b2 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Tue, 11 Nov 2025 23:48:17 +0500 Subject: [PATCH 3/3] Prevent auto-pause while pregen is running --- .../minecraft/MinecraftClientWrapper.java | 6 ++++ .../minecraft/MinecraftServerWrapper.java | 7 +++++ coreSubProjects | 2 +- .../mixins/server/MixinMinecraftServer.java | 28 +++++++++++++++++++ .../DistantHorizons.fabric.mixins.json | 3 +- .../mixins/server/MixinMinecraftServer.java | 28 +++++++++++++++++++ .../DistantHorizons.forge.mixins.json | 3 +- .../mixins/server/MixinMinecraftServer.java | 28 +++++++++++++++++++ .../DistantHorizons.neoforge.mixins.json | 3 +- 9 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinMinecraftServer.java create mode 100644 forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinMinecraftServer.java create mode 100644 neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinMinecraftServer.java diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java index 4dc914ab6..415d17e6c 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java @@ -396,4 +396,10 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra } } + @Override + public void setPreventAutoPause(boolean preventAutoPause) + { + throw new UnsupportedOperationException(); + } + } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftServerWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftServerWrapper.java index 32d9532ac..45906cf0c 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftServerWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftServerWrapper.java @@ -11,6 +11,7 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper public static final MinecraftServerWrapper INSTANCE = new MinecraftServerWrapper(); public DedicatedServer dedicatedServer = null; + public boolean preventAutoPause = false; //=============// @@ -49,4 +50,10 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper return this.dedicatedServer.getPlayerCount(); } + @Override + public void setPreventAutoPause(boolean preventAutoPause) + { + this.preventAutoPause = preventAutoPause; + } + } diff --git a/coreSubProjects b/coreSubProjects index 2a49fdee7..91dffa3c3 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 2a49fdee7f2cf1774953f6e04f5699e31eefa63c +Subproject commit 91dffa3c3e6759ec54afabfe60d6037cdbb6f957 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinMinecraftServer.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinMinecraftServer.java new file mode 100644 index 000000000..29445798c --- /dev/null +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinMinecraftServer.java @@ -0,0 +1,28 @@ +package com.seibel.distanthorizons.fabric.mixins.server; + +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper; +import net.minecraft.server.MinecraftServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.BooleanSupplier; + +@Mixin(MinecraftServer.class) +public class MixinMinecraftServer +{ + @Shadow + private int emptyTicks; + + @Inject(method = "tickServer", at = @At("HEAD")) + private void onTickServer(BooleanSupplier hasTimeLeft, CallbackInfo ci) + { + if (MinecraftServerWrapper.INSTANCE.preventAutoPause) + { + this.emptyTicks = 0; + } + } + +} diff --git a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json index dca9096a5..5c7df8859 100644 --- a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json +++ b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json @@ -9,7 +9,8 @@ "server.MixinServerPlayer", "server.MixinTracingExecutor", "server.MixinUtilBackgroundThread", - "server.MixinLevelTicks" + "server.MixinLevelTicks", + "server.MixinMinecraftServer" ], "client": [ "client.MixinClientLevel", diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinMinecraftServer.java b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinMinecraftServer.java new file mode 100644 index 000000000..29445798c --- /dev/null +++ b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinMinecraftServer.java @@ -0,0 +1,28 @@ +package com.seibel.distanthorizons.fabric.mixins.server; + +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper; +import net.minecraft.server.MinecraftServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.BooleanSupplier; + +@Mixin(MinecraftServer.class) +public class MixinMinecraftServer +{ + @Shadow + private int emptyTicks; + + @Inject(method = "tickServer", at = @At("HEAD")) + private void onTickServer(BooleanSupplier hasTimeLeft, CallbackInfo ci) + { + if (MinecraftServerWrapper.INSTANCE.preventAutoPause) + { + this.emptyTicks = 0; + } + } + +} diff --git a/forge/src/main/resources/DistantHorizons.forge.mixins.json b/forge/src/main/resources/DistantHorizons.forge.mixins.json index 6539935e7..9d6292ade 100644 --- a/forge/src/main/resources/DistantHorizons.forge.mixins.json +++ b/forge/src/main/resources/DistantHorizons.forge.mixins.json @@ -8,7 +8,8 @@ "server.MixinTFChunkGenerator", "server.MixinChunkMap", "server.MixinServerPlayer", - "server.MixinEntity" + "server.MixinEntity", + "server.MixinMinecraftServer" ], "client": [ "client.MixinClientPacketListener", diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinMinecraftServer.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinMinecraftServer.java new file mode 100644 index 000000000..6eb0234d4 --- /dev/null +++ b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinMinecraftServer.java @@ -0,0 +1,28 @@ +package com.seibel.distanthorizons.neoforge.mixins.server; + +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper; +import net.minecraft.server.MinecraftServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.BooleanSupplier; + +@Mixin(MinecraftServer.class) +public class MixinMinecraftServer +{ + @Shadow + private int emptyTicks; + + @Inject(method = "tickServer", at = @At("HEAD")) + private void onTickServer(BooleanSupplier hasTimeLeft, CallbackInfo ci) + { + if (MinecraftServerWrapper.INSTANCE.preventAutoPause) + { + this.emptyTicks = 0; + } + } + +} diff --git a/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json b/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json index e0f886569..a05364de6 100644 --- a/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json +++ b/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json @@ -9,7 +9,8 @@ "server.MixinTFChunkGenerator", "server.MixinTracingExecutor", "server.MixinUtilBackgroundThread", - "server.MixinLevelTicks" + "server.MixinLevelTicks", + "server.MixinMinecraftServer" ], "client": [ "client.MixinClientPacketListener",