mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-23 08:38:51 +00:00
Implement load-dependent population
This commit is contained in:
45
src/main/java/com/dfsek/terra/population/TreePopulator.java
Normal file
45
src/main/java/com/dfsek/terra/population/TreePopulator.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedDecorator;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.population.GaeaBlockPopulator;
|
||||
import org.polydev.gaea.population.PopulationManager;
|
||||
import org.polydev.gaea.util.WorldUtil;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TreePopulator extends GaeaBlockPopulator {
|
||||
|
||||
public TreePopulator(PopulationManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
int x = random.nextInt(16); // Decrease chances of chunk-crossing trees
|
||||
int z = random.nextInt(16);
|
||||
Location origin = chunk.getBlock(x, 0, z).getLocation();
|
||||
Biome b = TerraBiomeGrid.fromWorld(world).getBiome(origin);
|
||||
if(((UserDefinedDecorator) b.getDecorator()).getTreeChance() < random.nextInt(100)) return;
|
||||
int numTrees = 0;
|
||||
for(int i = 0; i < 10; i++) {
|
||||
int y = WorldUtil.getHighestValidSpawnAt(chunk, x, z);
|
||||
if(y <= 0) continue;
|
||||
origin = chunk.getBlock(x, y, z).getLocation().add(0, 1, 0);
|
||||
b = TerraBiomeGrid.fromWorld(world).getBiome(origin);
|
||||
numTrees++;
|
||||
try {
|
||||
b.getDecorator().getTrees().get(random).plant(origin, random, false, Terra.getInstance());
|
||||
} catch(NullPointerException ignored) {}
|
||||
if(numTrees >= b.getDecorator().getTreeDensity()) return;
|
||||
x = random.nextInt(16); // Decrease chances of chunk-crossing trees
|
||||
z = random.nextInt(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user