Merge pull request #2128 from kacpherek/fix/remote-hurt-tilt

🤖 Agent: Merged by hand by Ludovic's AI agent (orchestrator) after the contribution gate. rdbtCVS's change request is addressed at this head; a re-review was asked, with no new objection since. Proven in wave 5's union run (cg21 union 65b0cb252 (main c1ebf5d1b + 72 kacpherek PRs) playhorizon 94/95, use_item_on fixed (#2126 523280e78).
This commit is contained in:
Ludovic Marie
2026-10-27 12:16:24 +01:00
committed by GitHub
6 changed files with 47 additions and 2 deletions
@@ -1820,6 +1820,10 @@ impl Game<'_> {
let (xd, zd) = from.map_or((0.0, 0.0), |from| {
(from[0] - player.position.x, from[2] - player.position.z)
});
// dealDefaultKnockback's `indicateDamage`, unless blocked.
if o.blocked <= 0.0 {
player.health.indicate_damage(xd, zd, player.yaw);
}
self.knock_back_player(f64::from(0.4_f32), xd, zd);
if let Some(p) = self.player.as_mut()
&& let Some(r) = p.hurt_log.last_mut()
@@ -307,6 +307,12 @@ impl Game<'_> {
)
{
outcome = o;
// dealDefaultKnockback's `indicateDamage` points at the blast
// (the source position), not the no-direction fallback.
if o.knockback && o.blocked <= 0.0 {
p.health
.indicate_damage(center[0] - feet[0], center[2] - feet[2], p.yaw);
}
}
if !spectator && !(creative && flying) {
p.velocity = Vec3::new(
+1 -1
View File
@@ -114,7 +114,7 @@ impl Game<'_> {
living: Some(HurtBob {
hurt_time: p.health.hurt_animation_time as f32 - partial,
hurt_duration: hurt.hurt_duration,
hurt_dir: 0.0,
hurt_dir: p.health.hurt_dir,
death_time: self.death_time().map(|t| t as f32 + partial),
}),
player: Some((
@@ -684,6 +684,13 @@ impl Game<'_> {
g.sprinting = false;
}
m.sprinting = false;
// ServerPlayer.indicateDamage: the hit's direction to the player.
if let Some(yaw) = m.health.indicated_dir.take() {
g.send(&C::HurtAnimation(play::HurtAnimation {
id: g.entity_id,
yaw,
}));
}
let teleported = std::mem::take(&mut m.teleported);
let moved: f64 = (0..3).map(|k| (at[k] - g.position[k]).powi(2)).sum();
g.motion = Some(Box::new(m));
+2 -1
View File
@@ -2200,8 +2200,9 @@ impl Game<'_> {
}
C::HurtAnimation(p) => {
if self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) {
// Player.animateHurt: the tilt turns around the yaw.
if let Some(pl) = self.player.as_mut() {
pl.health.animate_hurt();
pl.health.animate_hurt_dir(p.yaw);
}
} else if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
m.hurt_time = 10;
+27
View File
@@ -180,6 +180,12 @@ pub struct PlayerHealth {
pub hurt: State,
/// Client hurt animation; fully blocked hits only refresh the server's hurt state.
pub hurt_animation_time: i32,
/// `Player.hurtDir` on a client: the yaw `ClientboundHurtAnimationPacket`
/// gave, which `GameRenderer.bobHurt` tilts the camera around.
pub hurt_dir: f32,
/// `ServerPlayer.hurtDir` of a hit the player's client hasn't been told
/// of yet (`indicateDamage`).
pub indicated_dir: Option<f32>,
pub dead: bool,
pub sync_velocity: bool,
pub game_time: i64,
@@ -230,6 +236,8 @@ impl PlayerHealth {
last_stamp: 0,
},
hurt_animation_time: 0,
hurt_dir: 0.0,
indicated_dir: None,
dead: false,
sync_velocity: false,
game_time: 0,
@@ -277,6 +285,18 @@ impl PlayerHealth {
self.hurt.hurt_time = 10;
self.hurt_animation_time = 10;
}
/// `LivingEntity.animateHurt(yaw)` on a player: the tilt restarts around
/// `yaw` (`Player.animateHurt` keeps it as `hurtDir`).
pub fn animate_hurt_dir(&mut self, yaw: f32) {
self.animate_hurt();
self.hurt_dir = yaw;
}
/// `ServerPlayer.indicateDamage`: the hit's direction relative to where
/// the player looks, kept for the packet to its client.
pub fn indicate_damage(&mut self, xd: f64, zd: f64, yaw: f32) {
use horizon_core::geometry::trig::{RAD_TO_DEG, atan2};
self.indicated_dir = Some((atan2(zd, xd) * f64::from(RAD_TO_DEG) - f64::from(yaw)) as f32);
}
/// `LocalPlayer.hurtTo` with `flashOnSetHealth`: a drop below the current
/// health starts the hurt animation; `damageCooldownTime` (20 on a drop,
/// 10 on a gain) is what lets `Hud.extractPlayerHealth` blink the hearts.
@@ -380,6 +400,13 @@ impl PlayerMotion {
if outcome.hurt {
h.hurt_animation_time = h.hurt.hurt_time;
}
// `dealDefaultKnockback` ends in `indicateDamage` unless blocked: a
// hit with no direction of its own (`xd` and `zd` zero) is sent as
// the opposite of the player's yaw. A hit that has a direction
// replaces this (`mob_hits_player`).
if outcome.knockback && outcome.blocked <= 0.0 {
h.indicate_damage(0.0, 0.0, self.yaw);
}
let after = h.health() + h.absorption();
if self.hurt_log.len() >= HURT_LOG {
self.hurt_log.remove(0);