From 562651cd9df742bf87ceb290b8ab51334415acf6 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 30 Oct 2024 10:20:24 +0100 Subject: [PATCH] [ci skip] Add component rewriter to template (#903) --- .../template/ComponentRewriter1_99.java | 48 +++++++++++++++++++ .../protocol/template/Protocol1_98To1_99.java | 6 +-- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java new file mode 100644 index 00000000..1a27d30b --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java @@ -0,0 +1,48 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.template; + +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.util.SerializerVersion; + +public class ComponentRewriter1_99 extends TranslatableRewriter { + + public ComponentRewriter1_99(final BackwardsProtocol 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 + // New added data which is not handled otherwise needs to be removed to prevent errors on the client + } + + @Override + protected SerializerVersion inputSerializerVersion() { + return SerializerVersion.V1_20_5; + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java index ae0d0ae8..39865c8b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; -import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; @@ -34,7 +33,6 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; -import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -58,7 +56,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this, Types1_21_2.PARTICLE/*, Types1_OLD.PARTICLE*/); - private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); + private final ComponentRewriter1_99 translatableRewriter = new ComponentRewriter1_99(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_98To1_99() { @@ -125,7 +123,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol getComponentRewriter() { + public ComponentRewriter1_99 getComponentRewriter() { return translatableRewriter; }