Search in sources :

Example 1 with ParticleOption

use of org.spongepowered.api.effect.particle.ParticleOption in project SpongeCommon by SpongePowered.

the class SpongeParticleEffectBuilder method buildContent.

@Override
protected Optional<ParticleEffect> buildContent(DataView container) throws InvalidDataException {
    if (!container.contains(DataQueries.PARTICLE_TYPE, DataQueries.PARTICLE_OPTIONS)) {
        return Optional.empty();
    }
    ParticleType particleType = container.getCatalogType(DataQueries.PARTICLE_TYPE, ParticleType.class).get();
    Map<ParticleOption<?>, Object> options = new HashMap<>();
    container.getViewList(DataQueries.PARTICLE_OPTIONS).get().forEach(view -> {
        ParticleOption<?> option = view.getCatalogType(DataQueries.PARTICLE_OPTION_KEY, ParticleOption.class).get();
        Object value;
        if (option.getValueType().isAssignableFrom(DataSerializable.class)) {
            value = view.getSerializable(DataQueries.PARTICLE_OPTION_VALUE, (Class<? extends DataSerializable>) option.getValueType()).get();
        } else {
            value = view.getObject(DataQueries.PARTICLE_OPTION_VALUE, option.getValueType()).get();
        }
        options.put(option, value);
    });
    return Optional.of(new SpongeParticleEffect((SpongeParticleType) particleType, options));
}
Also used : ParticleOption(org.spongepowered.api.effect.particle.ParticleOption) HashMap(java.util.HashMap) ParticleType(org.spongepowered.api.effect.particle.ParticleType)

Example 2 with ParticleOption

use of org.spongepowered.api.effect.particle.ParticleOption in project LanternServer by LanternPowered.

the class LanternParticleEffectBuilder method buildContent.

@Override
protected Optional<ParticleEffect> buildContent(DataView container) throws InvalidDataException {
    if (!container.contains(DataQueries.PARTICLE_TYPE, DataQueries.PARTICLE_OPTIONS)) {
        return Optional.empty();
    }
    ParticleType particleType = container.getCatalogType(DataQueries.PARTICLE_TYPE, ParticleType.class).get();
    Map<ParticleOption<?>, Object> options = new HashMap<>();
    container.getViewList(DataQueries.PARTICLE_OPTIONS).get().forEach(view -> {
        ParticleOption option = view.getCatalogType(DataQueries.PARTICLE_OPTION_KEY, ParticleOption.class).get();
        Object value;
        if (option.getValueType().isAssignableFrom(DataSerializable.class)) {
            value = view.getSerializable(DataQueries.PARTICLE_OPTION_VALUE, option.getValueType()).get();
        } else {
            value = view.getObject(DataQueries.PARTICLE_OPTION_VALUE, option.getValueType()).get();
        }
        options.put(option, value);
    });
    return Optional.of(new LanternParticleEffect((LanternParticleType) particleType, options));
}
Also used : ParticleOption(org.spongepowered.api.effect.particle.ParticleOption) HashMap(java.util.HashMap) ParticleType(org.spongepowered.api.effect.particle.ParticleType)

Aggregations

HashMap (java.util.HashMap)2 ParticleOption (org.spongepowered.api.effect.particle.ParticleOption)2 ParticleType (org.spongepowered.api.effect.particle.ParticleType)2