Search in sources :

Example 16 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project LogisticsPipes by RS485.

the class ModuleApiaristRefiller method tick.

@Override
public void tick() {
    if (++currentTickCount < ticksToOperation) {
        return;
    }
    currentTickCount = 0;
    IInventory inv = _service.getRealInventory();
    if (!(inv instanceof ISidedInventory)) {
        return;
    }
    ISidedInventory sinv = (ISidedInventory) inv;
    ForgeDirection direction = _service.inventoryOrientation().getOpposite();
    ItemStack stack = extractItem(sinv, false, direction, 1);
    if (stack == null) {
        return;
    }
    if (!(_service.canUseEnergy(100))) {
        return;
    }
    currentTickCount = ticksToOperation;
    if (reinsertBee(stack, sinv, direction)) {
        return;
    }
    Pair<Integer, SinkReply> reply = _service.hasDestination(ItemIdentifier.get(stack), true, new ArrayList<>());
    if (reply == null) {
        return;
    }
    _service.useEnergy(20);
    extractItem(sinv, true, direction, 1);
    _service.sendStack(stack, reply, ItemSendMode.Normal);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) SinkReply(logisticspipes.utils.SinkReply) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 17 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.

the class InventoryUtilities method getFirstStackStartingFromSlot.

public static GetFirstStackStartingFromSlotResult getFirstStackStartingFromSlot(IInventory inventory, ItemStack itemStack, int slot, int side) {
    if (inventory instanceof ISidedInventory) {
        ISidedInventory sidededInventory = (ISidedInventory) inventory;
        int[] slots = sidededInventory.getAccessibleSlotsFromSide(side);
        for (int i = slot; i < slots.length; i++) {
            itemStack = inventory.getStackInSlot(slots[i]);
            if (itemStack != null && canExtractItemFromInventory(sidededInventory, itemStack, slots[i], side)) {
                return new GetFirstStackStartingFromSlotResult(i, itemStack);
            }
        }
    } else {
        return getFirstStackStartingFromSlot(inventory, itemStack, slot);
    }
    return new GetFirstStackStartingFromSlotResult(-1, null);
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory)

Example 18 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.

the class InventoryUtilities method inventoryHasItem.

public static boolean inventoryHasItem(IInventory inventory, ItemStack search, int quantity, int side) {
    if (inventory instanceof ISidedInventory) {
        ISidedInventory sidedInventory = (ISidedInventory) inventory;
        int qtyFound = 0;
        int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
        for (int i = 0; i < slots.length; i++) {
            ItemStack inventoryStack = inventory.getStackInSlot(slots[i]);
            if (inventoryStack == null)
                continue;
            else if (compareItemStacks(inventoryStack, search, true, false, true, true)) {
                qtyFound += inventoryStack.stackSize;
                if (qtyFound >= quantity)
                    return true;
            }
        }
        return false;
    } else {
        return inventoryHasItem(inventory, search, quantity);
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 19 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.

the class InventoryUtilities method mergeIntoInventory.

public static boolean mergeIntoInventory(IInventory inventory, ItemStack toMerge, int quantity, int side) {
    if (inventory instanceof ISidedInventory) {
        ItemStack stack = toMerge.splitStack(Math.min(toMerge.stackSize, quantity));
        ISidedInventory sidedInventory = (ISidedInventory) inventory;
        int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
        boolean flag = false;
        for (int i = 0; i < slots.length && stack != null && stack.stackSize > 0; ++i) {
            //For each slot that can be accessed from this side
            ItemStack prvStack = sidedInventory.getStackInSlot(slots[i]);
            if (InventoryUtilities.canInsertItemToInventory(sidedInventory, stack, slots[i], side)) {
                //if the items can be inserted into the current slot
                if (prvStack == null) {
                    //if the stack in the slot is null then get the max value that can be moved and transfer the stack to the inventory
                    int max = Math.min(stack.getMaxStackSize(), sidedInventory.getInventoryStackLimit());
                    if (max >= stack.stackSize) {
                        sidedInventory.setInventorySlotContents(slots[i], stack.copy());
                        stack.stackSize = 0;
                        flag = true;
                    } else {
                        sidedInventory.setInventorySlotContents(slots[i], stack.splitStack(max));
                        flag = true;
                    }
                } else if (InventoryUtilities.canStacksMerge(prvStack, stack)) {
                    //if the stack in the slot can be merged with the stack we are trying to move get the max items that can exist in the slot
                    //and insert as many as will fit from the stack we are trying to move
                    int max = Math.min(stack.getMaxStackSize(), sidedInventory.getInventoryStackLimit());
                    if (max > prvStack.stackSize) {
                        int qty = Math.min(stack.stackSize, max - prvStack.stackSize);
                        prvStack.stackSize += qty;
                        stack.stackSize -= qty;
                        flag = qty > 0;
                    }
                }
            }
        }
        toMerge.stackSize = toMerge.stackSize + stack.stackSize;
        return flag;
    } else {
        return mergeIntoInventory(inventory, toMerge, quantity);
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 20 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.

the class InventoryUtilities method getLikeItemCount.

public static int getLikeItemCount(IInventory inventory, ItemStack stack, int side) {
    if (inventory instanceof ISidedInventory) {
        int totalCount = 0;
        ISidedInventory sidedInventory = (ISidedInventory) inventory;
        int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
        for (int i = 0; i < slots.length; i++) {
            ItemStack invStack = inventory.getStackInSlot(slots[i]);
            if (invStack != null && compareItemStacks(invStack, stack, true, false, true, true))
                totalCount += invStack.stackSize;
        }
        return totalCount;
    } else {
        return getLikeItemCount(inventory, stack);
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ISidedInventory (net.minecraft.inventory.ISidedInventory)21 ItemStack (net.minecraft.item.ItemStack)18 IInventory (net.minecraft.inventory.IInventory)13 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)3 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ISlotUpgradeManager (logisticspipes.interfaces.ISlotUpgradeManager)2 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)1 IMetaTileEntityItemPipe (gregtech.api.interfaces.metatileentity.IMetaTileEntityItemPipe)1 ICoverable (gregtech.api.interfaces.tileentity.ICoverable)1 IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)1 WeakReference (java.lang.ref.WeakReference)1 Map (java.util.Map)1