diff --git a/.gitmodules b/.gitmodules index b605ac7c2..45f80ad85 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "coreSubProjects"] path = coreSubProjects - url = https://gitlab.com/jeseibel/distant-horizons-core.git + url = https://gitlab.com/s809/distant-horizons-core.git diff --git a/build.gradle b/build.gradle index 901027300..e8789b033 100644 --- a/build.gradle +++ b/build.gradle @@ -216,7 +216,7 @@ subprojects { p -> forgeShadowMe("com.formdev:flatlaf-extras:${rootProject.flatlaf_version}") // Netty - forgeShadowMe("io.netty:netty-all:4.1.94.Final") + forgeShadowMe("io.netty:netty-all:${rootProject.netty_version}") // Remember, for lwjgl dependancies that arent included in Minecraft, you need to also need to add it to the ShadowJar thing forgeShadowMe("org.lwjgl:lwjgl-jawt:3.2.2") { 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 c4097ef7c..9e4e94ec6 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java @@ -30,15 +30,21 @@ import com.seibel.distanthorizons.core.config.ConfigBase; * This is the common main class * @author Ran */ -public class LodCommonMain { +public class LodCommonMain +{ public static boolean forge = false; public static LodForgeMethodCaller forgeMethodCaller; - public static void startup(LodForgeMethodCaller caller) { - if (caller != null) { + + + + public static void startup(LodForgeMethodCaller forgeMethodCaller) + { + if (forgeMethodCaller != null) + { LodCommonMain.forge = true; - forgeMethodCaller = caller; + LodCommonMain.forgeMethodCaller = forgeMethodCaller; } - + DependencySetup.createSharedBindings(); SharedApi.init(); // if (!serverSided) { @@ -53,4 +59,5 @@ public class LodCommonMain { ConfigBase.INSTANCE = new ConfigBase(ModInfo.ID, ModInfo.NAME, Config.class,1); Config.completeDelayedSetup(); } + } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkHandler.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkHandler.java deleted file mode 100644 index ecef2606c..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkHandler.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.common.networking; - -import net.minecraft.client.Minecraft; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; - -/** - * This is packet handler for our mod - * It basically handles the packets sent from the server & client - * - * @author Ran - */ - -// TODO: Server sided stuff here -public class NetworkHandler { - public static void receivePacketClient(Minecraft client, FriendlyByteBuf buf, Player player) { - // This just exists here for testing purposes, it'll be removed in the future - System.out.println("Received int " + buf.readInt()); - } - - public static void receivePacketServer(FriendlyByteBuf buf, Player player) { - - } -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkReceiver.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkReceiver.java deleted file mode 100644 index 218e70955..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkReceiver.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.common.networking; - -/* -#if MC_1_16_5 -import me.shedaniel.architectury.networking.NetworkManager; -#else -import dev.architectury.networking.NetworkManager; -#endif -import net.minecraft.client.Minecraft; -import net.minecraft.network.FriendlyByteBuf; -*/ - -/** - * @author Ran - */ -// Comment: What does the 'server' side mean? Dedicated server? Or does it include the internal server? -// (I removed the hookup that calls the register method, since I'm not sure what it is doing yet) -public class NetworkReceiver { - /* - public void register_Client() { - NetworkManager.registerReceiver(NetworkManager.serverToClient(), Networking.RESOURCE_LOCATION, new ClientReceiver()); - } - - public void register_Server() { - NetworkManager.registerReceiver(NetworkManager.clientToServer(), Networking.RESOURCE_LOCATION, new ServerReceiver()); - } - - static class ServerReceiver implements NetworkManager.NetworkReceiver { - @Override - public void receive(FriendlyByteBuf buf, NetworkManager.PacketContext context) { - com.seibel.distanthorizons.common.networking.NetworkHandler.receivePacketServer(buf, context.getPlayer()); - } - } - - static class ClientReceiver implements NetworkManager.NetworkReceiver { - @Override - public void receive(FriendlyByteBuf buf, NetworkManager.PacketContext context) { - com.seibel.distanthorizons.common.networking.NetworkHandler.receivePacketClient(Minecraft.getInstance(), buf, context.getPlayer()); - } - } - */ -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/Networking.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/Networking.java deleted file mode 100644 index a2d52071f..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/Networking.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.common.networking; - -import com.seibel.distanthorizons.coreapi.ModInfo; -//#if MC_1_16_5 -//import me.shedaniel.architectury.networking.NetworkManager; -//#else -//import dev.architectury.networking.NetworkManager; -//#endif -import io.netty.buffer.Unpooled; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; - -/** - * This class holds most of the networking code for the mod. - * @author Ran - */ -public class Networking { - public static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation("lod", "data"); - - public static FriendlyByteBuf createNew() { - // TODO: Probably replace the Unpooled.buffer() - FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - buf.writeInt(ModInfo.PROTOCOL_VERSION); - return buf; - } - - /** - * Sends a packet to a player. - * - * @param player the player to send the packet to - * @param buf the payload of the packet. - */ - public static void send(ServerPlayer player, FriendlyByteBuf buf) { -// NetworkManager.sendToPlayer(player, RESOURCE_LOCATION, buf); - } - - /** - * Sends a packet to the connected server. - * - * @param buf the payload of the packet - * @throws IllegalStateException if the client is not connected to a server - */ - public static void send(FriendlyByteBuf buf) throws IllegalStateException { -// NetworkManager.sendToServer(RESOURCE_LOCATION, buf); - } - -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java index a3d513e41..3e32636ea 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java @@ -45,7 +45,9 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSha * @author Ran * @version 12-1-2021 */ -public class DependencySetup { +public class DependencySetup +{ + public static void createSharedBindings() { SingletonInjector.INSTANCE.bind(ILangWrapper.class, LangWrapper.INSTANCE); @@ -56,15 +58,18 @@ public class DependencySetup { } //@Environment(EnvType.SERVER) - public static void createServerBindings() { + public static void createServerBindings() + { SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftDedicatedServerWrapper.INSTANCE); } //@Environment(EnvType.CLIENT) - public static void createClientBindings() { + public static void createClientBindings() + { SingletonInjector.INSTANCE.bind(IMinecraftClientWrapper.class, MinecraftClientWrapper.INSTANCE); SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftClientWrapper.INSTANCE); SingletonInjector.INSTANCE.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE); SingletonInjector.INSTANCE.bind(IReflectionHandler.class, ReflectionHandler.INSTANCE); } + } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java index 33d2356e0..3564e1262 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java @@ -23,7 +23,9 @@ import java.util.function.Supplier; public class DependencySetupDoneCheck { + // TODO move to DependencySetup public static boolean isDone = false; + // TODO why is this here and what is its purpose? public static Supplier getIsCurrentThreadDistantGeneratorThread = (() -> {return false;}); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java index a049f4392..8992217d1 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java @@ -124,7 +124,7 @@ public class WrapperFactory implements IWrapperFactory // Intentional compiler error to bring attention to the missing wrapper function. // If you need to work on an unimplemented version but don't have the ability to implement this yet // you can comment it out, but please don't commit it. Someone will have to implement it . - + // After implementing the new version please read this method's javadocs for instructions // on what other locations also need to be updated, the DhAPI specifically needs to // be updated to state which objects this method accepts. 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 bc9aa7930..bd7385640 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 @@ -22,6 +22,7 @@ package com.seibel.distanthorizons.common.wrappers.minecraft; import java.io.File; import java.lang.invoke.MethodHandles; import java.util.ArrayList; +import java.util.UUID; import com.mojang.blaze3d.platform.NativeImage; import com.seibel.distanthorizons.common.wrappers.McObjectConverter; @@ -148,6 +149,11 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra return mc.player != null; } + @Override + public UUID getPlayerUUID() { + return getPlayer().getUUID(); + } + @Override public DhBlockPos getPlayerBlockPos() { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java new file mode 100644 index 000000000..f8d640bfc --- /dev/null +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java @@ -0,0 +1,43 @@ +package com.seibel.distanthorizons.common.wrappers.misc; + +import com.google.common.collect.MapMaker; +import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper; +import net.minecraft.server.level.ServerPlayer; + +import java.util.UUID; +import java.util.concurrent.ConcurrentMap; + +public class ServerPlayerWrapper implements IServerPlayerWrapper { + private static final ConcurrentMap + serverPlayerWrapperMap = new MapMaker().weakKeys().makeMap(); + + private final ServerPlayer serverPlayer; + + public static ServerPlayerWrapper getWrapper(ServerPlayer serverPlayer) + { + return serverPlayerWrapperMap.computeIfAbsent(serverPlayer, ServerPlayerWrapper::new); + } + + private ServerPlayerWrapper(ServerPlayer serverPlayer) { + this.serverPlayer = serverPlayer; + } + + public UUID getUUID() { + return serverPlayer.getUUID(); + } + + public IServerLevelWrapper getLevel() { + return ServerLevelWrapper.getWrapper(serverPlayer.getLevel()); + } + + public Object getWrappedMcObject() { + return serverPlayer; + } + + @Override + public String toString() { + return "Wrapped{" + serverPlayer.toString() + "}"; + } +} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java index fc5566c84..295419050 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java @@ -31,7 +31,7 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.ProtoChunk; import net.minecraft.world.level.levelgen.Heightmap; -#if POST_MC_1_18_2 +#if POST_MC_1_18_2 #endif public final class StepFeatures { diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientMain.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientMain.java index ca773600c..2990b3ffd 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientMain.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientMain.java @@ -1,5 +1,6 @@ package com.seibel.distanthorizons.fabric; +import com.seibel.distanthorizons.common.LodCommonMain; import com.seibel.distanthorizons.common.wrappers.DependencySetup; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; @@ -20,6 +21,7 @@ public class FabricClientMain implements ClientModInitializer { DependencySetup.createClientBindings(); FabricMain.init(); + LodCommonMain.initConfig(); server_proxy = new FabricServerProxy(false); server_proxy.registerEvents(); diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java index f2bd95dcb..b8c4dd2ec 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java @@ -40,9 +40,11 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; @@ -50,6 +52,9 @@ import java.nio.FloatBuffer; import java.util.HashSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResult; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.phys.HitResult; @@ -226,6 +231,12 @@ public class FabricClientProxy onKeyInput(); } }); + + ClientPlayNetworking.registerGlobalReceiver(new ResourceLocation("distant_horizons", "world_control"), // TODO move these strings into a constant somewhere + (Minecraft client, ClientPacketListener handler, FriendlyByteBuf byteBuffer, PacketSender responseSender) -> + { + ClientApi.INSTANCE.serverMessageReceived(byteBuffer); + }); } private boolean isValidTime() { return !(Minecraft.getInstance().screen instanceof TitleScreen); } 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 db81ee969..7f224ba94 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java @@ -1,7 +1,9 @@ package com.seibel.distanthorizons.fabric; +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.eventHandlers.presets.ThreadPresetConfigEventHandler; import com.seibel.distanthorizons.core.util.LodUtil; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.EnvType; @@ -17,23 +19,37 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer private static final Logger LOGGER = LogManager.getLogger(FabricDedicatedServerMain.class.getSimpleName()); public static FabricServerProxy server_proxy; - public boolean hasPostSetupDone = false; - - @Override - public void onInitializeServer() { - DependencySetup.createServerBindings(); - FabricMain.init(); - - server_proxy = new FabricServerProxy(true); - server_proxy.registerEvents(); - - ServerLifecycleEvents.SERVER_STARTING.register((server) -> { - if (hasPostSetupDone) return; - hasPostSetupDone = true; - LodUtil.assertTrue(server instanceof DedicatedServer); - MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer) server; - FabricMain.postInit(); - LOGGER.info("Dedicated server inited at {}", server.getServerDirectory()); - }); - } + public boolean hasPostSetupDone = false; + + @Override + public void onInitializeServer() + { + DependencySetup.createServerBindings(); + FabricMain.init(); + + // FIXME this prevents returning uninitialized Config values + // resulting from a circular reference mid-initialization in a static class + // ThreadPresetConfigEventHandler <-> Config + ThreadPresetConfigEventHandler.INSTANCE.toString(); + + server_proxy = new FabricServerProxy(true); + server_proxy.registerEvents(); + + ServerLifecycleEvents.SERVER_STARTING.register((server) -> + { + if (this.hasPostSetupDone) + { + return; + } + + this.hasPostSetupDone = true; + LodUtil.assertTrue(server instanceof DedicatedServer); + + MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer) server; + LodCommonMain.initConfig(); + FabricMain.postInit(); + + LOGGER.info("Dedicated server initialized at "+server.getServerDirectory()); + }); + } } diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricMain.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricMain.java index 1c0ad6806..90ade3df6 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricMain.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricMain.java @@ -21,6 +21,7 @@ package com.seibel.distanthorizons.fabric; import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent; import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent; +import com.seibel.distanthorizons.core.config.ConfigBase; import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.*; import com.seibel.distanthorizons.common.LodCommonMain; import com.seibel.distanthorizons.coreapi.ModInfo; @@ -54,6 +55,9 @@ public class FabricMain if (Config.Client.Advanced.Graphics.Fog.disableVanillaFog.get() && SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib")) ModAccessorInjector.INSTANCE.get(IBCLibAccessor.class).setRenderCustomFog(false); // Remove BCLib's fog + if (ConfigBase.INSTANCE == null) + throw new IllegalStateException("Config was not initialized. Make sure to call LodCommonMain.initConfig() before calling this method."); + LOGGER.info("Mod Post-Initialized"); } @@ -88,9 +92,5 @@ public class FabricMain LOGGER.info(ModInfo.READABLE_NAME + " Initialized"); ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null); - - // Init config - // The reason im initialising in this rather than the post init process is cus im using this for the auto updater - LodCommonMain.initConfig(); } } diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java index 3bf1cd435..6f3d6c4c1 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java @@ -1,7 +1,7 @@ package com.seibel.distanthorizons.fabric; -import com.seibel.distanthorizons.common.networking.Networking; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; +import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper; import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper; import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment; @@ -16,13 +16,13 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import org.apache.logging.log4j.Logger; @@ -67,6 +67,7 @@ public class FabricServerProxy private IClientLevelWrapper getClientLevelWrapper(ClientLevel level) { return ClientLevelWrapper.getWrapper(level); } private ServerLevelWrapper getServerLevelWrapper(ServerLevel level) { return ServerLevelWrapper.getWrapper(level); } + private ServerPlayerWrapper getServerPlayerWrapper(ServerPlayer player) { return ServerPlayerWrapper.getWrapper(player); } /** Registers Fabric Events */ public void registerEvents() @@ -76,9 +77,6 @@ public class FabricServerProxy /* Register the mod needed event callbacks */ - // TEST EVENT - //ServerTickEvents.END_SERVER_TICK.register(this::tester); - // ServerTickEvent ServerTickEvents.END_SERVER_TICK.register((server) -> SERVER_API.serverTickEvent()); @@ -130,23 +128,20 @@ public class FabricServerProxy }); // ServerChunkSaveEvent - Done in MixinChunkMap - ClientPlayNetworking.registerGlobalReceiver(new ResourceLocation("distant_horizons", "world_control"), // TODO move these strings into a constant somewhere - (Minecraft client, ClientPacketListener handler, FriendlyByteBuf byteBuffer, PacketSender responseSender) -> - { - ClientApi.INSTANCE.serverMessageReceived(byteBuffer); - }); - } - - // This just exists here for testing purposes, it'll be removed in the future - public void tester(MinecraftServer server) - { // I disabled the Networking functions for now so this will not work atm - coolGi - for (ServerPlayer player : server.getPlayerList().getPlayers()) + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { - FriendlyByteBuf payload = Networking.createNew(); - payload.writeInt(1); - System.out.println("Sending int 1"); - Networking.send(player, payload); - } + if (isValidTime()) + { + ServerApi.INSTANCE.serverPlayerJoinEvent(getServerPlayerWrapper(handler.player)); + } + }); + ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> + { + if (isValidTime()) + { + ServerApi.INSTANCE.serverPlayerDisconnectEvent(getServerPlayerWrapper(handler.player)); + } + }); } } diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java index 440ff2c86..b4feaa656 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java @@ -67,5 +67,5 @@ public class MixinClientPacketListener } #endif - + } 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 05011d444..14c71f58e 100644 --- a/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeServerProxy.java +++ b/forge/src/main/java/com/seibel/distanthorizons/forge/ForgeServerProxy.java @@ -1,6 +1,5 @@ package com.seibel.distanthorizons.forge; -import com.seibel.distanthorizons.common.networking.Networking; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment; @@ -145,14 +144,4 @@ public class ForgeServerProxy } } } - - // This just exists here for testing purposes, it'll be removed in the future - public void tester(MinecraftServer server) { - for (ServerPlayer player : server.getPlayerList().getPlayers()) { - FriendlyByteBuf payload = Networking.createNew(); - payload.writeInt(1); - System.out.println("Sending int 1"); - Networking.send(player, payload); - } - } } diff --git a/gradle.properties b/gradle.properties index b70b1011b..50c7278f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,6 +26,7 @@ flatlaf_version=3.0 svgSalamander_version=1.1.3 log4j_version=2.20.0 +netty_version=4.1.94.Final lwjgl_version=3.2.3 joml_version=1.10.2