Custom recipes with custom item ?

Discussion in 'Plugin Development' started by BlaSfaiMe, Mar 18, 2020.

  1. Offline

    BlaSfaiMe

    Hi !
    Is it possible to create custom recipes with custom item (like an item with a specify custom name)
    If yes how, can i do that ?
    Thanks
     
  2. Offline

    Tango_

    First of all, what version are you using?
     
  3. Offline

    BlaSfaiMe

    I'm using the 1.13.2

    But I want a custom item as ingredient

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

    Tango_

    Code:
            //Custom ItemStack ingredient (can use meta)
            ItemStack ingredient = new ItemStack(Material.EGG);
    
            //Custom item which will be created
            ItemStack output = new ItemStack(Material.IRON_HELMET);
            ItemMeta outputMeta = output.getItemMeta();
           
            outputMeta.setDisplayName("Egg Helmet");
            output.setItemMeta(outputMeta);
    
            //Setting a new recipe for 'output' itemstack
            ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "any_key_here"), output);
           
            //Set the shape to an helmet crafting shape
            recipe.shape("***","*B*","BBB");
           
            //Set ingredients
            recipe.setIngredient('*', ingredient);
            recipe.setIngredient('B', Material.AIR);
            // Alternatively can leave 'AIR' as spaces in shape recipe
           
            getServer().addRecipe(recipe);
     
  5. Offline

    BlaSfaiMe

    But setIngredient() only takes a Material. Not an itemstack
     
    Last edited: Mar 18, 2020
  6. Offline

    travja

    I believe there is an event called PrepareItemCraftEvent or the like. You can use that to check the recipe and put your own item in the resultant item slot.
     
  7. Offline

    BlaSfaiMe

    @travja It's probably good, but we can't add a namespacedkey too...
    Maybe can I use a ShapedRecipe AND the event
     
    Last edited: Mar 18, 2020
  8. Offline

    travja

    That is exactly what you should do ;)
     
  9. Offline

    Tango_

    I tested it using Spigot 1.13.2 had no issues
     
  10. Offline

    BlaSfaiMe

    I know ! I need to create a basic recipe with basic material but I use PrepareCraftEvent to control if the element are these ! But thre is e.get(Crafting)Inventory() has a Matrix... How can I do ? (I don't know how to use matrix)
     
  11. Online

    timtower Moderator Moderator

    @BlaSfaiMe Have you tried printing the contents of it?
     
  12. Offline

    BlaSfaiMe

    Not yet , but going to
     

Share This Page