From 05b1a6bacd966a2f271cb6db38edc1ecfe5db6c2 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 29 Feb 2024 12:26:23 +0100 Subject: [PATCH] Start working on 24w09a --- .../api/rewriters/ItemRewriter.java | 4 + .../api/rewriters/ItemRewriterBase.java | 10 ++- .../api/rewriters/StructuredItemRewriter.java | 79 ++++++++++++++++++ .../packets/BlockItemPackets1_11.java | 4 +- .../packets/BlockItemPackets1_13.java | 8 +- .../packets/BlockItemPackets1_14.java | 2 +- .../Protocol1_20_2To1_20_3.java | 2 + .../Protocol1_20_3To1_20_5.java | 2 + .../BlockItemPacketRewriter1_20_5.java | 58 +++++++++++-- .../rewriter/EntityPacketRewriter1_20_5.java | 1 + .../data/mappings-1.20.5to1.20.3.nbt | Bin 113794 -> 114091 bytes gradle/libs.versions.toml | 2 +- 12 files changed, 154 insertions(+), 18 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredItemRewriter.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java index e78d7d62..a02898d1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java @@ -41,6 +41,10 @@ public class ItemRewriter itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { + super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, true); + } + @Override public @Nullable Item handleItemToClient(@Nullable Item item) { if (item == null) { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriterBase.java index d7d36cb9..80905961 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriterBase.java @@ -35,12 +35,16 @@ public abstract class ItemRewriterBase itemType, Type itemArrayType, boolean jsonNameFormat) { - super(protocol, itemType, itemArrayType); - this.jsonNameFormat = jsonNameFormat; + protected ItemRewriterBase(T protocol, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType, boolean jsonFormat) { + super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType); + this.jsonNameFormat = jsonFormat; nbtTagName = "VB|" + protocol.getClass().getSimpleName(); } + protected ItemRewriterBase(T protocol, Type itemType, Type itemArrayType, boolean jsonNameFormat) { + this(protocol, itemType, itemArrayType, itemType, itemArrayType, jsonNameFormat); + } + @Override public @Nullable Item handleItemToServer(@Nullable Item item) { if (item == null) return null; diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredItemRewriter.java new file mode 100644 index 00000000..06f33779 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredItemRewriter.java @@ -0,0 +1,79 @@ +/* + * 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.api.rewriters; + +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.data.MappedItem; +import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; +import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; +import com.viaversion.viaversion.api.type.Type; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class StructuredItemRewriter> extends ItemRewriter { + + public StructuredItemRewriter(T protocol, Type itemType, Type itemArrayType) { + super(protocol, itemType, itemArrayType); + } + + public StructuredItemRewriter(T protocol, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { + super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType); + } + + @Override + public @Nullable Item handleItemToClient(@Nullable Item item) { + if (item == null) { + return null; + } + + // TODO Translatable rewriter on name and lore + + MappedItem data = protocol.getMappingData() != null ? protocol.getMappingData().getMappedItem(item.identifier()) : null; + if (data == null) { + // Just rewrite the id + if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) { + item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier())); + } + } + + // TODO Save original id, set remapped id + if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) { + item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier())); + } + // TODO custom model data and custom name + return item; + } + + @Override + public @Nullable Item handleItemToServer(@Nullable Item item) { + if (item == null) return null; + + if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) { + item.setIdentifier(protocol.getMappingData().getOldItemId(item.identifier())); + } + + // TODO restore original id and display + return item; + } + + @Override + protected void restoreDisplayTag(final Item item) { + // TODO + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index e7aee953..05f7cc43 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -61,7 +61,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter handleItemToClient(wrapper.get(Type.ITEM1_8, 0))); // Handle Llama handler(wrapper -> { @@ -147,7 +147,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter handleItemToServer(wrapper.get(Type.ITEM1_8, 0))); // Llama slot handler(wrapper -> { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index a568340a..0f822ac2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -267,7 +267,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.SHORT); map(Type.ITEM1_13, Type.ITEM1_8); - handler(itemToClientHandler(Type.ITEM1_8)); + handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0))); } }); @@ -437,7 +437,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.VAR_INT); map(Type.ITEM1_13, Type.ITEM1_8); - handler(itemToClientHandler(Type.ITEM1_8)); + handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0))); } }); @@ -465,7 +465,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.SHORT); map(Type.ITEM1_8, Type.ITEM1_13); - handler(itemToServerHandler(Type.ITEM1_13)); + handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0))); } }); @@ -479,7 +479,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.VAR_INT); map(Type.ITEM1_8, Type.ITEM1_13); - handler(itemToServerHandler(Type.ITEM1_13)); + handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0))); } }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index f5d36d69..bf5acf51 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -228,7 +228,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit map(Type.VAR_INT); // 1 - Slot ID map(Type.ITEM1_13_2); // 2 - Item - handler(itemToClientHandler(Type.ITEM1_13_2)); + handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_13_2, 0))); handler(wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java index 338ae284..1dafc9da 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java @@ -57,6 +57,8 @@ import com.viaversion.viaversion.util.ComponentUtil; import java.util.BitSet; import java.util.UUID; +import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; + public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol { public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.20.3", "1.20.2", Protocol1_20_3To1_20_2.class); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java index 91e257be..99f762ea 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/Protocol1_20_3To1_20_5.java @@ -57,6 +57,8 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; +import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; + public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol { public static final BackwardsMappings MAPPINGS = new BackwardsMappings(); 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 1fa547d3..f7b40484 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 @@ -18,8 +18,10 @@ package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter; import com.viaversion.viabackwards.api.rewriters.ItemRewriter; +import com.viaversion.viabackwards.api.rewriters.StructuredItemRewriter; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5; import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_3; @@ -31,11 +33,12 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Clientb import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.Key; +import org.checkerframework.checker.nullness.qual.Nullable; -public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter { +public final class BlockItemPacketRewriter1_20_5 extends StructuredItemRewriter { public BlockItemPacketRewriter1_20_5(final Protocol1_20_3To1_20_5 protocol) { - super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY); + super(protocol, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY); } @Override @@ -72,7 +75,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter argument : particle.getArguments()) { argument.write(wrapper); } @@ -113,9 +116,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter recipeRewriter = new RecipeRewriter1_20_3<>(protocol); + final RecipeRewriter1_20_3 recipeRewriter = new RecipeRewriter1_20_3(protocol) { + @Override + protected Type itemType() { + return Types1_20_5.ITEM; + } + + @Override + protected Type itemArrayType() { + return Types1_20_5.ITEM_ARRAY; + } + + @Override + protected Type mappedItemType() { + return Type.ITEM1_20_2; + } + + @Override + protected Type mappedItemArrayType() { + return Type.ITEM1_20_2_ARRAY; + } + }; protocol.registerClientbound(ClientboundPackets1_20_5.DECLARE_RECIPES, wrapper -> { final int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { @@ -142,4 +169,21 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter { // Moved to server data final boolean enforcesSecureChat = wrapper.read(Type.BOOLEAN); diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.20.5to1.20.3.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.20.5to1.20.3.nbt index 1bc882884e8633aaec828065c2a30e556cbc2147..e184de8470b5990c6f6b58c0d57d473ef69d40b3 100644 GIT binary patch delta 420 zcmZqr$+r48Tf-Jc`%PSi+zd>KB@7G<*3&&VF-9A%12T63@opgA1H?yx_!tl$XJBAl z2E@x57?=ZrI0%S80`aHmXE!nGTTNtOV4VcSlY#gi5Z?#l$3Xl9h@S%SS0Mfd#NUDV z2N3@RT3eD2G}n4M-)6>;=?gY9vP@6f%&5f0*!Ld@fF@f^uiMP%q5@RB4I}~rK=y73 z3qbYGM%s0|$c;R6Hd=FFUnTFRL`S z03<8`70xZqNrelFCFSHNXX}-xmc$nqZKHArWS+Li)NOj=IWK_=cL6a7Ukv_ s=_M7VCT7EAd{Cs4ixQK;QexKB@7G<`qMo(F-FVo1TuF4@opeK0>npw_!t8N^E)7Z zKiNmjTIfCl1M34IehAcAk`I*DpKiCAF=YC*&5TM+%-5%1+{~yu{lR8N_UZpNGjeeJ T2Lhn#-P^UcFmB^uVqgFO@NFir diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 591b7d9e..2c4c3a49 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "4.10.0-24w07a-SNAPSHOT" +viaver = "4.10.0-24w09a-SNAPSHOT" # Common provided netty = "4.0.20.Final"