From ecde898be7eea9c6c9f584a0a7c550248d85c57d Mon Sep 17 00:00:00 2001 From: Raoul Van den Berge Date: Sun, 20 Mar 2016 21:57:09 +0100 Subject: [PATCH] Add functionality for interfaces --- .../container/ContainerBase.java | 4 + .../refinedstorage/tile/TileInterface.java | 76 ++++++++++++++++++- .../refinedstorage/util/InventoryUtils.java | 2 +- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/main/java/refinedstorage/container/ContainerBase.java b/src/main/java/refinedstorage/container/ContainerBase.java index 19b8349d9..896aa5cf4 100644 --- a/src/main/java/refinedstorage/container/ContainerBase.java +++ b/src/main/java/refinedstorage/container/ContainerBase.java @@ -63,6 +63,10 @@ public abstract class ContainerBase extends Container if (slot instanceof SlotSpecimen) { + // @TODO: Put whole the stack if left click + // @TODO: Put one item from stack if right click + // @TODO: If item is already there, on left / right click add 1 or remove 1 + // @TODO: If click with empty stack, empty it out if (clickedButton == 2 || player.inventory.getItemStack() == null) { slot.putStack(null); diff --git a/src/main/java/refinedstorage/tile/TileInterface.java b/src/main/java/refinedstorage/tile/TileInterface.java index a47d600dd..ded8cea32 100644 --- a/src/main/java/refinedstorage/tile/TileInterface.java +++ b/src/main/java/refinedstorage/tile/TileInterface.java @@ -12,9 +12,6 @@ import refinedstorage.util.InventoryUtils; public class TileInterface extends TileMachine implements ISidedInventory { - // 1st row for import - // 2st row for specimen to export - // 3st row for export private InventorySimple inventory = new InventorySimple("interface", 9 * 3); @Override @@ -26,6 +23,79 @@ public class TileInterface extends TileMachine implements ISidedInventory @Override public void updateMachine() { + for (int i = 0; i < 9; ++i) + { + if (inventory.getStackInSlot(i) != null) + { + ItemStack slot = inventory.getStackInSlot(i); + + if (getController().push(slot)) + { + inventory.setInventorySlotContents(i, null); + } + } + } + + for (int i = 9; i < 18; ++i) + { + ItemStack wanted = inventory.getStackInSlot(i); + ItemStack got = inventory.getStackInSlot(i + 9); + + if (wanted != null) + { + boolean ok = false; + + if (got != null) + { + if (!InventoryUtils.compareStackNoQuantity(wanted, got)) + { + if (getController().push(got)) + { + inventory.setInventorySlotContents(i + 9, null); + } + } + else + { + ok = true; + } + } + else + { + ok = true; + } + + if (ok) + { + got = inventory.getStackInSlot(i + 9); + + int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize; + + ItemStack goingToTake = wanted.copy(); + goingToTake.stackSize = needed; + + ItemStack took = getController().take(goingToTake); + + if (took != null) + { + if (got == null) + { + inventory.setInventorySlotContents(i + 9, took); + } + else + { + got.stackSize += took.stackSize; + } + } + } + } + else if (got != null) + { + if (getController().push(got)) + { + inventory.setInventorySlotContents(i + 9, null); + } + } + } } @Override diff --git a/src/main/java/refinedstorage/util/InventoryUtils.java b/src/main/java/refinedstorage/util/InventoryUtils.java index efff65cdd..f5263cd01 100644 --- a/src/main/java/refinedstorage/util/InventoryUtils.java +++ b/src/main/java/refinedstorage/util/InventoryUtils.java @@ -174,7 +174,7 @@ public class InventoryUtils for (int i = 0; i < inventory.getSizeInventory(); ++i) { - // @TODO: This is experimental + // @TODO: Test this better if (!inventory.isItemValidForSlot(i, stack)) { continue;