[1.19.2 Forge] Structure Gel API deadlocks game with Dungeons Plus when structures spawns skeletons during world generation
I gotten this issue report: https://github.com/TelepathicGrunt/RepurposedStructures/issues/277
The user provided an export of their modpack instance including the mods and world itself so testing and reproducing should be easy.
The short summary is for my Repurposed Structures Underground Bastion, I spawn skeletons as part of a feature from my structure's Template Pool. Code I use to do That. The deadlock happens when I call finalizeSpawn on the Skeleton to set everything up for spawning into the world: https://github.com/TelepathicGrunt/RepurposedStructures/blob/5982ff237a2d9c38e7708693ccd320ff4f1714a0/src/main/java/com/telepathicgrunt/repurposedstructures/world/features/Skeletons.java#L28
The issue appears to be that Dungeons Plus and Structure Gel API then runs onEntitySpawn event which runs ifInStructure and then calls isInStructurePiece which then somehow eventually runs isInStructurePiece again but deadlocks here. https://controlc.com/a9c568a6
The deadlock is most likely caused by using the wrong world to check for structure bounds. When in worldgen, always use the WorldGenRegion. Never the ServerLevel. Because here, while the chunk is generating, it runs your code which then goes to ServerLevel and tries to get the structure bounds there which then parks and waits for the target chunk to finish generating so it can have the bounds. Except that target chunk is the generating chunk so the chunk is now waiting on itself and gets stuck and deadlocks the game.
People can be spawning skeletons by NBT pieces or their own features so this is a valid use case as far as I know.