feat: support all OpenNBS hidden features (including rainbow easter egg !!!)
This commit is contained in:
parent
a933653112
commit
9d6fc74a34
8 changed files with 60 additions and 17 deletions
build-number.txt
src/main/java/me/chayapak1/chomens_bot
|
@ -1 +1 @@
|
|||
2005
|
||||
2014
|
|
@ -542,7 +542,8 @@ public class MusicCommand extends Command {
|
|||
1,
|
||||
i * 50,
|
||||
-1,
|
||||
100
|
||||
100,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import me.chayapak1.chomens_bot.util.LoggerUtilities;
|
|||
import me.chayapak1.chomens_bot.util.MathUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.util.HSVLike;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.BossBarColor;
|
||||
|
@ -53,6 +55,9 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
|
||||
public int amplify = 1;
|
||||
|
||||
public boolean rainbow = false; // nbs easter egg
|
||||
private float rainbowHue = 0F;
|
||||
|
||||
public String instrument = "off";
|
||||
|
||||
private int urlLimit = 0;
|
||||
|
@ -228,6 +233,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
public BotBossBar addBossBar () {
|
||||
if (currentSong == null) return null;
|
||||
|
||||
rainbow = false;
|
||||
|
||||
final BotBossBar bossBar = new BotBossBar(
|
||||
Component.empty(),
|
||||
BOTH_SELECTOR,
|
||||
|
@ -293,8 +300,15 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
}
|
||||
|
||||
public Component generateBossBar () {
|
||||
NamedTextColor nameColor;
|
||||
if (pitch > 0) {
|
||||
TextColor nameColor;
|
||||
|
||||
if (rainbow) {
|
||||
final int increment = 360 / 20;
|
||||
nameColor = TextColor.color(HSVLike.hsvLike(rainbowHue / 360.0f, 1, 1));
|
||||
rainbowHue = (rainbowHue + increment) % 360;
|
||||
|
||||
bossBarColor = BossBarColor.YELLOW;
|
||||
} else if (pitch > 0) {
|
||||
nameColor = NamedTextColor.LIGHT_PURPLE;
|
||||
bossBarColor = BossBarColor.PURPLE;
|
||||
} else if (pitch < 0) {
|
||||
|
@ -367,6 +381,11 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
while (currentSong.reachedNextNote()) {
|
||||
final Note note = currentSong.getNextNote();
|
||||
|
||||
if (note.isRainbowToggle) {
|
||||
rainbow = !rainbow;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (note.volume == 0) continue;
|
||||
|
||||
double key = note.shiftedPitch;
|
||||
|
|
|
@ -241,7 +241,7 @@ public class MidiConverter implements Converter {
|
|||
Instrument instrument = Instrument.fromId(noteId / 25);
|
||||
long time = microTime / 1000L;
|
||||
|
||||
return new Note(instrument, pitch, midiPitch, volume, time, (int) ((panning - 64) / (float) 64) * 100, 100);
|
||||
return new Note(instrument, pitch, midiPitch, volume, time, (int) ((panning - 64) / (float) 64) * 100, 100, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class NBSConverter implements Converter {
|
|||
String songAuthor = getString(buffer, bytes.length);
|
||||
String songOriginalAuthor = getString(buffer, bytes.length);
|
||||
String songDescription = getString(buffer, bytes.length);
|
||||
short tempo = buffer.getShort();
|
||||
double tempo = buffer.getShort();
|
||||
byte autoSaving = buffer.get();
|
||||
byte autoSavingDuration = buffer.get();
|
||||
byte timeSignature = buffer.get();
|
||||
|
@ -193,6 +193,7 @@ public class NBSConverter implements Converter {
|
|||
// song.loopCount = maxLoopCount;
|
||||
}
|
||||
for (NBSNote note : nbsNotes) {
|
||||
boolean isRainbowToggle = false;
|
||||
Instrument instrument;
|
||||
double key = note.key;
|
||||
if (note.instrument < INSTRUMENT_INDEX.length) {
|
||||
|
@ -209,12 +210,22 @@ public class NBSConverter implements Converter {
|
|||
String name = customInstrument.name
|
||||
.replace("entity.firework.", "entity.firework_rocket."); // this one is special
|
||||
|
||||
boolean isTempoChanger = false;
|
||||
|
||||
if (name.equals("Tempo Changer")) {
|
||||
isTempoChanger = true;
|
||||
|
||||
tempo = (double) Math.abs(note.pitch) * 100 / 15;
|
||||
} else if (name.equals("Toggle Rainbow")) {
|
||||
isRainbowToggle = true;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
if (!sounds.contains(name) && !sounds.contains(file)) {
|
||||
if (!sounds.contains(name) && !sounds.contains(file) && !isTempoChanger) {
|
||||
boolean replaced = false;
|
||||
|
||||
final String replacedName = StringUtilities.replaceAllWithMap(name.toLowerCase(), CUSTOM_INSTRUMENT_REPLACEMENTS);
|
||||
|
@ -257,11 +268,18 @@ public class NBSConverter implements Converter {
|
|||
|
||||
double pitch = key - 33;
|
||||
|
||||
try {
|
||||
song.add(new Note(instrument, pitch, key, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo), Byte.toUnsignedInt(note.panning), Byte.toUnsignedInt(nbsLayers.get(note.layer).stereo)));
|
||||
} catch (Exception e) {
|
||||
song.add(new Note(instrument, pitch, key, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo), -1, 100));
|
||||
}
|
||||
song.add(
|
||||
new Note(
|
||||
instrument,
|
||||
pitch,
|
||||
key,
|
||||
(float) note.velocity * (float) layerVolume / 10000f,
|
||||
getMilliTime(note.tick, tempo),
|
||||
Byte.toUnsignedInt(note.panning),
|
||||
Byte.toUnsignedInt(nbsLayers.get(note.layer).stereo),
|
||||
isRainbowToggle
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
song.length = song.get(song.size()-1).time + 50;
|
||||
|
@ -279,8 +297,8 @@ public class NBSConverter implements Converter {
|
|||
return new String(arr, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static int getMilliTime(int tick, int tempo) {
|
||||
return 1000 * tick * 100 / tempo;
|
||||
private static long getMilliTime (int tick, double tempo) {
|
||||
return (long) (1000L * tick * 100 / tempo);
|
||||
}
|
||||
|
||||
private static final Map<String, String> subtitles = new HashMap<>();
|
||||
|
|
|
@ -11,6 +11,7 @@ public class Note implements Comparable<Note> {
|
|||
public final long time;
|
||||
public final int panning;
|
||||
public final int stereo;
|
||||
public final boolean isRainbowToggle;
|
||||
|
||||
public Note (
|
||||
Instrument instrument,
|
||||
|
@ -19,7 +20,8 @@ public class Note implements Comparable<Note> {
|
|||
float volume,
|
||||
long time,
|
||||
int panning,
|
||||
int stereo
|
||||
int stereo,
|
||||
boolean isRainbowToggle
|
||||
) {
|
||||
this.instrument = instrument;
|
||||
this.shiftedInstrument = this.instrument;
|
||||
|
@ -30,6 +32,7 @@ public class Note implements Comparable<Note> {
|
|||
this.time = time;
|
||||
this.panning = panning;
|
||||
this.stereo = stereo;
|
||||
this.isRainbowToggle = isRainbowToggle;
|
||||
}
|
||||
|
||||
public Note (
|
||||
|
@ -52,6 +55,7 @@ public class Note implements Comparable<Note> {
|
|||
this.time = time;
|
||||
this.panning = panning;
|
||||
this.stereo = stereo;
|
||||
this.isRainbowToggle = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,7 +54,7 @@ public class SongPlayerConverter implements Converter {
|
|||
int noteId = buffer.getShort();
|
||||
if (noteId >= 0 && noteId < 400) {
|
||||
time += getVarLong(buffer);
|
||||
song.add(new Note(Instrument.fromId(noteId / 25), noteId % 25, noteId % 25, 1, time, -1, 100));
|
||||
song.add(new Note(Instrument.fromId(noteId / 25), noteId % 25, noteId % 25, 1, time, -1, 100, false));
|
||||
}
|
||||
else if ((noteId & 0xFFFF) == 0xFFFF) {
|
||||
break;
|
||||
|
|
|
@ -63,7 +63,8 @@ public class TextFileConverter implements Converter {
|
|||
volume,
|
||||
time,
|
||||
-1,
|
||||
100
|
||||
100,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue