From 0479af7cd3ef13edc632c3b88ab5ddee94326d6b Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 8 Feb 2022 23:15:41 -0500 Subject: [PATCH] Restore ClickPlan double-simulation This is used in some autocrafting situations. Oops. --- .../geysermc/geyser/inventory/click/ClickPlan.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java index 45d535167..b0cca53d9 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java @@ -75,6 +75,11 @@ public final class ClickPlan { gridSize = translator.getGridSize(); } + private void resetSimulation() { + this.simulatedItems.clear(); + this.simulatedCursor = session.getPlayerInventory().getCursor().copy(); + } + public void add(Click click, int slot) { add(click, slot, false); } @@ -89,10 +94,14 @@ public final class ClickPlan { ClickAction action = new ClickAction(click, slot, force); plan.add(action); + // RUNNING THE SIMULATION HERE IS IMPORTANT. The contents of the simulation are used in complex, multi-stage tasks + // such as autocrafting. + simulateAction(action); } public void execute(boolean refresh) { //update geyser inventory after simulation to avoid net id desync + resetSimulation(); ListIterator planIter = plan.listIterator(); while (planIter.hasNext()) { ClickAction action = planIter.next(); @@ -190,7 +199,9 @@ public final class ClickPlan { * Does not need to be called for the cursor */ private void onSlotItemChange(int slot, GeyserItemStack itemStack) { - changedItems.put(slot, itemStack.getItemStack()); + if (changedItems != null) { + changedItems.put(slot, itemStack.getItemStack()); + } } private void simulateAction(ClickAction action) {