use of buildcraft.api.core.IInvSlot 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.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class SchematicAutoWorkbench method placeInWorld.
@Override
public void placeInWorld(IBuilderContext context, BlockPos pos, List<ItemStack> stacks) {
super.placeInWorld(context, pos, stacks);
TileAutoWorkbench autoWb = getTile(context, pos);
if (autoWb != null) {
for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, EnumFacing.UP)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
stack.stackSize = 1;
}
}
}
}
use of buildcraft.api.core.IInvSlot 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;
}
use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.
the class AIRobotLoad method takeSingle.
/**
* 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().face)) {
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;
}
Aggregations