Search in sources :

Example 1 with RandomSpeciesSelector

use of com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.RandomSpeciesSelector in project DynamicTrees by DynamicTreesTeam.

the class JsonBiomePropertyApplierSpecies method readSpeciesSelector.

private ISpeciesSelector readSpeciesSelector(JsonObject mainObject) {
    JsonElement staticElement = mainObject.get("static");
    if (staticElement != null && staticElement.isJsonPrimitive()) {
        return createStaticSpeciesSelector(staticElement.getAsString());
    }
    JsonElement randomElement = mainObject.get("random");
    if (randomElement != null && randomElement.isJsonObject()) {
        RandomSpeciesSelector rand = new RandomSpeciesSelector();
        for (Entry<String, JsonElement> entry : randomElement.getAsJsonObject().entrySet()) {
            String speciesName = entry.getKey();
            JsonElement speciesElement = entry.getValue();
            int weight = 0;
            if (speciesElement.isJsonPrimitive() && speciesElement.getAsJsonPrimitive().isNumber()) {
                weight = speciesElement.getAsJsonPrimitive().getAsInt();
                if (weight > 0) {
                    if (isDefault(speciesName)) {
                        rand.add(weight);
                    } else {
                        Species species = TreeRegistry.findSpeciesSloppy(speciesName);
                        if (species != Species.NULLSPECIES) {
                            rand.add(species, weight);
                        }
                    }
                }
            }
        }
        if (rand.getSize() > 0) {
            return rand;
        }
    }
    return null;
}
Also used : RandomSpeciesSelector(com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.RandomSpeciesSelector) JsonElement(com.google.gson.JsonElement) Species(com.ferreusveritas.dynamictrees.trees.Species)

Aggregations

RandomSpeciesSelector (com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.RandomSpeciesSelector)1 Species (com.ferreusveritas.dynamictrees.trees.Species)1 JsonElement (com.google.gson.JsonElement)1