Solved Help! Recipe editing.

Discussion in 'Plugin Development' started by ryanhamshire, Sep 22, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    ryanhamshire

    I see several posts on this topic, but I don't see any answers to my specific issue. I want to increase the number of TNT produced by the existing TNT recipe. So during my plugin's load, I tried both of these, and neither worked. The TNT recipe still provides me only one TNT. Yes, I did remember to /reload.

    What's the proper way to change the result of a recipe?

    Code:
    Iterator<Recipe> recipeIterator = server.recipeIterator();
    while(recipeIterator.hasNext())
    {
        Recipe recipe = recipeIterator.next();
        if(recipe.getResult().getType() == Material.TNT)
        {
            ItemStack result = recipe.getResult();
            result.setAmount(result.getAmount() * 2);
        }
    }
    Code:
    List<Recipe> tntRecipes = server.getRecipesFor(new ItemStack(Material.TNT));
    for(int i = 0; i < tntRecipes.size(); i++)
    {
        Recipe recipe = tntRecipes.get(i);
        recipe.getResult().setAmount(recipe.getResult().getAmount() * 2);
    }
     
  2. Offline

    psychic94

    I recommend using RecipeManager for this. I don't know about this case, but removing recipes requires Spout.
     
  3. Offline

    ryanhamshire

    Correction, removing recipes does not require Spout. While iterating with the recipe iterator, one can call iterator.remove().

    Using RecipeManager doesn't help me. I'm looking for a way to code these changes into another plugin, not just make the changes on my server.

    Thanks anyway for responding, that's more than anyone else did! :)

    I resolved this, but it wasn't pretty. Basically I said "if recipe results in TNT, remove it", then "add my new shaped recipe which results in 3 TNT, and requires this shaped recipe (which in my case is the same recipe for the Vanilla TNT recipe)". The danger is that another plugin could add a TNT recipe as well, and my plugin would then remove it. Finding a very specific recipe, for example the Vanilla TNT recipe, is a very involved (lots of lines) business because it requires writing a lot of code to verify the EXACT shape, ingredients, and number of ingredients.
     
Thread Status:
Not open for further replies.

Share This Page