diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java index 66c4e1f..1d9670d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java @@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins; import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; import land.chipmunk.chayapak.chomens_bot.song.*; +import land.chipmunk.chayapak.chomens_bot.util.NumberUtilities; import lombok.Getter; import lombok.Setter; import land.chipmunk.chayapak.chomens_bot.Bot; @@ -231,7 +232,7 @@ public class MusicPlayerPlugin extends SessionAdapter { while (currentSong.reachedNextNote()) { final Note note = currentSong.getNextNote(); - final double floatingPitch = Math.pow(2, ((nightcore ? note.pitch + 1 : note.pitch) - 12) / 12.0); + final double floatingPitch = NumberUtilities.clamp(Math.pow(2, ((nightcore ? note.pitch + 1 : note.pitch) - 12) / 12.0), 0, 2); bot.core().run("minecraft:execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/NumberUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/NumberUtilities.java index 925348f..91bbbb3 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/NumberUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/NumberUtilities.java @@ -11,4 +11,9 @@ public class NumberUtilities { if (value < min) return min; return Math.min(value, max); } + + public static double clamp (double value, double min, double max) { + if (value < min) return min; + return Math.min(value, max); + } }