diff --git a/src/main/java/dev/hilligans/ourcraft/GameInstance.java b/src/main/java/dev/hilligans/ourcraft/GameInstance.java index 19620041..48bbb114 100644 --- a/src/main/java/dev/hilligans/ourcraft/GameInstance.java +++ b/src/main/java/dev/hilligans/ourcraft/GameInstance.java @@ -321,12 +321,6 @@ public ByteBuffer getResource(ResourceLocation resourceLocation, IBufferAllocato return DATA_LOADER.get(resourceLocation, allocator); } - public void registerDefaultContent() { - // Ourcraft.registerDefaultContent(OURCRAFT); - //Container.register(); - //Entity.register(); - } - public int getUniqueID() { return gameInstanceUniversalID; } diff --git a/src/main/java/dev/hilligans/ourcraft/client/Client.java b/src/main/java/dev/hilligans/ourcraft/client/Client.java index e9ec8018..3165dbd7 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/Client.java +++ b/src/main/java/dev/hilligans/ourcraft/client/Client.java @@ -7,8 +7,6 @@ import dev.hilligans.ourcraft.client.rendering.ContainerScreen; import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; import dev.hilligans.ourcraft.client.rendering.graphics.api.IInputProvider; -import dev.hilligans.ourcraft.client.rendering.graphics.implementations.splitwindows.SplitWindow; -import dev.hilligans.ourcraft.client.rendering.graphics.implementations.splitwindows.SubWindow; import dev.hilligans.ourcraft.client.rendering.graphics.opengl.OpenGLEngine; import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; import dev.hilligans.ourcraft.client.rendering.graphics.vulkan.VulkanEngine; @@ -25,12 +23,10 @@ import dev.hilligans.ourcraft.mod.handler.events.client.OpenScreenEvent; import dev.hilligans.ourcraft.network.ClientNetwork; import dev.hilligans.ourcraft.network.IClientPacketHandler; -import dev.hilligans.ourcraft.network.Protocol; -import dev.hilligans.ourcraft.network.packet.auth.CGetToken; +import dev.hilligans.ourcraft.network.PacketBase; import dev.hilligans.ourcraft.network.packet.client.CCloseScreen; import dev.hilligans.ourcraft.network.packet.client.CDropItem; import dev.hilligans.ourcraft.network.packet.client.COpenScreen; -import dev.hilligans.ourcraft.network.PacketBase; import dev.hilligans.ourcraft.client.audio.SoundBuffer; import dev.hilligans.ourcraft.client.audio.SoundEngine; import dev.hilligans.ourcraft.tag.CompoundNBTTag; @@ -39,7 +35,6 @@ import dev.hilligans.ourcraft.util.ThreadContext; import dev.hilligans.ourcraft.util.registry.Registry; import dev.hilligans.ourcraft.world.newworldsystem.ClientCubicWorld; -import dev.hilligans.ourcraft.world.newworldsystem.CubicWorld; import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import dev.hilligans.ourcraft.save.WorldLoader; import dev.hilligans.ourcraft.server.MultiPlayerServer; @@ -392,7 +387,7 @@ public void invoke(long window, double xoffset, double yoffset) { public static long timeSinceLastDraw = 0; public static float drawTime = 1000f * 1000000 / Settings.maxFps; - public void sendPacket(PacketBase packetBase) { + public void sendPacket(PacketBase packetBase) { network.sendPacket(packetBase); } diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java b/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java index e482c7f8..4d75002f 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java @@ -231,4 +231,9 @@ public PlayerEntity getPlayerEntity() { public ServerNetworkHandler getServerNetworkHandler() { return null; } + + @Override + public void disconnect(String reason) { + + } } diff --git a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContainer.java b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContainer.java index 7c7d686f..d31065ad 100644 --- a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContainer.java @@ -30,9 +30,6 @@ import java.lang.reflect.InvocationTargetException; import java.net.URLClassLoader; -import java.util.Arrays; -import java.util.List; -import java.util.function.Function; import java.util.function.Supplier; public class ModContainer { @@ -192,27 +189,27 @@ public void registerModel(IModel... models) { } @SafeVarargs - public final void registerPacket(Supplier... packets) { + public final void registerPacket(Supplier>... packets) { ModContainer self = this; - for(Supplier packet : packets) { + for(Supplier> packet : packets) { Protocol protocol = protocolRegistry.computeIfAbsent("ourcraft:Play", (s -> new Protocol(s.split(":")[1]).setSource(self))); protocol.register(packet); } } @SafeVarargs - public final void registerPacket(String protocolName, Supplier... packets) { + public final void registerPacket(String protocolName, Supplier>... packets) { ModContainer self = this; - for(Supplier packet : packets) { + for(Supplier> packet : packets) { Protocol protocol = protocolRegistry.computeIfAbsent(protocolName, (s -> new Protocol(s.split(":")[1]).setSource(self))); protocol.register(packet); } } @SafeVarargs - public final void registerPacket(String protocolName, int id, Supplier... packets) { + public final void registerPacket(String protocolName, int id, Supplier>... packets) { ModContainer self = this; - for(Supplier packet : packets) { + for(Supplier> packet : packets) { Protocol protocol = protocolRegistry.computeIfAbsent(protocolName, (s -> new Protocol(s.split(":")[1]).setSource(self))); protocol.register(packet,id); } diff --git a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java index 46ce99b7..356343de 100644 --- a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java +++ b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java @@ -1,42 +1,23 @@ package dev.hilligans.ourcraft.mod.handler.content; import dev.hilligans.ourcraft.GameInstance; -import dev.hilligans.ourcraft.biome.Biome; import dev.hilligans.ourcraft.block.Block; import dev.hilligans.ourcraft.client.Client; -import dev.hilligans.ourcraft.client.audio.SoundBuffer; -import dev.hilligans.ourcraft.client.input.Input; -import dev.hilligans.ourcraft.client.input.InputHandlerProvider; import dev.hilligans.ourcraft.client.rendering.ScreenBuilder; -import dev.hilligans.ourcraft.client.rendering.Texture; import dev.hilligans.ourcraft.client.rendering.graphics.*; -import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; -import dev.hilligans.ourcraft.client.rendering.graphics.api.ILayoutEngine; -import dev.hilligans.ourcraft.client.rendering.newrenderer.IModel; -import dev.hilligans.ourcraft.data.descriptors.Tag; import dev.hilligans.ourcraft.item.BlockItem; import dev.hilligans.ourcraft.item.Item; -import dev.hilligans.ourcraft.item.data.ToolLevel; import dev.hilligans.ourcraft.mod.handler.Mod; -import dev.hilligans.ourcraft.network.PacketBase; -import dev.hilligans.ourcraft.network.Protocol; -import dev.hilligans.ourcraft.resource.loaders.ResourceLoader; -import dev.hilligans.ourcraft.resource.registry.loaders.RegistryLoader; import dev.hilligans.ourcraft.save.WorldLoader; import dev.hilligans.ourcraft.util.IByteArray; import dev.hilligans.ourcraft.util.Settings; import dev.hilligans.ourcraft.util.Util; -import dev.hilligans.ourcraft.world.Feature; import org.json.JSONArray; import org.json.JSONObject; import java.net.URLClassLoader; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.function.Supplier; public class ModContent { diff --git a/src/main/java/dev/hilligans/ourcraft/network/ClientNetwork.java b/src/main/java/dev/hilligans/ourcraft/network/ClientNetwork.java index 5a9a4df9..380415ad 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/ClientNetwork.java +++ b/src/main/java/dev/hilligans/ourcraft/network/ClientNetwork.java @@ -15,7 +15,7 @@ public class ClientNetwork extends Network { public Client client; public GameInstance gameInstance; - public ArrayList packets = new ArrayList<>(); + public ArrayList> packets = new ArrayList<>(); public ClientNetwork(Protocol protocol) { super(protocol); @@ -53,7 +53,7 @@ public ClientNetwork debug(boolean debug) { } @Override - public void sendPacket(PacketBase packetBase) { + public void sendPacket(PacketBase packetBase) { // System.out.println("Sending packet:" + packetBase.getClass()); if(networkHandler != null && ((ClientNetworkHandler)networkHandler).enabled) { packetBase.packetId = sendProtocol.packetMap.get(packetBase.getClass()); @@ -64,13 +64,13 @@ public void sendPacket(PacketBase packetBase) { } public void flush() { - for (PacketBase packet : packets) { + for (PacketBase packet : packets) { ((ClientNetworkHandler) networkHandler).sendPacket(packet); } } @Override - public void sendPacketDirect(PacketBase packetBase) { + public void sendPacketDirect(PacketBase packetBase) { ((ClientNetworkHandler)networkHandler).sendPacket(packetBase); } diff --git a/src/main/java/dev/hilligans/ourcraft/network/ClientNetworkHandler.java b/src/main/java/dev/hilligans/ourcraft/network/ClientNetworkHandler.java index 3ced3af5..ba406b81 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/ClientNetworkHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/network/ClientNetworkHandler.java @@ -5,12 +5,11 @@ import io.netty.channel.*; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.function.Consumer; public class ClientNetworkHandler extends NetworkHandler { public ClientNetwork network; - public ConcurrentLinkedQueue packets = new ConcurrentLinkedQueue<>(); + public ConcurrentLinkedQueue> packets = new ConcurrentLinkedQueue<>(); public ClientNetworkHandler(ClientNetwork network) { this.network = network; @@ -35,7 +34,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { @Override protected void channelRead0(ChannelHandlerContext ctx, IPacketByteArray msg) throws Exception { - PacketBase packetBase = msg.createPacket(network.receiveProtocol); + PacketBase packetBase = msg.createPacket(network.receiveProtocol); packets.add(packetBase); } @@ -46,13 +45,9 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { } public void processPackets() { - PacketBase packetBase; + PacketBase packetBase; while((packetBase = packets.poll()) != null) { - if(packetBase instanceof PacketBaseNew packetBaseNew) { - packetBaseNew.handle(network.client); - } else { - packetBase.handle(); - } + packetBase.handle(network.client); } } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/IPacketByteArray.java b/src/main/java/dev/hilligans/ourcraft/network/IPacketByteArray.java index b9ee80e6..d010bbf3 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/IPacketByteArray.java +++ b/src/main/java/dev/hilligans/ourcraft/network/IPacketByteArray.java @@ -11,8 +11,8 @@ public interface IPacketByteArray extends IByteArray { void setOwner(ChannelHandlerContext ctx); ChannelHandlerContext getOwner(); - default PacketBase createPacket(Protocol protocol) { - PacketBase packetBase = protocol.packets.get(getPacketID()).getPacket(); + default PacketBase createPacket(Protocol protocol) { + PacketBase packetBase = protocol.packets.get(getPacketID()).getPacket(); packetBase.ctx = getOwner(); packetBase.decode(this); return packetBase; diff --git a/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java b/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java index ad03c759..915fdd99 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java @@ -33,6 +33,8 @@ public interface IServerPacketHandler extends IPacketHandler { ServerNetworkHandler getServerNetworkHandler(); + void disconnect(String reason); + default GameInstance getGameInstance() { return getServer().getGameInstance(); } @@ -41,7 +43,7 @@ default void handleDisconnect() { getWorld().removeEntity(getPlayerEntity().id, 0); } - default ChannelFuture sendPacket(PacketBase packetBase, ChannelHandlerContext ctx) { + default ChannelFuture sendPacket(PacketBase packetBase, ChannelHandlerContext ctx) { if(ServerNetworkHandler.debug) { return ctx.channel().writeAndFlush(new PacketTraceByteArray(packetBase)); } else { @@ -49,7 +51,7 @@ default ChannelFuture sendPacket(PacketBase packetBase, ChannelHandlerContext ct } } - default void sendPacket(PacketBase packetBase) { + default void sendPacket(PacketBase packetBase) { getServerNetworkHandler().sendPacketInternal(packetBase); } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/Network.java b/src/main/java/dev/hilligans/ourcraft/network/Network.java index 24248c23..9d352146 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/Network.java +++ b/src/main/java/dev/hilligans/ourcraft/network/Network.java @@ -54,9 +54,9 @@ public Network debug(boolean debug) { return this; } - public void sendPacket(PacketBase packetBase) {} + public void sendPacket(PacketBase packetBase) {} - public void sendPacketDirect(PacketBase packetBase) {} + public void sendPacketDirect(PacketBase packetBase) {} public void disconnect() { if(networkHandler instanceof ClientNetworkHandler) { diff --git a/src/main/java/dev/hilligans/ourcraft/network/NetworkHandler.java b/src/main/java/dev/hilligans/ourcraft/network/NetworkHandler.java index 1cbe032d..609aa4ce 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/NetworkHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/network/NetworkHandler.java @@ -23,7 +23,7 @@ public NetworkHandler setData(Channel channel, EventLoopGroup group, String ip, return this; } - public ChannelFuture sendPacket(PacketBase packetBase) { + public ChannelFuture sendPacket(PacketBase packetBase) { if(channel != null) { if(debug) { return channel.writeAndFlush(new PacketTraceByteArray(packetBase)); diff --git a/src/main/java/dev/hilligans/ourcraft/network/PacketBase.java b/src/main/java/dev/hilligans/ourcraft/network/PacketBase.java index 73deaaef..fe32caf2 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/PacketBase.java +++ b/src/main/java/dev/hilligans/ourcraft/network/PacketBase.java @@ -2,21 +2,24 @@ import io.netty.channel.ChannelHandlerContext; -public abstract class PacketBase { +public abstract class PacketBase { public ChannelHandlerContext ctx; - public int packetId; - public PacketBase(int id) { - this.packetId = id; - } - public PacketBase() {} + public PacketBase(int packetID) { + this.packetId = packetID; + } + public abstract void encode(IPacketByteArray packetData); public abstract void decode(IPacketByteArray packetData); - public abstract void handle(); + public abstract void handle(T t); + + public void handle(Object t) { + this.handle((T)t); + } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/PacketBaseNew.java b/src/main/java/dev/hilligans/ourcraft/network/PacketBaseNew.java deleted file mode 100644 index 793660af..00000000 --- a/src/main/java/dev/hilligans/ourcraft/network/PacketBaseNew.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.hilligans.ourcraft.network; - -public abstract class PacketBaseNew extends PacketBase { - - public PacketBaseNew() {} - - public PacketBaseNew(int packetID) { - super(packetID); - } - - - @Override - public void handle() { - //TODO implement and change over - } - - public abstract void handle(T t); - - public void handle(Object t) { - this.handle((T)t); - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/network/PacketByteArray.java b/src/main/java/dev/hilligans/ourcraft/network/PacketByteArray.java index 5478071e..5121ea49 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/PacketByteArray.java +++ b/src/main/java/dev/hilligans/ourcraft/network/PacketByteArray.java @@ -20,7 +20,7 @@ public PacketByteArray(ByteBuf byteBuf) { this.index = byteBuf.readableBytes(); } - public PacketByteArray(PacketBase packetBase) { + public PacketByteArray(PacketBase packetBase) { byteBuf = Unpooled.buffer(); packetID = (short) packetBase.packetId; packetBase.encode(this); diff --git a/src/main/java/dev/hilligans/ourcraft/network/PacketFetcher.java b/src/main/java/dev/hilligans/ourcraft/network/PacketFetcher.java index 1fdab6d6..3d4f2b32 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/PacketFetcher.java +++ b/src/main/java/dev/hilligans/ourcraft/network/PacketFetcher.java @@ -6,17 +6,17 @@ public class PacketFetcher { public int id; - public Supplier packet; - public Class packetClass; + public Supplier> packet; + public Class> packetClass; - public PacketFetcher(int id, Supplier packet) { + public PacketFetcher(int id, Supplier> packet) { this.packet = packet; this.id = id; - packetClass = (Class) packet.get().getClass(); + packetClass = (Class>) packet.get().getClass(); } - public PacketBase getPacket() { - PacketBase packetBase = packet.get(); + public PacketBase getPacket() { + PacketBase packetBase = packet.get(); packetBase.packetId = id; return packetBase; } diff --git a/src/main/java/dev/hilligans/ourcraft/network/Protocol.java b/src/main/java/dev/hilligans/ourcraft/network/Protocol.java index 228b2a3e..fba44771 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/Protocol.java +++ b/src/main/java/dev/hilligans/ourcraft/network/Protocol.java @@ -17,13 +17,13 @@ public class Protocol implements IRegistryElement { public String protocolName; public ArrayList packets = new ArrayList<>(); - public HashMap, Integer> packetMap = new HashMap<>(); + public HashMap>, Integer> packetMap = new HashMap<>(); public Int2BooleanOpenHashMap requiredIds = new Int2BooleanOpenHashMap(); public boolean compressed; public GameInstance gameInstance = Ourcraft.GAME_INSTANCE; public ModContainer source; - public void register(Supplier packet) { + public void register(Supplier> packet) { register(new PacketFetcher(packets.size(),packet)); } @@ -41,7 +41,7 @@ public void register(PacketFetcher packetFetcher) { packets.add(packetFetcher); } - public void register(Supplier packet, int id) { + public void register(Supplier> packet, int id) { register(new PacketFetcher(id, packet),id); } diff --git a/src/main/java/dev/hilligans/ourcraft/network/Protocols.java b/src/main/java/dev/hilligans/ourcraft/network/Protocols.java index 1306e8c7..d626f4eb 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/Protocols.java +++ b/src/main/java/dev/hilligans/ourcraft/network/Protocols.java @@ -23,7 +23,6 @@ public static void register(ModContainer modContent) { modContent.registerPacket(SChatMessage::new); modContent.registerPacket(CModifyStack::new); modContent.registerPacket(SUpdateContainer::new); - modContent.registerPacket(CActivateBlock::new); modContent.registerPacket(SOpenContainer::new); modContent.registerPacket(SUpdateInventory::new); modContent.registerPacket(CDropItem::new); @@ -34,7 +33,6 @@ public static void register(ModContainer modContent) { modContent.registerPacket(COpenScreen::new); modContent.registerPacket(SSendPlayerList::new); modContent.registerPacket(SSetGameMode::new); - modContent.registerPacket(SSendModContentPacket::new); modContent.registerPacket(CRequestContent::new); modContent.registerPacket("ourcraft:Auth", SAccountPacket::new); @@ -44,7 +42,6 @@ public static void register(ModContainer modContent) { modContent.registerPacket("ourcraft:Auth", CCreateAccount::new); modContent.registerPacket("ourcraft:Auth", CGetToken::new); - modContent.registerPacket("ourcraft:Auth", CTokenValid::new); modContent.registerPacket("ourcraft:Auth", CLogin::new); } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/ServerNetworkHandler.java b/src/main/java/dev/hilligans/ourcraft/network/ServerNetworkHandler.java index b3004be0..91584bcc 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/ServerNetworkHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/network/ServerNetworkHandler.java @@ -67,7 +67,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { @Override protected void channelRead0(ChannelHandlerContext ctx, IPacketByteArray msg) throws Exception { - PacketBase packetBase = msg.createPacket(network.receiveProtocol); + PacketBase packetBase = msg.createPacket(network.receiveProtocol); if(!(packetBase instanceof CHandshakePacket)) { if(mappedPlayerData.get(ctx.channel().id()) == null) { ctx.close(); @@ -75,15 +75,11 @@ protected void channelRead0(ChannelHandlerContext ctx, IPacketByteArray msg) thr } } try { - if (packetBase instanceof PacketBaseNew packetBaseNew) { - ServerPlayerData serverPlayerData = mappedPlayerData.get(ctx.channel().id()); - if(serverPlayerData == null) { - packetBaseNew.handle(this); - } else { - packetBaseNew.handle(serverPlayerData); - } - } else { - packetBase.handle(); + ServerPlayerData serverPlayerData = mappedPlayerData.get(ctx.channel().id()); + if(serverPlayerData == null) { + packetBase.handle(this); + } else { + packetBase.handle(serverPlayerData); } } catch (Exception e) { e.printStackTrace(); @@ -95,7 +91,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { ctx.close(); } - public void sendPacketInternal(PacketBase packetBase) { + public void sendPacketInternal(PacketBase packetBase) { for(int x = 0; x < channelIds.size(); x++) { Channel channel = channels.find(channelIds.get(x)); if(channel == null) { @@ -107,7 +103,7 @@ public void sendPacketInternal(PacketBase packetBase) { } } - public static ChannelFuture sendPacket(PacketBase packetBase, Channel channel) { + public static ChannelFuture sendPacket(PacketBase packetBase, Channel channel) { if(debug) { return channel.writeAndFlush(new PacketTraceByteArray(packetBase)); } else { @@ -115,15 +111,15 @@ public static ChannelFuture sendPacket(PacketBase packetBase, Channel channel) { } } - public ChannelFuture sendPacket(PacketBase packetBase, ChannelHandlerContext ctx) { + public ChannelFuture sendPacket(PacketBase packetBase, ChannelHandlerContext ctx) { return sendPacket(packetBase, ctx.channel()); } - public static ChannelFuture sendPacket1(PacketBase packetBase, ChannelHandlerContext ctx) { + public static ChannelFuture sendPacket1(PacketBase packetBase, ChannelHandlerContext ctx) { return sendPacket(packetBase, ctx.channel()); } - public static void sendPacketClose(PacketBase packetBase, ChannelHandlerContext ctx) { + public static void sendPacketClose(PacketBase packetBase, ChannelHandlerContext ctx) { try { sendPacket1(packetBase, ctx).addListeners((ChannelFutureListener) future -> { if (ctx.channel().isOpen()) { @@ -133,15 +129,15 @@ public static void sendPacketClose(PacketBase packetBase, ChannelHandlerContext } catch (Exception ignored) {} } - public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { + public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { sendPacket(packetBase, playerEntity.getPlayerData().getChannelId()); } - public void sendPacket(PacketBase packetBase, ChannelId channelId) { + public void sendPacket(PacketBase packetBase, ChannelId channelId) { sendPacket(packetBase, channels.find(channelId)); } - public void sendPacketExcept(PacketBase packetBase, ChannelHandlerContext ctx) { + public void sendPacketExcept(PacketBase packetBase, ChannelHandlerContext ctx) { for(int x = 0; x < channelIds.size(); x++) { Channel channel = channels.find(channelIds.get(x)); if(channel == null) { @@ -187,4 +183,9 @@ public IServer getServer() { public ServerNetworkHandler getServerNetworkHandler() { return this; } + + @Override + public void disconnect(String reason) { + + } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/debug/PacketTraceByteArray.java b/src/main/java/dev/hilligans/ourcraft/network/debug/PacketTraceByteArray.java index c9120208..e4c576f1 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/debug/PacketTraceByteArray.java +++ b/src/main/java/dev/hilligans/ourcraft/network/debug/PacketTraceByteArray.java @@ -10,7 +10,6 @@ import java.lang.foreign.MemorySegment; import java.lang.foreign.ValueLayout; -import java.nio.charset.StandardCharsets; public class PacketTraceByteArray implements IPacketByteArray { @@ -22,7 +21,7 @@ public class PacketTraceByteArray implements IPacketByteArray { public long universalPacketID; - public PacketTraceByteArray(PacketBase packetBase) { + public PacketTraceByteArray(PacketBase packetBase) { byteBuf = Unpooled.buffer(); packetID = (short) packetBase.packetId; packetBase.encode(this); @@ -187,8 +186,8 @@ public long getUniversalPacketID() { return universalPacketID; } - public PacketBase createPacket(Protocol protocol) { - PacketBase packetBase = protocol.packets.get(getPacketID()).getPacket(); + public PacketBase createPacket(Protocol protocol) { + PacketBase packetBase = protocol.packets.get(getPacketID()).getPacket(); packetBase.ctx = getOwner(); //System.out.println("Packet Trace:" + packetTrace.data); packetBase.decode(this); diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/InvalidFormatPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/InvalidFormatPacket.java index 221f9c82..3690e621 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/InvalidFormatPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/InvalidFormatPacket.java @@ -1,9 +1,10 @@ package dev.hilligans.ourcraft.network.packet; import dev.hilligans.ourcraft.network.IPacketByteArray; +import dev.hilligans.ourcraft.network.IPacketHandler; import dev.hilligans.ourcraft.network.PacketBase; -public class InvalidFormatPacket extends PacketBase { +public class InvalidFormatPacket extends PacketBase { public InvalidFormatPacket() { super(0); @@ -16,7 +17,7 @@ public void encode(IPacketByteArray packetData) {} public void decode(IPacketByteArray packetData) {} @Override - public void handle() { + public void handle(IPacketHandler iPacketHandler) { System.err.println("Received an invalid packet"); } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CCreateAccount.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CCreateAccount.java index 1b00c81e..b6813eac 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CCreateAccount.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CCreateAccount.java @@ -2,10 +2,11 @@ import dev.hilligans.ourcraft.network.IPacketByteArray; +import dev.hilligans.ourcraft.network.IPacketHandler; import dev.hilligans.ourcraft.network.PacketBase; -public class CCreateAccount extends PacketBase { +public class CCreateAccount extends PacketBase { String username; String password; @@ -37,7 +38,7 @@ public void encode(IPacketByteArray packetData) { public void decode(IPacketByteArray packetData) {} @Override - public void handle() {} - + public void handle(IPacketHandler iPacketHandler) { + } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CGetToken.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CGetToken.java index 27ff3393..d06d82f2 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CGetToken.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CGetToken.java @@ -1,9 +1,10 @@ package dev.hilligans.ourcraft.network.packet.auth; import dev.hilligans.ourcraft.network.IPacketByteArray; +import dev.hilligans.ourcraft.network.IPacketHandler; import dev.hilligans.ourcraft.network.PacketBase; -public class CGetToken extends PacketBase { +public class CGetToken extends PacketBase { String username; String loginToken; @@ -27,6 +28,9 @@ public void encode(IPacketByteArray packetData) { @Override public void decode(IPacketByteArray packetData) {} + @Override - public void handle() {} + public void handle(IPacketHandler iPacketHandler) { + + } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CLogin.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CLogin.java index 89ced41c..857e5bed 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CLogin.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CLogin.java @@ -1,9 +1,10 @@ package dev.hilligans.ourcraft.network.packet.auth; import dev.hilligans.ourcraft.network.IPacketByteArray; +import dev.hilligans.ourcraft.network.IServerPacketHandler; import dev.hilligans.ourcraft.network.PacketBase; -public class CLogin extends PacketBase { +public class CLogin extends PacketBase { String username; String password; @@ -34,7 +35,7 @@ public void decode(IPacketByteArray packetData) { } @Override - public void handle() { + public void handle(IServerPacketHandler iServerPacketHandler) { } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CTokenValid.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CTokenValid.java deleted file mode 100644 index 27638313..00000000 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/CTokenValid.java +++ /dev/null @@ -1,38 +0,0 @@ -package dev.hilligans.ourcraft.network.packet.auth; - -import dev.hilligans.ourcraft.network.IPacketByteArray; -import dev.hilligans.ourcraft.network.PacketBase; - -public class CTokenValid extends PacketBase { - - String username; - String token; - String ip; - String tempId; - - public CTokenValid() { - super(2); - } - - public CTokenValid(String username, String token, String ip, String tempId) { - super(2); - this.username = username; - this.token = token; - this.ip = ip; - this.tempId = tempId; - } - - @Override - public void encode(IPacketByteArray packetData) { - packetData.writeUTF16(username); - packetData.writeUTF16(token); - packetData.writeUTF16(ip); - packetData.writeUTF16(tempId); - } - - @Override - public void decode(IPacketByteArray packetData) {} - - @Override - public void handle() {} -} diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SAccountPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SAccountPacket.java index 1c0e5520..6143056a 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SAccountPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SAccountPacket.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.client.rendering.screens.AccountCreationScreen; import dev.hilligans.ourcraft.network.*; -public class SAccountPacket extends PacketBaseNew { +public class SAccountPacket extends PacketBase { String response; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendLoginToken.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendLoginToken.java index 47113eee..df8d0e39 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendLoginToken.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendLoginToken.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.network.*; -public class SSendLoginToken extends PacketBaseNew { +public class SSendLoginToken extends PacketBase { String token; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendToken.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendToken.java index e2a066f1..86007b70 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendToken.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/SSendToken.java @@ -2,7 +2,7 @@ import dev.hilligans.ourcraft.network.*; -public class SSendToken extends PacketBaseNew { +public class SSendToken extends PacketBase { String token; public SSendToken() { diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/STokenValid.java b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/STokenValid.java index 298fb175..7265cb80 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/auth/STokenValid.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/auth/STokenValid.java @@ -6,7 +6,7 @@ import dev.hilligans.ourcraft.ServerMain; import io.netty.channel.ChannelHandlerContext; -public class STokenValid extends PacketBaseNew { +public class STokenValid extends PacketBase { String username; String uuid; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateBlock.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateBlock.java deleted file mode 100644 index 3f952c38..00000000 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateBlock.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.hilligans.ourcraft.network.packet.client; - -import dev.hilligans.ourcraft.network.IPacketByteArray; -import dev.hilligans.ourcraft.network.PacketBase; - -public class CActivateBlock extends PacketBase { - public CActivateBlock() { - super(15); - } - - @Override - public void encode(IPacketByteArray packetData) { - - } - - @Override - public void decode(IPacketByteArray packetData) { - - } - - @Override - public void handle() { - - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateButton.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateButton.java index 6a418108..cc40642b 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateButton.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CActivateButton.java @@ -6,7 +6,7 @@ import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; import dev.hilligans.ourcraft.network.*; -public class CActivateButton extends PacketBaseNew { +public class CActivateButton extends PacketBase { short button; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CCloseScreen.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CCloseScreen.java index 82636bc9..8a343544 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CCloseScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CCloseScreen.java @@ -4,7 +4,7 @@ import dev.hilligans.ourcraft.network.*; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; -public class CCloseScreen extends PacketBaseNew { +public class CCloseScreen extends PacketBase { boolean newScreen = false; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CDropItem.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CDropItem.java index 85421d01..aab5d513 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CDropItem.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CDropItem.java @@ -2,7 +2,7 @@ import dev.hilligans.ourcraft.network.*; -public class CDropItem extends PacketBaseNew { +public class CDropItem extends PacketBase { short slot; byte count; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java index 04eea45c..7cc47146 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java @@ -17,7 +17,7 @@ import java.util.Random; -public class CHandshakePacket extends PacketBaseNew { +public class CHandshakePacket extends PacketBase { public int id; public String name; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CModifyStack.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CModifyStack.java index eaba7976..4715e229 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CModifyStack.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CModifyStack.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.network.*; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; -public class CModifyStack extends PacketBaseNew { +public class CModifyStack extends PacketBase { byte mode; short slot; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java index 9420ebf4..491d9eed 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java @@ -7,7 +7,7 @@ import dev.hilligans.ourcraft.network.*; import dev.hilligans.ourcraft.network.packet.server.SOpenContainer; -public class COpenScreen extends PacketBaseNew { +public class COpenScreen extends PacketBase { boolean containerScreen; short id; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestChunkPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestChunkPacket.java index ff59971f..e852b162 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestChunkPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestChunkPacket.java @@ -4,7 +4,7 @@ import dev.hilligans.ourcraft.network.packet.server.SSendChunkPacket; import dev.hilligans.ourcraft.world.newworldsystem.IChunk; -public class CRequestChunkPacket extends PacketBaseNew { +public class CRequestChunkPacket extends PacketBase { public int ChunkX; public int ChunkZ; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java index 22b10f30..a2249a21 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java @@ -1,17 +1,14 @@ package dev.hilligans.ourcraft.network.packet.client; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; -import dev.hilligans.ourcraft.entity.Entity; import dev.hilligans.ourcraft.entity.living.entities.PlayerEntity; import dev.hilligans.ourcraft.mod.handler.content.ModContent; import dev.hilligans.ourcraft.network.*; -import dev.hilligans.ourcraft.Ourcraft; -import dev.hilligans.ourcraft.ServerMain; import dev.hilligans.ourcraft.network.packet.server.*; import java.util.ArrayList; -public class CRequestContent extends PacketBaseNew { +public class CRequestContent extends PacketBase { ArrayList mods; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java index d6ca6e58..eb2831ca 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java @@ -8,7 +8,7 @@ import dev.hilligans.ourcraft.block.Blocks; import dev.hilligans.ourcraft.network.*; -public class CSendBlockChanges extends PacketBaseNew { +public class CSendBlockChanges extends PacketBase { int x; int y; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendMessage.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendMessage.java index cb95b22b..dda694d0 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendMessage.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendMessage.java @@ -6,7 +6,7 @@ import dev.hilligans.ourcraft.network.*; import dev.hilligans.ourcraft.network.packet.server.SChatMessage; -public class CSendMessage extends PacketBaseNew { +public class CSendMessage extends PacketBase { public String message; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUpdatePlayerPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUpdatePlayerPacket.java index 5d262480..934427df 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUpdatePlayerPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUpdatePlayerPacket.java @@ -6,7 +6,7 @@ import dev.hilligans.ourcraft.network.packet.server.SUpdateEntityPacket; import dev.hilligans.ourcraft.server.IServer; -public class CUpdatePlayerPacket extends PacketBaseNew { +public class CUpdatePlayerPacket extends PacketBase { double x; double y; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java index 0b41c3d8..44c94159 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java @@ -1,13 +1,10 @@ package dev.hilligans.ourcraft.network.packet.client; -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; import dev.hilligans.ourcraft.data.other.BlockPos; -import dev.hilligans.ourcraft.item.ItemStack; import dev.hilligans.ourcraft.network.*; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; -import dev.hilligans.ourcraft.ServerMain; -public class CUseItem extends PacketBaseNew { +public class CUseItem extends PacketBase { byte slot; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SChatMessage.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SChatMessage.java index 990e462c..f922aa20 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SChatMessage.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SChatMessage.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.network.*; -public class SChatMessage extends PacketBaseNew { +public class SChatMessage extends PacketBase { String message; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SCreateEntityPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SCreateEntityPacket.java index 2da43fe8..52ded843 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SCreateEntityPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SCreateEntityPacket.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.entity.Entity; import dev.hilligans.ourcraft.network.*; -public class SCreateEntityPacket extends PacketBaseNew { +public class SCreateEntityPacket extends PacketBase { int entityType; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SDisconnectPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SDisconnectPacket.java index 9240cab4..333a24d0 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SDisconnectPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SDisconnectPacket.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.client.rendering.screens.DisconnectScreen; import dev.hilligans.ourcraft.network.*; -public class SDisconnectPacket extends PacketBaseNew { +public class SDisconnectPacket extends PacketBase { public SDisconnectPacket() { super(22); diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java index 69d76db7..185265cb 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java @@ -3,14 +3,13 @@ import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.network.*; -import dev.hilligans.ourcraft.Ourcraft; import dev.hilligans.ourcraft.util.Settings; import java.io.File; import java.util.ArrayList; import java.util.Arrays; -public class SHandshakePacket extends PacketBaseNew { +public class SHandshakePacket extends PacketBase { public int playerId; public String[] mods; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java index 06863409..6ec8e1fe 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java @@ -4,7 +4,7 @@ import dev.hilligans.ourcraft.container.Slot; import dev.hilligans.ourcraft.network.*; -public class SOpenContainer extends PacketBaseNew { +public class SOpenContainer extends PacketBase { public short containerID; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SRemoveEntityPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SRemoveEntityPacket.java index b101e89a..27d59681 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SRemoveEntityPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SRemoveEntityPacket.java @@ -2,7 +2,7 @@ import dev.hilligans.ourcraft.network.*; -public class SRemoveEntityPacket extends PacketBaseNew { +public class SRemoveEntityPacket extends PacketBase { int id; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java index 2fe43e5f..2f7993d8 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java @@ -1,12 +1,11 @@ package dev.hilligans.ourcraft.network.packet.server; import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.block.Blocks; import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.data.other.blockstates.DataBlockState; import dev.hilligans.ourcraft.network.*; -public class SSendBlockChanges extends PacketBaseNew { +public class SSendBlockChanges extends PacketBase { int x; int y; int z; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendChunkPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendChunkPacket.java index ada5db32..ebf96ed4 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendChunkPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendChunkPacket.java @@ -5,7 +5,7 @@ import dev.hilligans.ourcraft.world.newworldsystem.CubicChunk; import dev.hilligans.ourcraft.world.newworldsystem.IChunk; -public class SSendChunkPacket extends PacketBaseNew { +public class SSendChunkPacket extends PacketBase { public byte mode; public IChunk newChunk; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java deleted file mode 100644 index 403887ba..00000000 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java +++ /dev/null @@ -1,36 +0,0 @@ -package dev.hilligans.ourcraft.network.packet.server; - -import dev.hilligans.ourcraft.mod.handler.content.ModContent; -import dev.hilligans.ourcraft.network.IPacketByteArray; -import dev.hilligans.ourcraft.network.PacketBase; -import dev.hilligans.ourcraft.Ourcraft; - -public class SSendModContentPacket extends PacketBase { - - ModContent modContent; - - public SSendModContentPacket() { - super(26); - } - - public SSendModContentPacket(ModContent modContent) { - this(); - this.modContent = modContent; - } - - @Override - public void encode(IPacketByteArray packetData) { - modContent.putData(packetData); - } - - @Override - public void decode(IPacketByteArray packetData) { - //modContent = new ModContent(packetData, Ourcraft.GAME_INSTANCE); - } - - @Override - public void handle() { - //Ourcraft.GAME_INSTANCE.CONTENT_PACK.putMod(modContent); - //Ourcraft.GAME_INSTANCE.CONTENT_PACK.generateData(); - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendPlayerList.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendPlayerList.java index 09c1c2e3..5670f782 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendPlayerList.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendPlayerList.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.data.other.PlayerList; import dev.hilligans.ourcraft.network.*; -public class SSendPlayerList extends PacketBaseNew { +public class SSendPlayerList extends PacketBase { byte mode; String[] players; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSetGameMode.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSetGameMode.java index c6579666..425149c3 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSetGameMode.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSetGameMode.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.network.*; -public class SSetGameMode extends PacketBaseNew { +public class SSetGameMode extends PacketBase { int id; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateContainer.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateContainer.java index 7b8c83c3..794f2d9e 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateContainer.java @@ -4,7 +4,7 @@ import dev.hilligans.ourcraft.item.ItemStack; import dev.hilligans.ourcraft.network.*; -public class SUpdateContainer extends PacketBaseNew { +public class SUpdateContainer extends PacketBase { short slot; ItemStack itemStack; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java index 3d8aa61e..e289cd99 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.entity.Entity; import dev.hilligans.ourcraft.network.*; -public class SUpdateEntityPacket extends PacketBaseNew { +public class SUpdateEntityPacket extends PacketBase { float x; float y; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateInventory.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateInventory.java index 71ad9a38..9dcf9b0f 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateInventory.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateInventory.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.data.other.Inventory; import dev.hilligans.ourcraft.network.*; -public class SUpdateInventory extends PacketBaseNew { +public class SUpdateInventory extends PacketBase { Inventory inventory; diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdatePlayer.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdatePlayer.java index 2e495479..b025d7e6 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdatePlayer.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdatePlayer.java @@ -2,7 +2,7 @@ import dev.hilligans.ourcraft.network.*; -public class SUpdatePlayer extends PacketBaseNew { +public class SUpdatePlayer extends PacketBase { float x; float y; diff --git a/src/main/java/dev/hilligans/ourcraft/server/IServer.java b/src/main/java/dev/hilligans/ourcraft/server/IServer.java index fe3c1ff2..129a1751 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/IServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/IServer.java @@ -23,9 +23,9 @@ public interface IServer { ServerNetworkHandler getServerNetworkHandler(); - void sendPacket(PacketBase packetBase); + void sendPacket(PacketBase packetBase); - void sendPacket(PacketBase packetBase, PlayerEntity playerEntity); + void sendPacket(PacketBase packetBase, PlayerEntity playerEntity); GameInstance getGameInstance(); diff --git a/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java b/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java index 8fd7924b..d5ac8e03 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java @@ -70,14 +70,14 @@ public ServerNetworkHandler getServerNetworkHandler() { } @Override - public void sendPacket(PacketBase packetBase) { + public void sendPacket(PacketBase packetBase) { // PacketData packetData = new PacketData(packetBase); // PacketBase packet = packetData.createPacket(); // packet.handle(); } @Override - public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { + public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { sendPacket(packetBase); } diff --git a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java index 2fe9e7f6..3dd6f23e 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java @@ -7,15 +7,13 @@ import dev.hilligans.ourcraft.entity.living.entities.PlayerEntity; import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.mod.handler.events.server.MultiPlayerServerStartEvent; +import dev.hilligans.ourcraft.network.PacketBase; import dev.hilligans.ourcraft.network.packet.client.CHandshakePacket; import dev.hilligans.ourcraft.network.packet.server.SDisconnectPacket; -import dev.hilligans.ourcraft.network.PacketBase; import dev.hilligans.ourcraft.network.ServerNetwork; import dev.hilligans.ourcraft.network.ServerNetworkHandler; import dev.hilligans.ourcraft.Ourcraft; -import dev.hilligans.ourcraft.ServerMain; import dev.hilligans.ourcraft.world.newworldsystem.IServerWorld; -import dev.hilligans.ourcraft.util.ConsoleReader; import dev.hilligans.ourcraft.util.NamedThreadFactory; import dev.hilligans.ourcraft.util.Settings; import io.netty.channel.ChannelHandlerContext; @@ -97,11 +95,11 @@ public ServerNetworkHandler getServerNetworkHandler() { return (ServerNetworkHandler) serverNetwork.networkHandler; } - public void sendPacket(PacketBase packetBase) { + public void sendPacket(PacketBase packetBase) { getServerNetworkHandler().sendPacketInternal(packetBase); } - public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { + public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { getServerNetworkHandler().sendPacket(packetBase,playerEntity); } diff --git a/src/main/java/dev/hilligans/ourcraft/util/IByteArray.java b/src/main/java/dev/hilligans/ourcraft/util/IByteArray.java index 526bdb8e..df150351 100644 --- a/src/main/java/dev/hilligans/ourcraft/util/IByteArray.java +++ b/src/main/java/dev/hilligans/ourcraft/util/IByteArray.java @@ -83,6 +83,18 @@ default long readVarLong() { return result; } + default int readUByte() { + return Byte.toUnsignedInt(readByte()); + } + + default int readUShort() { + return Short.toUnsignedInt(readShort()); + } + + default long readUInt() { + return Integer.toUnsignedLong(readInt()); + } + default boolean[] readBooleans(int count) { boolean[] values = new boolean[count]; byte val = 0; @@ -278,6 +290,18 @@ default void writeVarLong(long value) { } } + default void writeUByte(int value) { + writeByte((byte)value); + } + + default void writeUShort(int value) { + writeShort((short)value); + } + + default void writeUInt(long value) { + writeInt((int)value); + } + default void writeBooleans(boolean[] values) { writeVarInt(values.length); byte val = 0;