[GH-ISSUE #5290] Native mods: a mod block declares its own state properties #1629

Closed
opened 2026-11-02 15:48:29 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @sirrayi on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5290

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

Part of #4953, under Content registration ("Mod blocks with their own block properties and state spaces. Today a content block copies a vanilla block's states.").

The gap

A content mod's block is, in crates/horizon-mods/src/content.rs, "a vanilla template's behaviour, states and shapes under a new id". Its entire state space is the template's state run, copied verbatim: crates/horizon-client/src/mod_content.rs appends one row per template state and advances the id cursor by that state count.

default_state can only overlay values on properties the template already has — it explicitly rejects an unknown property:

{id}: unknown state property {key} on {template}

So a mod cannot declare a state property. A pipe cannot have north/south/east/west connections, a machine cannot have facing + lit + active, a belt cannot have a direction — unless it finds a vanilla block that happens to expose that exact combination, and then it also inherits every unrelated state that block has.

This is the first thing a large tech mod needs: it is block #1, before any capability or renderer matters.

Why it is not just "add a field"

The registry is baked from vanilla (gameplay-facts.json / facts.json, exported by horizon-prepare), and a block's states must be one contiguous run in registry order — Plan relies on that (range() in mod_content.rs), and Rename::id maps a template state id to a mod state id as a linear offset (first + (id - states.start)).

Declaring its own properties means a mod block's run becomes the product of the template's states and the mod's property values, so one template state maps to several mod states. That breaks the linear mapping in Rename::id, which is used for facts.json's defaults and for render-definitions.json (names(doc, true)). Any PR has to settle what a state id inside a copied row means once it fans out.

Proposed shape

A block file may declare properties:

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

Rules I would keep, mirroring how default_state and shapes already behave:

  • A declared name may not shadow a property the template already has.
  • A property is boolean (values false/true, vanilla's spelling) or enum with a non-empty, unique, lower-case value list.
  • The state run is the template's states × the declared combinations, in a fixed order (template state outer, declaration order inner), so ids stay deterministic across mods and load order.
  • default_state may set declared properties too, and must name exactly one state of the resulting run.
  • The total is still bounded by MAX_STATES, and a declared space that would exceed it is refused at plan time with a message naming the block.

The read/write hooks are already there: native_block_property (API 20) and native_set_block_property (API 18, 33). They can only reach the template's properties today; this issue is what makes them reach a mod's own.

Scope

Open questions where the maintainers' judgement should win:

  1. Should the fan-out be the full product, or should the template's states be narrowed to the ones the mod names (a piston-like template has 12 states, most irrelevant once a mod adds its own facing)?
  2. For a state id inside a copied row (render-definitions.json), is "the default combination" the right target, or should a mod block with declared properties keep the template's own reference?
  3. Do mod state properties need to reach native-hooks.json/#4402 names, or is native_block_property enough?

I am happy to take this in small PRs: schema and validation first, then the registry fan-out, then the model/blockstate side.

Recommended test: horizon-machine-sample — a pipe with per-side connections is exactly the case that fails today.

Originally created by @sirrayi on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5290 > 🤖 Filed by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally. Part of #4953, under **Content registration** ("Mod blocks with their own block properties and state spaces. Today a content block copies a vanilla block's states."). ## The gap A content mod's block is, in `crates/horizon-mods/src/content.rs`, "a vanilla template's behaviour, states and shapes under a new id". Its entire state space is the template's state run, copied verbatim: `crates/horizon-client/src/mod_content.rs` appends one row per template state and advances the id cursor by that state count. `default_state` can only overlay *values on properties the template already has* — it explicitly rejects an unknown property: ``` {id}: unknown state property {key} on {template} ``` So a mod cannot declare a state property. A pipe cannot have `north`/`south`/`east`/`west` connections, a machine cannot have `facing + lit + active`, a belt cannot have a direction — unless it finds a vanilla block that happens to expose that exact combination, and then it also inherits every unrelated state that block has. This is the first thing a large tech mod needs: it is block #1, before any capability or renderer matters. ## Why it is not just "add a field" The registry is baked from vanilla (`gameplay-facts.json` / `facts.json`, exported by `horizon-prepare`), and a block's states must be **one contiguous run in registry order** — `Plan` relies on that (`range()` in `mod_content.rs`), and `Rename::id` maps a template state id to a mod state id as a linear offset (`first + (id - states.start)`). Declaring its own properties means a mod block's run becomes the **product** of the template's states and the mod's property values, so one template state maps to several mod states. That breaks the linear mapping in `Rename::id`, which is used for `facts.json`'s defaults and for `render-definitions.json` (`names(doc, true)`). Any PR has to settle what a state id inside a copied row means once it fans out. ## Proposed shape A block file may declare properties: ```json { "template": "minecraft:stone", "state_properties": { "facing": {"type": "enum", "values": ["north", "south", "east", "west"]}, "lit": {"type": "boolean"} }, "default_state": {"facing": "north", "lit": "false"} } ``` Rules I would keep, mirroring how `default_state` and `shapes` already behave: - A declared name may not shadow a property the template already has. - A property is `boolean` (values `false`/`true`, vanilla's spelling) or `enum` with a non-empty, unique, lower-case value list. - The state run is the template's states × the declared combinations, in a fixed order (template state outer, declaration order inner), so ids stay deterministic across mods and load order. - `default_state` may set declared properties too, and must name exactly one state of the resulting run. - The total is still bounded by `MAX_STATES`, and a declared space that would exceed it is refused at plan time with a message naming the block. The read/write hooks are already there: `native_block_property` (API 20) and `native_set_block_property` (API 18, 33). They can only reach the template's properties today; this issue is what makes them reach a mod's own. ## Scope Open questions where the maintainers' judgement should win: 1. Should the fan-out be the full product, or should the template's states be narrowed to the ones the mod names (a piston-like template has 12 states, most irrelevant once a mod adds its own facing)? 2. For a state id inside a copied row (`render-definitions.json`), is "the default combination" the right target, or should a mod block with declared properties keep the template's own reference? 3. Do mod state properties need to reach `native-hooks.json`/`#4402` names, or is `native_block_property` enough? I am happy to take this in small PRs: schema and validation first, then the registry fan-out, then the model/blockstate side. **Recommended test:** [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample) — a pipe with per-side connections is exactly the case that fails today.
Author
Owner

@sirrayi commented on GitHub (Oct 31, 2026):

🤖 Agent: /claim

Taking the first slice (schema and validation in horizon-mods, then the registry fan-out in mod_content.rs) as #5290 describes. One PR at a time, tests with each.

<!-- gh-comment-id:6546652386 --> @sirrayi commented on GitHub (Oct 31, 2026): 🤖 Agent: /claim Taking the first slice (schema and validation in `horizon-mods`, then the registry fan-out in `mod_content.rs`) as #5290 describes. One PR at a time, tests with each.
Author
Owner

@sirrayi commented on GitHub (Oct 31, 2026):

🤖 Agent: the first slice is up as #5306 — the content and registry side.

What it adds: state_properties on a block file (boolean, or an enum of values) and the fan-out in mod_content.rs, so a block's states become its template's states times the declared combinations. default_state takes declared values too.

The part worth reviewing closely is the id mapping, since that was the open question in #5290. Rename::id was a linear offset; a fan-out makes one template state own several. Rather than special-case the two callers, the combination order puts every property at its declared default first, so a template state still maps to exactly one state — the block's default — and facts.json's defaults and render-definitions.json keep working unchanged. Ordering is by property name with the first varying slowest, so ids do not move between loads.

The declared values also go on each state's own facts.json row. That is load-bearing rather than cosmetic: the registry indexes states by name and properties, so without it every combination of one template state would collide into a single id.

Tested with unit tests on the fan-out, the ordering, the Rename mapping and each refusal; cargo test -p horizon-client --lib mod_content::tests:: is 20 passed. The content-root tests and parity harnesses could not run here (no .local/), so run-parity is on the PR. Nothing consumes the new states yet — the model/blockstate side and native_block_property are the next two slices.

<!-- gh-comment-id:6546793358 --> @sirrayi commented on GitHub (Oct 31, 2026): 🤖 Agent: the first slice is up as #5306 — the content and registry side. What it adds: `state_properties` on a block file (`boolean`, or an `enum` of values) and the fan-out in `mod_content.rs`, so a block's states become its template's states times the declared combinations. `default_state` takes declared values too. The part worth reviewing closely is the id mapping, since that was the open question in #5290. `Rename::id` was a linear offset; a fan-out makes one template state own several. Rather than special-case the two callers, the combination order puts every property at its declared default first, so a template state still maps to exactly one state — the block's default — and `facts.json`'s defaults and `render-definitions.json` keep working unchanged. Ordering is by property name with the first varying slowest, so ids do not move between loads. The declared values also go on each state's own `facts.json` row. That is load-bearing rather than cosmetic: the registry indexes states by name and properties, so without it every combination of one template state would collide into a single id. Tested with unit tests on the fan-out, the ordering, the `Rename` mapping and each refusal; `cargo test -p horizon-client --lib mod_content::tests::` is 20 passed. The content-root tests and parity harnesses could not run here (no `.local/`), so `run-parity` is on the PR. Nothing consumes the new states yet — the model/blockstate side and `native_block_property` are the next two slices.
Author
Owner

@sirrayi commented on GitHub (Nov 2, 2026):

🤖 Agent: delivered, so closing this. The three slices the plan named all landed, and none of the three open questions is still open.

  1. Schema, validation and the registry fan-out — #5306 (merged). state_properties on a block file (boolean, or an enum with a value list), refusals for the shadowing, duplicate and empty cases, MAX_STATES bound, and the fan-out in mod_content.rs so a block's states become its template's states times the declared combinations.
  2. The model/blockstate side — #5422 (merged, Aria's agent, for #5379). Model definitions and the per-state render ID list expand in the same combination order, so the declared states load their own models instead of falling back to the template's.
  3. Placement — #5516 (merged), the native hook (native_state_for_placement). The declared form for a content mod with no native code is the part of #5550's item 4 that is still open, and that is where it belongs rather than here.

The read and write hooks reach a declared property with no further work, because each combination is its own row in the registry with the declared values in its own properties map (set_state_properties, mod_content.rs:444): native_block_property reads that map (native_hooks.rs:4753), and native_set_block_property resolves the changed state through it (with_property, native_hooks.rs:5939).

The three questions:

  • Full product or narrowed states? Full product. Narrowing would make a state id depend on which states a mod chose to name, and the contiguous run a block's states must stay in is the whole reason the ordering is fixed.
  • A state id inside a copied row? The block's default combination — every declared property at its declared default first — which is what Rename::id still assumes, and what #5422's render list follows.
  • New names in native-hooks.json? None. native_block_property and native_set_block_property were enough.

What is not done: the end-to-end check the issue recommends, against horizon-machine-sample. There is no prepared game data on this machine, so nothing here was run in-game — the evidence above is code and merged PRs, not a pipe with per-side booleans placed and saved. If that sample still cannot declare its six booleans, reopen and that is the first thing to reproduce.

<!-- gh-comment-id:6566140007 --> @sirrayi commented on GitHub (Nov 2, 2026): 🤖 Agent: delivered, so closing this. The three slices the plan named all landed, and none of the three open questions is still open. 1. **Schema, validation and the registry fan-out** — #5306 (merged). `state_properties` on a block file (`boolean`, or an `enum` with a value list), refusals for the shadowing, duplicate and empty cases, `MAX_STATES` bound, and the fan-out in `mod_content.rs` so a block's states become its template's states times the declared combinations. 2. **The model/blockstate side** — #5422 (merged, Aria's agent, for #5379). Model definitions and the per-state render ID list expand in the same combination order, so the declared states load their own models instead of falling back to the template's. 3. **Placement** — #5516 (merged), the native hook (`native_state_for_placement`). The declared form for a content mod with no native code is the part of #5550's item 4 that is still open, and that is where it belongs rather than here. The read and write hooks reach a declared property with no further work, because each combination is its own row in the registry with the declared values in its own `properties` map (`set_state_properties`, `mod_content.rs:444`): `native_block_property` reads that map (`native_hooks.rs:4753`), and `native_set_block_property` resolves the changed state through it (`with_property`, `native_hooks.rs:5939`). The three questions: - **Full product or narrowed states?** Full product. Narrowing would make a state id depend on which states a mod chose to name, and the contiguous run a block's states must stay in is the whole reason the ordering is fixed. - **A state id inside a copied row?** The block's default combination — every declared property at its declared default first — which is what `Rename::id` still assumes, and what #5422's render list follows. - **New names in `native-hooks.json`?** None. `native_block_property` and `native_set_block_property` were enough. What is *not* done: the end-to-end check the issue recommends, against [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample). There is no prepared game data on this machine, so nothing here was run in-game — the evidence above is code and merged PRs, not a pipe with per-side booleans placed and saved. If that sample still cannot declare its six booleans, reopen and that is the first thing to reproduce.
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#1629
No description provided.