Search in sources :

Example 1 with EffectConfig

use of org.blockartistry.DynSurround.data.xface.EffectConfig in project DynamicSurroundings by OreCruncher.

the class BlockRegistry method register.

public void register(@Nonnull final BlockConfig entry) {
    if (entry.blocks.isEmpty())
        return;
    final SoundRegistry soundRegistry = ClientRegistry.SOUND;
    for (final String blockName : entry.blocks) {
        final BlockInfo blockInfo = BlockInfo.create(blockName);
        if (blockInfo == null) {
            DSurround.log().warn("Unknown block [%s] in block config file", blockName);
            continue;
        }
        final BlockProfile blockData = getOrCreateProfile(blockInfo);
        if (blockData == null) {
            DSurround.log().warn("Unknown block [%s] in block config file", blockName);
            continue;
        }
        // Reset of a block clears all registry
        if (entry.soundReset != null && entry.soundReset.booleanValue())
            blockData.clearSounds();
        if (entry.stepSoundReset != null && entry.stepSoundReset.booleanValue())
            blockData.clearStepSounds();
        if (entry.effectReset != null && entry.effectReset.booleanValue())
            blockData.clearEffects();
        if (entry.chance != null)
            blockData.setChance(entry.chance.intValue());
        if (entry.stepChance != null)
            blockData.setStepChance(entry.stepChance.intValue());
        for (final SoundConfig sr : entry.sounds) {
            if (sr.sound != null && !soundRegistry.isSoundBlocked(sr.sound)) {
                final SoundEffect.Builder b = new SoundEffect.Builder(sr);
                if (sr.soundCategory == null)
                    b.setSoundCategory(SoundCategory.BLOCKS);
                final SoundEffect eff = b.build();
                if (eff.getSoundType() == SoundType.STEP)
                    blockData.addStepSound(eff);
                else
                    blockData.addSound(eff);
            }
        }
        for (final EffectConfig e : entry.effects) {
            if (StringUtils.isEmpty(e.effect))
                continue;
            final BlockEffectType type = BlockEffectType.get(e.effect);
            if (type == BlockEffectType.UNKNOWN) {
                DSurround.log().warn("Unknown block effect type in configuration: [%s]", e.effect);
            } else if (type.isEnabled()) {
                final int chance = e.chance != null ? e.chance.intValue() : 100;
                final BlockEffect blockEffect = type.getInstance(chance);
                if (blockEffect != null) {
                    if (e.conditions != null)
                        blockEffect.setConditions(e.conditions);
                    blockData.addEffect(blockEffect);
                }
            }
        }
    }
}
Also used : SoundEffect(org.blockartistry.DynSurround.client.sound.SoundEffect) BlockEffect(org.blockartistry.DynSurround.client.fx.BlockEffect) SoundConfig(org.blockartistry.DynSurround.data.xface.SoundConfig) BlockEffectType(org.blockartistry.DynSurround.client.fx.BlockEffectType) EffectConfig(org.blockartistry.DynSurround.data.xface.EffectConfig)

Aggregations

BlockEffect (org.blockartistry.DynSurround.client.fx.BlockEffect)1 BlockEffectType (org.blockartistry.DynSurround.client.fx.BlockEffectType)1 SoundEffect (org.blockartistry.DynSurround.client.sound.SoundEffect)1 EffectConfig (org.blockartistry.DynSurround.data.xface.EffectConfig)1 SoundConfig (org.blockartistry.DynSurround.data.xface.SoundConfig)1