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