use of com.ferreusveritas.dynamictrees.worldgen.json.IJsonBiomeSelector 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));
});
}
Aggregations