Add more Flora config options

This commit is contained in:
dfsek
2020-09-24 02:18:08 -07:00
parent ae4be37fe8
commit fd49d0a99c
5 changed files with 107 additions and 32 deletions

View File

@@ -2,6 +2,8 @@ package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Block;
@@ -19,13 +21,16 @@ public class FloraPopulator extends GaeaBlockPopulator {
ProfileFuture flora = TerraProfiler.fromWorld(world).measure("FloraTime");
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
Biome biome = TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
UserDefinedBiome biome = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
if(biome.getDecorator().getFloraChance() <= 0 || random.nextInt(100) > biome.getDecorator().getFloraChance())
continue;
try {
Flora item = biome.getDecorator().getFlora().get(random);
Block highest = item.getHighestValidSpawnAt(chunk, x, z);
if(highest != null) item.plant(highest.getLocation());
BiomeConfig c = BiomeConfig.fromBiome(biome);
for(int i = 0; i < c.getFloraAttempts(); i++) {
Flora item = biome.getDecorator().getFlora().get(random);
Block highest = item.getHighestValidSpawnAt(chunk, x, z);
if(highest != null && c.getFloraHeights(item).isInRange(highest.getY())) item.plant(highest.getLocation());
}
} catch(NullPointerException ignored) {}
}
}