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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-17 21:40:57 +02:00
parent d223b383ee
commit 65d5a35cd2
3 changed files with 14 additions and 12 deletions
+2 -1
View File
@@ -137,7 +137,8 @@ pub struct Guest {
/// What the client believes the inventory menu holds (for change detection).
pub menu_sent: Vec<Option<ItemStack>>,
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]>,
+8 -10
View File
@@ -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);
}
+4 -1
View File
@@ -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):