Getting registered recipes

Discussion in 'Plugin Development' started by DutchJellyV2, Dec 13, 2018.

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

    DutchJellyV2

    I need help!

    There's a method to get all recipes from the server. These recipes are stored in a Recipe object. Unfortunately that recipe object only allows you to see the result of the recipe, while I would like to see the actual content of the recipe. I tried decompiling the Recipe class, but only got to see an interface class which doesn't help me at all.

    Maybe I can cast the returned recipe object from the iterator to some object that does contain methods to view the needed materials to craft the result. Does someone know what object that would be or another way to view recipe content?

    I'd greatly appreciate anyone helping me to find an answer to this.
     
  2. Offline

    torpkev

    Sorry if I'm off track on this.. but wouldn't you do something like:

    Code:
           
     ItemStack istack = new ItemStack(Material.ACACIA_BOAT, 1); 
            List<Recipe> lr = Bukkit.getRecipesFor(istack);
            if (lr != null)
            {
                for (Recipe r : lr)
                {
                    if (r instanceof ShapedRecipe)
                    {
                        ShapedRecipe sr = (ShapedRecipe) r;
                        // do whatever with sr.getIngredientMap()
                    }
                }
            }
    When i ran that and output the sr.getIngredientMap() I got:

    {a=ItemStack{ACACIA_PLANKS x 1}, b=null, c=ItemStack{ACACIA_PLANKS x 1}, d=ItemStack{ACACIA_PLANKS x 1}, e=ItemStack{ACACIA_PLANKS x 1}, f=ItemStack{ACACIA_PLANKS x 1}}

    but that was dumping it to a string - you should be able to interact with it easily enough though
     
  3. Offline

    DutchJellyV2

    Oh awesome! I didn't think the Recipe class extended ShapedRecipe. Perhaps I'm misunderstanding when you can cast an object to another object.

    Could you explain why you can use Recipe instanceof ShapedRecipe? I'm really confused by it.
     
  4. Offline

    torpkev

    ShapedRecipe implements Recipe, so knowing we have the recipe, checked to see if it was that with the instanceof and went from there.

    I also read up a bit here:

    https://jd.bukkit.org/org/bukkit/inventory/Recipe.html
    https://jd.bukkit.org/org/bukkit/inventory/ShapedRecipe.html
     
Thread Status:
Not open for further replies.

Share This Page