Search in sources :

Example 1 with WorldProvider

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

the class StorageManagerTest method setup.

@BeforeEach
public void setup(@TempDir Path tempHome) throws Exception {
    super.setup();
    PathManager.getInstance().useOverrideHomePath(tempHome);
    savePath = PathManager.getInstance().getSavePath("testSave");
    assert !Files.isRegularFile(tempHome.resolve("global.dat"));
    entityManager = context.get(EngineEntityManager.class);
    moduleEnvironment = mock(ModuleEnvironment.class);
    blockManager = context.get(BlockManager.class);
    extraDataManager = context.get(ExtraBlockDataManager.class);
    ModuleManager moduleManager = mock(ModuleManager.class);
    when(moduleManager.getEnvironment()).thenReturn(moduleEnvironment);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    recordAndReplayUtils = new RecordAndReplayUtils();
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
    recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    context.put(StorageManager.class, esm);
    this.character = entityManager.create();
    Client client = createClientMock(PLAYER_ID, character);
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
    context.put(NetworkSystem.class, networkSystem);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
    data.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
    testBlock = context.get(BlockManager.class).getBlock("test:testblock");
    testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
    context.put(ChunkProvider.class, mock(ChunkProvider.class));
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    context.put(WorldProvider.class, worldProvider);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) WorldProvider(org.terasology.engine.world.WorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Client(org.terasology.engine.network.Client) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with WorldProvider

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

the class NetworkSystemImpl method getServerInfoMessage.

private NetData.ServerInfoMessage getServerInfoMessage(String errorMessage) {
    NetData.ServerInfoMessage.Builder serverInfoMessageBuilder = NetData.ServerInfoMessage.newBuilder();
    serverInfoMessageBuilder.setTime(time.getGameTimeInMs());
    if (config.getServerMOTD() != null) {
        serverInfoMessageBuilder.setMOTD(config.getServerMOTD());
    }
    serverInfoMessageBuilder.setOnlinePlayersAmount(clientList.size());
    WorldProvider worldProvider = context.get(WorldProvider.class);
    if (worldProvider != null) {
        NetData.WorldInfo.Builder worldInfoBuilder = NetData.WorldInfo.newBuilder();
        worldInfoBuilder.setTime(worldProvider.getTime().getMilliseconds());
        worldInfoBuilder.setTitle(worldProvider.getTitle());
        serverInfoMessageBuilder.addWorldInfo(worldInfoBuilder);
    }
    WorldGenerator worldGen = context.get(WorldGenerator.class);
    if (worldGen != null) {
        serverInfoMessageBuilder.setReflectionHeight(worldGen.getWorld().getSeaLevel() + 0.5f);
    }
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        if (!StandardModuleExtension.isServerSideOnly(module)) {
            serverInfoMessageBuilder.addModule(NetData.ModuleInfo.newBuilder().setModuleId(module.getId().toString()).setModuleVersion(module.getVersion().toString()).build());
        }
    }
    for (Map.Entry<String, Short> blockMapping : blockManager.getBlockIdMap().entrySet()) {
        serverInfoMessageBuilder.addBlockId(blockMapping.getValue());
        serverInfoMessageBuilder.addBlockName(blockMapping.getKey());
    }
    for (BlockFamily registeredBlockFamily : blockManager.listRegisteredBlockFamilies()) {
        serverInfoMessageBuilder.addRegisterBlockFamily(registeredBlockFamily.getURI().toString());
    }
    if (errorMessage != null && !errorMessage.isEmpty()) {
        serverInfoMessageBuilder.setErrorMessage(errorMessage);
    }
    serializeComponentInfo(serverInfoMessageBuilder);
    serializeEventInfo(serverInfoMessageBuilder);
    return serverInfoMessageBuilder.build();
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) ByteString(com.google.protobuf.ByteString) ModuleManager(org.terasology.engine.core.module.ModuleManager) WorldProvider(org.terasology.engine.world.WorldProvider) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) Module(org.terasology.gestalt.module.Module) Map(java.util.Map) TIntLongMap(gnu.trove.map.TIntLongMap) TIntLongHashMap(gnu.trove.map.hash.TIntLongHashMap)

Example 3 with WorldProvider

use of org.terasology.engine.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();
    localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
    context.put(LocalPlayer.class, localPlayer);
    BlockManager blockManager = context.get(BlockManager.class);
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.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, extraDataManager);
    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
    context.put(BackdropProvider.class, new Skysphere(context));
    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.engine.logic.players.LocalPlayer) WorldProviderWrapper(org.terasology.engine.world.internal.WorldProviderWrapper) NetworkSystem(org.terasology.engine.network.NetworkSystem) WorldProviderCoreImpl(org.terasology.engine.world.internal.WorldProviderCoreImpl) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) DefaultCelestialSystem(org.terasology.engine.world.sun.DefaultCelestialSystem) RenderingSubsystemFactory(org.terasology.engine.core.subsystem.RenderingSubsystemFactory) WorldRenderer(org.terasology.engine.rendering.world.WorldRenderer) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) BasicCelestialModel(org.terasology.engine.world.sun.BasicCelestialModel) BlockManager(org.terasology.engine.world.block.BlockManager) Skysphere(org.terasology.engine.rendering.backdrop.Skysphere) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) WorldProvider(org.terasology.engine.world.WorldProvider) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) RemoteChunkProvider(org.terasology.engine.world.chunks.remoteChunkProvider.RemoteChunkProvider)

Example 4 with WorldProvider

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

the class ServerImpl method processBlockChanges.

/**
 * Apply the block changes from the message to the local world.
 */
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(Chunks.toChunkPos(pos), blockChange);
        }
    }
}
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 5 with WorldProvider

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

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