Search in sources :

Example 1 with IJsonBiomeApplier

use of com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeApplier in project DynamicTrees by DynamicTreesTeam.

the class BiomeDataBasePopulatorJson method readSection.

private void readSection(JsonObject section, BiomeDataBase dbase) {
    List<JsonBiomeSelectorData> selectors = new LinkedList<>();
    List<JsonBiomeApplierData> appliers = new LinkedList<>();
    for (Entry<String, JsonElement> entry : section.entrySet()) {
        String key = entry.getKey();
        JsonElement element = entry.getValue();
        if (!isComment(key)) {
            if (WHITE.equals(key)) {
                if (element.isJsonPrimitive()) {
                    if ("all".equals(element.getAsString())) {
                        blacklistedBiomes.clear();
                    }
                }
            } else if (SELECT.equals(key)) {
                if (element.isJsonObject()) {
                    for (Entry<String, JsonElement> selectElement : element.getAsJsonObject().entrySet()) {
                        String selectorName = selectElement.getKey();
                        if (!isComment(selectorName)) {
                            IJsonBiomeSelector selector = jsonBiomeSelectorMap.get(selectorName);
                            if (selector != null) {
                                selectors.add(new JsonBiomeSelectorData(selector, selectElement.getValue()));
                            } else {
                                System.err.println("Json Error: Undefined selector property \"" + selectorName + "\"");
                            }
                        }
                    }
                }
            } else if (APPLY.equals(key)) {
                if (element.isJsonObject()) {
                    for (Entry<String, JsonElement> selectElement : element.getAsJsonObject().entrySet()) {
                        String applierName = selectElement.getKey();
                        if (!isComment(applierName)) {
                            IJsonBiomeApplier applier = jsonBiomeApplierMap.get(applierName);
                            if (applier != null) {
                                appliers.add(new JsonBiomeApplierData(applier, selectElement.getValue()));
                            } else {
                                System.err.println("Json Error: Undefined applier property \"" + applierName + "\"");
                            }
                        }
                    }
                }
            } else {
                System.err.println("Json Error: Undefined operation \"" + key + "\"");
            }
        }
    }
    // Filter biomes by selector predicates
    Stream<Biome> stream = Lists.newArrayList(Biome.REGISTRY).stream();
    for (JsonBiomeSelectorData s : selectors) {
        stream = stream.filter(s.getFilter());
    }
    // Filter blacklisted biomes
    stream = stream.filter(b -> !blacklistedBiomes.contains(b));
    // Apply all of the applicators to the database
    stream.forEach(biome -> {
        appliers.forEach(a -> a.apply(dbase, biome));
    });
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) HashMap(java.util.HashMap) Operation(com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase.Operation) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JsonElement(com.google.gson.JsonElement) IJsonBiomeSelector(com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeSelector) Lists(com.google.common.collect.Lists) JsonBiomePropertyApplierChance(com.ferreusveritas.dynamictrees.worldgen.json.JsonBiomePropertyApplierChance) BiomeDictionary(net.minecraftforge.common.BiomeDictionary) Map(java.util.Map) EnumChance(com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.EnumChance) JsonHelper(com.ferreusveritas.dynamictrees.util.JsonHelper) JsonPrimitive(com.google.gson.JsonPrimitive) LinkedList(java.util.LinkedList) Predicate(java.util.function.Predicate) JsonBiomePropertyApplierSpecies(com.ferreusveritas.dynamictrees.worldgen.json.JsonBiomePropertyApplierSpecies) Set(java.util.Set) Collectors(java.util.stream.Collectors) BiomeDataBaseJsonCapabilityRegistryEvent(com.ferreusveritas.dynamictrees.api.WorldGenRegistry.BiomeDataBaseJsonCapabilityRegistryEvent) IBiomeDataBasePopulator(com.ferreusveritas.dynamictrees.api.worldgen.IBiomeDataBasePopulator) List(java.util.List) JsonArray(com.google.gson.JsonArray) Stream(java.util.stream.Stream) SpeciesSelection(com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.SpeciesSelection) JsonBiomePropertyApplierDensity(com.ferreusveritas.dynamictrees.worldgen.json.JsonBiomePropertyApplierDensity) Entry(java.util.Map.Entry) ResourceLocation(net.minecraft.util.ResourceLocation) IJsonBiomeApplier(com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeApplier) Biome(net.minecraft.world.biome.Biome) IJsonBiomeApplier(com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeApplier) LinkedList(java.util.LinkedList) Entry(java.util.Map.Entry) IJsonBiomeSelector(com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeSelector) Biome(net.minecraft.world.biome.Biome) JsonElement(com.google.gson.JsonElement)

Aggregations

BiomeDataBaseJsonCapabilityRegistryEvent (com.ferreusveritas.dynamictrees.api.WorldGenRegistry.BiomeDataBaseJsonCapabilityRegistryEvent)1 EnumChance (com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.EnumChance)1 SpeciesSelection (com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.SpeciesSelection)1 IBiomeDataBasePopulator (com.ferreusveritas.dynamictrees.api.worldgen.IBiomeDataBasePopulator)1 JsonHelper (com.ferreusveritas.dynamictrees.util.JsonHelper)1 Operation (com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase.Operation)1 IJsonBiomeApplier (com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeApplier)1 IJsonBiomeSelector (com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeSelector)1 JsonBiomePropertyApplierChance (com.ferreusveritas.dynamictrees.worldgen.json.JsonBiomePropertyApplierChance)1 JsonBiomePropertyApplierDensity (com.ferreusveritas.dynamictrees.worldgen.json.JsonBiomePropertyApplierDensity)1 JsonBiomePropertyApplierSpecies (com.ferreusveritas.dynamictrees.worldgen.json.JsonBiomePropertyApplierSpecies)1 Lists (com.google.common.collect.Lists)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1