diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 7990a2292..b3b6fb7c1 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -462,6 +462,16 @@ pub fn tick_swing(m: &mut Mob) { } m.anim.attack_anim = m.ai.swing_time as f32 / 6.0; } +/// `Entity.isInRain`: rain at the block position, or at the top of the box. +pub(super) fn in_rain(m: &Mob, w: &MobWorld) -> bool { + let (x, y, z) = ( + m.position.x.floor() as i32, + m.position.y.floor() as i32, + m.position.z.floor() as i32, + ); + let top = (m.position.y + f64::from(m.height())).floor() as i32; + w.raining_at(x, y, z) || w.raining_at(x, top, z) +} /// `LivingEntity.baseTick` refills a breather's air by 4, then /// `Axolotl.handleAirSupply` (unless the mob has no AI): water or rain fills /// it, anywhere else it runs down from the pre-tick value, and at -20 the @@ -472,15 +482,7 @@ fn axolotl_air_supply(m: &mut Mob, w: &MobWorld) { if m.no_ai { return; } - // Entity.isInRain: rain at the block, or at the top of the box. - let (x, y, z) = ( - m.position.x.floor() as i32, - m.position.y.floor() as i32, - m.position.z.floor() as i32, - ); - let top = (m.position.y + f64::from(m.height())).floor() as i32; - let in_rain = w.raining_at(x, y, z) || w.raining_at(x, top, z); - if m.fluids.in_water || in_rain { + if m.fluids.in_water || in_rain(m, w) { m.air = super::axolotl::MAX_AIR; } else { m.air = before - 1; @@ -508,8 +510,9 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { ); m.damage(fire, Damage::of(DamageKind::InFire)); } - // Fire: water extinguishes, lava ignites, burning hurts every second. - if m.fluids.in_water && m.fire_ticks > 0 { + // Fire: water or rain (Entity.isInRain) extinguishes, lava ignites, + // burning hurts every second. + if m.fire_ticks > 0 && (m.fluids.in_water || in_rain(m, w)) { m.fire_ticks = 0; events.push(MobEvent::Sound( "entity.generic.extinguish_fire", @@ -576,9 +579,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { m.air = (m.air + 4).min(300); } - if m.kind.flags.water_sensitive - && (m.fluids.in_water || w.raining && w.can_see_sky(ex, ey, ez)) - { + if m.kind.flags.water_sensitive && (m.fluids.in_water || in_rain(m, w)) { m.damage(1.0, Damage::of(DamageKind::Drown)); } } @@ -914,7 +915,7 @@ fn sun_burn_tick(m: &mut Mob, w: &MobWorld) -> bool { m.position.z.floor() as i32, ); let br = w.brightness(x, y, z); - let wet = m.fluids.in_water || w.raining && w.can_see_sky(x, y, z); + let wet = m.fluids.in_water || in_rain(m, w); br > 0.5 && m.random.next_float() * 30.0 < (br - 0.4) * 2.0 && !wet && w.can_see_sky(x, y, z) } /// Mob.serverAiStep diff --git a/crates/horizon-client/src/mobs/aquatic.rs b/crates/horizon-client/src/mobs/aquatic.rs index f63a42239..59a73c605 100644 --- a/crates/horizon-client/src/mobs/aquatic.rs +++ b/crates/horizon-client/src/mobs/aquatic.rs @@ -259,7 +259,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { } S::Dolphin => { // Dolphin.tick: moisture out of water, hop on land. - if m.fluids.in_water || w.raining { + if m.fluids.in_water || super::ai::in_rain(m, w) { m.extra.counter = 2400; } else { m.extra.counter -= 1; diff --git a/crates/horizon-client/src/mobs/enderman.rs b/crates/horizon-client/src/mobs/enderman.rs index 3ccd963a2..17566fb65 100644 --- a/crates/horizon-client/src/mobs/enderman.rs +++ b/crates/horizon-client/src/mobs/enderman.rs @@ -184,15 +184,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { } } } - if (m.fluids.in_water - || w.raining - && w.can_see_sky( - m.position.x.floor() as i32, - m.eye_y().floor() as i32, - m.position.z.floor() as i32, - )) - && m.alive() - { + if (m.fluids.in_water || super::ai::in_rain(m, w)) && m.alive() { // Hurt by water: teleport away. m.extra.counter2 = m.extra.counter2.max(1); } diff --git a/crates/horizon-client/src/mobs/happy_ghast.rs b/crates/horizon-client/src/mobs/happy_ghast.rs index bd4c5b1f3..296644acc 100644 --- a/crates/horizon-client/src/mobs/happy_ghast.rs +++ b/crates/horizon-client/src/mobs/happy_ghast.rs @@ -544,14 +544,15 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld) { m.ai.home = Some((here, radius)); } } - // continuousHeal: a point every 30 seconds, every second in rain. + // continuousHeal: a point every 30 seconds, every second in rain or snow + // (Level.precipitationAt). if m.alive() && m.death_time == 0 && m.health < m.attrs.max_health { let (x, y, z) = ( m.position.x.floor() as i32, m.position.y.floor() as i32, m.position.z.floor() as i32, ); - let wet = w.raining && w.can_see_sky(x, y, z); + let wet = w.precipitation_at(x, y, z).is_some(); let interval = if wet { 20 } else { 600 }; if m.age.is_multiple_of(interval) { m.health = (m.health + 1.0).min(m.attrs.max_health); diff --git a/crates/horizon-client/src/mobs/species.rs b/crates/horizon-client/src/mobs/species.rs index 047c1f882..92d1f21cd 100644 --- a/crates/horizon-client/src/mobs/species.rs +++ b/crates/horizon-client/src/mobs/species.rs @@ -1500,7 +1500,7 @@ impl Def { ), // Nautilus.handleAirSupply: it dries out on land. needs_water: aquatic || s == S::Nautilus, - water_sensitive: matches!(s, S::Enderman | S::Blaze | S::SnowGolem), + water_sensitive: matches!(s, S::Enderman | S::Blaze | S::SnowGolem | S::Strider), animal: !matches!(s, S::Bat | S::SulfurCube | S::Mannequin) && !self.hostile_class() && !aquatic diff --git a/crates/horizon-client/src/mobs/tame.rs b/crates/horizon-client/src/mobs/tame.rs index 3361a1f12..0b2075c96 100644 --- a/crates/horizon-client/src/mobs/tame.rs +++ b/crates/horizon-client/src/mobs/tame.rs @@ -529,12 +529,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { let v = &mut m.anim.v; v[INTEREST] += (goal - v[INTEREST]) * 0.4; // isWet (extra.flag2), isShaking (counter2 > 0). - let rain = w.raining - && w.can_see_sky( - m.position.x.floor() as i32, - (m.position.y + f64::from(m.height())).floor() as i32, - m.position.z.floor() as i32, - ); + let rain = super::ai::in_rain(m, w); let shaking = m.extra.counter2 > 0; if m.fluids.in_water || rain { m.extra.flag2 = true; diff --git a/crates/horizon-client/src/mobs/world.rs b/crates/horizon-client/src/mobs/world.rs index bce324228..dc201a3f3 100644 --- a/crates/horizon-client/src/mobs/world.rs +++ b/crates/horizon-client/src/mobs/world.rs @@ -206,18 +206,24 @@ impl MobWorld<'_> { } self.world.light(x, y, z) >> 4 == 15 } - /// Level.isRainingAt: raining, open to the sky, nothing motion blocking - /// above, and the biome's precipitation at the position is rain, not snow + /// Level.precipitationAt: raining, open to the sky, nothing motion + /// blocking above, then the biome's precipitation at the position: + /// `Some(true)` rain, `Some(false)` snow, `None` nothing. + pub fn precipitation_at(&self, x: i32, y: i32, z: i32) -> Option { + if !self.raining || !self.can_see_sky(x, y, z) || self.motion_blocking_height(x, z) > y { + return None; + } + let chunk = self.world.chunks.get(&(x >> 4, z >> 4))?; + let biome = self.biomes.get(chunk.biome(x, y, z)); + if !biome.precipitation { + return None; + } + Some(biome.temperature_at(BlockPos::new(x, y, z), self.sea_level) >= 0.15) + } + /// Level.isRainingAt: the precipitation at the position is rain, not snow /// or none. pub fn raining_at(&self, x: i32, y: i32, z: i32) -> bool { - if !self.raining || !self.can_see_sky(x, y, z) || self.motion_blocking_height(x, z) > y { - return false; - } - let Some(chunk) = self.world.chunks.get(&(x >> 4, z >> 4)) else { - return false; - }; - let biome = self.biomes.get(chunk.biome(x, y, z)); - biome.precipitation && biome.temperature_at(BlockPos::new(x, y, z), self.sea_level) >= 0.15 + self.precipitation_at(x, y, z) == Some(true) } /// Level.getLightLevelDependentMagicValue: the dimension's brightness curve /// at the raw (sky darkened) light level.