|
26 | 26 | import com.viaversion.viabackwards.api.rewriters.MapColorRewriter; |
27 | 27 | import com.viaversion.viabackwards.protocol.v1_17to1_16_4.Protocol1_17To1_16_4; |
28 | 28 | import com.viaversion.viabackwards.protocol.v1_17to1_16_4.data.MapColorMappings1_16_4; |
| 29 | +import com.viaversion.viabackwards.protocol.v1_17_1to1_17.storage.InventoryStateIds; |
29 | 30 | import com.viaversion.viabackwards.protocol.v1_17to1_16_4.storage.PlayerLastCursorItem; |
30 | 31 | import com.viaversion.viaversion.api.data.entity.EntityTracker; |
31 | 32 | import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; |
@@ -83,8 +84,26 @@ public void register() { |
83 | 84 | int mode = wrapper.passthrough(Types.VAR_INT); // Mode |
84 | 85 | Item clicked = handleItemToServer(wrapper.user(), wrapper.read(Types.ITEM1_13_2)); // Clicked item |
85 | 86 |
|
86 | | - // The 1.17 client would check the entire inventory for changes before -> after a click and send the changed slots here |
87 | | - wrapper.write(Types.VAR_INT, 0); // Empty array of slot+item |
| 87 | + // The 1.17 client would check the entire inventory for changes before -> after a click |
| 88 | + // and send the changed slots here. We include the clicked slot so the server |
| 89 | + // detects any desync (e.g. cancelled InventoryClickEvent) and sends corrections. |
| 90 | + if (slot >= 0 && clicked != null) { |
| 91 | + wrapper.write(Types.VAR_INT, 1); // One modified slot |
| 92 | + wrapper.write(Types.SHORT, slot); // The clicked slot |
| 93 | + wrapper.write(Types.ITEM1_13_2, (Item) null); // Predicted: empty (item picked up) |
| 94 | + } else { |
| 95 | + wrapper.write(Types.VAR_INT, 0); // Empty array of slot+item |
| 96 | + } |
| 97 | + |
| 98 | + // Non-PICKUP modes (shift-click, swap, throw, drag, etc.) affect multiple slots |
| 99 | + // that we can't easily predict. Force a state ID mismatch so the server |
| 100 | + // sends a full inventory resync instead of individual slot corrections. |
| 101 | + if (mode != 0) { |
| 102 | + InventoryStateIds stateIds = wrapper.user().get(InventoryStateIds.class); |
| 103 | + if (stateIds != null) { |
| 104 | + stateIds.setStateId(wrapper.get(Types.BYTE, 0), -1); |
| 105 | + } |
| 106 | + } |
88 | 107 |
|
89 | 108 | PlayerLastCursorItem state = wrapper.user().get(PlayerLastCursorItem.class); |
90 | 109 | if (mode == 0 && button == 0 && clicked != null) { |
|
0 commit comments