Solved Changing the name of an object created through a custom recipe.

Discussion in 'Plugin Development' started by Derthmonuter, Jun 6, 2013.

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


    Hello everyone,

    I have created a plugin which includes a custom recipe for creating a stick. However, when a stick is crafted in this way, I would like to change its name and add a little description tag beneath it (I think lore does this?).

    2. @EventHandler
    3. public void onCraft(PrepareItemCraftEvent event) {
    5. ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
    6. if (recipe.getResult().equals(woodLock.getResult())) {
    9. ItemStack result = woodLock.getResult();
    11. ItemMeta im = result.getItemMeta();
    12. ArrayList<String> lore = new ArrayList<>();
    13. lore.add("Description.");
    14. im.setDisplayName("Name.");
    15. im.setLore(lore);
    17. result.setItemMeta(im);
    18. }
    19. }

    The debug messages fire properly, no errors are reported, and the stick is crafted. But nothing else happens. It just remains a stick named stick, with no description beneath its name.

    Any idea what I'm doing wrong?

  2. Offline


    Since "result" is a local variable, try using event.getResult().setItemMeta(im).
  3. When you create the recipe, you can pass a named item stack instead of just a Material.STICK or new ItemStack(Material.STICK). Use the ItemMeta to do so. Got no more time for an example, need to go to work now ;)
    Derthmonuter likes this.
  4. Offline


    Why would this even possibly make a difference?

    I also don't see why this should make a difference, but I'll try it now.

    This worked. Thank you.

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

Share This Page