Add ability to loop the same song via command

This commit is contained in:
EnderKill98 2024-04-16 02:56:42 +02:00
parent 8de17aacc8
commit 281048f33a
3 changed files with 25 additions and 1 deletions

View File

@ -214,7 +214,24 @@ public class DiscjockeyCommand {
)
)
.then(literal("loop")
.executes(context -> {
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".loop_status", Main.SONG_PLAYER.loopSong ? "yes" : "no"));
return 1;
})
.then(literal("yes")
.executes(context -> {
Main.SONG_PLAYER.loopSong = true;
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".loop_enabled"));
return 1;
}))
.then(literal("no")
.executes(context -> {
Main.SONG_PLAYER.loopSong = false;
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".loop_disabled"));
return 1;
}))
)
);
}

View File

@ -60,6 +60,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
private int tuneInitialUntunedBlocks = -1;
private HashMap<BlockPos, Pair<Integer, Long>> notePredictions = new HashMap<>();
public boolean didSongReachEnd = false;
public boolean loopSong = false;
public SongPlayer() {
Main.TICK_LISTENERS.add(this);
@ -205,6 +206,9 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
if (index >= song.notes.length) {
stop();
didSongReachEnd = true;
if(loopSong) {
start(song);
}
break;
}
} else {

View File

@ -31,6 +31,9 @@
"disc_jockey.mapped_instruments": "Mapped instruments: %s",
"disc_jockey.no_mapped_instruments": "No instruments mapped, yet.",
"disc_jockey.instrument_maps_cleared": "Instrument mappings cleared.",
"disc_jockey.loop_status": "Loop song: %s",
"disc_jockey.loop_enabled": "Enabled looping of current song.",
"disc_jockey.loop_disabled": "Disabled looping of current song.",
"disc_jockey.warning": "WARNING!!! This mod is very likely to get false flagged as hacks, please contact a server administrator before using this mod! (You can disable this warning in the mod settings)",
"key.category.disc_jockey": "Disc Jockey",
"disc_jockey.key_bind.open_screen": "Open song selection screen",