diff --git a/build.gradle b/build.gradle index 996ae3480..34f6b7165 100644 --- a/build.gradle +++ b/build.gradle @@ -182,6 +182,9 @@ subprojects { p -> implementation("org.apache.logging.log4j:log4j-api:${rootProject.log4j_version}") implementation("org.apache.logging.log4j:log4j-core:${rootProject.log4j_version}") + // Netty + implementation("io.netty:netty-all:${rootProject.netty_version}") + // JOML implementation("org.joml:joml:${rootProject.joml_version}") diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/LodClient.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/LodClient.java deleted file mode 100644 index d31ce3a87..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/LodClient.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.seibel.distanthorizons.common.networking; - -import io.netty.handler.codec.LengthFieldBasedFrameDecoder; -import net.minecraft.client.Minecraft; - -public class LodClient { - public static final LodClient INSTANCE = new LodClient(); - - private final Minecraft client; - private final NetworkHandler networkHandler; - - private LodClient() { - client = Minecraft.getInstance(); - this.networkHandler = new NetworkHandler(); - } - - public void connect() { - - } - - public void disconnect() { - - } -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/LodServer.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/LodServer.java deleted file mode 100644 index b2b66deae..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/LodServer.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.seibel.distanthorizons.common.networking; - -import com.seibel.distanthorizons.common.networking.messages.MessageHandler; -import com.seibel.distanthorizons.common.networking.messages.MessageHandlerSide; -import com.seibel.distanthorizons.common.networking.messages.MessageRegistry; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.codec.LengthFieldBasedFrameDecoder; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.logging.LoggingHandler; - -public class LodServer { - // TODO move to config of some sort - static final int PORT = 25049; - - public void start() throws InterruptedException { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); - try { - ServerBootstrap b = new ServerBootstrap(); - b.group(bossGroup, workerGroup) - .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(getInitializer()); - - b.bind(PORT).sync().channel().closeFuture().sync(); - } finally { - bossGroup.shutdownGracefully(); - workerGroup.shutdownGracefully(); - } - } - - public void stop() { - - } - - private ChannelInitializer getInitializer() { - return new ChannelInitializer<>() { - @Override - public void initChannel(SocketChannel ch) { - ChannelPipeline pipeline = ch.pipeline(); - - var messageRegistry = new MessageRegistry(); - - // Encoding - pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2)); - pipeline.addLast(new MessageDecoder(messageRegistry)); - // TODO packet encoder - - pipeline.addLast(new MessageHandler(MessageHandlerSide.SERVER)); - } - }; - } -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/MessageDecoder.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/MessageDecoder.java deleted file mode 100644 index 65c08520f..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/MessageDecoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.seibel.distanthorizons.common.networking; - -import com.seibel.distanthorizons.common.networking.messages.MessageRegistry; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - -import java.util.List; - -public class MessageDecoder extends ByteToMessageDecoder { - private MessageRegistry messageRegistry; - - public MessageDecoder(MessageRegistry messageRegistry) { - this.messageRegistry = messageRegistry; - } - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - out.add(messageRegistry.createMessage(in.readShort()).decode(in)); - } -} 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 28fc16789..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/NetworkHandler.java +++ /dev/null @@ -1,39 +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 receivePacket(FriendlyByteBuf buf) { - // This just exists here for testing purposes, it'll be removed in the future - System.out.println("Received int " + buf.readInt()); - } -} 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/networking/messages/HelloMessage.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/HelloMessage.java deleted file mode 100644 index 471f44642..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/HelloMessage.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.seibel.distanthorizons.common.networking.messages; - -public class HelloMessage extends Message { - public int version = 1; -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/Message.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/Message.java deleted file mode 100644 index 7257db9b2..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/Message.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.seibel.distanthorizons.common.networking.messages; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; - -public abstract class Message { - public Message() { } - - public void encode(ByteBuf out) { - throw new UnsupportedOperationException(); - } - public Message decode(ByteBuf in) { - throw new UnsupportedOperationException(); - } - - protected void handle_Server(ChannelHandlerContext ctx) { - throw new UnsupportedOperationException(); - } - protected void handle_Client(ChannelHandlerContext ctx) { - throw new UnsupportedOperationException(); - } -} - diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageHandler.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageHandler.java deleted file mode 100644 index 946d32aba..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.seibel.distanthorizons.common.networking.messages; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; - -public class MessageHandler extends SimpleChannelInboundHandler { - private final MessageHandlerSide side; - - public MessageHandler(MessageHandlerSide side) { - this.side = side; - } - - @Override - public void channelRead0(ChannelHandlerContext ctx, Message msg) { - switch (side) { - case CLIENT -> msg.handle_Client(ctx); - case SERVER -> msg.handle_Server(ctx); - default -> throw new IllegalStateException("Invalid handler side"); - } - } -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageHandlerSide.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageHandlerSide.java deleted file mode 100644 index 95056390b..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageHandlerSide.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.seibel.distanthorizons.common.networking.messages; - -public enum MessageHandlerSide { - CLIENT, - SERVER -} diff --git a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageRegistry.java b/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageRegistry.java deleted file mode 100644 index 8f47e23d3..000000000 --- a/common/src/main/java/com/seibel/distanthorizons/common/networking/messages/MessageRegistry.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.seibel.distanthorizons.common.networking.messages; - -import java.util.Map; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -public class MessageRegistry { - private final Map> idToConstructor = Map.ofEntries( - // Do NOT remove messages from middle of the list; - // It will break backwards compatibility. - // (Stub indexes out instead) - Map.entry(1, HelloMessage::new) - ); - - private final Map, Integer> classToId = idToConstructor.entrySet().stream() - .collect(Collectors.toMap( - e -> e.getValue().getClass(), - Map.Entry::getKey - )); - - public Message createMessage(int id) throws IllegalArgumentException { - try { - return idToConstructor.get(id).get(); - } catch (NullPointerException e) { - throw new IllegalArgumentException("Invalid message ID"); - } - } - - public int getMessageId(Message message) { - return classToId.get(message.getClass()); - } -} diff --git a/coreSubProjects b/coreSubProjects index 9789b5be1..cc35e50ed 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 9789b5be126b402f4e4fb2174552a13298e832fa +Subproject commit cc35e50edc53f619bdc562c4d53a33ef7100e5c0 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 71e006f31..b0ffc2fc1 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java @@ -1,6 +1,5 @@ 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.world.ClientLevelWrapper; import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; @@ -70,9 +69,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()); @@ -124,17 +120,4 @@ public class FabricServerProxy }); // ServerChunkSaveEvent - Done in MixinChunkMap } - - // 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()) - { - FriendlyByteBuf payload = Networking.createNew(); - payload.writeInt(1); - System.out.println("Sending int 1"); - Networking.send(player, payload); - } - } - } 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 cd93deb36..d1add917a 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 b9a94aac6..319e64474 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,6 +25,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