Minecraft Forge Getting Required Items for IRecipe

I am working on a mod for Minecraft 1.10.2 and I am trying to get an input array ItemStack

from the interface IRecipe

.

How can i do this?

+3


source to share


1 answer


The code below should handle most of the Recipes, but not all. If you need more, I can write more.



     /**
     * Determines the input of a IRecipe.
     * This method handles most of the IRecipes, but not all of them.
     * @param Item
     * @return Null if not handled.
     */
    private List<ItemStack> Test(IRecipe Item)
    {
        try
        {
            if (Item instanceof ShapelessRecipes)
            {
                ShapelessRecipes a = (ShapelessRecipes)Item;
                return a.recipeItems;
            }

            if (Item instanceof ShapedRecipes)
            {
                ShapedRecipes a = (ShapedRecipes)Item;
                return Arrays.asList(a.recipeItems);
            }

            if (Item instanceof ShapedOreRecipe)
            {
                ShapedOreRecipe a = (ShapedOreRecipe)Item;

                ItemStack Item2;
                NonNullList<ItemStack> Item1 = NonNullList.create();

                for (Object b: a.getInput())
                {
                    if (b instanceof ItemStack)
                    {
                        Item2 = (ItemStack)b;
                        Item1.add(Item2);
                    }

                    if (b instanceof NonNullList)
                    {
                        NonNullList<ItemStack> NonNull1 = (NonNullList<ItemStack>)b;
                        Item1.addAll(NonNull1);
                    }   

                    return Item1;
                }
            }

            if (Item instanceof ShapelessOreRecipe)
            {
                ShapelessOreRecipe a = (ShapelessOreRecipe)Item;

                ItemStack Item2;
                NonNullList<ItemStack> Item1 = NonNullList.create();

                for (Object b: a.getInput())
                {
                    if (b instanceof ItemStack)
                    {
                        Item2 = (ItemStack)b;
                        Item1.add(Item2);
                    }

                    if (b instanceof NonNullList)
                    {
                        NonNullList<ItemStack> NonNull1 = (NonNullList<ItemStack>)b;
                        Item1.addAll(NonNull1);
                    }   
                }

                return Item1;
            }
        }
        catch (Exception e)
        {
            //Handle the error
        }

        return null;
    }

      

+1


source







All Articles