From 2a2afa38214a0ea270e94c5aed335385f5ca3727 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 11 Sep 2024 18:22:26 +0200 Subject: [PATCH] Register component rewriter --- .../template/BlockItemPacketRewriter1_99.java | 4 +- .../template/ComponentRewriter1_99.java | 46 +++++++++++++++++++ .../protocols/template/Protocol1_99To_98.java | 20 ++++++++ .../rewriter/ComponentRewriter1_21.java | 5 -- .../v1_21to1_21_2/Protocol1_21To1_21_2.java | 12 +++++ .../rewriter/ComponentRewriter1_21_2.java | 5 +- .../rewriter/ComponentRewriter.java | 2 +- .../viaversion/util/SerializerVersion.java | 2 +- 8 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/template/ComponentRewriter1_99.java diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java index 7d8da0bcf..ac066f88f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java @@ -57,8 +57,8 @@ final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter. + */ +package com.viaversion.viaversion.protocols.template; + +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.rewriter.ComponentRewriter; +import com.viaversion.viaversion.util.SerializerVersion; + +public final class ComponentRewriter1_99 extends ComponentRewriter { + + public ComponentRewriter1_99(final Protocol1_99To_98 protocol) { + super(protocol, ReadType.NBT); + } + + @Override + protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) { + super.handleShowItem(connection, itemTag, componentsTag); + if (componentsTag == null) { + return; + } + + // Remove or update data from componentsTag + } + + @Override + protected SerializerVersion inputSerializerVersion() { + return SerializerVersion.V1_20_5; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/template/Protocol1_99To_98.java b/common/src/main/java/com/viaversion/viaversion/protocols/template/Protocol1_99To_98.java index 700eafa0b..d79a08a0c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/template/Protocol1_99To_98.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/template/Protocol1_99To_98.java @@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; +import com.viaversion.viaversion.api.rewriter.ComponentRewriter; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; @@ -50,6 +51,7 @@ final class Protocol1_99To_98 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); + private final ComponentRewriter1_99 componentRewriter = new ComponentRewriter1_99(this); public Protocol1_99To_98() { // Passing the class types into the super constructor is needed for automatic packet type id remapping, but can otherwise be omitted @@ -63,6 +65,19 @@ final class Protocol1_99To_98 extends AbstractProtocol soundRewriter = new SoundRewriter<>(this); soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND); soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY); @@ -132,6 +147,11 @@ final class Protocol1_99To_98 extends AbstractProtocol createPacketTypesProvider() { return new SimplePacketTypesProvider<>( diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/ComponentRewriter1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/ComponentRewriter1_21.java index 739e3d4d3..409895843 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/ComponentRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/ComponentRewriter1_21.java @@ -60,9 +60,4 @@ public final class ComponentRewriter1_21 extends ComponentRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND); soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java index 2840e8745..b11a246b0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java @@ -62,8 +62,5 @@ public final class ComponentRewriter1_21_2 extends ComponentRewriter implements com.v } protected SerializerVersion outputSerializerVersion() { - return null; + return inputSerializerVersion(); // Only matters if the nbt serializer changed } private void convertLegacyContents(final CompoundTag hoverEvent) { diff --git a/common/src/main/java/com/viaversion/viaversion/util/SerializerVersion.java b/common/src/main/java/com/viaversion/viaversion/util/SerializerVersion.java index 1d1d8fa99..3380a2f78 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/SerializerVersion.java +++ b/common/src/main/java/com/viaversion/viaversion/util/SerializerVersion.java @@ -115,4 +115,4 @@ public enum SerializerVersion { throw new RuntimeException(e); } } -} \ No newline at end of file +}