From 7d6c330fa3d0a7a0149b9b17087e40ae418c2e0e Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 8 Apr 2024 15:05:01 +0200 Subject: [PATCH] Handle entity effect particle color --- .../BlockItemPacketRewriter1_20_5.java | 10 ++++++- .../rewriter/EntityPacketRewriter1_20_5.java | 29 +++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index 85e989c7..bbdb0511 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -75,12 +75,20 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem wrapper.passthrough(Type.FLOAT); // Offset X wrapper.passthrough(Type.FLOAT); // Offset Y wrapper.passthrough(Type.FLOAT); // Offset Z - wrapper.passthrough(Type.FLOAT); // Particle Data + final float data = wrapper.passthrough(Type.FLOAT); wrapper.passthrough(Type.INT); // Particle Count // Move it to the beginning, move out arguments here final Particle particle = wrapper.read(Types1_20_5.PARTICLE); rewriteParticle(particle); + if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) { + // Remove color argument + final int color = particle.removeArgument(0).getValue(); + if (data == 0) { + wrapper.set(Type.FLOAT, 3, (float) color); + } + } + wrapper.set(Type.VAR_INT, 0, particle.id()); for (final Particle.ParticleData argument : particle.getArguments()) { argument.write(wrapper); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java index ea053d34..feb6a8aa 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java @@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_20_3; @@ -262,6 +263,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { if (typeId == Types1_20_5.META_TYPES.particlesType.typeId()) { + // Handled with living entity return Types1_20_5.META_TYPES.particlesType; } @@ -290,7 +292,24 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { final Particle[] particles = meta.value(); - meta.setTypeAndValue(Types1_20_3.META_TYPES.varIntType, 0); // TODO + int color = 0; + for (final Particle particle : particles) { + if (particle.id() == protocol.getMappingData().getParticleMappings().id("entity_effect")) { + // Remove color argument, use one of them for the ambient particle color + color = particle.removeArgument(0).getValue(); + } + } + meta.setTypeAndValue(Types1_20_3.META_TYPES.varIntType, color); + }); + + filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).addIndex(9); // Color + filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).index(11).handler((event, meta) -> { + final Particle particle = meta.value(); + if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) { + // Move color to its own metadata + final int color = particle.removeArgument(0).getValue(); + event.createExtraMeta(new Metadata(9, Types1_20_3.META_TYPES.varIntType, color)); + } }); filter().type(EntityTypes1_20_5.MINECART_ABSTRACT).index(11).handler((event, meta) -> { @@ -304,14 +323,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter