diff options
author | bowser0000 <bowser0000@gmail.com> | 2021-03-28 17:46:45 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2021-03-28 17:46:45 -0400 |
commit | 57e5469f651610a4f07bf8e5266b789d7ca1fe34 (patch) | |
tree | 269182a8c643b6ce197e12c35b8253b6eb9bb019 /src/main/java/me/Danker/features/CustomMusic.java | |
parent | 786efa0ea48daffb075d2d6482a677571e136a1b (diff) | |
download | SkyblockMod-57e5469f651610a4f07bf8e5266b789d7ca1fe34.tar.gz SkyblockMod-57e5469f651610a4f07bf8e5266b789d7ca1fe34.tar.bz2 SkyblockMod-57e5469f651610a4f07bf8e5266b789d7ca1fe34.zip |
Change /dsmmusic volume to percentage from decibels
Also fix custom music not cancelling note block music
Diffstat (limited to 'src/main/java/me/Danker/features/CustomMusic.java')
-rw-r--r-- | src/main/java/me/Danker/features/CustomMusic.java | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/main/java/me/Danker/features/CustomMusic.java b/src/main/java/me/Danker/features/CustomMusic.java index 342913f..4b1f6bb 100644 --- a/src/main/java/me/Danker/features/CustomMusic.java +++ b/src/main/java/me/Danker/features/CustomMusic.java @@ -28,11 +28,11 @@ public class CustomMusic { static boolean prevInDungeonBossRoom = false; public static boolean inDungeonBossRoom = false; public static Song dungeonboss; - public static float dungeonbossDecibels; + public static int dungeonbossVolume; public static Song bloodroom; - public static float bloodroomDecibels; + public static int bloodroomVolume; public static Song dungeon; - public static float dungeonDecibels; + public static int dungeonVolume; @SubscribeEvent public void onWorldChange(WorldEvent.Load event) { @@ -66,9 +66,6 @@ public class CustomMusic { if (!prevInDungeonBossRoom) { dungeonboss.start(); } - } else { - inDungeonBossRoom = false; - dungeonboss.stop(); } } } @@ -100,8 +97,8 @@ public class CustomMusic { @SubscribeEvent public void onSound(PlaySoundEvent event) { - if (cancelNotes) { - if (event.isCancelable() && event.name.startsWith("note.")) event.setCanceled(true); + if (cancelNotes && event.name.startsWith("note.")) { + event.result = null; } } @@ -114,19 +111,18 @@ public class CustomMusic { File dungeonBossFile = new File(directory + "/dungeonboss.wav"); System.out.println("dungeonboss.wav exists?: " + dungeonBossFile.exists()); - dungeonboss = new Song(dungeonBossFile, dungeonbossDecibels); + dungeonboss = new Song(dungeonBossFile, dungeonbossVolume); File bloodRoomFile = new File(directory + "/bloodroom.wav"); System.out.println("bloodroom.wav exists?: " + bloodRoomFile.exists()); - bloodroom = new Song(bloodRoomFile, bloodroomDecibels); + bloodroom = new Song(bloodRoomFile, bloodroomVolume); File dungeonFile = new File(directory + "/dungeon.wav"); System.out.println("dungeon.wav exists?: " + dungeonFile.exists()); - dungeon = new Song(dungeonFile, dungeonDecibels); + dungeon = new Song(dungeonFile, dungeonVolume); } public static void reset() { - cancelNotes = false; if (dungeonboss != null) dungeonboss.stop(); if (bloodroom != null) bloodroom.stop(); if (dungeon != null) dungeon.stop(); @@ -136,20 +132,20 @@ public class CustomMusic { public Clip music; - public Song(File file, float decibels) throws IOException, UnsupportedAudioFileException, LineUnavailableException { + public Song(File file, int volume) throws IOException, UnsupportedAudioFileException, LineUnavailableException { if (file.exists()) { music = AudioSystem.getClip(); AudioInputStream ais = AudioSystem.getAudioInputStream(file); music.open(ais); - setVolume(decibels); + setVolume(volume); } } public void start() { reset(); - cancelNotes = true; if (music != null) { + cancelNotes = true; music.setMicrosecondPosition(0); music.start(); music.loop(Clip.LOOP_CONTINUOUSLY); @@ -161,13 +157,17 @@ public class CustomMusic { if (music != null) music.stop(); } - public boolean setVolume(float decibels) { + public boolean setVolume(int volume) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; if (music == null) return false; + if (volume <= 0 || volume > 100) { + if (player != null) player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Volume can only be set between 0% and 100%.")); + return false; + } + float decibels = (float) (20 * Math.log(volume / 100.0)); FloatControl control = (FloatControl) music.getControl(FloatControl.Type.MASTER_GAIN); if (decibels <= control.getMinimum() || decibels >= control.getMaximum()) { - EntityPlayer player = Minecraft.getMinecraft().thePlayer; - if (player != null) player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Volume can only be set between " + control.getMinimum() + " and " + control.getMaximum() + ".")); return false; } |