aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/CustomMusic.java
diff options
context:
space:
mode:
authorbowser0000 <bowser0000@gmail.com>2021-03-24 14:59:29 -0400
committerbowser0000 <bowser0000@gmail.com>2021-03-24 14:59:29 -0400
commite499665f275c324bcbf4c3c78b6ef40c20ba611b (patch)
tree8b521054c8f188ae0cf0606b3e3f968b2b512319 /src/main/java/me/Danker/features/CustomMusic.java
parent68a5e182ae5ad4760a2d1cd3974a6bfe4090c625 (diff)
downloadSkyblockMod-e499665f275c324bcbf4c3c78b6ef40c20ba611b.tar.gz
SkyblockMod-e499665f275c324bcbf4c3c78b6ef40c20ba611b.tar.bz2
SkyblockMod-e499665f275c324bcbf4c3c78b6ef40c20ba611b.zip
Add dungeon and blood room custom music
Diffstat (limited to 'src/main/java/me/Danker/features/CustomMusic.java')
-rw-r--r--src/main/java/me/Danker/features/CustomMusic.java111
1 files changed, 86 insertions, 25 deletions
diff --git a/src/main/java/me/Danker/features/CustomMusic.java b/src/main/java/me/Danker/features/CustomMusic.java
index ee0a2cc..342913f 100644
--- a/src/main/java/me/Danker/features/CustomMusic.java
+++ b/src/main/java/me/Danker/features/CustomMusic.java
@@ -6,6 +6,8 @@ import me.Danker.handlers.ScoreboardHandler;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StringUtils;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
@@ -22,10 +24,15 @@ import java.util.List;
public class CustomMusic {
+ static boolean cancelNotes;
static boolean prevInDungeonBossRoom = false;
- static boolean inDungeonBossRoom = false;
- public static Clip dungeonboss;
+ public static boolean inDungeonBossRoom = false;
+ public static Song dungeonboss;
public static float dungeonbossDecibels;
+ public static Song bloodroom;
+ public static float bloodroomDecibels;
+ public static Song dungeon;
+ public static float dungeonDecibels;
@SubscribeEvent
public void onWorldChange(WorldEvent.Load event) {
@@ -56,30 +63,44 @@ public class CustomMusic {
firstLine.contains("necron")) { // F7
inDungeonBossRoom = true;
- if (!prevInDungeonBossRoom && dungeonboss != null) {
- start();
+ if (!prevInDungeonBossRoom) {
+ dungeonboss.start();
}
} else {
- reset();
+ inDungeonBossRoom = false;
+ dungeonboss.stop();
}
}
}
}
}
- @SubscribeEvent
+ @SubscribeEvent(receiveCanceled = true)
public void onChat(ClientChatReceivedEvent event) {
- if (!Utils.inDungeons) return;
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
- if (message.contains("EXTRA STATS ")) {
- if (dungeonboss != null) dungeonboss.stop();
+ if (ToggleCommand.dungeonMusic && Utils.inDungeons) {
+ if (message.contains("[NPC] Mort: Here, I found this map when I first entered the dungeon.")) {
+ dungeon.start();
+ }
+ }
+
+ if (message.contains(":")) return;
+
+ if (Utils.inDungeons) {
+ if (message.contains("EXTRA STATS ")) {
+ dungeonboss.stop();
+ bloodroom.stop();
+ dungeon.stop();
+ } else if (ToggleCommand.bloodRoomMusic && message.contains("The BLOOD DOOR has been opened!")) {
+ bloodroom.start();
+ }
}
}
@SubscribeEvent
public void onSound(PlaySoundEvent event) {
- if (ToggleCommand.dungeonBossMusic && Utils.inDungeons && inDungeonBossRoom) {
+ if (cancelNotes) {
if (event.isCancelable() && event.name.startsWith("note.")) event.setCanceled(true);
}
}
@@ -91,29 +112,69 @@ public class CustomMusic {
reset();
- dungeonboss = AudioSystem.getClip();
- File dungeonBossFile = new File(configDirectory + "/dsmmusic/dungeonboss.wav");
+ File dungeonBossFile = new File(directory + "/dungeonboss.wav");
System.out.println("dungeonboss.wav exists?: " + dungeonBossFile.exists());
- if (dungeonBossFile.exists()) {
- AudioInputStream ais = AudioSystem.getAudioInputStream(dungeonBossFile);
- dungeonboss.open(ais);
+ dungeonboss = new Song(dungeonBossFile, dungeonbossDecibels);
- FloatControl volume = (FloatControl) dungeonboss.getControl(FloatControl.Type.MASTER_GAIN);
- volume.setValue(dungeonbossDecibels);
- }
+ File bloodRoomFile = new File(directory + "/bloodroom.wav");
+ System.out.println("bloodroom.wav exists?: " + bloodRoomFile.exists());
+ bloodroom = new Song(bloodRoomFile, bloodroomDecibels);
+
+ File dungeonFile = new File(directory + "/dungeon.wav");
+ System.out.println("dungeon.wav exists?: " + dungeonFile.exists());
+ dungeon = new Song(dungeonFile, dungeonDecibels);
}
- static void reset() {
- inDungeonBossRoom = false;
+ public static void reset() {
+ cancelNotes = false;
if (dungeonboss != null) dungeonboss.stop();
+ if (bloodroom != null) bloodroom.stop();
+ if (dungeon != null) dungeon.stop();
}
- public static void start() {
- if (dungeonboss != null && inDungeonBossRoom) {
- dungeonboss.setMicrosecondPosition(0);
- dungeonboss.start();
- dungeonboss.loop(Clip.LOOP_CONTINUOUSLY);
+ public static class Song {
+
+ public Clip music;
+
+ public Song(File file, float decibels) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
+ if (file.exists()) {
+ music = AudioSystem.getClip();
+ AudioInputStream ais = AudioSystem.getAudioInputStream(file);
+ music.open(ais);
+
+ setVolume(decibels);
+ }
}
+
+ public void start() {
+ reset();
+ cancelNotes = true;
+ if (music != null) {
+ music.setMicrosecondPosition(0);
+ music.start();
+ music.loop(Clip.LOOP_CONTINUOUSLY);
+ }
+ }
+
+ public void stop() {
+ cancelNotes = false;
+ if (music != null) music.stop();
+ }
+
+ public boolean setVolume(float decibels) {
+ if (music == null) return false;
+
+ 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;
+ }
+
+ control.setValue(decibels);
+ return true;
+ }
+
}
}