Enabling/Disabling Recipe

Discussion in 'Plugin Development' started by rubenio1, Jul 30, 2020.

Thread Status:
Not open for further replies.
  1. I want to be able to toggle a recipe via an ingame menu, Now everything is made and I use the following code for Enabling / making the crafting recipe:
    Code:
    ItemStack enchantedBook = new ItemStack(Material.ENCHANTED_BOOK);
    NamespacedKey enchantedBookKey = new NamespacedKey(this, "enchantedBookKey");
    ShapedRecipe enchantedBookRecipe = new ShapedRecipe(enchantedBookKey,enchantedBook);
    
    enchantedBookRecipe.shape("EEE","EBE","EEE"); // Enchanting Bottle = E | Book = B
    enchantedBookRecipe.setIngredient('E',Material.EXPERIENCE_BOTTLE);
    enchantedBookRecipe.setIngredient('B',Material.BOOK);
    
    Bukkit.addRecipe(enchantedBookRecipe);
    Disabling a recipe:
    Code:
    ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
    {
    Iterator<Recipe> it = Bukkit.getServer().recipeIterator();
    while (it.hasNext()) {
    ItemStack result = it.next().getResult();
    if (result.isSimilar(item)) {
    it.remove();
    }
    }
    }
    But if I enable the recipe, disable it again, and then later want to enable it again; It gives an error as the recipe is already loaded via Bukkit.addRecipe but disabled by recipeIterator. How can I fix this?
     
  2. Offline

    Chr0mosom3

    Instead of loading it again, enable it w/ recipie illiterator

    Sent from my motorola one vision using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page