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
Linked issues
Attachments
Comments 6
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
I'd actually like to request ownership of this issue to maintain it going forward seeing as the original poster is innactive, citing that in their name.
After discussion based on the code analysis provided, I will resolve this issue as a duplicate of MC-89347. Both issues appear to share the same cause.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki
Since this isn't considered the same as MC-89347, I can confirm that this is an issue. Also affects 21w37a. Just in case the provided information isn't clear, here are some extra details.
The Bug:
The player can die from being "shot by" any renamed item.
Steps to Reproduce:
Set the "naturalRegeneration" gamerule to false.
Set your health to a singular heart by running the following command three times.
Obtain a bow and some arrows.
Obtain any item of your choice and rename it in an anvil.
Switch into survival mode and shoot yourself using your bow and arrow but make sure that you hold the renamed item of your choice in your hand before you die.
→ ❌ Notice how the player can die from being "shot by" any renamed item.
Expected Behavior:
The expected behavior would be that the player cannot die from being "shot by" any renamed item. The death message should correctly state what weapon was used to kill the player.