From 4c4e579d3f9cc7e6cf78f9ba535b590d583a14ec Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 13 Oct 2026 23:38:02 +0200 Subject: [PATCH] Generated chunks keep the ticks their features scheduled VanillaTerrain::finish dropped the proto chunk's block and fluid ticks; vanilla's LevelChunk takes them over from the ProtoChunk (unpackBlockTicks), so the leaf re-measurements and the fluid ticks of lakes and springs run once the chunk is live. They now travel in the chunk's ChunkExtras, like a saved chunk's ticks, and register with the level's scheduler on arrival; block ticks are translated from worldgen's default state ids to the game's block indices. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/vanillagen.rs | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/horizon-client/src/vanillagen.rs b/crates/horizon-client/src/vanillagen.rs index 14f432fa3..9b48edb18 100644 --- a/crates/horizon-client/src/vanillagen.rs +++ b/crates/horizon-client/src/vanillagen.rs @@ -20,6 +20,9 @@ pub struct VanillaTerrain { loot: Option>, /// A worker for structure queries from the game thread. query: std::sync::Mutex>, + /// Block state id -> block index, the game's block tick type: worldgen + /// schedules block ticks by default state id. + tick_blocks: Vec, } /// A proto chunk, or the position of one whose generation failed. enum VanillaProto { @@ -64,11 +67,25 @@ impl VanillaTerrain { } } let loot = dir.parent().and_then(crate::structure_blocks::loot_data); + let mut tick_blocks = Vec::with_capacity(registry.len()); + let mut last: Option<&str> = None; + let mut index = 0u32; + for id in 0..registry.len() { + let name = registry + .state(horizon_world::registry::BlockStateId(id as u32)) + .map_or("", |s| s.name.as_str()); + if last.is_some_and(|l| l != name) { + index += 1; + } + last = Some(name); + tick_blocks.push(index); + } Ok(Self { generator, biome_map, loot, query: std::sync::Mutex::new(None), + tick_blocks, }) } /// The structure starts owned by a chunk (cached by the generator). @@ -217,6 +234,30 @@ impl ChunkGenerator for VanillaTerrain { Section::from_blocks(&values); } } + // Ticks the features scheduled (leaves reshaped at a tree's edge, + // fluids of lakes and springs) run once the chunk is live, as + // LevelChunk takes over ProtoChunk's ticks. + let block_ticks: Vec<_> = chunk + .terrain + .block_ticks() + .pack(0) + .iter() + .filter_map(|t| { + let kind = *self.tick_blocks.get(t.kind.0 as usize)?; + Some(horizon_core::ticks::SavedTick { + kind: horizon_core::ticks::TickTypeId(kind), + ..*t + }) + }) + .collect(); + let fluid_ticks = chunk.terrain.fluid_ticks().pack(0).to_vec(); + if !block_ticks.is_empty() || !fluid_ticks.is_empty() { + out.saved = Some(Arc::new(crate::save::ChunkExtras { + block_ticks, + fluid_ticks, + ..Default::default() + })); + } let base_section = chunk.terrain.min_y() >> 4; for (i, marks) in chunk.terrain.postprocessing().iter().enumerate() { let sy = (base_section + i as i32) * 16;