From 5f3630205780da78dfca5713a492df1b3970bde4 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 8 Nov 2017 18:12:15 +0000 Subject: [PATCH] Base 17w45a update (missing areaeffectcloud remap) --- bukkit/pom.xml | 2 +- bungee/pom.xml | 4 +- common/pom.xml | 2 +- .../api/protocol/ProtocolVersion.java | 2 +- .../Protocol1_12_1TO1_12.java | 2 - .../MetadataRewriter.java | 34 ++++ .../ProtocolSnapshotTo1_12_2.java | 164 +++++++++++++++++- .../storage/EntityTracker.java | 36 ++++ jar/pom.xml | 2 +- pom.xml | 2 +- sponge-legacy/pom.xml | 2 +- sponge/pom.xml | 2 +- 12 files changed, 242 insertions(+), 12 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/storage/EntityTracker.java diff --git a/bukkit/pom.xml b/bukkit/pom.xml index f4cb332ed..73494e248 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w43b + 1.4.0-17w45a 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 097fc68ba..eef022a1b 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w43b + 1.4.0-17w45a 4.0.0 @@ -37,7 +37,7 @@ us.myles viaversion-common - 1.4.0-17w43b + 1.4.0-17w45a \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml index b89a02afc..d68bcc32c 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w43b + 1.4.0-17w45a 4.0.0 diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 2f32dd5d5..b88afa618 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -62,7 +62,7 @@ public class ProtocolVersion { register(v1_12 = new ProtocolVersion(335, "1.12")); register(v1_12_1 = new ProtocolVersion(338, "1.12.1")); register(v1_12_2 = new ProtocolVersion(340, "1.12.2")); - register(v1_13 = new ProtocolVersion(342, "17w43b")); + register(v1_13 = new ProtocolVersion(343, "17w45a")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1TO1_12.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1TO1_12.java index a70891f8e..21812565a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1TO1_12.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1TO1_12.java @@ -86,8 +86,6 @@ public class Protocol1_12_1TO1_12 extends Protocol { }); } }); - - } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java new file mode 100644 index 000000000..7cc0a487b --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MetadataRewriter.java @@ -0,0 +1,34 @@ +package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2; + +import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_12Types; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; + +import java.util.ArrayList; +import java.util.List; + +public class MetadataRewriter { + public static void handleMetadata(int entityId, Entity1_12Types.EntityType type, List metadatas, UserConnection connection) { + + for (Metadata metadata : new ArrayList<>(metadatas)) { + try { + if (type.is(Entity1_12Types.EntityType.AREA_EFFECT_CLOUD)) { + if (metadata.getId() == 10 || metadata.getId() == 11) { + // TODO: AreaEffectCloud has lost 2 integers and gained "ef" + // Will be implemented when more info is known + metadata.setId(13); + } + } + } catch (Exception e) { + metadatas.remove(metadata); + if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); + Via.getPlatform().getLogger().warning("Metadata: " + metadata); + e.printStackTrace(); + } + } + } + + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java index 8a6e2dcef..fa15a4cff 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java @@ -1,16 +1,178 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2; +import com.google.common.base.Optional; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_12Types; 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.type.Type; +import us.myles.ViaVersion.api.type.types.version.Types1_12; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage.EntityTracker; // Development of 1.13 support! public class ProtocolSnapshotTo1_12_2 extends Protocol { @Override protected void registerPackets() { + // Outgoing packets + // Spawn Object + registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity id + map(Type.UUID); // 1 - UUID + map(Type.BYTE); // 2 - Type + + // Track Entity + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + + int entityId = wrapper.get(Type.VAR_INT, 0); + byte type = wrapper.get(Type.BYTE, 0); + + Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, true); + + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + } + }); + } + }); + + // Spawn mob packet + registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Entity UUID + map(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_12.METADATA_LIST); // 12 - Metadata + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + // Change Type :) + int type = wrapper.get(Type.VAR_INT, 1); + + Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false); + // Register Type ID + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + + registerOutgoing(State.PLAY, 0xF, 0xE); + // 0xE Tab complete was removed + registerOutgoing(State.PLAY, 0xE, 0xE, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.cancel(); + } + }); + } + }); + registerOutgoing(State.PLAY, 0x10, 0xF); + // New packet 0x10, empty packet, possible placeholder for new command system? + // Destroy entities + registerOutgoing(State.PLAY, 0x32, 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)) + wrapper.user().get(EntityTracker.class).removeEntity(entity); + } + }); + } + }); + // Metadata packet + registerOutgoing(State.PLAY, 0x3c, 0x3c, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Types1_12.METADATA_LIST); // 1 - Metadata list + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + + Optional type = wrapper.user().get(EntityTracker.class).get(entityId); + if (!type.isPresent()) + return; + + MetadataRewriter.handleMetadata(entityId, type.get(), wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + // 0x49 - New packet, options 0-4 followed by enum / string (possibly new command system?) + registerOutgoing(State.PLAY, 0x49, 0x4A); + registerOutgoing(State.PLAY, 0x4A, 0x4B); + registerOutgoing(State.PLAY, 0x4B, 0x4C); + registerOutgoing(State.PLAY, 0x4C, 0x4D); + registerOutgoing(State.PLAY, 0x4D, 0x4E); + registerOutgoing(State.PLAY, 0x4E, 0x4F); + registerOutgoing(State.PLAY, 0x4F, 0x50); + + // Incoming packets + registerIncoming(State.PLAY, 0x2, 0x1); + // 0x1 Tab complete was removed + registerIncoming(State.PLAY, 0x3, 0x2); + registerIncoming(State.PLAY, 0x4, 0x3); + registerIncoming(State.PLAY, 0x5, 0x4); + registerIncoming(State.PLAY, 0x6, 0x5); + registerIncoming(State.PLAY, 0x7, 0x6); + registerIncoming(State.PLAY, 0x8, 0x7); + registerIncoming(State.PLAY, 0x9, 0x8); + registerIncoming(State.PLAY, 0xA, 0x9); + registerIncoming(State.PLAY, 0xB, 0xA); + registerIncoming(State.PLAY, 0xC, 0xB); + registerIncoming(State.PLAY, 0xD, 0xC); + registerIncoming(State.PLAY, 0xE, 0xD); + registerIncoming(State.PLAY, 0xF, 0xE); + registerIncoming(State.PLAY, 0x10, 0xF); + registerIncoming(State.PLAY, 0x11, 0x10); + registerIncoming(State.PLAY, 0x12, 0x11); + registerIncoming(State.PLAY, 0x13, 0x12); + registerIncoming(State.PLAY, 0x14, 0x13); + registerIncoming(State.PLAY, 0x15, 0x14); + registerIncoming(State.PLAY, 0x16, 0x15); + registerIncoming(State.PLAY, 0x17, 0x16); + registerIncoming(State.PLAY, 0x18, 0x17); + registerIncoming(State.PLAY, 0x19, 0x18); + registerIncoming(State.PLAY, 0x1A, 0x19); + registerIncoming(State.PLAY, 0x1B, 0x1A); + registerIncoming(State.PLAY, 0x1C, 0x1B); + registerIncoming(State.PLAY, 0x1D, 0x1C); + registerIncoming(State.PLAY, 0x1E, 0x1D); + registerIncoming(State.PLAY, 0x1F, 0x1E); + registerIncoming(State.PLAY, 0x20, 0x1F); + } @Override public void init(UserConnection userConnection) { - + userConnection.put(new EntityTracker(userConnection)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/storage/EntityTracker.java new file mode 100644 index 000000000..524ea80c7 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/storage/EntityTracker.java @@ -0,0 +1,36 @@ +package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage; + +import com.google.common.base.Optional; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_12Types; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class EntityTracker extends StoredObject { + private final Map clientEntityTypes = new ConcurrentHashMap<>(); + + public EntityTracker(UserConnection user) { + super(user); + } + + public void removeEntity(int entityId) { + clientEntityTypes.remove(entityId); + } + + public void addEntity(int entityId, Entity1_12Types.EntityType type) { + clientEntityTypes.put(entityId, type); + } + + public boolean has(int entityId) { + return clientEntityTypes.containsKey(entityId); + } + + public Optional get(int id) { + if (!has(id)) + return Optional.absent(); + return Optional.of(clientEntityTypes.get(id)); + } + +} diff --git a/jar/pom.xml b/jar/pom.xml index 04ad3a60e..90f2ac9c5 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w43b + 1.4.0-17w45a 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index db785d8a5..29f8d14fb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 1.4.0-17w43b + 1.4.0-17w45a pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index ac2029173..88bef21fb 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w43b + 1.4.0-17w45a 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index a1dd90e23..cae0506ac 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-17w43b + 1.4.0-17w45a 4.0.0