diff options
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java index 54038ec..807cfc0 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java @@ -113,15 +113,15 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple 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)) { + if (!this.insertItem(toTransfer, this.playerInventory, true, player)) { return ItemStack.EMPTY; } - } else if (!this.insertItem(toTransfer, this.blockInventory, false)) { //Try to transfer the item from the player to the block + } else if (!this.insertItem(toTransfer, this.blockInventory, false, player)) { //Try to transfer the item from the player to the block return ItemStack.EMPTY; } } else { //There's no block, just swap between the player's storage and their hotbar - if (!swapHotbar(toTransfer, slotNumber, this.playerInventory)) { + if (!swapHotbar(toTransfer, slotNumber, this.playerInventory, player)) { return ItemStack.EMPTY; } } @@ -140,9 +140,9 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple } /** WILL MODIFY toInsert! Returns true if anything was inserted. */ - private boolean insertIntoExisting(ItemStack toInsert, Slot slot) { + private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) { ItemStack curSlotStack = slot.getStack(); - if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack)) { + if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canTakeItems(player)) { int combinedAmount = curSlotStack.getCount() + toInsert.getCount(); if (combinedAmount <= toInsert.getMaxCount()) { toInsert.setCount(0); @@ -176,7 +176,7 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple return false; } - private boolean insertItem(ItemStack toInsert, Inventory inventory, boolean walkBackwards) { + private boolean insertItem(ItemStack toInsert, Inventory inventory, boolean walkBackwards, PlayerEntity player) { //Make a unified list of slots *only from this inventory* ArrayList<Slot> inventorySlots = new ArrayList<>(); for(Slot slot : slots) { @@ -189,13 +189,13 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple if (walkBackwards) { for(int i=inventorySlots.size()-1; i>=0; i--) { Slot curSlot = inventorySlots.get(i); - if (insertIntoExisting(toInsert, curSlot)) inserted = true; + if (insertIntoExisting(toInsert, curSlot, player)) inserted = true; if (toInsert.isEmpty()) break; } } else { for(int i=0; i<inventorySlots.size(); i++) { Slot curSlot = inventorySlots.get(i); - if (insertIntoExisting(toInsert, curSlot)) inserted = true; + if (insertIntoExisting(toInsert, curSlot, player)) inserted = true; if (toInsert.isEmpty()) break; } @@ -222,7 +222,7 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple return inserted; } - private boolean swapHotbar(ItemStack toInsert, int slotNumber, Inventory inventory) { + private boolean swapHotbar(ItemStack toInsert, int slotNumber, Inventory inventory, PlayerEntity player) { //Feel out the slots to see what's storage versus hotbar ArrayList<Slot> storageSlots = new ArrayList<>(); ArrayList<Slot> hotbarSlots = new ArrayList<>(); @@ -246,7 +246,7 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple //swap from hotbar to storage for(int i=0; i<storageSlots.size(); i++) { Slot curSlot = storageSlots.get(i); - if (insertIntoExisting(toInsert, curSlot)) inserted = true; + if (insertIntoExisting(toInsert, curSlot, player)) inserted = true; if (toInsert.isEmpty()) break; } if (!toInsert.isEmpty()) { @@ -260,7 +260,7 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple //swap from storage to hotbar for(int i=0; i<hotbarSlots.size(); i++) { Slot curSlot = hotbarSlots.get(i); - if (insertIntoExisting(toInsert, curSlot)) inserted = true; + if (insertIntoExisting(toInsert, curSlot, player)) inserted = true; if (toInsert.isEmpty()) break; } if (!toInsert.isEmpty()) { @@ -343,13 +343,19 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple Block b = state.getBlock(); if (b instanceof InventoryProvider) { - return ((InventoryProvider)b).getInventory(state, world, pos); + Inventory inventory = ((InventoryProvider)b).getInventory(state, world, pos); + if (inventory != null) { + return inventory; + } } BlockEntity be = world.getBlockEntity(pos); if (be!=null) { if (be instanceof InventoryProvider) { - return ((InventoryProvider)be).getInventory(state, world, pos); + Inventory inventory = ((InventoryProvider)be).getInventory(state, world, pos); + if (inventory != null) { + return inventory; + } } else if (be instanceof Inventory) { return (Inventory)be; } |