Get readable item names

Is there a way, surely there must be, to get the readable name of an ItemStack?

The default name, not the display name.

Using getTranslation().get() works for most items, but not all. For example, heads still come out as item.skull.name
And all wool is just “Wool”. I was hoping to get the name that displays when you hold the item.

Also, the same for enchantments. How do I get “Silk Touch” instead of enchantment.untouching?

Are you displaying this to the player? If so you should use the translation itself, which will get translated when it’s received on the client.

I am. And the translation doesn’t work like I said. Heads are item.skull.name

This is how I do it in PlayerShopsRPG

public Text getItemName(ItemStack itemStack) {
    return itemStack.get(Keys.DISPLAY_NAME).orElse(Text.of(itemStack.getTranslation().get()));
}

Though I suppose it would still grab the current display name regardless of the default display name. Hmmm

1 Like

No I mean, you say use itemStack.getTranslation().get()

instead just use the itemstack directly, or the translation. itemstack.getTranslation()

calling .get() on the translation forces it to be translated using the server side default locale, which prevents translation on the client.

@ryantheleach Thanks, that did help.
It’s not exactly what I wanted but it’s good enough.

Although, is it possible to get exactly what is shown to the client when holding the item?
Example: “Spawn Creeper” shows in the game but the Translation is simply “Spawn”
And with heads, the Translation is “Head” but in the game it will show as “Psp’s Head” for my head.

And what about enchantments? Trying to get the Translation from an enchantment throws AbstractMethodError.