Search in sources :

Example 1 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class CreatureKilledMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    localPlayer = CoreRegistry.get(LocalPlayer.class);
    EntityRef playerEntity = localPlayer.getCharacterEntity();
    if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
        telemetryFieldToValue.clear();
        telemetryFieldToValue.putAll(gamePlayStatsComponent.creatureKilled);
        return telemetryFieldToValue;
    } else {
        return telemetryFieldToValue;
    }
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 2 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class GamePlayMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    localPlayer = CoreRegistry.get(LocalPlayer.class);
    EntityRef playerEntity = localPlayer.getCharacterEntity();
    if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
        distanceTraveled = gamePlayStatsComponent.distanceTraveled;
        playTimeMinute = (long) gamePlayStatsComponent.playTimeMinute;
        return super.createTelemetryFieldToValue();
    } else {
        return super.createTelemetryFieldToValue();
    }
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 3 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class AwaitCharacterSpawn method step.

@Override
public boolean step() {
    ComponentSystemManager componentSystemManager = context.get(ComponentSystemManager.class);
    for (UpdateSubscriberSystem updater : componentSystemManager.iterateUpdateSubscribers()) {
        updater.update(0.0f);
    }
    LocalPlayer localPlayer = context.get(LocalPlayer.class);
    ClientComponent client = localPlayer.getClientEntity().getComponent(ClientComponent.class);
    if (client != null && client.character.exists()) {
        client.character.send(new AwaitedLocalCharacterSpawnEvent());
        return true;
    } else {
        chunkProvider.completeUpdate();
        chunkProvider.beginUpdate();
    }
    return false;
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) UpdateSubscriberSystem(org.terasology.entitySystem.systems.UpdateSubscriberSystem) ClientComponent(org.terasology.network.ClientComponent) ComponentSystemManager(org.terasology.engine.ComponentSystemManager)

Example 4 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer 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)

Example 5 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class InitialiseWorld method step.

@Override
public boolean step() {
    BlockManager blockManager = context.get(BlockManager.class);
    BiomeManager biomeManager = context.get(BiomeManager.class);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
    WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
    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(Config.class).getSystem().isWriteSaveGamesEnabled();
    Path savePath = PathManager.getInstance().getSavePath(gameManifest.getTitle());
    StorageManager storageManager;
    try {
        storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(savePath, environment, entityManager, blockManager, biomeManager) : new ReadOnlyStorageManager(savePath, environment, entityManager, blockManager, biomeManager);
    } 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, biomeManager);
    context.get(ComponentSystemManager.class).register(new RelevanceSystem(chunkProvider), "engine: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);
    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;
    BackdropRenderer backdropRenderer = skysphere;
    context.put(BackdropProvider.class, backdropProvider);
    context.put(BackdropRenderer.class, backdropRenderer);
    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
    context.put(LocalPlayer.class, new LocalPlayer());
    context.put(Camera.class, worldRenderer.getActiveCamera());
    return true;
}
Also used : WorldGenerator(org.terasology.world.generator.WorldGenerator) WorldGeneratorManager(org.terasology.world.generator.internal.WorldGeneratorManager) UnresolvedWorldGeneratorException(org.terasology.world.generator.UnresolvedWorldGeneratorException) LocalChunkProvider(org.terasology.world.chunks.localChunkProvider.LocalChunkProvider) LocalPlayer(org.terasology.logic.players.LocalPlayer) WorldProviderWrapper(org.terasology.world.internal.WorldProviderWrapper) ReadOnlyStorageManager(org.terasology.persistence.internal.ReadOnlyStorageManager) ReadWriteStorageManager(org.terasology.persistence.internal.ReadWriteStorageManager) StorageManager(org.terasology.persistence.StorageManager) ModuleManager(org.terasology.engine.module.ModuleManager) EntityAwareWorldProvider(org.terasology.world.internal.EntityAwareWorldProvider) BackdropProvider(org.terasology.rendering.backdrop.BackdropProvider) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) DefaultWorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.DefaultWorldGeneratorPluginLibrary) EntityAwareWorldProvider(org.terasology.world.internal.EntityAwareWorldProvider) WorldProvider(org.terasology.world.WorldProvider) WorldInfo(org.terasology.world.internal.WorldInfo) BiomeManager(org.terasology.world.biomes.BiomeManager) EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) FastRandom(org.terasology.utilities.random.FastRandom) IOException(java.io.IOException) WorldProviderCoreImpl(org.terasology.world.internal.WorldProviderCoreImpl) DefaultCelestialSystem(org.terasology.world.sun.DefaultCelestialSystem) RenderingSubsystemFactory(org.terasology.engine.subsystem.RenderingSubsystemFactory) WorldRenderer(org.terasology.rendering.world.WorldRenderer) BasicCelestialModel(org.terasology.world.sun.BasicCelestialModel) EntityManager(org.terasology.entitySystem.entity.EntityManager) EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) BlockManager(org.terasology.world.block.BlockManager) ModuleEnvironment(org.terasology.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.modes.StateMainMenu) Skysphere(org.terasology.rendering.backdrop.Skysphere) Block(org.terasology.world.block.Block) ReadWriteStorageManager(org.terasology.persistence.internal.ReadWriteStorageManager) ReadOnlyStorageManager(org.terasology.persistence.internal.ReadOnlyStorageManager) RelevanceSystem(org.terasology.world.chunks.localChunkProvider.RelevanceSystem) BackdropRenderer(org.terasology.rendering.backdrop.BackdropRenderer)

Aggregations

LocalPlayer (org.terasology.logic.players.LocalPlayer)11 EntityRef (org.terasology.entitySystem.entity.EntityRef)8 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)5 ClientComponent (org.terasology.network.ClientComponent)4 GamePlayStatsComponent (org.terasology.telemetry.GamePlayStatsComponent)4 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)3 RenderingSubsystemFactory (org.terasology.engine.subsystem.RenderingSubsystemFactory)2 EntityManager (org.terasology.entitySystem.entity.EntityManager)2 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)2 InputSystem (org.terasology.input.InputSystem)2 ConsoleImpl (org.terasology.logic.console.ConsoleImpl)2 ConsoleSystem (org.terasology.logic.console.ConsoleSystem)2 CoreCommands (org.terasology.logic.console.commands.CoreCommands)2 BackdropProvider (org.terasology.rendering.backdrop.BackdropProvider)2 BackdropRenderer (org.terasology.rendering.backdrop.BackdropRenderer)2 Skysphere (org.terasology.rendering.backdrop.Skysphere)2 WorldRenderer (org.terasology.rendering.world.WorldRenderer)2 WorldProvider (org.terasology.world.WorldProvider)2 BlockManager (org.terasology.world.block.BlockManager)2 EntityAwareWorldProvider (org.terasology.world.internal.EntityAwareWorldProvider)2