From bf5e08403cee988dd5c3c751488be2fb7cd53391 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 13 Jun 2023 23:26:43 -0500 Subject: [PATCH] Fix shift-click crafting with item in hand When shift-clicking the result item in a crafting table while holding an item in your hand, items would bug out completely and cause weird inventory desyncs. --- .../inventory/InventoryTranslator.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java index acecac09c..106613e25 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java @@ -525,10 +525,28 @@ public abstract class InventoryTranslator { int remainder = transferAction.getCount() % resultSize; int timesToCraft = transferAction.getCount() / resultSize; - for (int i = 0; i < timesToCraft; i++) { - plan.add(Click.LEFT, sourceSlot); - plan.add(Click.LEFT, destSlot); + + if (plan.getCursor().isEmpty()) { + // No carried items - move to destination + for (int i = 0; i < timesToCraft; i++) { + plan.add(Click.LEFT, sourceSlot); + plan.add(Click.LEFT, destSlot); + } + } else { + GeyserItemStack cursor = session.getPlayerInventory().getCursor(); + int tempSlot = findTempSlot(inventory, cursor, true, sourceSlot, destSlot); + if (tempSlot == -1) { + return rejectRequest(request); + } + + plan.add(Click.LEFT, tempSlot); //place cursor into temp slot + for (int i = 0; i < timesToCraft; i++) { + plan.add(Click.LEFT, sourceSlot); //pick up source item + plan.add(Click.LEFT, destSlot); //place source item into dest slot + } + plan.add(Click.LEFT, tempSlot); //pick up original item } + if (remainder > 0) { plan.add(Click.LEFT, 0); for (int i = 0; i < remainder; i++) {