Forge versions are functional
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Forge Client & Server - Current" type="CompoundRunConfigurationType">
|
||||
<toRun name="Forge Client (:forge)" type="GradleRunConfiguration" />
|
||||
<toRun name="Forge Server (:forge)" type="GradleRunConfiguration" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -0,0 +1,24 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Forge Client (gradle)" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="forge:runClient" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<RunAsTest>false</RunAsTest>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -0,0 +1,24 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Forge Server (gradle)" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="forge:runServer" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<RunAsTest>false</RunAsTest>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -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<CommandSourceStack> commandDispatcher;
|
||||
|
||||
|
||||
public static void startup(LodForgeMethodCaller forgeMethodCaller)
|
||||
@@ -56,4 +84,88 @@ public class LodCommonMain
|
||||
Config.completeDelayedSetup();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static void initCommands()
|
||||
{
|
||||
LiteralArgumentBuilder<CommandSourceStack> 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<CommandContext<CommandSourceStack>, Object>,
|
||||
Command<CommandSourceStack>
|
||||
> 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<CommandSourceStack> 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<Class<?>, Pair<Supplier<ArgumentType<?>>, BiFunction<CommandContext<?>, String, ?>>> pair : new HashMap<
|
||||
Class<?>,
|
||||
Pair<
|
||||
Supplier<ArgumentType<?>>,
|
||||
BiFunction<CommandContext<?>, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-112
@@ -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<CommandSourceStack> 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<CommandSourceStack> 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<CommandContext<CommandSourceStack>, Object>,
|
||||
Command<CommandSourceStack>
|
||||
> 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<CommandSourceStack> 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<Class<?>, Pair<Supplier<ArgumentType<?>>, BiFunction<CommandContext<?>, String, ?>>> pair : new HashMap<
|
||||
Class<?>,
|
||||
Pair<
|
||||
Supplier<ArgumentType<?>>,
|
||||
BiFunction<CommandContext<?>, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public class ForgeClientProxy
|
||||
#else // < 1.20.2
|
||||
Predicate<String> 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;
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Level> 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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user