diff --git a/common/buildcraft/robotics/ai/AIRobotFetchAndEquipItemStack.java b/common/buildcraft/robotics/ai/AIRobotFetchAndEquipItemStack.java index 2c529243..05d80ec7 100755 --- a/common/buildcraft/robotics/ai/AIRobotFetchAndEquipItemStack.java +++ b/common/buildcraft/robotics/ai/AIRobotFetchAndEquipItemStack.java @@ -18,6 +18,7 @@ import buildcraft.core.lib.inventory.Transactor; import buildcraft.core.lib.inventory.filters.AggregateFilter; import buildcraft.core.lib.inventory.filters.IStackFilter; import buildcraft.robotics.statements.ActionRobotFilterTool; +import buildcraft.robotics.statements.ActionStationProvideItems; public class AIRobotFetchAndEquipItemStack extends AIRobot { @@ -79,15 +80,11 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot { return false; } - ITransactor trans = Transactor.getTransactorFor(tileInventory); - - ItemStack itemFound = trans.remove(filter, robot.getDockingStation().getItemInputSide(), true); - - if (itemFound != null) { - robot.setItemInUse(itemFound); - return true; + ItemStack possible = AIRobotLoad.takeSingle(robot.getDockingStation(), filter, true); + if (possible == null) { + return false; } - - return false; + robot.setItemInUse(possible); + return true; } } diff --git a/common/buildcraft/robotics/ai/AIRobotLoad.java b/common/buildcraft/robotics/ai/AIRobotLoad.java index 4cc31053..a8ed3475 100755 --- a/common/buildcraft/robotics/ai/AIRobotLoad.java +++ b/common/buildcraft/robotics/ai/AIRobotLoad.java @@ -57,6 +57,43 @@ public class AIRobotLoad extends AIRobot { } } + /** Similar method to {@link #load(EntityRobotBase, DockingStation, IStackFilter, int, boolean)} but returns the + * itemstack rather than loading it onto the robot. + * + * Only loads a single stack at once. */ + public static ItemStack takeSingle(DockingStation station, IStackFilter filter, boolean doTake) { + if (station == null) { + return null; + } + + IInventory tileInventory = station.getItemInput(); + if (tileInventory == null) { + return null; + } + + for (IInvSlot slot : InventoryIterator.getIterable(tileInventory, station.getItemInputSide())) { + ItemStack stack = slot.getStackInSlot(); + + if (stack == null + || !slot.canTakeStackFromSlot(stack) + || !filter.matches(stack) + || !ActionStationProvideItems.canExtractItem(station, stack) + || !ActionRobotFilter.canInteractWithItem(station, filter, + ActionStationProvideItems.class)) { + continue; + } + + if (doTake) { + stack = slot.decreaseStackInSlot(1); + } else { + stack = stack.copy(); + stack = stack.splitStack(1); + } + return stack; + } + return null; + } + public static boolean load(EntityRobotBase robot, DockingStation station, IStackFilter filter, int quantity, boolean doLoad) { if (station == null) {