Search in sources :

Example 46 with ItemStack

use of net.minecraft.item.ItemStack in project BluePower by Qmunity.

the class SlotCircuitTableCrafting method getCraftingComponents.

private static List<ItemStack> getCraftingComponents(ItemStack gate) {
    List<ItemStack> requiredItems = new ArrayList<ItemStack>();
    List recipeList = CraftingManager.getInstance().getRecipeList();
    for (IRecipe r : (List<IRecipe>) recipeList) {
        ItemStack result = r.getRecipeOutput();
        if (result != null && result.isItemEqual(gate)) {
            if (r instanceof ShapedOreRecipe) {
                ShapedOreRecipe recipe = (ShapedOreRecipe) r;
                for (Object o : recipe.getInput()) {
                    if (o != null) {
                        ItemStack stack;
                        if (o instanceof ItemStack) {
                            stack = (ItemStack) o;
                        } else {
                            List<ItemStack> list = (List<ItemStack>) o;
                            stack = list.size() > 0 ? list.get(0) : null;
                        }
                        if (stack != null) {
                            boolean needsAdding = true;
                            for (ItemStack listStack : requiredItems) {
                                if (listStack.isItemEqual(stack)) {
                                    listStack.stackSize++;
                                    needsAdding = false;
                                    break;
                                }
                            }
                            if (needsAdding)
                                requiredItems.add(stack.copy());
                        }
                    }
                }
                return requiredItems;
            } else if (r instanceof ShapedRecipes) {
                ShapedRecipes recipe = (ShapedRecipes) r;
                for (ItemStack stack : recipe.recipeItems) {
                    if (stack != null) {
                        boolean needsAdding = true;
                        for (ItemStack listStack : requiredItems) {
                            if (listStack.isItemEqual(stack)) {
                                listStack.stackSize++;
                                needsAdding = false;
                                break;
                            }
                        }
                        if (needsAdding)
                            requiredItems.add(stack.copy());
                    }
                }
                return requiredItems;
            }
        }
    }
    return new ArrayList<ItemStack>();
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 47 with ItemStack

use of net.minecraft.item.ItemStack in project BluePower by Qmunity.

the class IOHelper method extract.

public static ItemStack extract(IInventory inventory, ForgeDirection direction, boolean simulate) {
    if (inventory instanceof ISidedInventory) {
        ISidedInventory isidedinventory = (ISidedInventory) inventory;
        int[] accessibleSlotsFromSide = isidedinventory.getAccessibleSlotsFromSide(direction.ordinal());
        for (int anAccessibleSlotsFromSide : accessibleSlotsFromSide) {
            ItemStack stack = extract(inventory, direction, anAccessibleSlotsFromSide, simulate);
            if (stack != null)
                return stack;
        }
    } else {
        int j = inventory.getSizeInventory();
        for (int k = 0; k < j; ++k) {
            ItemStack stack = extract(inventory, direction, k, simulate);
            if (stack != null)
                return stack;
        }
    }
    return null;
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 48 with ItemStack

use of net.minecraft.item.ItemStack 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 49 with ItemStack

use of net.minecraft.item.ItemStack 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 50 with ItemStack

use of net.minecraft.item.ItemStack 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)

Aggregations

ItemStack (net.minecraft.item.ItemStack)9052 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)941 ArrayList (java.util.ArrayList)733 TileEntity (net.minecraft.tileentity.TileEntity)555 BlockPos (net.minecraft.util.math.BlockPos)551 EntityPlayer (net.minecraft.entity.player.EntityPlayer)526 IBlockState (net.minecraft.block.state.IBlockState)505 Block (net.minecraft.block.Block)494 Item (net.minecraft.item.Item)465 Slot (net.minecraft.inventory.Slot)448 EntityItem (net.minecraft.entity.item.EntityItem)423 Nonnull (javax.annotation.Nonnull)356 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)330 FluidStack (net.minecraftforge.fluids.FluidStack)289 NBTTagList (net.minecraft.nbt.NBTTagList)280 World (net.minecraft.world.World)277 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)269 ResourceLocation (net.minecraft.util.ResourceLocation)260 List (java.util.List)223 EnumFacing (net.minecraft.util.EnumFacing)208