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