From bd09f3e8083d18ff0c8879a5487f07c09ae3de8c Mon Sep 17 00:00:00 2001 From: Dynious Date: Tue, 11 Feb 2014 20:15:14 +0100 Subject: [PATCH] Fixed #626 with stack sizes > 1 --- .../ee3/tileentity/TileCalcinator.java | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java b/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java index 9d3543f3..e8080aa7 100644 --- a/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java +++ b/src/main/java/com/pahimar/ee3/tileentity/TileCalcinator.java @@ -377,27 +377,7 @@ public class TileCalcinator extends TileEE implements IInventory if (this.canCalcinate()) { ItemStack alchemicalDustStack = CalcinationManager.getCalcinationResult(this.inventory[INPUT_INVENTORY_INDEX]); - - if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] == null) - { - this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] = alchemicalDustStack.copy(); - } - else if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack) - && this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize < getInventoryStackLimit() - && this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize < this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].getMaxStackSize()) - { - inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize += alchemicalDustStack.stackSize; - } - else if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] == null) - { - this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] = alchemicalDustStack.copy(); - } - else if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack) - && this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize < getInventoryStackLimit() - && this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize < this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getMaxStackSize()) - { - inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize += alchemicalDustStack.stackSize; - } + addItemStackToOutput(alchemicalDustStack.copy()); this.inventory[INPUT_INVENTORY_INDEX].stackSize--; @@ -408,6 +388,40 @@ public class TileCalcinator extends TileEE implements IInventory } } + private void addItemStackToOutput(ItemStack alchemicalDustStack) + { + int maxStackSize = Math.min(getInventoryStackLimit(), alchemicalDustStack.getMaxStackSize()); + + if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] == null) + { + this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] = alchemicalDustStack; + return; + } + if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack) + && this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize < maxStackSize) + { + int addedSize = Math.min(alchemicalDustStack.stackSize, maxStackSize - this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize); + alchemicalDustStack.stackSize -= addedSize; + this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize += addedSize; + if (alchemicalDustStack == null || alchemicalDustStack.stackSize == 0) + { + return; + } + } + if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] == null) + { + this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] = alchemicalDustStack; + return; + } + if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack) + && this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize < maxStackSize) + { + int addedSize = Math.min(alchemicalDustStack.stackSize, maxStackSize - this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize); + alchemicalDustStack.stackSize -= addedSize; + this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize += addedSize; + } + } + @Override public Packet getDescriptionPacket() {