From 90a3fc82aa56d764e6a988e706c9cce1ff80571c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 27 Oct 2026 12:11:14 +0100 Subject: [PATCH] refactor: HealthRules lives in world.rs World holds the health rules but they were defined in health.rs, which made world depend on health, one of the edges that keep the client lib in a single cycle. The plain data type (and its Default) moves to world.rs and health re-exports it. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/health.rs | 24 +---------------------- crates/horizon-client/src/world.rs | 30 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/crates/horizon-client/src/health.rs b/crates/horizon-client/src/health.rs index 31e4e8104..2cee71a31 100644 --- a/crates/horizon-client/src/health.rs +++ b/crates/horizon-client/src/health.rs @@ -25,29 +25,7 @@ use std::{fs, io, path::Path}; pub(crate) type Attributes = LiveAttributes i32>>; pub(crate) type State = HurtState; -#[derive(Clone, Copy, Debug)] -pub struct HealthRules { - pub difficulty: Difficulty, - pub natural_regeneration: bool, - /// The `drowning_damage`, `fall_damage`, `fire_damage` and - /// `freeze_damage` rules `Player.isInvulnerableTo` reads. - pub drowning_damage: bool, - pub fall_damage: bool, - pub fire_damage: bool, - pub freeze_damage: bool, -} -impl Default for HealthRules { - fn default() -> Self { - Self { - difficulty: Difficulty::Normal, - natural_regeneration: true, - drowning_damage: true, - fall_damage: true, - fire_damage: true, - freeze_damage: true, - } - } -} +pub use crate::world::HealthRules; pub struct HealthResources { pub damage: Catalog, pub ids: PlayerFloatIds, diff --git a/crates/horizon-client/src/world.rs b/crates/horizon-client/src/world.rs index 00ff04ac5..9fe83bba2 100644 --- a/crates/horizon-client/src/world.rs +++ b/crates/horizon-client/src/world.rs @@ -53,7 +53,7 @@ pub struct World { pub chunks: crate::chunk_map::ChunkMap, pub random: LegacyRandom, pub revision: u64, - pub health_rules: crate::health::HealthRules, + pub health_rules: HealthRules, pub air: BlockStateId, /// Sections whose geometry changed and need remeshing. pub dirty_sections: DirtySections, @@ -170,7 +170,7 @@ impl World { chunks: Default::default(), random: LegacyRandom::new(seed), revision: 0, - health_rules: crate::health::HealthRules::default(), + health_rules: HealthRules::default(), air, fast_lava: false, dirty_sections: Default::default(), @@ -377,6 +377,32 @@ impl World { } } +/// The game rules and difficulty a player's health reads (`Player.isInvulnerableTo`, +/// natural regeneration), kept with the world they belong to. +#[derive(Clone, Copy, Debug)] +pub struct HealthRules { + pub difficulty: horizon_world::food::Difficulty, + pub natural_regeneration: bool, + /// The `drowning_damage`, `fall_damage`, `fire_damage` and + /// `freeze_damage` rules `Player.isInvulnerableTo` reads. + pub drowning_damage: bool, + pub fall_damage: bool, + pub fire_damage: bool, + pub freeze_damage: bool, +} +impl Default for HealthRules { + fn default() -> Self { + Self { + difficulty: horizon_world::food::Difficulty::Normal, + natural_regeneration: true, + drowning_damage: true, + fall_damage: true, + fire_damage: true, + freeze_damage: true, + } + } +} + #[cfg(test)] mod tests { use super::World;