Merge branch 'main' of gitlab.com:distant-horizons-team/distant-horizons
This commit is contained in:
@@ -115,8 +115,8 @@ public abstract class AbstractModInitializer
|
|||||||
this.initializeModCompat();
|
this.initializeModCompat();
|
||||||
|
|
||||||
LOGGER.info(ModInfo.READABLE_NAME + " server Initialized, adding event subscribers...");
|
LOGGER.info(ModInfo.READABLE_NAME + " server Initialized, adding event subscribers...");
|
||||||
|
this.commandInitializer = new CommandInitializer();
|
||||||
this.subscribeRegisterCommandsEvent(dispatcher -> { this.commandInitializer = new CommandInitializer(dispatcher); });
|
this.subscribeRegisterCommandsEvent(dispatcher -> { commandInitializer.initCommands(dispatcher); });
|
||||||
|
|
||||||
this.subscribeServerStartingEvent(server ->
|
this.subscribeServerStartingEvent(server ->
|
||||||
{
|
{
|
||||||
@@ -124,7 +124,7 @@ public abstract class AbstractModInitializer
|
|||||||
|
|
||||||
this.initConfig();
|
this.initConfig();
|
||||||
this.postInit();
|
this.postInit();
|
||||||
this.commandInitializer.initCommands();
|
this.commandInitializer.onServerReady();
|
||||||
|
|
||||||
this.checkForUpdates();
|
this.checkForUpdates();
|
||||||
|
|
||||||
|
|||||||
+28
-10
@@ -3,6 +3,7 @@ package com.seibel.distanthorizons.common.commands;
|
|||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
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 com.seibel.distanthorizons.core.network.messages.MessageRegistry.DEBUG_CODEC_CRASH_MESSAGE;
|
||||||
import static net.minecraft.commands.Commands.literal;
|
import static net.minecraft.commands.Commands.literal;
|
||||||
@@ -12,25 +13,42 @@ import static net.minecraft.commands.Commands.literal;
|
|||||||
*/
|
*/
|
||||||
public class CommandInitializer
|
public class CommandInitializer
|
||||||
{
|
{
|
||||||
private final CommandDispatcher<CommandSourceStack> commandDispatcher;
|
private boolean serverReady = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new instance of this class.
|
* A received command dispatcher, which is held until the server is ready to initialize the commands.
|
||||||
*
|
|
||||||
* @param commandDispatcher The dispatcher to use for registering commands.
|
|
||||||
*/
|
*/
|
||||||
public CommandInitializer(CommandDispatcher<CommandSourceStack> commandDispatcher)
|
@Nullable
|
||||||
|
private CommandDispatcher<CommandSourceStack> 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()
|
||||||
{
|
{
|
||||||
this.commandDispatcher = commandDispatcher;
|
this.serverReady = true;
|
||||||
|
if (this.commandDispatcher != null)
|
||||||
|
{
|
||||||
|
this.initCommands(this.commandDispatcher);
|
||||||
|
this.commandDispatcher = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all available commands.
|
* 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<CommandSourceStack> commandDispatcher)
|
||||||
{
|
{
|
||||||
|
if (!this.serverReady)
|
||||||
|
{
|
||||||
|
this.commandDispatcher = commandDispatcher;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LiteralArgumentBuilder<CommandSourceStack> builder = literal("dh")
|
LiteralArgumentBuilder<CommandSourceStack> builder = literal("dh")
|
||||||
.requires(source -> source.hasPermission(4));
|
.requires(source -> source.hasPermission(4));
|
||||||
|
|
||||||
@@ -43,7 +61,7 @@ public class CommandInitializer
|
|||||||
builder.then(new CrashCommand().buildCommand());
|
builder.then(new CrashCommand().buildCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.commandDispatcher.register(builder);
|
commandDispatcher.register(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -396,4 +396,10 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPreventAutoPause(boolean preventAutoPause)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -11,6 +11,7 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper
|
|||||||
public static final MinecraftServerWrapper INSTANCE = new MinecraftServerWrapper();
|
public static final MinecraftServerWrapper INSTANCE = new MinecraftServerWrapper();
|
||||||
|
|
||||||
public DedicatedServer dedicatedServer = null;
|
public DedicatedServer dedicatedServer = null;
|
||||||
|
public boolean preventAutoPause = false;
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
//=============//
|
||||||
@@ -49,4 +50,10 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper
|
|||||||
return this.dedicatedServer.getPlayerCount();
|
return this.dedicatedServer.getPlayerCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPreventAutoPause(boolean preventAutoPause)
|
||||||
|
{
|
||||||
|
this.preventAutoPause = preventAutoPause;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule coreSubProjects updated: 4d4d8fd8e9...6bfcf36687
+28
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
"server.MixinServerPlayer",
|
"server.MixinServerPlayer",
|
||||||
"server.MixinTracingExecutor",
|
"server.MixinTracingExecutor",
|
||||||
"server.MixinUtilBackgroundThread",
|
"server.MixinUtilBackgroundThread",
|
||||||
"server.MixinLevelTicks"
|
"server.MixinLevelTicks",
|
||||||
|
"server.MixinMinecraftServer"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"client.MixinClientLevel",
|
"client.MixinClientLevel",
|
||||||
|
|||||||
+28
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
"server.MixinTFChunkGenerator",
|
"server.MixinTFChunkGenerator",
|
||||||
"server.MixinChunkMap",
|
"server.MixinChunkMap",
|
||||||
"server.MixinServerPlayer",
|
"server.MixinServerPlayer",
|
||||||
"server.MixinEntity"
|
"server.MixinEntity",
|
||||||
|
"server.MixinMinecraftServer"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"client.MixinClientPacketListener",
|
"client.MixinClientPacketListener",
|
||||||
|
|||||||
+28
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
"server.MixinTFChunkGenerator",
|
"server.MixinTFChunkGenerator",
|
||||||
"server.MixinTracingExecutor",
|
"server.MixinTracingExecutor",
|
||||||
"server.MixinUtilBackgroundThread",
|
"server.MixinUtilBackgroundThread",
|
||||||
"server.MixinLevelTicks"
|
"server.MixinLevelTicks",
|
||||||
|
"server.MixinMinecraftServer"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"client.MixinClientPacketListener",
|
"client.MixinClientPacketListener",
|
||||||
|
|||||||
Reference in New Issue
Block a user