Potential fix for #3451

This commit is contained in:
AlexIIL 2016-11-16 17:38:27 +00:00
parent 3668dc883a
commit 42db6fb549
2 changed files with 43 additions and 9 deletions

View file

@ -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;
}
}

View file

@ -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) {