Java 类net.minecraftforge.client.event.sound.PlaySoundEvent 实例源码

项目:Melodium    文件:ItemCompositionPaper.java   
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void handleHearingSounds(PlaySoundEvent event) {
    EntityPlayer p = Minecraft.getMinecraft().player;
    if (p != null)
    {
        Tuple<SoundType, Double> result = getTypeFromSound(event.getName(), event.getSound());
        if (p.getHeldItemMainhand().getItem() == this)
        {
            if (addSound(p.getHeldItemMainhand(), result.getFirst(), result.getSecond())){
                PacketHandler.INSTANCE.sendToServer(new MessageCompositionUpdate(p.getUniqueID(),p.getHeldItemMainhand().getTagCompound(),true));
            }
        } else if (p.getHeldItemOffhand().getItem() == this) {
            if (addSound(p.getHeldItemOffhand(), result.getFirst(), result.getSecond())){
                PacketHandler.INSTANCE.sendToServer(new MessageCompositionUpdate(p.getUniqueID(),p.getHeldItemOffhand().getTagCompound(),false));
            }
        }
    }
}
项目:CrystalMod    文件:ClientEventHandler.java   
@SubscribeEvent
public void playSound(PlaySoundEvent event){
    World world = CrystalMod.proxy.getClientWorld();
    if(world == null)return;
    ISound sound = event.getSound();
    //if(sound instanceof ITickableSound)return;
    AxisAlignedBB bb = new AxisAlignedBB(sound.getXPosF(), sound.getYPosF(), sound.getZPosF(), sound.getXPosF(), sound.getYPosF(), sound.getZPosF()).expand(16, 16, 16);
    List<TileSoundMuffler> mufflers = BlockUtil.searchBoxForTiles(world, bb, TileSoundMuffler.class, null);
    for(TileSoundMuffler muffler : mufflers){
        if(muffler.isSoundInList(sound.getSoundLocation())){
            if(muffler.getVolume() <= 0.0f){
                event.setResultSound(null);
            } else {
                event.setResultSound(new WrappedSound(event.getSound(), muffler.getVolume()));
            }
            break;
        }
    }
}
项目:Aether-Legacy    文件:AetherMusicHandler.java   
@SubscribeEvent
public void onMusicControl(PlaySoundEvent event)
{
    ISound sound = event.getSound();
    SoundCategory category = sound.getCategory();

    if (category == SoundCategory.MUSIC)
    {
        if (this.mc.thePlayer != null && this.mc.thePlayer.dimension == AetherConfig.getAetherDimensionID())
        {
            if (!sound.getSoundLocation().toString().contains("aether_legacy") && (this.musicTicker.playingMusic() || !this.musicTicker.playingMusic()))
            {
                event.setResultSound(null);

                return;
            }
        }
    }
    else if (category == SoundCategory.RECORDS)
    {
        this.musicTicker.stopMusic();
        this.mc.getSoundHandler().stopSounds();

        return;
    }
}
项目:accesstweaks    文件:Sounds.java   
/** Play or prevent sound and subtitle according to settings.
 * This event catches some entity & all other sounds */
@SubscribeEvent
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());
    }
}
项目:DynamicSurroundings    文件:SoundCullHandler.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void soundEvent(final PlaySoundEvent event) {
    if (event.getSound() == null || event.getSound() instanceof ConfigSound)
        return;

    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);
    }
}
项目:Factorization    文件:MiscClientProxy.java   
@SubscribeEvent(priority = EventPriority.LOW)
public void supressExcessiveSound(PlaySoundEvent event) {
    // Basically, divide the volume by the number of events minus some threshold
    Minecraft mc = Minecraft.getMinecraft();
    if (mc.theWorld == null) {
        present_tick = -100;
        return;
    }
    if (event.result == null) return;
    if (event.isCanceled()) return;
    long now = mc.theWorld.getTotalWorldTime();
    if (now != present_tick) {
        present_tick = now;
        event_count = 0;
    }
    if (event_count++ < max_event) return;
    final double origVolume = event.result.getVolume();
    final float newVolume = (float)(origVolume / Math.log(event_count) * logMax);
    event.result = new ProxiedSound(event.result) {
        @Override
        public float getVolume() {
            return newVolume;
        }
    };
}
项目:TFC2    文件:BackgroundMusicHandler.java   
@SubscribeEvent
public void onBGMusic(PlaySoundEvent event)
{
    if(event.getSound() != null && event.getSound().getCategory() != null && event.getSound().getCategory() == SoundCategory.MUSIC)
    {
        if(event.getManager().isSoundPlaying(iSound))
        {
            event.setResultSound(null);
        }
        else
        {
            iSound = PositionedSoundRecord.getMusicRecord(TFC_Sounds.TFCMUSIC);
            event.setResultSound(iSound);
        }
    }
}
项目:Kingdom-Keys-Re-Coded    文件:ClientEventHandler.java   
@SubscribeEvent
public void musicControl(PlaySoundEvent event) {
    ISound sound = event.getSound();
    SoundCategory category = sound.getCategory();
    if (category == SoundCategory.MUSIC) {
        if (!sound.getSoundLocation().toString().contains("kk") && MainConfig.client.sound.EnableCustomMusic) {
            event.setResultSound(null);
            return;
        }
        if (!sound.getSoundLocation().toString().contains("kk") && this.musicHandler.isPlaying() && MainConfig.client.sound.EnableCustomMusic) {
            event.setResultSound(null);
            return;
        } else {
            if (MainConfig.client.sound.EnableCustomMusic) {
                musicHandler.stopSound(sound);
            }
        }
    } else if (category == SoundCategory.RECORDS) {
        this.musicHandler.stopMusic();
        this.mc.getSoundHandler().stopSounds();
        return;
    }
}
项目:Cyclic    文件:BlockSoundSuppress.java   
@SideOnly(Side.CLIENT)
@SubscribeEvent
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 = ((float) 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
  }
}
项目:TFC2    文件:BackgroundMusicHandler.java   
@SubscribeEvent
public void onBGMusic(PlaySoundEvent event)
{
    if(event.getSound() != null && event.getSound().getCategory() != null && event.getSound().getCategory() == SoundCategory.MUSIC)
    {
        if(event.getManager().isSoundPlaying(iSound))
        {
            event.setResultSound(null);
        }
        else
        {
            iSound = PositionedSoundRecord.getMusicRecord(TFC_Sounds.TFCMUSIC);
            event.setResultSound(iSound);
        }
    }
}
项目:OpenBlocks    文件:SoundEventsManager.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onSoundEvent(PlaySoundEvent evt) {
    if (SoundEventsManager.isPlayerWearingGlasses()) {
        final ISound sound = evt.getResultSound();
        if (sound != null) {
            // NOTE do not remove, otherwise sound.getVolume will throw NPE
            if (sound.createAccessor(evt.getManager().sndHandler) != null) {
                final IDrawableIcon icon = icons.getIcon(sound.getSoundLocation());

                synchronized (events) {
                    events.add(new SoundEvent(sound, icon, Math.log(sound.getVolume() + 1), sound.getPitch()));
                }
            }
        }
    }
}
项目:EssentialFeatures    文件:ClientEventHandler.java   
@SubscribeEvent
public void playSoundEvent (PlaySoundEvent event) {
    if (event.getSound().getCategory() == SoundCategory.MUSIC && !event.getName().startsWith("music.essential_features")) {
            ISound result = CustomMusic.PlayMusic(event.getSound());
            event.setResultSound(result);
    }
}
项目:DynamicSurroundings    文件:SoundEffectHandler.java   
@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);
    }
}
项目:morecommands    文件:CommandMusic.java   
@Override
public void onEvent(PlaySoundEvent event) {
    if (event.getSound().getCategory() == SoundCategory.MUSIC) {
        if (this.stopSound) 
            event.setResultSound(null);
    }
}
项目:ARKCraft-Code    文件:CoreClientEventHandler.java   
@SubscribeEvent
public void playSound(PlaySoundEvent event)
{
    if (!(event.name.contains("ark_theme")) && mc.currentScreen instanceof GuiMainMenuOverride)
    {
        event.result = null;
    }
}
项目:mod_autofish    文件:EventListener.java   
/**
 * Use the PlaySoundEvent to listen for bobber splashing
 * 
 * @param event
 */
@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
    if (ModAutoFish.config_autofish_enable && SoundEvents.ENTITY_BOBBER_SPLASH.getSoundName() == event.getSound().getSoundLocation()) {
        _autoFish.onBobberSplashDetected(event.getSound().getXPosF(), event.getSound().getYPosF(), event.getSound().getZPosF());
    }
}
项目:Allomancy    文件:ClientEventHandler.java   
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onSound(PlaySoundEvent event) {
    double motionX, motionY, motionZ, magnitude;

    player = this.mc.player;
    ISound sound = event.getSound();
    if ((player == null) || (sound == null)) {
        return;
    }

    magnitude = Math.sqrt(Math.pow((player.posX - sound.getXPosF()), 2) + Math.pow((player.posY - sound.getYPosF()), 2) + Math.pow((player.posZ - sound.getZPosF()), 2));
    if (((magnitude) > 20) || ((magnitude) < .5)) {
        return;
    }
    AllomancyCapability cap = AllomancyCapability.forPlayer(player);
    // Spawn sound particles
    if (cap.getMetalBurning(AllomancyCapability.TIN)) {
        if (sound.getSoundLocation().toString().contains("step") || sound.getSoundLocation().toString().contains("entity") || sound.getSoundLocation().toString().contains("hostile") || sound.getSoundLocation().toString().contains(".big")
                || sound.getSoundLocation().toString().contains("scream") || sound.getSoundLocation().toString().contains("bow")) {
            motionX = ((player.posX - (event.getSound().getXPosF() + .5)) * -0.7) / magnitude;
            motionY = ((player.posY - (event.getSound().getYPosF() + .2)) * -0.7) / magnitude;
            motionZ = ((player.posZ - (event.getSound().getZPosF() + .5)) * -0.7) / magnitude;
            Particle particle = new ParticleSound(player.world, player.posX + (Math.sin(Math.toRadians(player.getRotationYawHead())) * -.7d), player.posY + .2, player.posZ + (Math.cos(Math.toRadians(player.getRotationYawHead())) * .7d), motionX,
                    motionY, motionZ, sound);
            this.mc.effectRenderer.addEffect(particle);
        }

    }
}
项目:EnergyFromMatter    文件:CustomSoundManager.java   
/**
 * Plays a sound. Args: soundName, x, y, z, volume, pitch, fadeOutTime
 */
public static String playSound(String par1Str, float par2, float par3,
        float par4, float par5, float par6)
{
    SoundPoolEntry soundpoolentry = sndManager.soundPoolSounds
            .getRandomSoundFromSoundPool(par1Str);
    soundpoolentry = SoundEvent.getResult(new PlaySoundEvent(sndManager,
            soundpoolentry, par1Str, par2, par3, par4, par5, par6));

    if (soundpoolentry != null && par5 > 0.0F)
    {
        latestSoundID = 256 + ((latestSoundID + 1) % 256);
        String s1 = "sound_" + latestSoundID;
        float f5 = 16.0F;

        if (par5 > 1.0F)
        {
            f5 *= par5;
        }

        sndManager.sndSystem.newSource(par5 > 1.0F, s1,
                soundpoolentry.getSoundUrl(),
                soundpoolentry.getSoundName(), false, par2, par3, par4, 2,
                f5);

        if (par5 > 1.0F)
        {
            par5 = 1.0F;
        }

        sndManager.sndSystem.setPitch(s1, par6);
        sndManager.sndSystem.setVolume(s1, par5
                * Minecraft.getMinecraft().gameSettings.soundVolume);
        MinecraftForge.EVENT_BUS.post(new PlaySoundSourceEvent(sndManager,
                s1, par2, par3, par4));
        sndManager.sndSystem.play(s1);
        return s1;
    }
    return null;
}
项目:Nucleum-Omnium    文件:EventHandler.java   
@SideOnly(Side.CLIENT)
@ForgeSubscribe
public void soundEvent(PlaySoundEvent event)
{
    if (NucleumOmnium.getConfig().noRainNoise && (event != null) && (event.source != null) && event.source.getSoundName().startsWith("ambient/weather/rain"))
    {
        event.result = null;
    }
}
项目:CustomWorldGen    文件:ForgeHooksClient.java   
public static ISound playSound(SoundManager manager, ISound sound)
{
    PlaySoundEvent e = new PlaySoundEvent(manager, sound);
    MinecraftForge.EVENT_BUS.post(e);
    return e.getResultSound();
}