Search in sources :

Example 6 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Railcraft by Railcraft.

the class CraftingPlugin method makeVanillaShapedRecipe.

public static IRecipe makeVanillaShapedRecipe(ItemStack output, Object... components) {
    String s = "";
    int index = 0;
    int width = 0;
    int height = 0;
    if (components[index] instanceof String[]) {
        String[] as = (String[]) components[index++];
        for (String s2 : as) {
            height++;
            width = s2.length();
            s = (new StringBuilder()).append(s).append(s2).toString();
        }
    } else {
        while (components[index] instanceof String) {
            String s1 = (String) components[index++];
            height++;
            width = s1.length();
            s = (new StringBuilder()).append(s).append(s1).toString();
        }
    }
    HashMap<Character, ItemStack> hashMap = new HashMap<Character, ItemStack>();
    for (; index < components.length; index += 2) {
        Character character = (Character) components[index];
        ItemStack itemStack = InvTools.emptyStack();
        if (components[index + 1] instanceof Item) {
            itemStack = new ItemStack((Item) components[index + 1]);
        } else if (components[index + 1] instanceof Block) {
            itemStack = new ItemStack((Block) components[index + 1], 1, -1);
        } else if (components[index + 1] instanceof ItemStack) {
            itemStack = (ItemStack) components[index + 1];
        }
        hashMap.put(character, itemStack);
    }
    ItemStack[] recipeArray = new ItemStack[width * height];
    for (int i1 = 0; i1 < width * height; i1++) {
        char c = s.charAt(i1);
        if (hashMap.containsKey(c)) {
            recipeArray[i1] = hashMap.get(c).copy();
        } else {
            recipeArray[i1] = InvTools.emptyStack();
        }
    }
    return new ShapedRecipes(width, height, recipeArray, output);
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) HashMap(java.util.HashMap) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes 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 8 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Tropicraft by Tropicraft.

the class Encyclopedia method getFormattedRecipe.

public RecipeEntry getFormattedRecipe(IRecipe recipe) {
    // TODO support other kinds of recipes
    if (recipe instanceof ShapedRecipes) {
        ShapedRecipes shaped = (ShapedRecipes) recipe;
        int width = shaped.recipeWidth;
        int height = shaped.recipeHeight;
        NonNullList<Ingredient> items = shaped.recipeItems;
        ItemStack output = recipe.getRecipeOutput();
        return new RecipeEntry(width, height, items, output);
    } else if (recipe instanceof ShapelessRecipes) {
        return new RecipeEntry(3, 3, recipe.getIngredients(), recipe.getRecipeOutput());
    }
    return null;
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 9 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project EnderIO by SleepyTrousers.

the class Crafting method register.

@Override
public void register(@Nonnull String recipeName) {
    if (valid && active) {
        final ResourceLocation recipeRL = mkRL(recipeName);
        final IForgeRegistry<IRecipe> registry = ForgeRegistries.RECIPES;
        if (grid != null) {
            if (upgrade) {
                log("ShapedRecipe.Upgrade", recipeName, recipeRL, getOutput().getItemStack(), grid.getIngredients());
                registry.register(new ShapedRecipe.Upgrade(recipeRL, grid.getWidth(), grid.getHeight(), grid.getIngredients(), getOutput().getThing()));
            } else {
                log("ShapedRecipe", recipeName, recipeRL, getOutput().getItemStack(), grid.getIngredients());
                registry.register(new ShapedRecipe(recipeRL, grid.getWidth(), grid.getHeight(), grid.getIngredients(), getOutput().getThing()));
            }
            if (getOutput().hasAlternatives()) {
                getOutput().getAlternatives().apply(new Callback<ItemStack>() {

                    @Override
                    public void apply(@Nonnull ItemStack alternative) {
                        Log.debug("Providing synthetic alternative recipe to JEI for oredicted output: " + alternative + ": " + grid.getIngredients());
                        JeiAccessor.addAlternativeRecipe(new ShapedRecipes("", grid.getWidth(), grid.getHeight(), grid.getIngredients(), alternative));
                    }
                });
            }
        } else {
            if (upgrade) {
                log("GenericUpgradeRecipeShapeless", recipeName, recipeRL, getOutput().getItemStack(), shapeless.getIngredients());
                registry.register(new ShapelessRecipe.Upgrade(recipeRL, shapeless.getIngredients(), getOutput().getThing()));
            } else {
                log("ShapelessOreRecipe", recipeName, recipeRL, getOutput().getItemStack(), shapeless.getIngredients());
                registry.register(new ShapelessRecipe(recipeRL, shapeless.getIngredients(), getOutput().getThing()));
            }
            if (getOutput().hasAlternatives()) {
                getOutput().getAlternatives().apply(new Callback<ItemStack>() {

                    @Override
                    public void apply(@Nonnull ItemStack alternative) {
                        Log.debug("Providing synthetic alternative recipe to JEI for oredicted output: " + alternative + ": " + shapeless.getIngredients());
                        JeiAccessor.addAlternativeRecipe(new ShapelessRecipes("", alternative, shapeless.getIngredients()));
                    }
                });
            }
        }
    } else {
        Log.debug("Skipping Crafting '" + (getOutput() == null ? "null" : getOutput().getItemStack()) + "' (valid=" + valid + ", active=" + active + ")");
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ResourceLocation(net.minecraft.util.ResourceLocation) ShapedRecipe(crazypants.enderio.base.config.recipes.ShapedRecipe) ShapelessRecipe(crazypants.enderio.base.config.recipes.ShapelessRecipe) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 10 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Galacticraft by micdoodle8.

the class ShapedRecipeHandler method loadCraftingRecipes.

@Override
public void loadCraftingRecipes(ItemStack result) {
    for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
        if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
            CachedShapedRecipe recipe = null;
            if (irecipe instanceof ShapedRecipes) {
                recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
            } else if (irecipe instanceof ShapedOreRecipe) {
                recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
            }
            if (recipe == null) {
                continue;
            }
            recipe.computeVisuals();
            arecipes.add(recipe);
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) List(java.util.List)

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