Repository: movingblocks/terasology
Issue: On restarting a headless server with an existing world no world is retrieved from the game manifest

### What you were trying to do

Test something unrelated, by which I ended up restarting a headless server.

### What actually happened

The restart failed to bring the game server back up

### How to reproduce

* Start a headless server with any config (like just starting the headless run config in IntelliJ)
* Stop the server (can potentially skip steps 1 & 2 if you can reproduce with an existing save)
* Start the server again

On `InitialiseWorld` line 100 the failure occurs. The `gameManifest` loads but has no entries in its `worlds` list

### Log details and game version

Latest develop

```
16:48:21.601 [main] INFO  o.t.w.c.b.ExtraBlockDataManager - Extra data slots registered:
16:48:21.604 [main] ERROR o.terasology.engine.TerasologyEngine - Uncaught exception, attempting clean game shutdown
java.lang.NullPointerException: null
	at org.terasology.engine.modes.loadProcesses.InitialiseWorld.step(InitialiseWorld.java:101)
	at org.terasology.engine.modes.StateLoading.update(StateLoading.java:243)
	at org.terasology.engine.TerasologyEngine.tick(TerasologyEngine.java:458)
	at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:421)
	at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:397)
	at org.terasology.engine.Terasology.main(Terasology.java:145)
16:48:21.604 [main] INFO  o.terasology.engine.TerasologyEngine - Shutting down Terasology...
```

### Theory

Either the game isn't correctly saving the world in the first place or the game manifest isn't correctly figuring out where the actual world went so it can list it. Might relate to some of the multi-world changes, although that was a few months ago. Since it works fine the _first_ time you launch a headless server maybe we somehow missed it this long.

Also works partially with a client/server hosting a fresh game, exiting, then re-hosting. No crash, although when I tried it the client loaded into a black screen with no world visible (did have toolbar items etc)

Changed files:
engine/src/main/java/org/terasology/engine/subsystem/headless/mode/StateHeadlessSetup.java

diff --git a/engine/src/main/java/org/terasology/engine/subsystem/headless/mode/StateHeadlessSetup.java b/engine/src/main/java/org/terasology/engine/subsystem/headless/mode/StateHeadlessSetup.java
index 6d53f56e4..25fee757e 100644
--- a/engine/src/main/java/org/terasology/engine/subsystem/headless/mode/StateHeadlessSetup.java
+++ b/engine/src/main/java/org/terasology/engine/subsystem/headless/mode/StateHeadlessSetup.java
@@ -106,6 +106,13 @@ public void init(GameEngine gameEngine) {
         } else {
             gameManifest = createGameManifest();
         }
+
+        Config config = context.get(Config.class);
+        WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
+        config.getUniverseConfig().addWorldManager(worldInfo);
+        config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
+        config.getUniverseConfig().setUniverseSeed(gameManifest.getSeed());
+
         gameEngine.changeState(new StateLoading(gameManifest, NetworkMode.LISTEN_SERVER));
     }