Search in sources :

Example 41 with Component

use of org.terasology.gestalt.entitysystem.component.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.gestalt.entitysystem.component.Component)

Example 42 with Component

use of org.terasology.gestalt.entitysystem.component.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.gestalt.entitysystem.component.Component)

Example 43 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class ParticleUpdaterImpl method initialize.

@Override
public void initialize() {
    ModuleEnvironment environment = moduleManager.getEnvironment();
    for (Class<?> type : environment.getTypesAnnotatedWith(RegisterParticleSystemFunction.class)) {
        RegisterParticleSystemFunction annotation = type.getAnnotation(RegisterParticleSystemFunction.class);
        if (!ParticleSystemFunction.class.isAssignableFrom(type)) {
            logger.error("Cannot register particle system function {}, must be a subclass of ParticleSystemFunction", type.getSimpleName());
        } else {
            try {
                ParticleSystemFunction function = (ParticleSystemFunction) type.newInstance();
                if (function instanceof GeneratorFunction) {
                    Type componentClass = ReflectionUtil.getTypeParameterForSuper(type, GeneratorFunction.class, 0);
                    mapGeneratorFunction((GeneratorFunction) function, (Class<? extends Component>) componentClass);
                } else if (function instanceof AffectorFunction) {
                    Type componentClass = ReflectionUtil.getTypeParameterForSuper(type, AffectorFunction.class, 0);
                    mapAffectorFunction((AffectorFunction) function, (Class<? extends Component>) componentClass);
                }
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register particle system", e);
            }
        }
    }
}
Also used : Type(java.lang.reflect.Type) AffectorFunction(org.terasology.engine.particles.functions.affectors.AffectorFunction) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) RegisterParticleSystemFunction(org.terasology.engine.particles.functions.RegisterParticleSystemFunction) ParticleSystemFunction(org.terasology.engine.particles.functions.ParticleSystemFunction) RegisterParticleSystemFunction(org.terasology.engine.particles.functions.RegisterParticleSystemFunction) Component(org.terasology.gestalt.entitysystem.component.Component) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) GeneratorFunction(org.terasology.engine.particles.functions.generators.GeneratorFunction)

Example 44 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class NetworkEntitySerializer method serializeEntityDelta.

private EntityData.PackedEntity.Builder serializeEntityDelta(EntityRef entityRef, Prefab prefab, FieldSerializeCheck<Component> fieldCheck) {
    EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder();
    entity.setParentPrefabUri(prefab.getName());
    Set<Class<? extends Component>> presentClasses = Sets.newHashSet();
    ByteString.Output fieldIds = ByteString.newOutput();
    ByteString.Output componentFieldCounts = ByteString.newOutput();
    for (Component component : entityRef.iterateComponents()) {
        if (!componentSerializeCheck.serialize(componentLibrary.getMetadata(component.getClass()))) {
            continue;
        }
        presentClasses.add(component.getClass());
        Component prefabComponent = prefab.getComponent(component.getClass());
        if (prefabComponent == null) {
            serializeComponentFull(component, false, fieldCheck, entity, fieldIds, componentFieldCounts, true);
        } else {
            serializeComponentDelta(prefabComponent, component, fieldCheck, entity, fieldIds, componentFieldCounts, true);
        }
    }
    entity.setFieldIds(fieldIds.toByteString());
    entity.setComponentFieldCounts(componentFieldCounts.toByteString());
    for (Component prefabComponent : prefab.iterateComponents()) {
        if (!presentClasses.contains(prefabComponent.getClass()) && componentSerializeCheck.serialize(componentLibrary.getMetadata(prefabComponent.getClass()))) {
            entity.addRemovedComponent(idTable.get(prefabComponent.getClass()));
        }
    }
    return entity;
}
Also used : ByteString(com.google.protobuf.ByteString) Component(org.terasology.gestalt.entitysystem.component.Component)

Example 45 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class NetworkEntitySerializer method serializeEntityFull.

private EntityData.PackedEntity.Builder serializeEntityFull(EntityRef entityRef, FieldSerializeCheck<Component> fieldCheck) {
    EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder();
    ByteString.Output fieldIds = ByteString.newOutput();
    ByteString.Output componentFieldCounts = ByteString.newOutput();
    for (Component component : entityRef.iterateComponents()) {
        if (!componentSerializeCheck.serialize(componentLibrary.getMetadata(component.getClass()))) {
            continue;
        }
        serializeComponentFull(component, false, fieldCheck, entity, fieldIds, componentFieldCounts, true);
    }
    entity.setFieldIds(fieldIds.toByteString());
    entity.setComponentFieldCounts(componentFieldCounts.toByteString());
    return entity;
}
Also used : ByteString(com.google.protobuf.ByteString) Component(org.terasology.gestalt.entitysystem.component.Component)

Aggregations

Component (org.terasology.gestalt.entitysystem.component.Component)57 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)20 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)12 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 OnActivatedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent)11 NetworkComponent (org.terasology.engine.network.NetworkComponent)10 OnChangedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnChangedComponent)9 EntityData (org.terasology.protobuf.EntityData)8 BeforeDeactivateComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent)7 OnAddedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnAddedComponent)7 BlockComponent (org.terasology.engine.world.block.BlockComponent)7 EntityInfoComponent (org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent)6 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)5 ClientComponent (org.terasology.engine.network.ClientComponent)5 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)4 ByteString (com.google.protobuf.ByteString)3