Search in sources :

Example 1 with ArrayStackOrListFilter

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();
    }
}
Also used : IInvSlot(buildcraft.api.core.IInvSlot) ArrayStackOrListFilter(buildcraft.lib.inventory.filter.ArrayStackOrListFilter) IRequestProvider(buildcraft.api.robots.IRequestProvider) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ArrayStackOrListFilter

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;
}
Also used : ActionStationAcceptItems(buildcraft.robotics.statements.ActionStationAcceptItems) IInvSlot(buildcraft.api.core.IInvSlot) IInjectable(buildcraft.api.transport.IInjectable) ArrayStackOrListFilter(buildcraft.lib.inventory.filter.ArrayStackOrListFilter) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IInvSlot (buildcraft.api.core.IInvSlot)2 ArrayStackOrListFilter (buildcraft.lib.inventory.filter.ArrayStackOrListFilter)2 ItemStack (net.minecraft.item.ItemStack)2 IRequestProvider (buildcraft.api.robots.IRequestProvider)1 IInjectable (buildcraft.api.transport.IInjectable)1 ActionStationAcceptItems (buildcraft.robotics.statements.ActionStationAcceptItems)1 EnumFacing (net.minecraft.util.EnumFacing)1