Search in sources :

Example 71 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class PlayerStoreBuilder method build.

public EntityData.PlayerStore build(EngineEntityManager entityManager) {
    EntityData.PlayerStore.Builder playerEntityStore = EntityData.PlayerStore.newBuilder();
    playerEntityStore.setCharacterPosX(relevanceLocation.x());
    playerEntityStore.setCharacterPosY(relevanceLocation.y());
    playerEntityStore.setCharacterPosZ(relevanceLocation.z());
    playerEntityStore.setHasCharacter(characterEntityId != null);
    if (characterEntityId != null) {
        EntityRef character = entityManager.getEntity(characterEntityId);
        EntityStorer store = new EntityStorer(entityManager);
        store.store(character, PlayerStoreInternal.CHARACTER);
        storedEntities = store.getStoredEntities();
        playerEntityStore.setStore(store.finaliseStore());
    } else {
        storedEntities = Sets.newHashSet();
    }
    return playerEntityStore.build();
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 72 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class BlockPlacedMetric 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.blockPlacedMap);
        return telemetryFieldToValue;
    } else {
        return telemetryFieldToValue;
    }
}
Also used : LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.engine.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 73 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class LoadEntities method step.

@Override
public boolean step() {
    EntityManager em = context.get(EntityManager.class);
    boolean entityCreated = false;
    for (EntityRef entity : em.getAllEntities()) {
        entityCreated = true;
        logger.error("Entity created before load: {}", entity.toFullDescription());
    }
    if (entityCreated) {
        throw new IllegalStateException("Entity creation detected during component system initialisation, game load aborting");
    }
    StorageManager storageManager = context.get(StorageManager.class);
    try {
        storageManager.loadGlobalStore();
    } catch (IOException e) {
        logger.error("Failed to load global data.", e);
    }
    return true;
}
Also used : EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) StorageManager(org.terasology.engine.persistence.StorageManager) IOException(java.io.IOException) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 74 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class CreateWorldEntity method createWorldPoolsAndEntity.

private EntityRef createWorldPoolsAndEntity() {
    entityManager.createWorldPools(gameManifest);
    EntityRef worldEntity = entityManager.create();
    worldEntity.addComponent(new WorldComponent());
    NetworkComponent networkComponent = new NetworkComponent();
    networkComponent.replicateMode = NetworkComponent.ReplicateMode.ALWAYS;
    worldEntity.addComponent(networkComponent);
    return worldEntity;
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) WorldComponent(org.terasology.engine.world.WorldComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 75 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class CreateWorldEntity method step.

@Override
public boolean step() {
    this.entityManager = context.get(EntityManager.class);
    this.worldGenerator = context.get(WorldGenerator.class);
    this.config = context.get(Config.class);
    this.chunkProvider = context.get(ChunkProvider.class);
    this.worldConfigurator = worldGenerator.getConfigurator();
    Iterator<EntityRef> worldEntityIterator = entityManager.getEntitiesWith(WorldComponent.class).iterator();
    if (worldEntityIterator.hasNext()) {
        EntityRef worldEntity = worldEntityIterator.next();
        worldEntityIterator.forEachRemaining(w -> logger.warn("Ignored extra world {}", w));
        chunkProvider.setWorldEntity(worldEntity);
        // replace the world generator values from the components in the world entity
        worldConfigurator.getProperties().forEach((key, currentComponent) -> {
            Component component = worldEntity.getComponent(currentComponent.getClass());
            if (component != null) {
                worldConfigurator.setProperty(key, component);
            }
        });
    } else {
        // create world entity if one does not exist.
        EntityRef worldEntity = createWorldPoolsAndEntity();
        chunkProvider.setWorldEntity(worldEntity);
        // transfer all world generation parameters from Config to WorldEntity
        SimpleUri generatorUri = worldGenerator.getUri();
        worldConfigurator.getProperties().forEach((key, currentComponent) -> {
            Class<? extends Component> clazz = currentComponent.getClass();
            Component moduleComponent = gameManifest.getModuleConfig(generatorUri, key, clazz);
            if (moduleComponent != null) {
                // configure entity from component
                worldEntity.addComponent(moduleComponent);
                worldConfigurator.setProperty(key, moduleComponent);
            } else {
                worldEntity.addComponent(currentComponent);
            }
        });
    }
    return true;
}
Also used : EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) Config(org.terasology.engine.config.Config) SimpleUri(org.terasology.engine.core.SimpleUri) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) WorldComponent(org.terasology.engine.world.WorldComponent) Component(org.terasology.gestalt.entitysystem.component.Component) NetworkComponent(org.terasology.engine.network.NetworkComponent) WorldComponent(org.terasology.engine.world.WorldComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)298 Test (org.junit.jupiter.api.Test)88 ClientComponent (org.terasology.engine.network.ClientComponent)55 Vector3f (org.joml.Vector3f)51 LocationComponent (org.terasology.engine.logic.location.LocationComponent)44 Vector3i (org.joml.Vector3i)36 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)34 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)29 StringComponent (org.terasology.unittest.stubs.StringComponent)26 NetworkComponent (org.terasology.engine.network.NetworkComponent)23 EntityData (org.terasology.protobuf.EntityData)23 Quaternionf (org.joml.Quaternionf)19 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)19 Component (org.terasology.gestalt.entitysystem.component.Component)19 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)15 Map (java.util.Map)14 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)13 BlockComponent (org.terasology.engine.world.block.BlockComponent)13 Block (org.terasology.engine.world.block.Block)11 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)10