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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-13 23:38:02 +02:00
parent 2c8de2b015
commit 4c4e579d3f
+41
View File
@@ -20,6 +20,9 @@ pub struct VanillaTerrain {
loot: Option<Arc<horizon_world::loot::LootData>>,
/// A worker for structure queries from the game thread.
query: std::sync::Mutex<Option<GeneratorWorker>>,
/// Block state id -> block index, the game's block tick type: worldgen
/// schedules block ticks by default state id.
tick_blocks: Vec<u32>,
}
/// 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;