The death message of a dead player can show the name of an item which is unrelated to their death. For instance; this can occur when one player shoots another with a bow/crossbow, but then replaces the bow/crossbow in their main-hand with a different (renamed) item before the second player dies. The same can also be observed when the player has a bow in their off-hand, but a renamed item in their main hand. The general issue here being that the game does not properly detect the source of a death when choosing what item name to display, but instead uses the name of the item in the main hand (of the 'killer' player) upon death.
Steps to Reproduce:
Get a renamed item:
/give @s dirt[minecraft:custom_name='{"text":"Custom Name","color":"red"}']
Kill the player:
(Must be holding the renamed item when you do)/damage @p 20 minecraft:arrow by @p
Observed & Expected Behavior:
❌ - The game will output the death message "[Player] was shot by [Player] using [Renamed Dirt Block]", despite dying to arrow damage.
✔ - The death message would properly display the name of the item used to shoot the player. If a name is not applicable, it would give a vague message such as "[Player] shot [Player]"
Code Analysis:
This issue stems specifically from the return value of the getLocalizedDeathMessage() method in the DamageSource class.
As stated in the post, the game checks the name of the item the player is currently holding rather than the item used.
public Component getLocalizedDeathMessage(LivingEntity livingEntity) {
String s = "death.attack." + this.type().msgId();
if (this.causingEntity == null && this.directEntity == null) {
LivingEntity livingentity1 = livingEntity.getKillCredit();
String s1 = s + ".player";
return livingentity1 != null ? Component.translatable(s1, livingEntity.getDisplayName(), livingentity1.getDisplayName()) : Component.translatable(s, livingEntity.getDisplayName());
} else {
Component component = this.causingEntity == null ? this.directEntity.getDisplayName() : this.causingEntity.getDisplayName();
Entity entity = this.causingEntity;
ItemStack itemstack1;
if (entity instanceof LivingEntity) {
LivingEntity livingentity = (LivingEntity)entity;
itemstack1 = livingentity.getMainHandItem();
} else {
itemstack1 = ItemStack.EMPTY;
}
ItemStack itemstack = itemstack1;
--- > ISSUE START
return !itemstack.isEmpty() && itemstack.hasCustomHoverName() ? Component.translatable(s + ".item", livingEntity.getDisplayName(), component, itemstack.getDisplayName()) : Component.translatable(s, livingEntity.getDisplayName(), component);
--- > ISSUE END
}
}
decompiled code via MCP Reborn
Old Description
This is the original description, when the issue was triaged:
When you kill another player with bow (In second hand) and you have a renamed item (A dirt block with name "Hello worrld" for example) the death message is:
player was shot by <Me> using [Item in main hand (EX: Hello World")
Linked issues
is duplicated by 17
Attachments
Comments 16
@unknown: Please only confirm issues if you confirmed them yourself (you probably took confirmation from MC-91406). There's no need to confirm parent tickets for version X if you just pointed out a duplicate of it which has version X in the list of affected versions, we usually copy over affected versions when resolving duplicates. Thanks.
The classes EntityDamageSource
and IndirectEntityDamageSource
override the method DamageSource#getLocalizedDeathMessage
and check for the currently held item in the main hand of the attacker. As explained in this comment, the ItemStack
responsible for the action should be stored in the projectile then passed to the DamageSource
and used in the death message instead.
This is intended. When someone dies and the entity who killed holds a renamed item it shows the item that it is holding in the death message. That way the item cannot be mentioned if you throw it into lava before the entity dies like it should.
Um, buddy, you need an actual Mojang source for WAIs, and the report got priority assigned by Mojang, meaning it is NOT intended.
Confirmed for 15w43c.