Search in sources :

Example 6 with WorldInfo

use of org.terasology.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupWorldProvider.

@Override
protected void setupWorldProvider() {
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    when(worldProvider.getTime()).thenReturn(WORLD_TIME);
    context.put(WorldProvider.class, worldProvider);
}
Also used : WorldProvider(org.terasology.world.WorldProvider) WorldInfo(org.terasology.world.internal.WorldInfo)

Example 7 with WorldInfo

use of org.terasology.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class JoinServer method step.

@Override
public boolean step() {
    if (applyModuleThread != null) {
        if (!applyModuleThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.COMPLETE) {
        Server server = networkSystem.getServer();
        ServerInfoMessage serverInfo = networkSystem.getServer().getInfo();
        // If no GameName, use Server IP Address
        if (serverInfo.getGameName().length() > 0) {
            gameManifest.setTitle(serverInfo.getGameName());
        } else {
            gameManifest.setTitle(server.getRemoteAddress());
        }
        for (WorldInfo worldInfo : serverInfo.getWorldInfoList()) {
            gameManifest.addWorld(worldInfo);
        }
        Map<String, Short> blockMap = Maps.newHashMap();
        for (Entry<Integer, String> entry : serverInfo.getBlockIds().entrySet()) {
            String name = entry.getValue();
            short id = entry.getKey().shortValue();
            Short oldId = blockMap.put(name, id);
            if (oldId != null && oldId != id) {
                logger.warn("Overwriting Id {} for {} with Id {}", oldId, name, id);
            }
        }
        Map<String, Short> biomeMap = Maps.newHashMap();
        for (Entry<Short, String> entry : serverInfo.getBiomeIds().entrySet()) {
            String name = entry.getValue();
            short id = entry.getKey();
            Short oldId = biomeMap.put(name, id);
            if (oldId != null && oldId != id) {
                logger.warn("Overwriting Biome Id {} for {} with Id {}", oldId, name, id);
            }
        }
        gameManifest.setRegisteredBlockFamilies(serverInfo.getRegisterBlockFamilyList());
        gameManifest.setBlockIdMap(blockMap);
        gameManifest.setBiomeIdMap(biomeMap);
        gameManifest.setTime(networkSystem.getServer().getInfo().getTime());
        ModuleManager moduleManager = context.get(ModuleManager.class);
        Set<Module> moduleSet = Sets.newLinkedHashSet();
        for (NameVersion moduleInfo : networkSystem.getServer().getInfo().getModuleList()) {
            Module module = moduleManager.getRegistry().getModule(moduleInfo.getName(), moduleInfo.getVersion());
            if (module == null) {
                StateMainMenu mainMenu = new StateMainMenu("Missing required module: " + moduleInfo);
                context.get(GameEngine.class).changeState(mainMenu);
                return false;
            } else {
                logger.info("Activating module: {}:{}", moduleInfo.getName(), moduleInfo.getVersion());
                gameManifest.addModule(module.getId(), module.getVersion());
                moduleSet.add(module);
            }
        }
        oldEnvironment = moduleManager.getEnvironment();
        moduleManager.loadEnvironment(moduleSet, true);
        context.get(Game.class).load(gameManifest);
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        applyModuleThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
        applyModuleThread.start();
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
        StateMainMenu mainMenu = new StateMainMenu("Failed to connect to server: " + joinStatus.getErrorMessage());
        context.get(GameEngine.class).changeState(mainMenu);
        networkSystem.shutdown();
    }
    return false;
}
Also used : Set(java.util.Set) Server(org.terasology.network.Server) NameVersion(org.terasology.naming.NameVersion) GameEngine(org.terasology.engine.GameEngine) ModuleManager(org.terasology.engine.module.ModuleManager) Entry(java.util.Map.Entry) StateMainMenu(org.terasology.engine.modes.StateMainMenu) WorldInfo(org.terasology.world.internal.WorldInfo) ServerInfoMessage(org.terasology.network.ServerInfoMessage) Module(org.terasology.module.Module) Map(java.util.Map) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler)

Example 8 with WorldInfo

use of org.terasology.world.internal.WorldInfo 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

WorldInfo (org.terasology.world.internal.WorldInfo)8 ModuleManager (org.terasology.engine.module.ModuleManager)3 Module (org.terasology.module.Module)3 WorldProvider (org.terasology.world.WorldProvider)3 Set (java.util.Set)2 StateMainMenu (org.terasology.engine.modes.StateMainMenu)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 GameManifest (org.terasology.game.GameManifest)2 ModuleEnvironment (org.terasology.module.ModuleEnvironment)2 FastRandom (org.terasology.utilities.random.FastRandom)2 BiomeManager (org.terasology.world.biomes.BiomeManager)2 BlockManager (org.terasology.world.block.BlockManager)2 IOException (java.io.IOException)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1