Solved Cannot override Pickaxe Recipe

Discussion in 'Spigot Plugin Development' started by chrismin1302, Apr 19, 2017.

  1. Hello,
    Yesterday, as I was working on the Custom Recipes of my Custom Items I came across the following issue. I have replicated it here with some simpler code.
    Let's say that I want to override the Wooden Axe recipe to give TNT. My code would look like this:
    Code (Text):
    @SuppressWarnings("deprecation")
        public void onEnable() {
            ShapedRecipe recipe = new ShapedRecipe(new ItemStack(Material.TNT));

            recipe.shape("110", "120", "020");
            recipe.setIngredient('1', Material.WOOD, 1);
            recipe.setIngredient('2', Material.STICK);

            Bukkit.addRecipe(recipe);

            }
    And that works just fine, as you can see in the attached screenshot.
    2017-04-19_14.02.38.png
    However, let's say I wanted to override the Pickaxe Recipe instead. My code would look like this:
    Code (Text):
    @SuppressWarnings("deprecation")
        public void onEnable() {
            ShapedRecipe recipe = new ShapedRecipe(new ItemStack(Material.TNT));

            recipe.shape("111", "020", "020");
            recipe.setIngredient('1', Material.WOOD, 1);
            recipe.setIngredient('2', Material.STICK);

            Bukkit.addRecipe(recipe);

            }
    However, that doesn't work, as you can see in the attached screenshot. That's all the code that was running on the server at the time. I am running this on a 1.11.2 local Spigot Server. I also tried not using Magic values and instead having just the Planks, which didn't work either. 2017-04-19_14.02.01.png
    I know that an easy solution to this would be to just make a PrepareItemCraftEvent listener and manually detect and override that. However, that's not a universal solution, as if I or someone else were to add a different recipe, the result wouldn't be the same. So, do I report this on the bug tracker? Am I doing something wrong? Has anyone else had this issue before? And do you have any ideas on how I could make a universal solution?
    Thanks in advance.
     
  2. How about completely removing the recipe for a wooden pickaxe? You can go through the recipe iterator and remove recipes resulting in a wooden pickaxe. Then add your own recipe.
     
    • Informative Informative x 2
  3. I had no idea that was possible! Thanks, I'll try it out and see if it works. :D
     
  4. IT WORKS! Thank you so much! This is perfect, I'm going to adjust the code so that it fits my API. THANK YOU! Final code:
    Code (Text):
            Iterator<Recipe> recipes = Bukkit.recipeIterator();
            while (recipes.hasNext()) {
                if (recipes.next().getResult().getType().equals(Material.WOOD_PICKAXE)) {
                    recipes.remove();
                }
            }

            ShapedRecipe recipe = new ShapedRecipe(new ItemStack(Material.TNT));

            recipe.shape("111", "020", "020");
            recipe.setIngredient('1', Material.WOOD, 1);
            recipe.setIngredient('2', Material.STICK);
         
            Bukkit.addRecipe(recipe);
     
    • Friendly Friendly x 1