Search in sources :

Example 1 with WorldGenerationConfig

use of org.terasology.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());
        }
    }
    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, gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * 0.025f), worldGeneratorUri);
    gameManifest.addWorld(worldInfo);
    return gameManifest;
}
Also used : GameManifest(org.terasology.game.GameManifest) Config(org.terasology.config.Config) WorldGenerationConfig(org.terasology.config.WorldGenerationConfig) SimpleUri(org.terasology.engine.SimpleUri) WorldInfo(org.terasology.world.internal.WorldInfo) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) WorldGenerationConfig(org.terasology.config.WorldGenerationConfig) Name(org.terasology.naming.Name)

Aggregations

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