Search in sources :

Example 1 with IInventory

use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.

the class ItemSeedBag method getItemDamageForDisplay.

public int getItemDamageForDisplay(ItemStack stack) {
    int items = 0;
    IInventory seedBagInventory = InventoryItem.getItemInventory(stack, "Seed Bag", 9);
    seedBagInventory.openInventory();
    for (int i = 0; i < seedBagInventory.getSizeInventory(); i++) {
        ItemStack is = seedBagInventory.getStackInSlot(i);
        if (is != null) {
            items += is.stackSize;
        }
    }
    return items;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IInventory

use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.

the class IOHelper method extract.

/**
     * Retrieves an item from the specified inventory. This item can be specified.
     *
     * @param tile
     * @param direction
     * @param requestedStack
     * @param useItemCount
     *            if true, it'll only retrieve the stack of the exact item count given. it'll look in multiple slots of the inventory. if false, the
     *            first matching stack, ignoring item count, will be returned.
     * @param simulate
     * @param fuzzySetting
     *            ,
     * @return
     */
public static ItemStack extract(TileEntity tile, ForgeDirection direction, ItemStack requestedStack, boolean useItemCount, boolean simulate, int fuzzySetting) {
    if (requestedStack == null)
        return requestedStack;
    IInventory inv = getInventoryForTE(tile);
    if (inv != null) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(direction.ordinal());
        } else {
            accessibleSlots = new int[inv.getSizeInventory()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        int itemsFound = 0;
        for (int slot : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(slot);
            if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
                if (!useItemCount) {
                    if (!simulate) {
                        inv.setInventorySlotContents(slot, null);
                    }
                    return stack;
                }
                itemsFound += stack.stackSize;
            }
        }
        if (itemsFound >= requestedStack.stackSize) {
            ItemStack exportedStack = null;
            int itemsNeeded = requestedStack.stackSize;
            for (int slot : accessibleSlots) {
                ItemStack stack = inv.getStackInSlot(slot);
                if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
                    int itemsSubstracted = Math.min(itemsNeeded, stack.stackSize);
                    if (itemsSubstracted > 0)
                        exportedStack = stack;
                    itemsNeeded -= itemsSubstracted;
                    if (!simulate) {
                        stack.stackSize -= itemsSubstracted;
                        if (stack.stackSize == 0)
                            inv.setInventorySlotContents(slot, null);
                        tile.markDirty();
                    }
                }
            }
            exportedStack = exportedStack.copy();
            exportedStack.stackSize = requestedStack.stackSize;
            return exportedStack;
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IInventory

use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.

the class IOHelper method extractOneItem.

public static ItemStack extractOneItem(TileEntity tile, ForgeDirection dir) {
    IInventory inv = getInventoryForTE(tile);
    if (inv != null) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(dir.ordinal());
        } else {
            accessibleSlots = new int[inv.getSizeInventory()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        for (int slot : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(slot);
            ItemStack retrievingStack = stack == null ? null : stack.copy().splitStack(1);
            if (stack != null && IOHelper.canExtractItemFromInventory(inv, retrievingStack, slot, dir.ordinal())) {
                ItemStack ret = stack.splitStack(1);
                if (stack.stackSize == 0)
                    inv.setInventorySlotContents(slot, null);
                tile.markDirty();
                return ret;
            }
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IInventory

use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.

the class IOHelper method getItemCount.

public static int getItemCount(ItemStack type, TileEntity inv, ForgeDirection side, int fuzzySetting) {
    IInventory inventory = getInventoryForTE(inv);
    int[] slots = getAccessibleSlotsForInventory(inventory, side);
    int count = 0;
    for (int slot : slots) {
        ItemStack invStack = inventory.getStackInSlot(slot);
        if (invStack != null) {
            if (ItemStackHelper.areStacksEqual(invStack, type, fuzzySetting)) {
                count += invStack.stackSize;
            }
        }
    }
    return count;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IInventory

use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.

the class IOHelper method dropInventory.

public static void dropInventory(World world, int x, int y, int z) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (!(tileEntity instanceof IInventory)) {
        return;
    }
    IInventory inventory = (IInventory) tileEntity;
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        ItemStack itemStack = inventory.getStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            spawnItemInWorld(world, itemStack, x, y, z);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IInventory (net.minecraft.inventory.IInventory)123 ItemStack (net.minecraft.item.ItemStack)78 TileEntity (net.minecraft.tileentity.TileEntity)53 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 ArrayList (java.util.ArrayList)18 ISidedInventory (net.minecraft.inventory.ISidedInventory)13 EntityItem (net.minecraft.entity.item.EntityItem)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)9 AMVector3 (am2.api.math.AMVector3)8 List (java.util.List)8 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)8 SinkReply (logisticspipes.utils.SinkReply)8 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)8 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)7