Merge remote-tracking branch 'origin/master'

This commit is contained in:
Bud Gidiere 2020-11-21 08:34:44 -06:00
commit 8876dc3b21
No known key found for this signature in database
GPG Key ID: CD18F99E348902F7
20 changed files with 77 additions and 92 deletions

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.async;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.base.ConfigUtil;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@ -27,11 +28,11 @@ public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
*/
@Override
public boolean isValid(int x, int z, Biome target) {
return getGrid().getBiome(x, z, GenerationPhase.POST_GEN).equals(target);
return getGrid().getBiome(x * ConfigUtil.biomeSearchRes, z * ConfigUtil.biomeSearchRes, GenerationPhase.POST_GEN).equals(target);
}
@Override
public Vector finalizeVector(Vector orig) {
return orig;
return orig.multiply(ConfigUtil.biomeSearchRes);
}
}

View File

@ -1,6 +1,5 @@
package com.dfsek.terra.async;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
@ -34,7 +33,7 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<StructureConfig> {
public boolean isValid(int x, int z, StructureConfig target) {
World world = getWorld();
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
if(!TerraWorld.getWorld(world).getConfig().getBiome((UserDefinedBiome) getGrid().getBiome(spawn)).getStructures().contains(target))
if(!((UserDefinedBiome) getGrid().getBiome(spawn)).getConfig().getStructures().contains(target))
return false;
Random r2 = new FastRandom(spawn.hashCode());
Structure struc = target.getStructure(r2);

View File

@ -60,7 +60,7 @@ public class UserDefinedCarver extends Carver {
@Override
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
ConfigPack c = TerraWorld.getWorld(w).getConfig();
return new FastRandom(random.nextLong() + hash).nextInt(100) < c.getBiome((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getCarverChance(this);
return new FastRandom(random.nextLong() + hash).nextInt(100) < ((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getConfig().getCarverChance(this);
}
private class UserDefinedWorm extends Worm {

View File

@ -25,7 +25,7 @@ public class BiomeCommand extends WorldCommand {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
LangUtil.send("command.biome.in", sender, TerraWorld.getWorld(w).getConfig().getBiome(biome).getID());
LangUtil.send("command.biome.in", sender, biome.getID());
return true;
}

View File

@ -40,7 +40,7 @@ public class BiomeInfoCommand extends WorldCommand {
sender.sendMessage("Erodible: " + b.isErodible());
BiomeConfig bio = cfg.getBiome(b);
BiomeConfig bio = b.getConfig();
List<StructureConfig> structureConfigs = bio.getStructures();
if(structureConfigs.size() == 0) sender.sendMessage("No Structures");

View File

@ -2,7 +2,6 @@ package com.dfsek.terra.config.base;
import com.dfsek.terra.Debug;
import com.dfsek.terra.Terra;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.exception.ConfigException;
@ -274,13 +273,6 @@ public class ConfigPack extends YamlConfiguration {
return dataFolder;
}
public BiomeConfig getBiome(UserDefinedBiome b) {
for(BiomeConfig biome : biomes.values()) {
if(biome.getBiome().equals(b)) return biome;
}
throw new IllegalArgumentException("No BiomeConfig for provided biome.");
}
public BiomeConfig getBiome(String id) {
return biomes.get(id);
}

View File

@ -18,7 +18,6 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@ -29,7 +28,7 @@ public final class ConfigUtil {
public static boolean debug;
public static long dataSave; // Period of population data saving, in ticks.
public static boolean masterDisableCaves;
public static int cacheSize;
public static int biomeSearchRes;
public static void loadConfig(JavaPlugin main) {
main.saveDefaultConfig();
@ -38,9 +37,9 @@ public final class ConfigUtil {
LangUtil.load(config.getString("language", "en_us"), main);
debug = config.getBoolean("debug", false);
cacheSize = config.getInt("cache-size", 3);
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L;
masterDisableCaves = config.getBoolean("master-disable.caves", false);
biomeSearchRes = config.getInt("biome-search-resolution", 4);
if(config.getBoolean("dump-default", true)) {
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {

View File

@ -31,8 +31,6 @@ public class OreConfig extends TerraConfig {
private final double deformFrequency;
private final String id;
private final boolean update;
private final boolean crossChunks;
private final int chunkEdgeOffset;
Set<Material> replaceable;
public OreConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
@ -47,11 +45,6 @@ public class OreConfig extends TerraConfig {
deform = getDouble("deform", 0.75);
deformFrequency = getDouble("deform-frequency", 0.1);
update = getBoolean("update", false);
crossChunks = getBoolean("cross-chunks", true);
chunkEdgeOffset = getInt("edge-offset", 1);
if(chunkEdgeOffset > 7 || chunkEdgeOffset < 0)
throw new ConfigException("Edge offset is too high/low!", getID());
replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID());
@ -121,12 +114,4 @@ public class OreConfig extends TerraConfig {
public String toString() {
return "Ore with ID " + getID();
}
public boolean crossChunks() {
return crossChunks;
}
public int getChunkEdgeOffset() {
return chunkEdgeOffset;
}
}

View File

@ -13,11 +13,13 @@ import java.util.Map;
public class BiomeSnowConfig extends TerraConfigSection {
private final int[] snowHeights;
private boolean doSnow = false;
private final boolean physics;
public BiomeSnowConfig(TerraConfig parent) throws InvalidConfigurationException {
super(parent);
snowHeights = new int[256];
List<Map<?, ?>> maps = parent.getMapList("snow");
this.physics = getParent().getBoolean("snow-physics", false);
if(maps.size() == 0) return;
try {
for(Map<?, ?> e : maps) {
@ -41,4 +43,8 @@ public class BiomeSnowConfig extends TerraConfigSection {
public boolean doSnow() {
return doSnow;
}
public boolean doPhysics() {
return physics;
}
}

View File

@ -41,7 +41,7 @@ public class DebugFrame extends JFrame implements ActionListener {
xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
}
String str = TerraWorld.getWorld(p.getWorld()).getConfig().getBiome((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
String str = ((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
g.setColor(new Color(255, 255, 255, 128));
g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
g.setColor(Color.BLACK);

View File

@ -57,7 +57,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
super(ChunkInterpolator.InterpolationType.TRILINEAR);
this.configPack = c;
popMan.attach(new FloraPopulator());
popMan.attach(new OrePopulator());
popMan.attach(new SnowPopulator());
}
@ -226,7 +225,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
return Arrays.asList(new CavePopulator(), new StructurePopulator(), popMan);
return Arrays.asList(new CavePopulator(), new StructurePopulator(), new OrePopulator(), popMan);
}
@Override

View File

@ -1,6 +1,5 @@
package com.dfsek.terra.math;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.generation.config.NoiseBuilder;
import org.polydev.gaea.math.FastNoiseLite;
import parsii.eval.Expression;
@ -8,7 +7,6 @@ import parsii.eval.Expression;
import java.util.List;
public class NoiseFunction2 implements NoiseFunction {
private final Cache cache = new Cache();
private final FastNoiseLite gen;
public NoiseFunction2(long seed, NoiseBuilder builder) {
@ -22,32 +20,11 @@ public class NoiseFunction2 implements NoiseFunction {
@Override
public double eval(List<Expression> list) {
return cache.get(list.get(0).evaluate(), list.get(1).evaluate());
return gen.getNoise(list.get(0).evaluate(), list.get(1).evaluate());
}
@Override
public boolean isNaturalFunction() {
return true;
}
private final class Cache {
private final double[] cacheX = new double[ConfigUtil.cacheSize];
private final double[] cacheZ = new double[ConfigUtil.cacheSize];
private final double[] cacheValues = new double[ConfigUtil.cacheSize];
public double get(double x, double z) {
for(int i = 0; i < cacheX.length; i++) {
if(cacheX[i] == x && cacheZ[i] == z) return cacheValues[i];
}
cacheX[0] = x;
cacheZ[0] = z;
cacheValues[0] = gen.getNoise(x, z);
for(int i = 0; i < cacheX.length - 1; i++) {
cacheX[i + 1] = cacheX[i];
cacheZ[i + 1] = cacheZ[i];
cacheValues[i + 1] = cacheValues[i];
}
return cacheValues[0];
}
}
}

View File

@ -5,7 +5,6 @@ import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
import com.dfsek.terra.event.TreeGenerateEvent;
@ -34,7 +33,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
Tree tree = biome.getDecorator().getTrees().get(random);
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
Range range = biome.getConfig().getTreeRange(tree);
if(!range.isInRange(block.getY())) continue;
try {
Location l = block.getLocation();
@ -70,7 +69,6 @@ public class FloraPopulator extends GaeaBlockPopulator {
int originX = chunk.getX() << 4;
int originZ = chunk.getZ() << 4;
TerraBiomeGrid grid = tw.getGrid();
ConfigPack config = tw.getConfig();
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
@ -84,7 +82,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
}
if(biome.getDecorator().getFloraChance() <= 0) continue;
try {
BiomeConfig c = config.getBiome(biome);
BiomeConfig c = biome.getConfig();
BiomeFloraConfig f = c.getFlora();
for(int i = 0; i < f.getFloraAttempts(); i++) {
Flora item;

View File

@ -3,49 +3,52 @@ package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.genconfig.OreConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeOreConfig;
import com.dfsek.terra.event.OreVeinGenerateEvent;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range;
import org.polydev.gaea.population.GaeaBlockPopulator;
import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.util.FastRandom;
import java.util.Map;
import java.util.Random;
public class OrePopulator extends GaeaBlockPopulator {
public class OrePopulator extends BlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
TerraWorld tw = TerraWorld.getWorld(world);
if(!tw.isSafe()) return;
ConfigPack config = tw.getConfig();
Biome b = TerraWorld.getWorld(world).getGrid().getBiome((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8, GenerationPhase.POPULATE);
BiomeOreConfig ores = config.getBiome((UserDefinedBiome) b).getOres();
for(int cx = -1; cx <= 1; cx++) {
for(int cz = -1; cz <= 1; cz++) {
FastRandom r = new FastRandom(MathUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed()));
Biome b = TerraWorld.getWorld(world).getGrid().getBiome(((chunk.getX() + cx) << 4) + 8, ((chunk.getZ() + cz) << 4) + 8, GenerationPhase.POPULATE);
BiomeOreConfig ores = ((UserDefinedBiome) b).getConfig().getOres();
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
int num = e.getValue().get(random);
int num = e.getValue().get(r);
OreConfig ore = e.getKey();
int edgeOffset = ore.getChunkEdgeOffset();
for(int i = 0; i < num; i++) {
int x = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
int z = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
int y = ores.getOreHeights().get(ore).get(random);
int x = r.nextInt(16) + cx * 16;
int z = r.nextInt(16) + cz * 16;
int y = ores.getOreHeights().get(ore).get(r);
Vector v = new Vector(x, y, z);
OreVeinGenerateEvent event = new OreVeinGenerateEvent(tw, v.toLocation(world), ore);
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) {
if(ore.crossChunks()) ore.doVein(v, chunk, random);
else ore.doVeinSingle(new Vector(x, y, z), chunk, random);
ore.doVeinSingle(new Vector(x, y, z), chunk, r);
}
}
}
}
}

View File

@ -55,7 +55,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
TerraBiomeGrid g = w.getGrid();
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
BiomeConfig biome = w.getConfig().getBiome((UserDefinedBiome) g.getBiome(origX + x, origZ + z, GenerationPhase.PALETTE_APPLY));
BiomeConfig biome = ((UserDefinedBiome) g.getBiome(origX + x, origZ + z, GenerationPhase.PALETTE_APPLY)).getConfig();
if(!biome.getSnow().doSnow()) continue;
int y;
Block b = null;
@ -66,7 +66,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
if(random.nextInt(100) >= biome.getSnow().getSnowChance(y))
continue;
if(blacklistSpawn.contains(b.getType()) || b.isPassable()) continue;
chunk.getBlock(x, ++y, z).setBlockData(DataUtil.SNOW);
chunk.getBlock(x, ++y, z).setBlockData(DataUtil.SNOW, biome.getSnow().doPhysics());
}
}
}

View File

@ -41,7 +41,7 @@ public class StructurePopulator extends BlockPopulator {
structure:
for(StructureConfig conf : config.getAllStructures()) {
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
if(!config.getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(conf)) continue;
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue;
Random r2 = new FastRandom(spawn.hashCode());
Structure struc = conf.getStructure(r2);
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);

View File

@ -2,7 +2,6 @@ package com.dfsek.terra.structure.spawn;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.generation.config.WorldGenerator;
import org.bukkit.World;
@ -16,9 +15,8 @@ public class AirSpawn extends Requirement {
@Override
public boolean matches(int x, int y, int z) {
TerraWorld tw = TerraWorld.getWorld(getWorld());
ConfigPack wc = tw.getConfig();
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
BiomeConfig c = wc.getBiome(b);
BiomeConfig c = b.getConfig();
if(y <= c.getOcean().getSeaLevel()) return false;
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;

View File

@ -16,7 +16,7 @@ public class OceanSpawn extends Requirement {
public boolean matches(int x, int y, int z) {
TerraWorld tw = TerraWorld.getWorld(getWorld());
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
BiomeConfig c = tw.getConfig().getBiome(b);
BiomeConfig c = b.getConfig();
if(y > c.getOcean().getSeaLevel()) return false;
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;

View File

@ -3,6 +3,6 @@ data-save: PT6M
language: "en_us"
fail-type: SHUTDOWN
dump-default: true
cache-size: 8
biome-search-resolution: 4
master-disable:
caves: false

View File

@ -0,0 +1,28 @@
import com.dfsek.terra.generation.config.NoiseBuilder;
import com.dfsek.terra.math.NoiseFunction2;
import org.junit.jupiter.api.Test;
import parsii.eval.Expression;
import java.util.Arrays;
public class NoiseTest {
@Test
public void noise() {
NoiseFunction2 noiseFunction = new NoiseFunction2(12345, new NoiseBuilder());
for(int i = 0; i < 10; i++) {
long l = System.nanoTime();
for(int j = 0; j < 1000000; j++) {
noiseFunction.eval(Arrays.asList(get(j), get(i)));
noiseFunction.eval(Arrays.asList(get(j), get(i)));
noiseFunction.eval(Arrays.asList(get(j), get(i)));
}
double n = System.nanoTime() - l;
System.out.println(n / 1000000 + "ms");
}
}
private Expression get(double val) {
return () -> val;
}
}