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

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

Introduction

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

Prototype

public void setResultSound(ISound result) 

Source Link

Usage

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

License:Open Source License

@SideOnly(Side.CLIENT)
@SubscribeEvent/*  w  ww .jav  a 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
    }
}

From source file:com.masl.mp3Jukebox.Player.java

License:Open Source License

@SubscribeEvent
@SideOnly(Side.CLIENT)//from   w w  w .  j  av  a  2  s.co m
public void PlaySoundEvent(PlaySoundEvent event) {

    if (event.getSound().getCategory() == SoundCategory.MUSIC && soundPlaying) {

        mp3Jukebox.logger.log(Level.DEBUG, "Stoped Streamed Sound:  " + event.getSound().getCategory());

        event.setResultSound(null);
    } else if (event.getSound().getCategory() == SoundCategory.MUSIC) {
        currentMusic = event.getSound();
    }
}

From source file:jayavery.accesstweaks.Sounds.java

License:Open Source License

/** Play or prevent sound and subtitle according to settings.
 * This event catches some entity & all other sounds */
@SubscribeEvent//from   w w  w . j a  v  a 2 s  .c o m
public static void playSound(PlaySoundEvent event) {

    ISound sound = event.getSound();
    SoundCategory category = SoundCategory.categorise(sound);
    SoundResult result = categoryResults.get(category);

    if (!result.playSound()) {

        event.setResultSound(null);
    }

    if (result.showSubtitle()) {

        guiSubtitles.addSubtitle(sound,
                Minecraft.getMinecraft().getSoundHandler().getAccessor(event.getSound().getSoundLocation()),
                result.getColour());
    }
}

From source file:org.blockartistry.DynSurround.client.handlers.SoundCullHandler.java

License:MIT License

@SubscribeEvent(priority = EventPriority.LOWEST)
public void soundEvent(final PlaySoundEvent event) {
    if (event.getSound() == null || event.getSound() instanceof ConfigSound)
        return;/*  w  w w. j a  va 2 s  .c  o m*/

    final String resource = event.getSound().getSoundLocation().toString();
    if (this.soundsToBlock.contains(resource)) {
        event.setResultSound(null);
        return;
    }

    if (ModOptions.soundCullingThreshold <= 0)
        return;

    // Get the last time the sound was seen
    final int lastOccurance = this.soundCull.get(resource);
    if (lastOccurance == 0)
        return;

    final int currentTick = EnvironState.getTickCounter();
    if ((currentTick - lastOccurance) < ModOptions.soundCullingThreshold) {
        event.setResultSound(null);
    } else {
        this.soundCull.put(resource, currentTick);
    }
}

From source file:org.blockartistry.DynSurround.client.handlers.SoundEffectHandler.java

License:MIT License

@SubscribeEvent
public void soundPlay(@Nonnull final PlaySoundEvent e) {
    if (e.getName().equals("entity.lightning.thunder")) {
        final ISound sound = e.getSound();
        final BlockPos pos = new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
        final ISound newSound = Sounds.THUNDER.createSound(pos).setVolume(ModOptions.thunderVolume);
        e.setResultSound(newSound);
    }//from  w w  w .  j  av a 2 s.  c  om
}

From source file:org.blockartistry.mod.DynSurround.client.PlayerSoundEffectHandler.java

License:MIT License

@SubscribeEvent
public void soundEvent(final PlaySoundEvent event) {
    if (event.getSound() == null)
        return;//from  w  w  w .j  ava 2s . c om

    if ((ModOptions.alwaysOverrideSound || !StormProperties.doVanilla()) && replaceRainSound(event.getName())) {
        final ISound sound = event.getSound();
        event.setResultSound(new PositionedSoundRecord(StormProperties.getCurrentStormSound(),
                SoundCategory.WEATHER, StormProperties.getCurrentVolume(), sound.getPitch(), sound.getXPosF(),
                sound.getYPosF(), sound.getZPosF()));
        return;
    }
}

From source file:org.blockartistry.mod.DynSurround.client.SoundControlHandler.java

License:MIT License

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void soundEvent(final PlaySoundEvent event) {
    if (event.getSound() == null)
        return;//from www.ja v a 2 s . c  o m

    final String resource = event.getSound().getSoundLocation().toString();
    if (this.soundsToBlock.contains(resource)) {
        event.setResultSound(null);
        return;
    }

    if (ModOptions.soundCullingThreshold <= 0)
        return;

    // Get the last time the sound was seen
    final int lastOccurance = this.soundCull.get(resource);
    if (lastOccurance == 0)
        return;

    final int currentTick = EnvironState.getTickCounter();
    if ((currentTick - lastOccurance) < ModOptions.soundCullingThreshold) {
        event.setResultSound(null);
        return;
    } else {
        this.soundCull.put(resource, currentTick);
    }
}

From source file:org.blockartistry.mod.DynSurround.client.SoundControlHandler.java

License:MIT License

@SubscribeEvent(priority = EventPriority.LOWEST)
public void soundEventLast(final PlaySoundEvent event) {
    if (event.getSound() == null)
        return;//from  www.j  a  v  a2s .c o m

    final String resource = event.getSound().getSoundLocation().toString();
    if (SoundRegistry.hasCustomVolumeScale(resource))
        event.setResultSound(new SoundShim(event.getSound(), SoundRegistry.getCustomVolumeScale(resource)));
}

From source file:valkyrienwarfare.mod.event.EventsClient.java

License:Open Source License

@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
    ISound sound = event.getSound();// www.  j  ava  2s .c  o  m
    BlockPos pos = new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager
            .getObjectManagingPos(Minecraft.getMinecraft().world, pos);

    if (wrapper != null) {
        Vector newSoundLocation = new Vector(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
        RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, newSoundLocation);

        SoundFixWrapper soundFix = new SoundFixWrapper(sound, wrapper, newSoundLocation);

        event.setResultSound(soundFix);
    }
}

From source file:vazkii.quark.world.feature.OceanGuardians.java

License:Creative Commons License

@SubscribeEvent
@SideOnly(Side.CLIENT)/*w  w w . j a  v a 2  s  .co  m*/
public void onSound(PlaySoundEvent event) {
    if (!tweakSound)
        return;

    ISound sound = event.getSound();
    if (sound instanceof GuardianSound) {
        GuardianSound gsound = (GuardianSound) sound;
        EntityGuardian guardian = ReflectionHelper.getPrivateValue(GuardianSound.class, gsound,
                LibObfuscation.GUARDIAN);
        event.setResultSound(new GuardianSound2UnderwaterBoogaloo(guardian));
    }
}