Enter the following command to give yourself an item with a custom minecraft:item_name
component:
/give @s minecraft:diamond[minecraft:item_name='"item name"']
Then drop the item and enter:
/say @e[type=minecraft:item,limit=1,sort=nearest]
It prints "Diamond" to the chat instead of "item name".
(The same applies to the minecraft:custom_name
component, but I suspect that's not a bug since that's never worked before.)
Attachments
Comments 4
@unknown I don't think this has any relation to MC-209. This isn't related to blocks persisting item data.
I can confirm this issue in Minecraft snapshot 24w21b.
Code analysis (Yarn mappings)
The name for the item entity is determined using the following code:
@Override
public Text getName() {
Text customName = this.getCustomName();
return customName != null ? customName : Text.translatable(this.getStack().getTranslationKey()));
}
In other words, the item entity prioritizes the custom name (specified using CustomName
NBT) and falls back to stack-aware default name of the item. To support the custom name and item name components, the ItemStack#getName
method could be used:
@Override
public Text getName() {
Text customName = this.getCustomName();
return customName != null ? customName : this.getStack().getName();
}
Relates to MC-209