From cfcb518ddd6c71b8f6538e97a37df65ca6f4b45b Mon Sep 17 00:00:00 2001 From: Raoul Van den Berge Date: Sat, 19 Dec 2015 00:11:37 +0100 Subject: [PATCH] add expxorter tile.. --- .../network/MessageImporterUpdate.java | 20 +-- .../java/storagecraft/tile/TileExporter.java | 138 ++++++++++++++++++ .../storagecraft/tile/TileStorageProxy.java | 50 +------ .../storagecraft/util/InventoryUtils.java | 58 +++++++- 4 files changed, 206 insertions(+), 60 deletions(-) create mode 100644 src/main/java/storagecraft/tile/TileExporter.java diff --git a/src/main/java/storagecraft/network/MessageImporterUpdate.java b/src/main/java/storagecraft/network/MessageImporterUpdate.java index 9a13a02de..73ddcfd37 100644 --- a/src/main/java/storagecraft/network/MessageImporterUpdate.java +++ b/src/main/java/storagecraft/network/MessageImporterUpdate.java @@ -14,10 +14,10 @@ public class MessageImporterUpdate implements IMessage, IMessageHandler slot.getMaxStackSize()) { - toAdd = slot.getMaxStackSize() - slot.stackSize; - } - - slot.stackSize += toAdd; - - toGo -= toAdd; - - if (toGo == 0) { - return; - } - } - } + InventoryUtils.pushToInventory(inventory, stack); } @Override @@ -116,29 +92,7 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I return false; } - int toGo = stack.stackSize; - - for (int i = 0; i < inventory.getSizeInventory(); ++i) { - ItemStack slot = inventory.getStackInSlot(i); - - if (slot == null) { - return true; - } else if (InventoryUtils.compareStackNoQuantity(slot, stack)) { - int toAdd = toGo; - - if (slot.stackSize + toAdd > slot.getMaxStackSize()) { - toAdd = slot.getMaxStackSize() - slot.stackSize; - } - - toGo -= toAdd; - - if (toGo == 0) { - break; - } - } - } - - return toGo == 0; + return InventoryUtils.canPushToInventory(inventory, stack); } @Override diff --git a/src/main/java/storagecraft/util/InventoryUtils.java b/src/main/java/storagecraft/util/InventoryUtils.java index fa8705a4c..dc13e1021 100644 --- a/src/main/java/storagecraft/util/InventoryUtils.java +++ b/src/main/java/storagecraft/util/InventoryUtils.java @@ -88,8 +88,58 @@ public class InventoryUtils { } } - public static boolean compareStackNoQuantity(ItemStack first, ItemStack second) { - return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE); + public static void pushToInventory(IInventory inventory, ItemStack stack) { + int toGo = stack.stackSize; + + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + ItemStack slot = inventory.getStackInSlot(i); + + if (slot == null) { + inventory.setInventorySlotContents(i, stack); + + return; + } else if (compareStackNoQuantity(slot, stack)) { + int toAdd = toGo; + + if (slot.stackSize + toAdd > slot.getMaxStackSize()) { + toAdd = slot.getMaxStackSize() - slot.stackSize; + } + + slot.stackSize += toAdd; + + toGo -= toAdd; + + if (toGo == 0) { + return; + } + } + } + } + + public static boolean canPushToInventory(IInventory inventory, ItemStack stack) { + int toGo = stack.stackSize; + + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + ItemStack slot = inventory.getStackInSlot(i); + + if (slot == null) { + return true; + } else if (compareStackNoQuantity(slot, stack)) { + int toAdd = toGo; + + if (slot.stackSize + toAdd > slot.getMaxStackSize()) { + toAdd = slot.getMaxStackSize() - slot.stackSize; + } + + toGo -= toAdd; + + if (toGo == 0) { + break; + } + } + } + + return toGo == 0; } public static boolean compareStack(ItemStack first, ItemStack second) { @@ -117,4 +167,8 @@ public class InventoryUtils { return first.getItem() == second.getItem(); } + + public static boolean compareStackNoQuantity(ItemStack first, ItemStack second) { + return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE); + } }