Search in sources :

Example 1 with IInvSlot

use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.

the class TransactorSimple method inject.

@Override
public int inject(ItemStack stack, boolean doAdd) {
    List<IInvSlot> filledSlots = new ArrayList<>(inventory.getSizeInventory());
    List<IInvSlot> emptySlots = new ArrayList<>(inventory.getSizeInventory());
    for (IInvSlot slot : InventoryIterator.getIterable(inventory, orientation)) {
        if (slot.canPutStackInSlot(stack)) {
            if (slot.getStackInSlot() == null) {
                emptySlots.add(slot);
            } else {
                filledSlots.add(slot);
            }
        }
    }
    int injected = 0;
    injected = tryPut(stack, filledSlots, injected, doAdd);
    injected = tryPut(stack, emptySlots, injected, doAdd);
    if (injected > 0 && doAdd) {
        inventory.markDirty();
    }
    return injected;
}
Also used : IInvSlot(buildcraft.api.core.IInvSlot) ArrayList(java.util.ArrayList)

Example 2 with IInvSlot

use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.

the class BptBuilderBlueprint method useRequirements.

@Override
public void useRequirements(IInventory inv, BuildingSlot slot) {
    if (slot instanceof BuildingSlotBlock && ((BuildingSlotBlock) slot).mode == Mode.ClearIfInvalid) {
        return;
    }
    LinkedList<ItemStack> tmpReq = new LinkedList<>();
    try {
        for (ItemStack stk : slot.getRequirements(context)) {
            if (stk != null) {
                tmpReq.add(stk.copy());
            }
        }
    } catch (Throwable t) {
        // Defensive code against errors in implementers
        t.printStackTrace();
        BCLog.logger.throwing(t);
    }
    if (context.world().getWorldInfo().getGameType() == GameType.CREATIVE) {
        for (ItemStack s : tmpReq) {
            slot.addStackConsumed(s);
        }
        return;
    }
    ListIterator<ItemStack> itr = tmpReq.listIterator();
    while (itr.hasNext()) {
        ItemStack reqStk = itr.next();
        boolean smallStack = reqStk.stackSize == 1;
        ItemStack usedStack = reqStk;
        boolean itemBlock = reqStk.getItem() instanceof ItemBlock;
        Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).block) : null;
        if (fluid != null && inv instanceof TileAbstractBuilder && ((TileAbstractBuilder) inv).drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) {
            continue;
        }
        for (IInvSlot slotInv : InventoryIterator.getIterable(inv)) {
            if (inv instanceof TileAbstractBuilder && !((TileAbstractBuilder) inv).isBuildingMaterialSlot(slotInv.getIndex())) {
                continue;
            }
            ItemStack invStk = slotInv.getStackInSlot();
            if (invStk == null || invStk.stackSize == 0) {
                continue;
            }
            FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null;
            boolean fluidFound = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
            if (fluidFound || slot.getSchematic().isItemMatchingRequirement(invStk, reqStk)) {
                try {
                    usedStack = slot.getSchematic().useItem(context, reqStk, slotInv);
                    slot.addStackConsumed(usedStack);
                } catch (Throwable t) {
                    // Defensive code against errors in implementers
                    t.printStackTrace();
                    BCLog.logger.throwing(t);
                }
                if (reqStk.stackSize == 0) {
                    break;
                }
            }
        }
        if (reqStk.stackSize != 0) {
            return;
        }
        if (smallStack) {
            // set to the actual item used.
            itr.set(usedStack);
        }
    }
}
Also used : BuildingSlotBlock(buildcraft.core.builders.BuildingSlotBlock) IInvSlot(buildcraft.api.core.IInvSlot) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) TileAbstractBuilder(buildcraft.core.builders.TileAbstractBuilder) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) LinkedList(java.util.LinkedList)

Example 3 with IInvSlot

use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.

the class SchematicAutoWorkbench method storeRequirements.

@Override
public void storeRequirements(IBuilderContext context, BlockPos pos) {
    TileAutoWorkbench autoWb = getTile(context, pos);
    if (autoWb != null) {
        ArrayList<ItemStack> rqs = new ArrayList<>();
        rqs.add(new ItemStack(BuildCraftFactory.autoWorkbenchBlock));
        for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, EnumFacing.UP)) {
            ItemStack stack = slot.getStackInSlot();
            if (stack != null) {
                stack = stack.copy();
                stack.stackSize = 1;
                rqs.add(stack);
            }
        }
        storedRequirements = JavaTools.concat(storedRequirements, rqs.toArray(new ItemStack[rqs.size()]));
    }
}
Also used : IInvSlot(buildcraft.api.core.IInvSlot) TileAutoWorkbench(buildcraft.factory.TileAutoWorkbench) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IInvSlot

use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.

the class AIRobotDisposeItems method delegateAIEnded.

@Override
public void delegateAIEnded(AIRobot ai) {
    if (ai instanceof AIRobotGotoStationAndUnload) {
        if (ai.success()) {
            if (robot.containsItems()) {
                startDelegateAI(new AIRobotGotoStationAndUnload(robot));
            } else {
                terminate();
            }
        } else {
            for (IInvSlot slot : InventoryIterator.getIterable(robot)) {
                if (slot.getStackInSlot() != null) {
                    final EntityItem entity = new EntityItem(robot.worldObj, robot.posX, robot.posY, robot.posZ, slot.getStackInSlot());
                    robot.worldObj.spawnEntityInWorld(entity);
                    slot.setStackInSlot(null);
                }
            }
            terminate();
        }
    }
}
Also used : IInvSlot(buildcraft.api.core.IInvSlot) EntityItem(net.minecraft.entity.item.EntityItem)

Example 5 with IInvSlot

use of buildcraft.api.core.IInvSlot in project BuildCraft by BuildCraft.

the class AIRobotLoad method load.

public static boolean load(EntityRobotBase robot, DockingStation station, IStackFilter filter, int quantity, boolean doLoad) {
    if (station == null) {
        return false;
    }
    int loaded = 0;
    IInventory tileInventory = station.getItemInput();
    if (tileInventory == null) {
        return false;
    }
    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;
        }
        ITransactor robotTransactor = Transactor.getTransactorFor(robot, null);
        if (quantity == ANY_QUANTITY) {
            ItemStack added = robotTransactor.addNew(slot.getStackInSlot(), doLoad);
            if (doLoad) {
                slot.decreaseStackInSlot(added.stackSize);
            }
            return added.stackSize > 0;
        } else {
            ItemStack toAdd = slot.getStackInSlot().copy();
            if (toAdd.stackSize > quantity - loaded) {
                toAdd.stackSize = quantity - loaded;
            }
            ItemStack added = robotTransactor.addNew(toAdd, doLoad);
            if (doLoad) {
                slot.decreaseStackInSlot(added.stackSize);
            }
            loaded += added.stackSize;
            if (quantity - loaded <= 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IInvSlot(buildcraft.api.core.IInvSlot) ItemStack(net.minecraft.item.ItemStack) ITransactor(buildcraft.core.lib.inventory.ITransactor)

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