From 73b8a2fc9a5b1ee0764659af29c57d46f46da743 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 10 Aug 2016 18:54:56 +0100 Subject: [PATCH] Start support for entity type id tracking --- .../ProtocolSnapshotTo1_10.java | 47 ++++++++++++++++++- .../storage/EntityTracker.java | 21 +++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/storage/EntityTracker.java diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/ProtocolSnapshotTo1_10.java b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/ProtocolSnapshotTo1_10.java index 89a8c67a3..b1c0906ba 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/ProtocolSnapshotTo1_10.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/ProtocolSnapshotTo1_10.java @@ -3,10 +3,13 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_10; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.version.Types1_9; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage.EntityTracker; public class ProtocolSnapshotTo1_10 extends Protocol { @Override @@ -18,7 +21,24 @@ public class ProtocolSnapshotTo1_10 extends Protocol { map(Type.VAR_INT); // 0 - Entity ID map(Type.UUID); // 1 - Entity UUID map(Type.UNSIGNED_BYTE, Type.VAR_INT); // 2 - Entity Type + map(Type.DOUBLE); // 3 - X + map(Type.DOUBLE); // 4 - Y + map(Type.DOUBLE); // 5 - Z + map(Type.BYTE); // 6 - Yaw + map(Type.BYTE); // 7 - Pitch + map(Type.BYTE); // 8 - Head Pitch + map(Type.SHORT); // 9 - Velocity X + map(Type.SHORT); // 10 - Velocity Y + map(Type.SHORT); // 11 - Velocity Z + map(Types1_9.METADATA_LIST); // 12 - Metadata + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + // Register Type ID + wrapper.user().get(EntityTracker.class).getClientEntityTypes().put(wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 1)); + } + }); } }); @@ -37,10 +57,35 @@ public class ProtocolSnapshotTo1_10 extends Protocol { }); } }); + + // Metadata packet + registerOutgoing(State.PLAY, 0x39, 0x39, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Types1_9.METADATA_LIST); // 1 - Metadata list + } + }); + + // Destroy entities + registerOutgoing(State.PLAY, 0x30, 0x30, 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)) + wrapper.user().get(EntityTracker.class).removeEntity(entity); + } + }); + } + }); } @Override public void init(UserConnection userConnection) { - + userConnection.put(new EntityTracker(userConnection)); } } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/storage/EntityTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/storage/EntityTracker.java new file mode 100644 index 000000000..d4bbe73ce --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_10/storage/EntityTracker.java @@ -0,0 +1,21 @@ +package us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage; + +import lombok.Getter; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Getter +public class EntityTracker extends StoredObject{ + private final Map clientEntityTypes = new ConcurrentHashMap<>(); + + public EntityTracker(UserConnection user) { + super(user); + } + + public void removeEntity(Integer entityID) { + clientEntityTypes.remove(entityID); + } +}