From cfc9011cee0729583bab75339ade51763a4f4ac6 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 27 Jan 2024 20:51:28 +0100 Subject: [PATCH 1/4] Push books through component conversion in 1.20.2->1.20.3 Fixes #3579 --- .../BlockItemPacketRewriter1_20_3.java | 39 +++++++++++++++++++ .../viaversion/util/ComponentUtil.java | 11 ++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java index 6bd6bc9b0..ffa276cc2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java @@ -17,8 +17,14 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import com.github.steveice10.opennbt.tag.builtin.Tag; +import com.google.gson.JsonElement; import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -30,7 +36,9 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3 import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter; +import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Key; +import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter { @@ -125,4 +133,35 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter= SerializerVersion.V1_16.ordinal() && to.ordinal() < SerializerVersion.V1_16.ordinal()) { // Convert hover event to legacy format final Style style = component.getStyle(); From 01f28a052c2c4ae7a804acfbb2d7f64667d53493 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 29 Jan 2024 10:17:00 +0100 Subject: [PATCH 2/4] Ignore errors in book conversion --- .../viaversion/protocol/ProtocolPipelineImpl.java | 7 ++++--- .../rewriter/BlockItemPacketRewriter1_20_3.java | 11 +++++++++-- .../viaversion/rewriter/EntityRewriter.java | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java index d4df795e4..b45a288fa 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java @@ -107,7 +107,8 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot int originalID = packetWrapper.getId(); DebugHandler debugHandler = Via.getManager().debugHandler(); - if (debugHandler.enabled() && !debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) { + boolean debug = debugHandler.enabled(); + if (debug && !debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) { logPacket(direction, state, packetWrapper, originalID); } @@ -115,13 +116,13 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot packetWrapper.apply(direction, state, 0, protocolListFor(direction)); super.transform(direction, state, packetWrapper); - if (debugHandler.enabled() && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) { + if (debug && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) { logPacket(direction, state, packetWrapper, originalID); } } private List protocolListFor(final Direction direction) { - return Collections.unmodifiableList(direction == Direction.SERVERBOUND ? protocolList : reversedProtocolList); + return direction == Direction.SERVERBOUND ? protocolList : reversedProtocolList; } private void logPacket(Direction direction, State state, PacketWrapper packetWrapper, int originalID) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java index ffa276cc2..92d345a7b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java @@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.gson.JsonElement; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -160,8 +161,14 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter - * Calling {@link MetaFilter.Builder#register()} will automatically register the filter on this rewriter. + * Calling {@link com.viaversion.viaversion.rewriter.meta.MetaFilter.Builder#register()} will automatically register the filter on this rewriter. * * @return meta filter builder */ @@ -92,7 +92,7 @@ public abstract class EntityRewriter Date: Mon, 29 Jan 2024 10:32:02 +0100 Subject: [PATCH 3/4] Log the error by default, instead check suppression config --- .../viaversion/api/debug/DebugHandler.java | 14 ++++++++++++++ .../rewriter/BlockItemPacketRewriter1_20_3.java | 4 +--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java b/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java index 7b6b936fe..30e1b1032 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java +++ b/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java @@ -23,9 +23,11 @@ package com.viaversion.viaversion.api.debug; import com.google.common.annotations.Beta; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import java.util.logging.Level; @Beta public interface DebugHandler { @@ -102,4 +104,16 @@ public interface DebugHandler { addPacketTypeToLog(packetType); } } + + /** + * Logs an error if debug mode is enabled or error suppression is disabled. + * + * @param error error message + * @param t thrown exception + */ + default void error(final String error, final Throwable t) { + if (!Via.getConfig().isSuppressConversionWarnings() || enabled()) { + Via.getPlatform().getLogger().log(Level.SEVERE, error, t); + } + } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java index 92d345a7b..025a26403 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java @@ -165,9 +165,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter Date: Mon, 29 Jan 2024 17:21:59 +0100 Subject: [PATCH 4/4] Clean up more item type usage in ItemRewriter (#3674) --- .../packets/InventoryPackets.java | 4 +- .../packets/InventoryPackets.java | 4 +- .../packets/InventoryPackets.java | 12 ++--- .../packets/InventoryPackets.java | 13 +++-- .../packets/InventoryPackets.java | 16 +++--- .../packets/InventoryPackets.java | 16 +++--- .../packets/InventoryPackets.java | 14 ++--- .../packets/InventoryPackets.java | 14 ++--- .../packets/InventoryPackets.java | 14 ++--- .../packets/InventoryPackets.java | 12 ++--- .../packets/InventoryPackets.java | 4 +- .../packets/InventoryPackets.java | 4 +- .../packets/InventoryPackets.java | 4 +- .../packets/InventoryPackets.java | 4 +- .../packets/InventoryPackets.java | 2 +- .../viaversion/rewriter/ItemRewriter.java | 51 +++++++++---------- 16 files changed, 93 insertions(+), 95 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java index dcd7d310e..bb2269eba 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java @@ -27,12 +27,12 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_10To1_9_3_4 protocol) { - super(protocol, null, null); + super(protocol, Type.ITEM1_8, null); } @Override public void registerPackets() { - registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8); + registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java index 026ca21d7..22633016b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java @@ -27,12 +27,12 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_11_1To1_11 protocol) { - super(protocol, null, null); + super(protocol, Type.ITEM1_8, null); } @Override public void registerPackets() { - registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8); + registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java index 94451b75f..0cd567dbd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java @@ -29,14 +29,14 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_11To1_10 protocol) { - super(protocol, null, null); + super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY); } @Override public void registerPackets() { - registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8); - registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY); - registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8); + registerSetSlot(ClientboundPackets1_9_3.SET_SLOT); + registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS); + registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT); // Plugin message Packet -> Trading protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() { @@ -66,8 +66,8 @@ public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_12To1_11_1 protocol) { - super(protocol, null, null); + super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY); } @Override public void registerPackets() { - registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8); - registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY); - registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8); + registerSetSlot(ClientboundPackets1_9_3.SET_SLOT); + registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS); + registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT); - // Plugin message Packet -> Trading + // Plugin message -> Trading protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() { @Override public void register() { @@ -107,8 +107,7 @@ public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_13_1To1_13 protocol) { - super(protocol, Type.ITEM1_13, Type.ITEM1_13_ARRAY); + super(protocol, Type.ITEM1_13, Type.ITEM1_13_SHORT_ARRAY); } @Override public void registerPackets() { - registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.ITEM1_13); - registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.ITEM1_13_SHORT_ARRAY); - registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.ITEM1_13); + registerSetSlot(ClientboundPackets1_13.SET_SLOT); + registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS); + registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS); registerSetCooldown(ClientboundPackets1_13.COOLDOWN); protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketHandlers() { @@ -71,7 +71,7 @@ public class InventoryPackets extends ItemRewriter recipeRewriter = new RecipeRewriter(protocol) { @Override @@ -94,9 +94,9 @@ public class InventoryPackets extends ItemRewriter { Short windowId = wrapper.read(Type.UNSIGNED_BYTE); @@ -136,8 +136,8 @@ public class InventoryPackets extends ItemRewriter recipeRewriter = new RecipeRewriter<>(protocol); protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> { @@ -212,7 +212,7 @@ public class InventoryPackets extends ItemRewriter { // Selecting trade now moves the items, we need to resync the inventory @@ -229,9 +229,9 @@ public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_15To1_14_4 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY); } @Override public void registerPackets() { registerSetCooldown(ClientboundPackets1_14_4.COOLDOWN); - registerWindowItems(ClientboundPackets1_14_4.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY); + registerWindowItems(ClientboundPackets1_14_4.WINDOW_ITEMS); registerTradeList(ClientboundPackets1_14_4.TRADE_LIST); - registerSetSlot(ClientboundPackets1_14_4.SET_SLOT, Type.ITEM1_13_2); - registerEntityEquipment(ClientboundPackets1_14_4.ENTITY_EQUIPMENT, Type.ITEM1_13_2); - registerAdvancements(ClientboundPackets1_14_4.ADVANCEMENTS, Type.ITEM1_13_2); + registerSetSlot(ClientboundPackets1_14_4.SET_SLOT); + registerEntityEquipment(ClientboundPackets1_14_4.ENTITY_EQUIPMENT); + registerAdvancements(ClientboundPackets1_14_4.ADVANCEMENTS); new RecipeRewriter<>(protocol).register(ClientboundPackets1_14_4.DECLARE_RECIPES); - registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.ITEM1_13_2); - registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2); + registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW); + registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/InventoryPackets.java index 559071e6d..a95c45374 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/InventoryPackets.java @@ -27,17 +27,17 @@ import com.viaversion.viaversion.rewriter.RecipeRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_16_2To1_16_1 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY); } @Override public void registerPackets() { registerSetCooldown(ClientboundPackets1_16.COOLDOWN); - registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY); + registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS); registerTradeList(ClientboundPackets1_16.TRADE_LIST); - registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.ITEM1_13_2); + registerSetSlot(ClientboundPackets1_16.SET_SLOT); registerEntityEquipmentArray(ClientboundPackets1_16.ENTITY_EQUIPMENT); - registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.ITEM1_13_2); + registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS); protocol.registerClientbound(ClientboundPackets1_16.UNLOCK_RECIPES, wrapper -> { wrapper.passthrough(Type.VAR_INT); @@ -54,10 +54,10 @@ public class InventoryPackets extends ItemRewriter(protocol).register(ClientboundPackets1_16.DECLARE_RECIPES); - registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW, Type.ITEM1_13_2); - registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2); + registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW); + registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION); protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); - registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE); + registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.DOUBLE); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index d25b2a7d5..ff604e3db 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -43,7 +43,7 @@ import java.util.UUID; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_16To1_15_2 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY); } @Override @@ -107,10 +107,10 @@ public class InventoryPackets extends ItemRewriter(protocol).register(ClientboundPackets1_15.DECLARE_RECIPES); - registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.ITEM1_13_2); - registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2); + registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW); + registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION); protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, wrapper -> { InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); @@ -137,7 +137,7 @@ public class InventoryPackets extends ItemRewriter handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); - registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE); + registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.DOUBLE); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java index dcc5f824b..ed8e42fd7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java @@ -36,22 +36,22 @@ import com.viaversion.viaversion.rewriter.RecipeRewriter; public final class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_17To1_16_4 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY); } @Override public void registerPackets() { registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN); - registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY); + registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS); registerTradeList(ClientboundPackets1_16_2.TRADE_LIST); - registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.ITEM1_13_2); - registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.ITEM1_13_2); + registerSetSlot(ClientboundPackets1_16_2.SET_SLOT); + registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS); registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT); - registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE); + registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.DOUBLE); new RecipeRewriter<>(protocol).register(ClientboundPackets1_16_2.DECLARE_RECIPES); - registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2); + registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION); protocol.registerServerbound(ServerboundPackets1_17.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java index e732e2011..af7b7f335 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java @@ -38,7 +38,7 @@ public final class InventoryPackets extends ItemRewriter(protocol).register(ClientboundPackets1_17_1.DECLARE_RECIPES); registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW); - registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2); + registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/InventoryPackets.java index 025ca3bff..707418279 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/InventoryPackets.java @@ -50,11 +50,11 @@ public final class InventoryPackets extends ItemRewriter(protocol) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java index 0c506c250..8015ce262 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/InventoryPackets.java @@ -41,7 +41,7 @@ public final class InventoryPackets extends ItemRewriter itemType; private final Type itemArrayType; - @Deprecated/*(forRemoval = true)*/ - protected ItemRewriter(T protocol) { - this(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); - } - public ItemRewriter(T protocol, Type itemType, Type itemArrayType) { super(protocol); this.itemType = itemType; @@ -65,13 +60,13 @@ public class ItemRewriter type) { + public void registerWindowItems(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override public void register() { map(Type.UNSIGNED_BYTE); // Window id - map(type); // Items - handler(itemArrayToClientHandler(type)); + map(itemArrayType); // Items + handler(itemArrayToClientHandler(itemArrayType)); } }); } @@ -113,14 +108,14 @@ public class ItemRewriter type) { + public void registerSetSlot(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override public void register() { map(Type.UNSIGNED_BYTE); // Window id map(Type.SHORT); // Slot id - map(type); // Item - handler(itemToClientHandler(type)); + map(itemType); // Item + handler(itemToClientHandler(itemType)); } }); } @@ -139,15 +134,15 @@ public class ItemRewriter type) { + public void registerEntityEquipment(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override public void register() { map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 1 - Slot ID - map(type); // 2 - Item + map(itemType); // 2 - Item - handler(itemToClientHandler(type)); + handler(itemToClientHandler(itemType)); } }); } @@ -172,21 +167,17 @@ public class ItemRewriter type) { protocol.registerServerbound(packetType, new PacketHandlers() { @Override public void register() { map(Type.SHORT); // 0 - Slot - map(type); // 1 - Clicked Item - handler(itemToServerHandler(type)); + map(itemType); // 1 - Clicked Item + handler(itemToServerHandler(itemType)); } }); } - public void registerClickWindow(S packetType, Type type) { + public void registerClickWindow(S packetType) { protocol.registerServerbound(packetType, new PacketHandlers() { @Override public void register() { @@ -195,9 +186,9 @@ public class ItemRewriter type) { + public void registerAdvancements(C packetType) { protocol.registerClientbound(packetType, wrapper -> { wrapper.passthrough(Type.BOOLEAN); // Reset/clear int size = wrapper.passthrough(Type.VAR_INT); // Mapping size @@ -296,7 +287,7 @@ public class ItemRewriter itemType, Type coordType) { + public void registerSpawnParticle(C packetType, Type coordType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override public void register() { @@ -462,4 +453,12 @@ public class ItemRewriter type) { return wrapper -> handleItemToServer(wrapper.get(type, 0)); } + + public Type getItemType() { + return itemType; + } + + public Type getItemArrayType() { + return itemArrayType; + } }