Search in sources :

Example 1 with AffectorFunction

use of org.terasology.engine.particles.functions.affectors.AffectorFunction 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)

Aggregations

Type (java.lang.reflect.Type)1 ParticleEmitterComponent (org.terasology.engine.particles.components.ParticleEmitterComponent)1 ParticleSystemFunction (org.terasology.engine.particles.functions.ParticleSystemFunction)1 RegisterParticleSystemFunction (org.terasology.engine.particles.functions.RegisterParticleSystemFunction)1 AffectorFunction (org.terasology.engine.particles.functions.affectors.AffectorFunction)1 GeneratorFunction (org.terasology.engine.particles.functions.generators.GeneratorFunction)1 Component (org.terasology.gestalt.entitysystem.component.Component)1 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)1