From d04aaeb92643cdeb52ca86c39fcd7ac97c3efa2d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 8 Apr 2024 14:21:11 +0200 Subject: [PATCH] Handle color in area effect cloud --- .../viaversion/api/minecraft/Particle.java | 12 ++++++ .../rewriter/EntityPacketRewriter1_20_5.java | 38 ++++++++++++++++++- .../viaversion/rewriter/EntityRewriter.java | 13 +++++-- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java index 6d1e5ab38..41de2c114 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java @@ -73,6 +73,18 @@ public final class Particle implements IdHolder { arguments.add(index, new ParticleData<>(type, value)); } + public void set(final int index, final Type type, final T value) { + arguments.set(index, new ParticleData<>(type, value)); + } + + @Override + public String toString() { + return "Particle{" + + "arguments=" + arguments + + ", id=" + id + + '}'; + } + public static final class ParticleData { private final Type type; private T value; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index e3000274a..e18b704ca 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.Particle; 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.metadata.Metadata; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -285,6 +286,30 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { + // Color removed - Now put into the actual particle + final int metaIndex = event.index(); + if (metaIndex == 9) { + // If the color is found first + final Metadata particleData = event.metaAtIndex(11); + addColor(particleData, meta.value()); + + event.cancel(); + return; + } + + if (metaIndex > 9) { + event.setIndex(metaIndex - 1); + } + + if (metaIndex == 11) { + // If the particle is found first + final Metadata colorData = event.metaAtIndex(9); + if (colorData != null) { + addColor(meta, colorData.value()); + } + } + }); filter().type(EntityTypes1_20_5.MINECART_ABSTRACT).index(11).handler((event, meta) -> { final int blockState = meta.value(); @@ -292,11 +317,22 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter data = particle.getArgument(0); data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue())); } else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) { Particle.ParticleData data = particle.getArgument(0); - Item item = data.getValue(); - protocol.getItemRewriter().handleItemToClient(item); + ItemRewriter itemRewriter = protocol.getItemRewriter(); + Item item = itemRewriter.handleItemToClient(data.getValue()); + if (itemRewriter.mappedItemType() != null && itemRewriter.itemType() != itemRewriter.mappedItemType()) { + // Replace the type + particle.set(0, itemRewriter.mappedItemType(), item); + } else { + data.setValue(item); + } } particle.setId(protocol.getMappingData().getNewParticleId(id));