From 147e5269c76430060007b13a1dc947a99062896c Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 15:19:20 +0100 Subject: [PATCH 1/2] Play the rain sound the way vanilla picks it --- crates/horizon-client/src/game.rs | 35 +++---------------- crates/horizon-client/src/game/render_tick.rs | 23 +++++++++++- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 1d86fe990..f491b3f8f 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1382,6 +1382,8 @@ struct Game<'a> { /// `ClientAvatarState`: walked distance and view bob. avatar: horizon_client::camera::AvatarBob, flash: u32, + /// `ClientLevel.rainSoundTime`: ticks of rain since the last rain sound. + rain_sound_time: i32, /// Bolts that struck here and sky flashes they made, in total (`status`). lightning_seen: [u32; 2], /// The head of the bed while sleeping; the visual timer also survives waking. @@ -9497,37 +9499,7 @@ impl Game<'_> { if self.flash > 0 { self.flash -= 1; } - let (rain, _) = self.world.weather.levels(1.0); - let Some(eye) = self.eye_position() else { - return; - }; - // WeatherEffectRenderer.tickRainParticles: occasional rain sounds. - if rain > 0.0 && self.world.random.next_int_bound(3).unwrap_or(1) < (rain * 3.0) as i32 { - let r = &mut self.world.random; - let (dx, dz) = ( - r.next_int_bound(21).unwrap_or(10) - 10, - r.next_int_bound(21).unwrap_or(10) - 10, - ); - let (x, z) = (eye[0].floor() as i32 + dx, eye[2].floor() as i32 + dz); - let top = self.rain_height(x, z); - if self.precipitation(x, top, z) == Some(false) - && (top - eye[1] as i32).abs() < 10 - && self.world.random.next_int_bound(5).unwrap_or(1) == 0 - { - let above = f64::from(top) > eye[1] + 1.0; - let (name, volume, pitch) = if above { - ("minecraft:weather.rain.above", 0.1, 0.5) - } else { - ("minecraft:weather.rain", 0.2, 1.0) - }; - self.audio.play( - name, - Some([f64::from(x) + 0.5, f64::from(top), f64::from(z) + 0.5]), - volume, - pitch, - ); - } - } + // The rain sounds come with the rain splashes (`tick_particles`). } /// WeatherEffectRenderer: rain and snow columns within the weather radius. fn weather_geometry( @@ -12267,6 +12239,7 @@ impl<'a> Game<'a> { dragging: false, avatar: Default::default(), flash: 0, + rain_sound_time: 0, lightning_seen: [0; 2], sleeping: None, sleep_timer: 0, diff --git a/crates/horizon-client/src/game/render_tick.rs b/crates/horizon-client/src/game/render_tick.rs index e013c8d29..2356fbffe 100644 --- a/crates/horizon-client/src/game/render_tick.rs +++ b/crates/horizon-client/src/game/render_tick.rs @@ -288,11 +288,13 @@ impl Game<'_> { ]; animate_tick(self.res.animate(), &mut self.particles, &ctx, block); if rain > 0.0 { - // ClientLevel.tickWeatherEffects: rain splashes (weather radius 10). + // ClientLevel.tickWeatherEffects: rain splashes (weather radius 10) + // and the rain sound. let mut random = LegacyRandom::new(self.world.game_time.wrapping_mul(312_987_231)); let radius = 10; let diameter = 2 * radius + 1; let count = (0.225 * (diameter * diameter) as f32 * rain * rain) as i32; + let mut rain_position = None; for _ in 0..count { let x = block[0] + random.next_int_bound(diameter).unwrap_or(0) - radius; let z = block[2] + random.next_int_bound(diameter).unwrap_or(0) - radius; @@ -305,6 +307,7 @@ impl Game<'_> { continue; } let below = top - 1; + rain_position = Some([x, below, z]); let (bx, bz) = (random.next_double(), random.next_double()); let state = world.block(x, below, z); let f = facts.get(state); @@ -336,6 +339,24 @@ impl Game<'_> { self.particles .add(&ParticleOptions::simple(ty), p, [0.0; 3]); } + // The last rain column of the tick makes the sound, more often the + // longer it has been quiet; indoors it is the quieter one. + if let Some(at) = rain_position { + let waited = self.rain_sound_time; + self.rain_sound_time += 1; + if random.next_int_bound(3).unwrap_or(0) < waited { + self.rain_sound_time = 0; + let roof = + motion_blocking(world, facts, block[0], block[2], MIN_Y + HEIGHT); + let (name, volume, pitch) = if at[1] > block[1] + 1 && roof > block[1] { + ("minecraft:weather.rain.above", 0.1, 0.5) + } else { + ("minecraft:weather.rain", 0.2, 1.0) + }; + let p = at.map(|c| f64::from(c) + 0.5); + self.audio.play(name, Some(p), volume, pitch); + } + } } } if let Some(r) = &self.renderer { From 53ea3e7224480c6e72c73a7fd4404bd0cde04fb1 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 22:00:04 +0100 Subject: [PATCH 2/2] Play the rain sound for this client only --- crates/horizon-client/src/game/render_tick.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game/render_tick.rs b/crates/horizon-client/src/game/render_tick.rs index 2356fbffe..10404c0ba 100644 --- a/crates/horizon-client/src/game/render_tick.rs +++ b/crates/horizon-client/src/game/render_tick.rs @@ -354,7 +354,9 @@ impl Game<'_> { ("minecraft:weather.rain", 0.2, 1.0) }; let p = at.map(|c| f64::from(c) + 0.5); - self.audio.play(name, Some(p), volume, pitch); + // playLocalSound: guests make their own rain, so a host + // must not capture it for them. + self.audio.play_unshared(name, Some(p), volume, pitch); } } }