From e4a1530aa86b3c3a4ce0838365ba6550b65199d9 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 6 Jun 2023 13:28:02 +0200 Subject: [PATCH] Fix >1.18 vibration particle handling --- .../viaversion/api/type/types/Particle.java | 8 ++++++ .../type/types/minecraft/ParticleType.java | 16 +++++++++++ .../Protocol1_19_3To1_19_1.java | 2 +- .../Protocol1_19_4To1_19_3.java | 2 +- .../Protocol1_19To1_18_2.java | 2 +- .../packets/EntityPackets.java | 28 +++++++++++++++++-- .../packets/InventoryPackets.java | 15 ++++++++++ .../Protocol1_20To1_19_4.java | 2 +- .../viaversion/rewriter/ItemRewriter.java | 10 ++++--- 9 files changed, 75 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java index 05893369c..2f4d1fa7d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java @@ -83,5 +83,13 @@ public class Particle { public void setValue(Object value) { this.value = value; } + + @Override + public String toString() { + return "ParticleData{" + + "type=" + type + + ", value=" + value + + '}'; + } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java index fe1dbe4d3..26e6bce3b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java @@ -105,6 +105,7 @@ public class ParticleType extends Type { String resourceLocation = Type.STRING.read(buf); particle.add(Type.STRING, resourceLocation); + resourceLocation = Key.stripMinecraftNamespace(resourceLocation); if (resourceLocation.equals("block")) { particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // Target block pos @@ -115,6 +116,21 @@ public class ParticleType extends Type { } particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks }; + public static final ParticleReader VIBRATION1_19 = (buf, particle) -> { + String resourceLocation = Type.STRING.read(buf); + particle.add(Type.STRING, resourceLocation); + + resourceLocation = Key.stripMinecraftNamespace(resourceLocation); + if (resourceLocation.equals("block")) { + particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // Target block pos + } else if (resourceLocation.equals("entity")) { + particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Target entity + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Y offset + } else { + Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + resourceLocation); + } + particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks + }; public static final ParticleReader SCULK_CHARGE = (buf, particle) -> { particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Roll }; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/Protocol1_19_3To1_19_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/Protocol1_19_3To1_19_1.java index 495770f5b..da359ea71 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/Protocol1_19_3To1_19_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/Protocol1_19_3To1_19_1.java @@ -289,7 +289,7 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol meta.setMetaType(Types1_19.META_TYPES.byId(meta.metaType().typeId()))); + filter().handler((event, meta) -> { + meta.setMetaType(Types1_19.META_TYPES.byId(meta.metaType().typeId())); - registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null, Types1_19.META_TYPES.particleType); + final MetaType type = meta.metaType(); + if (type == Types1_19.META_TYPES.particleType) { + final Particle particle = (Particle) meta.getValue(); + final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); + if (particle.getId() == particleMappings.id("vibration")) { + // Remove the position + particle.getArguments().remove(0); + + final String resourceLocation = Key.stripMinecraftNamespace(particle.getArguments().get(0).get()); + if (resourceLocation.equals("entity")) { + // Add Y offset + particle.getArguments().add(2, new Particle.ParticleData(Type.FLOAT, 0F)); + } + } + + rewriteParticle(particle); + } + }); + + registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null, null); filter().filterFamily(Entity1_19Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> { // Convert to new block id diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java index 697496a92..b91fbd6b7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java @@ -18,6 +18,7 @@ package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -27,6 +28,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPacke import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.provider.AckSequenceProvider; import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.rewriter.RecipeRewriter; +import com.viaversion.viaversion.util.Key; public final class InventoryPackets extends ItemRewriter { @@ -54,6 +56,19 @@ public final class InventoryPackets extends ItemRewriter { + final int id = wrapper.get(Type.VAR_INT, 0); + final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); + if (id == particleMappings.id("vibration")) { + wrapper.read(Type.POSITION1_14); // Remove position + + final String resourceLocation = Key.stripMinecraftNamespace(wrapper.passthrough(Type.STRING)); + if (resourceLocation.equals("entity")) { + wrapper.passthrough(Type.VAR_INT); // Target entity + wrapper.write(Type.FLOAT, 0F); // Y offset + } + } + }); handler(getSpawnParticleHandler(Type.VAR_INT, Type.FLAT_VAR_INT_ITEM)); } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/Protocol1_20To1_19_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/Protocol1_20To1_19_4.java index 6af502083..cac492a18 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/Protocol1_20To1_19_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/Protocol1_20To1_19_4.java @@ -77,7 +77,7 @@ public final class Protocol1_20To1_19_4 extends AbstractProtocol idType, Type itemType) { return wrapper -> { int id = wrapper.get(idType, 0); - if (id == -1) return; + if (id == -1) { + return; + } ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); if (mappings.isBlockParticle(id)) { @@ -381,9 +383,9 @@ public abstract class ItemRewriter