From b11456d86b22c079563cc02170c5bc3ad51cfb99 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:17:55 +0200 Subject: [PATCH 1/5] Helper methods for cancelling packets --- .../ViaVersion/api/ViaVersionConfig.java | 7 --- .../ViaVersion/api/protocol/Protocol.java | 18 +++++++ .../Protocol1_12To1_11_1.java | 40 +++------------- .../Protocol1_13To1_12_2.java | 37 ++------------ .../packets/EntityPackets.java | 3 +- .../Protocol1_14To1_13_2.java | 38 ++------------- .../packets/EntityPackets.java | 12 +---- .../packets/PlayerPackets.java | 48 ++----------------- 8 files changed, 40 insertions(+), 163 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index d84d180f0..3ef26d04d 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -331,13 +331,6 @@ public interface ViaVersionConfig { boolean is1_14HealthNaNFix(); - /** - * Fixes non full blocks having 0 light for 1.14+ clients on sub 1.14 servers. - * - * @return True if enabled - */ - boolean isNonFullBlockLightFix(); - /** * Should 1.15 clients respawn instantly / without showing the death screen * diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index d6576b355..23d0acb49 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -116,6 +116,15 @@ public abstract class Protocol { incoming.put(pair, protocolPacket); } + public void cancelIncoming(State state, int newPacketID) { + registerIncoming(state, -1, newPacketID, new PacketRemapper() { + @Override + public void registerMap() { + handler(PacketWrapper::cancel); + } + }); + } + /** * Register an outgoing packet, with simple id transformation. * @@ -149,6 +158,15 @@ public abstract class Protocol { outgoing.put(pair, protocolPacket); } + public void cancelOutgoing(State state, int oldPacketID) { + registerIncoming(state, oldPacketID, -1, new PacketRemapper() { + @Override + public void registerMap() { + handler(PacketWrapper::cancel); + } + }); + } + /** * Transform a packet using this protocol * diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index f9bc869ae..84af37f9b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -272,18 +272,8 @@ public class Protocol1_12To1_11_1 extends Protocol { // Incoming // New packet at 0x01 - registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { + cancelIncoming(State.PLAY, 0x01); - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); registerIncoming(State.PLAY, 0x01, 0x02); registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x03, 0x04); @@ -336,33 +326,15 @@ public class Protocol1_12To1_11_1 extends Protocol { registerIncoming(State.PLAY, 0x13, 0x14); registerIncoming(State.PLAY, 0x14, 0x15); registerIncoming(State.PLAY, 0x15, 0x16); + // New packet at 0x17 - registerIncoming(State.PLAY, 0x17, 0x17, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { + cancelIncoming(State.PLAY, 0x17); - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); registerIncoming(State.PLAY, 0x16, 0x18); - // New packet 0x19 - registerIncoming(State.PLAY, 0x19, 0x19, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + // New packet 0x19 + cancelIncoming(State.PLAY, 0x19); + registerIncoming(State.PLAY, 0x17, 0x1a); // registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets registerIncoming(State.PLAY, 0x19, 0x1c); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index db72dfb65..cca497ea8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -799,30 +799,10 @@ public class Protocol1_13To1_12_2 extends Protocol { // Incoming packets // New packet 0x02 - Login Plugin Message - registerIncoming(State.LOGIN, -1, 0x02, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.LOGIN, 0x02); // New 0x01 - Query Block NBT - registerIncoming(State.PLAY, -1, 0x01, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x01); // Tab-Complete registerIncoming(State.PLAY, 0x1, 0x5, new PacketRemapper() { @@ -890,17 +870,8 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); // New 0x0C - Query Entity NBT - registerIncoming(State.PLAY, -1, 0x0C, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x0C); + registerIncoming(State.PLAY, 0x0A, 0x0D); registerIncoming(State.PLAY, 0x0B, 0x0E); registerIncoming(State.PLAY, 0x0C, 0x0F); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java index 56b4ef20d..6333a9235 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java @@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; public class EntityPackets { @@ -60,7 +61,7 @@ public class EntityPackets { @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); + wrapper.user().get(EntityTracker1_14.class).removeEntity(entity); } } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java index ec26d7976..c3e387772 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java @@ -217,17 +217,8 @@ public class Protocol1_14To1_13_2 extends Protocol { }); //Set Difficulty packet added in 19w11a - registerIncoming(State.PLAY, -1, 0x02, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x02); + registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x03, 0x04); registerIncoming(State.PLAY, 0x04, 0x05); @@ -242,17 +233,8 @@ public class Protocol1_14To1_13_2 extends Protocol { registerIncoming(State.PLAY, 0x0D, 0x0E); //Lock Difficulty packet added in 19w11a - registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x10); + registerIncoming(State.PLAY, 0x0E, 0x0F); registerIncoming(State.PLAY, 0x0F, 0x14); registerIncoming(State.PLAY, 0x10, 0x11); @@ -276,17 +258,7 @@ public class Protocol1_14To1_13_2 extends Protocol { registerIncoming(State.PLAY, 0x23, 0x25); //Unknown packet added in 19w13a - registerIncoming(State.PLAY, -1, 0x27, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x27); registerIncoming(State.PLAY, 0x27, 0x2A); registerIncoming(State.PLAY, 0x28, 0x2B); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index 4e3b50380..dd61f1ad4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -249,17 +249,7 @@ public class EntityPackets { // Update Entity NBT - protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelOutgoing(State.PLAY, 0x49); // Combat Event Packet protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index 3bada15be..3294f7bb8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -402,17 +402,7 @@ public class PlayerPackets { /* Removed packets */ // Set Compression - protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelOutgoing(State.PLAY, 0x46); /* Packets which do not have any field remapping or handlers */ @@ -482,43 +472,13 @@ public class PlayerPackets { }); // TP Confirm - protocol.registerIncoming(State.PLAY, -1, 0x00, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelIncoming(State.PLAY, 0x00); // Vehicle Move - protocol.registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelIncoming(State.PLAY, 0x10); // Steer Boat - protocol.registerIncoming(State.PLAY, -1, 0x11, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelIncoming(State.PLAY, 0x11); // Packet Plugin Message Incoming protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() { From 655ef137c1043d5a0b3f18d63472053e159d64dd Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 2 Oct 2019 15:09:50 +0200 Subject: [PATCH 2/5] Cleanup more entity tracking and rewriting --- .../ViaVersion/api/protocol/Protocol.java | 12 ++- .../api/rewriters/MetadataRewriter.java | 89 ++++++++++++++++--- .../Protocol1_11To1_10.java | 14 +-- .../metadata/MetadataRewriter1_11To1_10.java | 11 +++ .../Protocol1_12To1_11_1.java | 36 ++------ .../MetadataRewriter1_12To1_11_1.java | 10 +++ .../MetadataRewriter1_13_1To1_13.java | 9 ++ .../packets/EntityPackets.java | 28 +----- .../MetadataRewriter1_13To1_12_2.java | 16 ++++ .../packets/EntityPackets.java | 35 +------- .../MetadataRewriter1_14_1To1_14.java | 5 ++ .../packets/EntityPackets.java | 47 +--------- .../MetadataRewriter1_14To1_13_2.java | 11 +++ .../packets/EntityPackets.java | 29 +----- .../MetadataRewriter1_15To1_14_4.java | 11 +++ .../metadata/MetadataRewriter1_9To1_8.java | 9 ++ .../packets/EntityPackets.java | 2 +- .../packets/PlayerPackets.java | 2 +- 18 files changed, 185 insertions(+), 191 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index 23d0acb49..430e0c4f3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -116,8 +116,8 @@ public abstract class Protocol { incoming.put(pair, protocolPacket); } - public void cancelIncoming(State state, int newPacketID) { - registerIncoming(state, -1, newPacketID, new PacketRemapper() { + public void cancelIncoming(State state, int oldPacketID, int newPacketID) { + registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() { @Override public void registerMap() { handler(PacketWrapper::cancel); @@ -125,6 +125,10 @@ public abstract class Protocol { }); } + public void cancelIncoming(State state, int newPacketID) { + cancelOutgoing(state, -1, newPacketID); + } + /** * Register an outgoing packet, with simple id transformation. * @@ -158,8 +162,8 @@ public abstract class Protocol { outgoing.put(pair, protocolPacket); } - public void cancelOutgoing(State state, int oldPacketID) { - registerIncoming(state, oldPacketID, -1, new PacketRemapper() { + public void cancelOutgoing(State state, int oldPacketID, int newPacketID) { + registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() { @Override public void registerMap() { handler(PacketWrapper::cancel); diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index 1c809e59d..a9ba901a0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -78,23 +78,76 @@ public abstract class MetadataRewriter extends Rewriter { registerMetadataRewriter(oldPacketId, newPacketId, null, metaType); } - public void registerExtraTracker(int packetId, EntityType entityType, Type intType) { - getProtocol().registerOutgoing(State.PLAY, packetId, packetId, new PacketRemapper() { + /** + * Returns a packethandler to track and rewrite an entity. + * + * @param metaType type of the metadata list + * @return handler for tracking and rewriting entities + */ + public PacketHandler getTrackerAndRewriter(Type> metaType) { + return new PacketHandler() { @Override - public void registerMap() { - map(intType); // 0 - Entity id - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.user().get(entityTrackerClass).addEntity((int) wrapper.get(intType, 0), entityType); - } - }); + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + int type = wrapper.get(Type.VAR_INT, 1); + + int newType = getNewEntityId(type); + if (newType != type) { + wrapper.set(Type.VAR_INT, 1, newType); + } + + EntityType entType = getTypeFromId(newType); + // Register Type ID + wrapper.user().get(entityTrackerClass).addEntity(entityId, entType); + + if (metaType != null) { + handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user()); + } } - }); + }; } - public void registerExtraTracker(int packetId, EntityType entityType) { - registerExtraTracker(packetId, entityType, Type.VAR_INT); + public PacketHandler getTracker() { + return getTrackerAndRewriter(null); + } + + public PacketHandler getTrackerAndRewriter(Type> metaType, EntityType entityType) { + return new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + // Register Type ID + wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType); + + if (metaType != null) { + handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user()); + } + } + }; + } + + /** + * Returns a packethandler to track an object entity. + * + * @return handler for tracking and rewriting entities + */ + public PacketHandler getObjectTracker() { + return 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); + + int newType = getNewEntityId(type); + if (newType != type) { + wrapper.set(Type.BYTE, 0, (byte) newType); + } + + EntityType entType = getObjectTypeFromId(newType); + // Register Type ID + wrapper.user().get(entityTrackerClass).addEntity(entityId, entType); + } + }; } public void registerEntityDestroy(int oldPacketId, int newPacketId) { @@ -119,6 +172,16 @@ public abstract class MetadataRewriter extends Rewriter { registerEntityDestroy(packetId, packetId); } + protected abstract EntityType getTypeFromId(int type); + + protected EntityType getObjectTypeFromId(int type) { + return getTypeFromId(type); + } + + protected int getNewEntityId(int oldId) { + return oldId; + } + protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List metadatas, UserConnection connection) throws Exception { } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java index 27f7b7940..14f0cce58 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java @@ -44,19 +44,7 @@ public class Protocol1_11To1_10 extends Protocol { 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_11Types.EntityType entType = Entity1_11Types.getTypeFromId(type, true); - - // Register Type ID - wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType); - } - }); + handler(metadataRewriter.getObjectTracker()); } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java index 84ae81979..b181854d9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_11Types; import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -130,6 +131,16 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter metadata) { Optional optType = EntityType.findById(numType); if (!optType.isPresent()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index 84af37f9b..4b6fdcb34 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -8,7 +8,6 @@ import com.google.gson.JsonParser; import us.myles.ViaVersion.api.PacketWrapper; 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.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.platform.providers.ViaProviders; @@ -43,19 +42,7 @@ public class Protocol1_12To1_11_1 extends Protocol { 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(EntityTracker1_12.class).addEntity(entityId, entType); - } - }); + handler(metadataRewriter.getObjectTracker()); } }); @@ -77,19 +64,8 @@ public class Protocol1_12To1_11_1 extends Protocol { 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(EntityTracker1_12.class).addEntity(entityId, entType); - metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user()); - } - }); + // Track mob and rewrite metadata + handler(metadataRewriter.getTrackerAndRewriter(Types1_12.METADATA_LIST)); } }); @@ -272,7 +248,7 @@ public class Protocol1_12To1_11_1 extends Protocol { // Incoming // New packet at 0x01 - cancelIncoming(State.PLAY, 0x01); + cancelIncoming(State.PLAY, 0x01, 0x01); registerIncoming(State.PLAY, 0x01, 0x02); registerIncoming(State.PLAY, 0x02, 0x03); @@ -328,12 +304,12 @@ public class Protocol1_12To1_11_1 extends Protocol { registerIncoming(State.PLAY, 0x15, 0x16); // New packet at 0x17 - cancelIncoming(State.PLAY, 0x17); + cancelIncoming(State.PLAY, 0x17, 0x17); registerIncoming(State.PLAY, 0x16, 0x18); // New packet 0x19 - cancelIncoming(State.PLAY, 0x19); + cancelIncoming(State.PLAY, 0x19, 0x19); registerIncoming(State.PLAY, 0x17, 0x1a); // registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/metadata/MetadataRewriter1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/metadata/MetadataRewriter1_12To1_11_1.java index cf1154c72..0a85b80a3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/metadata/MetadataRewriter1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/metadata/MetadataRewriter1_12To1_11_1.java @@ -33,4 +33,14 @@ public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter optNewType = EntityTypeRewriter.getNewId(type); - type = optNewType.orElse(type); - Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); - - wrapper.set(Type.VAR_INT, 1, type); - - - // Register Type ID - wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); - - metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); - } - }); + handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST)); } }); @@ -132,17 +111,7 @@ public class EntityPackets { map(Type.BYTE); // 6 - Pitch map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - - Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER; - // Register Type ID - wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); - metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); - } - }); + handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER)); } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java index 529021971..485363222 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java @@ -26,4 +26,9 @@ public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter } } + @Override + protected EntityType getTypeFromId(int type) { + return Entity1_10Types.getTypeFromId(type, false); + } + + @Override + protected EntityType getObjectTypeFromId(int type) { + return Entity1_10Types.getTypeFromId(type, true); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index dd61f1ad4..9789b56fe 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -249,7 +249,7 @@ public class EntityPackets { // Update Entity NBT - protocol.cancelOutgoing(State.PLAY, 0x49); + protocol.cancelOutgoing(State.PLAY, 0x49, 0x49); // Combat Event Packet protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index 3294f7bb8..dd824f76e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -402,7 +402,7 @@ public class PlayerPackets { /* Removed packets */ // Set Compression - protocol.cancelOutgoing(State.PLAY, 0x46); + protocol.cancelOutgoing(State.PLAY, 0x46, 0x46); /* Packets which do not have any field remapping or handlers */ From 3adffdc43882363c9633fa3759a5727fc3c5968b Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 2 Oct 2019 15:14:03 +0200 Subject: [PATCH 3/5] Minor fix --- .../myles/ViaVersion/api/rewriters/MetadataRewriter.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index a9ba901a0..10a4f04b6 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -138,12 +138,7 @@ public abstract class MetadataRewriter extends Rewriter { int entityId = wrapper.get(Type.VAR_INT, 0); byte type = wrapper.get(Type.BYTE, 0); - int newType = getNewEntityId(type); - if (newType != type) { - wrapper.set(Type.BYTE, 0, (byte) newType); - } - - EntityType entType = getObjectTypeFromId(newType); + EntityType entType = getObjectTypeFromId(type); // Register Type ID wrapper.user().get(entityTrackerClass).addEntity(entityId, entType); } From 48edd014619dcdc3611be63572c5457ee10e1572 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 2 Oct 2019 15:55:59 +0200 Subject: [PATCH 4/5] Readd second cancelOutgoing method for VB --- .../java/us/myles/ViaVersion/api/protocol/Protocol.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index 430e0c4f3..fd9c853a3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -171,6 +171,15 @@ public abstract class Protocol { }); } + public void cancelOutgoing(State state, int oldPacketID) { + registerIncoming(state, oldPacketID, -1, new PacketRemapper() { + @Override + public void registerMap() { + handler(PacketWrapper::cancel); + } + }); + } + /** * Transform a packet using this protocol * From c131672870f74b10c6fce23b407058313959c91d Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Thu, 3 Oct 2019 11:00:55 +0200 Subject: [PATCH 5/5] Fix --- .../us/myles/ViaVersion/api/protocol/Protocol.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index fd9c853a3..73da1cce5 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -126,7 +126,7 @@ public abstract class Protocol { } public void cancelIncoming(State state, int newPacketID) { - cancelOutgoing(state, -1, newPacketID); + cancelIncoming(state, -1, newPacketID); } /** @@ -163,7 +163,7 @@ public abstract class Protocol { } public void cancelOutgoing(State state, int oldPacketID, int newPacketID) { - registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() { + registerOutgoing(state, oldPacketID, newPacketID, new PacketRemapper() { @Override public void registerMap() { handler(PacketWrapper::cancel); @@ -172,12 +172,7 @@ public abstract class Protocol { } public void cancelOutgoing(State state, int oldPacketID) { - registerIncoming(state, oldPacketID, -1, new PacketRemapper() { - @Override - public void registerMap() { - handler(PacketWrapper::cancel); - } - }); + cancelOutgoing(state, oldPacketID, -1); } /**