Solved Removing a vanilla recipe

Discussion in 'Plugin Development' started by JumpStartFactions, May 24, 2020.

  1. So i am currently coding a custom plugin called FactionsHopper which adds a whole new recipe to the game which is the normal hopper recipe but instead of iron_ingots around the chest it is Diamond_blocks. Everything works fine with the new recipe:

    Code:
        public ShapedRecipe getRecipe() {
           
            ItemStack item = new ItemStack(Material.HOPPER);
           
            NamespacedKey key = new NamespacedKey(this, "hopper");
           
            ShapedRecipe recipe = new ShapedRecipe(key, item);
           
            recipe.shape("D D", "DCD", " D ");
           
            recipe.setIngredient('D', Material.DIAMOND_BLOCK);
            recipe.setIngredient('C', Material.CHEST);
           
            return recipe;
        }
    But when I implement the code I found on removing the regular hopper recipe:

    Code:
        @Override
        public void onEnable() {
            Bukkit.addRecipe(getRecipe());
           
            Iterator<Recipe> it = getServer().recipeIterator();
            Recipe recipe;
            while(it.hasNext()) {
            recipe = it.next();
            if (recipe != null && recipe.getResult().getType() == Material.HOPPER) {
            it.remove();
            }
            }
        }
    It removes my previous custom recipe I just made for the hopper. I know this is because the code to remove the recipe is simply stating if the output is Material.Hopper then remove that recipe. Does anyone have any tips on how i can fix this to where you can't craft the regular hopper but you can make the custom one?
    EX. would adding a enchant or lore to the new hopper recipe fix this?
     
  2. Offline

    BrittleMind

    Not sure if you're trolling or not, so...
    Just add your custom recipe after removing the vanilla one
     
  3. I did.. that’s literally what the first code is, what I’m saying is when I remove the hopper recipe it removes my custom one too because the output of the vanilla recipe and the output of the custom one is a hopper

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2020
  4. Offline

    BrittleMind

    Code:
    @Override
    public void onEnable() {
        Iterator<Recipe> it = getServer().recipeIterator();
        Recipe recipe;
        while(it.hasNext()) {
            recipe = it.next();
            if (recipe != null && recipe.getResult().getType() == Material.HOPPER) {
                it.remove();
            }
        }
        Bukkit.addRecipe(getRecipe()); //Adding it here will mean it's not present in the 
    Iterator and won't be removed
    }
    
     
  5. OMG you, this helps a lot especially for future plugins. Worked perfectly
     

Share This Page