Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-89347

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 15w39b, Minecraft 15w43c, Minecraft 15w44a, Minecraft 15w46a, Minecraft 16w02a, Minecraft 1.9.1 Pre-Release 3, Minecraft 1.10.2, Minecraft 16w35a, Minecraft 16w41a, Minecraft 1.11.2, Minecraft 17w17a, Minecraft 17w17b, Minecraft 17w18a, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 18w48a, Minecraft 18w48b, Minecraft 18w49a, Minecraft 18w50a, 1.14.4, 1.15.1, 1.16 Pre-release 5, 1.16.1, 20w28a, 20w29a, 20w30a, 1.16.2 Pre-release 1, 1.16.2 Pre-release 2, 1.16.2 Pre-release 3, 1.16.2 Release Candidate 1, 1.16.2 Release Candidate 2, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 1, 1.16.4 Pre-release 2, 1.16.4 Release Candidate 1, 1.16.4, 20w45a, 20w46a, 20w48a, 20w49a, 20w51a, 21w03a, 1.16.5, 21w05b, 21w06a, 21w07a, 21w08b, 21w10a, 21w11a, 21w13a, 21w14a, 1.17, 1.17.1, 21w37a, 21w39a, 1.18.1, 22w06a, 1.18.2, 22w14a, 1.19 Release Candidate 2, 1.19, 1.19.2, 1.19.3, 1.19.4, 1.20.1, 1.20.2 Pre-release 2, 1.20.2, 23w41a, 23w43a, 1.20.3, 1.20.4 Release Candidate 1, 1.20.4, 23w51b, 24w07a, 24w13a, 1.20.5
    • Confirmed
    • Text
    • Low
    • Platform

      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")

            Unassigned Unassigned
            Jingy [Helper] Jiingy
            Votes:
            29 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              CHK: