use of buildcraft.lib.inventory.filter.ArrayStackOrListFilter in project BuildCraft by BuildCraft.
the class AIRobotDeliverRequested method delegateAIEnded.
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoStation) {
if (!ai.success()) {
setSuccess(false);
terminate();
return;
}
IInvSlot slot = InvUtils.getItem(robot, new ArrayStackOrListFilter(requested.getStack()));
if (slot == null) {
setSuccess(false);
terminate();
return;
}
IRequestProvider requester = requested.getRequester(robot.worldObj);
if (requester == null) {
setSuccess(false);
terminate();
return;
}
ItemStack newStack = requester.offerItem(requested.getSlot(), slot.getStackInSlot().copy());
if (newStack == null || newStack.stackSize != slot.getStackInSlot().stackSize) {
slot.setStackInSlot(newStack);
}
terminate();
}
}
use of buildcraft.lib.inventory.filter.ArrayStackOrListFilter in project BuildCraft by BuildCraft.
the class AIRobotUnload method unload.
public static boolean unload(EntityRobotBase robot, DockingStation station, boolean doUnload) {
if (station == null) {
return false;
}
IInjectable output = station.getItemOutput();
if (output == null) {
return false;
}
EnumFacing injectSide = station.getItemOutputSide().face;
if (!output.canInjectItems(injectSide)) {
return false;
}
for (IInvSlot robotSlot : InventoryIterator.getIterable(robot)) {
if (robotSlot.getStackInSlot() == null) {
continue;
}
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackOrListFilter(robotSlot.getStackInSlot()), ActionStationAcceptItems.class)) {
continue;
}
ItemStack stack = robotSlot.getStackInSlot();
int used = output.injectItem(stack, doUnload, injectSide, null);
if (used > 0) {
if (doUnload) {
robotSlot.decreaseStackInSlot(used);
}
return true;
}
}
if (robot.getHeldItem() != null) {
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackOrListFilter(robot.getHeldItem()), ActionStationAcceptItems.class)) {
return false;
}
ItemStack stack = robot.getHeldItem();
int used = output.injectItem(stack, doUnload, injectSide, null);
if (used > 0) {
if (doUnload) {
if (stack.stackSize <= used) {
robot.setItemInUse(null);
} else {
stack.stackSize -= used;
}
}
return true;
}
}
return false;
}
Aggregations