diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2021-12-22 17:56:19 +0200 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2021-12-22 17:56:19 +0200 |
commit | 23df2a0eeb7e9990c7be7d3eaf27dc353f4de889 (patch) | |
tree | b5f702cfa8a5b939557e6e9562b27734939d3ca7 | |
parent | 6fd28c14b331e99990331351eae5bc9103530d94 (diff) | |
download | LibGui-23df2a0eeb7e9990c7be7d3eaf27dc353f4de889.tar.gz LibGui-23df2a0eeb7e9990c7be7d3eaf27dc353f4de889.tar.bz2 LibGui-23df2a0eeb7e9990c7be7d3eaf27dc353f4de889.zip |
Move custom quick move implementation from onSlotClick to transferSlot
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java | 67 |
1 files changed, 28 insertions, 39 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index ebf9e56..f97842d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -132,51 +132,40 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio public void addSlotPeer(ValidatedSlot slot) { this.addSlot(slot); } - + @Override - public void onSlotClick(int slotNumber, int button, SlotActionType action, PlayerEntity player) { - if (action==SlotActionType.QUICK_MOVE) { - - if (slotNumber < 0) { - return; - } - - if (slotNumber>=this.slots.size()) return; - Slot slot = this.slots.get(slotNumber); - if (slot == null || !slot.canTakeItems(player)) { - return; - } - - ItemStack remaining = ItemStack.EMPTY; - if (slot != null && slot.hasStack()) { - ItemStack toTransfer = slot.getStack(); - remaining = toTransfer.copy(); - //if (slot.inventory==blockInventory) { - if (blockInventory!=null) { - if (slot.inventory==blockInventory) { - //Try to transfer the item from the block into the player's inventory - if (!this.insertItem(toTransfer, this.playerInventory, true, player)) { - return; - } - } else if (!this.insertItem(toTransfer, this.blockInventory, false, player)) { //Try to transfer the item from the player to the block - return; - } - } else { - //There's no block, just swap between the player's storage and their hotbar - if (!swapHotbar(toTransfer, slotNumber, this.playerInventory, player)) { - return; + public ItemStack transferSlot(PlayerEntity player, int index) { + ItemStack result = ItemStack.EMPTY; + Slot slot = slots.get(index); + + if (slot.hasStack()) { + ItemStack slotStack = slot.getStack(); + result = slotStack.copy(); + + if (blockInventory!=null) { + if (slot.inventory==blockInventory) { + //Try to transfer the item from the block into the player's inventory + if (!this.insertItem(slotStack, this.playerInventory, true, player)) { + return ItemStack.EMPTY; } + } else if (!this.insertItem(slotStack, this.blockInventory, false, player)) { //Try to transfer the item from the player to the block + return ItemStack.EMPTY; } - - if (toTransfer.isEmpty()) { - slot.setStack(ItemStack.EMPTY); - } else { - slot.markDirty(); + } else { + //There's no block, just swap between the player's storage and their hotbar + if (!swapHotbar(slotStack, index, this.playerInventory, player)) { + return ItemStack.EMPTY; } } - } else { - super.onSlotClick(slotNumber, button, action, player); + + if (slotStack.isEmpty()) { + slot.setStack(ItemStack.EMPTY); + } else { + slot.markDirty(); + } } + + return result; } /** WILL MODIFY toInsert! Returns true if anything was inserted. */ |