From b6828aa73dcb96ffc3764ce94797b721869a28e8 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 4 Dec 2024 15:43:49 +0100 Subject: [PATCH] Add missing set_player_inventory handler, update template protocol --- .../template/BlockItemPacketRewriter1_99.java | 23 ++++++------ .../template/ComponentRewriter1_99.java | 2 +- .../template/EntityPacketRewriter1_99.java | 36 +++++++++---------- .../protocol/template/Protocol1_98To1_99.java | 28 +++++++-------- .../BlockItemPacketRewriter1_21_4.java | 1 + 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java index f06d1994..ac657555 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java @@ -19,25 +19,25 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; -import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_4; +import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPacket1_21_4; +import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPackets1_21_4; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; 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.BlockRewriter; import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter; // To replace if needed: // ChunkType1_20_2 -// RecipeRewriter1_20_3 -// Types1_21 -final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter { +// RecipeDisplayRewriter +// Types1_21_4 +final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter { public BlockItemPacketRewriter1_99(final Protocol1_98To1_99 protocol) { - super(protocol, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY); + super(protocol, Types1_21_4.ITEM, Types1_21_4.ITEM_ARRAY); /*super(protocol, - Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY, - Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST + Types1_21_4.ITEM, Types1_21_4.ITEM_ARRAY, Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY, + Types1_21_4.ITEM_COST, Types1_21_4.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST );*/ } @@ -53,14 +53,15 @@ final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter< // registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, this::passthroughClientboundItem); + registerSetPlayerInventory(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY); registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN); registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT); registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT); registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS); registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT); registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS); - registerContainerClick1_21_2(ServerboundPackets1_21_2.CONTAINER_CLICK); - registerSetCreativeModeSlot(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT); + registerContainerClick1_21_2(ServerboundPackets1_21_4.CONTAINER_CLICK); + registerSetCreativeModeSlot(ServerboundPackets1_21_4.SET_CREATIVE_MODE_SLOT); final RecipeDisplayRewriter recipeRewriter = new RecipeDisplayRewriter<>(protocol); recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_2.UPDATE_RECIPES); 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 index 6628f7d1..8ac68b1c 100644 --- 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 @@ -43,6 +43,6 @@ final class ComponentRewriter1_99 extends TranslatableRewriter { public EntityPacketRewriter1_99(final Protocol1_98To1_99 protocol) { - super(protocol, Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType, Types1_20_5.ENTITY_DATA_TYPES.booleanType); + super(protocol, Types1_21_4.ENTITY_DATA_TYPES.optionalComponentType, Types1_21_4.ENTITY_DATA_TYPES.booleanType); } @Override public void registerPackets() { - registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK); - registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, /*Types1_OLD.ENTITY_DATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new entity data list if changed + registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_21_4.FALLING_BLOCK); + registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, /*Types1_OLD.ENTITY_DATA_LIST, */Types1_21_4.ENTITY_DATA_LIST); // Specify old and new entity data list if changed registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES); final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol); @@ -78,22 +78,22 @@ final class EntityPacketRewriter1_99 extends EntityRewriter { +final class Protocol1_98To1_99 extends BackwardsProtocol { // ViaBackwards uses its own mappings and also needs a translatablerewriter for translation mappings public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.99", "1.98", Protocol1_20_5To1_21.class); private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this); private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this); - private final ParticleRewriter particleRewriter = new ParticleRewriter<>(this, Types1_21_2.PARTICLE/*, Types1_OLD.PARTICLE*/); + private final ParticleRewriter particleRewriter = new ParticleRewriter<>(this, Types1_21_4.PARTICLE/*, Types1_OLD.PARTICLE*/); private final TranslatableRewriter translatableRewriter = new ComponentRewriter1_99(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_98To1_99() { - super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_2.class, ServerboundPacket1_21_2.class); + super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_4.class, ServerboundPacket1_21_4.class); } @Override @@ -100,7 +100,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol createPacketTypesProvider() { + protected PacketTypesProvider createPacketTypesProvider() { return new SimplePacketTypesProvider<>( packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), - packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class), - packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class) + packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class), + packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class) ); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java index 701bdf84..7c89988f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java @@ -70,6 +70,7 @@ public final class BlockItemPacketRewriter1_21_4 extends BackwardsStructuredItem protocol.cancelServerbound(ServerboundPackets1_21_2.PICK_ITEM); protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, this::passthroughClientboundItem); + registerSetPlayerInventory(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY); registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN); registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT); registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT);