Solved Can't use ItemMeta.displayName(component) with TranslatableComponent

km7dev

New member
Jan 14, 2024
2
0
1
Edit: It was an incorrect import.

I tried running meta.displayName(new TranslatableComponent("item.minecraftplus.copper_sword")); but it gave me the error The method displayName(Component) in the type ItemMeta is not applicable for the arguments (TranslatableComponent), can anyone tell me how to make it work? The javadocs say under setLocalizedName to "Use displayName(Component) with a TranslatableComponent." and that caused the error.
Here's the surrounding code if needed:
copperSword = new ItemStack(Material.STONE_SWORD); ItemMeta meta = copperSword.getItemMeta(); meta.displayName(new TranslatableComponent("item.minecraftplus.copper_sword")); copperSword.setItemMeta(meta);
 

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
132
6
19
18
California
You are using the wrong TranslatableComponent, probably the deprecated one (which is a good clue it's not what you want). Use adventure's components via Component#translatable which returns and adventure TranslatableComponent.

Note that server-side translations will not work with ItemMeta (display name, lore, etc.). Those do not support the server-side translation system so any non-vanilla translation keys will have to be present on the client via a resource pack.
 

km7dev

New member
Jan 14, 2024
2
0
1
You are using the wrong TranslatableComponent, probably the deprecated one (which is a good clue it's not what you want). Use adventure's components via Component#translatable which returns and adventure TranslatableComponent.

Note that server-side translations will not work with ItemMeta (display name, lore, etc.). Those do not support the server-side translation system so any non-vanilla translation keys will have to be present on the client via a resource pack.
I'd already found my issue, but thanks for letting me know I need to use a resource pack, was about to look into how to use it too.