add music amplifier + mabe NBS fix a bit

This commit is contained in:
Chayapak 2023-10-02 11:36:10 +07:00
parent e56b6533a1
commit 4667f60739
3 changed files with 35 additions and 12 deletions

View file

@ -49,6 +49,7 @@ public class MusicCommand extends Command {
"goto <timestamp>",
"pitch <pitch>",
"speed <speed>",
"amplify <amplification>",
"noteinstrument <instrument>",
"pause",
"resume",
@ -82,6 +83,7 @@ public class MusicCommand extends Command {
case "goto" -> goTo(context);
case "pitch" -> pitch(context);
case "speed" -> speed(context);
case "amplify" -> amplify(context);
case "noteinstrument" -> noteInstrument(context);
case "pause", "resume" -> pause(context);
case "info" -> info(context);
@ -395,6 +397,21 @@ public class MusicCommand extends Command {
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
public Component amplify(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final int amplify = context.getInteger(true);
if (amplify > 8) throw new CommandException(Component.text("Too big value"));
bot.music.amplify = amplify;
return Component.empty()
.append(Component.text("Set the amplification to "))
.append(Component.text(amplify).color(ColorUtilities.getColorByString(bot.config.colorPalette.number)))
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
public Component noteInstrument (CommandContext context) throws CommandException {
final Bot bot = context.bot;

View file

@ -49,6 +49,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
// sus nightcore stuff,..,.,.
public float pitch = 0;
public float speed = 1;
public int amplify = 1;
public String instrument = "off";
@ -355,6 +356,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
for (int i = 0; i < amplify; i++) {
bot.core.run(
"minecraft:execute as " +
(isMoreOrLessOctave ? SELECTOR : BOTH_SELECTOR) +
@ -365,6 +367,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
" " +
MathUtilities.clamp(floatingPitch, 0, 2)
);
}
notesPerSecond++;
}

View file

@ -197,6 +197,9 @@ public class NBSConverter implements Converter {
} else if (name.toLowerCase().contains("door close") || name.toLowerCase().contains("door open")) {
name = "block.wooden_door.open";
replaced = true;
} else if (name.toLowerCase().contains("anvil")) {
name = "block.anvil.fall";
replaced = true;
}
if (!sounds.contains(name) && !sounds.contains(file) && !replaced) {
@ -205,7 +208,7 @@ public class NBSConverter implements Converter {
final List<String> outputTitles = LevenshteinUtilities.searchTitles(name, subtitles.values());
final String bestMatch = outputTitles.size() == 0 ? "" : outputTitles.get(0);
final String bestMatch = outputTitles.isEmpty() ? "" : outputTitles.get(0);
for (Map.Entry<String, String> entry : subtitles.entrySet()) {
if (!entry.getValue().equals(bestMatch)) continue;
@ -220,7 +223,7 @@ public class NBSConverter implements Converter {
instrument = Instrument.of(name);
key += note.key + customInstrument.pitch;
key += note.key + (customInstrument.pitch / 100);
key -= 45 + (note.pitch / 100);
}