diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java deleted file mode 100644 index 300897ef..00000000 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java +++ /dev/null @@ -1,33 +0,0 @@ -package nl.matsv.viabackwards.api.rewriters; - -import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.protocol.ClientboundPacketType; -import us.myles.ViaVersion.api.remapper.PacketRemapper; -import us.myles.ViaVersion.api.type.Type; - -public abstract class RecipeRewriter { - - protected final ItemRewriterBase rewriter; - - protected RecipeRewriter(ItemRewriterBase rewriter) { - this.rewriter = rewriter; - } - - public abstract void handle(PacketWrapper wrapper, String type) throws Exception; - - public void registerDefaultHandler(ClientboundPacketType packetType) { - rewriter.getProtocol().registerOutgoing(packetType, new PacketRemapper() { - @Override - public void registerMap() { - handler(wrapper -> { - int size = wrapper.passthrough(Type.VAR_INT); - for (int i = 0; i < size; i++) { - String type = wrapper.passthrough(Type.STRING).replace("minecraft:", ""); - String id = wrapper.passthrough(Type.STRING); // Recipe Identifier - handle(wrapper, type); - } - }); - } - }); - } -} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java index 56f4dec1..26b9d61d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java @@ -56,47 +56,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol Plugin Message protocol.registerOutgoing(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @@ -282,12 +283,12 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); + RecipeRewriter recipeHandler = new RecipeRewriter1_14(protocol, this::handleItemToClient); protocol.registerOutgoing(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() { // c @Override public void registerMap() { handler(new PacketHandler() { private final Set removedTypes = ImmutableSet.of("crafting_special_suspiciousstew", "blasting", "smoking", "campfire_cooking", "stonecutting"); - private final RecipeRewriter recipeHandler = new RecipeRewriter1_14(BlockItemPackets1_14.this); @Override public void handle(PacketWrapper wrapper) throws Exception { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java index 5e1a2495..872b16f4 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java @@ -12,7 +12,6 @@ import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPack import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets.EntityPackets1_15; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.TagRewriter; import us.myles.ViaVersion.api.type.Type; @@ -80,45 +79,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java deleted file mode 100644 index 793644fa..00000000 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java +++ /dev/null @@ -1,45 +0,0 @@ -package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data; - -import nl.matsv.viabackwards.api.rewriters.ItemRewriterBase; -import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.RecipeRewriter1_14; -import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.minecraft.item.Item; -import us.myles.ViaVersion.api.type.Type; - -public class RecipeRewriter1_15 extends RecipeRewriter1_14 { - - public RecipeRewriter1_15(ItemRewriterBase rewriter) { - super(rewriter); - } - - @Override - public void handle(PacketWrapper wrapper, String type) throws Exception { - switch (type) { - case "crafting_shapeless": - handleCraftingShapeless(wrapper); - break; - case "crafting_shaped": - handleCraftingShaped(wrapper); - break; - case "blasting": // new - case "smoking": // new - case "campfire_cooking": // new - case "smelting": - handleSmelting(wrapper); - break; - case "stonecutting": // new - handleStonecutting(wrapper); - break; - } - } - - public void handleStonecutting(PacketWrapper wrapper) throws Exception { - wrapper.passthrough(Type.STRING); - Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients - for (Item item : items) { - rewriter.handleItemToClient(item); - } - - rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result - } -} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java index 6b419b4d..7183abe5 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java @@ -5,7 +5,6 @@ import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping; -import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; @@ -19,6 +18,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14 import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.RecipeRewriter1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -33,7 +33,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_14_4To1_15::getNewBlockStateId, Protocol1_14_4To1_15::getNewBlockId); - new RecipeRewriter1_15(this).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES); + new RecipeRewriter1_15(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES); protocol.registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() { @Override @@ -45,47 +45,9 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN, BlockItemPackets1_15::getOldItemId); itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - - protocol.registerOutgoing(ClientboundPackets1_15.TRADE_LIST, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.passthrough(Type.VAR_INT); - int size = wrapper.passthrough(Type.UNSIGNED_BYTE); - for (int i = 0; i < size; i++) { - Item input = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(input); - - Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(output); - - if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item - // Second Item - Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(second); - } - - wrapper.passthrough(Type.BOOLEAN); - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.INT); - - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.FLOAT); - wrapper.passthrough(Type.INT); - } - - wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.BOOLEAN); - } - }); - } - }); - + itemRewriter.registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java index 29d166e5..cbe5f508 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java @@ -95,42 +95,6 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { - wrapper.passthrough(Type.BOOLEAN); // Reset/clear - int size = wrapper.passthrough(Type.VAR_INT); - for (int i = 0; i < size; i++) { - wrapper.passthrough(Type.STRING); // Identifier - // Parent - if (wrapper.passthrough(Type.BOOLEAN)) { - wrapper.passthrough(Type.STRING); - } - // Display data - if (wrapper.passthrough(Type.BOOLEAN)) { - wrapper.passthrough(Type.COMPONENT); // Title - wrapper.passthrough(Type.COMPONENT); // Description - blockItemPackets.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Icon - wrapper.passthrough(Type.VAR_INT); // Frame type - int flags = wrapper.passthrough(Type.INT); // Flags - if ((flags & 1) != 0) { - wrapper.passthrough(Type.STRING); // Background texture - } - wrapper.passthrough(Type.FLOAT); // X - wrapper.passthrough(Type.FLOAT); // Y - } - - wrapper.passthrough(Type.STRING_ARRAY); // Criteria - int arrayLength = wrapper.passthrough(Type.VAR_INT); - for (int array = 0; array < arrayLength; array++) { - wrapper.passthrough(Type.STRING_ARRAY); // String array - } - } - }); - } - }); - registerOutgoing(ClientboundPackets1_16.STATISTICS, new PacketRemapper() { @Override public void registerMap() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java deleted file mode 100644 index d1795761..00000000 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java +++ /dev/null @@ -1,84 +0,0 @@ -package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data; - -import nl.matsv.viabackwards.api.rewriters.ItemRewriterBase; -import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15; -import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.minecraft.item.Item; -import us.myles.ViaVersion.api.protocol.ClientboundPacketType; -import us.myles.ViaVersion.api.remapper.PacketRemapper; -import us.myles.ViaVersion.api.type.Type; - -public class RecipeRewriter1_16 extends RecipeRewriter1_15 { - - public RecipeRewriter1_16(ItemRewriterBase rewriter) { - super(rewriter); - } - - public void register(ClientboundPacketType packetType) { - // Remove new smithing type, only in this handler - rewriter.getProtocol().registerOutgoing(packetType, new PacketRemapper() { - @Override - public void registerMap() { - handler(wrapper -> { - int size = wrapper.passthrough(Type.VAR_INT); - int newSize = size; - for (int i = 0; i < size; i++) { - String originalType = wrapper.read(Type.STRING); - String type = originalType.replace("minecraft:", ""); - if (type.equals("smithing")) { - newSize--; - - wrapper.read(Type.STRING); - wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); - wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); - wrapper.read(Type.FLAT_VAR_INT_ITEM); - continue; - } - - wrapper.write(Type.STRING, originalType); - String id = wrapper.passthrough(Type.STRING); // Recipe Identifier - handle(wrapper, type); - } - - wrapper.set(Type.VAR_INT, 0, newSize); - }); - } - }); - } - - @Override - public void handle(PacketWrapper wrapper, String type) throws Exception { - switch (type) { - case "crafting_shapeless": - handleCraftingShapeless(wrapper); - break; - case "crafting_shaped": - handleCraftingShaped(wrapper); - break; - case "blasting": - case "smoking": - case "campfire_cooking": - case "smelting": - handleSmelting(wrapper); - break; - case "stonecutting": - handleStonecutting(wrapper); - break; - case "smithing": // new - handleSmithing(wrapper); - break; - } - } - - public void handleSmithing(PacketWrapper wrapper) throws Exception { - Item[] baseIngredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); - for (Item item : baseIngredients) { - rewriter.handleItemToClient(item); - } - Item[] ingredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); - for (Item item : ingredients) { - rewriter.handleItemToClient(item); - } - rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result - } -} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 19c92812..88197dae 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -6,7 +6,6 @@ import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewriter; -import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.RecipeRewriter1_16; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; @@ -22,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.util.CompactArrayUtil; @@ -49,47 +49,42 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15_2To1_16::getNewBlockStateId, Protocol1_15_2To1_16::getNewBlockId); - new RecipeRewriter1_16(this).register(ClientboundPackets1_16.DECLARE_RECIPES); + RecipeRewriter1_16 recipeRewriter = new RecipeRewriter1_16(protocol, this::handleItemToClient); + // Remove new smithing type, only in this handler + protocol.registerOutgoing(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + int size = wrapper.passthrough(Type.VAR_INT); + int newSize = size; + for (int i = 0; i < size; i++) { + String originalType = wrapper.read(Type.STRING); + String type = originalType.replace("minecraft:", ""); + if (type.equals("smithing")) { + newSize--; + + wrapper.read(Type.STRING); + wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); + wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); + wrapper.read(Type.FLAT_VAR_INT_ITEM); + continue; + } + + wrapper.write(Type.STRING, originalType); + String id = wrapper.passthrough(Type.STRING); // Recipe Identifier + recipeRewriter.handle(wrapper, type); + } + + wrapper.set(Type.VAR_INT, 0, newSize); + }); + } + }); itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, BlockItemPackets1_16::getOldItemId); itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - - protocol.registerOutgoing(ClientboundPackets1_16.TRADE_LIST, new PacketRemapper() { - @Override - public void registerMap() { - handler(wrapper -> { - wrapper.passthrough(Type.VAR_INT); - int size = wrapper.passthrough(Type.UNSIGNED_BYTE); - for (int i = 0; i < size; i++) { - Item input = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(input); - - Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(output); - - if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item - // Second Item - Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(second); - } - - wrapper.passthrough(Type.BOOLEAN); - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.INT); - - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.FLOAT); - wrapper.passthrough(Type.INT); - } - - wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.BOOLEAN); - }); - } - }); + itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM); blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING); blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/Protocol1_16_1To1_16_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/Protocol1_16_1To1_16_2.java index f8e0f03b..c1f5a945 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/Protocol1_16_1To1_16_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/Protocol1_16_1To1_16_2.java @@ -55,42 +55,6 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol { - wrapper.passthrough(Type.BOOLEAN); // Reset/clear - int size = wrapper.passthrough(Type.VAR_INT); - for (int i = 0; i < size; i++) { - wrapper.passthrough(Type.STRING); // Identifier - // Parent - if (wrapper.passthrough(Type.BOOLEAN)) { - wrapper.passthrough(Type.STRING); - } - // Display data - if (wrapper.passthrough(Type.BOOLEAN)) { - wrapper.passthrough(Type.COMPONENT); // Title - wrapper.passthrough(Type.COMPONENT); // Description - blockItemPackets.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Icon - wrapper.passthrough(Type.VAR_INT); // Frame type - int flags = wrapper.passthrough(Type.INT); // Flags - if ((flags & 1) != 0) { - wrapper.passthrough(Type.STRING); // Background texture - } - wrapper.passthrough(Type.FLOAT); // X - wrapper.passthrough(Type.FLOAT); // Y - } - - wrapper.passthrough(Type.STRING_ARRAY); // Criteria - int arrayLength = wrapper.passthrough(Type.VAR_INT); - for (int array = 0; array < arrayLength; array++) { - wrapper.passthrough(Type.STRING_ARRAY); // String array - } - } - }); - } - }); - // Recipe book data has been split into 2 separate packets registerIncoming(ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() { @Override diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java index 44359f47..583f3d29 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java @@ -3,12 +3,10 @@ package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; -import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.RecipeRewriter1_16; import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2; import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data.BackwardsMappings; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; -import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.BlockRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter; @@ -16,6 +14,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -33,12 +32,14 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters. ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16_1To1_16_2::getNewBlockStateId, Protocol1_16_1To1_16_2::getNewBlockId); - new RecipeRewriter1_16(this).register(ClientboundPackets1_16.DECLARE_RECIPES); + new RecipeRewriter1_16(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_16.DECLARE_RECIPES); itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, BlockItemPackets1_16_2::getOldItemId); itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM); itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_16.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM); protocol.registerOutgoing(ClientboundPackets1_16.UNLOCK_RECIPES, new PacketRemapper() { @Override @@ -58,42 +59,6 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters. } }); - protocol.registerOutgoing(ClientboundPackets1_16.TRADE_LIST, new PacketRemapper() { - @Override - public void registerMap() { - handler(wrapper -> { - wrapper.passthrough(Type.VAR_INT); - int size = wrapper.passthrough(Type.UNSIGNED_BYTE); - for (int i = 0; i < size; i++) { - Item input = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(input); - - Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(output); - - if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item - // Second Item - Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - handleItemToClient(second); - } - - wrapper.passthrough(Type.BOOLEAN); - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.INT); - - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.INT); - wrapper.passthrough(Type.FLOAT); - wrapper.passthrough(Type.INT); - } - - wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.VAR_INT); - wrapper.passthrough(Type.BOOLEAN); - }); - } - }); - blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING); blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);