Search in sources :

Example 11 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project RebornCore by TechReborn.

the class RebornCraftingHelper method addShapedRecipe.

/**
 * Adds a basic shaped recipe
 *
 * @param output The stack that should be produced
 */
public static void addShapedRecipe(ItemStack output, Object... params) {
    ResourceLocation location = getNameForRecipe(output);
    CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(params);
    ShapedRecipes recipe = new ShapedRecipes(output.getItem().getRegistryName().toString(), primer.width, primer.height, primer.input, output);
    recipe.setRegistryName(location);
    GameData.register_impl(recipe);
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) ResourceLocation(net.minecraft.util.ResourceLocation) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper)

Example 12 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project RebornCore by TechReborn.

the class RecipeRemover method removeShapedRecipe.

public static void removeShapedRecipe(ItemStack resultItem) {
    for (IRecipe tmpRecipe : CraftingManager.REGISTRY) {
        if (tmpRecipe instanceof ShapedRecipes) {
            ShapedRecipes recipe = (ShapedRecipes) tmpRecipe;
            ItemStack recipeResult = recipe.getRecipeOutput();
            if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
                removeRecipe(recipe);
            }
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 13 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Minechem by iopleke.

the class Recipe method init.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void init() {
    Map<MapKey, ArrayList<Recipe>> preCullRecipes = new Hashtable<MapKey, ArrayList<Recipe>>();
    recipes = new LinkedHashMap<MapKey, Recipe>();
    smelting = FurnaceRecipes.smelting().getSmeltingList();
    List craftingRecipes = CraftingManager.getInstance().getRecipeList();
    if (Loader.isModLoaded("RotaryCraft")) {
        List add = getRotaryRecipes();
        if (add != null) {
            craftingRecipes.addAll(add);
        }
    }
    if (Loader.isModLoaded("Railcaft")) {
        List add = getRailcraftRecipes();
        if (add != null) {
            craftingRecipes.addAll(add);
        }
    }
    for (Object recipe : craftingRecipes) {
        if (recipe instanceof IRecipe) {
            ItemStack input = ((IRecipe) recipe).getRecipeOutput();
            if (!invalidStack(input)) {
                LogHelper.debug("Adding recipe for " + input.toString());
                ItemStack[] components = null;
                List<ItemStack> inputs = new ArrayList<ItemStack>();
                if (recipe.getClass().equals(ShapelessOreRecipe.class) && ((ShapelessOreRecipe) recipe).getInput().size() > 0) {
                    for (Object o : ((ShapelessOreRecipe) recipe).getInput()) {
                        if (o instanceof ItemStack) {
                            inputs.add((ItemStack) o);
                        }
                    }
                } else if (recipe.getClass().equals(ShapedOreRecipe.class)) {
                    for (Object o : ((ShapedOreRecipe) recipe).getInput()) {
                        if (o instanceof ItemStack) {
                            inputs.add((ItemStack) o);
                        } else if (o instanceof String) {
                            inputs.add(OreDictionary.getOres((String) o).get(0));
                        } else if (o instanceof ArrayList && !((ArrayList) o).isEmpty()) {
                            inputs.add((ItemStack) ((ArrayList) o).get(0));
                        }
                    }
                } else if (recipe.getClass().equals(ShapelessRecipes.class) && ((ShapelessRecipes) recipe).recipeItems.toArray() instanceof ItemStack[]) {
                    inputs = (List<ItemStack>) (List<?>) (((ShapelessRecipes) recipe).recipeItems);
                } else if (recipe.getClass().equals(ShapedRecipes.class)) {
                    inputs.addAll(Arrays.asList(((ShapedRecipes) recipe).recipeItems));
                }
                MapKey key = MapKey.getKey(input);
                if (inputs.size() > 0 && key != null) {
                    for (Iterator<ItemStack> itr = inputs.iterator(); itr.hasNext(); ) {
                        ItemStack component = itr.next();
                        if (invalidStack(component) || component.getItem().hasContainerItem(component))
                            itr.remove();
                    }
                    components = inputs.toArray(new ItemStack[inputs.size()]);
                    if (components.length > 0) {
                        Recipe addRecipe = new Recipe(input, components);
                        addPreCullRecipe(key, addRecipe, preCullRecipes);
                    }
                }
            }
        }
    }
    for (ItemStack input : smelting.keySet()) {
        ItemStack output = smelting.get(input);
        if (invalidStack(input) || invalidStack(output)) {
            continue;
        }
        MapKey key = MapKey.getKey(output);
        if (key != null) {
            Recipe addRecipe = new Recipe(output, new ItemStack[] { input });
            LogHelper.debug("Adding Smelting recipe for " + output.toString());
            addPreCullRecipe(key, addRecipe, preCullRecipes);
        }
    }
    for (Map.Entry<MapKey, ArrayList<Recipe>> entry : preCullRecipes.entrySet()) {
        if (entry.getValue() != null && entry.getValue().size() > 0) {
            LogHelper.debug("Culling recipe for " + entry.getValue().get(0).output.toString());
        }
        int depth = cullRecipes(entry, preCullRecipes);
        if (entry.getValue().size() == 1) {
            Recipe addRecipe = entry.getValue().get(0);
            addRecipe.depth = depth;
            recipes.put(entry.getKey(), addRecipe);
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) DecomposerRecipe(minechem.tileentity.decomposer.DecomposerRecipe) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 14 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project ArsMagica2 by Mithion.

the class RecipeUtilities method addShapedRecipeFirst.

public static void addShapedRecipeFirst(List recipeList, ItemStack itemstack, Object... objArray) {
    String var3 = "";
    int var4 = 0;
    int var5 = 0;
    int var6 = 0;
    if (objArray[var4] instanceof String[]) {
        String[] var7 = ((String[]) objArray[var4++]);
        for (int var8 = 0; var8 < var7.length; ++var8) {
            String var9 = var7[var8];
            ++var6;
            var5 = var9.length();
            var3 = var3 + var9;
        }
    } else {
        while (objArray[var4] instanceof String) {
            String var11 = (String) objArray[var4++];
            ++var6;
            var5 = var11.length();
            var3 = var3 + var11;
        }
    }
    HashMap var12;
    for (var12 = new HashMap(); var4 < objArray.length; var4 += 2) {
        Character var13 = (Character) objArray[var4];
        ItemStack var14 = null;
        if (objArray[var4 + 1] instanceof Item) {
            var14 = new ItemStack((Item) objArray[var4 + 1]);
        } else if (objArray[var4 + 1] instanceof Block) {
            var14 = new ItemStack((Block) objArray[var4 + 1], 1, Short.MAX_VALUE);
        } else if (objArray[var4 + 1] instanceof ItemStack) {
            var14 = (ItemStack) objArray[var4 + 1];
        }
        var12.put(var13, var14);
    }
    ItemStack[] var15 = new ItemStack[var5 * var6];
    for (int var16 = 0; var16 < var5 * var6; ++var16) {
        char var10 = var3.charAt(var16);
        if (var12.containsKey(Character.valueOf(var10))) {
            var15[var16] = ((ItemStack) var12.get(Character.valueOf(var10))).copy();
        } else {
            var15[var16] = null;
        }
    }
    ShapedRecipes var17 = new ShapedRecipes(var5, var6, var15, itemstack);
    recipeList.add(0, var17);
}
Also used : Item(net.minecraft.item.Item) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) HashMap(java.util.HashMap) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 15 with ShapedRecipes

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

the class AutoCraftingManager method printRecipes.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void printRecipes(ItemStack stack) {
    List<IRecipe> recipes = RecipeUtility.getRecipesByOutput(stack);
    for (IRecipe recipe : recipes) {
        if (recipe.getRecipeOutput() != null) {
            if (AutoCraftingManager.areStacksEqual(recipe.getRecipeOutput(), stack)) {
                if (recipe instanceof ShapedRecipes) {
                    printRecipe(((ShapedRecipes) recipe).recipeItems);
                } else if (recipe instanceof ShapelessRecipes) {
                    printRecipe(((ShapelessRecipes) recipe).recipeItems.toArray(new Object[1]));
                } else if (recipe instanceof ShapedOreRecipe) {
                    ShapedOreRecipe oreRecipe = (ShapedOreRecipe) recipe;
                    printRecipe((Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input"));
                } else if (recipe instanceof ShapelessOreRecipe) {
                    ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) recipe;
                    ArrayList oreRecipeInput = ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
                    for (Object obj : oreRecipeInput) {
                        System.out.println(obj);
                    }
                }
            }
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ArrayList(java.util.ArrayList) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

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