actually clamp the thing

This commit is contained in:
Chayapak 2023-05-12 11:47:00 +07:00
parent 0ad227acae
commit 5d56589c2e
2 changed files with 9 additions and 1 deletions

View file

@ -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);
}

View file

@ -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);
}
}