Tutorial How to make custom crafting recipes...

Discussion in 'Resources' started by JTGaming2012, Aug 9, 2014.

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


    Hello guys,
    Today I want to show you how to add some custom recipes in to your Minecraft server. Custom recipes add a lot of uniqueness to your server, especially RPGs and survivals! Also, this tutorial is aimed at the beginners who have just started to learn the basics of plugin development!

    What we are creating:

    Before we start, let's just get an idea of what our plugin is going to do... I want to add the ability to craft an item which can't currently be crafted in Vanilla Minecraft. How about an Exp Bottle? You can choose a different item like a cobweb or anything!

    So, we are going to simply add a crafting recipe for an Exp Bottle - here's how!


    This is what I currently have inside my new, empty project called ExpRecipe (see, it rhymes!), this is a class I called "Recipe". It is going to be our main class so it must contain our two, "onEnable" and "onDisable" methods.

    1. package me.jack.exprecipe;
    3. import org.bukkit.plugin.java.JavaPlugin;
    5. public class Recipe extends JavaPlugin {
    7. public void onEnable() {
    9. }
    11. public void onDisable() {
    13. }
    15. }

    If you don't know already, the onEnable method gets triggered when the server starts, so it can be used to load in data from a config file. The onDisable method is triggered when the server closes, so in here, we can save data and stuff!

    Because we want to add a recipe when the server starts, we are going to place the code we are about to write, in our "onEnable" method.

    The Exp Bottle:

    Now then, it is going to be useful to create a new ItemStack variable to store the item we want to be the outcome of the crafting recipe.

    We can do this like this:

    1. ItemStack bottle = new ItemStack(Material.EXP_BOTTLE);

    - So, here we are creating a variable which is an ItemStack. This is one of the most commonly used variables!

    - We are calling it "bottle". So when we want to change stuff about this ItemStack, we can refer to it by saying, "bottle".

    - And we are giving it a value of Material Exp Bottle.

    Creating the recipe:

    To create the actually recipe, we need to create a new variable, which is a ShapedRecipe type of variable.

    1. ShapedRecipe expBottle = new ShapedRecipe(bottle);

    - So, we are creating a variable which is a ShapedRecipe.

    - We are calling it "expBottle". So when we want to change things about the new recipe, we can refer to it by saying, "expBottle".

    - This new "expBottle" is going to have the value of a new ShapedRecipe with the outcome of the recipe being the "bottle". Remember, "bottle" is a ItemStack of ExpBottle. So when the player crafts our recipe, the outcome is the Exp Bottle.

    Setting the crafting recipe!

    So now we have a recipe, called, "expBottle". But we haven't told it what shape it is and what items there are!

    There is a very clever way of doing this, simple too!

    1. expBottle.shape("*%*","%B%","*%*");

    - So we are getting the "expBottle" and going to set its shape to those symbols. It looks confusing but is simple to understand! Each string represents a layer of the crafting table and each character represents a different item. We can later set each character to an item!

    Congratz! You just set the shape of your recipe to... Whatever you chose!
    However, now we need to tell the code what each symbol means!

    2. expBottle.setIngredient('*', Material.INK_SACK, 2);
    3. expBottle.setIngredient('%', Material.SUGAR);
    4. expBottle.setIngredient('B', Material.GLASS_BOTTLE);

    - Once again, we are referring to the, "expBottle" crafting recipe we made, and we are setting what each Item the symbol is.

    Let's have a closer look at one of these.

    2. expBottle.setIngredient('*', Material.INK_SACK, 2);

    - Ok, so we are getting the "expBottle" and setting the ingredient.

    - The, '*' is referring to that symbol that we set in the shape.

    - And the argument after it, "Material.INK_SACK" is setting that symbol to the material, "Ink Sack".

    - The final argument is the data value of the item. The Ink Sack with the data value of 2 is green dye. Only use this if you know what you're doing!

    Finishing off:

    To finish, we need to add the new crafting recipe to the server, otherwise, it won't work! Here's how!

    1. getServer().addRecipe(expBottle);

    - Simply just gets the server and adds the recipe, "expBottle".

    Final code:

    1. package me.jack.exprecipe;
    3. import org.bukkit.Material;
    4. import org.bukkit.inventory.ItemStack;
    5. import org.bukkit.inventory.ShapedRecipe;
    6. import org.bukkit.plugin.java.JavaPlugin;
    8. public class Recipe extends JavaPlugin {
    10. public void onEnable() {
    12. ItemStack bottle = new ItemStack(Material.EXP_BOTTLE, 1);
    14. ShapedRecipe expBottle = new ShapedRecipe(bottle);
    16. expBottle.shape("*%*","%B%","*%*");
    18. expBottle.setIngredient('*', Material.INK_SACK, 2);
    19. expBottle.setIngredient('%', Material.SUGAR);
    20. expBottle.setIngredient('B', Material.GLASS_BOTTLE);
    22. getServer().addRecipe(expBottle);
    24. }
    26. public void onDisable() {
    28. }
    30. }

    Plugin yml:

    name: ExpRecipe
    main: me.jack.exprecipe.Recipe
    version: 1.0
    description: >
                Crafting recipes!
  2. Offline


    you seem to be missing expBottle in your final code :p
  3. Offline


    lukasmcd14 Ah, thanks! Would never have noticed that. :)
    lukasmcd14 likes this.
  4. Offline


    How would you make it have a custom name?
  5. Offline


    gabe4356 I think you have to give the ItemStack bottle a custom name
  6. Offline


    codex01 Nevermind, I found out a way.
  7. Offline


    How about the crafting in player inventory?
  8. Offline


    Okay, so I followed this, but for an unknown reason it will not work. It does for other recipes on another plugin I tried...
    1. package com.mcpestuffs.dreamtime;
    4. import org.bukkit.Material;
    5. import org.bukkit.inventory.ItemStack;
    6. import org.bukkit.inventory.ShapedRecipe;
    7. import org.bukkit.plugin.java.JavaPlugin;
    9. public class Main extends JavaPlugin {
    11. public void onEnable(){
    12. ItemStack rum = new ItemStack(Material.MILK_BUCKET, 1);
    13. ShapedRecipe craftRum = new ShapedRecipe(rum);
    14. craftRum.shape("%*%","%$%","%$%");
    15. craftRum.setIngredient('%', Material.EMERALD);
    16. craftRum.setIngredient('$', Material.SUGAR_CANE);
    17. craftRum.setIngredient('*', Material.BUCKET);
    18. getServer().addRecipe(craftRum);
    19. }
    20. }
  9. Offline


    PocketMines Are you sure your plugin.yml is set up correctly? Can you post it here?
  10. Offline


    Ohhhh, thanks for bringing that up. I had a stray capital letter- whoops :D
  11. Offline


    I know this thread is a little bit old but I would like an answer to the following question.
    When you put in a custom recipe, how would I make it go to a new event for the item that will be crafted?
  12. Offline


    Could you elaborate on "go to a new event for the item that will be crafted"?
  13. Offline


    I guess maybe go to a new event like:
    public void craft() {
    Random random = new Random();
    int number = random.nextInt(5);

    ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);

    if (number == 1) {
    sword.addEnchantment(Enchantment.UNBREAKING, 3);

  14. Offline


  15. Offline


    How to create this recipe ?

    I try this code but not function :/
    ItemStack mazza = new ItemStack(Material.WOOD_SWORD, 1);
            ShapedRecipe ferrata = new ShapedRecipe(mazza);
            ferrata.shape(" * "," * ","%*%");
            ferrata.setIngredient('*', Material.STICK);
            ferrata.setIngredient('%', Material.IRON_INGOT);
  16. @PappaProntaTeam You don't need to add a amount of one in the ItemStack, it is already defaultly one.
  17. Offline


    In ferrata.Shape(), the first string is the TOP layer of the crafting table, the last string is the bottom one. You got the 2 mixed up!
  18. Offline


    Try this:
    ferrata.shape("%*%"," * "," * ");
  19. Offline


    how do you put permissions that player needs on this
  20. Offline


    Try the CraftItemEvent
  21. Offline


    I am making a 2x2 Crafting recipe. How do I make it so I can put it any 4 corners of the table?

    Also I found a bug in the code. I use a plugin called plugman that allows me to reload plugins individually making it easier to reload a plugin without reloading the whole server. I reloaded the plugin when I went to update a crafting recipe but it didn't change because it didn't remove the old recipe in the onDisable(). If I get it to clear recipes then no crafting recipe is craftable at all till I reload the entire server (because bukkit then reloads the recipes.). Is there a way to remove a specific crafting recipe?


    May someone assist me with this?

    {{Posts merged by Myrathi}}
    Last edited by a moderator: Jun 11, 2015
  22. Offline


    Reloading a plugin really isn't good practice, I know that plugman causes many errors with other plugins and I suggest that you restart the server instead of trying to reload a plugin like that.
    The answer to your question is to simply have the recipe set up like this:
    recipe.shape("xy", "xy");
  23. @BowWhalley
    Save your recipes somewhere random, and when your plugin disables, iterate over Bukkit.recipeIterator() and check if each recipe is one of your custom ones, if it is, remove it. (Iterator#remove())
  24. Offline


    I pretty much did exactly what he did but changed up the ingredients and it doesn't work for me.
    package me.redstery.recipe;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;
    public class main extends JavaPlugin {
    public void onEnable() {
    ItemStack bottle = new ItemStack(Material.EXP_BOTTLE, 1);
    ShapedRecipe expBottle = new ShapedRecipe(bottle);
    expBottle.shape("   ", " * ", "   ");
    expBottle.setIngredient('*', Material.DIAMOND);
    public void onDisable() {

    Can someone explain to me what is going wrong?
  25. Offline


    @RBHB16 Is your plugin loading?
  26. Offline


    Yes, I figured it out now.. But thanks for the help I appreciate it
  27. Offline


    I'm making a custom plugin that requires players to craft a spaceship the ItemStacks SmallShip.smallShip and LargeShip.largeShip are static variables of the desired result of the crafting.

    A picture of an attempt to craft SmallShip.smallShip is attached.

    I know the plugin is working because the commands are working.

    Here is my code. The addRecipes() method is called in onEnable(). Both methods are in the main class.
    public void addRecipes(){
            ShapedRecipe craftSmallShip = new ShapedRecipe(SmallShip.smallShip);
            craftSmallShip.setIngredient('I', Material.IRON_INGOT);
            craftSmallShip.setIngredient('G', Material.GLASS);
            craftSmallShip.setIngredient('R', Material.REDSTONE_BLOCK);
            craftSmallShip.setIngredient('C', Material.CHEST);
            ShapedRecipe craftLargeShip = new ShapedRecipe(LargeShip.largeShip);
            craftLargeShip.setIngredient('I', Material.IRON_BLOCK);
            craftLargeShip.setIngredient('S', Material.GLASS);
            craftLargeShip.setIngredient('D', Material.DIAMOND_BLOCK);
            craftLargeShip.setIngredient('C', Material.CHEST);
            craftLargeShip.setIngredient('G', Material.GOLD_BLOCK);
            craftLargeShip.setIngredient('R', Material.REDSTONE_BLOCK);
    Please help! The server I am coding this for needs this plugin to move forward.

    Thanks in advance.

    I think I may have found the issue. It is possible that an earlier method in onEnable() is throwing errors and the addRecipes() method isn't getting called. However, I'd still like some help if you can find any flaws in this my code.

    Attached Files:

    Last edited: Dec 30, 2015
  28. Offline


    How would you craft with items that have a custom name? Like:
    3 iron ingots renamed: "&bSteel Ingots", to craft a steel Pickaxe.
  29. Offline


    This is what you set the shaped recipe to craft. Itemstacks have ItemMeta where you can change the durability, lore or displaynames. Just set the bottles metadata to contain the new display name.
  30. Offline


    how do you this in a anvil? Thanks :F
Thread Status:
Not open for further replies.

Share This Page