Search in sources :

Example 26 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Armourers-Workshop by RiskyKen.

the class BookPageRecipe method renderRecipe.

private void renderRecipe(Minecraft mc, FontRenderer fontRenderer, IRecipe recipe, int x, int y) {
    RenderHelper.enableGUIStandardItemLighting();
    // ModRenderHelper.disableLighting();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    if (recipe instanceof ShapedRecipes) {
        ShapedRecipes shapedRecipe = (ShapedRecipes) recipe;
        for (int ix = 0; ix < shapedRecipe.recipeWidth; ix++) {
            for (int iy = 0; iy < shapedRecipe.recipeHeight; iy++) {
                itemRender.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), shapedRecipe.recipeItems[0], x, y + 10);
            }
        }
    }
    if (recipe instanceof ShapedOreRecipe) {
        ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
        Object[] input = shapedOreRecipe.getInput();
        int width = (Integer) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shapedOreRecipe, "width");
        int height = (Integer) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shapedOreRecipe, "height");
        for (int ix = 0; ix < width; ix++) {
            for (int iy = 0; iy < height; iy++) {
                Object inputObj = input[ix + iy * width];
                if (inputObj != null && (inputObj instanceof ItemStack | inputObj instanceof ArrayList<?>)) {
                    ItemStack stack;
                    if (inputObj instanceof ArrayList) {
                        ArrayList<ItemStack> list = (ArrayList) inputObj;
                        stack = (ItemStack) list.get(0);
                    } else {
                        stack = (ItemStack) inputObj;
                    }
                    if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
                        ArrayList<ItemStack> subItems = new ArrayList<ItemStack>();
                        stack.getItem().getSubItems(stack.getItem(), null, subItems);
                        int item = MathHelper.floor_double((double) (System.currentTimeMillis() + (ix + iy) * 1000) / 1000 % subItems.size());
                        stack = subItems.get(item);
                    }
                    itemRender.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), stack, x + 32 + ix * 18, y + 30 + iy * 18 + 10);
                    itemRender.renderItemOverlayIntoGUI(fontRenderer, mc.getTextureManager(), stack, x + 32 + ix * 18, y + 30 + iy * 18 + 10);
                }
            }
        }
    }
    if (recipe instanceof ShapelessRecipes) {
        ShapelessRecipes shapelessRecipes = (ShapelessRecipes) recipe;
    }
    if (recipe instanceof ShapelessOreRecipe) {
        ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe;
        int ix = 0;
        int iy = 0;
        for (int i = 0; i < shapelessOreRecipe.getRecipeSize(); i++) {
            Object inputObj = shapelessOreRecipe.getInput().get(i);
            if (inputObj != null && (inputObj instanceof ItemStack | inputObj instanceof ArrayList<?>)) {
                ItemStack stack;
                if (inputObj instanceof ArrayList) {
                    ArrayList<ItemStack> list = (ArrayList) inputObj;
                    stack = (ItemStack) list.get(0);
                } else {
                    stack = (ItemStack) inputObj;
                }
                itemRender.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), stack, x + 32 + ix * 18, y + 30 + iy * 18 + 10);
                itemRender.renderItemOverlayIntoGUI(fontRenderer, mc.getTextureManager(), stack, x + 32 + ix * 18, y + 30 + iy * 18 + 10);
            }
            ix++;
            if (ix > 2) {
                ix = 0;
                iy++;
            }
        }
    }
    itemRender.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), recipe.getRecipeOutput(), x + 50, y + 100);
    GL11.glDisable(GL11.GL_LIGHTING);
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 27 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project PneumaticCraft by MineMaarten.

the class CraftingRegistrator method addPressureChamberStorageBlockRecipes.

/**
 * Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
 */
public static void addPressureChamberStorageBlockRecipes() {
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe recipe : recipes) {
        if (recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes) recipe;
            ItemStack[] input = shaped.recipeItems;
            ItemStack ref = input[0];
            if (ref == null || input.length < 9)
                continue;
            boolean valid = true;
            for (int i = 0; i < 9; i++) {
                if (input[i] == null || !input[i].isItemEqual(ref)) {
                    valid = false;
                    break;
                }
            }
            if (valid) {
                ItemStack inputStack = ref.copy();
                inputStack.stackSize = 9;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack }, 1.0F, new ItemStack[] { shaped.getRecipeOutput() }, false));
                ItemStack inputStack2 = shaped.getRecipeOutput().copy();
                inputStack2.stackSize = 1;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack2 }, -0.5F, new ItemStack[] { inputStack }, false));
            }
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack) PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe)

Example 28 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Engine by VoltzEngine-Project.

the class AutoCraftingManager method getReverseRecipe.

/**
 * Gets a basic array containing all items that were used to craft the given item. Doesn't sort
 * threw the recipes and will return the first possible recipe
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ItemStack[] getReverseRecipe(ItemStack outputItem, int outputSize) {
    for (Object object : CraftingManager.getInstance().getRecipeList()) {
        if (object instanceof IRecipe) {
            if (((IRecipe) object).getRecipeOutput() != null) {
                if (((IRecipe) object).getRecipeOutput().isItemEqual(outputItem) && (outputSize == -1 || ((IRecipe) object).getRecipeOutput().stackSize == outputItem.stackSize)) {
                    if (object instanceof ShapedRecipes) {
                        return ((ShapedRecipes) object).recipeItems.clone();
                    } else if (object instanceof ShapelessRecipes) {
                        return (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[9]).clone();
                    } else if (object instanceof ShapedOreRecipe) {
                        ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
                        Object[] recipeItems = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
                        ItemStack[] actualResources;
                        if (recipeItems != null) {
                            actualResources = new ItemStack[recipeItems.length];
                            for (int i = 0; i < recipeItems.length; i++) {
                                if (recipeItems[i] instanceof ItemStack) {
                                    actualResources[i] = ((ItemStack) recipeItems[i]).copy();
                                } else if (recipeItems[i] instanceof ArrayList) {
                                    Object[] ingredientsArray = ((ArrayList) recipeItems[i]).toArray();
                                    for (int x = 0; x < ingredientsArray.length; x++) {
                                        if (ingredientsArray[x] != null && ingredientsArray[x] instanceof ItemStack) {
                                            actualResources[i] = ((ItemStack) ingredientsArray[x]).copy();
                                            break;
                                        }
                                    }
                                }
                            }
                            return actualResources;
                        }
                    } else if (object instanceof ShapelessOreRecipe) {
                        ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
                        return (ItemStack[]) ((ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input")).toArray(new ItemStack[9]).clone();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)28 ItemStack (net.minecraft.item.ItemStack)19 IRecipe (net.minecraft.item.crafting.IRecipe)18 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)14 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)13 ArrayList (java.util.ArrayList)10 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)8 List (java.util.List)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 Block (net.minecraft.block.Block)5 Ingredient (net.minecraft.item.crafting.Ingredient)5 ResourceLocation (net.minecraft.util.ResourceLocation)3 Pair (com.builtbroken.jlib.type.Pair)2 ItemBlock (net.minecraft.item.ItemBlock)2 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)1 ItemSpellPart (am2.items.ItemSpellPart)1 RecipeArsMagica (am2.items.RecipeArsMagica)1