Moonrise

Moonrise

13.8k Downloads

Bug: Entity tracking state is incorrectly updated on chunk status upgrades

Owen1212055 opened this issue ยท 1 comments

commented

Minecraft Version

1.21.4

Moonrise Version

0973595

Mod Loader

Both (NeoForge and Fabric)

Logs and Crash Reports

N/A

Additional Context

This was initially reported on Paper, but is replicatable on Fabric with Moonrise installed as well.
When chunk statuses are upgraded, entity tracking methods are incorrectly called multiple times.

This occurs when spawning into a chunk with an Allay already existing:

(Paper logs- what I had easily availiable)
https://pastes.dev/jAhalfZrJE
tracking start -> tracking end -> tracking start

(Vanilla)
https://pastes.dev/nf7zpAdu0r
tracking start

Paper Issue: PaperMC/Paper#11751

This behavior causes small breaks, for example, DynamicGameEventListener does not expect tracking start to be called in this nature.
Vanilla stores the lastSection for which dynamic game event listeners were registered into. When the entity is first spawned, it registers the listeners, but when it's (incorrectly) untracked it unregisters them. However, when the entity is retracked lastSection is already set, so game event listeners do not get re-registered when the entity is added.

A "bandaid" fix is to set lastSection = null on DynamicGameEventListener#remove. But again, this is fundamentally a behavior change.

commented

See the conversation starting here for context

Basically there are two topics here:

  1. There are cases where chunks are redundantly loaded, unloaded, and reloaded, #22 aims to change this
  2. The actual issue at hand seems to be that in vanilla allays do not expect the same instance to ever be untracked and retracked. It expects the allay to save to disk and be reloaded as a new instance before retracking. Something in the Moonrise chunk system is causing entity instances to be reused in a way vanilla doesn't expect when chunks are demoted and re-promoted.