Search in sources :

Example 1 with RecipeArsMagica

use of am2.items.RecipeArsMagica in project ArsMagica2 by Mithion.

the class GuiArcaneCompendium method getAndAnalyzeRecipe.

private void getAndAnalyzeRecipe() {
    if (renderStack == null)
        return;
    if (renderStack.getItem() == ItemsCommonProxy.essence || renderStack.getItem() == ItemsCommonProxy.deficitCrystal) {
        RecipeArsMagica essenceRecipe = RecipesEssenceRefiner.essenceRefinement().recipeFor(renderStack);
        if (essenceRecipe != null) {
            craftingComponents = essenceRecipe.getRecipeItems();
            recipeHeight = 2;
        } else {
            craftingComponents = null;
        }
    } else if (renderStack.getItem() instanceof ItemSpellPart) {
        ISkillTreeEntry part = SkillManager.instance.getSkill(this.entryName);
        if (part == null)
            return;
        ArrayList<Object> recipe = new ArrayList<Object>();
        if (part instanceof ISpellPart) {
            Object[] recipeItems = ((ISpellPart) part).getRecipeItems();
            SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipeItems);
            MinecraftForge.EVENT_BUS.post(event);
            recipeItems = event.recipeItems;
            if (recipeItems != null) {
                for (int i = 0; i < recipeItems.length; ++i) {
                    Object o = recipeItems[i];
                    boolean matches = false;
                    if (o instanceof ItemStack) {
                        recipe.add(o);
                    } else if (o instanceof Item) {
                        recipe.add(new ItemStack((Item) o));
                    } else if (o instanceof Block) {
                        recipe.add(new ItemStack((Block) o));
                    } else if (o instanceof String) {
                        if (((String) o).startsWith("P:")) {
                            // potion
                            String s = ((String) o).substring(2);
                            int pfx = SpellRecipeManager.parsePotionMeta(s);
                            recipe.add(new ItemStack(Items.potionitem, 1, pfx));
                        } else if (((String) o).startsWith("E:")) {
                            // essence
                            String s = ((String) o);
                            try {
                                int[] types = SpellRecipeManager.ParseEssenceIDs(s);
                                int type = 0;
                                for (int t : types) type |= t;
                                int amount = (Integer) recipeItems[++i];
                                recipe.add(new ItemStack(ItemsCommonProxy.essence, amount, ItemsCommonProxy.essence.META_MAX + type));
                            } catch (Throwable t) {
                                continue;
                            }
                        } else {
                            recipe.add(OreDictionary.getOres((String) o));
                        }
                    }
                }
            }
        }
        craftingComponents = recipe.toArray();
    } else {
        IRecipe recipe = RecipeUtilities.getRecipeFor(renderStack);
        if (recipe != null) {
            renderStack = recipe.getRecipeOutput();
            if (recipe instanceof ShapedRecipes) {
                recipeWidth = ((ShapedRecipes) recipe).recipeWidth;
                recipeHeight = ((ShapedRecipes) recipe).recipeHeight;
                craftingComponents = ((ShapedRecipes) recipe).recipeItems;
            } else if (recipe instanceof ShapedOreRecipe) {
                recipeWidth = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "width");
                recipeHeight = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "height");
                craftingComponents = ((ShapedOreRecipe) recipe).getInput();
            } else if (recipe instanceof ShapelessRecipes) {
                recipeWidth = ((ShapelessRecipes) recipe).getRecipeSize();
                recipeHeight = -1;
                craftingComponents = ((ShapelessRecipes) recipe).recipeItems.toArray();
            } else if (recipe instanceof ShapelessOreRecipe) {
                recipeWidth = ((ShapelessOreRecipe) recipe).getRecipeSize();
                recipeHeight = -1;
                craftingComponents = ((ShapelessOreRecipe) recipe).getInput().toArray();
            } else {
                craftingComponents = null;
            }
        } else {
            craftingComponents = null;
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ItemSpellPart(am2.items.ItemSpellPart) ISpellPart(am2.api.spell.component.interfaces.ISpellPart) RecipeArsMagica(am2.items.RecipeArsMagica) Item(net.minecraft.item.Item) RenderItem(net.minecraft.client.renderer.entity.RenderItem) SpellRecipeItemsEvent(am2.api.events.SpellRecipeItemsEvent) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Aggregations

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 Block (net.minecraft.block.Block)1 RenderItem (net.minecraft.client.renderer.entity.RenderItem)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)1 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)1 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)1 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)1