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