mojira.dev
MC-272409

Item entity's name ignores `item_name` component

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();
}

Confirmed also for 1.21

 

[media]

As can be seen the output from `/loot` is correct using the item_name.

the output from `/say` is incorrect.

 

Item: 

minecraft:diamond_pickaxe[minecraft:item_name='"Diamond Hammer"']

GrantGryczan

(Unassigned)

Community Consensus

Platform

Normal

Commands, Items

1.20.6, 24w21b, 1.21

24w36a

Retrieved