Minecraft Forge 获取 IRecipe 所需的 ItemStacks

Minecraft Forge Getting Required ItemStacks for IRecipe

我正在为 Minecraft 1.10.2 开发 mod,我正在尝试从 IRecipe 界面中获取输入 ItemStack 数组。

我该怎么做?

下面的代码应该可以处理大部分食谱,但不是全部。如果你需要更多,我可以写更多。

     /**
     * 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;
    }