Search in sources :

Example 1 with PlaySoundEvent

use of net.minecraftforge.client.event.sound.PlaySoundEvent in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method playSound.

public static ISound playSound(SoundManager manager, ISound sound) {
    PlaySoundEvent e = new PlaySoundEvent(manager, sound);
    MinecraftForge.EVENT_BUS.post(e);
    return e.getResultSound();
}
Also used : PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent)

Example 2 with PlaySoundEvent

use of net.minecraftforge.client.event.sound.PlaySoundEvent in project Railcraft by Railcraft.

the class RCSoundHandler method onPlaySound.

//TODO: test, catch PlaySoundAtEntityEvent?
@SubscribeEvent
public void onPlaySound(PlaySoundEvent event) {
    ISound soundEvent = event.getSound();
    ResourceLocation soundResource = soundEvent.getSoundLocation();
    if (SoundHelper.matchesSoundResource(soundResource, "null")) {
        event.setResultSound(null);
    } else if (SoundHelper.matchesSoundResource(soundResource, "override")) {
        World world = Railcraft.getProxy().getClientWorld();
        if (world != null) {
            float x = soundEvent.getXPosF();
            float y = soundEvent.getYPosF();
            float z = soundEvent.getZPosF();
            BlockPos pos = new BlockPos(x, y, z);
            String soundPath = soundEvent.getSoundLocation().getResourcePath();
            SoundType blockSound = SoundRegistry.getBlockSound(world, pos);
            if (blockSound == null) {
                if (soundPath.contains("place")) {
                    //Play sound later to adjust for the block not being there yet.
                    event.getManager().playDelayedSound(event.getSound(), 3);
                } else if (soundPath.contains("step")) {
                    blockSound = SoundRegistry.getBlockSound(world, pos.down());
                }
            }
            if (blockSound != null) {
                SoundEvent newSound = SoundHelper.matchSoundEvent(soundResource, blockSound);
                ObfuscationReflectionHelper.setPrivateValue(PositionedSound.class, (PositionedSound) soundEvent, newSound.getSoundName(), 3);
            } else {
                event.setResultSound(null);
            }
        }
    }
}
Also used : SoundType(net.minecraft.block.SoundType) ISound(net.minecraft.client.audio.ISound) PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent) SoundEvent(net.minecraft.util.SoundEvent) PositionedSound(net.minecraft.client.audio.PositionedSound) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

PlaySoundEvent (net.minecraftforge.client.event.sound.PlaySoundEvent)2 SoundType (net.minecraft.block.SoundType)1 ISound (net.minecraft.client.audio.ISound)1 PositionedSound (net.minecraft.client.audio.PositionedSound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SoundEvent (net.minecraft.util.SoundEvent)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1