diff --git a/.run/Forge Client & Server - Current.run.xml b/.run/Forge Client & Server - Current.run.xml
new file mode 100644
index 000000000..046441476
--- /dev/null
+++ b/.run/Forge Client & Server - Current.run.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.run/Forge Client (gradle).run.xml b/.run/Forge Client (gradle).run.xml
new file mode 100644
index 000000000..312b3ef1c
--- /dev/null
+++ b/.run/Forge Client (gradle).run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/Forge Server (gradle).run.xml b/.run/Forge Server (gradle).run.xml
new file mode 100644
index 000000000..4690ddf5d
--- /dev/null
+++ b/.run/Forge Server (gradle).run.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java b/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java
index 010fbe8e5..79850e64c 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java
@@ -19,12 +19,40 @@
package com.seibel.distanthorizons.common;
+import com.mojang.brigadier.Command;
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.ArgumentType;
+import com.mojang.brigadier.arguments.BoolArgumentType;
+import com.mojang.brigadier.arguments.DoubleArgumentType;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.context.CommandContext;
import com.seibel.distanthorizons.common.forge.LodForgeMethodCaller;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
+import com.seibel.distanthorizons.core.config.types.AbstractConfigType;
+import com.seibel.distanthorizons.core.config.types.ConfigEntry;
+import com.seibel.distanthorizons.core.util.objects.Pair;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigBase;
+import net.minecraft.commands.CommandSourceStack;
+
+#if MC_VER >= MC_1_19_2
+import net.minecraft.network.chat.Component;
+#else // < 1.19.2
+import net.minecraft.network.chat.TranslatableComponent;
+#endif
+
+import java.util.HashMap;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+import static com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg;
+import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
+import static net.minecraft.commands.Commands.argument;
+import static net.minecraft.commands.Commands.literal;
/**
* This is the common main class
@@ -35,7 +63,7 @@ public class LodCommonMain
{
public static boolean forge = false;
public static LodForgeMethodCaller forgeMethodCaller;
-
+ public static CommandDispatcher commandDispatcher;
public static void startup(LodForgeMethodCaller forgeMethodCaller)
@@ -56,4 +84,88 @@ public class LodCommonMain
Config.completeDelayedSetup();
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static void initCommands()
+ {
+ LiteralArgumentBuilder builder = literal("dhconfig")
+ .requires(source -> source.hasPermission(4));
+
+ for (AbstractConfigType, ?> type : ConfigBase.INSTANCE.entries)
+ {
+ if (!(type instanceof ConfigEntry)) continue;
+ ConfigEntry configEntry = (ConfigEntry) type;
+ if (configEntry.getServersideShortName() == null) continue;
+
+ Function<
+ Function, Object>,
+ Command
+ > makeConfigUpdater = getter -> c -> {
+ Object value = getter.apply(c);
+ #if MC_VER >= MC_1_20_1
+ c.getSource().sendSuccess(() -> Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true);
+ #elif MC_VER >= MC_1_19_2
+ c.getSource().sendSuccess(Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true);
+ #else // < 1.19.2
+ c.getSource().sendSuccess(new TranslatableComponent("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true);
+ #endif
+ configEntry.set(value);
+ return 1;
+ };
+
+ LiteralArgumentBuilder subcommand = literal(configEntry.getServersideShortName())
+ .executes(c -> {
+ #if MC_VER >= MC_1_20_1
+ c.getSource().sendSuccess(() -> Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
+ #elif MC_VER >= MC_1_19_2
+ c.getSource().sendSuccess(Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
+ #else // < 1.19.2
+ c.getSource().sendSuccess(new TranslatableComponent("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
+ #endif
+ return 1;
+ });
+
+ if (Enum.class.isAssignableFrom(configEntry.getType()))
+ {
+ for (Object choice : configEntry.getType().getEnumConstants())
+ {
+ subcommand.then(
+ literal(choice.toString())
+ .executes(makeConfigUpdater.apply(c -> choice))
+ );
+ }
+ }
+ else
+ {
+ boolean setterAdded = false;
+
+ for (java.util.Map.Entry, Pair>, BiFunction, String, ?>>> pair : new HashMap<
+ Class>,
+ Pair<
+ Supplier>,
+ BiFunction, String, ?>>
+ >() {{
+ put(Integer.class, new Pair<>(() -> integer((int) configEntry.getMin(), (int) configEntry.getMax()), IntegerArgumentType::getInteger));
+ put(Double.class, new Pair<>(() -> doubleArg((double) configEntry.getMin(), (double) configEntry.getMax()), DoubleArgumentType::getDouble));
+ put(Boolean.class, new Pair<>(BoolArgumentType::bool, BoolArgumentType::getBool));
+ }}.entrySet())
+ {
+ if (!pair.getKey().isAssignableFrom(configEntry.getType())) continue;
+
+ subcommand.then(argument("value", pair.getValue().first.get())
+ .executes(makeConfigUpdater.apply(c -> pair.getValue().second.apply(c, "value"))));
+
+ setterAdded = true;
+ break;
+ }
+
+ if (!setterAdded)
+ throw new RuntimeException("Config type of "+type.getName()+" is not supported: "+configEntry.getType().getSimpleName());
+ }
+
+ builder.then(subcommand);
+ }
+
+ commandDispatcher.register(builder);
+ }
+
}
diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java
index bfd336ac1..63d9bbe38 100644
--- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java
+++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java
@@ -1,28 +1,15 @@
package com.seibel.distanthorizons.fabric;
-import com.mojang.brigadier.Command;
-import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.arguments.ArgumentType;
-import com.mojang.brigadier.arguments.BoolArgumentType;
-import com.mojang.brigadier.arguments.DoubleArgumentType;
-import com.mojang.brigadier.arguments.IntegerArgumentType;
-import com.mojang.brigadier.builder.LiteralArgumentBuilder;
-import com.mojang.brigadier.context.CommandContext;
import com.seibel.distanthorizons.common.LodCommonMain;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
-import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
-import com.seibel.distanthorizons.core.config.types.AbstractConfigType;
-import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import com.seibel.distanthorizons.core.util.LodUtil;
-import com.seibel.distanthorizons.core.util.objects.Pair;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
-import net.minecraft.commands.CommandSourceStack;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.dedicated.DedicatedServer;
import org.apache.logging.log4j.LogManager;
@@ -30,22 +17,10 @@ import org.apache.logging.log4j.Logger;
#if MC_VER >= MC_1_19_2
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
-import net.minecraft.network.chat.Component;
#else // < 1.19.2
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
-import net.minecraft.network.chat.TranslatableComponent;
#endif
-import java.util.HashMap;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-import static com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg;
-import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
-import static net.minecraft.commands.Commands.argument;
-import static net.minecraft.commands.Commands.literal;
-
@Environment(EnvType.SERVER)
public class FabricDedicatedServerMain implements DedicatedServerModInitializer
{
@@ -55,7 +30,6 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer
public static FabricServerProxy server_proxy;
public boolean hasPostSetupDone = false;
- private CommandDispatcher commandDispatcher;
@Override
public void onInitializeServer()
@@ -77,7 +51,7 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer
#else // < 1.19.2
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
#endif
- this.commandDispatcher = dispatcher;
+ LodCommonMain.commandDispatcher = dispatcher;
});
ServerLifecycleEvents.SERVER_STARTING.addPhaseOrdering(INITIAL_PHASE, Event.DEFAULT_PHASE);
@@ -94,94 +68,10 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer) server;
LodCommonMain.initConfig();
FabricMain.postInit();
- this.initCommands();
+ LodCommonMain.initCommands();
LOGGER.info("Dedicated server initialized at " + server.getServerDirectory());
});
}
- @SuppressWarnings({"rawtypes", "unchecked"})
- public void initCommands()
- {
- LiteralArgumentBuilder builder = literal("dhconfig")
- .requires(source -> source.hasPermission(4));
-
- for (AbstractConfigType, ?> type : ConfigBase.INSTANCE.entries)
- {
- if (!(type instanceof ConfigEntry)) continue;
- ConfigEntry configEntry = (ConfigEntry) type;
- if (configEntry.getServersideShortName() == null) continue;
-
- Function<
- Function, Object>,
- Command
- > makeConfigUpdater = getter -> c -> {
- Object value = getter.apply(c);
- #if MC_VER >= MC_1_20_1
- c.getSource().sendSuccess(() -> Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true);
- #elif MC_VER >= MC_1_19_2
- c.getSource().sendSuccess(Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true);
- #else // < 1.19.2
- c.getSource().sendSuccess(new TranslatableComponent("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true);
- #endif
- configEntry.set(value);
- return 1;
- };
-
- LiteralArgumentBuilder subcommand = literal(configEntry.getServersideShortName())
- .executes(c -> {
- #if MC_VER >= MC_1_20_1
- c.getSource().sendSuccess(() -> Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
- #elif MC_VER >= MC_1_19_2
- c.getSource().sendSuccess(Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
- #else // < 1.19.2
- c.getSource().sendSuccess(new TranslatableComponent("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
- #endif
- return 1;
- });
-
- if (Enum.class.isAssignableFrom(configEntry.getType()))
- {
- for (Object choice : configEntry.getType().getEnumConstants())
- {
- subcommand.then(
- literal(choice.toString())
- .executes(makeConfigUpdater.apply(c -> choice))
- );
- }
- }
- else
- {
- boolean setterAdded = false;
-
- for (java.util.Map.Entry, Pair>, BiFunction, String, ?>>> pair : new HashMap<
- Class>,
- Pair<
- Supplier>,
- BiFunction, String, ?>>
- >() {{
- put(Integer.class, new Pair<>(() -> integer((int) configEntry.getMin(), (int) configEntry.getMax()), IntegerArgumentType::getInteger));
- put(Double.class, new Pair<>(() -> doubleArg((double) configEntry.getMin(), (double) configEntry.getMax()), DoubleArgumentType::getDouble));
- put(Boolean.class, new Pair<>(BoolArgumentType::bool, BoolArgumentType::getBool));
- }}.entrySet())
- {
- if (!pair.getKey().isAssignableFrom(configEntry.getType())) continue;
-
- subcommand.then(argument("value", pair.getValue().first.get())
- .executes(makeConfigUpdater.apply(c -> pair.getValue().second.apply(c, "value"))));
-
- setterAdded = true;
- break;
- }
-
- if (!setterAdded)
- throw new RuntimeException("Config type of "+type.getName()+" is not supported: "+configEntry.getType().getSimpleName());
- }
-
- builder.then(subcommand);
- }
-
- commandDispatcher.register(builder);
- }
-
}
diff --git a/forge/build.gradle b/forge/build.gradle
index 9c159a519..09527167b 100644
--- a/forge/build.gradle
+++ b/forge/build.gradle
@@ -37,15 +37,15 @@ loom {
client {
client()
setConfigName("Forge Client")
- ideConfigGenerated(true)
- runDir("../run")
+ ideConfigGenerated(false)
+ runDir("../run/client")
// vmArgs("-XX:-OmitStackTraceInFastThrow", minecraftMemoryJavaArg)
}
server {
server()
setConfigName("Forge Server")
- ideConfigGenerated(true)
- runDir("../run")
+ ideConfigGenerated(false)
+ runDir("../run/server")
}
}
}
diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeClientProxy.java b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeClientProxy.java
index c074a8a56..422865a69 100644
--- a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeClientProxy.java
+++ b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeClientProxy.java
@@ -277,7 +277,7 @@ public class ForgeClientProxy
#else // < 1.20.2
Predicate versionTest = versionString ->
{
- if (versionString.equals(NetworkRegistry.ABSENT) || versionString.equals(NetworkRegistry.ACCEPTVANILLA))
+ if (versionString.equals(NetworkRegistry.ABSENT #if MC_VER >= MC_1_19_4 .version() #endif) || versionString.equals(NetworkRegistry.ACCEPTVANILLA))
{
// allow using networking on vanilla servers or if DH isn't installed on the server
return true;
diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeMain.java b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeMain.java
index e2fbef032..cfe03bdb7 100644
--- a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeMain.java
+++ b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeMain.java
@@ -50,6 +50,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.*;
@@ -187,6 +188,10 @@ public class ForgeMain implements LodForgeMethodCaller
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
+ MinecraftForge.EVENT_BUS.addListener((RegisterCommandsEvent e) -> {
+ LodCommonMain.commandDispatcher = e.getDispatcher();
+ });
+
#if MC_VER >= MC_1_18_2
MinecraftForge.EVENT_BUS.addListener((ServerStartingEvent e) -> {
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)e.getServer();
@@ -199,6 +204,7 @@ public class ForgeMain implements LodForgeMethodCaller
// The reason im initialising in this rather than the post init process is cus im using this for the auto updater
LodCommonMain.initConfig();
postInitCommon();
+ LodCommonMain.initCommands();
});
}
diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeServerProxy.java b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeServerProxy.java
index 7b5c9b29c..09ce9814e 100644
--- a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeServerProxy.java
+++ b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeServerProxy.java
@@ -2,18 +2,20 @@ package com.seibel.distanthorizons.forge;
import com.seibel.distanthorizons.common.util.ProxyUtil;
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
-import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
+import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.distanthorizons.core.api.internal.ServerApi;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
-import net.minecraft.client.multiplayer.ClientLevel;
+import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.event.entity.player.PlayerEvent;
#if MC_VER < MC_1_19_2
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
@@ -23,6 +25,13 @@ import net.minecraftforge.event.level.LevelEvent;
#endif
import net.minecraftforge.eventbus.api.SubscribeEvent;
+#if MC_VER >= MC_1_19_4
+import net.minecraft.core.registries.Registries;
+#else // < 1.19.4
+import net.minecraft.core.Registry;
+import net.minecraft.core.RegistryAccess;
+#endif
+
#if MC_VER == MC_1_16_5
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
@@ -138,6 +147,26 @@ public class ForgeServerProxy
this.serverApi.serverChunkSaveEvent(chunk, levelWrapper);
}
+ @SubscribeEvent
+ public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event)
+ {
+ this.serverApi.serverPlayerJoinEvent(getServerPlayerWrapper(event));
+ }
+ @SubscribeEvent
+ public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent event)
+ {
+ this.serverApi.serverPlayerDisconnectEvent(getServerPlayerWrapper(event));
+ }
+ @SubscribeEvent
+ public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent event)
+ {
+ this.serverApi.serverPlayerLevelChangeEvent(
+ getServerPlayerWrapper(event),
+ getServerLevelWrapper(event.getFrom(), event),
+ getServerLevelWrapper(event.getTo(), event)
+ );
+ }
+
//================//
@@ -147,4 +176,32 @@ public class ForgeServerProxy
private static ServerLevelWrapper getServerLevelWrapper(ServerLevel level) { return ServerLevelWrapper.getWrapper(level); }
+ private static ServerLevelWrapper getServerLevelWrapper(ResourceKey resourceKey, PlayerEvent.PlayerChangedDimensionEvent event)
+ {
+ return getServerLevelWrapper(
+ #if MC_VER >= MC_1_19_4
+ (ServerLevel) event.getEntity().getServer().registryAccess().registryOrThrow(Registries.DIMENSION).get(resourceKey)
+ #else // < 1.19.4
+ (ServerLevel) RegistryAccess
+ #if MC_VER >= MC_1_18_2
+ .builtinCopy()
+ #else // < 1.18.2
+ .builtin()
+ #endif
+ .registry(Registry.DIMENSION_REGISTRY).get()
+ .get(resourceKey)
+ #endif
+ );
+ }
+
+ private static ServerPlayerWrapper getServerPlayerWrapper(PlayerEvent event) {
+ return ServerPlayerWrapper.getWrapper(
+ #if MC_VER >= MC_1_19_2
+ (ServerPlayer) event.getEntity()
+ #else
+ (ServerPlayer) event.getPlayer()
+ #endif
+ );
+ }
+
}