Make the fall, drowning, fire and freeze damage game rules work

This commit is contained in:
Kacpherek
2026-10-26 13:20:37 +01:00
parent 5a9e07301b
commit 30fa41ddbd
3 changed files with 23 additions and 2 deletions
@@ -351,6 +351,7 @@ pub fn main() -> Result<()> {
horizon_world::food::Difficulty::Hard,
][op["difficulty"].as_u64().unwrap() as usize],
natural_regeneration: op["regenerate"].as_bool().unwrap(),
..Default::default()
};
}
"food" => {
+5
View File
@@ -763,6 +763,11 @@ impl Game<'_> {
pub(super) fn sync_rules(&mut self) {
self.world.health_rules.natural_regeneration =
self.ui.rules.bool("natural_health_regeneration");
// Player.isInvulnerableTo: the damage-type rules.
self.world.health_rules.drowning_damage = self.ui.rules.bool("drowning_damage");
self.world.health_rules.fall_damage = self.ui.rules.bool("fall_damage");
self.world.health_rules.fire_damage = self.ui.rules.bool("fire_damage");
self.world.health_rules.freeze_damage = self.ui.rules.bool("freeze_damage");
use horizon_world::food::Difficulty;
self.world.health_rules.difficulty = match self.ui.difficulty {
0 => Difficulty::Peaceful,
+17 -2
View File
@@ -29,12 +29,22 @@ pub(crate) type State = HurtState<DamageTypeId>;
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,
}
}
}
@@ -604,8 +614,13 @@ impl ImmunityWorld for Environment<'_> {
fn enchantment_immunity(&mut self) -> io::Result<bool> {
Ok(false)
}
fn damage_rule(&mut self, _: DamageRule) -> io::Result<bool> {
Ok(true)
fn damage_rule(&mut self, rule: DamageRule) -> io::Result<bool> {
Ok(match rule {
DamageRule::Drowning => self.rules.drowning_damage,
DamageRule::Fall => self.rules.fall_damage,
DamageRule::Fire => self.rules.fire_damage,
DamageRule::Freeze => self.rules.freeze_damage,
})
}
fn changing_dimension(&mut self) -> io::Result<bool> {
Ok(false)