Example usage for net.minecraftforge.client.event.sound PlaySoundEvent getResultSound

List of usage examples for net.minecraftforge.client.event.sound PlaySoundEvent getResultSound

Introduction

In this page you can find the example usage for net.minecraftforge.client.event.sound PlaySoundEvent getResultSound.

Prototype

public ISound getResultSound() 

Source Link

Usage

From source file:com.lothrazar.cyclicmagic.block.BlockSoundSuppress.java

License:Open Source License

@SideOnly(Side.CLIENT)
@SubscribeEvent//from  w w w . java  2s .  com
public void onPlaySound(PlaySoundEvent event) {
    if (event.getResultSound() == null || event.getResultSound() instanceof ITickableSound
            || ModCyclic.proxy.getClientWorld() == null) {
        return;
    } //long term/repeating/music
    ISound sound = event.getResultSound();
    List<BlockPos> blocks = UtilWorld.findBlocks(ModCyclic.proxy.getClientWorld(),
            new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF()), this, RADIUS);
    if (blocks == null || blocks.size() == 0) {
        return;
    }
    try {//WARNING": DO NOT USE getVolume anywhere here it just crashes
         //we do use it inside the sound class, but the engine callss tat later on, and our factor is tacked in
        SoundVolumeControlled newSound = new SoundVolumeControlled(sound);
        //the number of nearby blocks informs how much we muffle the sound by
        float pct = (VOL_REDUCE_PER_BLOCK) / 100F;
        newSound.setVolume(pct / blocks.size());
        event.setResultSound(newSound);
    } catch (Exception e) {
        ModCyclic.logger.error("Error trying to detect volume of sound from 3rd party ");
        ModCyclic.logger.error(e.getMessage());
        e.printStackTrace();//getVolume() in naive Positioned sound event gives NPE
    }
}