[PR #6245] [MERGED] OptiFine entity models: animations stop re-showing hidden parts and counting twice a frame #6739

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

📋 Pull Request Information

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

Base: main ← Head: optifine/emf-anim-fixes


📝 Commits (9)

  • e300bc8 OptiFine entity models: animations no longer re-show hidden parts or run twice a frame
  • fa8f4bd OptiFine entity models: previews leave the world's animation variables alone
  • d53fcde OptiFine entity models: pass the preview closure by value (clippy)
  • 21acaaa OptiFine entity models: the preview test expects what the world last stored
  • bf3a4df OptiFine entity models: a preview-only entity keeps counting, globals read once per frame
  • 787b60e OptiFine entity models: comments say when a preview stores, the globals test catches a storing preview
  • 5328eca OptiFine entity models: the preview test's comment gives the right starting values
  • ed15952 OptiFine entity models: the globals test fills is_in_gui so a storing preview shows
  • bf724b4 Merge main into optifine/emf-anim-fixes

📊 Changes

5 files changed (+754 additions, -180 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+4 -0)
📝 crates/horizon-client/src/game/mount_menu.rs (+13 -10)
📝 crates/horizon-client/src/game/perspective.rs (+13 -10)
📝 crates/horizon-client/src/mobs/anim.rs (+10 -2)
📝 crates/horizon-client/src/mobs/cem_anim.rs (+714 -158)

📄 Description

Custom entity model animations (#5665) shipped with bugs the review found but that weren't fixed before the merge:

  • A pack that only mentioned a part ("head.rx": ...) re-showed parts vanilla hides: a sheared mooshroom's mushrooms, a player's disabled hat layer, a spectator's body, horse reins.
  • First-person checks always read "third person".
  • Counters ran 2–4 times a frame for mobs drawn more than once (the illusioner, the inventory and mount previews, the glowing pass), and a preview's run overwrote the world's.
  • Several is_* flags read nothing on clients.

This fixes them in mobs/cem_anim.rs:

  • Visibility: a part's visible/visible_boxes start from what the vanilla animation set, and only a change is written back. visible_boxes = 0 skips a part's boxes; 1 leaves vanilla's skip alone, as before.
  • The frame: one default for the frame state, and mob_geometry fills first_person, third_person_reversed and paused from the game. The inventory preview (survival and the creative tab, both through draw_player_preview) and the mount screen draw inside cem_anim::in_gui, a thread-local flag, so is_in_gui reads 1 there. Spawner displays are world drawing in vanilla too, so they deliberately stay outside it.
  • Variables:
    • Every run of an entity in one frame starts from that frame's starting values, and only the first draw stores its result. A preview stores nothing, unless the world didn't draw the entity this frame or the last: the inventory's own player in first person, whom the world never draws, still animates.
    • global_var.*/global_varb.* are one value shared by every entity, as EMF documents. Each entity reads them as its frame began, and only its storing run writes them.
    • No allocation after an entity's first frame.
    • When the table is full, entities not seen for 600 frames are forgotten. If it still reaches twice its size, it starts over.
  • Parameters on clients:
    • is_aggressive reads the synced aggressive flag, not the AI target that only server mobs have.
    • is_sitting, is_tamed, is_sprinting and is_sneaking read the fields remote mobs carry.
    • is_right_handed reads Mob::main_arm_left(): a player's main-hand option, or a mob's left-handedness.
  • Bad values: a result that isn't finite leaves the vanilla pose, or the variable's old value, in place.
  • Limits: at most 4096 expressions per model, with a warning.
  • Locks: the frame lock is taken once per run.

Size: +750/−182 lines, over the ~500 guideline. Most of it is cem_anim.rs's new tests. The fixes share the run function, so splitting them would mean writing it twice.

Docs I worked from (no mod source read): OptiFine's cem_animation.txt, EMF's emf_animation.txt and FEATURES.md.

Checks:

  • cargo fmt: clean
  • Tests (new in cem_anim.rs):
    • a hidden part stays hidden when named, and visible_boxes = 0 skips
    • parameters through a real Mob and State: hurt_time with the partial tick, limb_swing, head_yaw, the burning/jumping/child flags, distance
    • the synced client flags
    • a second run in a frame doesn't advance var.n, and the next frame does
    • a preview stores nothing, while a preview-only entity keeps counting
    • globals are shared across entities and read and stored once per entity per frame
    • eviction keeps recent entities, and the table starts over at twice its size
    • is_in_gui inside and outside a preview
    • NaN and infinity leave poses and variables alone
    • the 4096-expression cap
  • Build, clippy and the suite run in fork CI, since this machine doesn't build. An earlier head compiled and passed clippy there; the latest head is at https://github.com/some-du6e/horizon/actions/runs/41341324019 (verify passed on the previous head, bf3a4dfbf)
  • Review loop: three rounds. Round 3 found only stale comments and one test that couldn't catch a storing preview, both fixed in 787b60eea. The live game test is skipped: there's no vanilla data (.local/) here. Worth checking by someone with it: a Fresh Animations mob, a sheared mooshroom, the inventory in first and third person.

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/6245 **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/emf-anim-fixes` --- ### 📝 Commits (9) - [`e300bc8`](https://github.com/horizon-rust/horizon/commit/e300bc82d5c2685910cd8b6ed80b3696ff15b701) OptiFine entity models: animations no longer re-show hidden parts or run twice a frame - [`fa8f4bd`](https://github.com/horizon-rust/horizon/commit/fa8f4bdd0c18ff44edc6a350131eb9c2b85bf4f2) OptiFine entity models: previews leave the world's animation variables alone - [`d53fcde`](https://github.com/horizon-rust/horizon/commit/d53fcde29a54c709d14e312e8fb2f0dfcfb48a3d) OptiFine entity models: pass the preview closure by value (clippy) - [`21acaaa`](https://github.com/horizon-rust/horizon/commit/21acaaa65fb0bb4334af39e5e09ef18111426257) OptiFine entity models: the preview test expects what the world last stored - [`bf3a4df`](https://github.com/horizon-rust/horizon/commit/bf3a4dfbfaf1c53e56f06fb4fc98b22de65fb7dc) OptiFine entity models: a preview-only entity keeps counting, globals read once per frame - [`787b60e`](https://github.com/horizon-rust/horizon/commit/787b60eeaef976ecc3a2d8e19fb85d5d58b69bbf) OptiFine entity models: comments say when a preview stores, the globals test catches a storing preview - [`5328eca`](https://github.com/horizon-rust/horizon/commit/5328ecaf139f30fb32a2177737b074e37fb05ed8) OptiFine entity models: the preview test's comment gives the right starting values - [`ed15952`](https://github.com/horizon-rust/horizon/commit/ed15952d2e7f2236191dc7983fddc883be83ac50) OptiFine entity models: the globals test fills is_in_gui so a storing preview shows - [`bf724b4`](https://github.com/horizon-rust/horizon/commit/bf724b491927d7bdb79414efcaf66e29ed493089) Merge main into optifine/emf-anim-fixes ### 📊 Changes **5 files changed** (+754 additions, -180 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+4 -0) 📝 `crates/horizon-client/src/game/mount_menu.rs` (+13 -10) 📝 `crates/horizon-client/src/game/perspective.rs` (+13 -10) 📝 `crates/horizon-client/src/mobs/anim.rs` (+10 -2) 📝 `crates/horizon-client/src/mobs/cem_anim.rs` (+714 -158) </details> ### 📄 Description Custom entity model animations (#5665) shipped with bugs the review found but that weren't fixed before the merge: - A pack that only mentioned a part (`"head.rx": ...`) re-showed parts vanilla hides: a sheared mooshroom's mushrooms, a player's disabled hat layer, a spectator's body, horse reins. - First-person checks always read "third person". - Counters ran 2–4 times a frame for mobs drawn more than once (the illusioner, the inventory and mount previews, the glowing pass), and a preview's run overwrote the world's. - Several `is_*` flags read nothing on clients. This fixes them in `mobs/cem_anim.rs`: - **Visibility:** a part's `visible`/`visible_boxes` start from what the vanilla animation set, and only a change is written back. `visible_boxes = 0` skips a part's boxes; `1` leaves vanilla's skip alone, as before. - **The frame:** one default for the frame state, and `mob_geometry` fills `first_person`, `third_person_reversed` and `paused` from the game. The inventory preview (survival and the creative tab, both through `draw_player_preview`) and the mount screen draw inside `cem_anim::in_gui`, a thread-local flag, so `is_in_gui` reads 1 there. Spawner displays are world drawing in vanilla too, so they deliberately stay outside it. - **Variables:** - Every run of an entity in one frame starts from that frame's starting values, and only the first draw stores its result. A preview stores nothing, unless the world didn't draw the entity this frame or the last: the inventory's own player in first person, whom the world never draws, still animates. - `global_var.*`/`global_varb.*` are one value shared by every entity, as EMF documents. Each entity reads them as its frame began, and only its storing run writes them. - No allocation after an entity's first frame. - When the table is full, entities not seen for 600 frames are forgotten. If it still reaches twice its size, it starts over. - **Parameters on clients:** - `is_aggressive` reads the synced aggressive flag, not the AI target that only server mobs have. - `is_sitting`, `is_tamed`, `is_sprinting` and `is_sneaking` read the fields remote mobs carry. - `is_right_handed` reads `Mob::main_arm_left()`: a player's main-hand option, or a mob's left-handedness. - **Bad values:** a result that isn't finite leaves the vanilla pose, or the variable's old value, in place. - **Limits:** at most 4096 expressions per model, with a warning. - **Locks:** the frame lock is taken once per run. Size: +750/−182 lines, over the ~500 guideline. Most of it is `cem_anim.rs`'s new tests. The fixes share the run function, so splitting them would mean writing it twice. Docs I worked from (no mod source read): OptiFine's `cem_animation.txt`, EMF's `emf_animation.txt` and `FEATURES.md`. Checks: - `cargo fmt`: clean - Tests (new in `cem_anim.rs`): - a hidden part stays hidden when named, and `visible_boxes = 0` skips - parameters through a real `Mob` and `State`: `hurt_time` with the partial tick, `limb_swing`, `head_yaw`, the burning/jumping/child flags, `distance` - the synced client flags - a second run in a frame doesn't advance `var.n`, and the next frame does - a preview stores nothing, while a preview-only entity keeps counting - globals are shared across entities and read and stored once per entity per frame - eviction keeps recent entities, and the table starts over at twice its size - `is_in_gui` inside and outside a preview - NaN and infinity leave poses and variables alone - the 4096-expression cap - Build, clippy and the suite run in fork CI, since this machine doesn't build. An earlier head compiled and passed clippy there; the latest head is at https://github.com/some-du6e/horizon/actions/runs/41341324019 (`verify` passed on the previous head, bf3a4dfbf) - Review loop: three rounds. Round 3 found only stale comments and one test that couldn't catch a storing preview, both fixed in 787b60eea. The live game test is skipped: there's no vanilla data (`.local/`) here. Worth checking by someone with it: a Fresh Animations mob, a sheared mooshroom, the inventory in first and third person. > [!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:56 +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#6739
No description provided.