Search in sources :

Example 6 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class NetworkedInventory method insertIntoTargets.

public int insertIntoTargets(@Nonnull ItemStack toExtract) {
    if (Prep.isInvalid(toExtract)) {
        return 0;
    }
    int totalToInsert = toExtract.getCount();
    int leftToInsert = totalToInsert;
    boolean matchedStickyInput = false;
    Iterable<Target> targets = getTargetIterator();
    // for (Target target : sendPriority) {
    for (Target target : targets) {
        if (target.stickyInput && !matchedStickyInput) {
            IItemFilter of = target.inv.getCon().getInputFilter(target.inv.getConDir());
            matchedStickyInput = of != null && of.isValid() && of.doesItemPassFilter(this.getInventory(), toExtract);
        }
        if (target.stickyInput || !matchedStickyInput) {
            int inserted = target.inv.insertItem(toExtract);
            if (inserted > 0) {
                toExtract.shrink(inserted);
                leftToInsert -= inserted;
            }
            if (leftToInsert <= 0) {
                return totalToInsert;
            }
        }
    }
    return totalToInsert - leftToInsert;
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter)

Example 7 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class NetworkedInventory method transferItems.

private boolean transferItems() {
    final IItemHandler inventory = getInventory();
    if (inventory == null) {
        return false;
    }
    final int numSlots = inventory.getSlots();
    if (numSlots < 1) {
        return false;
    }
    final int maxExtracted = con.getMaximumExtracted(conDir);
    final IItemFilter filter = con.getInputFilter(conDir);
    int slot = -1;
    final int slotChecksPerTick = Math.min(numSlots, ItemConduitNetwork.MAX_SLOT_CHECK_PER_TICK);
    for (int i = 0; i < slotChecksPerTick; i++) {
        slot = nextSlot(numSlots);
        ItemStack item = inventory.extractItem(slot, maxExtracted, SIMULATE);
        if (Prep.isValid(item)) {
            if (filter instanceof ILimitedItemFilter && filter.isLimited()) {
                final int count = filter.getMaxCountThatPassesFilter(this.getInventory(), item);
                if (count <= 0) {
                    // doesn't pass filter
                    item = Prep.getEmpty();
                } else if (count < Integer.MAX_VALUE) {
                    // some limit
                    final ItemStack stackInSlot = inventory.getStackInSlot(slot);
                    if (stackInSlot.getCount() <= count) {
                        // there's less than the limit in there
                        item = Prep.getEmpty();
                    } else if (stackInSlot.getCount() - item.getCount() < count) {
                        // we are trying to extract more than allowed
                        item = inventory.extractItem(slot, stackInSlot.getCount() - count, SIMULATE);
                    }
                }
            } else if (filter != null && !filter.doesItemPassFilter(this.getInventory(), item)) {
                item = Prep.getEmpty();
            }
            if (Prep.isValid(item) && doTransfer(inventory, item, slot)) {
                setNextStartingSlot(slot);
                return true;
            }
        }
    }
    return false;
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter) IItemHandler(net.minecraftforge.items.IItemHandler) ILimitedItemFilter(crazypants.enderio.base.filter.ILimitedItemFilter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IItemFilter (crazypants.enderio.base.filter.IItemFilter)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ItemStack (net.minecraft.item.ItemStack)3 EnumFacing (net.minecraft.util.EnumFacing)2 DyeColor (com.enderio.core.common.util.DyeColor)1 ILimitedItemFilter (crazypants.enderio.base.filter.ILimitedItemFilter)1 ExistingItemFilter (crazypants.enderio.base.filter.filters.ExistingItemFilter)1 ItemFilter (crazypants.enderio.base.filter.filters.ItemFilter)1 RedstoneControlMode (crazypants.enderio.base.machine.modes.RedstoneControlMode)1 Target (crazypants.enderio.conduits.conduit.item.NetworkedInventory.Target)1 ArrayList (java.util.ArrayList)1 IItemHandler (net.minecraftforge.items.IItemHandler)1