mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-08-30 05:40:34 +00:00
Implement load-dependent population
This commit is contained in:
@@ -83,7 +83,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.polydev</groupId>
|
<groupId>org.polydev</groupId>
|
||||||
<artifactId>gaea</artifactId>
|
<artifactId>gaea</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package com.dfsek.terra;
|
|||||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.config.WorldConfig;
|
import com.dfsek.terra.config.WorldConfig;
|
||||||
import com.dfsek.terra.population.FaunaPopulator;
|
import com.dfsek.terra.population.FaunaPopulator;
|
||||||
|
import com.dfsek.terra.population.TreePopulator;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.polydev.gaea.biome.BiomeGrid;
|
|
||||||
import org.polydev.gaea.generation.GaeaChunkGenerator;
|
import org.polydev.gaea.generation.GaeaChunkGenerator;
|
||||||
import org.polydev.gaea.generation.GenerationPopulator;
|
import org.polydev.gaea.generation.GenerationPopulator;
|
||||||
import org.polydev.gaea.math.FastNoise;
|
import org.polydev.gaea.math.FastNoise;
|
||||||
import org.polydev.gaea.math.InterpolationType;
|
import org.polydev.gaea.math.InterpolationType;
|
||||||
|
import org.polydev.gaea.population.PopulationManager;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -20,8 +20,10 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class TerraChunkGenerator extends GaeaChunkGenerator {
|
public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||||
|
private final PopulationManager popMan = new PopulationManager();
|
||||||
public TerraChunkGenerator() {
|
public TerraChunkGenerator() {
|
||||||
super(InterpolationType.TRILINEAR);
|
super(InterpolationType.TRILINEAR);
|
||||||
|
popMan.attach(new TreePopulator(popMan));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,6 +62,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||||
return Arrays.asList(new FaunaPopulator());
|
return Arrays.asList(popMan, new FaunaPopulator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import java.util.Map;
|
|||||||
public class UserDefinedDecorator extends Decorator {
|
public class UserDefinedDecorator extends Decorator {
|
||||||
|
|
||||||
private final ProbabilityCollection<Fauna> fauna = new ProbabilityCollection<>();
|
private final ProbabilityCollection<Fauna> fauna = new ProbabilityCollection<>();
|
||||||
private int faunaChance;
|
private final ProbabilityCollection<Tree> trees = new ProbabilityCollection<>();
|
||||||
|
private final int faunaChance;
|
||||||
|
private final int treeChance;
|
||||||
|
private final int treeDensity;
|
||||||
|
|
||||||
public UserDefinedDecorator(BiomeConfig config) {
|
public UserDefinedDecorator(BiomeConfig config) {
|
||||||
if(config.contains("fauna")) {
|
if(config.contains("fauna")) {
|
||||||
@@ -20,17 +23,28 @@ public class UserDefinedDecorator extends Decorator {
|
|||||||
fauna.add(Fauna.valueOf(e.getKey()), (Integer) e.getValue());
|
fauna.add(Fauna.valueOf(e.getKey()), (Integer) e.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(config.contains("trees")) {
|
||||||
|
for(Map.Entry<String, Object> e : config.getConfigurationSection("trees").getValues(false).entrySet()) {
|
||||||
|
trees.add(Tree.valueOf(e.getKey()), (Integer) e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
faunaChance = config.getInt("fauna-chance", 0);
|
faunaChance = config.getInt("fauna-chance", 0);
|
||||||
|
treeChance = config.getInt("tree-chance", 0);
|
||||||
|
treeDensity = config.getInt("tree-density", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbabilityCollection<Tree> getTrees() {
|
public ProbabilityCollection<Tree> getTrees() {
|
||||||
return null;
|
return trees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTreeChance() {
|
||||||
|
return treeChance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTreeDensity() {
|
public int getTreeDensity() {
|
||||||
return 0;
|
return treeDensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class BiomeGridConfig extends YamlConfiguration {
|
|||||||
this.gridID = getString("id");
|
this.gridID = getString("id");
|
||||||
if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!");
|
if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!");
|
||||||
this.friendlyName = getString("name");
|
this.friendlyName = getString("name");
|
||||||
this.grid = new UserDefinedGrid(world, 1f/256, 1f/512, this);// TODO: custom frequency
|
this.grid = new UserDefinedGrid(world, 1f/512, 1f/1024, this);// TODO: custom frequency
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ public class WorldConfig {
|
|||||||
private static JavaPlugin main;
|
private static JavaPlugin main;
|
||||||
private static final Map<World, WorldConfig> configs = new HashMap<>();
|
private static final Map<World, WorldConfig> configs = new HashMap<>();
|
||||||
private final Map<String, BiomeGridConfig> biomeGrids = new HashMap<>();
|
private final Map<String, BiomeGridConfig> biomeGrids = new HashMap<>();
|
||||||
public float zoneFreq = 1f/1536;
|
public float zoneFreq;
|
||||||
public float freq1 = 1f/256;
|
public float freq1;
|
||||||
public float freq2 = 1f/512;
|
public float freq2;
|
||||||
public int seaLevel;
|
public int seaLevel;
|
||||||
public UserDefinedGrid[] definedGrids = new UserDefinedGrid[32];
|
public UserDefinedGrid[] definedGrids = new UserDefinedGrid[32];
|
||||||
|
|
||||||
@@ -66,6 +66,9 @@ public class WorldConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
seaLevel = config.getInt("sea-level", 63);
|
seaLevel = config.getInt("sea-level", 63);
|
||||||
|
zoneFreq = config.getInt("frequencies.zone", 1536);
|
||||||
|
freq1 = config.getInt("frequencies.grid-1", 256);
|
||||||
|
freq2 = config.getInt("frequencies.grid-2", 512);
|
||||||
|
|
||||||
try (Stream<Path> paths = Files.walk(Paths.get(main.getDataFolder() + File.separator + "grids"))) {
|
try (Stream<Path> paths = Files.walk(Paths.get(main.getDataFolder() + File.separator + "grids"))) {
|
||||||
paths
|
paths
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ public class LookupGenerator {
|
|||||||
private static double[] lookup;
|
private static double[] lookup;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int dist = 32;
|
int dist = 16;
|
||||||
|
|
||||||
List<Double> vals = new ArrayList<>();
|
List<Double> vals = new ArrayList<>();
|
||||||
FastNoise noise = new FastNoise(new Random().nextInt());
|
FastNoise noise = new FastNoise(new Random().nextInt());
|
||||||
@@ -25,7 +25,7 @@ public class LookupGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 10000000; i++) {
|
for(int i = 0; i < 10000000; i++) {
|
||||||
double n = noise.getSimplexFractal(0, i);
|
double n = noise.getNoise(0, i);
|
||||||
max = Math.max(max, n);
|
max = Math.max(max, n);
|
||||||
min = Math.min(min, n);
|
min = Math.min(min, n);
|
||||||
vals.add(n);
|
vals.add(n);
|
||||||
@@ -59,7 +59,7 @@ public class LookupGenerator {
|
|||||||
numbers = new int[dist];
|
numbers = new int[dist];
|
||||||
vals = new ArrayList<>();
|
vals = new ArrayList<>();
|
||||||
for(int i = 0; i < 10000000; i++) {
|
for(int i = 0; i < 10000000; i++) {
|
||||||
double n = noise.getSimplexFractal(0, i);
|
double n = noise.getNoise(0, i);
|
||||||
vals.add(n);
|
vals.add(n);
|
||||||
numbers[normalizeNew(n)]++;
|
numbers[normalizeNew(n)]++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user