gpt4 book ai didi

java - Minecraft Forge 1.7.10 - 从 ID 中删除配方

转载 作者:行者123 更新时间:2023-11-30 08:18:33 25 4
gpt4 key购买 nike

我正在尝试为 Minecraft 1.7.10 制作一个小型实用程序模组,您可以在其中将 ID 列表放入配置文件中,模组将从游戏中删除它们的配方。我的配置文件可以正常工作,但我似乎无法删除食谱。

我删除食谱的方法是我在其他地方的几个论坛主题中看到的,并略微修改以适用于我的配置文件(或者不适用于我的情况)。

方法如下:

private void removeRecipes(String toDelete)
{

ArrayList<?> recipes = (ArrayList<?>) CraftingManager.getInstance().getRecipeList();

ItemStack recipeResult = null;

ItemStack resultItem = new ItemStack((Item)Item.itemRegistry.getObject(toDelete));
resultItem.stackSize = 1;
resultItem.setItemDamage(0);

for (int scan = 0; scan < recipes.size(); scan++)
{
IRecipe tmpRecipe = (IRecipe) recipes.get(scan);
if (tmpRecipe instanceof ShapedRecipes)
{
ShapedRecipes recipe = (ShapedRecipes)tmpRecipe;
recipeResult = recipe.getRecipeOutput();

recipeResult.stackSize = 1;
recipeResult.setItemDamage(0);
}
if (tmpRecipe instanceof ShapelessRecipes)
{
ShapelessRecipes recipe = (ShapelessRecipes)tmpRecipe;
recipeResult = recipe.getRecipeOutput();

recipeResult.stackSize = 1;
recipeResult.setItemDamage(0);
}
if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
{
System.out.println("[RecipeRemover] Removed Recipe: " + recipes.get(scan) + " -> " + recipeResult);
recipes.remove(scan);
}
}
}

最佳答案

我的代码显然有些问题,但这是一种有效得多的方法(并且应该普遍适用):

@SuppressWarnings("unchecked")
private void removeRecipes(String toDelete)
{
ItemStack resultItem = new ItemStack((Item)Item.itemRegistry.getObject(toDelete));
resultItem.stackSize = 1;
resultItem.setItemDamage(0);

List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();

for (int i = 0; i < recipes.size(); i++)
{
IRecipe tmpRecipe = recipes.get(i);

ItemStack recipeResult = tmpRecipe.getRecipeOutput();
if(recipeResult != null)
{
recipeResult.stackSize = 1;
recipeResult.setItemDamage(0);
}

if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
{
recipes.remove(i--);
}
}
}

关于java - Minecraft Forge 1.7.10 - 从 ID 中删除配方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27459815/

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