Merge pull request #2567 from kacpherek/fix/rain-at-mobs

🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19). Thanks @kacpherek: Check rain at the mob's position, not the global weather. I checked it against vanilla 26.3, and it passed every harness it reaches in a union with your other PRs, plus lan_e2e in both modes.
This commit is contained in:
Ludovic Marie
2026-10-27 09:26:55 +01:00
committed by GitHub
7 changed files with 39 additions and 44 deletions
+16 -15
View File
@@ -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<MobEvent>) {
);
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<MobEvent>) {
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
+1 -1
View File
@@ -259,7 +259,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
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;
+1 -9
View File
@@ -184,15 +184,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
}
}
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);
}
@@ -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);
+1 -1
View File
@@ -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
+1 -6
View File
@@ -529,12 +529,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
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;
+16 -10
View File
@@ -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<bool> {
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.