[PR #674] [MERGED] Block state ids past 16 bits: ATM10's 42 carried mods load #2720

Closed
opened 2026-11-02 15:58:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/674
Author: @ludovic111
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/17/2026
Merged by: @ludovic111

Base: main ← Head: feat/wide-block-states


📝 Commits (4)

  • f48a54d Block state ids past 16 bits
  • 4d1596f Load ATM10's 42 carried mods: room past 8,192 textures and tags
  • a60519e Merge origin/main into feat/wide-block-states
  • a6592eb Merge main into feat/wide-block-states

📊 Changes

48 files changed (+407 additions, -224 deletions)

View changed files

📝 crates/horizon-client/examples/lan_flat.rs (+1 -6)
📝 crates/horizon-client/examples/light_parity.rs (+3 -3)
📝 crates/horizon-client/examples/random_tick_eligibility_bench.rs (+4 -4)
📝 crates/horizon-client/examples/save_batch_bench.rs (+2 -2)
📝 crates/horizon-client/examples/save_parity.rs (+2 -2)
📝 crates/horizon-client/examples/section_mesh_fixture.rs (+1 -1)
📝 crates/horizon-client/src/assets.rs (+3 -0)
📝 crates/horizon-client/src/chunk.rs (+38 -24)
📝 crates/horizon-client/src/chunk_map.rs (+1 -1)
📝 crates/horizon-client/src/crafting.rs (+9 -1)
📝 crates/horizon-client/src/flatgen.rs (+2 -2)
📝 crates/horizon-client/src/game.rs (+1 -1)
📝 crates/horizon-client/src/game/commands.rs (+4 -7)
📝 crates/horizon-client/src/game/creaking.rs (+1 -1)
📝 crates/horizon-client/src/game/lan.rs (+2 -2)
📝 crates/horizon-client/src/game/natural_spawning.rs (+1 -1)
📝 crates/horizon-client/src/game/remote.rs (+28 -4)
📝 crates/horizon-client/src/game/sculk.rs (+8 -11)
📝 crates/horizon-client/src/gfx.rs (+9 -1)
📝 crates/horizon-client/src/lan/chunks.rs (+17 -13)

...and 28 more files

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Content mods can now take the block registry past 65,536 states. ATM10's 42 carried data-tier mods (193,762 states, 18 bits) load into a world and render. Before this they were refused by the #648 guard, and the game started without content mods.

ATM10's carried blocks in game

Design

  • Chunk palettes. Section keeps block states as u32. PalettedContainer storage was already u32-capable. The global palette's width comes from the registry: chunk::set_block_states(registry.len()) is called once in Assets::load, and chunk::block_strategy() replaces the BLOCK_STRATEGY const. The width is ceil_log2(states).max(16), so vanilla keeps exactly 16 bits. Sections only reach the global palette past 256 distinct states, so resident memory doesn't change: 36.0 KiB per chunk before and after.
  • Network. The LAN host writes chunks at the registry's width. With vanilla, or with mods that stay within 16 bits, the wire bytes are unchanged, so vanilla clients get vanilla ids. The width grows only for a Horizon whose content mods pass 65,536 states, which means Horizon-to-Horizon with the same mods.
    • A remote chunk's global sections are read at the server's width (16 from a vanilla server) and then widened to ours. Ids past our registry read as air, so joining a host whose mods we lack can't corrupt the palette.
    • SectionBlocksUpdate already packs the state into a VarLong, and BlockUpdate/BlockEvent now carry the full id.
  • Limit. mod_content::MAX_STATES goes from 2^16 to 2^20.
  • Everything that held a state in 16 bits now uses u32: the light engine, mesher, fluid mesher, minimap, sculk, creaking, natural spawning, commands, LAN hub, save decode, worldgen fixtures, examples and tests. Silent as u16 truncations in LAN block events are gone.

The 42 mods also needed these loaders to stop refusing big or imperfect content (second commit):

  • Block sprites: eight texture arrays of 2048 layers instead of four. The 42 mods take 9,790 block textures, and vanilla needs one array.
  • Per-state tables read as NBT: Limits::tables() covers 2^20 states, and level data's cached-collision.nbt now uses it.
  • Worldgen block tags: up to 2^20 blocks instead of 8,192 (mineable/pickaxe takes every stone block of a pack).
  • Broken mod files load the way vanilla loads them:
    • A blockstate definition that doesn't bind (11 Chipped vines) is logged and its block gets no model.
    • A block model that is missing or doesn't parse (5 in Macaw's and Regions Unexplored) gets the missing model.
    • A recipe that doesn't parse (3 in Pam's) is skipped.
    • Before, one bad file dropped every mod or stopped the game.
    • Vanilla's strict model loading is unchanged: the lenient path only runs when the strict one fails.

Found but not fixed here (the carry step's job, next PR): a lang file with an uppercase name (Mekanism Tools), an empty tag file (CTOV) and vanilla tags with "replace": true (Towns and Towers). I set those files aside by hand for the run above.

Vanilla speed: no slowdown measured

Mac mini M4 Pro. The machine is shared and noisy: other sessions kept CPU at 70-95% and the load average around 40. Base (origin/main before this branch) and new binaries ran alternately.

chunk_bench --size 8 (vanilla terrain, 100 chunks), 15 alternating runs each, min / median:

base new
light, ms per column 1.31 / 3.56 1.36 / 1.72
mesh, µs per section 77.2 / 140.7 76.3 / 114.7
random get, ns 11.5 / 24.5 10.3 / 19.0
scan get, ns 1.37 / 2.54 1.34 / 2.01
resident per chunk 36.0 KiB 36.0 KiB

streaming_bench --threads 4 --radius 8, 6 alternating runs: fill took 3.68-6.40 s (base) and 2.68-6.73 s (new). The noise is larger than any difference.

Checks

  • cargo fmt; cargo clippy --workspace --all-targets -- -D warnings.
  • Tests for horizon-client, horizon-world, horizon-core and horizon-protocol all pass. New tests:
    • tests/wide_states.rs: sections and chunks hold states past 65,536 and switch to a 17-bit global palette.
    • builds_past_sixteen_bit_states: 40 redstone-wire copies build a content root.
    • refuses_more_states_than_a_world_holds: past 2^20.
    • The model library's missing-model fallback.
    • The worldgen tag bound.
  • Local parity (tools/parity.py --changed origin/main on 4d1596fe): 295 harnesses selected, 295 passed, 0 failed.
  • In game: --dev-mod with ATM10's 42 carried mods. 193,762 block states, 12,931 items, playing at 20-25 FPS offscreen while the machine was busy. Blocks placed past id 65,536 (Macaw's Roofs, Regions Unexplored, Luminax) read back and render.

Not in this PR: memory. The 42 mods take the game to about 7.9 GB RSS. The next PR measures where it goes per loader and cuts it.

🤖 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/674 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/wide-block-states` --- ### 📝 Commits (4) - [`f48a54d`](https://github.com/horizon-rust/horizon/commit/f48a54da095686cdf5f1088e13e0f5731db0f66e) Block state ids past 16 bits - [`4d1596f`](https://github.com/horizon-rust/horizon/commit/4d1596fe3b903d4f2ca35ad8aac097f571c5f81b) Load ATM10's 42 carried mods: room past 8,192 textures and tags - [`a60519e`](https://github.com/horizon-rust/horizon/commit/a60519eb638aff757e2de8f1217aa3a18b5d52a1) Merge origin/main into feat/wide-block-states - [`a6592eb`](https://github.com/horizon-rust/horizon/commit/a6592eb188f00336b71d9b31a9f96ffddd73a237) Merge main into feat/wide-block-states ### 📊 Changes **48 files changed** (+407 additions, -224 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/lan_flat.rs` (+1 -6) 📝 `crates/horizon-client/examples/light_parity.rs` (+3 -3) 📝 `crates/horizon-client/examples/random_tick_eligibility_bench.rs` (+4 -4) 📝 `crates/horizon-client/examples/save_batch_bench.rs` (+2 -2) 📝 `crates/horizon-client/examples/save_parity.rs` (+2 -2) 📝 `crates/horizon-client/examples/section_mesh_fixture.rs` (+1 -1) 📝 `crates/horizon-client/src/assets.rs` (+3 -0) 📝 `crates/horizon-client/src/chunk.rs` (+38 -24) 📝 `crates/horizon-client/src/chunk_map.rs` (+1 -1) 📝 `crates/horizon-client/src/crafting.rs` (+9 -1) 📝 `crates/horizon-client/src/flatgen.rs` (+2 -2) 📝 `crates/horizon-client/src/game.rs` (+1 -1) 📝 `crates/horizon-client/src/game/commands.rs` (+4 -7) 📝 `crates/horizon-client/src/game/creaking.rs` (+1 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+2 -2) 📝 `crates/horizon-client/src/game/natural_spawning.rs` (+1 -1) 📝 `crates/horizon-client/src/game/remote.rs` (+28 -4) 📝 `crates/horizon-client/src/game/sculk.rs` (+8 -11) 📝 `crates/horizon-client/src/gfx.rs` (+9 -1) 📝 `crates/horizon-client/src/lan/chunks.rs` (+17 -13) _...and 28 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Content mods can now take the block registry past 65,536 states. ATM10's 42 carried data-tier mods (193,762 states, 18 bits) load into a world and render. Before this they were refused by the #648 guard, and the game started without content mods. ![ATM10's carried blocks in game](https://raw.githubusercontent.com/ludovic111/horizon/4ae787d19f7847d5a2b862527584ec428ac06e10/atm10-wide-states.png) ## Design - **Chunk palettes.** `Section` keeps block states as `u32`. `PalettedContainer` storage was already `u32`-capable. The global palette's width comes from the registry: `chunk::set_block_states(registry.len())` is called once in `Assets::load`, and `chunk::block_strategy()` replaces the `BLOCK_STRATEGY` const. The width is `ceil_log2(states).max(16)`, so vanilla keeps exactly 16 bits. Sections only reach the global palette past 256 distinct states, so resident memory doesn't change: 36.0 KiB per chunk before and after. - **Network.** The LAN host writes chunks at the registry's width. With vanilla, or with mods that stay within 16 bits, the wire bytes are unchanged, so vanilla clients get vanilla ids. The width grows only for a Horizon whose content mods pass 65,536 states, which means Horizon-to-Horizon with the same mods. - A remote chunk's global sections are read at the server's width (16 from a vanilla server) and then widened to ours. Ids past our registry read as air, so joining a host whose mods we lack can't corrupt the palette. - `SectionBlocksUpdate` already packs the state into a VarLong, and `BlockUpdate`/`BlockEvent` now carry the full id. - **Limit.** `mod_content::MAX_STATES` goes from 2^16 to 2^20. - **Everything that held a state in 16 bits** now uses `u32`: the light engine, mesher, fluid mesher, minimap, sculk, creaking, natural spawning, commands, LAN hub, save decode, worldgen fixtures, examples and tests. Silent `as u16` truncations in LAN block events are gone. The 42 mods also needed these loaders to stop refusing big or imperfect content (second commit): - **Block sprites:** eight texture arrays of 2048 layers instead of four. The 42 mods take 9,790 block textures, and vanilla needs one array. - **Per-state tables read as NBT:** `Limits::tables()` covers 2^20 states, and level data's `cached-collision.nbt` now uses it. - **Worldgen block tags:** up to 2^20 blocks instead of 8,192 (`mineable/pickaxe` takes every stone block of a pack). - **Broken mod files load the way vanilla loads them:** - A blockstate definition that doesn't bind (11 Chipped vines) is logged and its block gets no model. - A block model that is missing or doesn't parse (5 in Macaw's and Regions Unexplored) gets the missing model. - A recipe that doesn't parse (3 in Pam's) is skipped. - Before, one bad file dropped every mod or stopped the game. - Vanilla's strict model loading is unchanged: the lenient path only runs when the strict one fails. Found but not fixed here (the carry step's job, next PR): a lang file with an uppercase name (Mekanism Tools), an empty tag file (CTOV) and vanilla tags with `"replace": true` (Towns and Towers). I set those files aside by hand for the run above. ## Vanilla speed: no slowdown measured Mac mini M4 Pro. The machine is shared and noisy: other sessions kept CPU at 70-95% and the load average around 40. Base (`origin/main` before this branch) and new binaries ran alternately. `chunk_bench --size 8` (vanilla terrain, 100 chunks), 15 alternating runs each, min / median: | | base | new | |---|---:|---:| | light, ms per column | 1.31 / 3.56 | 1.36 / 1.72 | | mesh, µs per section | 77.2 / 140.7 | 76.3 / 114.7 | | random `get`, ns | 11.5 / 24.5 | 10.3 / 19.0 | | scan `get`, ns | 1.37 / 2.54 | 1.34 / 2.01 | | resident per chunk | 36.0 KiB | 36.0 KiB | `streaming_bench --threads 4 --radius 8`, 6 alternating runs: fill took 3.68-6.40 s (base) and 2.68-6.73 s (new). The noise is larger than any difference. ## Checks - `cargo fmt`; `cargo clippy --workspace --all-targets -- -D warnings`. - Tests for horizon-client, horizon-world, horizon-core and horizon-protocol all pass. New tests: - `tests/wide_states.rs`: sections and chunks hold states past 65,536 and switch to a 17-bit global palette. - `builds_past_sixteen_bit_states`: 40 redstone-wire copies build a content root. - `refuses_more_states_than_a_world_holds`: past 2^20. - The model library's missing-model fallback. - The worldgen tag bound. - Local parity (`tools/parity.py --changed origin/main` on 4d1596fe): 295 harnesses selected, 295 passed, 0 failed. - In game: `--dev-mod` with ATM10's 42 carried mods. 193,762 block states, 12,931 items, playing at 20-25 FPS offscreen while the machine was busy. Blocks placed past id 65,536 (Macaw's Roofs, Regions Unexplored, Luminax) read back and render. Not in this PR: memory. The 42 mods take the game to about 7.9 GB RSS. The next PR measures where it goes per loader and cuts it. 🤖 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-02 15:58:31 +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#2720
No description provided.