From 3d1d73a81a0be4306d82b5438b4cfb05bbaa00e1 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Wed, 22 Aug 2018 17:05:46 -0300 Subject: [PATCH] Rewrite declare recipes and villager gui --- .../packets/InventoryPackets.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java index 0c365a2ce..98f827e83 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java @@ -52,6 +52,41 @@ public class InventoryPackets { } }); + // Plugin message + protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); // Channel + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + String channel = wrapper.get(Type.STRING, 0); + if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) { + wrapper.passthrough(Type.INT); // Passthrough Window ID + + int size = wrapper.passthrough(Type.UNSIGNED_BYTE); + for (int i = 0; i < size; i++) { + // Input Item + toClient(wrapper.passthrough(Type.FLAT_ITEM)); + // Output Item + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); + + boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item + if (secondItem) { + // Second Item + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); + } + + wrapper.passthrough(Type.BOOLEAN); // Trade disabled + wrapper.passthrough(Type.INT); // Number of tools uses + wrapper.passthrough(Type.INT); // Maximum number of trade uses + } + } + } + }); + } + }); + // Entity Equipment Packet protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { @Override @@ -70,6 +105,55 @@ public class InventoryPackets { } }); + // Declare Recipes + protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int recipesNo = wrapper.passthrough(Type.VAR_INT); + for (int i = 0; i < recipesNo; i++) { + wrapper.passthrough(Type.STRING); // Id + String type = wrapper.passthrough(Type.STRING); + if (type.equals("crafting_shapeless")) { + wrapper.passthrough(Type.STRING); // Group + int ingredientsNo = wrapper.passthrough(Type.VAR_INT); + for (int i1 = 0; i1 < ingredientsNo; i1++) { + Item[] items = wrapper.passthrough(Type.FLAT_ITEM_ARRAY); + for (int i2 = 0; i2 < items.length; i2++) { + InventoryPackets.toClient(items[i2]); + } + } + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Result + } else if (type.equals("crafting_shaped")) { + int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); + wrapper.passthrough(Type.STRING); // Group + for (int i1 = 0; i1 < ingredientsNo; i1++) { + Item[] items = wrapper.passthrough(Type.FLAT_ITEM_ARRAY); + for (int i2 = 0; i2 < items.length; i2++) { + InventoryPackets.toClient(items[i2]); + } + } + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Result + } else if (type.equals("smelting")) { + wrapper.passthrough(Type.STRING); // Group + // Ingredient start + Item[] items = wrapper.passthrough(Type.FLAT_ITEM_ARRAY); + for (int i2 = 0; i2 < items.length; i2++) { + InventoryPackets.toClient(items[i2]); + } + // Ingredient end + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); + wrapper.passthrough(Type.FLOAT); // EXP + wrapper.passthrough(Type.VAR_INT); // Cooking time + } + } + } + }); + } + }); + /* Incoming packets