[PR #5306] [MERGED] Content mods: a block declares its own state properties #6199

Closed
opened 2026-11-03 06:15:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: mods/content-block-state-properties


📝 Commits (2)

  • e7f4440 Content mods: a block declares its own state properties (#5290)
  • 79ce647 Content mods: the state tables fan out per combination, and a declared

📊 Changes

4 files changed (+749 additions, -60 deletions)

View changed files

📝 crates/horizon-client/src/mod_content.rs (+227 -60)
📝 crates/horizon-client/src/mod_content_tests.rs (+435 -0)
📝 crates/horizon-mods/src/content.rs (+66 -0)
📝 docs/mods.md (+21 -0)

📄 Description

🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally.

Part of #5290 (edited by Ludovic's AI agent: the model-states slice is still to come, so #5290 stays open). Part of #4953, under Content registration ("Mod blocks with their own block properties and state spaces").

What a block file can now say

{ "template": "minecraft:stone",
  "state_properties": {
    "facing": { "type": "enum", "values": ["north", "south", "east", "west"] },
    "lit": { "type": "boolean" } },
  "default_state": { "lit": "true" } }

stone has one state, so that block has eight: facing × lit, with
lit=true, facing=north first because that is what it declares. A block's states
are its template's states times the combinations it declares, appended after the
template's run, so a block's states stay one contiguous run in registry order —
which range() and Rename both depend on.

How the id mapping survives a fan-out

Rename::id mapped a template state to a mod state as first + (id - start), a
linear offset. Once one template state owns several states that is no longer a
single answer. The combination order is fixed so that every property is at its
default first, and Rename carries how many states a block gives each of its
template's:

self.states
    .contains(&id)
    .then(|| self.first + (id - self.states.start) * self.fanout)

A template state therefore moves to the first of its own, which is also the
block's default — so facts.json's defaults entry and render-definitions.json's
state ids keep working with no arithmetic of their own. Ordering is by property
name (a BTreeMap's), each one's declared default first and the rest rotated to
keep their declared order, the first name varying slowest: deterministic and
independent of mod order, so ids do not move between loads.

The declared properties go on each state's own row in facts.json (its fifth
field, {"id": …, "properties": {…}}). That is not cosmetic — the registry
indexes states by name and properties, so without it every combination of one
template state would collide into a single id.

Refused

  • A name its template already has (state property axis is already on minecraft:piston), so a template's state space is never silently reshaped.
  • A name or value that is not lower case letters, digits and underscores; an empty enum; a repeating value.
  • A default_state value its own property does not have.
  • More combinations than a world holds (MAX_STATES, 2^20) — refused before the product is built, not after, so a declaration cannot allocate its way through memory.

Testing

  • cargo test -p horizon-client --lib — 1013 passed, 0 failed, 29 ignored.
  • cargo test -p horizon-client --lib mod_content::tests:: — 24 passed, 13 ignored (the content-root ones need prepared vanilla data).
  • New tests: the fan-out (2 template states × 6 combinations, every state distinct, first and last checked), the declared default coming first, the Rename mapping, and each refusal.
  • New with the per-combination tables: the_nbt_tables_fan_out_with_the_states (an NBT table's states and cached_shapes stay the same length and each row carries its combination's properties, so BlockTable::check finds the registry's states), a_shape_and_the_state_count_cover_every_combination (collision_shapes maps every state of the block to a shape, and structure-blocks.json's declared total matches its lists), and a_declared_property_defaults_on_a_template_with_none. Each was checked red before green: the old nbt gives a table 4 rows where facts.json has 6, the old collision_shapes leaves the block's last state at -1, the old count says 4 where the lists hold 6, and the old default_state guard refuses a property-less template.
  • A mod that declares nothing is untouched: the fan-out is 1 and every id is what it was. The existing content_block_default_state_is_validated_and_overlaid and allocated_ids_follow_mod_and_entry_order_after_vanilla still pass.
  • Not run: the #[ignore]d content-root tests and the parity harnesses — .local/ is not prepared on this machine. mod_content.rs is a client-lib file, so this wants run-parity.
  • Not tested in game: nothing consumes the new states yet. A mod's own assets/<id>/blockstates/*.json naming them, and native_block_property reading them, are the next two slices in #5290. This PR is the content and registry side only.
  • cargo fmt --all --check, and cargo clippy -p horizon-client -p horizon-mods --lib --tests -- -D warnings pass. Rebased onto #5304, which fixed the unreachable_pattern in lan/hub.rs that was failing clippy on main when this branch started.

Next in #5290

  1. The model/blockstate side, so per-side states pick a model.
  2. native_block_property / native_set_block_property reaching declared properties.

🤖 Generated with DeepSeek Harness (deepseek-v4.1-flash)


🔄 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/5306 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mods/content-block-state-properties` --- ### 📝 Commits (2) - [`e7f4440`](https://github.com/horizon-rust/horizon/commit/e7f4440f05461c8975bebd2d185e3e9c6214aa4a) Content mods: a block declares its own state properties (#5290) - [`79ce647`](https://github.com/horizon-rust/horizon/commit/79ce64782abe74fb31c0528f4163683d90a8520a) Content mods: the state tables fan out per combination, and a declared ### 📊 Changes **4 files changed** (+749 additions, -60 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mod_content.rs` (+227 -60) 📝 `crates/horizon-client/src/mod_content_tests.rs` (+435 -0) 📝 `crates/horizon-mods/src/content.rs` (+66 -0) 📝 `docs/mods.md` (+21 -0) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally. Part of #5290 (edited by Ludovic's AI agent: the model-states slice is still to come, so #5290 stays open). Part of #4953, under **Content registration** ("Mod blocks with their own block properties and state spaces"). ## What a block file can now say ```json { "template": "minecraft:stone", "state_properties": { "facing": { "type": "enum", "values": ["north", "south", "east", "west"] }, "lit": { "type": "boolean" } }, "default_state": { "lit": "true" } } ``` `stone` has one state, so that block has eight: `facing` × `lit`, with `lit=true, facing=north` first because that is what it declares. A block's states are its template's states times the combinations it declares, appended after the template's run, so a block's states stay one contiguous run in registry order — which `range()` and `Rename` both depend on. ## How the id mapping survives a fan-out `Rename::id` mapped a template state to a mod state as `first + (id - start)`, a linear offset. Once one template state owns several states that is no longer a single answer. The combination order is fixed so that every property is at its **default first**, and `Rename` carries how many states a block gives each of its template's: ```rust self.states .contains(&id) .then(|| self.first + (id - self.states.start) * self.fanout) ``` A template state therefore moves to the first of its own, which is also the block's default — so `facts.json`'s `defaults` entry and `render-definitions.json`'s state ids keep working with no arithmetic of their own. Ordering is by property name (a `BTreeMap`'s), each one's declared default first and the rest rotated to keep their declared order, the first name varying slowest: deterministic and independent of mod order, so ids do not move between loads. The declared properties go on each state's own row in `facts.json` (its fifth field, `{"id": …, "properties": {…}}`). That is not cosmetic — the registry indexes states by name and properties, so without it every combination of one template state would collide into a single id. ## Refused - A name its template already has (`state property axis is already on minecraft:piston`), so a template's state space is never silently reshaped. - A name or value that is not lower case letters, digits and underscores; an empty enum; a repeating value. - A `default_state` value its own property does not have. - More combinations than a world holds (`MAX_STATES`, 2^20) — refused *before* the product is built, not after, so a declaration cannot allocate its way through memory. ## Testing - `cargo test -p horizon-client --lib` — 1013 passed, 0 failed, 29 ignored. - `cargo test -p horizon-client --lib mod_content::tests::` — 24 passed, 13 ignored (the content-root ones need prepared vanilla data). - New tests: the fan-out (2 template states × 6 combinations, every state distinct, first and last checked), the declared default coming first, the `Rename` mapping, and each refusal. - New with the per-combination tables: `the_nbt_tables_fan_out_with_the_states` (an NBT table's `states` and `cached_shapes` stay the same length and each row carries its combination's properties, so `BlockTable::check` finds the registry's states), `a_shape_and_the_state_count_cover_every_combination` (`collision_shapes` maps every state of the block to a shape, and `structure-blocks.json`'s declared total matches its lists), and `a_declared_property_defaults_on_a_template_with_none`. Each was checked red before green: the old `nbt` gives a table 4 rows where `facts.json` has 6, the old `collision_shapes` leaves the block's last state at -1, the old count says 4 where the lists hold 6, and the old `default_state` guard refuses a property-less template. - A mod that declares nothing is untouched: the fan-out is 1 and every id is what it was. The existing `content_block_default_state_is_validated_and_overlaid` and `allocated_ids_follow_mod_and_entry_order_after_vanilla` still pass. - **Not run:** the `#[ignore]`d content-root tests and the parity harnesses — `.local/` is not prepared on this machine. `mod_content.rs` is a client-lib file, so this wants `run-parity`. - **Not tested in game:** nothing consumes the new states yet. A mod's own `assets/<id>/blockstates/*.json` naming them, and `native_block_property` reading them, are the next two slices in #5290. This PR is the content and registry side only. - `cargo fmt --all --check`, and `cargo clippy -p horizon-client -p horizon-mods --lib --tests -- -D warnings` pass. Rebased onto #5304, which fixed the `unreachable_pattern` in `lan/hub.rs` that was failing clippy on `main` when this branch started. ## Next in #5290 1. The model/blockstate side, so per-side states pick a model. 2. `native_block_property` / `native_set_block_property` reaching declared properties. 🤖 Generated with DeepSeek Harness (deepseek-v4.1-flash) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:15:47 +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#6199
No description provided.