From 30fea5f435098d2089444952d8bc02db5dcf41e7 Mon Sep 17 00:00:00 2001 From: IndigoPolecat <115671621+IndigoPolecat@users.noreply.github.com> Date: Sun, 4 Aug 2024 08:04:09 -0600 Subject: Fix slot binding in chest or non-player GUIs (#1189) Co-authored-by: nopo --- .../notenoughupdates/miscfeatures/SlotLocking.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index c3313375..f67ece5a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -495,15 +495,23 @@ public class SlotLocking { LockedSlot boundLocked = getLockedSlot(boundSlot); + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { + return; + } + GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen; + int size = container.inventorySlots.inventorySlots.size(); + int from, to; int id = slotClickEvent.slot.getSlotIndex(); - if (id >= 9 && 0 <= locked.boundTo && locked.boundTo < 8 && !boundLocked.locked) { - from = id; + int idChest = id + (size - 45); // adjust the id of the clicked slot to align with the current inventory's number of slots + + if (idChest >= 9 && 0 <= locked.boundTo && locked.boundTo < 8 && !boundLocked.locked) { + from = idChest; to = locked.boundTo; if (boundLocked == DEFAULT_LOCKED_SLOT) { LockedSlot[] lockedSlots = getDataForProfile(); lockedSlots[locked.boundTo] = new LockedSlot(); - lockedSlots[locked.boundTo].boundTo = id; + lockedSlots[locked.boundTo].boundTo = idChest; } else { boundLocked.boundTo = id; } -- cgit