Solved how to replace a craft ?

Discussion in 'Plugin Development' started by cdnyassuo34, Aug 31, 2019.

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

    cdnyassuo34

    Hi, I am creating a craft plugin and I am currently making the replacecrafts command but I don't know how to replace a craft. I tought about detecting the items in the crafting table but It's way too long and i don't even know how to do it but instead I tought about detecting if the item has a name but I don't know how to detect if the item has a name when the craft event detect an event. so I am asking here to know how to do it ^^
    thanks in advance for any answers that will be posted ^^
     
  2. So you want to change crafting recipes did I get this right? The best way to do this would be to create a new recipe which override the old ones (there are plenty tutorials). But that requires a restart of the server. Otherwise you'll have to work with the PrepareItemCraftEvent (but then you probably have to check every ingredient which isnt as bad as you might think)
     
  3. Offline

    cdnyassuo34

    So how i override a craft?
     
  4. I'm not 100% sure about this but I'd say you just have to register a new recipe with the same result. So if you want to change the recipe for a diamond block, just create a new one which has the diamond block as a result.

    EDIT: okay you also have to remove the old one, that means remove it from getServer()#receipeIterator()

    So basically, you dont override it, you delete it and create a new one. Sorry that wasnt explained right
     
  5. Offline

    cdnyassuo34

    Oh ok thanks ^^ i'll try

    how do I remove an old craft ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 1, 2019
  6. Offline

    SnowPingerr

    You should try with this:
    Code:
    Iterator<Recipe> recipes = getServer().recipeIterator();
    Recipe recipe;
    while(recipes.hasNext())
                        {
                            recipe = recipes.next();
                            if(recipe != null && recipe.getResult().getType() == Material.getMaterial(MATERIAL_TO_REMOVE))
                            {
                                recipes.remove();
                            }
                        }
    
    not sure it's the right one but it should work and remove a craft
     
  7. Offline

    cdnyassuo34

    It's weird ... I am still abled to do the craft even after removing it ...
    do I have to restart my server or something like that ?
     
  8. Yeah I mentioned that before, you have to restart the server and I'm pretty sure the best place to remove the recipes is in the onEnable

    It's the same with adding a new recipe you cant do it while the server is running
     
  9. Offline

    cdnyassuo34

    adding recipe is possible even without a reload ^^ but removing I don't know how to do it :/
    but it's weird ... even with this code I still can craft the craft I removed ...
     
  10. Then show us your code please
     
  11. Offline

    cdnyassuo34

    Iterator<Recipe> recipes = getServer().recipeIterator();
    Recipe recipe;
    while(recipes.hasNext())
    {
    recipe = recipes.next();
    if(recipe != null && recipe.getResult().getType() == Material.getMaterial(args[0))
    {
    recipes.remove();
    }
    }
     
    Last edited: Sep 2, 2019
  12. Works fine for me. I assume the missing ']' is not the problem but note that the String you pass has to be uppercase, so make sure to do args[0].toUpperCase()
     
  13. Offline

    cdnyassuo34

    oh ok thanks ^^ worked fine this time ^^
     
Thread Status:
Not open for further replies.

Share This Page