Search in sources :

Example 1 with IStackFilter

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

the class ItemTransactorHelper method move.

/**
 * Attempts to move up to maxItems from the source {@link IItemTransactor} to the destination.
 *
 * @param filter The stack filter to use - only items that match this filter will be moved.
 * @param maxItems The maximum number of items to move.
 * @return The number of items moved.
 */
public static int move(IItemTransactor src, IItemTransactor dst, IStackFilter filter, int maxItems) {
    int moved = 0;
    IStackFilter rFilter = dst::canPartiallyAccept;
    if (filter != null) {
        rFilter = rFilter.and(filter);
    }
    while (true) {
        int m = moveSingle0(src, dst, rFilter, maxItems - moved, false, false);
        if (m == 0) {
            break;
        } else {
            moved += m;
        }
    }
    return moved;
}
Also used : IStackFilter(buildcraft.api.core.IStackFilter)

Example 2 with IStackFilter

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

the class ItemTransactorHelper method moveSingle0.

private static int moveSingle0(IItemTransactor src, IItemTransactor dst, IStackFilter filter, int maxItems, boolean simulateSrc, boolean simulateDst) {
    ItemStack potential = src.extract(filter, 1, maxItems, true);
    if (potential.isEmpty())
        return 0;
    ItemStack leftOver = dst.insert(potential, false, simulateDst);
    int toTake = potential.getCount() - leftOver.getCount();
    IStackFilter exactFilter = (stack) -> StackUtil.canMerge(stack, potential);
    ItemStack taken = src.extract(exactFilter, toTake, toTake, simulateSrc);
    if (taken.getCount() != toTake) {
        String msg = "One of the two transactors (either src = ";
        msg += src.getClass() + " or dst = " + dst.getClass() + ")";
        msg += " didn't respect the movement flags! ( potential = " + potential;
        msg += ", leftOver = " + leftOver + ", taken = " + taken;
        msg += ", count = " + toTake + " )";
        throw new IllegalStateException(msg);
    }
    return toTake;
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) IItemHandler(net.minecraftforge.items.IItemHandler) InventoryUtil(buildcraft.lib.misc.InventoryUtil) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) World(net.minecraft.world.World) IItemInsertable(buildcraft.api.inventory.IItemTransactor.IItemInsertable) PipeApi(buildcraft.api.transport.pipe.PipeApi) EnumFacing(net.minecraft.util.EnumFacing) IInjectable(buildcraft.api.transport.IInjectable) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityArrow(net.minecraft.entity.projectile.EntityArrow) ItemStack(net.minecraft.item.ItemStack) IStackFilter(buildcraft.api.core.IStackFilter) ISidedInventory(net.minecraft.inventory.ISidedInventory) Vec3d(net.minecraft.util.math.Vec3d) IInventory(net.minecraft.inventory.IInventory) StackUtil(buildcraft.lib.misc.StackUtil) CapUtil(buildcraft.lib.misc.CapUtil) NonNullList(net.minecraft.util.NonNullList) Nonnull(javax.annotation.Nonnull) IItemTransactor(buildcraft.api.inventory.IItemTransactor) IStackFilter(buildcraft.api.core.IStackFilter) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IStackFilter

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

the class FlexibleRecipe method craft.

@Override
public CraftingResult<T> craft(IFlexibleCrafter baseCrafter, boolean preview) {
    if (output == null) {
        return null;
    }
    IFlexibleCrafter crafter = baseCrafter;
    if (preview) {
        crafter = new FakeFlexibleCrafter(baseCrafter);
    }
    CraftingResult<T> result = new CraftingResult<>();
    result.recipe = this;
    result.powerCost = powerCost;
    result.craftingTime = craftingTime;
    for (ItemStack requirement : inputItems) {
        IStackFilter filter = new ArrayStackFilter(requirement);
        int amount = requirement.stackSize;
        if (consumeItems(crafter, result, filter, amount) != 0) {
            return null;
        }
    }
    for (List<ItemStack> requirements : inputItemsWithAlternatives) {
        IStackFilter filter = new ArrayStackFilter(requirements.toArray(new ItemStack[requirements.size()]));
        int amount = requirements.get(0).stackSize;
        if (consumeItems(crafter, result, filter, amount) != 0) {
            return null;
        }
    }
    for (FluidStack requirement : inputFluids) {
        int amount = requirement.amount;
        for (int tankid = 0; tankid < crafter.getCraftingFluidStackSize(); tankid++) {
            FluidStack fluid = crafter.getCraftingFluidStack(tankid);
            if (fluid != null && fluid.isFluidEqual(requirement)) {
                int amountUsed;
                if (fluid.amount > amount) {
                    amountUsed = amount;
                    if (!preview) {
                        crafter.decrCraftingFluidStack(tankid, amount);
                    }
                    amount = 0;
                } else {
                    amountUsed = fluid.amount;
                    if (!preview) {
                        crafter.decrCraftingFluidStack(tankid, fluid.amount);
                    }
                    amount -= fluid.amount;
                }
                result.usedFluids.add(new FluidStack(requirement.getFluid(), amountUsed));
            }
            if (amount == 0) {
                break;
            }
        }
        if (amount != 0) {
            return null;
        }
    }
    // Output generation
    result.crafted = output;
    return result;
}
Also used : ArrayStackFilter(buildcraft.lib.inventory.filter.ArrayStackFilter) FluidStack(net.minecraftforge.fluids.FluidStack) IStackFilter(buildcraft.api.core.IStackFilter) IFlexibleCrafter(buildcraft.api.recipes.IFlexibleCrafter) ItemStack(net.minecraft.item.ItemStack) CraftingResult(buildcraft.api.recipes.CraftingResult)

Example 4 with IStackFilter

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

the class BoardRobotCarrier method update.

@Override
public void update() {
    if (!robot.containsItems()) {
        IStackFilter filter = ActionRobotFilter.getGateFilter(robot.getLinkedStation());
        startDelegateAI(new AIRobotGotoStationAndLoad(robot, filter, AIRobotLoad.ANY_QUANTITY));
    } else {
        startDelegateAI(new AIRobotGotoStationAndUnload(robot));
    }
}
Also used : AIRobotGotoStationAndLoad(buildcraft.robotics.ai.AIRobotGotoStationAndLoad) AIRobotGotoStationAndUnload(buildcraft.robotics.ai.AIRobotGotoStationAndUnload) IStackFilter(buildcraft.api.core.IStackFilter)

Example 5 with IStackFilter

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

the class TileAdvancedCraftingTable method searchNeighborsForIngredients.

private void searchNeighborsForIngredients() {
    for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, EnumFacing.UP)) {
        ItemStack ingred = slot.getStackInSlot();
        if (ingred == null) {
            continue;
        }
        IStackFilter filter = new CraftingFilter(ingred);
        if (InvUtils.countItems(invInput, EnumFacing.UP, filter) < InvUtils.countItems(craftingSlots, EnumFacing.UP, filter)) {
            for (EnumFacing side : SEARCH_SIDES) {
                TileEntity tile = getTile(side);
                if (tile instanceof IInventory) {
                    IInventory inv = InvUtils.getInventory((IInventory) tile);
                    ItemStack result = InvUtils.moveOneItem(inv, side.getOpposite(), invInput, side, filter);
                    if (result != null) {
                        return;
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) IInvSlot(buildcraft.api.core.IInvSlot) IStackFilter(buildcraft.api.core.IStackFilter) CraftingFilter(buildcraft.lib.inventory.filter.CraftingFilter) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IStackFilter (buildcraft.api.core.IStackFilter)5 ItemStack (net.minecraft.item.ItemStack)3 IInventory (net.minecraft.inventory.IInventory)2 EnumFacing (net.minecraft.util.EnumFacing)2 IInvSlot (buildcraft.api.core.IInvSlot)1 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 IItemInsertable (buildcraft.api.inventory.IItemTransactor.IItemInsertable)1 CraftingResult (buildcraft.api.recipes.CraftingResult)1 IFlexibleCrafter (buildcraft.api.recipes.IFlexibleCrafter)1 IInjectable (buildcraft.api.transport.IInjectable)1 PipeApi (buildcraft.api.transport.pipe.PipeApi)1 ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 CraftingFilter (buildcraft.lib.inventory.filter.CraftingFilter)1 CapUtil (buildcraft.lib.misc.CapUtil)1 InventoryUtil (buildcraft.lib.misc.InventoryUtil)1 StackUtil (buildcraft.lib.misc.StackUtil)1 AIRobotGotoStationAndLoad (buildcraft.robotics.ai.AIRobotGotoStationAndLoad)1 AIRobotGotoStationAndUnload (buildcraft.robotics.ai.AIRobotGotoStationAndUnload)1 Nonnull (javax.annotation.Nonnull)1 Entity (net.minecraft.entity.Entity)1