From 2d72e987c59db0d610cc30a3ae69b61790d3d1be Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:53:15 +0100 Subject: [PATCH] Play ambient sounds and spawn fireflies around firefly bushes, eyeblossoms, pale moss and dry plants --- .../examples/probe/marker_particles_probe.rs | 3 + crates/horizon-client/src/animate_tick.rs | 146 +++++++++++++++++- crates/horizon-client/src/game/render_tick.rs | 22 ++- 3 files changed, 169 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/examples/probe/marker_particles_probe.rs b/crates/horizon-client/examples/probe/marker_particles_probe.rs index 72ebaff22..aec1ccff6 100644 --- a/crates/horizon-client/examples/probe/marker_particles_probe.rs +++ b/crates/horizon-client/examples/probe/marker_particles_probe.rs @@ -74,6 +74,9 @@ pub fn main() -> Result<()> { biomes: &biomes, registry: assets.registry, raining_at: &|_| false, + height_no_leaves: &|_| 0, + firefly_bush_sounds: false, + sky_darken: 0, marker: target.map(|name| (name, &options as &dyn Fn(_) -> _)), }; engine.seed_randoms(1057, 0, 0); diff --git a/crates/horizon-client/src/animate_tick.rs b/crates/horizon-client/src/animate_tick.rs index 28b28544b..7d3d2ca6c 100644 --- a/crates/horizon-client/src/animate_tick.rs +++ b/crates/horizon-client/src/animate_tick.rs @@ -70,6 +70,14 @@ enum Animate { waterlogged: bool, }, EndPortal, + FireflyBush, + /// An open eyeblossom (`Type.OPEN.emitSounds()`). + OpenEyeblossom, + PaleHangingMoss, + /// `DryVegetationBlock`: a dead bush. + DeadBush, + /// `ShortDryGrassBlock` and `TallDryGrassBlock`. + DryGrass, } fn step(facing: &str) -> [i32; 3] { match facing { @@ -149,6 +157,11 @@ fn classify(name: &str, prop: &dyn Fn(&str) -> Option) -> Animate { waterlogged: prop("waterlogged").as_deref() == Some("true"), }, "end_portal" => Animate::EndPortal, + "firefly_bush" => Animate::FireflyBush, + "open_eyeblossom" => Animate::OpenEyeblossom, + "pale_hanging_moss" => Animate::PaleHangingMoss, + "dead_bush" => Animate::DeadBush, + "short_dry_grass" | "tall_dry_grass" => Animate::DryGrass, "sculk_sensor" | "calibrated_sculk_sensor" if prop("sculk_sensor_phase").as_deref() == Some("active") => { @@ -194,6 +207,10 @@ pub struct AnimateTables { power_transmitter: Vec, /// `#triggers_ambient_dried_ghast_block_sounds` (soul sand, soul soil). dried_ghast_sounds: Vec, + /// `#triggers_ambient_desert_dry_vegetation_block_sounds`. + desert_dry_vegetation_sounds: Vec, + terracotta: Vec, + pale_oak_logs: Vec, /// `FireBlock.canBurn`: states with ignite odds above zero (none waterlogged). burnable: Vec, /// Biome id -> ambient particles and probabilities (`minecraft:visual/ambient_particles`). @@ -269,6 +286,11 @@ impl AnimateTables { power_provider: by_state("minecraft:enchantment_power_provider"), power_transmitter: by_state("minecraft:enchantment_power_transmitter"), dried_ghast_sounds: by_state("minecraft:triggers_ambient_dried_ghast_block_sounds"), + desert_dry_vegetation_sounds: by_state( + "minecraft:triggers_ambient_desert_dry_vegetation_block_sounds", + ), + terracotta: by_state("minecraft:terracotta"), + pale_oak_logs: by_state("minecraft:pale_oak_logs"), burnable, ambient, }) @@ -294,6 +316,12 @@ pub struct AnimateContext<'a> { pub registry: &'a BlockRegistry, /// `Level.isRainingAt`. pub raining_at: &'a dyn Fn([i32; 3]) -> bool, + /// `getHeight(MOTION_BLOCKING_NO_LEAVES, x, z)` at a position's column. + pub height_no_leaves: &'a dyn Fn([i32; 3]) -> i32, + /// `EnvironmentAttributes.FIREFLY_BUSH_SOUNDS` (overworld day timeline). + pub firefly_bush_sounds: bool, + /// `Level.getSkyDarken`, for `getMaxLocalRawBrightness`. + pub sky_darken: i32, /// Creative main-hand marker block and a resolver for each placed state's sprite. pub marker: Option<(&'a str, &'a dyn Fn(BlockStateId) -> Option)>, } @@ -344,6 +372,12 @@ impl AnimateContext<'_> { ], )) } + /// `Level.getMaxLocalRawBrightness`: the brighter of block light and + /// sky light less the sky darkening. + fn max_local_raw_brightness(&self, p: [i32; 3]) -> i32 { + let light = self.world.light(p[0], p[1], p[2]); + i32::from(light & 15).max(i32::from(light >> 4) - self.sky_darken) + } fn foliage(&self, p: [i32; 3]) -> u32 { let biome = self .world @@ -395,7 +429,7 @@ fn do_animate_tick( return; } let state = ctx.state(pos); - block_animate_tick(tables, engine, ctx, state, pos); + block_animate_tick(tables, engine, ctx, state, pos, center); let facts = ctx.facts.get(state); if facts.fluid != Fluid::None { fluid_animate_tick( @@ -504,6 +538,22 @@ fn try_spawn_drip( } } } +/// `AmbientDesertBlockSoundsPlayer.shouldPlayDesertDryVegetationBlockSounds`: +/// sand or terracotta two blocks deep. +fn desert_dry_vegetation_sounds( + tables: &AnimateTables, + ctx: &AnimateContext, + below: [i32; 3], +) -> bool { + let triggers = |p: [i32; 3]| { + tables + .desert_dry_vegetation_sounds + .get(ctx.state(p).0 as usize) + .copied() + .unwrap_or(false) + }; + triggers(below) && triggers([below[0], below[1] - 1, below[2]]) +} /// `WaterFluid.animateTick` / `LavaFluid.animateTick`. fn fluid_animate_tick( engine: &mut ParticleEngine, @@ -579,6 +629,7 @@ fn block_animate_tick( ctx: &AnimateContext, state: BlockStateId, pos: [i32; 3], + player: [i32; 3], ) { let (fx, fy, fz) = (f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])); match tables.kind(state) { @@ -935,6 +986,99 @@ fn block_animate_tick( } } } + Animate::FireflyBush => { + // FireflyBushBlock.animateTick: the idle sound on a quiet night + // under open sky, and fireflies in the dark within 5 blocks. + if next_int(engine.random(), 30) == 0 + && ctx.firefly_bush_sounds + && (ctx.height_no_leaves)(pos) <= pos[1] + { + let name = "minecraft:block.firefly_bush.idle"; + sound(engine, name, [fx, fy, fz], 1.0, 1.0); + } + if ctx.max_local_raw_brightness(pos) <= 13 { + let r = engine.random(); + if r.next_double() <= 0.7 { + let p = [ + fx + r.next_double() * 10.0 - 5.0, + fy + r.next_double() * 5.0, + fz + r.next_double() * 10.0 - 5.0, + ]; + add(engine, T::Firefly, p, [0.0; 3]); + } + } + } + Animate::OpenEyeblossom => { + // EyeblossomBlock.animateTick: pale moss below. + if next_int(engine.random(), 700) == 0 { + let below = ctx.state([pos[0], pos[1] - 1, pos[2]]); + if ctx + .registry + .state(below) + .is_some_and(|s| s.name == "minecraft:pale_moss_block") + { + let name = "minecraft:block.eyeblossom.idle"; + sound(engine, name, [fx, fy, fz], 1.0, 1.0); + } + } + } + Animate::PaleHangingMoss => { + // HangingMossBlock.animateTick: under pale oak logs or leaves. + if next_int(engine.random(), 500) == 0 { + let above = ctx.state([pos[0], pos[1] + 1, pos[2]]); + let pale_leaves = ctx + .registry + .state(above) + .is_some_and(|s| s.name == "minecraft:pale_oak_leaves"); + if pale_leaves + || tables + .pale_oak_logs + .get(above.0 as usize) + .copied() + .unwrap_or(false) + { + let name = "minecraft:block.pale_hanging_moss.idle"; + sound(engine, name, [fx, fy, fz], 1.0, 1.0); + } + } + } + Animate::DeadBush => { + // AmbientDesertBlockSoundsPlayer.playAmbientDeadBushSounds. + if next_int(engine.random(), 130) == 0 { + let below = [pos[0], pos[1] - 1, pos[2]]; + let state = ctx.state(below); + let red_sand = ctx + .registry + .state(state) + .is_some_and(|s| s.name == "minecraft:red_sand"); + let terracotta = tables + .terracotta + .get(state.0 as usize) + .copied() + .unwrap_or(false); + if (red_sand || terracotta) && next_int(engine.random(), 3) != 0 { + return; + } + if desert_dry_vegetation_sounds(tables, ctx, below) { + let name = "minecraft:block.deadbush.idle"; + sound(engine, name, [fx, fy, fz], 1.0, 1.0); + } + } + } + Animate::DryGrass => { + // AmbientDesertBlockSoundsPlayer.playAmbientDryGrassSounds: + // played at the player. + if next_int(engine.random(), 200) == 0 + && desert_dry_vegetation_sounds(tables, ctx, [pos[0], pos[1] - 1, pos[2]]) + { + let at = [ + f64::from(player[0]) + 0.5, + f64::from(player[1]), + f64::from(player[2]) + 0.5, + ]; + sound(engine, "minecraft:block.dry_grass.ambient", at, 1.0, 1.0); + } + } Animate::EndPortal => { // EndPortalBlock.animateTick: one smoke particle above the surface. let r = engine.random(); diff --git a/crates/horizon-client/src/game/render_tick.rs b/crates/horizon-client/src/game/render_tick.rs index e013c8d29..d106e32ad 100644 --- a/crates/horizon-client/src/game/render_tick.rs +++ b/crates/horizon-client/src/game/render_tick.rs @@ -18,10 +18,22 @@ use horizon_core::random::{LegacyRandom, RandomSource}; /// The first motion-blocking block at or below `from` (Heightmap MOTION_BLOCKING), plus one. fn motion_blocking(world: &World, facts: &BlockFacts, x: i32, z: i32, from: i32) -> i32 { + motion_blocking_leaves(world, facts, x, z, from, true) +} +/// `motion_blocking` where leaves count only for MOTION_BLOCKING, not for +/// MOTION_BLOCKING_NO_LEAVES. +fn motion_blocking_leaves( + world: &World, + facts: &BlockFacts, + x: i32, + z: i32, + from: i32, + leaves: bool, +) -> i32 { let mut y = from.min(MIN_Y + HEIGHT - 1); while y > MIN_Y { let f = facts.get(world.block(x, y, z)); - if f.full_collision || f.fluid != Fluid::None || f.name.contains("leaves") { + if f.full_collision || f.fluid != Fluid::None || leaves && f.name.contains("leaves") { return y + 1; } y -= 1; @@ -271,6 +283,11 @@ impl Game<'_> { && motion_blocking(world, facts, p[0], p[2], p[1] + 64) <= p[1] && rains_at(world, biomes, p[0], p[1], p[2]) }; + let height_no_leaves = + |p: [i32; 3]| motion_blocking_leaves(world, facts, p[0], p[2], i32::MAX, false); + // The day timeline: firefly bush sounds from 12600 to 23400. + let firefly_bush_sounds = self.dim == Dim::Overworld + && (12600..23401).contains(&self.world.day_time.rem_euclid(24000)); let ctx = AnimateContext { world, facts, @@ -278,6 +295,9 @@ impl Game<'_> { biomes, registry: self.pack.assets.registry, raining_at: &raining_at, + height_no_leaves: &height_no_leaves, + firefly_bush_sounds, + sky_darken: self.sky_darken(), marker: marker.map(|name| (name, &marker_options as &dyn Fn(_) -> _)), }; if let Some(e) = eye {