From fcd91bb855bb1dc3a152c957c2a90281c6b27292 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 13 Aug 2024 12:45:36 +0200 Subject: [PATCH] Add item cost and particle types to item rewriter --- .../template/BlockItemPacketRewriter1_99.java | 16 +++++-- .../protocols/template/Protocol1_99To_98.java | 2 +- .../rewriter/BlockItemPacketRewriter1_21.java | 14 ++++-- .../viaversion/rewriter/ItemRewriter.java | 47 +++++++++++++------ .../rewriter/StructuredItemRewriter.java | 10 ++++ 5 files changed, 63 insertions(+), 26 deletions(-) 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 0be808fe5..655e1db33 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 @@ -18,7 +18,7 @@ package com.viaversion.viaversion.protocols.template; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; -import com.viaversion.viaversion.api.type.types.version.Types1_20_5; +import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; @@ -30,10 +30,16 @@ import com.viaversion.viaversion.rewriter.StructuredItemRewriter; // To replace if needed: // ChunkType1_20_2 // RecipeRewriter1_20_3 +// Types1_21, Types1_OLD final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter { public BlockItemPacketRewriter1_99(final Protocol1_99To_98 protocol) { - super(protocol, /*TypesOLD.ITEM, TypesOLD.ITEM_ARRAY, */Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY); + super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY); + /*super(protocol, + Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY, + Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, + Types1_OLD.PARTICLE, Types1_21.PARTICLE + );*/ } @Override @@ -58,10 +64,10 @@ final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES); // OR do this if serialization of recipes changed and override the relevant method 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 4a021e313..068bb2287 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 @@ -90,7 +90,7 @@ final class Protocol1_99To_98 extends AbstractProtocol DISCS = List.of("11", "13", "5", "blocks", "cat", "chirp", "far", "mall", "mellohi", "otherside", "pigstep", "relic", "stal", "strad", "wait", "ward"); public BlockItemPacketRewriter1_21(final Protocol1_20_5To1_21 protocol) { - super(protocol, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY); + super(protocol, + Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY, + Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, + Types1_20_5.PARTICLE, Types1_21.PARTICLE + ); } @Override @@ -66,10 +70,10 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter { wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id @@ -212,4 +216,4 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter mappedItemType; private final Type itemArrayType; private final Type mappedItemArrayType; + private final Type itemCostType; + private final Type mappedItemCostType; + private final Type optionalItemCostType; + private final Type mappedOptionalItemCostType; + private final Type particleType; + private final Type mappedParticleType; - public ItemRewriter(T protocol, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { + public ItemRewriter( + T protocol, + Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType, + Type itemCostType, Type optionalItemCostType, Type mappedItemCostType, Type mappedOptionalItemCostType, + Type particleType, Type mappedParticleType + ) { super(protocol); this.itemType = itemType; this.itemArrayType = itemArrayType; this.mappedItemType = mappedItemType; this.mappedItemArrayType = mappedItemArrayType; + this.itemCostType = itemCostType; + this.mappedItemCostType = mappedItemCostType; + this.optionalItemCostType = optionalItemCostType; + this.mappedOptionalItemCostType = mappedOptionalItemCostType; + this.particleType = particleType; + this.mappedParticleType = mappedParticleType; + } + + public ItemRewriter(T protocol, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { + this(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, null, null, null, null, null, null); } public ItemRewriter(T protocol, Type itemType, Type itemArrayType) { @@ -322,25 +343,21 @@ public class ItemRewriter costType, final Type mappedCostType, - final Type optionalCostType, final Type mappedOptionalCostType - ) { + public void registerMerchantOffers1_20_5(final C packetType) { protocol.registerClientbound(packetType, wrapper -> { wrapper.passthrough(Types.VAR_INT); // Container id int size = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < size; i++) { - final Item input = wrapper.read(costType); - wrapper.write(mappedCostType, handleItemToClient(wrapper.user(), input)); + final Item input = wrapper.read(itemCostType); + wrapper.write(mappedItemCostType, handleItemToClient(wrapper.user(), input)); handleClientboundItem(wrapper); // Result - Item secondInput = wrapper.read(optionalCostType); + Item secondInput = wrapper.read(optionalItemCostType); if (secondInput != null) { handleItemToClient(wrapper.user(), secondInput); } - wrapper.write(mappedOptionalCostType, secondInput); + wrapper.write(mappedOptionalItemCostType, secondInput); wrapper.passthrough(Types.BOOLEAN); // Out of stock wrapper.passthrough(Types.INT); // Number of trade uses @@ -491,7 +508,7 @@ public class ItemRewriter unmappedParticleType, Type mappedParticleType) { + public void registerLevelParticles1_20_5(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override public void register() { @@ -505,7 +522,7 @@ public class ItemRewriter { - final Particle particle = wrapper.read(unmappedParticleType); + final Particle particle = wrapper.read(particleType); rewriteParticle(wrapper.user(), particle); wrapper.write(mappedParticleType, particle); }); @@ -513,7 +530,7 @@ public class ItemRewriter unmappedParticleType, Type mappedParticleType) { + public void registerExplosion(C packetType) { final SoundRewriter soundRewriter = new SoundRewriter<>(protocol); protocol.registerClientbound(packetType, wrapper -> { wrapper.passthrough(Types.DOUBLE); // X @@ -531,8 +548,8 @@ public class ItemRewriter> extends ItemRewriter { + public StructuredItemRewriter( + T protocol, + Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType, + Type itemCostType, Type optionalItemCostType, Type mappedItemCostType, Type mappedOptionalItemCostType, + Type particleType, Type mappedParticleType + ) { + super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, itemCostType, optionalItemCostType, mappedItemCostType, mappedOptionalItemCostType, particleType, mappedParticleType); + } + public StructuredItemRewriter(T protocol, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType); }