Skip to content

fix(animation): clear tracked animation when an animated block is removed#74

Merged
duzos merged 3 commits into
mainfrom
fix/animation-state-cleanup
Jun 5, 2026
Merged

fix(animation): clear tracked animation when an animated block is removed#74
duzos merged 3 commits into
mainfrom
fix/animation-state-cleanup

Conversation

@duzos
Copy link
Copy Markdown
Contributor

@duzos duzos commented Jun 5, 2026

Fixes #68 and #45.

Animated block entities derive their animation UUID from world + position (AnimatedBlockEntity#getUuid), and animation state was never cleared when a block was removed - so a block placed where an animated one was broken inherited the stale animation (#68), and animations survived chunk unload/reload (#45).

This clears tracked animation state for any AnimatedInstance block entity via a mixin on vanilla BlockEntity#markRemoved (server-side only). Hooking the vanilla lifecycle rather than ABlockEntity.onBreak means it also covers downstream block entities that implement AnimatedBlockEntity on a plain BlockEntity (e.g. ait-extras' MonitorCoverBlockEntity), and because markRemoved fires on chunk unload it fixes #45 too. Only syncs a removal when an animation is actually tracked, to avoid needless packets on unload.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes stale server-side animation state for animated block entities by clearing their AnimationTracker entry when the block is actually removed/replaced, preventing a newly placed block at the same position from inheriting an old animation.

Changes:

  • Implemented ABlockEntity.onBreak(...) to remove tracked animations for AnimatedInstance block entities on the server.
  • Added the required imports to support the new tracker cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@duzos duzos added A: Models Area: Automatic models, block/item model generation & rendering helpers. size/S Denotes a PR that changes 10-99 lines. T: Bugfix Type: Bugs and/or bugfixes. labels Jun 5, 2026
@duzos
Copy link
Copy Markdown
Contributor Author

duzos commented Jun 5, 2026

generalized the fix after the ait-extras MonitorCoverBlockEntity catch. that one (and any addon) implements AnimatedBlockEntity on a vanilla BlockEntity, not ABlockEntity, so the old ABlockEntity.onBreak hook never fired for it - #68 still happened.

moved the cleanup into a BlockEntity#markRemoved mixin keyed on AnimatedInstance (1d9ec4d), so it now covers every animated block entity regardless of base class. bonus: markRemoved also fires on chunk unload, so this properly fixes #45 (anim stops after you leave and come back) which the break-only hook didnt. reverted the now-redundant onBreak removal.

./gradlew build green.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/main/java/dev/amble/lib/mixin/BlockEntityMixin.java Outdated
Comment thread src/main/java/dev/amble/lib/mixin/BlockEntityMixin.java
@duzos duzos requested a review from Copilot June 5, 2026 19:48
@github-actions github-actions Bot added A: Core Tech Area: Underlying core tech for the mod and the GitHub repository. and removed A: Models Area: Automatic models, block/item model generation & rendering helpers. labels Jun 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@duzos duzos merged commit bce00d7 into main Jun 5, 2026
4 checks passed
@duzos duzos deleted the fix/animation-state-cleanup branch June 5, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A: Core Tech Area: Underlying core tech for the mod and the GitHub repository. size/S Denotes a PR that changes 10-99 lines. T: Bugfix Type: Bugs and/or bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

animation state not forgeting if you start the animation, go away, then come back its still playing

2 participants