diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java index 4a04ef3..b198307 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java @@ -7,6 +7,7 @@ import land.chipmunk.chipmunkbot.song.*; import com.github.steveice10.packetlib.event.session.SessionListener; import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.DisconnectedEvent; +import land.chipmunk.chipmunkbot.util.MathUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; @@ -179,7 +180,7 @@ public class SongPlayer extends SessionAdapter { while (currentSong.reachedNextNote()) { final Note note = currentSong.getNextNote(); - final double floatingPitch = 0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12))); + final double floatingPitch = MathUtilities.clamp(0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12))), 0, 2); client.core().run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); } diff --git a/src/main/java/land/chipmunk/chipmunkbot/util/MathUtilities.java b/src/main/java/land/chipmunk/chipmunkbot/util/MathUtilities.java new file mode 100644 index 0000000..a2eaab6 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkbot/util/MathUtilities.java @@ -0,0 +1,7 @@ +package land.chipmunk.chipmunkbot.util; + +public class MathUtilities { + public static double clamp (double value, double min, double max) { + return Math.max(Math.min(value, max), min); + } +}