[PR #5710] [MERGED] OptiFine random entities: read the rules that pick a mob's texture variant #6452

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

📋 Pull Request Information

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

Base: main ← Head: optifine/etf-rules


📝 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

8 files changed (+1397 additions, -14 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 (+5 -2)
📝 crates/horizon-optifine/src/matchers.rs (+15 -8)
➕ crates/horizon-optifine/src/random.rs (+792 -0)

📄 Description

OptiFine packs that give mobs random looks (several zombie or creeper skins, a biome-specific villager, a pig named "Pinky") put numbered textures and rules under optifine/random/entity/. Horizon ignores them, so every mob of a kind looks the same. This is the first PR of a stack that adds random entity textures the way OptiFine and Entity Texture Features do. It only reads the rules and picks a variant. Nothing in the game uses it yet, so players see no change.

horizon_optifine::random::Rules::parse reads a random-entities .properties file into its numbered rules, and Rules::select(facts, seed) returns the variant index an entity wears (1 is the default texture):

  • textures.<n> / skins.<n> index lists with ranges, and weights.<n> (ignored when the count doesn't match the textures, as the docs say the counts must match). A rule lists at most 256 textures, indices above 1024 are dropped, and a file holds at most 1024 rules (each rule reads every entry, so a hostile file of 200,000 rules would take minutes).
  • ETF's seedOffset.<n>.
  • Conditions:
    • biomes: ids with !, and ETF's pattern:/regex: forms, matched with or without the namespace
    • heights (negative bounds in brackets, or bare as ETF writes them: -64--30) and the legacy minHeight/maxHeight
    • name with pattern:, ipattern:, regex:, iregex: and !, plus ETF's names with "quoted groups"
    • professions with levels (librarian:1,3-4, minecraft: or a mod's namespace)
    • colors / collarColors, baby, health in points or percent
    • moonPhase, dayTime, weather, sizes
    • blocks with block states and !
  • Rules are tried in order of <n>. The first one that matches picks a texture, and if none matches the entity wears the default.
  • A rule never matches if it holds a condition that is empty or doesn't parse (a bad range, baby.1=yes, a lone !, a regex Rust can't compile) or one that isn't read yet (nbt.<n>.*, ETF's teams, items, angry, seedSource=vehicle...). Ignoring such a condition would put that rule's texture on every entity.
  • The seed is Java's UUID.hashCode of the entity's UUID, so it stays the same for the entity's whole life and is the same on every client. Neither OptiFine's nor ETF's docs say how the seed becomes a choice, so a pack's mobs get the same spread of variants here but not necessarily the same variant per mob as under OptiFine.
  • An unnamed entity fails name.1=Bob and name.1=pattern:*, but passes name.1=!Bob.
  • Rules::updates() says whether a file reads a fact that can change while the entity lives (name, profession, colour, baby, health). ETF lists these as the properties it rechecks. The others (biome, height, block, moon, time, weather) are fixed when the entity is first seen.

It uses the shared matchers in horizon-optifine (Name, RangeList, BlockMatch). It adds one change to them: RangeList now also reads bare negative ranges such as -64--30, which ETF documents. Everything that parsed before parses the same way.

Next in the stack: find the variant textures in the packs (optifine/random, optifine/mob, mcpatcher/mob, ETF's etf/random, numbered files with no .properties), put them in the entity atlas, choose a variant when an entity is first seen, and swap the texture name in mobs/render.rs. That swap goes after the custom-model texture swap from #5659, so random textures also work on EMF models. Emissive _e layers and ETF blinking come after that.

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

  • OptiFine's OptiFineDoc/doc/random_entities.properties (github.com/sp614x/optifine)
  • ETF's .github/README-assets/RANDOM_GUIDE.md and random_entities.properties

Checks:

  • cargo fmt: clean
  • cargo test -p horizon-optifine: 22 passed. They use hand-computed answers: OptiFine's creeper example with its weights (seed % 43), the fallback rule, both the passing and failing side of every condition, negated name lists, seedOffset, rule order by number, rules that don't parse or aren't supported, and Java UUID.hashCode values.
  • Review rounds with fresh reviewers (correctness, edges, tests, simplicity, fit). Their fixes are in the later commits.
  • clippy and the full test suite 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/5710 **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-rules` --- ### 📝 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 **8 files changed** (+1397 additions, -14 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` (+5 -2) 📝 `crates/horizon-optifine/src/matchers.rs` (+15 -8) ➕ `crates/horizon-optifine/src/random.rs` (+792 -0) </details> ### 📄 Description OptiFine packs that give mobs random looks (several zombie or creeper skins, a biome-specific villager, a pig named "Pinky") put numbered textures and rules under `optifine/random/entity/`. Horizon ignores them, so every mob of a kind looks the same. This is the first PR of a stack that adds random entity textures the way OptiFine and Entity Texture Features do. It only reads the rules and picks a variant. Nothing in the game uses it yet, so players see no change. `horizon_optifine::random::Rules::parse` reads a random-entities `.properties` file into its numbered rules, and `Rules::select(facts, seed)` returns the variant index an entity wears (1 is the default texture): - `textures.<n>` / `skins.<n>` index lists with ranges, and `weights.<n>` (ignored when the count doesn't match the textures, as the docs say the counts must match). A rule lists at most 256 textures, indices above 1024 are dropped, and a file holds at most 1024 rules (each rule reads every entry, so a hostile file of 200,000 rules would take minutes). - ETF's `seedOffset.<n>`. - Conditions: - `biomes`: ids with `!`, and ETF's `pattern:`/`regex:` forms, matched with or without the namespace - `heights` (negative bounds in brackets, or bare as ETF writes them: `-64--30`) and the legacy `minHeight`/`maxHeight` - `name` with `pattern:`, `ipattern:`, `regex:`, `iregex:` and `!`, plus ETF's `names` with `"quoted groups"` - `professions` with levels (`librarian:1,3-4`, `minecraft:` or a mod's namespace) - `colors` / `collarColors`, `baby`, `health` in points or percent - `moonPhase`, `dayTime`, `weather`, `sizes` - `blocks` with block states and `!` - Rules are tried in order of `<n>`. The first one that matches picks a texture, and if none matches the entity wears the default. - A rule never matches if it holds a condition that is empty or doesn't parse (a bad range, `baby.1=yes`, a lone `!`, a regex Rust can't compile) or one that isn't read yet (`nbt.<n>.*`, ETF's `teams`, `items`, `angry`, `seedSource=vehicle`...). Ignoring such a condition would put that rule's texture on every entity. - The seed is Java's `UUID.hashCode` of the entity's UUID, so it stays the same for the entity's whole life and is the same on every client. Neither OptiFine's nor ETF's docs say how the seed becomes a choice, so a pack's mobs get the same spread of variants here but not necessarily the same variant per mob as under OptiFine. - An unnamed entity fails `name.1=Bob` and `name.1=pattern:*`, but passes `name.1=!Bob`. - `Rules::updates()` says whether a file reads a fact that can change while the entity lives (name, profession, colour, baby, health). ETF lists these as the properties it rechecks. The others (biome, height, block, moon, time, weather) are fixed when the entity is first seen. It uses the shared matchers in `horizon-optifine` (`Name`, `RangeList`, `BlockMatch`). It adds one change to them: `RangeList` now also reads bare negative ranges such as `-64--30`, which ETF documents. Everything that parsed before parses the same way. **Next in the stack:** find the variant textures in the packs (`optifine/random`, `optifine/mob`, `mcpatcher/mob`, ETF's `etf/random`, numbered files with no `.properties`), put them in the entity atlas, choose a variant when an entity is first seen, and swap the texture name in `mobs/render.rs`. That swap goes after the custom-model texture swap from #5659, so random textures also work on EMF models. Emissive `_e` layers and ETF blinking come after that. **Docs I wrote it from** (no mod source read): - OptiFine's `OptiFineDoc/doc/random_entities.properties` (github.com/sp614x/optifine) - ETF's `.github/README-assets/RANDOM_GUIDE.md` and `random_entities.properties` **Checks:** - `cargo fmt`: clean - `cargo test -p horizon-optifine`: 22 passed. They use hand-computed answers: OptiFine's creeper example with its weights (seed % 43), the fallback rule, both the passing and failing side of every condition, negated name lists, `seedOffset`, rule order by number, rules that don't parse or aren't supported, and Java `UUID.hashCode` values. - Review rounds with fresh reviewers (correctness, edges, tests, simplicity, fit). Their fixes are in the later commits. - clippy and the full test suite 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:20:54 +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#6452
No description provided.