CrimsonCrips / AlexsMobsInteraction

MIT License
2 stars 2 forks source link

Server freezes when loading specific structure from Integrated Dungeons and Structures mod. #29

Closed osoper closed 2 months ago

osoper commented 3 months ago

When going near a specific structure (ruins of the deep) from the popular IDAS mod, the structure fails to load and freezes the server. This bug only occurs when this mod (Alex's Mob Interactions) is loaded alongside IDAS and its associated dependencies (including the optional dependency Alex's Mobs, of course). The structure contains giant squids, so I am guessing that the problem has something to do with them.

Forge 1.20.1, all mods on their latest version at the time of this post.

celestmia commented 3 months ago

Seems like it's caused by the event handler AMInteractionEvents#onEntityFinalizeSpawn at the call to giantSquid.isInWaterOrBubble(), which ends up calling the getChunk on the current chunk being generated causing a deadlock.

It seems like it's not safe to access the current chunk in this event then, since it gets called as part of chunk gen instead of afterwards in some cases? Perhaps just when the spawn type is not structure?

Code in question: https://github.com/CrimsonCrips/AlexsMobsInteraction/blob/f6fb0e89a665d151fb246c934c498e46cee83190/src/main/java/com/crimsoncrips/alexsmobsinteraction/event/AMInteractionEvents.java#L318-L322

So for the end user it could be prevented by disabling the following in the config: SQUID_CANNIBALIZE_ENABLED for now.

I think the call to giantSquid.isInWaterOrBubble() might not be needed anyway? Since it means if you have a giant squid outside of the water when it is spawned, it won't canibalize other giant squids even if the config is enabled and the squid is pushed into water?

Also another related thing I noticed! Maybe the EntityJoinLevelEvent might be better suited too? As the MobSpawnEvent.FinalizeSpawn event only gets called when the entity is initially spawned into the world, and not when a chunk deserializes the entities inside it. Currently the goals being added would not persist exiting the game and returning to it due to this.

CrimsonCrips commented 2 months ago

I forgot to comment on this issue, but this is fixed now and the cause is due to the massive amount of giant squids in the structure