/** * Dynamically generates a sound JSON file based on a resource pack's file structure. * * If it's a folder, then load it as a sound collection. * A sound collection falls under the same resource name. When called to play, it will pick a random sound from the collection to play it. * * If it's just a sound file, then load the sound file * * @param pack The resource pack to generate the sound JSON for. * @return The generated sound JSON. */ public static String generateSoundJSON(AbstractResourcePack pack) { StringWriter sw = new StringWriter(); try (JsonGenerator json = Json.createGenerator(sw);) { json.writeStartObject(); if (pack instanceof FileResourcePack) { //For zip resource packs try { generateSoundJSON((FileResourcePack) pack, json); } catch (Exception e) { Error error = new ExceptionInInitializerError("Error generating fake sound JSON file."); error.addSuppressed(e); throw error; } } else if (pack instanceof FolderResourcePack) { //For folder resource packs generateSoundJSON((FolderResourcePack) pack, json); } json.writeEnd().flush(); return sw.toString(); } }
@SuppressWarnings("unchecked") private static JsonGenerator generateSoundJSON(FolderResourcePack pack, JsonGenerator json) { for (String domain : (Set<String>) pack.getResourceDomains()) { //Load all sounds in the assets/domain/sounds/* File folder = getFileForResourcePack(pack, "assets/" + domain + "/sounds/"); if (folder.exists()) { for (File listedFile : folder.listFiles()) { String soundName = listedFile.getName().replaceFirst("\\.[^\\.]+$", ""); json.writeStartObject(soundName); json.write("category", "ambient"); json.writeStartArray("sounds"); if (listedFile.isFile()) { json.write(soundName); } else if (listedFile.isDirectory()) { for (File soundItemFile : listedFile.listFiles()) json.write(soundName + "/" + soundItemFile.getName().replaceFirst("\\.[^\\.]+$", "")); } json.writeEnd().writeEnd(); } } } return json; }
public void func_110516_a() throws IOException { this.field_110524_c = (ResourcePack)(this.field_110523_b.isDirectory()?new FolderResourcePack(this.field_110523_b):new FileResourcePack(this.field_110523_b)); this.field_110521_d = (PackMetadataSection)this.field_110524_c.func_135058_a(this.field_110525_a.field_110621_c, "pack"); try { this.field_110522_e = this.field_110524_c.func_110586_a(); } catch (IOException var2) { ; } if(this.field_110522_e == null) { this.field_110522_e = this.field_110525_a.field_110620_b.func_110586_a(); } this.func_110517_b(); }
private static IResourcePack createResourcePack(File file) { if(file.isDirectory()) { return new FolderResourcePack(file); } else { return new FileResourcePack(file); } }
public static File getFileForResourcePack(FolderResourcePack pack, String path) { if (pack instanceof NovaFolderResourcePack) { Optional<File> file = ((NovaFolderResourcePack) pack).findFileCaseInsensitive(path); if (file.isPresent()) return file.get(); } return new File(pack.resourcePackFile, path); }
@Override public void loadCoreModules() { List<IResourcePack> defaultResourcePacks = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "defaultResourcePacks", "field_110449_ao"); defaultResourcePacks.add(new FolderResourcePack(new File(Minecraft.getMinecraft().mcDataDir, "/RLM"))); File screenshots = new File(Minecraft.getMinecraft().mcDataDir, "screenshots"); if (!screenshots.exists()) { screenshots.mkdirs(); } for (File f : screenshots.listFiles()) { Screenshotspack.filenames.add(f.getName()); } defaultResourcePacks.add(new Screenshotspack()); Minecraft.getMinecraft().refreshResources(); File RLMDirectory = new File(Minecraft.getMinecraft().mcDataDir, "RLM/texts"); if (RLMDirectory.exists()) { File jobfile = new File(RLMDirectory, "Jobs.txt"); File newjobfile = null; try { FileUtils.copyURLToFile(new URL("http://themoddingparadise.de/RealLifeMod/Jobs.txt"), jobfile); jobfile.setLastModified(System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); } if (jobfile.exists()) { System.out.println("Succesfully downloaded Resources"); } } else { RLMDirectory.mkdirs(); } }