Search in sources :

Example 6 with WorldProvider

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

the class WorldProvidingHeadlessEnvironment method setupWorldProvider.

public void setupWorldProvider(WorldGenerator generator) {
    generator.initialize();
    WorldProviderCore stub = new MapWorldProvider(generator, context.get(BlockManager.class), context.get(ExtraBlockDataManager.class));
    WorldProvider world = new WorldProviderWrapper(stub, context.get(ExtraBlockDataManager.class));
    CoreRegistry.put(WorldProvider.class, world);
    CoreRegistry.put(BlockEntityRegistry.class, new EntityAwareWorldProvider(stub, context));
}
Also used : WorldProviderCore(org.terasology.engine.world.internal.WorldProviderCore) BlockManager(org.terasology.engine.world.block.BlockManager) WorldProviderWrapper(org.terasology.engine.world.internal.WorldProviderWrapper) WorldProvider(org.terasology.engine.world.WorldProvider) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider)

Example 7 with WorldProvider

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

the class InitialiseWorld method step.

@Override
public boolean step() {
    BlockManager blockManager = context.get(BlockManager.class);
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
    WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
    verify(worldInfo.getWorldGenerator().isValid(), "Game manifest did not specify world type.");
    if (worldInfo.getSeed() == null || worldInfo.getSeed().isEmpty()) {
        FastRandom random = new FastRandom();
        worldInfo.setSeed(random.nextString(16));
    }
    logger.info("World seed: \"{}\"", worldInfo.getSeed());
    // TODO: Separate WorldRenderer from world handling in general
    WorldGeneratorManager worldGeneratorManager = context.get(WorldGeneratorManager.class);
    WorldGenerator worldGenerator;
    try {
        worldGenerator = WorldGeneratorManager.createGenerator(worldInfo.getWorldGenerator(), context);
        // setting the world seed will create the world builder
        worldGenerator.setWorldSeed(worldInfo.getSeed());
        context.put(WorldGenerator.class, worldGenerator);
    } catch (UnresolvedWorldGeneratorException e) {
        logger.error("Unable to load world generator {}. Available world generators: {}", worldInfo.getWorldGenerator(), worldGeneratorManager.getWorldGenerators());
        context.get(GameEngine.class).changeState(new StateMainMenu("Failed to resolve world generator."));
        // We need to return true, otherwise the loading state will just call us again immediately
        return true;
    }
    // Init. a new world
    EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
    boolean writeSaveGamesEnabled = context.get(SystemConfig.class).writeSaveGamesEnabled.get();
    // Gets save data from a normal save or from a recording if it is a replay
    Path saveOrRecordingPath = getSaveOrRecordingPath();
    StorageManager storageManager;
    RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
    RecordAndReplayUtils recordAndReplayUtils = context.get(RecordAndReplayUtils.class);
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    try {
        storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus) : new ReadOnlyStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager);
    } catch (IOException e) {
        logger.error("Unable to create storage manager!", e);
        context.get(GameEngine.class).changeState(new StateMainMenu("Unable to create storage manager!"));
        // We need to return true, otherwise the loading state will just call us again immediately
        return true;
    }
    context.put(StorageManager.class, storageManager);
    LocalChunkProvider chunkProvider = new LocalChunkProvider(storageManager, entityManager, worldGenerator, blockManager, extraDataManager, Maps.newConcurrentMap());
    RelevanceSystem relevanceSystem = new RelevanceSystem(chunkProvider);
    context.put(RelevanceSystem.class, relevanceSystem);
    context.get(ComponentSystemManager.class).register(relevanceSystem, "engine:relevanceSystem");
    chunkProvider.setRelevanceSystem(relevanceSystem);
    Block unloadedBlock = blockManager.getBlock(BlockManager.UNLOADED_ID);
    WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(worldInfo, chunkProvider, unloadedBlock, context);
    EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context);
    WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider, extraDataManager);
    context.put(WorldProvider.class, worldProvider);
    chunkProvider.setBlockEntityRegistry(entityWorldProvider);
    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);
    Skysphere skysphere = new Skysphere(context);
    BackdropProvider backdropProvider = skysphere;
    context.put(BackdropProvider.class, backdropProvider);
    RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
    WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
    context.put(WorldRenderer.class, worldRenderer);
    // TODO: These shouldn't be done here, nor so strongly tied to the world renderer
    LocalPlayer localPlayer = new LocalPlayer();
    localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
    context.put(LocalPlayer.class, localPlayer);
    context.put(Camera.class, worldRenderer.getActiveCamera());
    return true;
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) LocalChunkProvider(org.terasology.engine.world.chunks.localChunkProvider.LocalChunkProvider) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) WorldProviderWrapper(org.terasology.engine.world.internal.WorldProviderWrapper) ReadOnlyStorageManager(org.terasology.engine.persistence.internal.ReadOnlyStorageManager) StorageManager(org.terasology.engine.persistence.StorageManager) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) BackdropProvider(org.terasology.engine.rendering.backdrop.BackdropProvider) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) DefaultWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.DefaultWorldGeneratorPluginLibrary) WorldProvider(org.terasology.engine.world.WorldProvider) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) FastRandom(org.terasology.engine.utilities.random.FastRandom) IOException(java.io.IOException) WorldProviderCoreImpl(org.terasology.engine.world.internal.WorldProviderCoreImpl) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) DefaultCelestialSystem(org.terasology.engine.world.sun.DefaultCelestialSystem) RenderingSubsystemFactory(org.terasology.engine.core.subsystem.RenderingSubsystemFactory) WorldRenderer(org.terasology.engine.rendering.world.WorldRenderer) BasicCelestialModel(org.terasology.engine.world.sun.BasicCelestialModel) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) BlockManager(org.terasology.engine.world.block.BlockManager) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) Skysphere(org.terasology.engine.rendering.backdrop.Skysphere) Block(org.terasology.engine.world.block.Block) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ReadOnlyStorageManager(org.terasology.engine.persistence.internal.ReadOnlyStorageManager) RelevanceSystem(org.terasology.engine.world.chunks.localChunkProvider.RelevanceSystem)

Example 8 with WorldProvider

use of org.terasology.engine.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.engine.world.WorldProvider)

Example 9 with WorldProvider

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

the class ServerImpl method onChunkReady.

@Override
public void onChunkReady(Vector3ic chunkPos) {
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    List<NetData.BlockChangeMessage> updateBlockMessages = awaitingChunkReadyBlockUpdates.removeAll(new Vector3i(chunkPos));
    for (NetData.BlockChangeMessage message : updateBlockMessages) {
        Vector3i pos = NetMessageUtil.convert(message.getPos());
        Block newBlock = blockManager.getBlock((short) message.getNewBlock());
        worldProvider.setBlock(pos, newBlock);
    }
    List<NetData.ExtraDataChangeMessage> updateExtraDataMessages = awaitingChunkReadyExtraDataUpdates.removeAll(new Vector3i(chunkPos));
    for (NetData.ExtraDataChangeMessage message : updateExtraDataMessages) {
        Vector3i pos = NetMessageUtil.convert(message.getPos());
        int newValue = message.getNewData();
        int i = message.getIndex();
        worldProvider.setExtraData(i, pos, newValue);
    }
}
Also used : NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.engine.world.WorldProvider) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 10 with WorldProvider

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

the class ServerImpl method processExtraDataChanges.

/**
 * Apply the extra-data changes from the message to the local world.
 */
private void processExtraDataChanges(NetData.NetMessage message) {
    for (NetData.ExtraDataChangeMessage extraDataChange : message.getExtraDataChangeList()) {
        WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
        Vector3i pos = NetMessageUtil.convert(extraDataChange.getPos());
        if (worldProvider.isBlockRelevant(pos)) {
            worldProvider.setExtraData(extraDataChange.getIndex(), pos, extraDataChange.getNewData());
        } else {
            awaitingChunkReadyExtraDataUpdates.put(Chunks.toChunkPos(pos), extraDataChange);
        }
    }
}
Also used : NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.engine.world.WorldProvider) Vector3i(org.joml.Vector3i)

Aggregations

WorldProvider (org.terasology.engine.world.WorldProvider)10 BlockManager (org.terasology.engine.world.block.BlockManager)4 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)4 Vector3i (org.joml.Vector3i)3 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)3 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)3 Block (org.terasology.engine.world.block.Block)3 EntityAwareWorldProvider (org.terasology.engine.world.internal.EntityAwareWorldProvider)3 WorldInfo (org.terasology.engine.world.internal.WorldInfo)3 WorldProviderWrapper (org.terasology.engine.world.internal.WorldProviderWrapper)3 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)2 RenderingSubsystemFactory (org.terasology.engine.core.subsystem.RenderingSubsystemFactory)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)2 NetworkSystem (org.terasology.engine.network.NetworkSystem)2 RecordAndReplaySerializer (org.terasology.engine.recording.RecordAndReplaySerializer)2 RecordAndReplayUtils (org.terasology.engine.recording.RecordAndReplayUtils)2 Skysphere (org.terasology.engine.rendering.backdrop.Skysphere)2 WorldRenderer (org.terasology.engine.rendering.world.WorldRenderer)2