From 4667f60739e5ac58e966d94f826d6ef440dcb668 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:36:10 +0700 Subject: [PATCH] add music amplifier + mabe NBS fix a bit --- .../chomens_bot/commands/MusicCommand.java | 17 ++++++++++++++ .../plugins/MusicPlayerPlugin.java | 23 +++++++++++-------- .../chomens_bot/song/NBSConverter.java | 7 ++++-- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java index 9bac125..ea6749e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java @@ -49,6 +49,7 @@ public class MusicCommand extends Command { "goto ", "pitch ", "speed ", + "amplify ", "noteinstrument ", "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; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java index e90bc7d..88248f7 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java @@ -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,16 +356,18 @@ public class MusicPlayerPlugin extends Bot.Listener { floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0); - bot.core.run( - "minecraft:execute as " + - (isMoreOrLessOctave ? SELECTOR : BOTH_SELECTOR) + - " at @s run playsound " + - (!instrument.equals("off") ? instrument : note.instrument.sound) + - " record @s ^" + blockPosition + " ^ ^ " + - note.volume + - " " + - MathUtilities.clamp(floatingPitch, 0, 2) - ); + for (int i = 0; i < amplify; i++) { + bot.core.run( + "minecraft:execute as " + + (isMoreOrLessOctave ? SELECTOR : BOTH_SELECTOR) + + " at @s run playsound " + + (!instrument.equals("off") ? instrument : note.instrument.sound) + + " record @s ^" + blockPosition + " ^ ^ " + + note.volume + + " " + + MathUtilities.clamp(floatingPitch, 0, 2) + ); + } notesPerSecond++; } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java index 2205fc6..68af988 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java @@ -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 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 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); }