[PR #5716] [MERGED] OptiFine random entities: find each mob texture's variants and rules in the packs #6457

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

📋 Pull Request Information

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

Base: main ← Head: optifine/etf-pack


📝 Commits (10+)

  • a6fcdfa OptiFine CEM: custom entity models animate
  • 6049010 OptiFine random entities: read the rules that pick an entity's texture variant
  • ffb010b OptiFine random entities: a rule with a bad or unsupported condition never matches
  • 9375dab OptiFine random entities: nbt list paths, seedSource and exact health percent
  • a8a1d74 OptiFine random entities: biome patterns, and empty conditions skip the rule
  • 733c361 OptiFine random entities: a lone ! or an empty weights line, and one key scan
  • 2e80781 OptiFine random entities: the bad-condition test uses facts a dropped entry would pass
  • 90f5650 OptiFine random entities: a blocks rule fails when no blocks are known
  • 763a448 OptiFine random entities: say what empty Facts.blocks means
  • db3b3df OptiFine random entities: a file holds at most 1024 rules

📊 Changes

10 files changed (+1996 additions, -18 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+15 -0)
📝 crates/horizon-client/src/mobs.rs (+1 -0)
📝 crates/horizon-client/src/mobs/cem.rs (+26 -3)
➕ crates/horizon-client/src/mobs/cem_anim.rs (+534 -0)
📝 crates/horizon-client/src/mobs/render.rs (+9 -1)
📝 crates/horizon-optifine/src/lib.rs (+7 -2)
📝 crates/horizon-optifine/src/matchers.rs (+15 -8)
📝 crates/horizon-optifine/src/paths.rs (+34 -4)
➕ crates/horizon-optifine/src/random.rs (+792 -0)
➕ crates/horizon-optifine/src/random_textures.rs (+563 -0)

📄 Description

Random entity textures need to know, for each mob texture, which numbered variants a pack ships and which rules choose between them. #5710 reads the rules. This PR finds the files. Nothing in the game uses it yet, so players see no change. The next PR puts the variants in the entity atlas and draws them.

horizon_optifine::random_textures::RandomTextures::scan(root) walks the layered resource root once and keys every varied texture by the name the entity atlas uses (entity/zombie/zombie, mymod:entity/bug/bug):

  • Folders, first match wins per texture:

    1. ETF's etf/random/
    2. optifine/random/
    3. the legacy optifine/mob/, then mcpatcher/mob/ (these mirror textures/entity/)
    4. ETF's extra: beside the texture in textures/entity/. ETF doesn't require a .properties there, but Horizon only uses this folder for textures that have rules there (their own, or those of the name they extend), so a pack with no OptiFine files never changes a texture.

    Every namespace counts.

  • Variant names:

    • creeper2.png, creeper3.png...
    • a name ending in a digit uses a .: warden_pulsating_spots_2.3.png
    • <name>1.png, if present, replaces variant 1, the default (ETF)
    • indices run from 1 to 1024 with no leading zeros (creeper02.png is no variant); 0 is always the texture itself
    • a name ending in _ (spots_2.png) is no variant
  • Rules:

    • a texture's own <name>.properties
    • otherwise the one of the name it extends, cut at _ within the file name and looked up in the same folder: wolf_tame and wolf_angry use wolf.properties, spider_eyes uses spider.properties. That is the docs' "you do not need wolf_tame.properties".
    • a properties file is parsed once, however many textures share it. It is read as UTF-8, or as ISO-8859-1 (what Java's Properties.load reads) when it isn't valid UTF-8. A file over 64 KiB, or one that can't be read, holds no rules, so the texture keeps its default: parsing grows with the square of the size, and real ones are a few KB.
  • No rules: Entry::even(seed) picks evenly between the texture and its variants 2, 3... up to the first missing number. That's the docs' "if there are any gaps, textures after the gap are ignored".

  • Atlas names: each variant has the name the entity atlas will give it: its namespace and its path, minecraft:optifine/random/entity/creeper/creeper3. RandomTextures::files() lists each variant's file and name, so the next PR can pack exactly those into the atlas.

It also adds paths::files_under(root, dir, endings), the shared walker generalised from properties_files (same link-loop guard and depth cap).

Stacked on #5710; this branch includes its commits until it merges. Only random_textures.rs, paths.rs and lib.rs (the module line and its doc) are new here.

Docs I wrote it from (no mod source read):

  • OptiFine's OptiFineDoc/doc/random_entities.properties: folders, variant naming, the . separator, the shared properties of multi-texture mobs, the legacy mob/ folder
  • ETF's RANDOM_GUIDE.md and random_entities.properties: the etf/random and vanilla folders and their order, <name>1.png, the fallback of wolf_tame to wolf.properties, the gap rule

Checks:

  • cargo fmt: clean
  • cargo test -p horizon-optifine: 31 passed (9 of them new here). Temp packs with hand-made files check:
    • the variant names, <name>1.png, spots_2.2 versus spots_22
    • the gap rule (creeper2, 3, 5 gives an even choice of 1-3), and a rule naming a variant past a gap
    • inherited rules: wolf_tame, spider_eyes, a_b_c → a, never across a folder or into another source
    • folder priority across ETF, optifine/random, optifine/mob, mcpatcher/mob and a mod namespace
    • the texture's own folder only counting with rules, including inherited ones
    • a Latin-1 .properties file, and an oversized one
    • an empty pack giving nothing
  • clippy and the full tests run in CI on my fork. I didn't run them locally because the machine is shared.
  • No live game test: this machine has no .local/ vanilla data, and nothing in the game reads this code yet.

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/5716 **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/etf-pack` --- ### 📝 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 - [`ffb010b`](https://github.com/horizon-rust/horizon/commit/ffb010b543d40f072a95eb9a5e1f41945df4a60e) OptiFine random entities: a rule with a bad or unsupported condition never matches - [`9375dab`](https://github.com/horizon-rust/horizon/commit/9375dab6328006ec380095908d58f5f4d9d09f11) OptiFine random entities: nbt list paths, seedSource and exact health percent - [`a8a1d74`](https://github.com/horizon-rust/horizon/commit/a8a1d74d1573cbf91f91ad58abbf19ffe8ea08df) OptiFine random entities: biome patterns, and empty conditions skip the rule - [`733c361`](https://github.com/horizon-rust/horizon/commit/733c361874bba9c115347c847759786981dfb3fb) OptiFine random entities: a lone ! or an empty weights line, and one key scan - [`2e80781`](https://github.com/horizon-rust/horizon/commit/2e80781c76ef2e22149a46ec75e390b40bb13cec) OptiFine random entities: the bad-condition test uses facts a dropped entry would pass - [`90f5650`](https://github.com/horizon-rust/horizon/commit/90f565000793666ebc525c30c4d26e1be6e59f5e) OptiFine random entities: a blocks rule fails when no blocks are known - [`763a448`](https://github.com/horizon-rust/horizon/commit/763a4489850c8f4b4d81feb6c092278316658b4e) OptiFine random entities: say what empty Facts.blocks means - [`db3b3df`](https://github.com/horizon-rust/horizon/commit/db3b3dfb96e60897488885f8a3b04e2c10c33470) OptiFine random entities: a file holds at most 1024 rules ### 📊 Changes **10 files changed** (+1996 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+15 -0) 📝 `crates/horizon-client/src/mobs.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs/cem.rs` (+26 -3) ➕ `crates/horizon-client/src/mobs/cem_anim.rs` (+534 -0) 📝 `crates/horizon-client/src/mobs/render.rs` (+9 -1) 📝 `crates/horizon-optifine/src/lib.rs` (+7 -2) 📝 `crates/horizon-optifine/src/matchers.rs` (+15 -8) 📝 `crates/horizon-optifine/src/paths.rs` (+34 -4) ➕ `crates/horizon-optifine/src/random.rs` (+792 -0) ➕ `crates/horizon-optifine/src/random_textures.rs` (+563 -0) </details> ### 📄 Description Random entity textures need to know, for each mob texture, which numbered variants a pack ships and which rules choose between them. #5710 reads the rules. This PR finds the files. Nothing in the game uses it yet, so players see no change. The next PR puts the variants in the entity atlas and draws them. `horizon_optifine::random_textures::RandomTextures::scan(root)` walks the layered resource root once and keys every varied texture by the name the entity atlas uses (`entity/zombie/zombie`, `mymod:entity/bug/bug`): - **Folders, first match wins per texture:** 1. ETF's `etf/random/` 2. `optifine/random/` 3. the legacy `optifine/mob/`, then `mcpatcher/mob/` (these mirror `textures/entity/`) 4. ETF's extra: beside the texture in `textures/entity/`. ETF doesn't require a `.properties` there, but Horizon only uses this folder for textures that have rules there (their own, or those of the name they extend), so a pack with no OptiFine files never changes a texture. Every namespace counts. - **Variant names:** - `creeper2.png`, `creeper3.png`... - a name ending in a digit uses a `.`: `warden_pulsating_spots_2.3.png` - `<name>1.png`, if present, replaces variant 1, the default (ETF) - indices run from 1 to 1024 with no leading zeros (`creeper02.png` is no variant); 0 is always the texture itself - a name ending in `_` (`spots_2.png`) is no variant - **Rules:** - a texture's own `<name>.properties` - otherwise the one of the name it extends, cut at `_` within the file name and looked up in the same folder: `wolf_tame` and `wolf_angry` use `wolf.properties`, `spider_eyes` uses `spider.properties`. That is the docs' "you do not need wolf_tame.properties". - a properties file is parsed once, however many textures share it. It is read as UTF-8, or as ISO-8859-1 (what Java's `Properties.load` reads) when it isn't valid UTF-8. A file over 64 KiB, or one that can't be read, holds no rules, so the texture keeps its default: parsing grows with the square of the size, and real ones are a few KB. - **No rules:** `Entry::even(seed)` picks evenly between the texture and its variants 2, 3... up to the first missing number. That's the docs' "if there are any gaps, textures after the gap are ignored". - **Atlas names:** each variant has the name the entity atlas will give it: its namespace and its path, `minecraft:optifine/random/entity/creeper/creeper3`. `RandomTextures::files()` lists each variant's file and name, so the next PR can pack exactly those into the atlas. It also adds `paths::files_under(root, dir, endings)`, the shared walker generalised from `properties_files` (same link-loop guard and depth cap). Stacked on #5710; this branch includes its commits until it merges. Only `random_textures.rs`, `paths.rs` and `lib.rs` (the module line and its doc) are new here. **Docs I wrote it from** (no mod source read): - OptiFine's `OptiFineDoc/doc/random_entities.properties`: folders, variant naming, the `.` separator, the shared properties of multi-texture mobs, the legacy `mob/` folder - ETF's `RANDOM_GUIDE.md` and `random_entities.properties`: the `etf/random` and vanilla folders and their order, `<name>1.png`, the fallback of `wolf_tame` to `wolf.properties`, the gap rule **Checks:** - `cargo fmt`: clean - `cargo test -p horizon-optifine`: 31 passed (9 of them new here). Temp packs with hand-made files check: - the variant names, `<name>1.png`, `spots_2.2` versus `spots_22` - the gap rule (`creeper2, 3, 5` gives an even choice of 1-3), and a rule naming a variant past a gap - inherited rules: `wolf_tame`, `spider_eyes`, `a_b_c` → `a`, never across a folder or into another source - folder priority across ETF, `optifine/random`, `optifine/mob`, `mcpatcher/mob` and a mod namespace - the texture's own folder only counting with rules, including inherited ones - a Latin-1 `.properties` file, and an oversized one - an empty pack giving nothing - clippy and the full tests run in CI on my fork. I didn't run them locally because the machine is shared. - No live game test: this machine has no `.local/` vanilla data, and nothing in the game reads this code yet. > [!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:00 +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#6457
No description provided.