Util Translated item names with Fanciful

Discussion in 'Resources' started by bobacadodl, Jan 31, 2015.

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


    If you've ever wanted to output the name of an item in a plugin, you probably know that there is not really any good way to do this. I found a pretty decent method to do this using some NMS code and JSON messages!

    This method will return the item code of an item. For example, stone will return tile.stone.stone, and a block of gold will return tile.blockGold
    public String getItemCode(ItemStack item) throws InvocationTargetException, IllegalAccessException {
            Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, item);
            return (String) Reflection.getMethod(nmsItem.getClass(), "a").invoke(nmsItem);
    This allows you to put this item code into a FancyMessage using the translate feature to show the name of the item in the chat! Here is an example
    new FancyMessage("Item Name: ").then(TextualComponent.localizedText(getItemCode(item) + ".name")).itemTooltip(item);
  2. Offline


  3. Offline


    I just today had a similar problem: I am trying to append some text to an item's current name (via displayname of the item). However, if the item has no custom display name yet, minecraft shows the localized item name. So the task now would be to get the localized item name and append the custom text and use that as displayname.

    Do you know if item displaynames support localized text components / json formatted text?
  4. Offline


    Where can I see the class code "Reflection"?
Thread Status:
Not open for further replies.

Share This Page