use of mcjty.rftools.api.storage.IStorageScanner in project RFToolsControl by McJty.
the class ProcessorTileEntity method pushItems.
public int pushItems(IProgram program, Inventory inv, Integer slot, @Nullable Integer amount, int virtualSlot) {
IStorageScanner scanner = getScannerForInv(inv);
IItemHandler handler = getHandlerForInv(inv);
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealSlot(virtualSlot);
IItemHandler itemHandler = getItemHandler();
ItemStack extracted = itemHandler.extractItem(realSlot, amount == null ? 64 : amount, false);
if (extracted.isEmpty()) {
// Nothing to do
return 0;
}
ItemStack remaining = InventoryTools.insertItem(handler, scanner, extracted, slot);
if (!remaining.isEmpty()) {
itemHandler.insertItem(realSlot, remaining, false);
return extracted.getCount() - remaining.getCount();
}
return extracted.getCount();
}
use of mcjty.rftools.api.storage.IStorageScanner in project RFToolsControl by McJty.
the class ProcessorTileEntity method fetchItems.
public int fetchItems(IProgram program, Inventory inv, Integer slot, ItemStack itemMatcher, boolean routable, boolean oredict, @Nullable Integer amount, int virtualSlot) {
if (amount != null && amount == 0) {
throw new ProgException(EXCEPT_BADPARAMETERS);
}
IStorageScanner scanner = getScannerForInv(inv);
IItemHandler handler = getHandlerForInv(inv);
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealSlot(virtualSlot);
ItemStack stack = InventoryTools.tryExtractItem(handler, scanner, amount, routable, oredict, itemMatcher, slot);
if (stack.isEmpty()) {
// Nothing to do
return 0;
}
IItemHandler capability = getItemHandler();
if (!capability.insertItem(realSlot, stack, true).isEmpty()) {
// Not enough room. Do nothing
return 0;
}
// All seems ok. Do the real thing now.
stack = InventoryTools.extractItem(handler, scanner, amount, routable, oredict, false, itemMatcher, slot);
capability.insertItem(realSlot, stack, false);
return stack.getCount();
}
Aggregations