From bc0cb10406660228cea9f65d16b0bca4a7e3ae2f Mon Sep 17 00:00:00 2001 From: Matsv Date: Sat, 19 Jan 2019 12:11:11 +0100 Subject: [PATCH] Handle entity/dimension tracking correctly --- .../Protocol1_12_2To1_13.java | 21 ------ .../packets/EntityPackets1_13.java | 71 ++++++++++++++++++- 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index 43492ebb..cc14bb23 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -23,7 +23,6 @@ import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; -import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -61,23 +60,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x24, 0x22, cancel()); // Spawn Particle TODO MODIFIED - out(State.PLAY, 0x25, 0x23, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Entity ID - map(Type.UNSIGNED_BYTE); // 1 - Gamemode - map(Type.INT); // 2 - Dimension - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 1); - clientChunks.setEnvironment(dimensionId); - } - }); - } - }); // Join Game out(State.PLAY, 0x27, 0x25); // Entity out(State.PLAY, 0x28, 0x26); // Entity Relative Move out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move @@ -92,17 +74,14 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { out(State.PLAY, 0x32, 0x2F); // Player Position And Look (clientbound) out(State.PLAY, 0x33, 0x30); // Use Bed out(State.PLAY, 0x34, 0x31, cancel()); // Unlock Recipes TODO MODIFIED - out(State.PLAY, 0x35, 0x32); // Destroy Entities out(State.PLAY, 0x36, 0x33); // Remove Entity Effect out(State.PLAY, 0x37, 0x34); // Resource Pack Send - out(State.PLAY, 0x38, 0x35); // Respawn out(State.PLAY, 0x39, 0x36); // Entity Head Look out(State.PLAY, 0x3A, 0x37); // Select Advancement Tab out(State.PLAY, 0x3B, 0x38); // World Border out(State.PLAY, 0x3C, 0x39); // Camera out(State.PLAY, 0x3D, 0x3A); // Held Item Change (clientbound) out(State.PLAY, 0x3E, 0x3B); // Display Scoreboard - out(State.PLAY, 0x3F, 0x3C, cancel()); // Entity Metadata out(State.PLAY, 0x40, 0x3D); // Attach Entity out(State.PLAY, 0x41, 0x3E); // Entity Velocity out(State.PLAY, 0x43, 0x40); // Set Experience diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index a6ea3e25..e677ae57 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.Optional; @@ -133,6 +134,7 @@ public class EntityPackets1_13 extends EntityRewriter { map(Type.SHORT); map(Type.SHORT); map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); + handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -219,7 +221,74 @@ public class EntityPackets1_13 extends EntityRewriter { } }); - } + // Join game + protocol.out(State.PLAY, 0x25, 0x23, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Entity ID + map(Type.UNSIGNED_BYTE); // 1 - Gamemode + map(Type.INT); // 2 - Dimension + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 1); + clientChunks.setEnvironment(dimensionId); + } + }); + } + }); + + + // Respawn Packet (save dimension id) + protocol.registerOutgoing(State.PLAY, 0x38, 0x35, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Dimension ID + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 0); + clientWorld.setEnvironment(dimensionId); + } + }); + } + }); + + // Destroy Entities Packet + protocol.registerOutgoing(State.PLAY, 0x35, 0x32, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT_ARRAY); // 0 - Entity IDS + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) + getEntityTracker(wrapper.user()).removeEntity(entity); + } + }); + } + }); + + // Entity Metadata packet + protocol.registerOutgoing(State.PLAY, 0x3F, 0x3C, new PacketRemapper() { + @Override + public void registerMap() { + // TODO HANDLE + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.cancel(); + } + }); + } + }); + } @Override protected void registerRewrites() {