CaffeineMC / lithium-fabric

A Fabric mod designed to improve the general performance of Minecraft without breaking things
GNU Lesser General Public License v3.0
1.94k stars 190 forks source link

Move NearbyEntityListener::forEachChunkInRangeChange call to after Fabric Api's ServerEntityEvents#ENTITY_LOAD runs #465

Closed Fuzss closed 1 year ago

Fuzss commented 1 year ago

Hey there, so I have a couple mods that add additional goals to some vanilla entities which are of type AvoidEntityGoal, e.g. make villagers avoid/flee from skeletons. I do this using Fabric Api's ServerEntityEvents#ENTITY_LOAD callback, since this seems to be the best place for such a thing without having to resort to custom mixins.

When doing this with Lithium installed, the game crashes when my new goals are trying to be added in ServerEntityEvents#ENTITY_LOAD with the following exception: java.lang.IllegalStateException: Cannot add sublisteners after listening range was set! (full crash-report)

This happens since NearbyEntityListenerMulti#range is set in NearbyEntityListenerMulti::getChunkRange which runs before the Fabric Api callback.

Would it be possible to set the range field after Fabric Api's callback has run, either by moving the injection in ServerEntityManagerMixin or by migrating to the Fabric Api callback at a phase that runs after fabric:default?

2No2Name commented 1 year ago

Your request is not possible, but instead I replaced the IllegalStateException with code that handles the situation correctly. This should fix the issue without futher action from your side.