[PR #5749] [MERGED] OptiFine CIT: match stacks against the packs' rules #6474

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

📋 Pull Request Information

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

Base: main ← Head: optifine/cit-match


📝 Commits (10+)

  • a6fcdfa OptiFine CEM: custom entity models animate
  • 6049010 OptiFine random entities: read the rules that pick an entity's texture variant
  • f51a81b OptiFine packs: read connected-texture rules (optifine/ctm)
  • 68f749d OptiFine CIT: read the rules of optifine/cit and their component tests
  • 943b1c7 OptiFine CTM rules: bound tile ranges, reject bad names, read Latin-1
  • ffb010b OptiFine random entities: a rule with a bad or unsupported condition never matches
  • c76b2a2 OptiFine CTM rules: close the tile cap, refuse backslashes and bad heights
  • 9375dab OptiFine random entities: nbt list paths, seedSource and exact health percent
  • 4bef210 OptiFine CIT: bad ids and masks drop the rule, paths keep to the pack, and Resewn's lookups
  • 7a2b81f OptiFine CTM rules: one bound on tile ranges

📊 Changes

35 files changed (+6514 additions, -66 deletions)

View changed files

📝 Cargo.lock (+2 -0)
📝 THIRD_PARTY_NOTICES.md (+25 -0)
📝 crates/horizon-client-render/Cargo.toml (+3 -0)
📝 crates/horizon-client-render/src/assets.rs (+30 -2)
➕ crates/horizon-client-render/src/cit.rs (+662 -0)
➕ crates/horizon-client-render/src/connected.rs (+724 -0)
📝 crates/horizon-client-render/src/hud.rs (+37 -7)
📝 crates/horizon-client-render/src/lib.rs (+2 -0)
📝 crates/horizon-client-render/src/sprites.rs (+45 -2)
📝 crates/horizon-client/Cargo.toml (+1 -1)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/creatures.rs (+15 -0)
📝 crates/horizon-client/src/game/packs.rs (+11 -0)
📝 crates/horizon-client/src/game/perspective.rs (+1 -0)
➕ crates/horizon-client/src/game/random_textures.rs (+64 -0)
📝 crates/horizon-client/src/game/remote.rs (+1 -0)
📝 crates/horizon-client/src/lib.rs (+12 -11)
📝 crates/horizon-client/src/mobs.rs (+5 -0)
📝 crates/horizon-client/src/mobs/cem.rs (+26 -3)
➕ crates/horizon-client/src/mobs/cem_anim.rs (+534 -0)

...and 15 more files

📄 Description

Custom Item Textures rules (parsed in #5712) need to be checked against real stacks: "is this diamond sword named Excalibur, with Sharpness V, in the off hand?". This is the second PR of the CIT stack. It loads the enabled packs' rules and decides which rule each stack matches. Nothing draws with the result yet; the next PRs do. Players see no change.

This PR builds on #5712. GitHub shows that PR's commits here too. This PR's own commits are the last three ("load the enabled packs' rules" onwards).

What it adds, in horizon-client-render (cit.rs, re-exported as horizon_client::cit):

  • load_rules(root) reads every rule under optifine/cit/, mcpatcher/cit/ and CIT Resewn's citresewn/cit/ from the overlay resource root. It sorts them by priority (weight, then path) and skips the global cit.properties.
    • Files are read as CIT Resewn reads them (= first), and a file that is not UTF-8 is read as Latin-1, as Java's Properties does.
    • horizon-optifine gains properties_files_in(root, tops, feature) for the extra folder.
  • CitRules::select(kind, stack, hand, max_damage) returns the winning item, armour or elytra rule. CitRules::enchantments(stack, max_damage) returns every matching enchantment rule.
  • Cheap matching:
    • Rules are indexed by kind and item id. A stack whose item no rule names returns at once without allocating, which is nearly every stack.
    • Conditions are tested cheapest first: hand, count, damage (counted only for damageable items, as CIT Resewn does), enchantments from the crafting list (stored ones for books), then component tests.
    • Results are cached per stack. The key hashes the item, count, damage, hand, max damage and encoded components; the cache is cleared past 4096 entries. Tag derives Hash for that.
  • Component tests walk the stack's encoded components compound:
    • * matches any key or element, count is a list's length, and numbers index lists and arrays.
    • Strings, integers, floats, ranges, exists:, raw: and ! work as the OptiFine doc describes. A bare SNBT compound or list must be contained in the value, as Mojang's NbtUtils.compareNbt checks it.
    • Names and lore match by their plain text, so nbt.display.Name=Excalibur matches a styled name. A JSON text value ({"text":"Excalibur"}) compares as plain text, as CIT Resewn does.
    • Legacy nbt.Enchantments / StoredEnchantments see a {id, lvl} list built from the stack.
    • written_book_content.generation and fireworks.flight_duration read as 0 when the component leaves them out.

Docs used: OptiFine's cit_single.properties (github.com/sp614x/optifine OptiFineDoc/doc); CIT Resewn's wiki (citresewn.shcm.io, CIT Base); and CIT Resewn Continuation's MIT source at b792f9a (LICENSE checked), ConditionNBT / ConditionComponents / CITContext, for the component walk and the text-matching rules. No OptiFine code was read.

Checks:

  • cargo fmt
  • Fork CI (verify: workspace clippy -D warnings and every test) passed on this code with the atlas and model PRs on top: https://github.com/some-du6e/horizon/actions/runs/41274924066. A rerun with the last small commit is in progress.
  • Nothing was built locally: the machine is shared.
  • The live game test was skipped: this PR draws nothing, and there is no vanilla data (.local/) here.

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/5749 **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-match` --- ### 📝 Commits (10+) - [`a6fcdfa`](https://github.com/horizon-rust/horizon/commit/a6fcdfaf847d98155f5fe061bea740679c310ffc) OptiFine CEM: custom entity models animate - [`6049010`](https://github.com/horizon-rust/horizon/commit/6049010105be7fa6c51ab695529af56055699dcc) OptiFine random entities: read the rules that pick an entity's texture variant - [`f51a81b`](https://github.com/horizon-rust/horizon/commit/f51a81bbed5b82e1f62a9c3420baa316e4415447) OptiFine packs: read connected-texture rules (optifine/ctm) - [`68f749d`](https://github.com/horizon-rust/horizon/commit/68f749df47663bc321f7f0a88e246aacbfc23662) OptiFine CIT: read the rules of optifine/cit and their component tests - [`943b1c7`](https://github.com/horizon-rust/horizon/commit/943b1c7bc136e90a8d9e5c27813b4af23501617e) OptiFine CTM rules: bound tile ranges, reject bad names, read Latin-1 - [`ffb010b`](https://github.com/horizon-rust/horizon/commit/ffb010b543d40f072a95eb9a5e1f41945df4a60e) OptiFine random entities: a rule with a bad or unsupported condition never matches - [`c76b2a2`](https://github.com/horizon-rust/horizon/commit/c76b2a249a8ed398738c7f7001629fd88272f43c) OptiFine CTM rules: close the tile cap, refuse backslashes and bad heights - [`9375dab`](https://github.com/horizon-rust/horizon/commit/9375dab6328006ec380095908d58f5f4d9d09f11) OptiFine random entities: nbt list paths, seedSource and exact health percent - [`4bef210`](https://github.com/horizon-rust/horizon/commit/4bef210597ea6372427ef5b273613b7cef80a96a) OptiFine CIT: bad ids and masks drop the rule, paths keep to the pack, and Resewn's lookups - [`7a2b81f`](https://github.com/horizon-rust/horizon/commit/7a2b81f86f7f7fd1d9f810371df1991e191c097e) OptiFine CTM rules: one bound on tile ranges ### 📊 Changes **35 files changed** (+6514 additions, -66 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+2 -0) 📝 `THIRD_PARTY_NOTICES.md` (+25 -0) 📝 `crates/horizon-client-render/Cargo.toml` (+3 -0) 📝 `crates/horizon-client-render/src/assets.rs` (+30 -2) ➕ `crates/horizon-client-render/src/cit.rs` (+662 -0) ➕ `crates/horizon-client-render/src/connected.rs` (+724 -0) 📝 `crates/horizon-client-render/src/hud.rs` (+37 -7) 📝 `crates/horizon-client-render/src/lib.rs` (+2 -0) 📝 `crates/horizon-client-render/src/sprites.rs` (+45 -2) 📝 `crates/horizon-client/Cargo.toml` (+1 -1) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+15 -0) 📝 `crates/horizon-client/src/game/packs.rs` (+11 -0) 📝 `crates/horizon-client/src/game/perspective.rs` (+1 -0) ➕ `crates/horizon-client/src/game/random_textures.rs` (+64 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+1 -0) 📝 `crates/horizon-client/src/lib.rs` (+12 -11) 📝 `crates/horizon-client/src/mobs.rs` (+5 -0) 📝 `crates/horizon-client/src/mobs/cem.rs` (+26 -3) ➕ `crates/horizon-client/src/mobs/cem_anim.rs` (+534 -0) _...and 15 more files_ </details> ### 📄 Description Custom Item Textures rules (parsed in #5712) need to be checked against real stacks: "is this diamond sword named *Excalibur*, with Sharpness V, in the off hand?". This is the second PR of the CIT stack. It loads the enabled packs' rules and decides which rule each stack matches. Nothing draws with the result yet; the next PRs do. Players see no change. **This PR builds on #5712.** GitHub shows that PR's commits here too. This PR's own commits are the last three ("load the enabled packs' rules" onwards). What it adds, in `horizon-client-render` (`cit.rs`, re-exported as `horizon_client::cit`): - `load_rules(root)` reads every rule under `optifine/cit/`, `mcpatcher/cit/` and CIT Resewn's `citresewn/cit/` from the overlay resource root. It sorts them by priority (weight, then path) and skips the global `cit.properties`. - Files are read as CIT Resewn reads them (`=` first), and a file that is not UTF-8 is read as Latin-1, as Java's `Properties` does. - `horizon-optifine` gains `properties_files_in(root, tops, feature)` for the extra folder. - `CitRules::select(kind, stack, hand, max_damage)` returns the winning item, armour or elytra rule. `CitRules::enchantments(stack, max_damage)` returns every matching enchantment rule. - **Cheap matching:** - Rules are indexed by kind and item id. A stack whose item no rule names returns at once without allocating, which is nearly every stack. - Conditions are tested cheapest first: hand, count, damage (counted only for damageable items, as CIT Resewn does), enchantments from the crafting list (stored ones for books), then component tests. - Results are cached per stack. The key hashes the item, count, damage, hand, max damage and encoded components; the cache is cleared past 4096 entries. `Tag` derives `Hash` for that. - **Component tests** walk the stack's encoded `components` compound: - `*` matches any key or element, `count` is a list's length, and numbers index lists and arrays. - Strings, integers, floats, ranges, `exists:`, `raw:` and `!` work as the OptiFine doc describes. A bare SNBT compound or list must be contained in the value, as Mojang's `NbtUtils.compareNbt` checks it. - Names and lore match by their plain text, so `nbt.display.Name=Excalibur` matches a styled name. A JSON text value (`{"text":"Excalibur"}`) compares as plain text, as CIT Resewn does. - Legacy `nbt.Enchantments` / `StoredEnchantments` see a `{id, lvl}` list built from the stack. - `written_book_content.generation` and `fireworks.flight_duration` read as 0 when the component leaves them out. **Docs used:** OptiFine's `cit_single.properties` (github.com/sp614x/optifine `OptiFineDoc/doc`); CIT Resewn's wiki (citresewn.shcm.io, CIT Base); and CIT Resewn Continuation's MIT source at `b792f9a` (LICENSE checked), `ConditionNBT` / `ConditionComponents` / `CITContext`, for the component walk and the text-matching rules. No OptiFine code was read. **Checks:** - `cargo fmt` - Fork CI (`verify`: workspace clippy `-D warnings` and every test) passed on this code with the atlas and model PRs on top: https://github.com/some-du6e/horizon/actions/runs/41274924066. A rerun with the last small commit is in progress. - Nothing was built locally: the machine is shared. - The live game test was skipped: this PR draws nothing, 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:21:14 +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#6474
No description provided.