Search in sources :

Example 1 with WorldGenerationConfig

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;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Config(org.terasology.engine.config.Config) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Name(org.terasology.gestalt.naming.Name)

Aggregations

Config (org.terasology.engine.config.Config)1 WorldGenerationConfig (org.terasology.engine.config.WorldGenerationConfig)1 SimpleUri (org.terasology.engine.core.SimpleUri)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 GameManifest (org.terasology.engine.game.GameManifest)1 WorldInfo (org.terasology.engine.world.internal.WorldInfo)1 Module (org.terasology.gestalt.module.Module)1 Name (org.terasology.gestalt.naming.Name)1