Search in sources :

Example 1 with WorldProvider

use of org.terasology.world.WorldProvider in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method addGameManifestToSaveTransaction.

private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    BiomeManager biomeManager = CoreRegistry.get(BiomeManager.class);
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);
    GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
        registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<Biome> biomes = biomeManager.getBiomes();
    Map<String, Short> biomeIdMap = new HashMap<>(biomes.size());
    for (Biome biome : biomes) {
        short shortId = biomeManager.getBiomeShortId(biome);
        String id = biomeManager.getBiomeId(biome);
        biomeIdMap.put(id, shortId);
    }
    gameManifest.setBiomeIdMap(biomeIdMap);
    gameManifest.addWorld(worldProvider.getWorldInfo());
    saveTransactionBuilder.setGameManifest(gameManifest);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) HashMap(java.util.HashMap) Time(org.terasology.engine.Time) ModuleManager(org.terasology.engine.module.ModuleManager) Game(org.terasology.game.Game) Biome(org.terasology.world.biomes.Biome) GameManifest(org.terasology.game.GameManifest) BlockManager(org.terasology.world.block.BlockManager) WorldProvider(org.terasology.world.WorldProvider) BlockFamily(org.terasology.world.block.family.BlockFamily) Module(org.terasology.module.Module)

Example 2 with WorldProvider

use of org.terasology.world.WorldProvider in project Terasology by MovingBlocks.

the class NetClient method disconnect.

@Override
public void disconnect() {
    super.disconnect();
    if (channel.isOpen()) {
        channel.close().awaitUninterruptibly();
    }
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    if (worldProvider != null) {
        worldProvider.unregisterListener(this);
    }
}
Also used : WorldProvider(org.terasology.world.WorldProvider)

Example 3 with WorldProvider

use of org.terasology.world.WorldProvider in project Terasology by MovingBlocks.

the class ServerImpl method processBiomeChanges.

private void processBiomeChanges(NetData.NetMessage message) {
    for (NetData.BiomeChangeMessage biomeChange : message.getBiomeChangeList()) {
        logger.debug("Received block change to {}", blockManager.getBlock((short) biomeChange.getNewBiome()));
        // TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
        WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
        Vector3i pos = NetMessageUtil.convert(biomeChange.getPos());
        if (worldProvider.isBlockRelevant(pos)) {
            Biome newBiome = biomeManager.getBiomeByShortId((short) biomeChange.getNewBiome());
            worldProvider.setBiome(pos, newBiome);
        } else {
            awaitingChunkReadyBiomeUpdates.put(ChunkMath.calcChunkPos(pos), biomeChange);
        }
    }
}
Also used : Biome(org.terasology.world.biomes.Biome) NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.world.WorldProvider) Vector3i(org.terasology.math.geom.Vector3i)

Example 4 with WorldProvider

use of org.terasology.world.WorldProvider in project Terasology by MovingBlocks.

the class ServerImpl method processBlockChanges.

private void processBlockChanges(NetData.NetMessage message) {
    for (NetData.BlockChangeMessage blockChange : message.getBlockChangeList()) {
        Block newBlock = blockManager.getBlock((short) blockChange.getNewBlock());
        logger.debug("Received block change to {}", newBlock);
        // TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
        WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
        Vector3i pos = NetMessageUtil.convert(blockChange.getPos());
        if (worldProvider.isBlockRelevant(pos)) {
            worldProvider.setBlock(pos, newBlock);
        } else {
            awaitingChunkReadyBlockUpdates.put(ChunkMath.calcChunkPos(pos), blockChange);
        }
    }
}
Also used : NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.world.WorldProvider) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 5 with WorldProvider

use of org.terasology.world.WorldProvider in project Terasology by MovingBlocks.

the class InitialiseRemoteWorld method step.

@Override
public boolean step() {
    // TODO: These shouldn't be done here, nor so strongly tied to the world renderer
    LocalPlayer localPlayer = new LocalPlayer();
    context.put(LocalPlayer.class, localPlayer);
    BlockManager blockManager = context.get(BlockManager.class);
    RemoteChunkProvider chunkProvider = new RemoteChunkProvider(blockManager, localPlayer);
    WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD), chunkProvider, blockManager.getBlock(BlockManager.UNLOADED_ID), context);
    EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context);
    WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider);
    context.put(WorldProvider.class, worldProvider);
    context.put(BlockEntityRegistry.class, entityWorldProvider);
    context.get(ComponentSystemManager.class).register(entityWorldProvider, "engine:BlockEntityRegistry");
    DefaultCelestialSystem celestialSystem = new DefaultCelestialSystem(new BasicCelestialModel(), context);
    context.put(CelestialSystem.class, celestialSystem);
    context.get(ComponentSystemManager.class).register(celestialSystem);
    // Init. a new world
    Skysphere skysphere = new Skysphere(context);
    BackdropProvider backdropProvider = skysphere;
    BackdropRenderer backdropRenderer = skysphere;
    context.put(BackdropProvider.class, backdropProvider);
    context.put(BackdropRenderer.class, backdropRenderer);
    RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
    WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
    float reflectionHeight = context.get(NetworkSystem.class).getServer().getInfo().getReflectionHeight();
    worldRenderer.getActiveCamera().setReflectionHeight(reflectionHeight);
    context.put(WorldRenderer.class, worldRenderer);
    // TODO: These shouldn't be done here, nor so strongly tied to the world renderer
    context.put(Camera.class, worldRenderer.getActiveCamera());
    context.get(NetworkSystem.class).setRemoteWorldProvider(chunkProvider);
    return true;
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) WorldProviderWrapper(org.terasology.world.internal.WorldProviderWrapper) NetworkSystem(org.terasology.network.NetworkSystem) WorldProviderCoreImpl(org.terasology.world.internal.WorldProviderCoreImpl) EntityAwareWorldProvider(org.terasology.world.internal.EntityAwareWorldProvider) DefaultCelestialSystem(org.terasology.world.sun.DefaultCelestialSystem) BackdropProvider(org.terasology.rendering.backdrop.BackdropProvider) RenderingSubsystemFactory(org.terasology.engine.subsystem.RenderingSubsystemFactory) WorldRenderer(org.terasology.rendering.world.WorldRenderer) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) BasicCelestialModel(org.terasology.world.sun.BasicCelestialModel) BlockManager(org.terasology.world.block.BlockManager) Skysphere(org.terasology.rendering.backdrop.Skysphere) WorldProvider(org.terasology.world.WorldProvider) EntityAwareWorldProvider(org.terasology.world.internal.EntityAwareWorldProvider) RemoteChunkProvider(org.terasology.world.chunks.remoteChunkProvider.RemoteChunkProvider) BackdropRenderer(org.terasology.rendering.backdrop.BackdropRenderer)

Aggregations

WorldProvider (org.terasology.world.WorldProvider)11 BlockManager (org.terasology.world.block.BlockManager)5 Biome (org.terasology.world.biomes.Biome)4 BiomeManager (org.terasology.world.biomes.BiomeManager)4 ModuleManager (org.terasology.engine.module.ModuleManager)3 Vector3i (org.terasology.math.geom.Vector3i)3 NetData (org.terasology.protobuf.NetData)3 Block (org.terasology.world.block.Block)3 EntityAwareWorldProvider (org.terasology.world.internal.EntityAwareWorldProvider)3 WorldInfo (org.terasology.world.internal.WorldInfo)3 WorldProviderWrapper (org.terasology.world.internal.WorldProviderWrapper)3 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)2 RenderingSubsystemFactory (org.terasology.engine.subsystem.RenderingSubsystemFactory)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 LocalPlayer (org.terasology.logic.players.LocalPlayer)2 Module (org.terasology.module.Module)2 ModuleEnvironment (org.terasology.module.ModuleEnvironment)2 NetworkSystem (org.terasology.network.NetworkSystem)2 BackdropProvider (org.terasology.rendering.backdrop.BackdropProvider)2 BackdropRenderer (org.terasology.rendering.backdrop.BackdropRenderer)2