gpt4 book ai didi

java - Minecraft Forge 获取 IRecipe 所需的 ItemStacks

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:50:06 25 4
gpt4 key购买 nike

我正在为 Minecraft 1.10.2 开发一个模组,我正在尝试从 IRecipe 接口(interface)中获取输入 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;
}

关于java - Minecraft Forge 获取 IRecipe 所需的 ItemStacks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44803995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com