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>", "goto <timestamp>",
"pitch <pitch>", "pitch <pitch>",
"speed <speed>", "speed <speed>",
"amplify <amplification>",
"noteinstrument <instrument>", "noteinstrument <instrument>",
"pause", "pause",
"resume", "resume",
@ -82,6 +83,7 @@ public class MusicCommand extends Command {
case "goto" -> goTo(context); case "goto" -> goTo(context);
case "pitch" -> pitch(context); case "pitch" -> pitch(context);
case "speed" -> speed(context); case "speed" -> speed(context);
case "amplify" -> amplify(context);
case "noteinstrument" -> noteInstrument(context); case "noteinstrument" -> noteInstrument(context);
case "pause", "resume" -> pause(context); case "pause", "resume" -> pause(context);
case "info" -> info(context); case "info" -> info(context);
@ -395,6 +397,21 @@ public class MusicCommand extends Command {
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); .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 { public Component noteInstrument (CommandContext context) throws CommandException {
final Bot bot = context.bot; final Bot bot = context.bot;

View file

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

View file

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