diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java index 9f72186..d8f2386 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkbot/commands/MusicCommand.java @@ -20,8 +20,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat; import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; +import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg; import static com.mojang.brigadier.arguments.LongArgumentType.getLong; import static land.chipmunk.chipmunkbot.command.arguments.LocationArgumentType.*; import static land.chipmunk.chipmunkbot.command.arguments.TimestampArgumentType.timestamp; @@ -77,6 +79,14 @@ public class MusicCommand { .executes(instance::gotoCommand) ) ) + + .then( + literal("pitch") + .then( + argument("pitch", floatArg()) + .executes(instance::pitch) + ) + ) ); } @@ -255,4 +265,25 @@ public class MusicCommand { return 1; } + + public int pitch (CommandContext context) throws CommandSyntaxException { + final CommandSource source = context.getSource(); + final SongPlayer songPlayer = source.client().songPlayer(); + final Song currentSong = songPlayer.currentSong(); + + if (currentSong == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create(); + + final float pitch = getFloat(context, "pitch"); + + songPlayer.pitch(pitch); + + source.sendOutput( + Component.translatable( + "Set the pitch to: %s", + Component.text(String.valueOf(pitch)) + ).color(TextColor.fromHexString(source.client().config().color().primary())) + ); + + return 1; + } } diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java index 13b1c6b..4a04ef3 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java @@ -34,6 +34,8 @@ public class SongPlayer extends SessionAdapter { @Getter @Setter private SongLoaderThread loaderThread; private int ticksUntilPausedActionbar = 20; + @Getter @Setter private float pitch = 0; + public SongPlayer (ChipmunkBot client) { this.client = client; client.addListener((SessionListener) this); @@ -177,7 +179,7 @@ public class SongPlayer extends SessionAdapter { while (currentSong.reachedNextNote()) { final Note note = currentSong.getNextNote(); - final double floatingPitch = Math.pow(2, (note.pitch - 12) / 12.0); + final double floatingPitch = 0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12))); client.core().run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); }