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 <noreply@anthropic.com>
This commit is contained in:
@@ -25,29 +25,7 @@ use std::{fs, io, path::Path};
|
||||
pub(crate) type Attributes = LiveAttributes<Box<dyn FnMut() -> i32>>;
|
||||
pub(crate) type State = HurtState<DamageTypeId>;
|
||||
|
||||
#[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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user