Search in sources :

Example 6 with ShapelessRecipes

use of net.minecraft.item.crafting.ShapelessRecipes in project SecurityCraft by Geforce132.

the class GuiSCManual method updateRecipeAndIcons.

private void updateRecipeAndIcons() {
    if (currentPage < 0) {
        recipe = null;
        hoverCheckers.clear();
        return;
    }
    hoverCheckers.clear();
    if (SecurityCraft.instance.manualPages.get(currentPage).hasCustomRecipe())
        recipe = SecurityCraft.instance.manualPages.get(currentPage).getRecipe();
    else
        for (Object object : CraftingManager.getInstance().getRecipeList()) {
            if (object instanceof ShapedRecipes) {
                ShapedRecipes recipe = (ShapedRecipes) object;
                if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
                    this.recipe = recipe.recipeItems;
                    break;
                }
            } else if (object instanceof ShapelessRecipes) {
                ShapelessRecipes recipe = (ShapelessRecipes) object;
                if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
                    this.recipe = toItemStackArray(recipe.recipeItems);
                    break;
                }
            }
            recipe = null;
        }
    if (recipe != null) {
        outer: for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if ((i * 3) + j == recipe.length)
                    break outer;
                if (recipe[(i * 3) + j] != null)
                    hoverCheckers.add(new CustomHoverChecker(144 + (i * 20), 144 + (i * 20) + 16, (k + 100) + (j * 20), (k + 100) + (j * 20) + 16, 20, recipe[(i * 3) + j].getDisplayName()));
            }
        }
    } else if (SecurityCraft.instance.manualPages.get(currentPage).isRecipeDisabled())
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.disabled")));
    else if (SecurityCraft.instance.manualPages.get(currentPage).getHelpInfo().equals("help.reinforced.info"))
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.recipe.reinforced")));
    else {
        String name = SecurityCraft.instance.manualPages.get(currentPage).getItem().getUnlocalizedName().substring(5);
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.recipe." + name)));
    }
    Item item = SecurityCraft.instance.manualPages.get(currentPage).getItem();
    TileEntity te = ((item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof ITileEntityProvider) ? ((ITileEntityProvider) ((ItemBlock) item).getBlock()).createNewTileEntity(Minecraft.getMinecraft().theWorld, 0) : null);
    Block itemBlock = ((item instanceof ItemBlock) ? ((ItemBlock) item).getBlock() : null);
    if (te != null) {
        if (te instanceof IOwnable)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 29, (k + 29) + 16, 20, StatCollector.translateToLocal("gui.scManual.ownableBlock")));
        if (te instanceof IPasswordProtected)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 55, (k + 55) + 16, 20, StatCollector.translateToLocal("gui.scManual.passwordProtectedBlock")));
        if (te instanceof TileEntitySCTE && ((TileEntitySCTE) te).isActivatedByView())
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 81, (k + 81) + 16, 20, StatCollector.translateToLocal("gui.scManual.viewActivatedBlock")));
        if (itemBlock instanceof IExplosive)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 107, (k + 107) + 16, 20, StatCollector.translateToLocal("gui.scManual.explosiveBlock")));
        if (te instanceof CustomizableSCTE)
            hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 213, (k + 213) + 16, 20, StatCollector.translateToLocal("gui.scManual.customizableBlock")));
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IPasswordProtected(net.geforcemods.securitycraft.api.IPasswordProtected) CustomHoverChecker(net.geforcemods.securitycraft.gui.components.CustomHoverChecker) TileEntitySCTE(net.geforcemods.securitycraft.api.TileEntitySCTE) ItemBlock(net.minecraft.item.ItemBlock) TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) IExplosive(net.geforcemods.securitycraft.api.IExplosive) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 7 with ShapelessRecipes

use of net.minecraft.item.crafting.ShapelessRecipes 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

ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)7 ItemStack (net.minecraft.item.ItemStack)6 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)6 ArrayList (java.util.ArrayList)4 Item (net.minecraft.item.Item)4 IRecipe (net.minecraft.item.crafting.IRecipe)4 Block (net.minecraft.block.Block)3 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)3 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)3 List (java.util.List)2 TileEntity (net.minecraft.tileentity.TileEntity)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 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 ChemthrowerEffect (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect)1 ChemthrowerEffect_Extinguish (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Extinguish)1 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)1