From 0986e174a243a9da653b2140a191ae2d7608773e Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 15 Mar 2021 14:50:58 +0100 Subject: [PATCH] Fix drag desync --- .../packets/InventoryPackets.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java index 1c79b8a20..7edc25319 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java @@ -35,7 +35,7 @@ public class InventoryPackets { } }); - // This will likely cause desync issues + // This will cause desync issues to clients with a high latency protocol.registerIncoming(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() { @Override public void registerMap() { @@ -43,7 +43,7 @@ public class InventoryPackets { map(Type.SHORT); // Slot map(Type.BYTE); // Button create(wrapper -> wrapper.write(Type.SHORT, (short) 0)); // Action id - doesn't matter, as the sent out confirmation packet will be cancelled - map(Type.VAR_INT); // Mode + map(Type.VAR_INT); // Action handler(wrapper -> { // Affected items - throw them away! @@ -53,13 +53,23 @@ public class InventoryPackets { wrapper.read(Type.FLAT_VAR_INT_ITEM); } - // Carried item - toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); + // 1.17 clients send the then carried item, but 1.16 expects the clicked one + Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM); + int action = wrapper.get(Type.VAR_INT, 0); + if (action == 5) { + // Quick craft (= dragging / mouse movement while clicking on an empty slot) + // The server always expects an empty item here + item = null; + } else { + // Use the item sent + toServer(item); + } + + wrapper.write(Type.FLAT_VAR_INT_ITEM, item); }); } }); - //TODO fix drags not working at all, try to work against desync issues with keepalive abuise protocol.registerOutgoing(ClientboundPackets1_16_2.WINDOW_CONFIRMATION, null, new PacketRemapper() { @Override public void registerMap() {