use of com.mcmoddev.orespawn.OreSpawn in project OreSpawn by MinecraftModDevelopmentMods.
the class ReplacementsRegistry method saveFile.
public void saveFile(String modName) {
JsonObject outs = new JsonObject();
registry.getEntries().stream().filter(ent -> ent.getKey().getResourceDomain().equals(modName)).forEach(ent -> {
JsonArray entry = new JsonArray();
IReplacementEntry workVal = ent.getValue();
workVal.getEntries().stream().forEach(bs -> {
JsonObject block = new JsonObject();
block.addProperty(Constants.ConfigNames.BLOCK, bs.getBlock().getRegistryName().toString());
if (!bs.toString().matches("\\[normal\\]")) {
block.addProperty(Constants.ConfigNames.STATE, bs.toString().replaceAll("[\\[\\]]", ""));
}
entry.add(block);
});
outs.add(ent.getKey().toString(), entry);
});
Path p = Paths.get("config", "orespawn3", "sysconfig", String.format("replacements-%s.json", modName));
try (BufferedWriter w = Files.newBufferedWriter(p)) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String ov = gson.toJson(outs);
w.write(ov);
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed writing replacements file %s", p.toAbsolutePath().toString()));
report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
}
Aggregations