mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 23:06:05 +00:00
Add more configurability to caves.
This commit is contained in:
@@ -5,12 +5,14 @@ import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.BiomeConfig;
|
||||
import com.dfsek.terra.config.CarverConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.world.BlockPalette;
|
||||
import org.polydev.gaea.world.carving.Carver;
|
||||
import org.polydev.gaea.world.carving.Worm;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class UserDefinedCarver extends Carver {
|
||||
@@ -21,7 +23,7 @@ public class UserDefinedCarver extends Carver {
|
||||
private final double[] radiusMultiplier;
|
||||
private final MaxMin length;
|
||||
private final MaxMin radius;
|
||||
public UserDefinedCarver(MaxMin height, MaxMin radius, MaxMin length, double[] start, double[] mutate, double[] radiusMultiplier) {
|
||||
public UserDefinedCarver(MaxMin height, MaxMin radius, MaxMin length, double[] start, double[] mutate, double[] radiusMultiplier) {
|
||||
super(height.getMin(), height.getMax());
|
||||
this.radius = radius;
|
||||
this.length = length;
|
||||
|
||||
@@ -207,13 +207,10 @@ public class BiomeConfig extends YamlConfiguration {
|
||||
paths
|
||||
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||
.forEach(path -> {
|
||||
logger.info("Loading biome from " + path.toString());
|
||||
try {
|
||||
BiomeConfig biome = new BiomeConfig(path.toFile());
|
||||
biomes.put(biome.getBiomeID(), biome);
|
||||
logger.info("Friendly name: " + biome.getFriendlyName());
|
||||
logger.info("ID: " + biome.getBiomeID());
|
||||
logger.info("Noise equation: " + biome.get("noise-equation"));
|
||||
logger.info("Loaded Biome with name " + biome.getFriendlyName() + ", ID " + biome.getBiomeID() + " and noise equation " + biome.get("noise-equation") + " from " + path.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||
|
||||
@@ -84,12 +84,10 @@ public class BiomeGridConfig extends YamlConfiguration {
|
||||
paths
|
||||
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||
.forEach(path -> {
|
||||
main.getLogger().info("Loading BiomeGrid from " + path.toString());
|
||||
try {
|
||||
BiomeGridConfig grid = new BiomeGridConfig(path.toFile());
|
||||
biomeGrids.put(grid.getGridID(), grid);
|
||||
main.getLogger().info("Friendly name: " + grid.getFriendlyName());
|
||||
main.getLogger().info("ID: " + grid.getGridID());
|
||||
main.getLogger().info("Loaded BiomeGrid with name " + grid.getFriendlyName() + ", ID " + grid.getGridID() + " from " + path.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.config;
|
||||
import com.dfsek.terra.MaxMin;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -18,36 +19,32 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CarverConfig extends YamlConfiguration {
|
||||
private static final Map<String, CarverConfig> caveConfig = new HashMap<>();
|
||||
private UserDefinedCarver carver;
|
||||
private MaxMin length;
|
||||
private MaxMin height;
|
||||
private String id;
|
||||
private final Set<Material> replaceableInner = new HashSet<>();
|
||||
private final Set<Material> replaceableOuter = new HashSet<>();
|
||||
private boolean replaceIsBlacklistInner;
|
||||
private boolean replaceIsBlacklistOuter;
|
||||
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;
|
||||
}
|
||||
@@ -55,32 +52,45 @@ public class CarverConfig extends YamlConfiguration {
|
||||
@Override
|
||||
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
|
||||
super.load(file);
|
||||
BlockPalette inner;
|
||||
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 = PaletteConfig.fromID(getString("palette.interior")).getPalette();
|
||||
}
|
||||
|
||||
BlockPalette walls;
|
||||
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 = PaletteConfig.fromID(getString("palette.walls")).getPalette();
|
||||
if(contains("palette.inner.replace")) {
|
||||
for(String s : getStringList("palette.inner.replace")) {
|
||||
replaceableInner.add(Bukkit.createBlockData(s).getMaterial());
|
||||
}
|
||||
}
|
||||
if(contains("palette.outer.replace")) {
|
||||
for(String s : getStringList("palette.outer.replace")) {
|
||||
replaceableOuter.add(Bukkit.createBlockData(s).getMaterial());
|
||||
}
|
||||
}
|
||||
replaceIsBlacklistInner = getBoolean("palette.inner.replace-blacklist", false);
|
||||
replaceIsBlacklistOuter = getBoolean("palette.outer.replace-blacklist", false);
|
||||
|
||||
|
||||
double[] start = new double[] {getDouble("start.x"), getDouble("start.y"), getDouble("start.z")};
|
||||
double[] mutate = new double[] {getDouble("mutate.x"), getDouble("mutate.y"), getDouble("mutate.z"), getDouble("mutate.radius")};
|
||||
double[] radiusMultiplier = new double[] {getDouble("start.radius.multiply.x"), getDouble("start.radius.multiply.y"), getDouble("start.radius.multiply.z")};
|
||||
length = new MaxMin(getInt("length.min"), getInt("length.max"));
|
||||
MaxMin length = new MaxMin(getInt("length.min"), getInt("length.max"));
|
||||
MaxMin radius = new MaxMin(getInt("start.radius.min"), getInt("start.radius.max"));
|
||||
height = new MaxMin(getInt("start.height.min"), getInt("start.height.max"));
|
||||
double radMutate = getDouble("mutate.radius");
|
||||
MaxMin height = new MaxMin(getInt("start.height.min"), getInt("start.height.max"));
|
||||
id = getString("id");
|
||||
carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier);
|
||||
}
|
||||
|
||||
public boolean isReplaceableInner(Material m) {
|
||||
if(replaceIsBlacklistInner) {
|
||||
return !replaceableInner.contains(m);
|
||||
}
|
||||
return replaceableInner.contains(m);
|
||||
}
|
||||
|
||||
public boolean isReplaceableOuter(Material m) {
|
||||
if(replaceIsBlacklistOuter) {
|
||||
return !replaceableOuter.contains(m);
|
||||
}
|
||||
return replaceableOuter.contains(m);
|
||||
}
|
||||
|
||||
protected static void loadCaves(JavaPlugin main) {
|
||||
// TODO: Merge all load methods
|
||||
Logger logger = main.getLogger();
|
||||
@@ -91,11 +101,10 @@ public class CarverConfig extends YamlConfiguration {
|
||||
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());
|
||||
logger.info("Loaded Carver with ID " + cave.getID() + " from " + path.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||
|
||||
@@ -99,11 +99,9 @@ public class FaunaConfig extends YamlConfiguration implements Fauna {
|
||||
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||
.forEach(path -> {
|
||||
try {
|
||||
logger.info("Loading fauna from " + path.toString());
|
||||
FaunaConfig fauna = new FaunaConfig(path.toFile());
|
||||
faunaConfig.put(fauna.getID(), fauna);
|
||||
logger.info("Friendly name: " + fauna.getFriendlyName());
|
||||
logger.info("ID: " + fauna.getID());
|
||||
logger.info("Loaded Fauna with name " + fauna.getFriendlyName() + ", ID " + fauna.getID() + " from " + path.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||
|
||||
@@ -57,7 +57,6 @@ public class OreConfig extends YamlConfiguration {
|
||||
|
||||
try {
|
||||
replaceable = ConfigUtil.getElements(getStringList("replace"), Material.class);
|
||||
Bukkit.getLogger().info("[Terra] Added " + replaceable.size() + " items to replaceable list.");
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new InvalidConfigurationException("Invalid material ID in replace list: " + e.getMessage());
|
||||
}
|
||||
@@ -106,11 +105,10 @@ public class OreConfig extends YamlConfiguration {
|
||||
paths
|
||||
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||
.forEach(path -> {
|
||||
logger.info("Loading ore from " + path.toString());
|
||||
try {
|
||||
OreConfig ore = new OreConfig(path.toFile());
|
||||
ores.put(ore.getID(), ore);
|
||||
logger.info("ID: " + ore.getID());
|
||||
logger.info("Loaded ore with ID " + ore.getID() + " from " + path.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||
|
||||
@@ -65,9 +65,7 @@ public class PaletteConfig extends YamlConfiguration {
|
||||
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());
|
||||
@@ -86,12 +84,10 @@ public class PaletteConfig extends YamlConfiguration {
|
||||
paths
|
||||
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||
.forEach(path -> {
|
||||
logger.info("Loading BlockPalette from " + path.toString());
|
||||
try {
|
||||
PaletteConfig grid = new PaletteConfig(path.toFile());
|
||||
palettes.put(grid.getPaletteID(), grid);
|
||||
logger.info("Friendly name: " + grid.getFriendlyName());
|
||||
logger.info("ID: " + grid.getPaletteID());
|
||||
PaletteConfig palette = new PaletteConfig(path.toFile());
|
||||
palettes.put(palette.getPaletteID(), palette);
|
||||
logger.info("Loaded BlockPalette with name: " + palette.getFriendlyName() + ", ID " + palette.getPaletteID() + "with " + palette.getPalette().getSize() + " layers from " + path.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(InvalidConfigurationException | IllegalArgumentException e) {
|
||||
|
||||
@@ -3,24 +3,18 @@ package com.dfsek.terra.config;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.UserDefinedGrid;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.commons.io.FileUtils;
|
||||
import org.polydev.gaea.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class WorldConfig {
|
||||
private static JavaPlugin main;
|
||||
|
||||
@@ -2,22 +2,37 @@ package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.config.CarverConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.generation.GenerationPopulator;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
import org.polydev.gaea.world.carving.CarvingData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class CavePopulator extends GenerationPopulator {
|
||||
|
||||
@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 : CarverConfig.getCarvers()) {
|
||||
chunk = c.getCarver().carve(chunkX, chunkZ, world).merge(chunk, true);
|
||||
ProfileFuture cave = TerraProfiler.fromWorld(world).measure("CaveTime");
|
||||
Map<Vector, CarvingData.CarvingType> blocks = c.getCarver().carve(chunkX, chunkZ, world).getCarvedBlocks();
|
||||
for(Map.Entry<Vector, CarvingData.CarvingType> e : blocks.entrySet()) {
|
||||
Vector v = e.getKey();
|
||||
Material m = chunk.getType(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
if(e.getValue().equals(CarvingData.CarvingType.CENTER) && c.isReplaceableInner(m)) {
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), Material.AIR);
|
||||
} else if(c.isReplaceableOuter(m)){
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), Material.ANDESITE);
|
||||
}
|
||||
|
||||
}
|
||||
if(cave != null) cave.complete();
|
||||
}
|
||||
if(cave != null) cave.complete();
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user