steel_core/player/
health_sync.rs1use crate::player::Player;
7
8pub struct HealthSyncState {
10 pub last_health: f32,
12 pub last_food: i32,
14 pub saturation_zero: bool,
16}
17
18impl HealthSyncState {
19 #[must_use]
21 pub const fn new() -> Self {
22 Self {
23 last_health: -1.0,
24 last_food: -1,
25 saturation_zero: true,
26 }
27 }
28
29 #[expect(
31 clippy::float_cmp,
32 reason = "intentional exact comparison: we only want to send updates when the value changes from what we last sent"
33 )]
34 #[must_use]
35 pub fn needs_update(&self, health: f32, food: i32, saturation_zero: bool) -> bool {
36 self.last_health != health
37 || self.last_food != food
38 || self.saturation_zero != saturation_zero
39 }
40
41 pub const fn record_sent(&mut self, health: f32, food: i32, saturation_zero: bool) {
43 self.last_health = health;
44 self.last_food = food;
45 self.saturation_zero = saturation_zero;
46 }
47
48 pub const fn invalidate(&mut self) {
50 self.last_health = -1.0e8;
51 }
52}
53
54impl Player {
55 pub fn reset_sent_info(&self) {
58 self.health_sync.lock().invalidate();
59 }
60}