Search in sources :

Example 6 with IStorageScanner

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();
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IStorageScanner(mcjty.rftools.api.storage.IStorageScanner) ItemStack(net.minecraft.item.ItemStack)

Example 7 with IStorageScanner

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();
}
Also used : ProgException(mcjty.rftoolscontrol.logic.running.ProgException) IItemHandler(net.minecraftforge.items.IItemHandler) IStorageScanner(mcjty.rftools.api.storage.IStorageScanner) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IStorageScanner (mcjty.rftools.api.storage.IStorageScanner)7 ItemStack (net.minecraft.item.ItemStack)7 IItemHandler (net.minecraftforge.items.IItemHandler)5 ProgException (mcjty.rftoolscontrol.logic.running.ProgException)4 ArrayList (java.util.ArrayList)1 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 CraftingStationTileEntity (mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity)1 MultiTankTileEntity (mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity)1 NodeTileEntity (mcjty.rftoolscontrol.blocks.node.NodeTileEntity)1 WorkbenchTileEntity (mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 Pair (org.apache.commons.lang3.tuple.Pair)1