diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index ea12c2edb..780be4a33 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -137,7 +137,8 @@ pub struct Guest { /// What the client believes the inventory menu holds (for change detection). pub menu_sent: Vec>, pub menu_state: i32, - pub sent_health: Option<(f32, i32, f32)>, + /// `lastSentHealth`, `lastSentFood` and `lastFoodSaturationZero`. + pub sent_health: Option<(f32, i32, bool)>, pub sent_xp: Option<(f32, i32, i32)>, /// Where the player last died (Player.lastDeathLocation), sent with the respawn. pub last_death: Option<[i32; 3]>, diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index b18187835..845f094eb 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -1585,17 +1585,15 @@ impl Hub { self.flush_advancements(i, true); } } - let health = { - let g = &self.guests[i]; - (g.health, g.food, g.saturation) - }; - // A dead player's health isn't sent (the death screen shows from the combat kill). - if self.guests[i].sent_health != Some(health) && !self.guests[i].dead { - let g = &mut self.guests[i]; + // Sent when the health or the food level changes, or the saturation + // reaches or leaves zero; a dead player's health of 0 too. + let g = &mut self.guests[i]; + let health = (g.health, g.food, g.saturation == 0.0); + if g.sent_health != Some(health) { g.send(&C::SetHealth(play::SetHealth { - health: health.0, - food: health.1, - saturation: health.2, + health: g.health, + food: g.food, + saturation: g.saturation, })); g.sent_health = Some(health); } diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index b1e7ec098..790778968 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -454,6 +454,9 @@ def check_hazards(host, guest, out): # A fresh life: full health, so no regeneration eats food while the guest runs. guest('command', command='kill @s') guest.wait(20) + # ServerPlayer.doTick sends the dead player's health of 0 too. + died = {'screen': guest('state').get('screen'), 'health': remote(guest)['health']} + assert died == {'screen': 'dead', 'health': 0.0}, f'the guest was killed: {died}' guest.raw('respawn') guest.wait(40) # Sprint-jumping down a stone lane: ServerPlayer.jumpFromGround and checkMovementStatistics. @@ -506,7 +509,7 @@ def check_hazards(host, guest, out): assert spent > 1.0, f'no hunger from moving: {hunger} ({spent:.2f} spent)' for name, (before, after) in hurt.items(): assert after < before, f'{name} never hurt the guest: health {before} -> {after} (all: {hurt})' - return {'hunger': hunger, **hurt} + return {'died': died, 'hunger': hunger, **hurt} def check_pvp(host, guest, out):