diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java new file mode 100644 index 000000000..c4fbe3bf8 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java @@ -0,0 +1,50 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * 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.viaversion.rewriter; + +import com.viaversion.viaversion.api.protocol.Protocol; +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; +import com.viaversion.viaversion.api.type.Type; + +public class AttributeRewriter { + private final Protocol protocol; + + public AttributeRewriter(Protocol protocol) { + this.protocol = protocol; + } + + public void register1_20_5(C packetType) { + protocol.registerClientbound(packetType, wrapper -> { + wrapper.passthrough(Type.VAR_INT); // Entity ID + + final int size = wrapper.passthrough(Type.VAR_INT); + for (int i = 0; i < size; i++) { + final int attributeId = wrapper.read(Type.VAR_INT); + wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewAttributeId(attributeId)); + + wrapper.passthrough(Type.DOUBLE); // Base + final int modifierSize = wrapper.passthrough(Type.VAR_INT); + for (int j = 0; j < modifierSize; j++) { + wrapper.passthrough(Type.UUID); // ID + wrapper.passthrough(Type.DOUBLE); // Amount + wrapper.passthrough(Type.BYTE); // Operation + } + } + }); + } +} diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java b/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java index ce3e62634..5e0f720e6 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java +++ b/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java @@ -27,6 +27,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Clientb import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPacket1_20_5; +import com.viaversion.viaversion.rewriter.AttributeRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -56,18 +57,16 @@ public final class Protocol1_99To_98 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); tagRewriter.registerGeneric(ClientboundPackets1_20_5.TAGS); tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS); - // Registers sound id changes final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_5.SOUND); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_5.ENTITY_SOUND); - // Registers registry type id changes as well as stat id changes if also included in the json mappings new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.STATISTICS); + new AttributeRewriter<>(this).register1_20_5(ClientboundPackets1_20_5.ENTITY_PROPERTIES); // Uncomment if an existing type changed serialization format. Mappings for argument type keys can also be defined in mapping files /*final CommandRewriter1_19_4 commandRewriter = new CommandRewriter1_19_4(this) { @@ -82,7 +81,6 @@ public final class Protocol1_99To_98 extends AbstractProtocol(protocol).register(ClientboundPackets1_20_5.DECLARE_RECIPES); + new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_20_5.DECLARE_RECIPES); // OR do this if serialization of recipes changed and override the relevant method // Add new serializers to RecipeRewriter, or extend the last one for changes // new RecipeRewriter1_20_3(this) {}.register1_20_5(ClientboundPackets1_20_5.DECLARE_RECIPES);