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);
}
}
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);
}
}
}
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);
}
}
}
}
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;
}
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;
}
Aggregations