Generating/loading worlds asynchronously

Currently world generation is done on the main thread, this is fine at startup however during runtime this causes other players to be unable to do anything until the world is generated and loaded.

I was wondering if there is a way to, or any plans to, allow a world to be generated and loaded asynchronously? The reason I ask is because we may be converting our server plugins to use Sponge, the one thing holding us back is not being able to generate/load worlds asynchronously, as worlds are constantly being generated on the server and we do not want other players to be affected by the generation.

I tried simply using an async task with the Scheduler to create the world however it failed as expected due to an NPE somewhere.



So far I know that’s all done in forge. Its loading chunks async from the disk. Not sure what it does, when the chunk doesn’t exist. But it would make sense to me that it also generates it async.

(pls someone correct me if I am wrong)

1 Like

That looks promising, although that requires a dependency on Forge, and also means we need to handle instantiating worlds as well, it could all get quite messy. However it may work well as a temporary solution to the problem.

I don’t understand what is wrong with a dependency on forge? And also why would we need to handle instantiating worlds? Forge/Minecraft is already doing that.

Having a dependency on Forge is bad, because it means that the plugin (or part of the plugin) will not work on SpongeVanilla.

Also what I mean by instantiating worlds is, basically I want to generate a brand new world asynchronously, we can’t use the WorldBuilder in Sponge as in doing so it start the world generation process… synchronously.

Unless I maybe set “keepSpawnInMemory” to false and make it generate asynchronously from there… hmm. Will report back.

1 Like

This is my attempt at async world loading, but the Runnable seems to just be executed straight away and the player falls into the void until the world is generated. Even if I add a 20 second delay til the player is moved to the new world it isn’t loaded.

This is on my todo list, currently finishing inventory events so maybe after.


Thank you! This would definitely be an awesome feature! Would implement it myself but I’m very new to the Sponge codebase.