diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 959b3426b..37b0067c9 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1527,6 +1527,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. @@ -10343,40 +10345,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) - }; - // The Horizon Weather option off silences the rain too. - if self.settings.horizon.weather { - 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( @@ -13299,6 +13268,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 c5bd437ae..fecb58615 100644 --- a/crates/horizon-client/src/game/render_tick.rs +++ b/crates/horizon-client/src/game/render_tick.rs @@ -289,14 +289,16 @@ impl Game<'_> { e[2].floor() as i32, ]; animate_tick(self.res.animate(), &mut self.particles, &ctx, block); - // The Horizon Weather option off means no rain visuals at all. + // The Horizon Weather option off means no rain visuals or sounds at all. if rain > 0.0 && self.settings.horizon.weather { - // ClientLevel.tickWeatherEffects: rain splashes within the weather radius. + // ClientLevel.tickWeatherEffects: rain splashes within the weather + // radius, and the rain sound. let mut random = LegacyRandom::new(self.world.game_time.wrapping_mul(312_987_231)); let radius = self.settings.weather_radius; let diameter = 2 * radius + 1; let count = (0.225 * (diameter * diameter) as f32 * rain * rain) as i32 / if self.settings.particles == 1 { 2 } else { 1 }; + 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; @@ -308,11 +310,13 @@ impl Game<'_> { { continue; } - // The Minimal option stops at the first spot that rains. + let below = top - 1; + rain_position = Some([x, below, z]); + // The Minimal option stops at the first spot that rains (the + // rain sound still plays there). if self.settings.particles >= 2 { break; } - let below = top - 1; let (bx, bz) = (random.next_double(), random.next_double()); let state = world.block(x, below, z); let f = facts.get(state); @@ -344,6 +348,26 @@ 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); + // playLocalSound: guests make their own rain, so a host + // must not capture it for them. + self.audio.play_unshared(name, Some(p), volume, pitch); + } + } } } if let Some(r) = &self.renderer {