Add two new subcommands: speed and info
This commit is contained in:
parent
ea852c2481
commit
fdf171ac6a
@ -1,6 +1,7 @@
|
||||
package semmiedev.disc_jockey;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
@ -9,6 +10,7 @@ import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import semmiedev.disc_jockey.gui.screen.DiscJockeyScreen;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
|
||||
@ -66,15 +68,57 @@ public class DiscjockeyCommand {
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
.then(literal("speed")
|
||||
.then(argument("speed", FloatArgumentType.floatArg(0.0001F, 15.0F))
|
||||
.suggests((context, builder) -> CommandSource.suggestMatching(Arrays.asList("0.5", "0.75", "1", "1.25", "1.5", "2"), builder))
|
||||
.executes(context -> {
|
||||
float newSpeed = FloatArgumentType.getFloat(context, "speed");
|
||||
Main.SONG_PLAYER.speed = newSpeed;
|
||||
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".speed_changed", Main.SONG_PLAYER.speed));
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(literal("info")
|
||||
.executes(context -> {
|
||||
|
||||
if (!Main.SONG_PLAYER.running) {
|
||||
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".info_not_running", Main.SONG_PLAYER.speed));
|
||||
return 0;
|
||||
}
|
||||
if (!Main.SONG_PLAYER.tuned) {
|
||||
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".info_tuning", Main.SONG_PLAYER.song.displayName, Main.SONG_PLAYER.speed));
|
||||
return 0;
|
||||
}else if(!Main.SONG_PLAYER.didSongReachEnd) {
|
||||
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".info_playing", formatTimestamp((int) Main.SONG_PLAYER.getSongElapsedSeconds()), formatTimestamp((int) Main.SONG_PLAYER.song.getLengthInSeconds()), Main.SONG_PLAYER.song.displayName, Main.SONG_PLAYER.speed));
|
||||
return 0;
|
||||
}else {
|
||||
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".info_finished", Main.SONG_PLAYER.song != null ? Main.SONG_PLAYER.song.displayName : "???", Main.SONG_PLAYER.speed));
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean isLoading(CommandContext<FabricClientCommandSource> context) {
|
||||
if (SongLoader.loadingSongs) {
|
||||
context.getSource().sendError(Text.translatable(Main.MOD_ID+".still_loading"));
|
||||
context.getSource().sendError(Text.translatable(Main.MOD_ID + ".still_loading"));
|
||||
SongLoader.showToast = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String padZeroes(int number, int length) {
|
||||
StringBuilder builder = new StringBuilder("" + number);
|
||||
while(builder.length() < length)
|
||||
builder.insert(0, '0');
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String formatTimestamp(int seconds) {
|
||||
return padZeroes(seconds / 60, 2) + ":" + padZeroes(seconds % 60, 2);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
|
||||
private int index;
|
||||
private double tick; // Aka song position
|
||||
private HashMap<Instrument, HashMap<Byte, BlockPos>> noteBlocks = null;
|
||||
private boolean tuned;
|
||||
public boolean tuned;
|
||||
private long lastPlaybackTickAt = -1L;
|
||||
|
||||
// Used to check and enforce packet rate limits to not get kicked
|
||||
|
@ -17,7 +17,12 @@
|
||||
"disc_jockey.loading_done": "All songs are loaded",
|
||||
"disc_jockey.song_not_found": " Song '%s' does not exist",
|
||||
"disc_jockey.not_playing": "Not playing any song",
|
||||
"disc_jockey.speed_changed": "Changed playback speed to %s",
|
||||
"disc_jockey.stopped_playing": "Stopped playing '%s'",
|
||||
"disc_jockey.info_not_running": "No song is playing (Speed: %s)",
|
||||
"disc_jockey.info_tuning": "Tuning: (Speed: %s)",
|
||||
"disc_jockey.info_playing": "Playing: [%s/%s] %s (Speed: %s)",
|
||||
"disc_jockey.info_finished": "Finished: %s (Speed: %s)",
|
||||
"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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user