Guest User

SoundManager.class

a guest
Oct 1st, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. public class SoundManager {
  2.        
  3.     public void playSound(ImplSound sound){
  4.         try {
  5.             this.playSoundDirectly(sound);
  6.         } catch (MalformedURLException e) {
  7.             e.printStackTrace();
  8.         }
  9.     }
  10.    
  11.     public SoundSystem getMCSoundSystem() {
  12.         net.minecraft.client.audio.SoundManager sndManager=ObfuscationReflectionHelper.getPrivateValue(SoundHandler.class, Minecraft.getMinecraft().getSoundHandler(), "sndManager");
  13.         SoundSystem sndSystem=ObfuscationReflectionHelper.getPrivateValue(net.minecraft.client.audio.SoundManager.class, sndManager, "sndSystem");
  14.         return sndSystem;
  15.     }
  16.    
  17.     private void playSoundDirectly(ImplSound sound) throws MalformedURLException{
  18.         boolean flag = sound.getReapeat();
  19.         String s=sound.getName()+"8d3j3d9h39d";
  20.         URL soundUrl=ResourceHandler.getResourcePath((sound.getCategory()==SoundCategory.NEUTRAL?"sound":"music")+"/"+sound.getName()+".ogg", FileCategory.SOUND).toUri().toURL();
  21.        
  22.         float f1 = this.getClampedVolume(sound);
  23.         float f2 = this.getClampedPitch(sound);
  24.         float f3 = sound.getVolume();
  25.         float f = 16.0F;
  26.  
  27.         if (f3 > 1.0F)
  28.         {
  29.             f *= f3;
  30.         }
  31.        
  32.         if (sound.getIsStreaming())
  33.         {
  34.             this.getMCSoundSystem().newStreamingSource(false, s, soundUrl, soundUrl.toString(), flag, (float)sound.getX(), (float)sound.getY(), (float)sound.getZ(), 0, f);
  35.         }
  36.         else
  37.         {
  38.             this.getMCSoundSystem().newSource(false, s, soundUrl, soundUrl.toString(), flag, (float)sound.getX(), (float)sound.getY(), (float)sound.getZ(), 2, f);
  39.         }
  40.  
  41.         this.getMCSoundSystem().setPitch(s, f2);
  42.         this.getMCSoundSystem().setVolume(s, f1);
  43.         this.getMCSoundSystem().play(s);
  44.     }
  45.  
  46.     public void stopSound(String soundName)
  47.     {
  48.         this.getMCSoundSystem().stop(soundName+"8d3j3d9h39d");
  49.     }
  50.    
  51.     private float getClampedPitch(ImplSound sound) {
  52.         return MathHelper.clamp_float(sound.getPitch(), 0.5F, 2.0F);
  53.     }
  54.    
  55.     private float getClampedVolume(ImplSound sound) {
  56.         return MathHelper.clamp_float(sound.getVolume() * this.getVolume(sound.getCategory()), 0.0F, 1.0F);
  57.     }
  58.    
  59.     private float getVolume(SoundCategory category)
  60.     {
  61.         return category != null && category != SoundCategory.MASTER ? Minecraft.getMinecraft().gameSettings.getSoundLevel(category) : 1.0F;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment