Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SoundManager {
- public void playSound(ImplSound sound){
- try {
- this.playSoundDirectly(sound);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
- public SoundSystem getMCSoundSystem() {
- net.minecraft.client.audio.SoundManager sndManager=ObfuscationReflectionHelper.getPrivateValue(SoundHandler.class, Minecraft.getMinecraft().getSoundHandler(), "sndManager");
- SoundSystem sndSystem=ObfuscationReflectionHelper.getPrivateValue(net.minecraft.client.audio.SoundManager.class, sndManager, "sndSystem");
- return sndSystem;
- }
- private void playSoundDirectly(ImplSound sound) throws MalformedURLException{
- boolean flag = sound.getReapeat();
- String s=sound.getName()+"8d3j3d9h39d";
- URL soundUrl=ResourceHandler.getResourcePath((sound.getCategory()==SoundCategory.NEUTRAL?"sound":"music")+"/"+sound.getName()+".ogg", FileCategory.SOUND).toUri().toURL();
- float f1 = this.getClampedVolume(sound);
- float f2 = this.getClampedPitch(sound);
- float f3 = sound.getVolume();
- float f = 16.0F;
- if (f3 > 1.0F)
- {
- f *= f3;
- }
- if (sound.getIsStreaming())
- {
- this.getMCSoundSystem().newStreamingSource(false, s, soundUrl, soundUrl.toString(), flag, (float)sound.getX(), (float)sound.getY(), (float)sound.getZ(), 0, f);
- }
- else
- {
- this.getMCSoundSystem().newSource(false, s, soundUrl, soundUrl.toString(), flag, (float)sound.getX(), (float)sound.getY(), (float)sound.getZ(), 2, f);
- }
- this.getMCSoundSystem().setPitch(s, f2);
- this.getMCSoundSystem().setVolume(s, f1);
- this.getMCSoundSystem().play(s);
- }
- public void stopSound(String soundName)
- {
- this.getMCSoundSystem().stop(soundName+"8d3j3d9h39d");
- }
- private float getClampedPitch(ImplSound sound) {
- return MathHelper.clamp_float(sound.getPitch(), 0.5F, 2.0F);
- }
- private float getClampedVolume(ImplSound sound) {
- return MathHelper.clamp_float(sound.getVolume() * this.getVolume(sound.getCategory()), 0.0F, 1.0F);
- }
- private float getVolume(SoundCategory category)
- {
- return category != null && category != SoundCategory.MASTER ? Minecraft.getMinecraft().gameSettings.getSoundLevel(category) : 1.0F;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment