[PR #3999] [MERGED] Light a column again when an edit darkens it beside an unlit one #5345

Closed
opened 2026-11-03 05:11:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3999
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-2786


📝 Commits (1)

  • b495d49 Light a column again when an edit darkens it beside an unlit one

📊 Changes

2 files changed (+91 additions, -0 deletions)

View changed files

📝 crates/horizon-client-render/src/light.rs (+81 -0)
📝 crates/horizon-client-render/src/streaming.rs (+10 -0)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

Fixes #2786

Generated worlds sometimes saved block light that vanilla never could: an air block at 0 right next to an air block at 6, across a chunk border.

Root cause. A column's light job (light_chunk) lights it from the blocks of its whole 3x3. So a column can already hold light from a neighbour whose own light job hasn't landed yet: the neighbour is loaded, but lit is still false. If a block in the lit column then changes (postprocessing and fluid shape updates do this right after generation), light::relight runs. But relight reads and writes only lit columns (LightWorld::section filters on c.lit). Its darkening pass clears the light that came from the unlit neighbour, and its increase pass can't bring it back, because it can't see into that neighbour. When the neighbour's job lands later, it writes only its own column. Nothing relights the damaged column again, so the 0 next to the 6 stays and is saved with isLightOn 1.

I confirmed the order with logging on a failing run of the issue's repro. Chunk (27, -9) was lit while (28, -9) was loaded but unlit. Edits at (444, -12, -134) and (447, -12, -133) then ran the incremental relight, and only after that did (28, -9)'s first light job land. In passing runs, the same edits come after (28, -9) is lit.

Fix. The new light::beside_unlit lists the columns whose light an incremental relight changed and that border (diagonals included) a loaded column that isn't lit yet. After relight_edits and replay_light_edits, Streaming puts those columns back in dirty_light. Their full job then lights them from the 3x3's blocks again, the neighbour's light sources included. This only triggers while a neighbour's first light is still pending, which in practice means around freshly generated columns.

Overlap: open #3961 also edits Streaming::update's light stage, but it bounds how many light jobs are in flight. This PR only adds columns to dirty_light from relight_edits / replay_light_edits, and the two merge cleanly.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

net.minecraft.world.level.lighting.LevelLightEngine holds one block engine and one sky engine (LightEngine) over a single light storage for every loaded section. Block changes (LevelLightEngine.checkBlock → LightEngine.checkBlock, then propagateDecreases / propagateIncreases in runLightUpdates) and chunk lighting (ThreadedLevelLightEngine.propagateLightSources / setLightEnabled) go through that same storage. So an edit never drops light that another chunk sends in. Horizon lights each column from its 3x3 and relights edits only across lit columns, so a column that loses that light has to be lit again. (Checked with javap -c -p on the 26.3 client jar.)

tools/test_light_parity.py checks light_chunk and relight against vanilla. Neither function changes here: the change only decides when an existing full job runs, so that harness doesn't exercise this path. The new unit test and the end-to-end runs below do.

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran its steps by hand:

cargo fmt --all -- --check                                                  # ok
cargo clippy --profile fast -p horizon-client-render --all-targets -- -D warnings   # ok
cargo test --profile fast -p horizon-client-render --lib light       # 36 passed, 0 failed, 4 ignored
cargo test --profile fast -p horizon-client-render --lib streaming   # 12 passed, 0 failed, 2 ignored
python tools/test_light_parity.py   # 1179648 values compared: 0 sky and 0 block light values differ;
                                     # 100 edits: 0 light values differ from a full relight; light parity ok

New test, light::tests::an_edit_beside_a_column_not_lit_yet_lights_the_column_again:

  • Chunk (1, 0) is loaded but unlit, with a torch at x 22.
  • Chunk (0, 0) is lit from the 3x3. Its own torch at x 14 gives 13 at x 15.
  • The test removes the torch at x 14 and relights. Then (1, 0)'s job lands. After that, x 16 / 15 / 14 must read 8 / 7 / 6.

Before, with only the code reverted (beside_unlit returning nothing, which is what main does):

thread 'light::tests::an_edit_beside_a_column_not_lit_yet_lights_the_column_again' panicked at crates\horizon-client-render\src\light.rs:1155:9:
assertion `left == right` failed: air beside 8 across the border
  left: 0
 right: 7
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 568 filtered out

After:

test light::tests::an_edit_beside_a_column_not_lit_yet_lights_the_column_again ... ok
test result: ok. 15 passed; 0 failed; 2 ignored; 0 measured; 552 filtered out   (light::)

End to end (dedicated server, the issue's repro)

I followed the issue's steps with horizon-client --dedicated --nogui: a new world with seed 1, tick freeze, forceload add 400 -176 495 -97, then polling until execute if loaded 447 0 -136 passes, save-all flush and stop. Then I read BlockLight at y -14, z -136 from the saved region file. Each run used a fresh world folder. "main" is this branch with only the code reverted.

Build Runs x 445 / 446 / 447 (chunk 27) / 448 (chunk 28)
main 12 3 runs stale: 0 / 0 / 0 / 6; 9 runs 3 / 4 / 5 / 6
this PR 15 all 15 runs 3 / 4 / 5 / 6

The issue's vanilla values for 446 / 447 / 448 are 4 / 5 / 6.

The issue's second table, seed 12345: I force-loaded -64 144 95 303 (10 × 10 chunks) the same way. Then I counted adjacent air pairs in the interior chunks whose saved light differs by more than 1, which is impossible in vanilla:

Build Runs Block light pairs off by >1 15 -22 227 block light (vanilla 12)
main 8 6 runs with bad pairs (21, 21, 21 and 31 in the four I counted); 2 runs clean 7 in 3 runs
this PR 7 0 in every run 12 in every run

On the single-player server thread, I opened the same seed-12345 spot (a trial chamber with a copper bulb) on both builds, and also force-loaded the area with ticks frozen and scanned the saved world. Both builds read block light 10 / 11 / 12 / 13 at x 13..16. Neither showed a bad pair, because the race didn't come up there in my runs. With the fix, single player works as before.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3999 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-2786` --- ### 📝 Commits (1) - [`b495d49`](https://github.com/horizon-rust/horizon/commit/b495d4931e71872cdda458b2bb0d1f1e1b77d98a) Light a column again when an edit darkens it beside an unlit one ### 📊 Changes **2 files changed** (+91 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/light.rs` (+81 -0) 📝 `crates/horizon-client-render/src/streaming.rs` (+10 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #2786 Generated worlds sometimes saved block light that vanilla never could: an air block at 0 right next to an air block at 6, across a chunk border. **Root cause.** A column's light job (`light_chunk`) lights it from the blocks of its whole 3x3. So a column can already hold light from a neighbour whose own light job hasn't landed yet: the neighbour is loaded, but `lit` is still false. If a block in the lit column then changes (postprocessing and fluid shape updates do this right after generation), `light::relight` runs. But relight reads and writes only lit columns (`LightWorld::section` filters on `c.lit`). Its darkening pass clears the light that came from the unlit neighbour, and its increase pass can't bring it back, because it can't see into that neighbour. When the neighbour's job lands later, it writes only its own column. Nothing relights the damaged column again, so the 0 next to the 6 stays and is saved with `isLightOn` 1. I confirmed the order with logging on a failing run of the issue's repro. Chunk (27, -9) was lit while (28, -9) was loaded but unlit. Edits at (444, -12, -134) and (447, -12, -133) then ran the incremental relight, and only after that did (28, -9)'s first light job land. In passing runs, the same edits come after (28, -9) is lit. **Fix.** The new `light::beside_unlit` lists the columns whose light an incremental relight changed and that border (diagonals included) a loaded column that isn't lit yet. After `relight_edits` and `replay_light_edits`, `Streaming` puts those columns back in `dirty_light`. Their full job then lights them from the 3x3's blocks again, the neighbour's light sources included. This only triggers while a neighbour's first light is still pending, which in practice means around freshly generated columns. Overlap: open #3961 also edits `Streaming::update`'s light stage, but it bounds how many light jobs are in flight. This PR only adds columns to `dirty_light` from `relight_edits` / `replay_light_edits`, and the two merge cleanly. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `net.minecraft.world.level.lighting.LevelLightEngine` holds one block engine and one sky engine (`LightEngine`) over a single light storage for every loaded section. Block changes (`LevelLightEngine.checkBlock` → `LightEngine.checkBlock`, then `propagateDecreases` / `propagateIncreases` in `runLightUpdates`) and chunk lighting (`ThreadedLevelLightEngine.propagateLightSources` / `setLightEnabled`) go through that same storage. So an edit never drops light that another chunk sends in. Horizon lights each column from its 3x3 and relights edits only across lit columns, so a column that loses that light has to be lit again. (Checked with `javap -c -p` on the 26.3 client jar.) `tools/test_light_parity.py` checks `light_chunk` and `relight` against vanilla. Neither function changes here: the change only decides when an existing full job runs, so that harness doesn't exercise this path. The new unit test and the end-to-end runs below do. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran its steps by hand: ``` cargo fmt --all -- --check # ok cargo clippy --profile fast -p horizon-client-render --all-targets -- -D warnings # ok cargo test --profile fast -p horizon-client-render --lib light # 36 passed, 0 failed, 4 ignored cargo test --profile fast -p horizon-client-render --lib streaming # 12 passed, 0 failed, 2 ignored python tools/test_light_parity.py # 1179648 values compared: 0 sky and 0 block light values differ; # 100 edits: 0 light values differ from a full relight; light parity ok ``` New test, `light::tests::an_edit_beside_a_column_not_lit_yet_lights_the_column_again`: - Chunk (1, 0) is loaded but unlit, with a torch at x 22. - Chunk (0, 0) is lit from the 3x3. Its own torch at x 14 gives 13 at x 15. - The test removes the torch at x 14 and relights. Then (1, 0)'s job lands. After that, x 16 / 15 / 14 must read 8 / 7 / 6. Before, with only the code reverted (`beside_unlit` returning nothing, which is what main does): ``` thread 'light::tests::an_edit_beside_a_column_not_lit_yet_lights_the_column_again' panicked at crates\horizon-client-render\src\light.rs:1155:9: assertion `left == right` failed: air beside 8 across the border left: 0 right: 7 test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 568 filtered out ``` After: ``` test light::tests::an_edit_beside_a_column_not_lit_yet_lights_the_column_again ... ok test result: ok. 15 passed; 0 failed; 2 ignored; 0 measured; 552 filtered out (light::) ``` ### End to end (dedicated server, the issue's repro) I followed the issue's steps with `horizon-client --dedicated --nogui`: a new world with seed 1, `tick freeze`, `forceload add 400 -176 495 -97`, then polling until `execute if loaded 447 0 -136` passes, `save-all flush` and `stop`. Then I read `BlockLight` at y -14, z -136 from the saved region file. Each run used a fresh world folder. "main" is this branch with only the code reverted. | Build | Runs | x 445 / 446 / 447 (chunk 27) / 448 (chunk 28) | |---|---|---| | main | 12 | 3 runs stale: **0 / 0 / 0 / 6**; 9 runs 3 / 4 / 5 / 6 | | this PR | 15 | all 15 runs 3 / 4 / 5 / 6 | The issue's vanilla values for 446 / 447 / 448 are 4 / 5 / 6. The issue's second table, seed 12345: I force-loaded `-64 144 95 303` (10 × 10 chunks) the same way. Then I counted adjacent air pairs in the interior chunks whose saved light differs by more than 1, which is impossible in vanilla: | Build | Runs | Block light pairs off by >1 | 15 -22 227 block light (vanilla 12) | |---|---|---|---| | main | 8 | 6 runs with bad pairs (21, 21, 21 and 31 in the four I counted); 2 runs clean | 7 in 3 runs | | this PR | 7 | 0 in every run | 12 in every run | On the single-player server thread, I opened the same seed-12345 spot (a trial chamber with a copper bulb) on both builds, and also force-loaded the area with ticks frozen and scanned the saved world. Both builds read block light 10 / 11 / 12 / 13 at x 13..16. Neither showed a bad pair, because the race didn't come up there in my runs. With the fix, single player works as before. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:11:57 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5345
No description provided.