Naturalist Lag Fix
A small fix for a memory leak in [Naturalist](https://www.curseforge.com/minecraft/mc-mods/naturalist) (2.0.5, NeoForge 1.21.1) that makes servers slower and slower the longer they run.
The problem
Whales and Great White Sharks have multi-part bodies. Naturalist registers every body part in a list attached to the world, but only removes them when the creature dies or is discarded. When the creature is simply unloaded with its chunk, its parts stay in the list forever — and a new copy is added each time the chunk reloads.
Every time the game searches for nearby entities (mob AI, collisions, item pickup, Create contraptions…), Naturalist loops over that whole list. On our server, `naturalist$includeMobParts` ended up taking about 33% of every server tick in spark.
The fix
- Body parts are removed as soon as their creature leaves the world, including when its chunk unloads.
- Every 10 seconds, any leftover orphan parts are cleaned up.
- Nothing else in Naturalist is changed: whales and sharks behave exactly the same.
Installation
- Server: required.
- Client: recommended (the same leak exists client-side).
- Requires Naturalist. When the fix works, a line `[NaturalistFix] … parties fantomes retirees` appears in the log.
Credits
- Naturalist by Starfish Studios (Crispytwig): all credit for the mod, its creatures and its content goes to them. This is an unofficial fix, not affiliated with the Naturalist team. If they fix the leak upstream, you won't need this mod anymore.