[PR #6360] [MERGED] Native mods: their own models baked with the blocks', ModelEvent.RegisterStandalone #6825

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6360
Author: @levzzz5154
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: mods/standalone-models


📝 Commits (2)

  • 7a9f20a Native mods: models no blockstate names, ModelEvent.RegisterStandalone
  • ceb9787 Merge remote-tracking branch 'hr/main' into mods/standalone-models

📊 Changes

8 files changed (+318 additions, -30 deletions)

View changed files

📝 crates/horizon-client-render/src/models.rs (+45 -1)
📝 crates/horizon-client-render/src/models/catalog.rs (+196 -26)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/minecarts.rs (+15 -1)
📝 crates/horizon-client/src/game/mods.rs (+7 -0)
📝 crates/horizon-client/src/game/native_block_entity_draw.rs (+26 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+13 -0)
➕ tools/native-hook-fragments/standalone_models.json (+15 -0)

📄 Description

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

What and why

Step 1 of #6303 (model changes at bake time, a design proposal), part of #4953 ("Model changes at bake time (ModelEvent.ModifyBakingResult, ModelData)"). It is also the third part of #5551 ("models no blockstate names"), and what the instanced-drawing proposal (#6302) draws. #6303 stays open for its other steps.

A block entity draws parts that aren't blocks: a shaft half, a cog, a press head, a gauge needle. NeoForge mods register them as standalone models (ModelEvent.RegisterStandalone). Until now a Horizon mod had to register a block that is never placed, only so its model got baked, and draw that block (native_draw_block's doc said so).

One client hook point and one helper, API from a fragment (tools/native-hook-fragments/standalone_models.json):

  • native_standalone_models(models: &mut Vec<String>) (ModelEvent.RegisterStandalone): static, asked once at start before the resources load (beside native_component_types). The ids it gets are kept for the run, sorted, deduplicated, and those without a namespace dropped (horizon_client::models::register_standalone).
  • Every resource load, a pack reload included, bakes them beside the block models (StateModels::bake_standalone, after from_facts_with_models), from that pack's files, unturned. One a block state already bakes unturned is shared, not baked twice. One that doesn't read (missing, or a missing parent) is logged and left out, as a blockstate that doesn't read is. A dedicated server bakes nothing, as before.
  • native_draw_model(draw, model, tint) draws one under a BlockEntityDraw's pose, in native_block_entity_submit or native_mob_submit, as native_draw_block draws a block's model: lit by draw.light, with the 0xRRGGBB tint on its tinted faces. It returns false for a model that isn't baked. Its vertex loop is tinted_block_model_vertices's, split out as baked_model_vertices (no change for its callers).

Kind

  • feature: something new for players (mod authors)

Vanilla reference

Vanilla 26.3's ModelManager.reload discovers models (ModelDiscovery) and bakes them (ModelBakery.bakeModels). NeoForge's ModelEvent.RegisterStandalone is posted when discovery collects its top models: a mod registers a StandaloneModelKey with its unbaked model, and it is baked with the rest on every reload. Horizon bakes in StateModels::from_facts_with_models on the start-up thread and on the pack reload worker, so the extra models bake there. The hook is asked once rather than on each discovery: a static hook has no reload to answer from, and the list is the mod's own.

Other projects' code

None. NeoForge's names and javadoc only.

Proof in the real game

The branch is rebased on hr/main ff8e46848 (after #5446). The server-thread run below was repeated at that head with the same output; the dedicated-server run was at the first head, on dea6dea98. Engine from this branch with throwaway lines in the hook bodies (not in this PR). A dev content mod lanef declared lanef:machine (template minecraft:glass, its blockstate pointing at glass's model) and shipped assets/lanef/models/block/shaft_half.json, which no blockstate names: a 6×16×6 post, gold sides, diamond ends. The probe:

  • pushed lanef:block/shaft_half, lanef:block/absent (no file) and nonamespace in native_standalone_models;
  • gave lanef:machine a block entity in native_block_entity;
  • in native_block_entity_submit, translated up one block, turned 4° a tick about Y, and called native_draw_model for both models.

Server thread (horizon-ctl launch --world L --creative --offscreen --dev-mod …, /setblock 0 119 5 lanef:machine, then F3+T):

TESTHOOK standalone_models asked: ["lanef:block/shaft_half", "lanef:block/absent", "nonamespace"]
Horizon: standalone model lanef:block/absent not loaded: No such file or directory (os error 2)
Horizon: resources loaded in 1.8s; 35724 block states, 1659 items, 67 biomes; 11 worker threads
TESTHOOK submit lanef:machine at [0, 119, 5]: shaft_half drawn=true absent drawn=false light=0xf0
Horizon: standalone model lanef:block/absent not loaded: No such file or directory (os error 2)

The second warning is the F3+T reload baking the list again. The hook was asked once. Screenshots before and after the reload show the gold post standing on the glass block, turned between frames.

Dedicated server (port 25760, the mod in its horizon-mods/ and on in horizon-mods.txt) with an offscreen client connected (--dev-mod), the block set from the server's console:

client:
TESTHOOK standalone_models asked: ["lanef:block/shaft_half", "lanef:block/absent", "nonamespace"]
Horizon: standalone model lanef:block/absent not loaded: No such file or directory (os error 2)
TESTHOOK submit lanef:machine at [0, 119, 5]: shaft_half drawn=true absent drawn=false light=0xf0
server:
TESTHOOK standalone_models asked: ["lanef:block/shaft_half", "lanef:block/absent", "nonamespace"]
[Server thread/INFO]: System chat: Changed the block at 0, 119, 5

The client's screenshot shows the same post. The server asked the hook but baked nothing (no warning there).

Not run: drawing a standalone model from native_mob_submit. It takes the same BlockEntityDraw, so it goes through the same code.

Unit tests:

  • models::catalog::tests::standalone_models_bake_once_and_skip_what_does_not_read: a model and its child bake with their own textures. A model with a missing parent and an absent one are left out. A name given twice bakes once. The same works without a parsed library.
  • a_standalone_model_a_state_bakes_unturned_is_shared.
  • models::tests::standalone_names_are_namespaced_sorted_and_set_once.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at ff8e46848, 2 min 24 s)

Check Result
Scope ✅ 8 files, +310 −30
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 594 passed (33 s)
rustfmt ✅ (6 s)
clippy ✅ (56 s)
tests: horizon-client, horizon-client-render ❌ 556 passed, 2 failed (46 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)
  • The two TNT failures (game::tnt::tests::primed_tnt_follows_water_currents_after_moving, a_soul_sand_bubble_column_lifts_primed_tnt) also fail on hr/main ff8e46848 in the same worktree when the vanilla data is present. I checked. Because they failed first, cargo stopped before horizon-client-render's tests. I ran those on their own: cargo test -p horizon-client-render --lib, 917 passed, 0 failed.

🤖 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/6360 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/standalone-models` --- ### 📝 Commits (2) - [`7a9f20a`](https://github.com/horizon-rust/horizon/commit/7a9f20a33fda80a8a732a0ab3025e6772ecc9456) Native mods: models no blockstate names, ModelEvent.RegisterStandalone - [`ceb9787`](https://github.com/horizon-rust/horizon/commit/ceb97871712cfb8939b29af0c2b0d231444da633) Merge remote-tracking branch 'hr/main' into mods/standalone-models ### 📊 Changes **8 files changed** (+318 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/models.rs` (+45 -1) 📝 `crates/horizon-client-render/src/models/catalog.rs` (+196 -26) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/minecarts.rs` (+15 -1) 📝 `crates/horizon-client/src/game/mods.rs` (+7 -0) 📝 `crates/horizon-client/src/game/native_block_entity_draw.rs` (+26 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+13 -0) ➕ `tools/native-hook-fragments/standalone_models.json` (+15 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Step 1 of #6303 (model changes at bake time, a design proposal), part of #4953 ("Model changes at bake time (`ModelEvent.ModifyBakingResult`, `ModelData`)"). It is also the third part of #5551 ("models no blockstate names"), and what the instanced-drawing proposal (#6302) draws. #6303 stays open for its other steps. A block entity draws parts that aren't blocks: a shaft half, a cog, a press head, a gauge needle. NeoForge mods register them as standalone models (`ModelEvent.RegisterStandalone`). Until now a Horizon mod had to register a block that is never placed, only so its model got baked, and draw that block (`native_draw_block`'s doc said so). One client hook point and one helper, API from a fragment (`tools/native-hook-fragments/standalone_models.json`): - `native_standalone_models(models: &mut Vec<String>)` (`ModelEvent.RegisterStandalone`): static, asked once at start before the resources load (beside `native_component_types`). The ids it gets are kept for the run, sorted, deduplicated, and those without a namespace dropped (`horizon_client::models::register_standalone`). - Every resource load, a pack reload included, bakes them beside the block models (`StateModels::bake_standalone`, after `from_facts_with_models`), from that pack's files, unturned. One a block state already bakes unturned is shared, not baked twice. One that doesn't read (missing, or a missing parent) is logged and left out, as a blockstate that doesn't read is. A dedicated server bakes nothing, as before. - `native_draw_model(draw, model, tint)` draws one under a `BlockEntityDraw`'s pose, in `native_block_entity_submit` or `native_mob_submit`, as `native_draw_block` draws a block's model: lit by `draw.light`, with the 0xRRGGBB `tint` on its tinted faces. It returns false for a model that isn't baked. Its vertex loop is `tinted_block_model_vertices`'s, split out as `baked_model_vertices` (no change for its callers). ## Kind - [x] feature: something new for players (mod authors) ## Vanilla reference Vanilla 26.3's `ModelManager.reload` discovers models (`ModelDiscovery`) and bakes them (`ModelBakery.bakeModels`). NeoForge's `ModelEvent.RegisterStandalone` is posted when discovery collects its top models: a mod registers a `StandaloneModelKey` with its unbaked model, and it is baked with the rest on every reload. Horizon bakes in `StateModels::from_facts_with_models` on the start-up thread and on the pack reload worker, so the extra models bake there. The hook is asked once rather than on each discovery: a static hook has no reload to answer from, and the list is the mod's own. ## Other projects' code None. NeoForge's names and javadoc only. ## Proof in the real game The branch is rebased on hr/main ff8e46848 (after #5446). The server-thread run below was repeated at that head with the same output; the dedicated-server run was at the first head, on dea6dea98. Engine from this branch with throwaway lines in the hook bodies (not in this PR). A dev content mod `lanef` declared `lanef:machine` (template `minecraft:glass`, its blockstate pointing at glass's model) and shipped `assets/lanef/models/block/shaft_half.json`, which no blockstate names: a 6×16×6 post, gold sides, diamond ends. The probe: - pushed `lanef:block/shaft_half`, `lanef:block/absent` (no file) and `nonamespace` in `native_standalone_models`; - gave `lanef:machine` a block entity in `native_block_entity`; - in `native_block_entity_submit`, translated up one block, turned 4° a tick about Y, and called `native_draw_model` for both models. Server thread (`horizon-ctl launch --world L --creative --offscreen --dev-mod …`, `/setblock 0 119 5 lanef:machine`, then F3+T): ``` TESTHOOK standalone_models asked: ["lanef:block/shaft_half", "lanef:block/absent", "nonamespace"] Horizon: standalone model lanef:block/absent not loaded: No such file or directory (os error 2) Horizon: resources loaded in 1.8s; 35724 block states, 1659 items, 67 biomes; 11 worker threads TESTHOOK submit lanef:machine at [0, 119, 5]: shaft_half drawn=true absent drawn=false light=0xf0 Horizon: standalone model lanef:block/absent not loaded: No such file or directory (os error 2) ``` The second warning is the F3+T reload baking the list again. The hook was asked once. Screenshots before and after the reload show the gold post standing on the glass block, turned between frames. Dedicated server (port 25760, the mod in its `horizon-mods/` and on in `horizon-mods.txt`) with an offscreen client connected (`--dev-mod`), the block set from the server's console: ``` client: TESTHOOK standalone_models asked: ["lanef:block/shaft_half", "lanef:block/absent", "nonamespace"] Horizon: standalone model lanef:block/absent not loaded: No such file or directory (os error 2) TESTHOOK submit lanef:machine at [0, 119, 5]: shaft_half drawn=true absent drawn=false light=0xf0 server: TESTHOOK standalone_models asked: ["lanef:block/shaft_half", "lanef:block/absent", "nonamespace"] [Server thread/INFO]: System chat: Changed the block at 0, 119, 5 ``` The client's screenshot shows the same post. The server asked the hook but baked nothing (no warning there). Not run: drawing a standalone model from `native_mob_submit`. It takes the same `BlockEntityDraw`, so it goes through the same code. Unit tests: - `models::catalog::tests::standalone_models_bake_once_and_skip_what_does_not_read`: a model and its child bake with their own textures. A model with a missing parent and an absent one are left out. A name given twice bakes once. The same works without a parsed library. - `a_standalone_model_a_state_bakes_unturned_is_shared`. - `models::tests::standalone_names_are_namespaced_sorted_and_set_once`. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at ff8e46848, 2 min 24 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +310 −30 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 594 passed (33 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (56 s) | | tests: horizon-client, horizon-client-render | ❌ 556 passed, 2 failed (46 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | - **The two TNT failures** (`game::tnt::tests::primed_tnt_follows_water_currents_after_moving`, `a_soul_sand_bubble_column_lifts_primed_tnt`) also fail on hr/main ff8e46848 in the same worktree when the vanilla data is present. I checked. Because they failed first, cargo stopped before horizon-client-render's tests. I ran those on their own: `cargo test -p horizon-client-render --lib`, 917 passed, 0 failed. 🤖 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 06:27:35 +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#6825
No description provided.