Search in sources :

Example 1 with ILimitedItemFilter

use of crazypants.enderio.base.filter.ILimitedItemFilter 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)1 ILimitedItemFilter (crazypants.enderio.base.filter.ILimitedItemFilter)1 ItemStack (net.minecraft.item.ItemStack)1 IItemHandler (net.minecraftforge.items.IItemHandler)1