[GH-ISSUE #6303] Native mods: model changes at bake time, ModelEvent.RegisterStandalone / ModifyBakingResult / ModelData (design proposal) #2049

Open
opened 2026-11-02 15:51:37 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @levzzz5154 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6303

Originally assigned to: @levzzz5154 on GitHub.

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

Part of #4953 ("Model changes at bake time (ModelEvent.ModifyBakingResult, ModelData)").

A design proposal: the options, a recommendation, and the steps as small PRs. Step 1 (models no blockstate names, ModelEvent.RegisterStandalone) is self-contained and I claim it; it is also the third part of #5551 and what instanced drawing (#6302) is made of. Steps 2 and 3 need the decisions at the end.

The problem

Mods change models in code in three ways that Horizon has no route for:

  1. Models no blockstate names. A block entity draws parts that aren't a block: a shaft half, a cog, a press head, a gauge needle. NeoForge mods register them as standalone models (ModelEvent.RegisterStandalone). On Horizon, a mod registers a block that is never placed, only so that its model is baked, and draws that block (native_draw_block's doc says so).
  2. Changing baked models. Connected or emissive textures, a model wrapped with extra quads, every state of a block swapped for a generated one: ModelEvent.ModifyBakingResult, after baking and before the models are used.
  3. Per-position model data. A facade or a cover showing another block's model, a pipe's connections kept in its block entity rather than its state, a framed block: the chunk mesh depends on block-entity data. NeoForge: BlockEntity.getModelData(), requestModelDataUpdate(), and BlockStateModel.collectParts(level, pos, state, random, parts) reading level.getModelData(pos) on the meshing thread.

How Horizon bakes today

  • Decode (crates/horizon-assets): blockstates (blockstate.rs, bind.rs), models (model.rs, resolve.rs's ModelLibrary), quads (bake.rs: ModelQuad, bake_block_model). Items: item_bake.rs, baked lazily by ItemRenderer.
  • Bake (crates/horizon-client-render/src/models/catalog.rs): StateModels::from_facts_with_models binds each block's states to variants, builds a library of only the models those variants reach (ParsedModels::block_library), and bakes each distinct (model, rotations, uv_lock) once into a BakedModel (faces with an atlas layer, opaque/translucent flags). States point at baked variants; the weighted pick is made per position at lookup (models_at).
  • When: at start (load_core, on a start-up thread) and on a resource-pack reload (stage_pack on the PackReload worker; apply_staged_pack swaps it in on the render thread and remeshes everything). native_client_resources_reloaded (#5806) hears the swap.
  • Meshing: worker threads (streaming.rs) with a 3×3 chunk snapshot: state ids, light, biomes. No block entities, no mod state.
  • Mods: content blocks' models are ordinary blockstate and model files in the shared pipeline (#5422). No hook touches models, quads or the mesher.

Vanilla and NeoForge 26.3

  • Vanilla ModelManager.reload discovers models (ModelDiscovery), bakes them (ModelBakery.bakeModels → BakingResult(missingModels, blockStateModels, itemStackModels, itemProperties)), then hands them to the block model set.
  • NeoForge: ModelEvent.RegisterStandalone (a StandaloneModelKey and its unbaked model, baked with the rest), ModelEvent.ModifyBakingResult (the BakingResult, the material baker and the atlases' preparations; fired on a worker thread; only the bakery's data may be touched), ModelEvent.BakingCompleted (read-only, after the models are in use), ModelEvent.RegisterLoaders. ModelData is an immutable map of ModelProperty values a block entity returns; "MUST BE IMMUTABLE OR THREAD-SAFE", read on another thread.

Options

Standalone models (step 1). One shape is natural: a static collect hook, native_standalone_models(models: &mut Vec<String>), as native_component_types is, asked once at start; the models are baked beside the block models on every resource load; a drawing helper draws one by id. #5551 proposes naming them in a content file instead; that can come later and feed the same list.

Changing baked models (step 2).

  • A. A bake-time hook with a narrow view (recommended). native_modify_baking_result(result: &mut NativeBakingResult), asked on the reload thread after StateModels bakes and before the sprites are finished, so new sprite names can still be added. The view: the faces of a state's models or of a standalone model; replace them, add quads (ModelQuad with a sprite name), point a state at another baked model. Static (no Game): the reload thread has none.
  • B. Only files. A resource pack can already replace a model. It can't make generated quads.

Per-position model data (step 3).

  • A. Selection only (recommended first). On the game thread, a mod block entity answers native_block_entity_model_parts(pos, entity, parts) with a list of parts: a standalone model or a block state's model, each with a rotation. Horizon snapshots the lists into each section's mesh job and remeshes the section when native_request_model_data_update(pos) is called or the update tag changes. The mesher draws the parts with ordinary culling, AO and light. No mod code on the mesher threads.
  • B. A mesher-thread hook as NeoForge's collectParts: native_block_model_parts(state, pos, data, parts) on worker threads, with data the snapshot.
  • For A: covers facades, covers, framed blocks and pipes; the mesher stays fast and free of mod code; easy to keep stable. Against A: a model computed from data (a procedurally built mesh) has to be baked as standalone models first.
  • For B: anything. Against B: mod code on every worker thread, in the hottest path the client has; a panicking or slow mod stalls chunk meshing; the hook must be Send + Sync and allocation-free to be acceptable.

Recommendation

Standalone models now; step 2 as A; step 3 as A, with B added only for a mod that needs it.

Steps

  1. Standalone models (~250 lines). native_standalone_models(models: &mut Vec<String>), asked once at start; each named model is baked with the block models on every resource load (a model that doesn't read is left out, logged); native_draw_model(draw, model, tint) draws one under the pose of a block entity's or mob's draw, as native_draw_block draws a block. Docs, a fragment, unit tests. Claimed here.
  2. native_modify_baking_result (option A above).
  3. Model parts from block-entity data (option A above), with native_request_model_data_update.
  4. Model loaders (ModelEvent.RegisterLoaders): #5551's neoforge:obj and neoforge:composite, there.

Decisions needed

  • Step 2's view type, and that it runs on the reload thread (maintainers: Ludovic; #6216's author for how a static hook appears in the typed API).
  • Step 3: selection only (A) or a mesher-thread hook (B).
Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6303 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. Part of #4953 ("Model changes at bake time (`ModelEvent.ModifyBakingResult`, `ModelData`)"). A design proposal: the options, a recommendation, and the steps as small PRs. Step 1 (models no blockstate names, `ModelEvent.RegisterStandalone`) is self-contained and I claim it; it is also the third part of #5551 and what instanced drawing (#6302) is made of. Steps 2 and 3 need the decisions at the end. ## The problem Mods change models in code in three ways that Horizon has no route for: 1. **Models no blockstate names.** A block entity draws parts that aren't a block: a shaft half, a cog, a press head, a gauge needle. NeoForge mods register them as standalone models (`ModelEvent.RegisterStandalone`). On Horizon, a mod registers a block that is never placed, only so that its model is baked, and draws that block (`native_draw_block`'s doc says so). 2. **Changing baked models.** Connected or emissive textures, a model wrapped with extra quads, every state of a block swapped for a generated one: `ModelEvent.ModifyBakingResult`, after baking and before the models are used. 3. **Per-position model data.** A facade or a cover showing another block's model, a pipe's connections kept in its block entity rather than its state, a framed block: the chunk mesh depends on block-entity data. NeoForge: `BlockEntity.getModelData()`, `requestModelDataUpdate()`, and `BlockStateModel.collectParts(level, pos, state, random, parts)` reading `level.getModelData(pos)` on the meshing thread. ## How Horizon bakes today - **Decode** (crates/horizon-assets): blockstates (`blockstate.rs`, `bind.rs`), models (`model.rs`, `resolve.rs`'s `ModelLibrary`), quads (`bake.rs`: `ModelQuad`, `bake_block_model`). Items: `item_bake.rs`, baked lazily by `ItemRenderer`. - **Bake** (crates/horizon-client-render/src/models/catalog.rs): `StateModels::from_facts_with_models` binds each block's states to variants, builds a library of only the models those variants reach (`ParsedModels::block_library`), and bakes each distinct `(model, rotations, uv_lock)` once into a `BakedModel` (faces with an atlas layer, opaque/translucent flags). States point at baked variants; the weighted pick is made per position at lookup (`models_at`). - **When:** at start (`load_core`, on a start-up thread) and on a resource-pack reload (`stage_pack` on the `PackReload` worker; `apply_staged_pack` swaps it in on the render thread and remeshes everything). `native_client_resources_reloaded` (#5806) hears the swap. - **Meshing:** worker threads (`streaming.rs`) with a 3×3 chunk snapshot: state ids, light, biomes. No block entities, no mod state. - **Mods:** content blocks' models are ordinary blockstate and model files in the shared pipeline (#5422). No hook touches models, quads or the mesher. ## Vanilla and NeoForge 26.3 - Vanilla `ModelManager.reload` discovers models (`ModelDiscovery`), bakes them (`ModelBakery.bakeModels` → `BakingResult(missingModels, blockStateModels, itemStackModels, itemProperties)`), then hands them to the block model set. - NeoForge: `ModelEvent.RegisterStandalone` (a `StandaloneModelKey` and its unbaked model, baked with the rest), `ModelEvent.ModifyBakingResult` (the `BakingResult`, the material baker and the atlases' preparations; fired on a worker thread; only the bakery's data may be touched), `ModelEvent.BakingCompleted` (read-only, after the models are in use), `ModelEvent.RegisterLoaders`. `ModelData` is an immutable map of `ModelProperty` values a block entity returns; "MUST BE IMMUTABLE OR THREAD-SAFE", read on another thread. ## Options **Standalone models (step 1).** One shape is natural: a static collect hook, `native_standalone_models(models: &mut Vec<String>)`, as `native_component_types` is, asked once at start; the models are baked beside the block models on every resource load; a drawing helper draws one by id. #5551 proposes naming them in a content file instead; that can come later and feed the same list. **Changing baked models (step 2).** - **A. A bake-time hook with a narrow view (recommended).** `native_modify_baking_result(result: &mut NativeBakingResult)`, asked on the reload thread after `StateModels` bakes and before the sprites are finished, so new sprite names can still be added. The view: the faces of a state's models or of a standalone model; replace them, add quads (`ModelQuad` with a sprite name), point a state at another baked model. Static (no `Game`): the reload thread has none. - **B. Only files.** A resource pack can already replace a model. It can't make generated quads. **Per-position model data (step 3).** - **A. Selection only (recommended first).** On the game thread, a mod block entity answers `native_block_entity_model_parts(pos, entity, parts)` with a list of parts: a standalone model or a block state's model, each with a rotation. Horizon snapshots the lists into each section's mesh job and remeshes the section when `native_request_model_data_update(pos)` is called or the update tag changes. The mesher draws the parts with ordinary culling, AO and light. No mod code on the mesher threads. - **B. A mesher-thread hook** as NeoForge's `collectParts`: `native_block_model_parts(state, pos, data, parts)` on worker threads, with `data` the snapshot. - For A: covers facades, covers, framed blocks and pipes; the mesher stays fast and free of mod code; easy to keep stable. Against A: a model computed from data (a procedurally built mesh) has to be baked as standalone models first. - For B: anything. Against B: mod code on every worker thread, in the hottest path the client has; a panicking or slow mod stalls chunk meshing; the hook must be `Send + Sync` and allocation-free to be acceptable. ## Recommendation Standalone models now; step 2 as A; step 3 as A, with B added only for a mod that needs it. ## Steps 1. **Standalone models** (~250 lines). `native_standalone_models(models: &mut Vec<String>)`, asked once at start; each named model is baked with the block models on every resource load (a model that doesn't read is left out, logged); `native_draw_model(draw, model, tint)` draws one under the pose of a block entity's or mob's draw, as `native_draw_block` draws a block. Docs, a fragment, unit tests. Claimed here. 2. **`native_modify_baking_result`** (option A above). 3. **Model parts from block-entity data** (option A above), with `native_request_model_data_update`. 4. **Model loaders** (`ModelEvent.RegisterLoaders`): #5551's `neoforge:obj` and `neoforge:composite`, there. ## Decisions needed - Step 2's view type, and that it runs on the reload thread (maintainers: Ludovic; #6216's author for how a static hook appears in the typed API). - Step 3: selection only (A) or a mesher-thread hook (B).
Author
Owner

@levzzz5154 commented on GitHub (Nov 1, 2026):

/claim

<!-- gh-comment-id:6562428525 --> @levzzz5154 commented on GitHub (Nov 1, 2026): /claim
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#2049
No description provided.