diff --git a/src/main/java/config/Version.java b/src/main/java/config/Version.java index 5f5eec4..fcea1f8 100644 --- a/src/main/java/config/Version.java +++ b/src/main/java/config/Version.java @@ -13,6 +13,7 @@ public enum Version { V1_19_3(761, 3218), V1_20(763, 3463), V1_20_2(764, 3578), + V1_20_3(765, 3698), ANY(0, 0); public final int dataVersion; diff --git a/src/main/java/game/data/dimension/DimensionCodec.java b/src/main/java/game/data/dimension/DimensionCodec.java index a38da1b..5c7ea40 100644 --- a/src/main/java/game/data/dimension/DimensionCodec.java +++ b/src/main/java/game/data/dimension/DimensionCodec.java @@ -4,7 +4,7 @@ import game.data.chunk.palette.StateProvider; import se.llbit.nbt.*; -import java.io.*; +import java.io.IOException; import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; @@ -16,6 +16,7 @@ */ public class DimensionCodec { public static final Gson GSON; + static { /* * To convert the properties to JSON, we need to register adapters so that GSON knows how to turn our NBT object @@ -56,6 +57,7 @@ public class DimensionCodec { private final Map dimensionTypesByHash; private final Map dimensionTypesByName; private final Map biomes; + private DimensionCodec() { this.dimensions = new HashMap<>(); this.dimensionTypesByHash = new HashMap<>(); @@ -103,7 +105,7 @@ private void readDimensionTypes(ListTag dimensionList) { String[] parts = identifier.split(":"); String namespace = parts[0]; String name = parts[1]; - + DimensionType type = new DimensionType(namespace, name, d); this.dimensionTypesByHash.put(type.getSignature(), type); this.dimensionTypesByName.put(type.getName(), type); diff --git a/src/main/java/game/protocol/ConfigurationProtocol.java b/src/main/java/game/protocol/ConfigurationProtocol.java index 4e11963..2bbfa1d 100644 --- a/src/main/java/game/protocol/ConfigurationProtocol.java +++ b/src/main/java/game/protocol/ConfigurationProtocol.java @@ -1,5 +1,8 @@ package game.protocol; +import config.Config; +import config.Version; + import java.util.HashMap; import java.util.Map; @@ -11,7 +14,13 @@ public ConfigurationProtocol() { clientBound = new HashMap<>(); serverBound = new HashMap<>(); - serverBound.put(0x03, "FinishConfiguration"); + if (Config.versionReporter().isAtLeast(Version.V1_20_2)) { + serverBound.put(0x02, "FinishConfiguration"); + + clientBound.put(0x05, "RegistryData"); + } else { + serverBound.put(0x03, "FinishConfiguration"); + } } @Override diff --git a/src/main/java/packets/handler/ClientBoundConfigurationPacketHandler.java b/src/main/java/packets/handler/ClientBoundConfigurationPacketHandler.java index 48af430..2166ae5 100644 --- a/src/main/java/packets/handler/ClientBoundConfigurationPacketHandler.java +++ b/src/main/java/packets/handler/ClientBoundConfigurationPacketHandler.java @@ -1,17 +1,31 @@ package packets.handler; +import config.Config; +import config.Option; +import config.Version; +import packets.handler.version.ClientBoundConfigurationPacketHandler_1_20_2; +import proxy.ConnectionManager; + import java.util.HashMap; import java.util.Map; -import proxy.ConnectionManager; public class ClientBoundConfigurationPacketHandler extends PacketHandler { + private final HashMap operations = new HashMap<>(); + public ClientBoundConfigurationPacketHandler(ConnectionManager connectionManager) { super(connectionManager); } + public static PacketHandler of(ConnectionManager connectionManager) { + return Config.versionReporter().select(PacketHandler.class, + Option.of(Version.V1_20_2, () -> new ClientBoundConfigurationPacketHandler_1_20_2(connectionManager)), + Option.of(Version.ANY, () -> new ClientBoundConfigurationPacketHandler(connectionManager)) + ); + } + @Override public Map getOperators() { - return new HashMap<>(); + return operations; } @Override diff --git a/src/main/java/packets/handler/PacketHandler.java b/src/main/java/packets/handler/PacketHandler.java index 000bf26..faf1b64 100644 --- a/src/main/java/packets/handler/PacketHandler.java +++ b/src/main/java/packets/handler/PacketHandler.java @@ -6,8 +6,8 @@ import packets.DataTypeProvider; import proxy.ConnectionManager; -import java.util.Map; import javax.naming.SizeLimitExceededException; +import java.util.Map; /** * Family of classes to handle incoming packets and perform appropriate actions based on the packet type and contents. @@ -34,6 +34,7 @@ protected ConnectionManager getConnectionManager() { /** * Build the given packet, will generate a type provider to parse the contents of the packages to real values. Will * determine if the packet is to be forwarded using its return value. + * * @param size the size of the packet to build * @return true if the packet should be forwarded, otherwise false. */ @@ -58,6 +59,7 @@ public final boolean handle(int size) { } public abstract Map getOperators(); + public abstract boolean isClientBound(); public void setReader(DataProvider reader) { diff --git a/src/main/java/packets/handler/ServerBoundGamePacketHandler.java b/src/main/java/packets/handler/ServerBoundGamePacketHandler.java index 4d4038e..c941c95 100644 --- a/src/main/java/packets/handler/ServerBoundGamePacketHandler.java +++ b/src/main/java/packets/handler/ServerBoundGamePacketHandler.java @@ -28,6 +28,8 @@ public ServerBoundGamePacketHandler(ConnectionManager connectionManager) { PacketOperator updatePlayerRotation = provider -> { double yaw = provider.readFloat() % 360; + provider.readFloat(); // pitch + provider.readBoolean(); // on ground WorldManager.getInstance().setPlayerRotation(yaw); return true; }; diff --git a/src/main/java/packets/handler/version/ClientBoundConfigurationPacketHandler_1_20_2.java b/src/main/java/packets/handler/version/ClientBoundConfigurationPacketHandler_1_20_2.java new file mode 100644 index 0000000..9bb313b --- /dev/null +++ b/src/main/java/packets/handler/version/ClientBoundConfigurationPacketHandler_1_20_2.java @@ -0,0 +1,26 @@ +package packets.handler.version; + +import game.data.WorldManager; +import game.data.dimension.DimensionCodec; +import packets.handler.ClientBoundConfigurationPacketHandler; +import packets.handler.PacketOperator; +import proxy.ConnectionManager; +import se.llbit.nbt.SpecificTag; + +import java.util.Map; + +public class ClientBoundConfigurationPacketHandler_1_20_2 extends ClientBoundConfigurationPacketHandler { + public ClientBoundConfigurationPacketHandler_1_20_2(ConnectionManager connectionManager) { + super(connectionManager); + + Map operators = getOperators(); + WorldManager worldManager = WorldManager.getInstance(); + + operators.put("RegistryData", provider -> { + SpecificTag registryData = provider.readNbtTag(); + worldManager.setDimensionCodec(DimensionCodec.fromNbt(registryData)); + + return true; + }); + } +} diff --git a/src/main/java/packets/handler/version/ClientBoundGamePacketHandler_1_20_2.java b/src/main/java/packets/handler/version/ClientBoundGamePacketHandler_1_20_2.java index 9b52146..4599deb 100644 --- a/src/main/java/packets/handler/version/ClientBoundGamePacketHandler_1_20_2.java +++ b/src/main/java/packets/handler/version/ClientBoundGamePacketHandler_1_20_2.java @@ -21,7 +21,6 @@ public ClientBoundGamePacketHandler_1_20_2(ConnectionManager connectionManager) super(connectionManager); Protocol protocol = Config.versionReporter().getProtocol(); - WorldManager worldManager = WorldManager.getInstance(); EntityRegistry entityRegistry = WorldManager.getInstance().getEntityRegistry(); Map operators = getOperators(); @@ -68,23 +67,5 @@ public ClientBoundGamePacketHandler_1_20_2(ConnectionManager connectionManager) entityRegistry.updatePlayerAction(provider); return true; }); - - operators.put("RegistryData", provider -> { - try { - SpecificTag dimensionCodec = provider.readNbtTag(); - if (!(dimensionCodec instanceof CompoundTag)) { - return true; - } - for (var nbt : ((CompoundTag) dimensionCodec)) { - if (nbt.name.equals("minecraft:dimension_type")) { - worldManager.setDimensionCodec(DimensionCodec.fromNbt(dimensionCodec)); - break; - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return true; - }); } } \ No newline at end of file diff --git a/src/main/java/proxy/ConnectionManager.java b/src/main/java/proxy/ConnectionManager.java index 9d9ee8e..9cfe5af 100644 --- a/src/main/java/proxy/ConnectionManager.java +++ b/src/main/java/proxy/ConnectionManager.java @@ -52,7 +52,7 @@ public void setMode(NetworkMode mode) { case CONFIGURATION: PacketHandler.setProtocol(new ConfigurationProtocol()); serverBoundDataReader.setPacketHandler(new ServerBoundConfigurationPacketHandler(this)); - clientBoundDataReader.setPacketHandler(new ClientBoundConfigurationPacketHandler(this)); + clientBoundDataReader.setPacketHandler(ClientBoundConfigurationPacketHandler.of(this)); break; } } diff --git a/src/main/resources/protocol-versions.json b/src/main/resources/protocol-versions.json index c47d56c..31e9d17 100644 --- a/src/main/resources/protocol-versions.json +++ b/src/main/resources/protocol-versions.json @@ -405,8 +405,6 @@ "dataVersion": 3578, "clientBound": { "0x01": "AddEntity", - "0x05": "RegistryData", - "0x3c": "UpdatePlayerInfo", "0x07": "BlockEntityData", "0x09": "BlockUpdate", "0x12": "ContainerClose", @@ -420,6 +418,7 @@ "0x2c": "MoveEntityPos", "0x2d": "MoveEntityPosRot", "0x31": "OpenScreen", + "0x3c": "UpdatePlayerInfo", "0x40": "RemoveEntities", "0x43": "Respawn", "0x45": "SectionBlocksUpdate", @@ -441,6 +440,47 @@ "0x34": "UseItemOn", "0x35": "UseItem" } + }, + "765": { + "version": "1.20.3", + "dataVersion": 3698, + "clientBound": { + "0x01": "AddEntity", + "0x07": "BlockEntityData", + "0x09": "BlockUpdate", + "0x12": "ContainerClose", + "0x13": "ContainerSetContent", + "0x1f": "ForgetLevelChunk", + "0x25": "LevelChunkWithLight", + "0x28": "LightUpdate", + "0x29": "Login", + "0x2a": "MapItemData", + "0x2b": "TradeList", + "0x2c": "MoveEntityPos", + "0x2d": "MoveEntityPosRot", + "0x31": "OpenScreen", + "0x3c": "UpdatePlayerInfo", + "0x40": "RemoveEntities", + "0x45": "Respawn", + "0x47": "SectionBlocksUpdate", + "0x53": "SetChunkCacheRadius", + "0x56": "SetEntityData", + "0x59": "SetEquipment", + "0x69": "SystemChat", + "0x6d": "TeleportEntity" + }, + "serverBound": { + "0x0b": "ConfigurationAcknowledged", + "0x0c": "ContainerClose", + "0x12": "Interact", + "0x16": "MovePlayerPos", + "0x18": "MovePlayerPosRot", + "0x19": "MovePlayerRot", + "0x1b": "MoveVehicle", + "0x2d": "SetCommandBlock", + "0x35": "UseItemOn", + "0x36": "UseItem" + } } } } \ No newline at end of file