forked from chipmunkmc/chipmunkbot
music pitch YUUUUUP
This commit is contained in:
parent
e45d2c1f48
commit
9a0261ccad
2 changed files with 34 additions and 1 deletions
|
@ -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<CommandSource> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue