Advertisement
Guest User

Untitled

a guest
Jul 27th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /**
  2. * Checks if given sound is being played.
  3. * @param res
  4. * The sound that is checked for. Format: {@code isSoundPlaying(new ResourceLocation("modid:mySound")}
  5. */
  6. public static boolean isSoundPlaying(ResourceLocation res)
  7. {
  8. HashBiMap<String, ISound> playing = null;
  9. SoundManager manager = null;
  10. try
  11. {
  12. // handler -> manager -> playingList
  13.  
  14. // gets SoundHandler
  15. net.minecraft.client.audio.SoundHandler handler;
  16. Field field_handler = Minecraft.class.getDeclaredField("mcSoundHandler");
  17. field_handler.setAccessible(true);
  18. handler = (net.minecraft.client.audio.SoundHandler) field_handler.get(Minecraft.getMinecraft());
  19.  
  20. // gets SoundManager
  21. Field field_manager = net.minecraft.client.audio.SoundHandler.class.getDeclaredField("sndManager");
  22. field_manager.setAccessible(true);
  23. manager = (SoundManager) field_manager.get(handler);
  24.  
  25. // gets playing list
  26. Field field_playing = SoundManager.class.getDeclaredField("playingSounds");
  27. field_playing.setAccessible(true);
  28. playing = (HashBiMap<String, ISound>) field_playing.get(manager);
  29.  
  30. }
  31. catch (Exception ex)
  32. {
  33. // ex.printStackTrace();
  34. }
  35.  
  36. if (playing != null)
  37. {
  38. ISound[] array_playing = playing.values().toArray(new ISound[playing.values().size()]);
  39. for (int i = 0; i < array_playing.length; i++)
  40. if (array_playing[i].getPositionedSoundLocation().equals(res))
  41. return true;
  42. }
  43. return false;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement