diff --git a/common/buildcraft/core/utils/Utils.java b/common/buildcraft/core/utils/Utils.java index c111d0a6..d4bf61d4 100644 --- a/common/buildcraft/core/utils/Utils.java +++ b/common/buildcraft/core/utils/Utils.java @@ -51,6 +51,16 @@ public class Utils { public static final float pipeMaxPos = 0.75F; public static float pipeNormalSpeed = 0.01F; + /** + * Tries to add the passed stack to any valid inventories around the given coordinates. + * @param stack + * @param world + * @param x + * @param y + * @param z + * @param from + * @return ItemStack representing what was added. + */ public static ItemStack addToRandomInventory(ItemStack stack, World world, int x, int y, int z, Orientations from) { LinkedList possibleInventories = new LinkedList(); diff --git a/common/buildcraft/factory/TileAutoWorkbench.java b/common/buildcraft/factory/TileAutoWorkbench.java index cb7bbf89..53d3eba8 100644 --- a/common/buildcraft/factory/TileAutoWorkbench.java +++ b/common/buildcraft/factory/TileAutoWorkbench.java @@ -14,7 +14,8 @@ import java.util.LinkedList; import buildcraft.api.core.Orientations; import buildcraft.api.core.Position; import buildcraft.api.inventory.ISpecialInventory; -import buildcraft.core.utils.StackUtil; +import buildcraft.core.inventory.ITransactor; +import buildcraft.core.inventory.TransactorSimple; import buildcraft.core.utils.Utils; import net.minecraft.src.Container; @@ -283,7 +284,8 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory { /* ISPECIALINVENTORY */ @Override public int addItem(ItemStack stack, boolean doAdd, Orientations from) { - StackUtil stackUtils = new StackUtil(stack); + + ITransactor transactor = new TransactorSimple(this); int minSimilar = Integer.MAX_VALUE; int minSlot = -1; @@ -299,18 +301,17 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory { } if (minSlot != -1) { - if (stackUtils.tryAdding(this, minSlot, doAdd, false)) { - if (doAdd && stack.stackSize != 0) { - addItem(stack, doAdd, from); - } - - return stackUtils.itemsAdded; - } else { - return stackUtils.itemsAdded; - } - } else { + ItemStack added = transactor.add(stack, from, doAdd); + ItemStack remaining = stack.copy(); + remaining.stackSize -= added.stackSize; + + if(doAdd && remaining.stackSize >= 0) + added.stackSize += addItem(remaining, doAdd, from); + + return added.stackSize; + } else return 0; - } + } @Override