Search in sources :

Example 6 with SoundEffect

use of org.blockartistry.mod.DynSurround.client.sound.SoundEffect in project BetterRain by OreCruncher.

the class PlayerSoundEffectHandler method process.

@Override
public void process(final World world, final EntityPlayer player) {
    // Dead players hear no sounds
    if (player.isDead) {
        resetSounds();
        return;
    }
    final BiomeGenBase playerBiome = EnvironState.getPlayerBiome();
    final String conditions = EnvironState.getConditions();
    final List<SoundEffect> sounds = new ArrayList<SoundEffect>();
    if (doBiomeSounds())
        sounds.addAll(getBiomeSounds(conditions));
    sounds.addAll(BiomeRegistry.getSounds(BiomeRegistry.PLAYER, conditions));
    SoundManager.queueAmbientSounds(sounds);
    if (doBiomeSounds()) {
        SoundEffect sound = BiomeRegistry.getSpotSound(playerBiome, conditions, EnvironState.RANDOM);
        if (sound != null)
            SoundManager.playSoundAtPlayer(player, sound);
    }
    SoundEffect sound = BiomeRegistry.getSpotSound(BiomeRegistry.PLAYER, conditions, EnvironState.RANDOM);
    if (sound != null)
        SoundManager.playSoundAtPlayer(player, sound);
    processWaterDrops();
    SoundManager.update();
}
Also used : SoundEffect(org.blockartistry.mod.DynSurround.client.sound.SoundEffect) ArrayList(java.util.ArrayList) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase)

Example 7 with SoundEffect

use of org.blockartistry.mod.DynSurround.client.sound.SoundEffect in project BetterRain by OreCruncher.

the class PlayerSoundEffectHandler method getBiomeSounds.

private static List<SoundEffect> getBiomeSounds(final String conditions) {
    // Need to collect sounds from all the applicable biomes
    // along with their weights.
    final TObjectIntHashMap<SoundEffect> sounds = new TObjectIntHashMap<SoundEffect>();
    final TObjectIntHashMap<BiomeGenBase> weights = BiomeSurveyHandler.getBiomes();
    for (final BiomeGenBase biome : weights.keySet()) {
        final List<SoundEffect> bs = BiomeRegistry.getSounds(biome, conditions);
        for (final SoundEffect sound : bs) sounds.put(sound, sounds.get(sound) + weights.get(biome));
    }
    // Scale the volumes in the resulting list based on the weights
    final List<SoundEffect> result = new ArrayList<SoundEffect>();
    final int area = BiomeSurveyHandler.getArea();
    for (final SoundEffect sound : sounds.keySet()) {
        final float scale = 0.3F + 0.7F * ((float) sounds.get(sound) / (float) area);
        result.add(SoundEffect.scaleVolume(sound, scale));
    }
    return result;
}
Also used : SoundEffect(org.blockartistry.mod.DynSurround.client.sound.SoundEffect) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) ArrayList(java.util.ArrayList) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase)

Example 8 with SoundEffect

use of org.blockartistry.mod.DynSurround.client.sound.SoundEffect in project BetterRain by OreCruncher.

the class BlockRegistry method getRandomSound.

private static SoundEffect getRandomSound(final List<SoundEffect> list, final Random random, final String conditions) {
    int totalWeight = 0;
    final List<SoundEffect> candidates = new ArrayList<SoundEffect>();
    for (final SoundEffect s : list) if (s.matches(conditions)) {
        candidates.add(s);
        totalWeight += s.weight;
    }
    if (totalWeight <= 0)
        return null;
    if (candidates.size() == 1)
        return candidates.get(0);
    int targetWeight = random.nextInt(totalWeight);
    int i = 0;
    for (i = candidates.size(); (targetWeight -= candidates.get(i - 1).weight) >= 0; i--) ;
    return candidates.get(i - 1);
}
Also used : SoundEffect(org.blockartistry.mod.DynSurround.client.sound.SoundEffect) ArrayList(java.util.ArrayList)

Aggregations

SoundEffect (org.blockartistry.mod.DynSurround.client.sound.SoundEffect)8 ArrayList (java.util.ArrayList)4 Block (net.minecraft.block.Block)2 BiomeGenBase (net.minecraft.world.biome.BiomeGenBase)2 SoundConfig (org.blockartistry.mod.DynSurround.data.config.SoundConfig)2 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Item (net.minecraft.item.Item)1 ItemAxe (net.minecraft.item.ItemAxe)1 ItemStack (net.minecraft.item.ItemStack)1 ItemSword (net.minecraft.item.ItemSword)1 BlockPos (net.minecraft.util.BlockPos)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 BlockEffect (org.blockartistry.mod.DynSurround.client.fx.BlockEffect)1 JetEffect (org.blockartistry.mod.DynSurround.client.fx.JetEffect)1 BiomeConfig (org.blockartistry.mod.DynSurround.data.config.BiomeConfig)1 BlockConfig (org.blockartistry.mod.DynSurround.data.config.BlockConfig)1 Effect (org.blockartistry.mod.DynSurround.data.config.BlockConfig.Effect)1 Color (org.blockartistry.mod.DynSurround.util.Color)1