[PR #6232] [CLOSED] OptiFine CIT: the item rules' textures reach the atlas #6733

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6232
Author: @some-du6e
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: optifine/cit-atlas


📝 Commits (9)

  • f4a28f2 OptiFine CIT: item rules' textures reach the atlas
  • efbf434 Merge remote-tracking branch 'origin/main' into optifine/cit-atlas
  • 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
  • 5060a5b OptiFine CIT: Horizon's own sprites and the layout stay theirs; item mipmaps and PBR maps for CIT textures
  • 0f49685 OptiFine CIT: textures past what the atlas holds are left out before decoding; mipmap test; layout doc in place
  • f345299 OptiFine CIT: the texture budget charges a packed frame, skips refused files, and keeps going past one that doesn't fit
  • 3bd2683 OptiFine CIT: still CIT textures are packed whole, not cut to a square
  • 6984048 Merge remote-tracking branch 'origin/main' into s6232

📊 Changes

6 files changed (+654 additions, -26 deletions)

View changed files

📝 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

Since #5749, Horizon knows which Custom Item Textures rule each stack matches, but the textures those rules name can't be drawn. They live under optifine/cit/ (or the pack's own folders), and the item atlas only packs assets/minecraft/textures/{item,block,...}. This PR packs them into the atlas so the next PR (the item swap) has something to draw. Players see no change yet: nothing asks for these sprites until that PR.

What it does:

  • cit_assets.rs (new): gives CIT files ids in a reserved horizon_cit namespace.
    • Ids are built from the resource path: assets/minecraft/optifine/cit/swords/flame.png → horizon_cit:minecraft/optifine/cit/swords/flame. They can't collide with a vanilla or mod sprite, since those always map to assets/<ns>/textures/....
    • A rule texture that already sits under textures/ keeps its normal id (minecraft:item/x), so nothing is packed twice.
    • Paths that aren't valid identifiers (uppercase letters, spaces) are refused with a warning, as CIT Resewn refuses them. So is a pack's own assets/horizon_cit/ folder. A texture id whose path would leave the resource root (a pack model can write any) now names a file that isn't there, for every namespace, instead of one outside the root.
    • model_id is here too, for the model PR that comes next, so both kinds of id live in one place.
  • atlas_sources::texture_path maps horizon_cit: ids back to their files. Sprites::decode goes through it too, so FileSprites (extrusion masks, translucency) and animated .png.mcmeta find CIT textures. horizon_cit: names skip the sprite disk cache, as insert_file's OptiFine files do, because its fingerprint only covers textures/.
  • HudAtlas::pack adds the textures of the enabled packs' item rules after the atlas definitions' sprites:
    • an animated strip keeps its first frame and registers its animation, like other item textures; a still texture is packed whole (it is not cut to a square, so 2:1 armour layers survive for the armour PR);
    • the 1024x512 limit that applies to every other texture applies to a CIT texture's frame; an image bigger than 64 such frames is refused from its PNG header, without decoding it;
    • if the CIT textures are more than the atlas can hold, they are left out with a warning, and the packs still load;
    • CIT textures can't take Horizon's own sprite names (horizon/white, the run-time slots);
    • in the world's sprite arrays they mipmap as item textures (tested), and pick up LabPBR _n/_s maps beside them (not tested: those maps are read only for a native shader pack);
    • textures decode on the same threads pack uses for the rest, since big CIT packs name thousands; and no more of them are decoded than the atlas could hold: each is charged, from its PNG header, the frame it can be packed as (512x512 at most), with room kept for the glyph rows; a file that would be refused anyway costs nothing, and one that doesn't fit leaves the rest in;
    • a texture that fails to decode is skipped with a warning.
  • Without CIT rules nothing is added: cit_sprites returns nothing. One test checks that removing the optifine folder gives the same sprite keys, minus the CIT one.

Tests (synthetic PNGs and rule files in a temp root; no Mojang files):

  • id round trips and refusals;
  • a 4x2 still texture packs whole;
  • a 2x2 CIT texture packs with the written colour;
  • a 16x48 animated strip packs at 16x16 with one 3-frame animation;
  • a texture named only by an armour rule is not packed (armour comes in a later PR);
  • texture.<name> textures are packed; a rule naming vanilla's own item/stick adds no second copy; a broken PNG and a 1040x1040 one are skipped while the atlas still builds;
  • Sprites::insert loads a horizon_cit: strip with its 3-frame animation, and a rewritten CIT texture is read again rather than served from the disk cache;
  • a grid animation 1104 wide packs its 16x16 frame; a 20000x20000 header sorted first leaves the next small texture in; the layout leaves CIT textures out when they don't fit, and fails as before when vanilla's alone don't;
  • the reserved namespace and ids that would leave the root are refused;
  • the no-CIT case above.

Stack: this is PR 3 of the CIT stack (after #5712 and #5749, both merged). Next come: baking with swapped textures over extra models (horizon-assets), then items drawing their CIT texture or model, then worn armour and elytra, then enchantment glints.

Docs used: CIT Resewn's wiki (citresewn.shcm.io, CIT Base "Asset Resolution", CIT Item) and OptiFine's cit_single.properties. 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/6232 **Author:** [@some-du6e](https://github.com/some-du6e) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `optifine/cit-atlas` --- ### 📝 Commits (9) - [`f4a28f2`](https://github.com/horizon-rust/horizon/commit/f4a28f2bd454e11363403bb96b14bb65ab2666c8) OptiFine CIT: item rules' textures reach the atlas - [`efbf434`](https://github.com/horizon-rust/horizon/commit/efbf43422ea0c91e797dda96f4bec97dcdf1cce5) Merge remote-tracking branch 'origin/main' into optifine/cit-atlas - [`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 - [`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 - [`0f49685`](https://github.com/horizon-rust/horizon/commit/0f49685690b7799d7336ff2e98ac045d1001a1f5) OptiFine CIT: textures past what the atlas holds are left out before decoding; mipmap test; layout doc in place - [`f345299`](https://github.com/horizon-rust/horizon/commit/f345299ba2006fd0cdae438b3067160853de92a1) OptiFine CIT: the texture budget charges a packed frame, skips refused files, and keeps going past one that doesn't fit - [`3bd2683`](https://github.com/horizon-rust/horizon/commit/3bd26833e1b14030b109ddca8a182d5f0f3b5802) OptiFine CIT: still CIT textures are packed whole, not cut to a square - [`6984048`](https://github.com/horizon-rust/horizon/commit/6984048ad303065543459749f6244038f262e90b) Merge remote-tracking branch 'origin/main' into s6232 ### 📊 Changes **6 files changed** (+654 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `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 Since #5749, Horizon knows which Custom Item Textures rule each stack matches, but the textures those rules name can't be drawn. They live under `optifine/cit/` (or the pack's own folders), and the item atlas only packs `assets/minecraft/textures/{item,block,...}`. This PR packs them into the atlas so the next PR (the item swap) has something to draw. Players see no change yet: nothing asks for these sprites until that PR. What it does: - **`cit_assets.rs` (new):** gives CIT files ids in a reserved `horizon_cit` namespace. - Ids are built from the resource path: `assets/minecraft/optifine/cit/swords/flame.png` → `horizon_cit:minecraft/optifine/cit/swords/flame`. They can't collide with a vanilla or mod sprite, since those always map to `assets/<ns>/textures/...`. - A rule texture that already sits under `textures/` keeps its normal id (`minecraft:item/x`), so nothing is packed twice. - Paths that aren't valid identifiers (uppercase letters, spaces) are refused with a warning, as CIT Resewn refuses them. So is a pack's own `assets/horizon_cit/` folder. A texture id whose path would leave the resource root (a pack model can write any) now names a file that isn't there, for every namespace, instead of one outside the root. - `model_id` is here too, for the model PR that comes next, so both kinds of id live in one place. - **`atlas_sources::texture_path`** maps `horizon_cit:` ids back to their files. `Sprites::decode` goes through it too, so `FileSprites` (extrusion masks, translucency) and animated `.png.mcmeta` find CIT textures. `horizon_cit:` names skip the sprite disk cache, as `insert_file`'s OptiFine files do, because its fingerprint only covers `textures/`. - **`HudAtlas::pack`** adds the textures of the enabled packs' item rules after the atlas definitions' sprites: - an animated strip keeps its first frame and registers its animation, like other item textures; a still texture is packed whole (it is not cut to a square, so 2:1 armour layers survive for the armour PR); - the 1024x512 limit that applies to every other texture applies to a CIT texture's frame; an image bigger than 64 such frames is refused from its PNG header, without decoding it; - if the CIT textures are more than the atlas can hold, they are left out with a warning, and the packs still load; - CIT textures can't take Horizon's own sprite names (`horizon/white`, the run-time slots); - in the world's sprite arrays they mipmap as item textures (tested), and pick up LabPBR `_n`/`_s` maps beside them (not tested: those maps are read only for a native shader pack); - textures decode on the same threads `pack` uses for the rest, since big CIT packs name thousands; and no more of them are decoded than the atlas could hold: each is charged, from its PNG header, the frame it can be packed as (512x512 at most), with room kept for the glyph rows; a file that would be refused anyway costs nothing, and one that doesn't fit leaves the rest in; - a texture that fails to decode is skipped with a warning. - **Without CIT rules nothing is added:** `cit_sprites` returns nothing. One test checks that removing the `optifine` folder gives the same sprite keys, minus the CIT one. **Tests** (synthetic PNGs and rule files in a temp root; no Mojang files): - id round trips and refusals; - a 4x2 still texture packs whole; - a 2x2 CIT texture packs with the written colour; - a 16x48 animated strip packs at 16x16 with one 3-frame animation; - a texture named only by an armour rule is not packed (armour comes in a later PR); - `texture.<name>` textures are packed; a rule naming vanilla's own `item/stick` adds no second copy; a broken PNG and a 1040x1040 one are skipped while the atlas still builds; - `Sprites::insert` loads a `horizon_cit:` strip with its 3-frame animation, and a rewritten CIT texture is read again rather than served from the disk cache; - a grid animation 1104 wide packs its 16x16 frame; a 20000x20000 header sorted first leaves the next small texture in; the layout leaves CIT textures out when they don't fit, and fails as before when vanilla's alone don't; - the reserved namespace and ids that would leave the root are refused; - the no-CIT case above. **Stack:** this is PR 3 of the CIT stack (after #5712 and #5749, both merged). Next come: baking with swapped textures over extra models (horizon-assets), then items drawing their CIT texture or model, then worn armour and elytra, then enchantment glints. **Docs used:** CIT Resewn's wiki (citresewn.shcm.io, CIT Base "Asset Resolution", CIT Item) and OptiFine's `cit_single.properties`. No mod code was read for this PR. **Checks:** - `cargo fmt` - Fork CI (`verify`: workspace clippy `-D warnings` and all tests) passed on this code before main was merged in: https://github.com/some-du6e/horizon/actions/runs/41274924066. The run on the current head: https://github.com/some-du6e/horizon/actions/runs/41341128216 - Nothing was built locally: the machine is shared. - The live game test was skipped: nothing draws these sprites 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:25:49 +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#6733
No description provided.