forked from chipmunkmc/chipmunkbot
actually clamp the thing
This commit is contained in:
parent
0ad227acae
commit
5d56589c2e
2 changed files with 9 additions and 1 deletions
|
@ -7,6 +7,7 @@ import land.chipmunk.chipmunkbot.song.*;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
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.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
@ -179,7 +180,7 @@ public class SongPlayer extends SessionAdapter {
|
||||||
while (currentSong.reachedNextNote()) {
|
while (currentSong.reachedNextNote()) {
|
||||||
final Note note = currentSong.getNextNote();
|
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);
|
client.core().run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue