mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 02:22:32 +00:00
Properly implement configurable caves
This commit is contained in:
parent
e2823b808d
commit
886999c97a
2
pom.xml
2
pom.xml
@ -83,7 +83,7 @@
|
||||
<dependency>
|
||||
<groupId>org.polydev</groupId>
|
||||
<artifactId>gaea</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<version>1.6.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -1,31 +1,11 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.BiomeConfig;
|
||||
import com.dfsek.terra.config.CarverConfig;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeTerrain;
|
||||
import org.polydev.gaea.biome.Decorator;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.parsii.eval.Parser;
|
||||
import org.polydev.gaea.math.parsii.eval.Scope;
|
||||
import org.polydev.gaea.math.parsii.tokenizer.ParseException;
|
||||
import org.polydev.gaea.structures.features.Feature;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.world.BlockPalette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class UserDefinedBiome implements Biome {
|
||||
private final UserDefinedGenerator gen;
|
||||
|
@ -1,58 +1,66 @@
|
||||
package com.dfsek.terra;
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.MaxMin;
|
||||
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.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.Random;
|
||||
|
||||
public class UserDefinedCarver extends Carver {
|
||||
private final CarverConfig config;
|
||||
public UserDefinedCarver(CarverConfig config) {
|
||||
super(config.getHeight().getMin(), config.getHeight().getMax());
|
||||
this.config = config;
|
||||
private BlockPalette inner;
|
||||
private BlockPalette walls;
|
||||
private final double[] start; // 0, 1, 2 = x, y, z.
|
||||
private final double[] mutate; // 0, 1, 2 = x, y, z. 3 = radius.
|
||||
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) {
|
||||
super(height.getMin(), height.getMax());
|
||||
this.radius = radius;
|
||||
this.length = length;
|
||||
this.start = start;
|
||||
this.mutate = mutate;
|
||||
this.radiusMultiplier = radiusMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector vector) {
|
||||
Random r = new Random(l);
|
||||
return new UserDefinedWorm(config.getLength().get(r), r, vector, 6);
|
||||
}
|
||||
|
||||
public CarverConfig getConfig() {
|
||||
return config;
|
||||
return new UserDefinedWorm(length.get(r), r, vector, radius.getMax());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(chunkX << 4, chunkZ << 4);
|
||||
return random.nextInt(100) < BiomeConfig.fromBiome(b).getCarverChance(config);
|
||||
return random.nextInt(100) < BiomeConfig.fromBiome(b).getCarverChance(this);
|
||||
}
|
||||
|
||||
private static class UserDefinedWorm extends Worm {
|
||||
private class UserDefinedWorm extends Worm {
|
||||
private final Vector direction;
|
||||
private final int maxRad;
|
||||
private double runningRadius;
|
||||
public UserDefinedWorm(int length, Random r, Vector origin, int maxRad) {
|
||||
super(length, r, origin);
|
||||
runningRadius = (r.nextDouble()/2+0.5)*4;
|
||||
runningRadius = radius.get(r);
|
||||
this.maxRad = maxRad;
|
||||
direction = new Vector(r.nextDouble()-0.5D, (r.nextDouble()-0.5D)/4, r.nextDouble()-0.5D).normalize();
|
||||
direction = new Vector((r.nextDouble()-0.5D)*start[0], (r.nextDouble()-0.5D)*start[1], (r.nextDouble()-0.5D)*start[2]).normalize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void step() {
|
||||
setRadius(new int[] {(int) runningRadius, (int) runningRadius, (int) runningRadius});
|
||||
runningRadius += (getRandom().nextDouble()-0.5)/8;
|
||||
setRadius(new int[] {(int) (runningRadius*radiusMultiplier[0]), (int) (runningRadius*radiusMultiplier[1]), (int) (runningRadius*radiusMultiplier[2])});
|
||||
runningRadius += (getRandom().nextDouble()-0.5)*mutate[3];
|
||||
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));
|
||||
direction.rotateAroundX(Math.toRadians(getRandom().nextDouble()*mutate[0]));
|
||||
direction.rotateAroundY(Math.toRadians(getRandom().nextDouble()*mutate[1]));
|
||||
direction.rotateAroundZ(Math.toRadians(getRandom().nextDouble()*mutate[2]));
|
||||
getRunning().add(direction);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import com.dfsek.terra.TerraTree;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.UserDefinedDecorator;
|
||||
import com.dfsek.terra.biome.UserDefinedGenerator;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -227,7 +228,7 @@ public class BiomeConfig extends YamlConfiguration {
|
||||
main.getLogger().info("Loaded " + biomes.size() + " biomes.");
|
||||
}
|
||||
|
||||
public int getCarverChance(CarverConfig c) {
|
||||
return carvers.getOrDefault(c, 0);
|
||||
public int getCarverChance(UserDefinedCarver c) {
|
||||
return carvers.getOrDefault(CarverConfig.fromDefinedCarver(c), 0);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.config;
|
||||
|
||||
import com.dfsek.terra.MaxMin;
|
||||
import com.dfsek.terra.UserDefinedCarver;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -27,13 +27,7 @@ import java.util.stream.Stream;
|
||||
public class CarverConfig extends YamlConfiguration {
|
||||
private static final Map<String, CarverConfig> caveConfig = new HashMap<>();
|
||||
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 {
|
||||
@ -61,12 +55,14 @@ 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 {
|
||||
@ -74,14 +70,15 @@ public class CarverConfig extends YamlConfiguration {
|
||||
}
|
||||
|
||||
|
||||
start = new double[] {getDouble("start.x"), getDouble("start.y"), getDouble("start.y")};
|
||||
mutate = new double[] {getDouble("mutate.x"), getDouble("mutate.y"), getDouble("mutate.z")};
|
||||
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"));
|
||||
radius = new MaxMin(getInt("start.radius.min"), getInt("start.radius.max"));
|
||||
MaxMin 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");
|
||||
double radMutate = getDouble("mutate.radius");
|
||||
id = getString("id");
|
||||
carver = new UserDefinedCarver(this);
|
||||
carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier);
|
||||
}
|
||||
|
||||
protected static void loadCaves(JavaPlugin main) {
|
||||
@ -118,4 +115,11 @@ public class CarverConfig extends YamlConfiguration {
|
||||
public static CarverConfig fromID(String id) {
|
||||
return caveConfig.get(id);
|
||||
}
|
||||
|
||||
public static CarverConfig fromDefinedCarver(UserDefinedCarver c) {
|
||||
for(CarverConfig co : caveConfig.values()) {
|
||||
if(co.getCarver().equals(c)) return co;
|
||||
}
|
||||
throw new IllegalArgumentException("Unable to find carver!");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user