mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Implement caves
This commit is contained in:
parent
2db311759f
commit
ad83a3054b
2
pom.xml
2
pom.xml
@ -83,7 +83,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.polydev</groupId>
|
<groupId>org.polydev</groupId>
|
||||||
<artifactId>gaea</artifactId>
|
<artifactId>gaea</artifactId>
|
||||||
<version>1.5.15</version>
|
<version>1.6.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
23
src/main/java/com/dfsek/terra/MaxMin.java
Normal file
23
src/main/java/com/dfsek/terra/MaxMin.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.dfsek.terra;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class MaxMin {
|
||||||
|
private final int min;
|
||||||
|
private final int max;
|
||||||
|
public MaxMin(int min, int max) {
|
||||||
|
this.max = max;
|
||||||
|
this.min = min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
public int get(Random r) {
|
||||||
|
return r.nextInt((max-min)+1)+min;
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,24 @@
|
|||||||
package com.dfsek.terra;
|
package com.dfsek.terra;
|
||||||
|
|
||||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||||
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.WorldConfig;
|
import com.dfsek.terra.config.WorldConfig;
|
||||||
|
import com.dfsek.terra.population.CavePopulator;
|
||||||
import com.dfsek.terra.population.FaunaPopulator;
|
import com.dfsek.terra.population.FaunaPopulator;
|
||||||
import com.dfsek.terra.population.OrePopulator;
|
import com.dfsek.terra.population.OrePopulator;
|
||||||
import com.dfsek.terra.population.TreePopulator;
|
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.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
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.math.MathUtil;
|
||||||
import org.polydev.gaea.population.PopulationManager;
|
import org.polydev.gaea.population.PopulationManager;
|
||||||
|
import org.polydev.gaea.profiler.ProfileFuture;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -55,7 +60,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GenerationPopulator> getGenerationPopulators(World world) {
|
public List<GenerationPopulator> getGenerationPopulators(World world) {
|
||||||
return Collections.emptyList();
|
return Collections.singletonList(new CavePopulator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,7 +16,8 @@ public class TerraProfiler extends WorldProfiler {
|
|||||||
.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "ChunkBaseGenTime")
|
.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "ChunkBaseGenTime")
|
||||||
.addMeasurement(new Measurement(2000000, DataType.PERIOD_MILLISECONDS), "BiomeSetTime")
|
.addMeasurement(new Measurement(2000000, DataType.PERIOD_MILLISECONDS), "BiomeSetTime")
|
||||||
.addMeasurement(new Measurement(25000000, DataType.PERIOD_MILLISECONDS), "TreeGenTime")
|
.addMeasurement(new Measurement(25000000, DataType.PERIOD_MILLISECONDS), "TreeGenTime")
|
||||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "FaunaTime");
|
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "FaunaTime")
|
||||||
|
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "CaveTime");
|
||||||
profilerMap.put(w, this);
|
profilerMap.put(w, this);
|
||||||
}
|
}
|
||||||
public static TerraProfiler fromWorld(World w) {
|
public static TerraProfiler fromWorld(World w) {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.dfsek.terra;
|
package com.dfsek.terra;
|
||||||
|
|
||||||
import com.dfsek.terra.config.BiomeConfig;
|
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||||
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
|
import com.dfsek.terra.config.CarverConfig;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.polydev.gaea.world.carving.Carver;
|
import org.polydev.gaea.world.carving.Carver;
|
||||||
@ -9,36 +12,48 @@ import org.polydev.gaea.world.carving.Worm;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class UserDefinedCarver extends Carver {
|
public class UserDefinedCarver extends Carver {
|
||||||
private final int chance;
|
private final CarverConfig config;
|
||||||
private final int minLength;
|
public UserDefinedCarver(CarverConfig config) {
|
||||||
private final int maxLength;
|
super(config.getHeight().getMin(), config.getHeight().getMax());
|
||||||
public UserDefinedCarver(ConfigurationSection config) {
|
this.config = config;
|
||||||
super(config.getInt("y.min"), config.getInt("y.max"));
|
|
||||||
this.chance = config.getInt("chance");
|
|
||||||
minLength = config.getInt("length.min");
|
|
||||||
maxLength = config.getInt("length.max");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Worm getWorm(long l, Vector vector) {
|
public Worm getWorm(long l, Vector vector) {
|
||||||
return null;
|
Random r = new Random(l);
|
||||||
|
return new UserDefinedWorm(config.getLength().get(r), r, vector, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarverConfig getConfig() {
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChunkCarved(Random random) {
|
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||||
return random.nextInt(100) < chance;
|
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8);
|
||||||
|
return random.nextInt(100) < b.getCarverChance(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UserDefinedWorm extends Worm {
|
private static class UserDefinedWorm extends Worm {
|
||||||
|
private final Vector direction;
|
||||||
public UserDefinedWorm(int length, Random r, Vector origin) {
|
private final int maxRad;
|
||||||
|
private double runningRadius;
|
||||||
|
public UserDefinedWorm(int length, Random r, Vector origin, int maxRad) {
|
||||||
super(length, r, origin);
|
super(length, r, origin);
|
||||||
|
runningRadius = (r.nextDouble()/2+0.5)*4;
|
||||||
|
this.maxRad = maxRad;
|
||||||
|
direction = new Vector(r.nextDouble()-0.5D, (r.nextDouble()-0.5D)/4, r.nextDouble()-0.5D).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void step() {
|
public void step() {
|
||||||
|
setRadius(new int[] {(int) runningRadius, (int) runningRadius, (int) runningRadius});
|
||||||
|
runningRadius += (getRandom().nextDouble()-0.5)/8;
|
||||||
|
runningRadius = Math.min(runningRadius, maxRad);
|
||||||
|
direction.rotateAroundX(Math.toRadians(getRandom().nextDouble()*2));
|
||||||
|
direction.rotateAroundY(Math.toRadians(getRandom().nextDouble()*6));
|
||||||
|
direction.rotateAroundZ(Math.toRadians(getRandom().nextDouble()*2));
|
||||||
|
getRunning().add(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.dfsek.terra.biome;
|
package com.dfsek.terra.biome;
|
||||||
|
|
||||||
|
import com.dfsek.terra.UserDefinedCarver;
|
||||||
import com.dfsek.terra.config.BiomeConfig;
|
import com.dfsek.terra.config.BiomeConfig;
|
||||||
|
import com.dfsek.terra.config.CarverConfig;
|
||||||
import com.dfsek.terra.config.ConfigUtil;
|
import com.dfsek.terra.config.ConfigUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
@ -17,7 +19,9 @@ import org.polydev.gaea.structures.features.Feature;
|
|||||||
import org.polydev.gaea.tree.Tree;
|
import org.polydev.gaea.tree.Tree;
|
||||||
import org.polydev.gaea.world.BlockPalette;
|
import org.polydev.gaea.world.BlockPalette;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -27,6 +31,8 @@ public class UserDefinedBiome implements Biome {
|
|||||||
private final UserDefinedGenerator gen;
|
private final UserDefinedGenerator gen;
|
||||||
private final BiomeConfig config;
|
private final BiomeConfig config;
|
||||||
private final UserDefinedDecorator decorator;
|
private final UserDefinedDecorator decorator;
|
||||||
|
private final List<CarverConfig> carvers = new ArrayList<>();
|
||||||
|
private final Map<CarverConfig, Integer> carverChance = new HashMap<>();
|
||||||
public UserDefinedBiome(BiomeConfig config) throws ParseException, InvalidConfigurationException {
|
public UserDefinedBiome(BiomeConfig config) throws ParseException, InvalidConfigurationException {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
TreeMap<Integer, BlockPalette> paletteMap = new TreeMap<>();
|
TreeMap<Integer, BlockPalette> paletteMap = new TreeMap<>();
|
||||||
@ -53,11 +59,28 @@ public class UserDefinedBiome implements Biome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config.contains("carving")) {
|
||||||
|
for(Map<?, ?> e : config.getMapList("carving")) {
|
||||||
|
for(Map.Entry<?, ?> entry : e.entrySet()) {
|
||||||
|
try {
|
||||||
|
//carvers.add(new UserDefinedCarver((Integer) entry.getValue(), ConfigUtil.getCarver((String) entry.getKey())));
|
||||||
|
carverChance.put(ConfigUtil.getCarver((String) entry.getKey()), (Integer) entry.getValue());
|
||||||
|
} catch(ClassCastException ex) {
|
||||||
|
throw new InvalidConfigurationException("SEVERE configuration error for Carvers in biome" + config.getFriendlyName() + ", ID: " + config.getBiomeID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.decorator = new UserDefinedDecorator(config);
|
this.decorator = new UserDefinedDecorator(config);
|
||||||
|
|
||||||
gen = new UserDefinedGenerator(Objects.requireNonNull(config.getString("noise-equation")), Collections.emptyList(), paletteMap);
|
gen = new UserDefinedGenerator(Objects.requireNonNull(config.getString("noise-equation")), Collections.emptyList(), paletteMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<CarverConfig> getCarvers() {
|
||||||
|
return carvers;
|
||||||
|
}
|
||||||
|
|
||||||
public BiomeConfig getConfig() {
|
public BiomeConfig getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@ -101,4 +124,8 @@ public class UserDefinedBiome implements Biome {
|
|||||||
public Decorator getDecorator() {
|
public Decorator getDecorator() {
|
||||||
return decorator;
|
return decorator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCarverChance(CarverConfig c) {
|
||||||
|
return carverChance.getOrDefault(c, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.dfsek.terra.config;
|
package com.dfsek.terra.config;
|
||||||
|
|
||||||
|
import com.dfsek.terra.MaxMin;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -10,11 +10,8 @@ import org.polydev.gaea.math.parsii.tokenizer.ParseException;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class BiomeConfig extends YamlConfiguration {
|
public class BiomeConfig extends YamlConfiguration {
|
||||||
private UserDefinedBiome biome;
|
private UserDefinedBiome biome;
|
||||||
@ -25,6 +22,8 @@ public class BiomeConfig extends YamlConfiguration {
|
|||||||
private final Map<OreConfig, MaxMin> ores = new HashMap<>();
|
private final Map<OreConfig, MaxMin> ores = new HashMap<>();
|
||||||
private final Map<OreConfig, MaxMin> oreHeights = new HashMap<>();
|
private final Map<OreConfig, MaxMin> oreHeights = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public BiomeConfig(File file) throws InvalidConfigurationException, IOException {
|
public BiomeConfig(File file) throws InvalidConfigurationException, IOException {
|
||||||
super();
|
super();
|
||||||
load(file);
|
load(file);
|
||||||
@ -54,6 +53,8 @@ public class BiomeConfig extends YamlConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!contains("vanilla")) throw new InvalidConfigurationException("Vanilla Biome unspecified!");
|
if(!contains("vanilla")) throw new InvalidConfigurationException("Vanilla Biome unspecified!");
|
||||||
if(!contains("palette")) throw new InvalidConfigurationException("Palette unspecified!");
|
if(!contains("palette")) throw new InvalidConfigurationException("Palette unspecified!");
|
||||||
try {
|
try {
|
||||||
@ -91,24 +92,4 @@ public class BiomeConfig extends YamlConfiguration {
|
|||||||
public Map<OreConfig, MaxMin> getOres() {
|
public Map<OreConfig, MaxMin> getOres() {
|
||||||
return ores;
|
return ores;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MaxMin {
|
|
||||||
private final int min;
|
|
||||||
private final int max;
|
|
||||||
public MaxMin(int min, int max) {
|
|
||||||
this.max = max;
|
|
||||||
this.min = min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMax() {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMin() {
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
public int get(Random r) {
|
|
||||||
return r.nextInt((max-min)+1)+min;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.polydev.gaea.biome.BiomeGrid;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
75
src/main/java/com/dfsek/terra/config/CarverConfig.java
Normal file
75
src/main/java/com/dfsek/terra/config/CarverConfig.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package com.dfsek.terra.config;
|
||||||
|
|
||||||
|
import com.dfsek.terra.MaxMin;
|
||||||
|
import com.dfsek.terra.UserDefinedCarver;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.polydev.gaea.math.ProbabilityCollection;
|
||||||
|
import org.polydev.gaea.world.BlockPalette;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class CarverConfig extends YamlConfiguration {
|
||||||
|
private UserDefinedCarver carver;
|
||||||
|
private BlockPalette inner;
|
||||||
|
private BlockPalette walls;
|
||||||
|
private double[] start;
|
||||||
|
private double[] mutate;
|
||||||
|
private double radMutate;
|
||||||
|
private MaxMin length;
|
||||||
|
private MaxMin radius;
|
||||||
|
private MaxMin height;
|
||||||
|
private String id;
|
||||||
|
public CarverConfig(File file) throws IOException, InvalidConfigurationException {
|
||||||
|
super();
|
||||||
|
this.load(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public MaxMin getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaxMin getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserDefinedCarver getCarver() {
|
||||||
|
return carver;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
|
||||||
|
super.load(file);
|
||||||
|
if(Objects.requireNonNull(getString("palette.interior")).startsWith("BLOCK:")) {
|
||||||
|
inner = new BlockPalette().addBlockData(new ProbabilityCollection<BlockData>().add(Bukkit.createBlockData(getString("palette.interior").substring(6)), 1), 1);
|
||||||
|
} else {
|
||||||
|
inner = ConfigUtil.getPalette(getString("palette.interior")).getPalette();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Objects.requireNonNull(getString("palette.walls")).startsWith("BLOCK:")) {
|
||||||
|
walls = new BlockPalette().addBlockData(new ProbabilityCollection<BlockData>().add(Bukkit.createBlockData(getString("palette.walls").substring(6)), 1), 1);
|
||||||
|
} else {
|
||||||
|
walls = ConfigUtil.getPalette(getString("palette.walls")).getPalette();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
start = new double[] {getDouble("start.x"), getDouble("start.y"), getDouble("start.y")};
|
||||||
|
mutate = new double[] {getDouble("mutate.x"), getDouble("mutate.y"), getDouble("mutate.z")};
|
||||||
|
length = new MaxMin(getInt("length.min"), getInt("length.max"));
|
||||||
|
radius = new MaxMin(getInt("start.radius.min"), getInt("start.radius.max"));
|
||||||
|
height = new MaxMin(getInt("start.height.min"), getInt("start.height.max"));
|
||||||
|
radMutate = getDouble("mutate.radius");
|
||||||
|
id = getString("id");
|
||||||
|
carver = new UserDefinedCarver(this);
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,7 @@ public class ConfigUtil {
|
|||||||
private static final Map<String, OreConfig> ores = new HashMap<>();
|
private static final Map<String, OreConfig> ores = new HashMap<>();
|
||||||
private static final Map<String, PaletteConfig> palettes = new HashMap<>();
|
private static final Map<String, PaletteConfig> palettes = new HashMap<>();
|
||||||
private static final Map<String, FaunaConfig> faunaConfig = new HashMap<>();
|
private static final Map<String, FaunaConfig> faunaConfig = new HashMap<>();
|
||||||
|
private static final Map<String, CarverConfig> caveConfig = new HashMap<>();
|
||||||
|
|
||||||
public static void loadConfig(JavaPlugin main) {
|
public static void loadConfig(JavaPlugin main) {
|
||||||
Logger logger = main.getLogger();
|
Logger logger = main.getLogger();
|
||||||
@ -36,6 +37,8 @@ public class ConfigUtil {
|
|||||||
|
|
||||||
loadPalettes(main);
|
loadPalettes(main);
|
||||||
|
|
||||||
|
loadCaves(main);
|
||||||
|
|
||||||
loadFauna(main);
|
loadFauna(main);
|
||||||
|
|
||||||
loadBiomes(main);
|
loadBiomes(main);
|
||||||
@ -163,6 +166,33 @@ public class ConfigUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void loadCaves(JavaPlugin main) {
|
||||||
|
Logger logger = main.getLogger();
|
||||||
|
caveConfig.clear();
|
||||||
|
File oreFolder = new File(main.getDataFolder() + File.separator + "carving");
|
||||||
|
oreFolder.mkdirs();
|
||||||
|
try (Stream<Path> paths = Files.walk(oreFolder.toPath())) {
|
||||||
|
paths
|
||||||
|
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||||
|
.forEach(path -> {
|
||||||
|
logger.info("Loading cave from " + path.toString());
|
||||||
|
try {
|
||||||
|
CarverConfig cave = new CarverConfig(path.toFile());
|
||||||
|
caveConfig.put(cave.getID(), cave);
|
||||||
|
logger.info("ID: " + cave.getID());
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||||
|
logger.severe("Configuration error for Carver. ");
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
logger.severe("Correct this before proceeding!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static BiomeConfig getBiome(String id) {
|
public static BiomeConfig getBiome(String id) {
|
||||||
return biomes.get(id);
|
return biomes.get(id);
|
||||||
}
|
}
|
||||||
@ -175,6 +205,10 @@ public class ConfigUtil {
|
|||||||
return faunaConfig.get(id);
|
return faunaConfig.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CarverConfig getCarver(String id) {
|
||||||
|
return caveConfig.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
public static OreConfig getOre(String id) {
|
public static OreConfig getOre(String id) {
|
||||||
return ores.get(id);
|
return ores.get(id);
|
||||||
}
|
}
|
||||||
@ -182,4 +216,8 @@ public class ConfigUtil {
|
|||||||
public static <E extends Enum<E>> List<E> getElements(List<String> st, Class<E> clazz) {
|
public static <E extends Enum<E>> List<E> getElements(List<String> st, Class<E> clazz) {
|
||||||
return st.stream().map((s) -> E.valueOf(clazz, s)).collect(Collectors.toList());
|
return st.stream().map((s) -> E.valueOf(clazz, s)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<CarverConfig> getCarvers() {
|
||||||
|
return new ArrayList<>(caveConfig.values());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,10 @@ import org.polydev.gaea.world.BlockPalette;
|
|||||||
import org.polydev.gaea.world.Fauna;
|
import org.polydev.gaea.world.Fauna;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class FaunaConfig extends YamlConfiguration implements Fauna {
|
public class FaunaConfig extends YamlConfiguration implements Fauna {
|
||||||
private BlockPalette faunaPalette = new BlockPalette();
|
private BlockPalette faunaPalette = new BlockPalette();
|
||||||
@ -35,7 +31,7 @@ public class FaunaConfig extends YamlConfiguration implements Fauna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(@NotNull File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
|
||||||
super.load(file);
|
super.load(file);
|
||||||
if(!contains("blocks")) throw new InvalidConfigurationException("No blocks defined in custom fauna!");
|
if(!contains("blocks")) throw new InvalidConfigurationException("No blocks defined in custom fauna!");
|
||||||
if(!contains("id")) throw new InvalidConfigurationException("Fauna ID unspecified!");
|
if(!contains("id")) throw new InvalidConfigurationException("Fauna ID unspecified!");
|
||||||
@ -49,23 +45,10 @@ public class FaunaConfig extends YamlConfiguration implements Fauna {
|
|||||||
throw new InvalidConfigurationException("Invalid material ID in spawnable list: " + e.getMessage());
|
throw new InvalidConfigurationException("Invalid material ID in spawnable list: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
faunaPalette = new BlockPalette();
|
faunaPalette = PaletteConfig.getPalette(getMapList("blocks"));
|
||||||
for(Map<?, ?> m : getMapList("blocks")) {
|
if(!contains("id")) throw new InvalidConfigurationException("Fauna ID unspecified!");
|
||||||
try {
|
|
||||||
ProbabilityCollection<BlockData> layer = new ProbabilityCollection<>();
|
|
||||||
for(Map.Entry<String, Integer> type : ((Map<String, Integer>) m.get("materials")).entrySet()) {
|
|
||||||
layer.add(Bukkit.createBlockData(type.getKey()), type.getValue());
|
|
||||||
Bukkit.getLogger().info("[Terra] Added " + type.getKey() + " with probability " + type.getValue());
|
|
||||||
}
|
|
||||||
Bukkit.getLogger().info("[Terra] Added above materials for " + m.get("layers") + " layers.");
|
|
||||||
faunaPalette.addBlockData(layer, (Integer) m.get("layers"));
|
|
||||||
} catch(ClassCastException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!contains("id")) throw new InvalidConfigurationException("Grid ID unspecified!");
|
|
||||||
this.id = getString("id");
|
this.id = getString("id");
|
||||||
if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!");
|
if(!contains("name")) throw new InvalidConfigurationException("Fauna Name unspecified!");
|
||||||
this.friendlyName = getString("name");
|
this.friendlyName = getString("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.config;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -25,20 +26,7 @@ public class PaletteConfig extends YamlConfiguration {
|
|||||||
@Override
|
@Override
|
||||||
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
|
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
|
||||||
super.load(file);
|
super.load(file);
|
||||||
palette = new BlockPalette();
|
palette = getPalette(getMapList("blocks"));
|
||||||
for(Map<?, ?> m : getMapList("blocks")) {
|
|
||||||
try {
|
|
||||||
ProbabilityCollection<BlockData> layer = new ProbabilityCollection<>();
|
|
||||||
for(Map.Entry<String, Integer> type : ((Map<String, Integer>) m.get("materials")).entrySet()) {
|
|
||||||
layer.add(Bukkit.createBlockData(type.getKey()), type.getValue());
|
|
||||||
Bukkit.getLogger().info("[Terra] Added " + type.getKey() + " with probability " + type.getValue());
|
|
||||||
}
|
|
||||||
Bukkit.getLogger().info("[Terra] Added above materials for " + m.get("layers") + " layers.");
|
|
||||||
palette.addBlockData(layer, (Integer) m.get("layers"));
|
|
||||||
} catch(ClassCastException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!contains("id")) throw new InvalidConfigurationException("Grid ID unspecified!");
|
if(!contains("id")) throw new InvalidConfigurationException("Grid ID unspecified!");
|
||||||
this.paletteID = getString("id");
|
this.paletteID = getString("id");
|
||||||
if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!");
|
if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!");
|
||||||
@ -61,4 +49,22 @@ public class PaletteConfig extends YamlConfiguration {
|
|||||||
public String getPaletteID() {
|
public String getPaletteID() {
|
||||||
return paletteID;
|
return paletteID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BlockPalette getPalette(List<Map<?, ?>> maps) throws InvalidConfigurationException {
|
||||||
|
BlockPalette p = new BlockPalette();
|
||||||
|
for(Map<?, ?> m : maps) {
|
||||||
|
try {
|
||||||
|
ProbabilityCollection<BlockData> layer = new ProbabilityCollection<>();
|
||||||
|
for(Map.Entry<String, Integer> type : ((Map<String, Integer>) m.get("materials")).entrySet()) {
|
||||||
|
layer.add(Bukkit.createBlockData(type.getKey()), type.getValue());
|
||||||
|
Bukkit.getLogger().info("[Terra] Added " + type.getKey() + " with probability " + type.getValue());
|
||||||
|
}
|
||||||
|
Bukkit.getLogger().info("[Terra] Added above materials for " + m.get("layers") + " layers.");
|
||||||
|
p.addBlockData(layer, (Integer) m.get("layers"));
|
||||||
|
} catch(ClassCastException e) {
|
||||||
|
throw new InvalidConfigurationException("SEVERE configuration error for BlockPalette: \n\n" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
package com.dfsek.terra.population;
|
package com.dfsek.terra.population;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import com.dfsek.terra.TerraProfiler;
|
||||||
|
import com.dfsek.terra.config.CarverConfig;
|
||||||
|
import com.dfsek.terra.config.ConfigUtil;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.polydev.gaea.generation.GenerationPopulator;
|
||||||
import org.polydev.gaea.world.carving.Carver;
|
import org.polydev.gaea.profiler.ProfileFuture;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class CavePopulator extends BlockPopulator {
|
public class CavePopulator extends GenerationPopulator {
|
||||||
@Override
|
|
||||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkGenerator.ChunkData populate(World world, ChunkGenerator.ChunkData chunk, Random random, int chunkX, int chunkZ) {
|
||||||
|
ProfileFuture cave = TerraProfiler.fromWorld(world).measure("CaveTime");
|
||||||
|
for(CarverConfig c : ConfigUtil.getCarvers()) {
|
||||||
|
chunk = c.getCarver().carve(chunkX, chunkZ, world).merge(chunk, true);
|
||||||
|
}
|
||||||
|
if(cave != null) cave.complete();
|
||||||
|
return chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.population;
|
package com.dfsek.terra.population;
|
||||||
|
|
||||||
|
import com.dfsek.terra.MaxMin;
|
||||||
import com.dfsek.terra.biome.BiomeZone;
|
import com.dfsek.terra.biome.BiomeZone;
|
||||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
@ -21,7 +22,7 @@ public class OrePopulator extends GaeaBlockPopulator {
|
|||||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||||
Location l = chunk.getBlock(8, 0, 0).getLocation();
|
Location l = chunk.getBlock(8, 0, 0).getLocation();
|
||||||
Biome b = TerraBiomeGrid.fromWorld(world).getBiome(l.getBlockX(), l.getBlockZ());
|
Biome b = TerraBiomeGrid.fromWorld(world).getBiome(l.getBlockX(), l.getBlockZ());
|
||||||
for(Map.Entry<OreConfig, BiomeConfig.MaxMin> e : ((UserDefinedBiome) b).getConfig().getOres().entrySet()) {
|
for(Map.Entry<OreConfig, MaxMin> e : ((UserDefinedBiome) b).getConfig().getOres().entrySet()) {
|
||||||
int num = e.getValue().get(random);
|
int num = e.getValue().get(random);
|
||||||
for(int i = 0; i < num; i++) {
|
for(int i = 0; i < num; i++) {
|
||||||
int x = random.nextInt(16);
|
int x = random.nextInt(16);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user