[PR #6264] [MERGED] Item models: bake with swapped textures, over a library with extra models #6754

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6264
Author: @some-du6e
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: optifine/cit-overlay


📝 Commits (10+)

  • f4a28f2 OptiFine CIT: item rules' textures reach the atlas
  • 6f0f1da Item models: bake a model with its textures swapped, over a library with extra models
  • efbf434 Merge remote-tracking branch 'origin/main' into optifine/cit-atlas
  • 5b4391f Merge branch 'optifine/cit-atlas' into optifine/cit-overlay
  • df33374 OptiFine CIT: CIT ids stay in the root and out of the disk cache; textures decode in parallel and huge ones are refused unread
  • 91a8946 OptiFine CIT: too many CIT textures leave them out, not the packs; refused ids read nothing; strips bounded by size
  • 30a809f Item models: the built-in generated model stays; tests that check bakes by hand
  • 0a59f3e Merge branch 'optifine/cit-atlas' into optifine/cit-overlay
  • 5060a5b OptiFine CIT: Horizon's own sprites and the layout stay theirs; item mipmaps and PBR maps for CIT textures
  • 078c434 Item models: the built-ins test checks the built-ins

📊 Changes

8 files changed (+985 additions, -28 deletions)

View changed files

📝 crates/horizon-assets/src/item_bake.rs (+95 -2)
📝 crates/horizon-assets/src/resolve.rs (+236 -0)
📝 crates/horizon-client-render/src/atlas_sources.rs (+18 -2)
➕ crates/horizon-client-render/src/cit_assets.rs (+164 -0)
📝 crates/horizon-client-render/src/hud.rs (+348 -1)
📝 crates/horizon-client-render/src/lib.rs (+1 -0)
📝 crates/horizon-client-render/src/sprites.rs (+112 -12)
📝 crates/horizon-client/src/client_lib.rs (+11 -11)

📄 Description

OptiFine Custom Item Textures rules can swap an item's model for one the pack ships (model=), or keep the model and swap only its textures (texture=, texture.layer1=, texture.potion_overlay=...). Horizon's item model library is built once from assets/*/models/ and is immutable, and baking resolves a model only by name, so neither swap was possible. This PR adds the two pieces the item renderer needs for them, in horizon-assets. Players see no change until the next PR uses them.

This PR builds on #6232 (the CIT atlas). GitHub shows that PR's commits here too. This PR's own changes are crates/horizon-assets/src/resolve.rs and item_bake.rs.

What it adds:

  • ModelLibrary::overlaid(extra): returns this library plus extra models. An extra model replaces a model of the same name, but not the built-in builtin/missing and builtin/generated (as in from_models and with_item_generator). Every existing model is shared (the Arcs are cloned, not the models), so the block mesher's library stays as it is.
  • ModelLibrary::resolve_with_textures(name, child): resolves name as if a child model with only textures sat in front of it. The child's slots win, and #references bind through them, so builtin/generated's particle: #layer0 follows a replaced layer0. A cyclic chain is an error, as for resolve; callers fall back to the missing model themselves. The old resolve body became a private resolve_chain that both call; resolve behaves exactly as before.
  • bake_resolved(model, sprites): bake_item_model's body after resolve. bake_item_model keeps its signature and output, and now calls resolve then bake_resolved.

Tests (synthetic JSON models, hand-computed answers):

  • A child {layer0: horizon_cit:…} over a generated stick resolves layer0 and particle to the CIT sprite and keeps the parent's ground transform (translation [0,2,0] → [0,0.125,0]). Plain resolve still gives item/stick.
  • Child slots join reference chains both ways: a base layer0: #tex follows the child's tex, and a child particle: #layer1 follows the base's layer1. A child slot referring to itself ends unresolved instead of looping. An absent base gives the missing cube; a cyclic one gives an error.
  • An overlaid horizon_cit model whose parent is item/handheld inherits the right-hand rotation [0,-90,55]. A replaced item/stick changes only in the overlay, and an untouched model is the same Arc in both libraries.
  • An overlay that replaces a parent (item/handheld) changes the base's children (item/sword) in the overlay only. Replacements of the two built-ins are ignored, and two spellings of one id are refused.
  • By name: a stick bakes to 10 quads, a slab with an unknown sprite to the missing sprite, and a cyclic chain to the 6-quad missing cube.
  • A replaced layer0 extrudes the CIT sprite's own mask (1 opaque pixel → 6 quads), not the stick's.

Docs used: CIT Resewn's wiki (citresewn.shcm.io, CIT Item: model replaces the model, texture with model replaces every texture in it, texture.<sub> a layer) and the vanilla model format (minecraft.wiki "Model"). No mod code was read for this PR.

Checks:

Note

Filed by Opus 5.5 using 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/6264 **Author:** [@some-du6e](https://github.com/some-du6e) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `optifine/cit-overlay` --- ### 📝 Commits (10+) - [`f4a28f2`](https://github.com/horizon-rust/horizon/commit/f4a28f2bd454e11363403bb96b14bb65ab2666c8) OptiFine CIT: item rules' textures reach the atlas - [`6f0f1da`](https://github.com/horizon-rust/horizon/commit/6f0f1da64ed8962d7b2e0edf1d6815084d8cba01) Item models: bake a model with its textures swapped, over a library with extra models - [`efbf434`](https://github.com/horizon-rust/horizon/commit/efbf43422ea0c91e797dda96f4bec97dcdf1cce5) Merge remote-tracking branch 'origin/main' into optifine/cit-atlas - [`5b4391f`](https://github.com/horizon-rust/horizon/commit/5b4391fce39bc06ff47fdd79a2c572774255c2d2) Merge branch 'optifine/cit-atlas' into optifine/cit-overlay - [`df33374`](https://github.com/horizon-rust/horizon/commit/df333744c687d12960e953396648944df8fc3b17) OptiFine CIT: CIT ids stay in the root and out of the disk cache; textures decode in parallel and huge ones are refused unread - [`91a8946`](https://github.com/horizon-rust/horizon/commit/91a89466d978435dc632f89fd95067ac072df81f) OptiFine CIT: too many CIT textures leave them out, not the packs; refused ids read nothing; strips bounded by size - [`30a809f`](https://github.com/horizon-rust/horizon/commit/30a809f2671af91ec849e8a946b294a37236c77d) Item models: the built-in generated model stays; tests that check bakes by hand - [`0a59f3e`](https://github.com/horizon-rust/horizon/commit/0a59f3e04c46f8afa68e5f2929df3453437676dc) Merge branch 'optifine/cit-atlas' into optifine/cit-overlay - [`5060a5b`](https://github.com/horizon-rust/horizon/commit/5060a5bee35cba27d103f8f0da91ef3239dc6db5) OptiFine CIT: Horizon's own sprites and the layout stay theirs; item mipmaps and PBR maps for CIT textures - [`078c434`](https://github.com/horizon-rust/horizon/commit/078c43479b73d9b0e5adc1c5c91b3767d21629ef) Item models: the built-ins test checks the built-ins ### 📊 Changes **8 files changed** (+985 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-assets/src/item_bake.rs` (+95 -2) 📝 `crates/horizon-assets/src/resolve.rs` (+236 -0) 📝 `crates/horizon-client-render/src/atlas_sources.rs` (+18 -2) ➕ `crates/horizon-client-render/src/cit_assets.rs` (+164 -0) 📝 `crates/horizon-client-render/src/hud.rs` (+348 -1) 📝 `crates/horizon-client-render/src/lib.rs` (+1 -0) 📝 `crates/horizon-client-render/src/sprites.rs` (+112 -12) 📝 `crates/horizon-client/src/client_lib.rs` (+11 -11) </details> ### 📄 Description OptiFine Custom Item Textures rules can swap an item's model for one the pack ships (`model=`), or keep the model and swap only its textures (`texture=`, `texture.layer1=`, `texture.potion_overlay=`...). Horizon's item model library is built once from `assets/*/models/` and is immutable, and baking resolves a model only by name, so neither swap was possible. This PR adds the two pieces the item renderer needs for them, in `horizon-assets`. Players see no change until the next PR uses them. **This PR builds on #6232** (the CIT atlas). GitHub shows that PR's commits here too. This PR's own changes are `crates/horizon-assets/src/resolve.rs` and `item_bake.rs`. What it adds: - **`ModelLibrary::overlaid(extra)`:** returns this library plus extra models. An extra model replaces a model of the same name, but not the built-in `builtin/missing` and `builtin/generated` (as in `from_models` and `with_item_generator`). Every existing model is shared (the `Arc`s are cloned, not the models), so the block mesher's library stays as it is. - **`ModelLibrary::resolve_with_textures(name, child)`:** resolves `name` as if a child model with only `textures` sat in front of it. The child's slots win, and `#references` bind through them, so `builtin/generated`'s `particle: #layer0` follows a replaced `layer0`. A cyclic chain is an error, as for `resolve`; callers fall back to the missing model themselves. The old `resolve` body became a private `resolve_chain` that both call; `resolve` behaves exactly as before. - **`bake_resolved(model, sprites)`:** `bake_item_model`'s body after `resolve`. `bake_item_model` keeps its signature and output, and now calls `resolve` then `bake_resolved`. **Tests** (synthetic JSON models, hand-computed answers): - A child `{layer0: horizon_cit:…}` over a generated stick resolves `layer0` and `particle` to the CIT sprite and keeps the parent's ground transform (translation `[0,2,0]` → `[0,0.125,0]`). Plain `resolve` still gives `item/stick`. - Child slots join reference chains both ways: a base `layer0: #tex` follows the child's `tex`, and a child `particle: #layer1` follows the base's `layer1`. A child slot referring to itself ends unresolved instead of looping. An absent base gives the missing cube; a cyclic one gives an error. - An overlaid `horizon_cit` model whose parent is `item/handheld` inherits the right-hand rotation `[0,-90,55]`. A replaced `item/stick` changes only in the overlay, and an untouched model is the same `Arc` in both libraries. - An overlay that replaces a parent (`item/handheld`) changes the base's children (`item/sword`) in the overlay only. Replacements of the two built-ins are ignored, and two spellings of one id are refused. - By name: a stick bakes to 10 quads, a slab with an unknown sprite to the missing sprite, and a cyclic chain to the 6-quad missing cube. - A replaced `layer0` extrudes the CIT sprite's own mask (1 opaque pixel → 6 quads), not the stick's. **Docs used:** CIT Resewn's wiki (citresewn.shcm.io, CIT Item: `model` replaces the model, `texture` with `model` replaces every texture in it, `texture.<sub>` a layer) and the vanilla model format (minecraft.wiki "Model"). No mod code was read for this PR. **Checks:** - `cargo fmt` - `cargo test -p horizon-assets --lib -- resolve:: item_bake::` locally (8 passed; horizon-assets is small) - Fork CI (`verify`: workspace clippy `-D warnings` and every test) passed before the review fixes: https://github.com/some-du6e/horizon/actions/runs/41335671509. On the current head: https://github.com/some-du6e/horizon/actions/runs/41339855300 - The live game test was skipped: nothing calls these yet, and there is no vanilla data (`.local/`) here. > [!NOTE] > Filed by Opus 5.5 using 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:26:09 +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#6754
No description provided.