use of org.terasology.engine.config.WorldGenerationConfig in project Terasology by MovingBlocks.
the class StateHeadlessSetup method createGameManifest.
public GameManifest createGameManifest() {
GameManifest gameManifest = new GameManifest();
Config config = context.get(Config.class);
ModuleManager moduleManager = context.get(ModuleManager.class);
for (Name moduleName : config.getDefaultModSelection().listModules()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
if (module != null) {
gameManifest.addModule(module.getId(), module.getVersion());
} else {
logger.warn("ModuleRegistry has no latest version for module {}", moduleName);
}
}
WorldGenerationConfig worldGenConfig = config.getWorldGeneration();
// If no valid default world generator set then try to find one - no option to pick one manually in headless
if (!worldGenConfig.getDefaultGenerator().isValid()) {
// find the first gameplay module that is available, it should have a preferred world gen
for (Name moduleName : config.getDefaultModSelection().listModules()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
if (StandardModuleExtension.isGameplayModule(module)) {
SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
worldGenConfig.setDefaultGenerator(defaultWorldGenerator);
break;
}
}
}
SimpleUri worldGeneratorUri = worldGenConfig.getDefaultGenerator();
gameManifest.setTitle(worldGenConfig.getWorldTitle());
gameManifest.setSeed(worldGenConfig.getDefaultSeed());
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, worldGenConfig.getWorldTitle(), gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), worldGeneratorUri);
gameManifest.addWorld(worldInfo);
return gameManifest;
}
Aggregations