From 316ae1020e55a4b4779c3c2e24ff3eb03792d1fd Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Sat, 26 Jan 2019 19:25:24 +0100 Subject: [PATCH] remap trading gui 1.131 to 1.13 --- .../packets/InventoryPackets.java | 81 ++++++++++++++----- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java index f1f94122..32c5c3fb 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java @@ -16,30 +16,12 @@ public class InventoryPackets { Outgoing packets */ - // Set slot packet - protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.BYTE); // 0 - Window ID - map(Type.SHORT); // 1 - Slot ID - map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Slot Value - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - Item stack = wrapper.get(Type.FLAT_ITEM, 0); - toClient(stack); - } - }); - } - }); - // Window items packet protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID - map(Type.FLAT_ITEM_ARRAY, Type.FLAT_ITEM_ARRAY); // 1 - Window Values + map(Type.FLAT_ITEM_ARRAY); // 1 - Window Values handler(new PacketHandler() { @Override @@ -52,13 +34,68 @@ public class InventoryPackets { } }); + // Set slot packet + protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.BYTE); // 0 - Window ID + map(Type.SHORT); // 1 - Slot ID + map(Type.FLAT_ITEM); // 2 - Slot Value + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Item stack = wrapper.get(Type.FLAT_ITEM, 0); + toClient(stack); + } + }); + } + }); + + //Plugin Message + protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + String channel = wrapper.passthrough(Type.STRING); + if (channel.equals("minecraft: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 + Item input = wrapper.passthrough(Type.FLAT_ITEM); + toClient(input); + //Output Item + Item output = wrapper.passthrough(Type.FLAT_ITEM); + toClient(input); + + boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item + if (secondItem) { + //Second Item + Item second = wrapper.passthrough(Type.FLAT_ITEM); + toClient(input); + } + + 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 public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 1 - Slot ID - map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Item + map(Type.FLAT_ITEM); // 2 - Item handler(new PacketHandler() { @Override @@ -84,7 +121,7 @@ public class InventoryPackets { map(Type.BYTE); // 2 - Button map(Type.SHORT); // 3 - Action number map(Type.VAR_INT); // 4 - Mode - map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item + map(Type.FLAT_ITEM); // 5 - Clicked Item handler(new PacketHandler() { @Override @@ -102,7 +139,7 @@ public class InventoryPackets { @Override public void registerMap() { map(Type.SHORT); // 0 - Slot - map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item + map(Type.FLAT_ITEM); // 1 - Clicked Item handler(new PacketHandler() { @Override