Make the toast only appear if the user attempted to access the songs

This commit is contained in:
Semmieboy YT 2023-04-01 21:54:10 +02:00
parent 9251163a02
commit b7b26a767d
3 changed files with 5 additions and 1 deletions

View File

@ -72,6 +72,7 @@ public class DiscjockeyCommand {
private static boolean isLoading(CommandContext<FabricClientCommandSource> context) {
if (SongLoader.loadingSongs) {
context.getSource().sendError(Text.translatable(Main.MOD_ID+".still_loading"));
SongLoader.showToast = true;
return true;
}
return false;

View File

@ -64,6 +64,7 @@ public class Main implements ClientModInitializer {
if (openScreenKeyBind.wasPressed()) {
if (SongLoader.loadingSongs) {
client.inGameHud.getChatHud().addMessage(Text.translatable(Main.MOD_ID+".still_loading").formatted(Formatting.RED));
SongLoader.showToast = true;
} else {
client.setScreen(new DiscJockeyScreen());
}

View File

@ -16,6 +16,7 @@ public class SongLoader {
public static final ArrayList<Song> SONGS = new ArrayList<>();
public static final ArrayList<String> SONG_SUGGESTIONS = new ArrayList<>();
public static volatile boolean loadingSongs;
public static volatile boolean showToast;
public static void loadSongs() {
if (loadingSongs) return;
@ -36,7 +37,8 @@ public class SongLoader {
for (Song song : SONGS) SONG_SUGGESTIONS.add(song.displayName);
Main.config.favorites.removeIf(favorite -> SongLoader.SONGS.stream().map(song -> song.fileName).noneMatch(favorite::equals));
if (MinecraftClient.getInstance().textRenderer != null) SystemToast.add(MinecraftClient.getInstance().getToastManager(), SystemToast.Type.PACK_LOAD_FAILURE, Main.NAME, Text.translatable(Main.MOD_ID+".loading_done"));
if (showToast && MinecraftClient.getInstance().textRenderer != null) SystemToast.add(MinecraftClient.getInstance().getToastManager(), SystemToast.Type.PACK_LOAD_FAILURE, Main.NAME, Text.translatable(Main.MOD_ID+".loading_done"));
showToast = true;
loadingSongs = false;
}).start();
}