From d6017151266c7c9890a6d5d5604b0949daecd7c1 Mon Sep 17 00:00:00 2001 From: FusselTV Date: Tue, 27 Oct 2026 03:08:53 +0100 Subject: [PATCH] Streaming: the last finished ring is lit against decorated neighbours A chunk was lit only once all eight neighbours were finished, so the outermost finished ring of a loaded area (a /forceload square, a /pregen band's edge, a player's last ring) stayed unlit: saved as FULL with no light at all, and with no generation animals, which wait for light. Vanilla's LIGHT step needs its neighbours only at INITIALIZE_LIGHT (ChunkPyramid), so its last FULL ring is lit against decorated chunks. A light job now reads a neighbour that will not finish (past the area) from its decorated proto chunk (ChunkGenerator::light_view). A chunk saved unlit is saved again once lit, and one whose light changes when a neighbour finishes later is saved again. `execute if loaded` needs the chunk lit, as vanilla's needs it ENTITY_TICKING. Co-Authored-By: Claude Opus 5.5 --- .../src/game/commands/execute.rs | 10 +++-- crates/horizon-client/src/save.rs | 3 ++ crates/horizon-client/src/streaming.rs | 40 ++++++++++++++++++- crates/horizon-client/src/vanillagen.rs | 6 +++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/crates/horizon-client/src/game/commands/execute.rs b/crates/horizon-client/src/game/commands/execute.rs index 3f7e4c2a0..b2b410337 100644 --- a/crates/horizon-client/src/game/commands/execute.rs +++ b/crates/horizon-client/src/game/commands/execute.rs @@ -807,10 +807,12 @@ impl Game<'_> { .coords(c, "pos") .map(|co| co.block(self.source_position(), self.source_rotation())); let dimension = self.command_source.map_or(self.dim, |s| s.dimension); - return Ok(flag( - dimension == self.dim - && p.is_some_and(|p| self.world.chunks.contains_key(&(p[0] >> 4, p[2] >> 4))), - )); + // ExecuteCommand.isChunkLoaded: ENTITY_TICKING, which is past lit. + let loaded = |p: [i32; 3]| { + let key = (p[0] >> 4, p[2] >> 4); + self.world.chunks.contains_key(&key) && self.streaming.is_lit(key.0, key.1) + }; + return Ok(flag(dimension == self.dim && p.is_some_and(loaded))); } if c.has("dimension") { let dimension = self.command_source.map_or(self.dim, |s| s.dimension); diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index 5431adcd6..033392224 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -3841,6 +3841,9 @@ impl ChunkGenerator for Persistent { fn is_decorated(&self, proto: &crate::streaming::Proto) -> bool { self.inner.is_decorated(proto) } + fn light_view(&self, proto: &crate::streaming::Proto) -> Option { + self.inner.light_view(proto) + } fn save_protos(&self, protos: &[&crate::streaming::Proto]) { self.save .tables diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 643a604bc..7d25cf64c 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -70,6 +70,11 @@ pub trait ChunkGenerator: Send + Sync + 'static { false } /// What to save of a proto chunk dropped before it became final. + /// A decorated proto chunk's blocks as a column, to light a finished + /// neighbour against (vanilla lights with neighbours at FEATURES). + fn light_view(&self, _proto: &Proto) -> Option { + None + } fn saved_proto(&self, _proto: &Proto) -> Option { None } @@ -207,6 +212,7 @@ struct Shared { } pub struct Streaming { shared: Arc, + light_view: Arc Option + Send + Sync>, results: mpsc::Receiver, threads: Vec>, order: u64, @@ -531,8 +537,13 @@ impl Streaming { .expect("spawn worker") }) .collect(); + let light_view = { + let generator = generator.clone(); + Arc::new(move |p: &Proto| generator.light_view(p)) + }; Self { shared, + light_view, results, threads, order: 0, @@ -746,6 +757,26 @@ impl Streaming { fn distance(&self, x: i32, z: i32) -> i64 { self.ranges().priority(x, z, self.loading) } + /// The 3x3 a light job reads: the finished columns, and for a neighbour + /// that will not finish (past the area), its decorated proto chunk, as + /// vanilla lights its last FULL ring against neighbours at FEATURES. + fn light_region(&self, world: &World, x: i32, z: i32) -> Option> { + let mut region: Region = Default::default(); + for dz in 0..3 { + for dx in 0..3 { + let n = (x + dx as i32 - 1, z + dz as i32 - 1); + region[dz][dx] = Some(match world.chunks.get(&n) { + Some(chunk) => chunk.clone(), + None if !self.in_range(n.0, n.1, 1) && self.decorated.contains(&n) => { + let proto = self.protos.get(&n)?.as_ref()?; + Arc::new((self.light_view)(proto)?) + } + None => return None, + }); + } + } + Some(Box::new(region)) + } fn region(world: &World, x: i32, z: i32) -> Option> { let mut region: Region = Default::default(); for dz in 0..3 { @@ -866,6 +897,11 @@ impl Streaming { } else { apply_relighting(chunk, sections, &mut changed); } + // Saved unlit (at the edge of what was loaded), or its light + // changed: saved again. + if (first && !chunk.light_loaded) || !changed.is_empty() { + world.modified.insert((x, z)); + } chunk.lit = true; if first { for dz in -1..=1 { @@ -1102,7 +1138,7 @@ impl Streaming { world.dirty_light.remove(&(x, z)); continue; } - let Some(region) = Self::region(world, x, z) else { + let Some(region) = self.light_region(world, x, z) else { continue; }; world.dirty_light.remove(&(x, z)); @@ -1424,7 +1460,7 @@ impl Streaming { counts[1] += 1; } else { counts[2] += 1; - if Self::region(world, key.0, key.1).is_some() { + if self.light_region(world, key.0, key.1).is_some() { world.dirty_light.insert(key); } } diff --git a/crates/horizon-client/src/vanillagen.rs b/crates/horizon-client/src/vanillagen.rs index 923818a08..c07082426 100644 --- a/crates/horizon-client/src/vanillagen.rs +++ b/crates/horizon-client/src/vanillagen.rs @@ -433,6 +433,12 @@ impl ChunkGenerator for VanillaTerrain { fn is_decorated(&self, proto: &Proto) -> bool { matches!(proto.downcast_ref::(), Some(VanillaProto::Ready(c)) if c.is_decorated()) } + fn light_view(&self, proto: &Proto) -> Option { + match proto.downcast_ref::() { + Some(VanillaProto::Ready(chunk)) => Some(self.column(chunk)), + _ => None, + } + } fn saved_proto(&self, proto: &Proto) -> Option { let Some(VanillaProto::Ready(chunk)) = proto.downcast_ref::() else { return None;