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