From a4d1ac3b95b22ac113b698cdc164e4bb0f5c6c1d Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 9 Dec 2020 11:03:40 +0100 Subject: [PATCH] Add getSpawnParticleHandler method to ItemRewriter --- .../api/rewriters/ItemRewriter.java | 38 ++++++++++--------- .../packets/EntityPackets.java | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) 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 6bfa25559..ffc020fb4 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,27 +205,31 @@ public class ItemRewriter { map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count - handler(wrapper -> { - int id = wrapper.get(Type.INT, 0); - if (id == -1) return; - - ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); - if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) { - int data = wrapper.passthrough(Type.VAR_INT); - wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); - } else if (id == mappings.getItemId()) { - toClient.rewrite(wrapper.passthrough(itemType)); - } - - int newId = protocol.getMappingData().getNewParticleId(id); - if (newId != id) { - wrapper.set(Type.INT, 0, newId); - } - }); + handler(getSpawnParticleHandler(itemType, coordType)); } }); } + public PacketHandler getSpawnParticleHandler(Type itemType, Type coordType) { + return wrapper -> { + int id = wrapper.get(Type.INT, 0); + if (id == -1) return; + + ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); + if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) { + int data = wrapper.passthrough(Type.VAR_INT); + wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); + } else if (id == mappings.getItemId()) { + toClient.rewrite(wrapper.passthrough(itemType)); + } + + int newId = protocol.getMappingData().getNewParticleId(id); + if (newId != id) { + wrapper.set(Type.INT, 0, newId); + } + }; + } + // Only sent to the client public PacketHandler itemArrayHandler(Type type) { return wrapper -> { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java index e93ea1114..651aaefd3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java @@ -43,8 +43,8 @@ public class EntityPackets { dimensionName = "minecraft:overworld"; } - wrapper.write(Type.STRING, dimensionName); // dimension type wrapper.write(Type.STRING, dimensionName); // dimension + wrapper.write(Type.STRING, dimensionName); // world }; public static final CompoundTag DIMENSIONS_TAG = new CompoundTag(""); private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};