Search in sources :

Example 11 with IInvSlot

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

Example 12 with IInvSlot

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;
            }
        }
    }
}
Also used : IInvSlot(buildcraft.api.core.IInvSlot) TileAutoWorkbench(buildcraft.factory.TileAutoWorkbench) ItemStack(net.minecraft.item.ItemStack)

Example 13 with IInvSlot

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

Example 14 with IInvSlot

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

Aggregations

IInvSlot (buildcraft.api.core.IInvSlot)14 ItemStack (net.minecraft.item.ItemStack)11 IInventory (net.minecraft.inventory.IInventory)4 EnumFacing (net.minecraft.util.EnumFacing)3 BuildingSlotBlock (buildcraft.core.builders.BuildingSlotBlock)2 TileAutoWorkbench (buildcraft.factory.TileAutoWorkbench)2 ArrayStackOrListFilter (buildcraft.lib.inventory.filter.ArrayStackOrListFilter)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ItemBlock (net.minecraft.item.ItemBlock)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Fluid (net.minecraftforge.fluids.Fluid)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 IStackFilter (buildcraft.api.core.IStackFilter)1 IRequestProvider (buildcraft.api.robots.IRequestProvider)1 IInjectable (buildcraft.api.transport.IInjectable)1 TileAbstractBuilder (buildcraft.core.builders.TileAbstractBuilder)1 ITransactor (buildcraft.core.lib.inventory.ITransactor)1 InventoryCopy (buildcraft.core.lib.inventory.InventoryCopy)1 CraftingFilter (buildcraft.lib.inventory.filter.CraftingFilter)1