Tutorial Custom Crafting Recipes + Name and Lore

Discussion in 'Resources' started by JoelyBob, Apr 17, 2015.

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

    JoelyBob

    Hey Guys,

    This is my first tutorial, so if you have any tips on how to make it better, please say!!

    Today I will be showing you how to make custom crafting recipes which have a custom name and custom lore in a Bukkit Server. Just so you know, this isn't creating a custom item that will get implemented into the game, that is somewhat impossible.

    So, first of all let's start of with an item. I've decided to make a 'Feather of Ping' and what I want this to do is when you right-click the feather, it will send a "Pong!" message, to see if you're lagged out or not.

    Let's start with the item;

    Code:
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
        ItemStack pingfeather = new ItemStack(Material.FEATHER);
        ItemMeta im = ping.getItemMeta();
    ItemStack pingfeather = new ItemStack(Material.FEATHER); is defining the new ItemStack as pingfeather which is needed when you make the custom recipe in-game. There will be an error if this is not included because the recipe will not make the customized item. ItemMeta is aliased to im and the ping is the custom ItemMeta, so we will be using that through out the plugin instead of continually writing the line of code.

    Code:
        im.setDisplayName(ChatColor.GREEN + "Feather of Ping");
        ArrayList<String> lore = new ArrayList<String>();
       yourItemMeta.setLore(Arrays.asList(ChatColor.GOLD + "Right Click for a Ping Check", "Second Line"));
        im.setLore(lore);
        speed.setItemMeta(im);
    im.setDisplayName(ChatColor.GREEN + "Feather of Ping"); is setting the display name of the item we will be creating. I have added the color of light-green to the name for the look. As you can see, instead of writing out the line of code to do with the ItemMeta, we defined the new ItemMeta as im which means whenever we put im it'll know that that equals the custom ItemStack from the previous code. Keep in mind, this is all part of the same code!

    Now onto making the recipe;

    Code:
        pingfeather.setItemMeta(im);
        ShapedRecipe pingFeather = new ShapedRecipe(pingfeather);
    We once again defined the ItemMeta of the customized item as im and we moved onto the recipe. ShapedRecipe pingFeather = new ShapedRecipe(pingfeather); is creating a name of the item for the recipe. So where it says pingFeather would you obviously have your own, scaled down, item name.

    Now we will make the actual recipe.

    Code:
        pingFeather.shape("%*%");
        pingFeather.setIngredient('*', Material.EMERALD);
        pingFeather.setIngredient('%', Material.FEATHER);
        getServer().addRecipe(pingFeather);
    pingFeather.shape("%*%"); is the shape of the recipe. I suggest writing that in, but leaving it blank for now. Make a decision on what items you would like to make your item, in this case I have chosen an Emerald and a Feather. So now, for putting the recipe together, the little '*', is the ID of the item. You need to set the ID for each item before putting together the recipe. I use simple characters like the Asterix and the Percentage sign.

    Code:
    pingFeather.shape("%*%");
    Now this right here is placing the recipe together. As you can see we used the material IDs we set before, and that basically means that the recipe in-game will go anywhere on the crafting table, as long as it is horizontal and the materials will be; FEATHERxEMERALDxFEATHER.

    Adding multiple rows into the recipe is just as easy as setting one row.

    Code:
    ping.Feather.shape("%*%", "*%*", "***");
    
    // % = Feather, * = Emerald
    All we have to do is do add a comma and a space between each row, starting from TOP to BOTTOM.

    Make sure that getServer().addRecipe(pingFeather); is there, so the recipe will work on the server.

    Adding picture examples soon!

    I will update the tutorial soon. This is my first, and probably my crappest job at a tutorial. Any feedback is appreciated!

    Please Like and Follow me!
     
    Last edited: Apr 16, 2016
    bronzzze and ChipDev like this.
  2. Offline

    meguy26

    @JoelyBob
    Could you update the tutorial to include multi-row recipes.
     
    JoelyBob likes this.
  3. Offline

    JoelyBob

    Sure thing, I'll work on it now. For the time being:

    It is very simple. All we have to do is add more lines of the recipe into it, e.g)
    Code:
    pingFeather.shape("%*%", "*%*", "***");
    
    //That equals FEATHERxEMERALDxFEATHER EMERALDxFEATHERxEMERALD EMERALDxEMERALDxEMERALD
    
    If there are any problems, please tell me :)

    EDIT:

    ("%*%" ,= First Row || "*%*", = Second Row || "***"); = Third Row
     
    Last edited: May 29, 2015
  4. Offline

    Monollyth

    This is a nice tutorial, but a quick tip. Using an arraylist to store the item lore can cause duplicate glitches with the lore, if not cleared. You should use "yourItemMeta.setLore(Arrays.asList("line 1", "line 2"));".
     
  5. Offline

    JoelyBob

    Ahh, thanks!
     
  6. Offline

    pinkitty1

    So anyway to add potion effects to item stacks? This is what I have but it throws an error saying to cast it and when I do it doesn't work this also could add on to @JoelyBob 's tutorial if this code can be fixed
    Code:
    ItemStack helmet = new ItemStack(Material.CHAINMAIL_HELMET, 1);
            helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4);
            helmet.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 9999, 1));
     
  7. Offline

    NickDEV

  8. Offline

    JoelyBob

    That's becaus a potion effect cannot be added to an item. You'll have to create an ItemInteractEvent and give the player the potion effect when they have the item on/in hand.

    No problems I'll update it all very soon :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page