diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java index ffc020fb4..d7ce883b3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java @@ -205,12 +205,12 @@ public class ItemRewriter { map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count - handler(getSpawnParticleHandler(itemType, coordType)); + handler(getSpawnParticleHandler(itemType)); } }); } - public PacketHandler getSpawnParticleHandler(Type itemType, Type coordType) { + public PacketHandler getSpawnParticleHandler(Type itemType) { return wrapper -> { int id = wrapper.get(Type.INT, 0); if (id == -1) return; diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java index 8174bf8a1..2099d9d2b 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java @@ -52,6 +52,8 @@ public class TagRewriter { } /** + * Pre 1.17 reading of hardcoded registry types. + * * @param packetType packet type * @param readUntilType read and process the types until (including) the given registry type */ @@ -64,6 +66,20 @@ public class TagRewriter { }); } + /** + * 1.17+ reading of generic tag types. + * + * @param packetType packet type + */ + public void registerGeneric(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { + @Override + public void registerMap() { + handler(getGenericHandler()); + } + }); + } + public PacketHandler getHandler(@Nullable RegistryType readUntilType) { return wrapper -> { for (RegistryType type : RegistryType.getValues()) { @@ -77,6 +93,25 @@ public class TagRewriter { }; } + public PacketHandler getGenericHandler() { + return wrapper -> { + int length = wrapper.passthrough(Type.VAR_INT); + for (int i = 0; i < length; i++) { + String registryKey = wrapper.passthrough(Type.STRING); + if (registryKey.startsWith("minecraft:")) { + registryKey = registryKey.substring(10); + } + + RegistryType type = RegistryType.getByKey(registryKey); + if (type != null) { + handle(wrapper, getRewriter(type), getNewTags(type)); + } else { + handle(wrapper, null, null); + } + } + }; + } + public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, List newTags) throws Exception { int tagsSize = wrapper.read(Type.VAR_INT); wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java index eace47286..bc9056e8f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java @@ -56,7 +56,7 @@ public class InventoryPackets { wrapper.passthrough(Type.FLOAT); // Scale } }); - handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM, Type.DOUBLE)); + handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM)); } }); }