mojira.dev
MC-89347

The 'using []' part of a player's death message can show the wrong item

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:

  1. Get a renamed item:

    /give @s dirt[minecraft:custom_name='{"text":"Custom Name","color":"red"}']
  2. 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

MC-264835 Wrong item in death message Resolved MC-268032 Death messages from players killed by an area effect cloud created by another player do not display the correct information Resolved MC-91406 Incorrect death message with offhand bow and named item Resolved MC-95728 Death Message shows weapon of default hand but not actual death-causing weapon of offhand Resolved MC-98022 When killed with weapon in offhand, death message says you were killed by weapon in main hand Resolved

Attachments

Comments 16

Confirmed for 15w43c.

@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.

@unknown: I did actually confirm it myself. Alright, thanks for the info!

In that case, there was no need to - I was going to believe the other report either way 😃

Confirmed for 15w44a.

6 more comments

Confirmed in 1.16-pre5.

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.

lluiscab

[Mod] Jingy

(Unassigned)

Confirmed

Platform

Low

Text

off-hand

Minecraft 15w39b, Minecraft 15w43c, Minecraft 15w44a, Minecraft 15w46a, Minecraft 16w02a, ..., 23w51b, 24w07a, 24w13a, 1.20.5, 1.21.5

Retrieved