···1010import net.lerariemann.infinity.util.core.CommonIO;
1111import net.lerariemann.infinity.util.core.RandomProvider;
1212import net.lerariemann.infinity.util.loading.DimensionGrabber;
1313-import net.minecraft.block.jukebox.JukeboxSong;
1413import net.minecraft.client.MinecraftClient;
1514import net.minecraft.nbt.NbtCompound;
1615import net.minecraft.nbt.NbtElement;
···3433/**
3534 * Pipeline for generating custom sound events and jukebox song definitions for every music track in the game.
3635 */
3636+// TODO soundpacks
3737public record SoundScanner(Map<Identifier, Resource> soundIds) {
3838 /** Holds a map which allows to get the list of all sound IDs in existence and .ogg data for each.
3939 * Seeded by {@link SoundListMixin} on client launch. */
···5050 * <p>On player connect, the server sends a {@link ModPayloads.DownloadSoundPack} payload to the client.
5151 * <p>If the server already contains data upon which the client should create its resource pack, it holds this data.
5252 * <p>Otherwise, this payload is empty, and the server relies on the client to create it and send it back to the server for future use. */
5353- public static void unpackDownloadedPack(ModPayloads.DownloadSoundPack payload, Object clientContext) {
5454- MinecraftClient cl = ModPayloads.client(clientContext);
5555- //the client unpacks a non-empty payload only when needed, meaning only if it doesn't have necessary files yet
5656- if (!payload.songIds().isEmpty() && !Files.exists(cl.getResourcePackDir().resolve("infinity/assets/infinity/sounds.json"))) {
5757- cl.execute(() -> saveResourcePack(cl, payload.songIds().getList("entries", NbtElement.STRING_TYPE).stream()
5858- .map(NbtElement::asString).map(Identifier::of), false));
5959- }
6060- else if (isPreloaded()) {
6161- cl.execute(() -> {
6262- NbtCompound jukeboxes = saveResourcePack(cl, getMatchingLoadedIds(), true);
6363- NbtCompound res = new NbtCompound();
6464- NbtList songIds = new NbtList();
6565- getMatchingLoadedIds().forEach(id -> songIds.add(NbtString.of(id.toString())));
6666- res.put("entries", songIds);
6767- res.put("jukeboxes", jukeboxes);
6868- ClientPlayNetworking.send(new ModPayloads.UploadJukeboxes(res));
6969- });
7070- }
7171- }
5353+// public static void unpackDownloadedPack(ModPayloads.DownloadSoundPack payload, Object clientContext) {
5454+// MinecraftClient cl = ModPayloads.client(clientContext);
5555+// //the client unpacks a non-empty payload only when needed, meaning only if it doesn't have necessary files yet
5656+// if (!payload.songIds().isEmpty() && !Files.exists(cl.getResourcePackDir().resolve("infinity/assets/infinity/sounds.json"))) {
5757+// cl.execute(() -> saveResourcePack(cl, payload.songIds().getList("entries", NbtElement.STRING_TYPE).stream()
5858+// .map(NbtElement::asString).map(Identifier::of), false));
5959+// }
6060+// else if (isPreloaded()) {
6161+// cl.execute(() -> {
6262+// NbtCompound jukeboxes = saveResourcePack(cl, getMatchingLoadedIds(), true);
6363+// NbtCompound res = new NbtCompound();
6464+// NbtList songIds = new NbtList();
6565+// getMatchingLoadedIds().forEach(id -> songIds.add(NbtString.of(id.toString())));
6666+// res.put("entries", songIds);
6767+// res.put("jukeboxes", jukeboxes);
6868+// ClientPlayNetworking.send(new ModPayloads.UploadJukeboxes(res));
6969+// });
7070+// }
7171+// }
7272 /**
7373 * Generating and saving a resource pack from a stream of identifiers that correspond to music tracks.
7474 * @param sendJukeboxes if this is true, the method also generates and returns data that needs to be sent to the server
···8080 songIds.forEach(id -> {
8181 String str = id.toString().replace(".ogg", "").replace("sounds/", "");
8282 List<String> arr = Arrays.stream(str.split("[:/]")).toList(); //preloading IDs
8383- String songID = "disc." + arr.getFirst() + "." + arr.getLast();
8383+ String songID = "disc." + arr.get(0) + "." + arr.get(arr.size()-1);
8484 String subtitleID = "infinity:subtitles." + songID;
8585- String subtitleData = InfinityMethods.formatAsTitleCase(arr.getFirst() + " - " + arr.getLast());
8585+ String subtitleData = InfinityMethods.formatAsTitleCase(arr.get(0) + " - " + arr.get(arr.size()-1));
86868787 NbtList soundForRPList = new NbtList();
8888 soundForRPList.add(NbtString.of(str));
···100100 } catch (IOException e) {
101101 length = 600;
102102 }
103103- jukeboxes.put(arr.getLast(), getJukeboxDef(songID, subtitleID, length));
103103+ jukeboxes.put(arr.get(arr.size()-1), getJukeboxDef(songID, subtitleID, length));
104104 }
105105 });
106106 CommonIO.write(soundsForRP, client.getResourcePackDir().resolve("infinity/assets/infinity"), "sounds.json");
···108108 return jukeboxes;
109109 }
110110111111- /** Receiver for a C2S {@link ModPayloads.UploadJukeboxes} payload, which holds data to send to clients in the future for them to
111111+ /** Receiver for a C2S {@link ModPayloads} payload, which holds data to send to clients in the future for them to
112112 * generate custom sound resource packs, as well as jukebox song definitions corresponding to this data. */
113113- public static void unpackUploadedJukeboxes(ModPayloads.UploadJukeboxes payload, ServerPlayNetworking.Context context) {
114114- if (!InfinityMod.provider.rule("useSoundSyncPackets")) return;
115115- NbtCompound data = payload.data();
116116- if (!data.contains("jukeboxes") || !data.contains("entries")) return;
117117- MinecraftServer server = context.player().server;
118118- if (Files.exists(server.getSavePath(WorldSavePath.DATAPACKS).resolve("client_sound_pack_data.json"))) return;
119119-120120- unpackUploadedJukeboxes(server, data.getCompound("jukeboxes"));
121121- data.remove("jukeboxes");
122122- NbtCompound packData = new NbtCompound();
123123- packData.put("entries", data.get("entries"));
124124- CommonIO.write(packData, server.getSavePath(WorldSavePath.DATAPACKS), "client_sound_pack_data.json");
125125- }
113113+// public static void unpackUploadedJukeboxes(ModPayloads payload, ServerPlayNetworking.Context context) {
114114+// if (!InfinityMod.provider.rule("useSoundSyncPackets")) return;
115115+// NbtCompound data = payload.data();
116116+// if (!data.contains("jukeboxes") || !data.contains("entries")) return;
117117+// MinecraftServer server = context.player().server;
118118+// if (Files.exists(server.getSavePath(WorldSavePath.DATAPACKS).resolve("client_sound_pack_data.json"))) return;
119119+//
120120+// unpackUploadedJukeboxes(server, data.getCompound("jukeboxes"));
121121+// data.remove("jukeboxes");
122122+// NbtCompound packData = new NbtCompound();
123123+// packData.put("entries", data.get("entries"));
124124+// CommonIO.write(packData, server.getSavePath(WorldSavePath.DATAPACKS), "client_sound_pack_data.json");
125125+// }
126126 public static void unpackUploadedJukeboxes(MinecraftServer server, NbtCompound allJukeboxes) {
127127 Path pathJukeboxes = server.getSavePath(WorldSavePath.DATAPACKS).resolve("infinity/data/infinity/jukebox_song");
128128 for (String key: allJukeboxes.getKeys()) {
···130130 CommonIO.write(jukebox, pathJukeboxes, key + ".json");
131131 }
132132 }
133133- grabJukeboxes(server);
133133+// grabJukeboxes(server);
134134 }
135135 /** Injects freshly received jukebox song definitions into the server's registries, config files and {@link RandomProvider}. */
136136- public static void grabJukeboxes(MinecraftServer server) {
137137- Path pathJukeboxes = server.getSavePath(WorldSavePath.DATAPACKS).resolve("infinity/data/infinity/jukebox_song");
138138- InfinityMod.LOGGER.info("grabbing jukeboxes");
139139- DimensionGrabber grabber = new DimensionGrabber(server.getRegistryManager());
140140- grabber.buildGrabber(JukeboxSong.CODEC, RegistryKeys.JUKEBOX_SONG).grabAll(pathJukeboxes);
141141- grabber.close();
142142- if (!((MinecraftServerAccess)server).infinity$needsInvocation()) {
143143- ConfigFactory.of(server.getRegistryManager().get(RegistryKeys.JUKEBOX_SONG)).generate("misc", "jukeboxes");
144144- InfinityMod.updateProvider(server);
145145- }
146146- }
136136+// public static void grabJukeboxes(MinecraftServer server) {
137137+// Path pathJukeboxes = server.getSavePath(WorldSavePath.DATAPACKS).resolve("infinity/data/infinity/jukebox_song");
138138+// InfinityMod.LOGGER.info("grabbing jukeboxes");
139139+// DimensionGrabber grabber = new DimensionGrabber(server.getRegistryManager());
140140+// grabber.buildGrabber(JukeboxSong.CODEC, RegistryKeys.JUKEBOX_SONG).grabAll(pathJukeboxes);
141141+// grabber.close();
142142+// if (!((MinecraftServerAccess)server).infinity$needsInvocation()) {
143143+// ConfigFactory.of(server.getRegistryManager().get(RegistryKeys.JUKEBOX_SONG)).generate("misc", "jukeboxes");
144144+// InfinityMod.updateProvider(server);
145145+// }
146146+// }
147147148148 /**
149149 Getting a duration of an OGG file from its byte data; <a href="https://stackoverflow.com/a/44407355">implementation from StackOverflow</a>.