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

Dying to arrow damage while holding a renamed item causes the "shot by" death message to show incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • 1.16.5, 1.17.1, 21w37a, 1.18.1, 1.19.3, 1.19.4, 1.20.1, 1.20.2, 23w41a, 23w43a, 1.20.3, 1.20.4 Release Candidate 1, 1.20.4
    • Community Consensus
    • Survival
    • Text

      If a player fires an arrow at themselves with a bow or crossbow in their mainhand and then immediately switches their mainhand slot to a renamed item before the fired arrow hits and kills them, an incorrect death message will be displayed. The death message will use the name of the renamed item, rather than remembering the name of the item that fired the arrow originally.

      Steps to Reproduce:

      • Give the player a renamed item:
         /give @p dirt{display:{Name:'{"text":"Renamed Dirt Block"}'}} 1 
      • While holding the renamed item, run the following command:
        (This effectively does the same thing as shooting yourself with an arrow, but is more convenient)
      •  /damage @p 20 minecraft:arrow by @p 

      Observed Behavior:
      The game will output the death message "[Player] was shot by  [Player] using [Renamed Dirt Block]"

      Expected Behavior:
      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;
               return !itemstack.isEmpty() && itemstack.hasCustomHoverName() ? Component.translatable(s + ".item", livingEntity.getDisplayName(), component, itemstack.getDisplayName()) : Component.translatable(s, livingEntity.getDisplayName(), component);
            }
         }
      

      decompiled code via MCP Reborn

        1. killed_by_gold.jpg
          26 kB
          user-83872
        2. MC-222677.png
          148 kB
          [Mod] Avoma

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

              Created:
              Updated:
              Resolved:
              CHK: