Search in sources :

Example 36 with Component

use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.

the class ParticleUpdaterImpl method configureEmitter.

@Override
public void configureEmitter(final ParticleEmitterComponent emitter, final BiMap<Class<Component>, AffectorFunction> registeredAffectorFunctions, final BiMap<Class<Component>, GeneratorFunction> registeredGeneratorFunctions) {
    emitter.generatorFunctionMap.clear();
    emitter.affectorFunctionMap.clear();
    for (Component c : emitter.ownerEntity.iterateComponents()) {
        if (registeredGeneratorFunctions.containsKey(c.getClass())) {
            emitter.generatorFunctionMap.put(c, registeredGeneratorFunctions.get(c.getClass()));
        } else if (registeredAffectorFunctions.containsKey(c.getClass())) {
            emitter.affectorFunctionMap.put(c, registeredAffectorFunctions.get(c.getClass()));
        }
    }
}
Also used : ParticleEmitterComponent(org.terasology.particles.components.ParticleEmitterComponent) Component(org.terasology.entitySystem.Component)

Example 37 with Component

use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.

the class EntitySetDeltaRecorder method onEntityComponentChange.

public void onEntityComponentChange(EntityRef entity, Class<? extends Component> componentClass) {
    if (entity.isPersistent()) {
        EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity);
        Component component = entity.getComponent(componentClass);
        Component componentSnapshot = componentLibrary.copy(component);
        entityDelta.setChangedComponent(componentSnapshot);
    }
}
Also used : Component(org.terasology.entitySystem.Component)

Example 38 with Component

use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.

the class EntitySetDeltaRecorder method onReactivation.

public void onReactivation(EntityRef entity, Collection<Component> components) {
    if (entity.isPersistent()) {
        EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity);
        for (Component component : components) {
            Component componentSnapshot = componentLibrary.copy(component);
            entityDelta.setChangedComponent(componentSnapshot);
        }
    }
}
Also used : Component(org.terasology.entitySystem.Component)

Example 39 with Component

use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.

the class GlobalStoreBuilder method build.

public EntityData.GlobalStore build(EngineEntityManager entityManager, Iterable<EntityRef> entities) {
    EntityData.GlobalStore.Builder store = EntityData.GlobalStore.newBuilder();
    Map<Class<? extends Component>, Integer> componentIdTable = Maps.newHashMap();
    for (ComponentMetadata<?> componentMetadata : entityManager.getComponentLibrary().iterateComponentMetadata()) {
        store.addComponentClass(componentMetadata.getUri().toString());
        componentIdTable.put(componentMetadata.getType(), componentIdTable.size());
    }
    prefabSerializer.setComponentIdMapping(componentIdTable);
    /*
         * The prefabs can't be obtained from  entityManager.getPrefabManager().listPrefabs() as that might not
         * be thread save.
         */
    Set<Prefab> prefabsRequiredForEntityStorage = new HashSet<>();
    for (EntityRef entityRef : entityManager.getAllEntities()) {
        Prefab prefab = entityRef.getParentPrefab();
        if (prefab != null) {
            prefabsRequiredForEntityStorage.add(prefab);
        }
    }
    for (Prefab prefab : prefabsRequiredForEntityStorage) {
        store.addPrefab(prefabSerializer.serialize(prefab));
    }
    EntitySerializer entitySerializer = new EntitySerializer(entityManager);
    entitySerializer.setComponentIdMapping(componentIdTable);
    for (EntityRef entity : entities) {
        if (entity.isPersistent()) {
            store.addEntity(entitySerializer.serialize(entity));
        }
    }
    store.setNextEntityId(nextEntityId);
    return store.build();
}
Also used : Component(org.terasology.entitySystem.Component) Prefab(org.terasology.entitySystem.prefab.Prefab) EntityRef(org.terasology.entitySystem.entity.EntityRef) HashSet(java.util.HashSet) EntitySerializer(org.terasology.persistence.serializers.EntitySerializer)

Example 40 with Component

use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.

the class PrefabData method createFromPrefab.

public static PrefabData createFromPrefab(Prefab prefab) {
    PrefabData result = new PrefabData();
    for (Component component : prefab.iterateComponents()) {
        result.addComponent(component);
    }
    result.setAlwaysRelevant(prefab.isAlwaysRelevant());
    result.setParent(prefab.getParent());
    result.setPersisted(prefab.isPersisted());
    return result;
}
Also used : Component(org.terasology.entitySystem.Component)

Aggregations

Component (org.terasology.entitySystem.Component)49 EntityRef (org.terasology.entitySystem.entity.EntityRef)15 Prefab (org.terasology.entitySystem.prefab.Prefab)9 LocationComponent (org.terasology.logic.location.LocationComponent)9 EntityData (org.terasology.protobuf.EntityData)8 OnActivatedComponent (org.terasology.entitySystem.entity.lifecycleEvents.OnActivatedComponent)7 NetworkComponent (org.terasology.network.NetworkComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 OnAddedComponent (org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent)6 OnChangedComponent (org.terasology.entitySystem.entity.lifecycleEvents.OnChangedComponent)6 EntityInfoComponent (org.terasology.entitySystem.entity.internal.EntityInfoComponent)5 BeforeDeactivateComponent (org.terasology.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent)5 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)4 ByteString (com.google.protobuf.ByteString)3 Test (org.junit.Test)3 BeforeRemoveComponent (org.terasology.entitySystem.entity.lifecycleEvents.BeforeRemoveComponent)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)3 SectorSimulationComponent (org.terasology.entitySystem.sectors.SectorSimulationComponent)3 ParticleEmitterComponent (org.terasology.particles.components.ParticleEmitterComponent)3 WorldConfigurator (org.terasology.world.generator.WorldConfigurator)3