diff --git a/crates/horizon-client/src/game/combat.rs b/crates/horizon-client/src/game/combat.rs index f125899f3..9216351dc 100644 --- a/crates/horizon-client/src/game/combat.rs +++ b/crates/horizon-client/src/game/combat.rs @@ -39,6 +39,11 @@ pub(super) struct CombatTracker { pub(super) last_hurt_mob: Option<(u32, i64)>, /// The mob whose projectile is hitting the player now. pub(super) projectile_owner: Option, + /// The display name of the projectile hitting the player now: the + /// `DamageSource.directEntity` the death message names when no owner is + /// known (`AbstractArrow.onHitEntity` makes an ownerless arrow its own + /// cause). + pub(super) projectile_direct: Option, /// The projectile hitting the player now is another player's that /// `ServerPlayer.canHarmPlayer` refuses (the `pvp` rule, an ally). pub(super) refuse_player_hit: bool, @@ -204,6 +209,7 @@ impl Game<'_> { } self.combat.pending.clear(); self.combat.pending_direct.clear(); + self.combat.projectile_direct = None; self.combat.fall_before = self.player.as_ref().map_or(0.0, |p| p.fall_distance); } /// `FallLocation.getCurrentFallLocation` and the fall distance so far. diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 225948e31..34b7ed206 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -1876,6 +1876,10 @@ impl Game<'_> { if let Some(a) = attacker.or(owner) { self.note_attacker(damage_type, a); } + // The projectile is the direct entity: named when it has no owner. + if let Some(name) = self.combat.projectile_direct.take() { + self.note_direct_entity(damage_type, name); + } // DamageSource.scalesWithDifficulty: a mob (or its projectile's // owner) caused the hit, not a player. let living_cause = attacker.or(owner).is_some(); @@ -2455,6 +2459,26 @@ impl Game<'_> { Some(Who::Mob(id)) => Some(id), _ => None, }; + self.combat.projectile_direct = match hit { + Hit::Entity { + who: Who::Player, .. + } => { + let spectral = p + .arrow + .as_ref() + .is_some_and(|a| &*a.pickup_item.item == "minecraft:spectral_arrow"); + let id = if spectral { + "minecraft:spectral_arrow" + } else { + p.kind.id() + }; + Some(Text::translate( + &format!("entity.{}", id.replace(':', ".")), + &[], + )) + } + _ => None, + }; let at = match hit { Hit::Entity { at, .. } | Hit::Block { at, .. } => at, Hit::None => return Ok(()),