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

标签 java config minecraft minecraft-forge

我正在尝试为 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/

相关文章:

java - 无需通过多层传递配置对象即可访问 hadoop 配置设置

java - 如何在 spigot 1.16.4 中获取玩家的 ping

java - 每个 jsf 的 C 都不起作用。日本科学基金会

java - (LibGDX And​​roid) 无法实例化 Activity ComponentInfo ClassNotFoundException

java - 如何在运行时添加单选按钮

javascript - Typescript 没有选择 Jest 类型

java - jdbc : front end java, 后端 Oracle 10g Express 版

Java系统级deployment.properties

java - 在 Bukkit 中从原理图中设置 block 数据?

java - 如何进行 foreach 调用