From f32d7675ce113d03cb1a9c5d4ef98ed377033e68 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 1 Apr 2023 11:07:44 +0700 Subject: [PATCH] sussy clamp --- .../chayapak/chomens_bot/plugins/MusicPlayerPlugin.java | 3 ++- .../chipmunk/chayapak/chomens_bot/util/NumberUtilities.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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); + } }