diff --git a/build-number.txt b/build-number.txt index 44c590d3..377ce3c6 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1658 \ No newline at end of file +1660 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java index 292d95ae..cde67701 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/MusicPlayerPlugin.java @@ -446,16 +446,14 @@ public class MusicPlayerPlugin extends Bot.Listener { else if (note.panning == 100 && note.stereo != 100) value = note.stereo; else value = (double) (note.stereo + note.panning) / 2; - double pos; + double xPos; - if (value > 100) pos = (value - 100) / -100; - else if (value == 100) pos = 0; - else pos = ((value - 100) * -1) / 100; + if (value > 100) xPos = (value - 100) / -100; + else if (value == 100) xPos = 0; + else xPos = ((value - 100) * -1) / 100; - blockPosition = Vector3d.from(pos, 0, 0); + blockPosition = Vector3d.from(xPos, 0, 0); } else { - // i wrote this part - final double originalPitch = note.originalPitch; double xPos = -(double) originalPitch / 768; diff --git a/src/main/java/me/chayapak1/chomens_bot/song/NBSConverter.java b/src/main/java/me/chayapak1/chomens_bot/song/NBSConverter.java index d72d8f25..624cf5a3 100644 --- a/src/main/java/me/chayapak1/chomens_bot/song/NBSConverter.java +++ b/src/main/java/me/chayapak1/chomens_bot/song/NBSConverter.java @@ -6,6 +6,7 @@ import com.google.gson.JsonParser; import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.util.ComponentUtilities; import me.chayapak1.chomens_bot.util.LevenshteinUtilities; +import me.chayapak1.chomens_bot.util.StringUtilities; import java.io.BufferedReader; import java.io.IOException; @@ -22,7 +23,7 @@ import java.util.Map; // Author: hhhzzzsss public class NBSConverter implements Converter { - public static final Instrument[] instrumentIndex = new Instrument[] { + public static final Instrument[] INSTRUMENT_INDEX = new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BASEDRUM, @@ -41,6 +42,19 @@ public class NBSConverter implements Converter { Instrument.PLING, }; + public static final Map CUSTOM_INSTRUMENT_REPLACEMENTS = new HashMap<>(); + + static { + CUSTOM_INSTRUMENT_REPLACEMENTS.put("entity\\.firework\\.", "entity.firework_rocket."); + CUSTOM_INSTRUMENT_REPLACEMENTS.put(".*glass.*", "block.glass.break"); + CUSTOM_INSTRUMENT_REPLACEMENTS.put(".*door.*", "block.wooden_door.open"); + CUSTOM_INSTRUMENT_REPLACEMENTS.put(".*anvil.*", "block.anvil.fall"); + CUSTOM_INSTRUMENT_REPLACEMENTS.put(".*piston.*", "block.piston.extend"); + CUSTOM_INSTRUMENT_REPLACEMENTS.put(".*explode|explosion.*", "entity.generic.explode"); + CUSTOM_INSTRUMENT_REPLACEMENTS.put(".*eye.*", "block.end_portal_frame.fill"); + CUSTOM_INSTRUMENT_REPLACEMENTS.put("fizz", "block.sand.break"); // not really sure what this exactly is, but it exists in some NBSes + } + public static class NBSNote { public int tick; public short layer; @@ -182,46 +196,37 @@ public class NBSConverter implements Converter { for (NBSNote note : nbsNotes) { Instrument instrument; double key = note.key; - if (note.instrument < instrumentIndex.length) { - instrument = instrumentIndex[note.instrument]; + if (note.instrument < INSTRUMENT_INDEX.length) { + instrument = INSTRUMENT_INDEX[note.instrument]; key = (double) ((note.key * 100) + note.pitch) / 100; } else { - int index = note.instrument - instrumentIndex.length; + final int index = note.instrument - INSTRUMENT_INDEX.length; if (index >= customInstruments.size()) continue; - NBSCustomInstrument customInstrument = customInstruments.get(index); - - String name = customInstrument.name.replace("entity.firework.", "entity.firework_rocket."); + final NBSCustomInstrument customInstrument = customInstruments.get(index); + String name = customInstrument.name; String file = Path.of(customInstrument.file).getFileName().toString(); + + // should i hardcode the extension like this? if (file.endsWith(".ogg")) file = file.substring(0, file.length() - ".ogg".length()); - file = file.replace("entity.firework.", "entity.firework_rocket."); boolean replaced = false; - if (name.toLowerCase().contains("glass break") || name.toLowerCase().contains("glass broken")) { - name = "block.glass.break"; + final String replacedName = StringUtilities.replaceAllWithMap(name.toLowerCase(), CUSTOM_INSTRUMENT_REPLACEMENTS); + final String replacedFile = StringUtilities.replaceAllWithMap(file.toLowerCase(), CUSTOM_INSTRUMENT_REPLACEMENTS); + + if (!file.equals(replacedFile)) { + file = replacedFile; replaced = true; - } 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; - } else if (name.toLowerCase().contains("piston extend")) { - name = "block.piston.extend"; - replaced = true; - } else if (name.toLowerCase().contains("explosion")) { - name = "entity.generic.explode"; + } else if (!name.equals(replacedName)) { + name = replacedName; replaced = true; } if (!sounds.contains(name) && !sounds.contains(file) && !replaced) { - name = name - .replaceAll("Eye.*Fill", "Eye of Ender attaches"); - final List outputTitles = LevenshteinUtilities.searchTitles(name, subtitles.values()); final String bestMatch = outputTitles.isEmpty() ? "" : outputTitles.getFirst(); diff --git a/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java index 26eaf240..5ffaf1c5 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java @@ -6,6 +6,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; import java.nio.charset.StandardCharsets; +import java.util.Map; public class StringUtilities { // https://stackoverflow.com/a/8910767/18518424 @@ -63,4 +64,12 @@ public class StringUtilities { public static boolean isNotNullAndNotBlank (String text) { return text != null && !text.isBlank(); } + + public static String replaceAllWithMap (String input, Map replacements) { + String result = input; + for (Map.Entry entry : replacements.entrySet()) { + result = result.replaceAll(entry.getKey(), entry.getValue()); + } + return result; + } }