Avoid hurt animation for fully blocked shield hits
This commit is contained in:
@@ -106,7 +106,7 @@ impl Game<'_> {
|
|||||||
let hurt = &p.health.hurt;
|
let hurt = &p.health.hurt;
|
||||||
let state = BobState {
|
let state = BobState {
|
||||||
living: Some(HurtBob {
|
living: Some(HurtBob {
|
||||||
hurt_time: hurt.hurt_time as f32 - partial,
|
hurt_time: p.health.hurt_animation_time as f32 - partial,
|
||||||
hurt_duration: hurt.hurt_duration,
|
hurt_duration: hurt.hurt_duration,
|
||||||
hurt_dir: 0.0,
|
hurt_dir: 0.0,
|
||||||
death_time: self.death_time().map(|t| t as f32 + partial),
|
death_time: self.death_time().map(|t| t as f32 + partial),
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ impl Game<'_> {
|
|||||||
.map(|s| s.item.clone());
|
.map(|s| s.item.clone());
|
||||||
let off = self.offhand.as_ref().map(|s| s.item.clone());
|
let off = self.offhand.as_ref().map(|s| s.item.clone());
|
||||||
let riding = self.riding.is_some();
|
let riding = self.riding.is_some();
|
||||||
let hurt = p.health.hurt.hurt_time;
|
let hurt = p.health.hurt_animation_time;
|
||||||
let Some(m) = self.player_model.as_mut() else {
|
let Some(m) = self.player_model.as_mut() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -161,6 +161,8 @@ pub struct PlayerHealth {
|
|||||||
pub ids: PlayerFloatIds,
|
pub ids: PlayerFloatIds,
|
||||||
pub food: FoodData,
|
pub food: FoodData,
|
||||||
pub hurt: State,
|
pub hurt: State,
|
||||||
|
/// Client hurt animation; fully blocked hits only refresh the server's hurt state.
|
||||||
|
pub hurt_animation_time: i32,
|
||||||
pub dead: bool,
|
pub dead: bool,
|
||||||
pub sync_velocity: bool,
|
pub sync_velocity: bool,
|
||||||
pub game_time: i64,
|
pub game_time: i64,
|
||||||
@@ -210,6 +212,7 @@ impl PlayerHealth {
|
|||||||
last_source: None,
|
last_source: None,
|
||||||
last_stamp: 0,
|
last_stamp: 0,
|
||||||
},
|
},
|
||||||
|
hurt_animation_time: 0,
|
||||||
dead: false,
|
dead: false,
|
||||||
sync_velocity: false,
|
sync_velocity: false,
|
||||||
game_time: 0,
|
game_time: 0,
|
||||||
@@ -242,6 +245,9 @@ impl PlayerHealth {
|
|||||||
if self.hurt.hurt_time > 0 {
|
if self.hurt.hurt_time > 0 {
|
||||||
self.hurt.hurt_time -= 1;
|
self.hurt.hurt_time -= 1;
|
||||||
}
|
}
|
||||||
|
if self.hurt_animation_time > 0 {
|
||||||
|
self.hurt_animation_time -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl PlayerMotion {
|
impl PlayerMotion {
|
||||||
@@ -300,8 +306,11 @@ impl PlayerMotion {
|
|||||||
sound: environment.block_sound,
|
sound: environment.block_sound,
|
||||||
};
|
};
|
||||||
if environment.totem_fired {
|
if environment.totem_fired {
|
||||||
self.health.totem_used = true;
|
h.totem_used = true;
|
||||||
self.health.totem_ready = false;
|
h.totem_ready = false;
|
||||||
|
}
|
||||||
|
if outcome.hurt {
|
||||||
|
h.hurt_animation_time = h.hurt.hurt_time;
|
||||||
}
|
}
|
||||||
Ok(outcome)
|
Ok(outcome)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ impl PlayerMotion {
|
|||||||
data: &mut h.data,
|
data: &mut h.data,
|
||||||
ids: h.ids,
|
ids: h.ids,
|
||||||
hurt: &mut h.hurt,
|
hurt: &mut h.hurt,
|
||||||
|
hurt_animation_time: &mut h.hurt_animation_time,
|
||||||
dead: &mut h.dead,
|
dead: &mut h.dead,
|
||||||
sync_velocity: &mut h.sync_velocity,
|
sync_velocity: &mut h.sync_velocity,
|
||||||
game_time: h.game_time,
|
game_time: h.game_time,
|
||||||
@@ -70,6 +71,7 @@ struct TickWorld<'a> {
|
|||||||
data: &'a mut SyncedFloats,
|
data: &'a mut SyncedFloats,
|
||||||
ids: PlayerFloatIds,
|
ids: PlayerFloatIds,
|
||||||
hurt: &'a mut State,
|
hurt: &'a mut State,
|
||||||
|
hurt_animation_time: &'a mut i32,
|
||||||
dead: &'a mut bool,
|
dead: &'a mut bool,
|
||||||
sync_velocity: &'a mut bool,
|
sync_velocity: &'a mut bool,
|
||||||
game_time: i64,
|
game_time: i64,
|
||||||
@@ -142,8 +144,11 @@ impl FoodWorld for TickWorld<'_> {
|
|||||||
totem: false,
|
totem: false,
|
||||||
totem_fired: false,
|
totem_fired: false,
|
||||||
};
|
};
|
||||||
ServerPlayerCombat::new(self.attributes, self.data, food, self.ids, &mut environment)?
|
if ServerPlayerCombat::new(self.attributes, self.data, food, self.ids, &mut environment)?
|
||||||
.hurt(self.hurt, amount)?;
|
.hurt(self.hurt, amount)?
|
||||||
|
{
|
||||||
|
*self.hurt_animation_time = self.hurt.hurt_time;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2166,8 +2166,13 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn player_fire_damage_queues_hurt_sound_only_for_fresh_hits() {
|
fn player_fire_damage_queues_hurt_sound_only_for_fresh_hits() {
|
||||||
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3");
|
let root = std::env::var_os("HORIZON_TEST_RESOURCES")
|
||||||
|
.map(std::path::PathBuf::from)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3")
|
||||||
|
});
|
||||||
if !root.join("movement-properties.nbt").exists() {
|
if !root.join("movement-properties.nbt").exists() {
|
||||||
|
eprintln!("skipped damage regression: prepared resources unavailable");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let assets = Assets::load(&root).unwrap();
|
let assets = Assets::load(&root).unwrap();
|
||||||
@@ -2195,6 +2200,8 @@ mod tests {
|
|||||||
.count(),
|
.count(),
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
assert_eq!(player.health.hurt_animation_time, 10);
|
||||||
|
player.health.advance_clock();
|
||||||
player.events.clear();
|
player.events.clear();
|
||||||
assert!(
|
assert!(
|
||||||
!player
|
!player
|
||||||
@@ -2207,9 +2214,14 @@ mod tests {
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|e| matches!(e, MotionEvent::HurtSound(_)))
|
.any(|e| matches!(e, MotionEvent::HurtSound(_)))
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
player.health.hurt_animation_time, 9,
|
||||||
|
"cooldown hit must not restart animation"
|
||||||
|
);
|
||||||
for _ in 0..20 {
|
for _ in 0..20 {
|
||||||
player.health.advance_clock();
|
player.health.advance_clock();
|
||||||
}
|
}
|
||||||
|
assert_eq!(player.health.hurt_animation_time, 0);
|
||||||
player.invulnerable = true;
|
player.invulnerable = true;
|
||||||
player.events.clear();
|
player.events.clear();
|
||||||
assert!(
|
assert!(
|
||||||
@@ -2271,16 +2283,62 @@ mod tests {
|
|||||||
Default::default(),
|
Default::default(),
|
||||||
source,
|
source,
|
||||||
4.0,
|
4.0,
|
||||||
Some(shield),
|
Some(shield.clone()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!outcome.hurt && outcome.sound && outcome.blocked == 4.0);
|
assert!(!outcome.hurt && outcome.sound && outcome.blocked == 4.0);
|
||||||
|
assert_eq!(
|
||||||
|
player.health.hurt.hurt_time, 10,
|
||||||
|
"preserve server damage bookkeeping"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
player.health.hurt_animation_time, 0,
|
||||||
|
"a fully blocked arrow must not animate hurt"
|
||||||
|
);
|
||||||
assert!(
|
assert!(
|
||||||
!player
|
!player
|
||||||
.events
|
.events
|
||||||
.iter()
|
.iter()
|
||||||
.any(|e| matches!(e, MotionEvent::HurtSound(_)))
|
.any(|e| matches!(e, MotionEvent::HurtSound(_)))
|
||||||
);
|
);
|
||||||
|
// An unblocked hit after the shield block must still animate normally.
|
||||||
|
for _ in 0..20 {
|
||||||
|
player.health.advance_clock();
|
||||||
|
}
|
||||||
|
assert!(
|
||||||
|
player
|
||||||
|
.hurt(&resources.health, Default::default(), source, 4.0)
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
assert_eq!(player.health.hurt_animation_time, 10);
|
||||||
|
player.health.advance_clock();
|
||||||
|
assert!(
|
||||||
|
!player
|
||||||
|
.hurt_blocking(
|
||||||
|
&resources.health,
|
||||||
|
Default::default(),
|
||||||
|
source,
|
||||||
|
4.0,
|
||||||
|
Some(shield)
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.hurt
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
player.health.hurt_animation_time, 9,
|
||||||
|
"blocking must not erase or restart an existing animation"
|
||||||
|
);
|
||||||
|
let mut starving = PlayerMotion::new(&resources, Vec3::ZERO).unwrap();
|
||||||
|
starving.health.food.food = 0;
|
||||||
|
starving.health.food.timer = 79;
|
||||||
|
starving
|
||||||
|
.food_tick(&resources.health, Default::default())
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(starving.health.health(), 19.0);
|
||||||
|
assert_eq!(
|
||||||
|
starving.health.hurt_animation_time, 10,
|
||||||
|
"starvation must still animate hurt"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Footsteps on the prepared vanilla resources, when they are present:
|
/// Footsteps on the prepared vanilla resources, when they are present:
|
||||||
|
|||||||
Reference in New Issue
Block a user