Search in sources :

Example 51 with ItemStack

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

Example 52 with ItemStack

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

the class GateNullCell method drawHighlight.

@Override
public boolean drawHighlight(QMovingObjectPosition mop, EntityPlayer player, float frame) {
    Vec3d hit = new Vec3d(mop.hitVec).sub(mop.blockX, mop.blockY, mop.blockZ).rotateUndo(getFace(), Vec3d.center);
    Vec3 pos = player.getPosition(frame);
    ItemStack held = player.getCurrentEquippedItem();
    if (held == null)
        return false;
    if (held.getItem() instanceof ItemPart) {
        IPart part = ((ItemPart) held.getItem()).createPart(held, player, null, null);
        if (part == null)
            return false;
        if (!(part instanceof PartRedwireFaceUninsulated))
            return false;
        PartRedwireFace wire = (PartRedwireFace) part;
        RenderHelper renderer = RenderHelper.instance;
        renderer.fullReset();
        renderer.setRenderCoords(getWorld(), getX(), getY(), getZ());
        double height = 2 / 16D;
        IIcon wireIcon = IconSupplier.wire;
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
        Tessellator.instance.startDrawingQuads();
        Tessellator.instance.addTranslation((float) -pos.xCoord, (float) -pos.yCoord, (float) -pos.zCoord);
        {
            switch(getFace()) {
                case DOWN:
                    break;
                case UP:
                    renderer.addTransformation(new Rotation(180, 180, 0, Vec3d.center));
                    break;
                case NORTH:
                    renderer.addTransformation(new Rotation(90, 0, 0, Vec3d.center));
                    break;
                case SOUTH:
                    renderer.addTransformation(new Rotation(-90, 0, 0, Vec3d.center));
                    break;
                case WEST:
                    renderer.addTransformation(new Rotation(0, 0, -90, Vec3d.center));
                    break;
                case EAST:
                    renderer.addTransformation(new Rotation(0, 0, 90, Vec3d.center));
                    break;
                default:
                    break;
            }
            int rotation = getRotation();
            if (rotation != -1)
                renderer.addTransformation(new Rotation(0, 90 * -rotation, 0));
            renderer.setOpacity(0.5);
            renderer.setColor(WireHelper.getColorForPowerLevel(wire.getRedwireType(ForgeDirection.UNKNOWN), (byte) (255 / 2)));
            ForgeDirection dir = ForgeDirection.NORTH;
            if (getRotation() % 2 == 1)
                dir = dir.getRotation(getFace());
            if (hit.getY() > 2 / 16D) {
                if (typeB == null) {
                    renderer.renderBox(new Vec3dCube(0 / 16D, 2 / 16D, 7 / 16D, 2 / 16D, 10 / 16D, 9 / 16D), wireIcon);
                    renderer.renderBox(new Vec3dCube(14 / 16D, 2 / 16D, 7 / 16D, 16 / 16D, 10 / 16D, 9 / 16D), wireIcon);
                    renderer.renderBox(new Vec3dCube(0 / 16D, 10 / 16D, 7 / 16D, 16 / 16D, 12 / 16D, 9 / 16D), wireIcon);
                }
            } else {
                if (typeA == null)
                    renderer.renderBox(new Vec3dCube(7 / 16D, 2 / 16D, 0 / 16D, 9 / 16D, 2 / 16D + height, 16 / 16D), wireIcon);
            }
            renderer.fullReset();
        }
        Tessellator.instance.addTranslation((float) pos.xCoord, (float) pos.yCoord, (float) pos.zCoord);
        Tessellator.instance.draw();
        GL11.glDisable(GL11.GL_BLEND);
        return true;
    } else if (held.getItem() instanceof IScrewdriver) {
    // List<Vec3dCube> l = new ArrayList<Vec3dCube>();
    // super.addBoxes(l);
    // boolean def = false;
    // for (Vec3dCube c : l)
    // if (mop.getCube().equals(c.clone().rotate(getFace(), Vec3d.center).rotate(0, 90 * -getRotation(), 0, Vec3d.center)))
    // def = true;
    // if (def || hit.getY() <= 2 / 16D) {
    // Vec3dCube c = Vec3dCube.merge(getSelectionBoxes()).expand(0.001);
    //
    // GL11.glEnable(GL11.GL_BLEND);
    // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    // GL11.glDisable(GL11.GL_TEXTURE_2D);
    // GL11.glColor4f(0, 0, 0, 0.4F);
    // GL11.glLineWidth(2);
    // GL11.glDepthMask(true);
    // GL11.glPushMatrix();
    //
    // Tessellator var2 = Tessellator.instance;
    // var2.startDrawing(3);
    // Tessellator.instance.addTranslation((float) -pos.xCoord + getX(), (float) -pos.yCoord + getY(), (float) -pos.zCoord
    // + getZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
    // var2.draw();
    // var2.startDrawing(3);
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
    // var2.draw();
    // var2.startDrawing(1);
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMaxZ());
    // Tessellator.instance.addTranslation((float) pos.xCoord - getX(), (float) pos.yCoord - getY(), (float) pos.zCoord - getZ());
    // var2.draw();
    //
    // GL11.glPopMatrix();
    // GL11.glDepthMask(false);
    // GL11.glEnable(GL11.GL_TEXTURE_2D);
    // GL11.glDisable(GL11.GL_BLEND);
    //
    // return true;
    // }
    //
    // return true;
    }
    return false;
}
Also used : ItemPart(com.bluepowermod.item.ItemPart) RenderHelper(uk.co.qmunity.lib.client.render.RenderHelper) IIcon(net.minecraft.util.IIcon) Rotation(uk.co.qmunity.lib.transform.Rotation) Vec3d(uk.co.qmunity.lib.vec.Vec3d) PartRedwireFaceUninsulated(com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated) IScrewdriver(com.bluepowermod.api.misc.IScrewdriver) IPart(uk.co.qmunity.lib.part.IPart) Vec3(net.minecraft.util.Vec3) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) PartRedwireFace(com.bluepowermod.part.wire.redstone.PartRedwireFace) ItemStack(net.minecraft.item.ItemStack) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube)

Example 53 with ItemStack

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

the class GateNullCell method getStackWithData.

public static ItemStack getStackWithData(GateNullCell gate) {
    ItemStack is = PartManager.getPartInfo("nullcell").getStack();
    if (is.getTagCompound() == null)
        is.setTagCompound(new NBTTagCompound());
    NBTTagCompound tag = new NBTTagCompound();
    gate.writeToNBT(tag);
    is.getTagCompound().setTag("tileData", tag);
    is.getTagCompound().setBoolean("hideSilkyTooltip", true);
    return is;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 54 with ItemStack

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

the class AlloyFurnaceRegistry method addRecipe.

@Override
public void addRecipe(ItemStack craftingResult, Object... requiredItems) {
    if (craftingResult == null || craftingResult.getItem() == null)
        throw new NullPointerException("Can't register an Alloy Furnace recipe with a null output stack or item");
    ItemStack[] requiredStacks = new ItemStack[requiredItems.length];
    for (int i = 0; i < requiredStacks.length; i++) {
        if (requiredItems[i] instanceof ItemStack) {
            requiredStacks[i] = (ItemStack) requiredItems[i];
        } else if (requiredItems[i] instanceof Item) {
            requiredStacks[i] = new ItemStack((Item) requiredItems[i], 1, OreDictionary.WILDCARD_VALUE);
        } else if (requiredItems[i] instanceof Block) {
            requiredStacks[i] = new ItemStack(Item.getItemFromBlock((Block) requiredItems[i]), 1, OreDictionary.WILDCARD_VALUE);
        } else {
            throw new IllegalArgumentException("Alloy Furnace crafting ingredients can only be ItemStack, Item or Block!");
        }
    }
    addRecipe(new StandardAlloyFurnaceRecipe(craftingResult, requiredStacks));
}
Also used : Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 55 with ItemStack

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

the class AlloyFurnaceRegistry method generateRecyclingRecipes.

@SuppressWarnings("unchecked")
public void generateRecyclingRecipes() {
    Collections.addAll(blacklist, Config.alloyFurnaceBlacklist);
    List<Item> blacklist = new ArrayList<Item>();
    for (String configString : this.blacklist) {
        Item item = GameData.getItemRegistry().getObject(configString);
        if (item != null) {
            blacklist.add(item);
        } else {
            BluePower.log.info("Config entry \"" + configString + "\" not an existing item/block name! Will not be added to the blacklist");
        }
    }
    List<ItemStack> registeredRecycledItems = new ArrayList<ItemStack>();
    List<ItemStack> registeredResultItems = new ArrayList<ItemStack>();
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe recipe : recipes) {
        int recyclingAmount = 0;
        ItemStack currentlyRecycledInto = null;
        for (ItemStack recyclingItem : bufferedRecyclingItems) {
            try {
                if (recipe instanceof ShapedRecipes) {
                    ShapedRecipes shaped = (ShapedRecipes) recipe;
                    if (shaped.recipeItems != null) {
                        for (ItemStack input : shaped.recipeItems) {
                            if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
                                ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                    currentlyRecycledInto = moltenDownItem;
                                    recyclingAmount += moltenDownItem.stackSize;
                                }
                            }
                        }
                    }
                } else if (recipe instanceof ShapelessRecipes) {
                    ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
                    if (shapeless.recipeItems != null) {
                        for (ItemStack input : (List<ItemStack>) shapeless.recipeItems) {
                            if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
                                ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                    currentlyRecycledInto = moltenDownItem;
                                    recyclingAmount += moltenDownItem.stackSize;
                                }
                            }
                        }
                    }
                } else if (recipe instanceof ShapedOreRecipe) {
                    ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
                    if (shapedOreRecipe.getInput() != null) {
                        for (Object input : shapedOreRecipe.getInput()) {
                            if (input != null) {
                                List<ItemStack> itemList;
                                if (input instanceof ItemStack) {
                                    itemList = new ArrayList<ItemStack>();
                                    itemList.add((ItemStack) input);
                                } else {
                                    itemList = (List<ItemStack>) input;
                                }
                                for (ItemStack item : itemList) {
                                    if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
                                        ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                        if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                            currentlyRecycledInto = moltenDownItem;
                                            recyclingAmount += moltenDownItem.stackSize;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                } else if (recipe instanceof ShapelessOreRecipe) {
                    ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
                    for (Object input : shapeless.getInput()) {
                        if (input != null) {
                            List<ItemStack> itemList;
                            if (input instanceof ItemStack) {
                                itemList = new ArrayList<ItemStack>();
                                itemList.add((ItemStack) input);
                            } else {
                                itemList = (List<ItemStack>) input;
                            }
                            for (ItemStack item : itemList) {
                                if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
                                    ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                    if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                        currentlyRecycledInto = moltenDownItem;
                                        recyclingAmount += moltenDownItem.stackSize;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            } catch (Throwable e) {
                BluePower.log.error("Error when generating an Alloy Furnace recipe for item " + recyclingItem.getDisplayName() + ", recipe output: " + recipe.getRecipeOutput().getDisplayName());
                e.printStackTrace();
            }
        }
        if (recyclingAmount > 0 && recipe.getRecipeOutput().stackSize > 0) {
            boolean shouldAdd = true;
            for (int i = 0; i < registeredRecycledItems.size(); i++) {
                if (ItemStackUtils.isItemFuzzyEqual(registeredRecycledItems.get(i), recipe.getRecipeOutput())) {
                    if (registeredResultItems.get(i).stackSize < recyclingAmount) {
                        shouldAdd = false;
                        break;
                    } else {
                        registeredResultItems.remove(i);
                        registeredRecycledItems.remove(i);
                        i--;
                    }
                }
            }
            if (shouldAdd) {
                if (blacklist.contains(recipe.getRecipeOutput().getItem())) {
                    BluePower.log.info("Skipped adding item/block " + recipe.getRecipeOutput().getDisplayName() + " to the Alloy Furnace recipes.");
                    continue;
                }
                ItemStack resultItem = new ItemStack(currentlyRecycledInto.getItem(), Math.min(64, recyclingAmount), currentlyRecycledInto.getItemDamage());
                registeredResultItems.add(resultItem);
                registeredRecycledItems.add(recipe.getRecipeOutput());
            }
        }
    }
    for (int i = 0; i < registeredResultItems.size(); i++) {
        addRecipe(registeredResultItems.get(i), registeredRecycledItems.get(i));
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) Item(net.minecraft.item.Item) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

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