Create Items with custom names and lore

Discussion in 'Plugin Development' started by Glass_Eater84, Jun 20, 2014.

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

    Glass_Eater84

    Hello,
    I was wondering how I can create a custom item say I wanted to craft a wolf egg I would do

    Code:java
    1. ShapedRecipe wolfegg = new ShapedRecipe(new ItemStack(Material.MONSTER_EGG, 1, (short) 95));
    2. wolfegg.shape("@@@","@!@","@@@").setIngredient('@', Material.GOLD_NUGGET).setIngredient('!', Material.BONE);
    3. Bukkit.getServer().addRecipe(wolfegg);


    How can I make it so it has a custom name?

    Glass
     
  2. Code:
    ItemStack itemStack = new ItemStack(Material.MONSTER_EGG, 1, (short) 95); // Or whatever
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta != null) {
        itemMeta.setDisplayName("Display name");
        itemMeta.setLore(new ArrayList<String>()); // May be setLores, not sure.
        itemStack.setItemMeta(itemMeta);
    }
     
  3. Offline

    AoH_Ruthless

    Glass_Eater84
    The ingredients can't be checked for a custom name. However, you can give the final product a custom name.

    ItemStack is = new ItemStack(Material.MONSTER_EGG, 1, (short) 95);
    ItemMeta im = is.getItemMeta(); // get Item Meta then set display name
    im.setDisplayName("name");
    is.setItemMeta(im); // refresh the itemmeta
    ShapedRecipe r = new ShapedRecipe(is);


    Edit: God damn it KingFaris11 :(
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page