From 65d5a35cd22aa723695b0885a5ecd7d5e3a4b710 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 21:40:57 +0200 Subject: [PATCH] Server: a dead guest is sent its health of 0, as ServerPlayer.doTick does The hub held SetHealth back once a guest died, so the guest's health stayed at its last positive value under the death screen. ServerPlayer sends it every tick it changes, dead or not, and only when the health or the food level changes or the saturation reaches or leaves zero: the hub sent it on every change of saturation too. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/guest.rs | 3 ++- crates/horizon-client/src/lan/hub.rs | 18 ++++++++---------- tools/lan_e2e.py | 5 ++++- 3 files changed, 14 insertions(+), 12 deletions(-) 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):