Search in sources :

Example 1 with BiomeDataBase

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

the class WorldGenRegistry method populateDataBase.

public static void populateDataBase() {
    if (WorldGenRegistry.isWorldGenEnabled()) {
        BiomeDataBaseJsonCapabilityRegistryEvent capabilityEvent = new BiomeDataBaseJsonCapabilityRegistryEvent();
        // Register the main Json capabilities
        BiomeDataBasePopulatorJson.registerJsonCapabilities(capabilityEvent);
        // Send out an event asking for Json Capabilities to be registered
        MinecraftForge.EVENT_BUS.post(capabilityEvent);
        // Prep the databases by clearing them out
        TreeGenerator.getTreeGenerator().clearAllBiomeDataBases();
        BiomeDataBase database = TreeGenerator.getTreeGenerator().getDefaultBiomeDataBase();
        // This collects all available populators and returns an aggregate populator for the lot
        IBiomeDataBasePopulator biomePopulator = collectDataBasePopulators();
        // This is where the main population occurs
        biomePopulator.populate(database);
        // Send out an event after the database has been populated
        MinecraftForge.EVENT_BUS.post(new PopulateDataBaseEvent(database, biomePopulator));
        // Populate custom dimensions if available
        loadMultiDimensionalPopulator(biomePopulator);
        // Blacklist certain dimensions according to the base config
        ModConfigs.dimensionBlacklist.forEach(d -> TreeGenerator.getTreeGenerator().BlackListDimension(d));
        // Cleanup all of the unused static objects
        BiomeDataBasePopulatorJson.cleanup();
    }
}
Also used : IBiomeDataBasePopulator(com.ferreusveritas.dynamictrees.api.worldgen.IBiomeDataBasePopulator) PopulateDataBaseEvent(com.ferreusveritas.dynamictrees.api.events.PopulateDataBaseEvent) BiomeDataBase(com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase)

Example 2 with BiomeDataBase

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

the class JsonBiomePropertyApplierDensity method apply.

@Override
public void apply(BiomeDataBase dbase, JsonElement element, Biome biome) {
    if (element.isJsonObject()) {
        JsonObject object = element.getAsJsonObject();
        Operation operation = readMethod(object);
        dbase.setDensitySelector(biome, readDensitySelector(object, biome), operation);
    } else if (element.isJsonArray()) {
        dbase.setDensitySelector(biome, createScaleDensitySelector(element.getAsJsonArray()), Operation.REPLACE);
    } else if (element.isJsonPrimitive()) {
        JsonPrimitive prim = element.getAsJsonPrimitive();
        if (prim.isNumber()) {
            float value = prim.getAsFloat();
            dbase.setDensitySelector(biome, (rnd, n) -> value, Operation.REPLACE);
        } else if (prim.isString()) {
            String simple = prim.getAsString();
            if ("standard".equals(simple)) {
                final double treeDensity = MathHelper.clamp(biome.decorator.treesPerChunk / 10.0f, 0.0f, 1.0f);
                dbase.setDensitySelector(biome, (rnd, n) -> n * treeDensity, Operation.REPLACE);
            }
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) List(java.util.List) MathHelper(net.minecraft.util.math.MathHelper) BiomeDataBase(com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase) Operation(com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase.Operation) JsonPrimitive(com.google.gson.JsonPrimitive) IDensitySelector(com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.IDensitySelector) Biome(net.minecraft.world.biome.Biome) ArrayList(java.util.ArrayList) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) Operation(com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase.Operation)

Aggregations

BiomeDataBase (com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase)2 PopulateDataBaseEvent (com.ferreusveritas.dynamictrees.api.events.PopulateDataBaseEvent)1 IDensitySelector (com.ferreusveritas.dynamictrees.api.worldgen.BiomePropertySelectors.IDensitySelector)1 IBiomeDataBasePopulator (com.ferreusveritas.dynamictrees.api.worldgen.IBiomeDataBasePopulator)1 Operation (com.ferreusveritas.dynamictrees.worldgen.BiomeDataBase.Operation)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 List (java.util.List)1 MathHelper (net.minecraft.util.math.MathHelper)1 Biome (net.minecraft.world.biome.Biome)1