Search in sources :

Example 1 with OreSpawn

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());
    }
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) StateUtil(com.mcmoddev.orespawn.util.StateUtil) JsonParser(com.google.gson.JsonParser) GsonBuilder(com.google.gson.GsonBuilder) IReplacementEntry(com.mcmoddev.orespawn.api.os3.IReplacementEntry) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) Charset(java.nio.charset.Charset) OreDictionary(net.minecraftforge.oredict.OreDictionary) Gson(com.google.gson.Gson) RegistryBuilder(net.minecraftforge.registries.RegistryBuilder) Map(java.util.Map) IForgeRegistryModifiable(net.minecraftforge.registries.IForgeRegistryModifiable) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) OreSpawn(com.mcmoddev.orespawn.OreSpawn) BufferedWriter(java.io.BufferedWriter) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ReplacementEntry(com.mcmoddev.orespawn.impl.os3.ReplacementEntry) Collectors(java.util.stream.Collectors) IBlockState(net.minecraft.block.state.IBlockState) CrashReport(net.minecraft.crash.CrashReport) JsonArray(com.google.gson.JsonArray) List(java.util.List) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Collections(java.util.Collections) JsonArray(com.google.gson.JsonArray) Path(java.nio.file.Path) IReplacementEntry(com.mcmoddev.orespawn.api.os3.IReplacementEntry) GsonBuilder(com.google.gson.GsonBuilder) CrashReport(net.minecraft.crash.CrashReport) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 OreSpawn (com.mcmoddev.orespawn.OreSpawn)1 IReplacementEntry (com.mcmoddev.orespawn.api.os3.IReplacementEntry)1 ReplacementEntry (com.mcmoddev.orespawn.impl.os3.ReplacementEntry)1 StateUtil (com.mcmoddev.orespawn.util.StateUtil)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1