Update to latest Gaea, allow configuration of terrain octaves/frequency

This commit is contained in:
dfsek
2020-10-17 16:49:43 -07:00
parent 2c49160731
commit 2741a761a0
32 changed files with 136 additions and 111 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -111,9 +111,9 @@
<dependency> <dependency>
<groupId>org.polydev</groupId> <groupId>org.polydev</groupId>
<artifactId>gaea</artifactId> <artifactId>gaea</artifactId>
<version>1.11.6</version> <version>1.12.0</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${basedir}/lib/Gaea-1.11.6.jar</systemPath> <systemPath>${basedir}/lib/Gaea-1.12.0.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
+8 -4
View File
@@ -7,6 +7,7 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator; import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -18,12 +19,13 @@ import org.polydev.gaea.lang.Language;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
public class Terra extends GaeaPlugin { public class Terra extends GaeaPlugin {
private static Terra instance; private static Terra instance;
private static final Set<String> loadedWorlds = new HashSet<>(); private Map<String, TerraChunkGenerator> generatorMap = new HashMap<>();
public static Terra getInstance() { public static Terra getInstance() {
return instance; return instance;
@@ -54,9 +56,11 @@ public class Terra extends GaeaPlugin {
@Override @Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) { public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
if(!loadedWorlds.contains(worldName)) TerraWorld.loadWorld(new WorldConfig(worldName, id, this)); return generatorMap.computeIfAbsent(worldName, name -> {
loadedWorlds.add(worldName); // Ensure world config is only loaded once for world. WorldConfig c = new WorldConfig(worldName, id, this);
return new TerraChunkGenerator(); TerraWorld.loadWorld(c);
return new TerraChunkGenerator(c.getConfig());
});
} }
@Override @Override
@@ -6,7 +6,7 @@ import org.bukkit.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.polydev.gaea.biome.BiomeGrid; import org.polydev.gaea.biome.BiomeGrid;
import org.polydev.gaea.biome.NormalizationUtil; import org.polydev.gaea.biome.NormalizationUtil;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import java.util.Objects; import java.util.Objects;
@@ -15,15 +15,16 @@ import java.util.Objects;
*/ */
public class BiomeZone { public class BiomeZone {
private final BiomeGrid[] grids; private final BiomeGrid[] grids;
private final FastNoise noise; private final FastNoiseLite noise;
@Nullable @Nullable
private final ImageLoader imageLoader; private final ImageLoader imageLoader;
private final boolean useImage; private final boolean useImage;
private final ImageLoader.Channel channel; private final ImageLoader.Channel channel;
public BiomeZone(World w, WorldConfig wc, BiomeGrid[] grids) { public BiomeZone(World w, WorldConfig wc, BiomeGrid[] grids) {
this.noise = new FastNoise((int) w.getSeed()+2); this.noise = new FastNoiseLite((int) w.getSeed()+2);
this.noise.setNoiseType(FastNoise.NoiseType.SimplexFractal); this.noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
this.noise.setFractalType(FastNoiseLite.FractalType.FBm);
this.noise.setFractalOctaves(4); this.noise.setFractalOctaves(4);
this.noise.setFrequency(wc.getConfig().zoneFreq); this.noise.setFrequency(wc.getConfig().zoneFreq);
this.grids = grids; this.grids = grids;
@@ -39,7 +40,7 @@ public class BiomeZone {
* @return BiomeGrid at coordinates. * @return BiomeGrid at coordinates.
*/ */
protected BiomeGrid getGrid(int x, int z) { protected BiomeGrid getGrid(int x, int z) {
return grids[NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length)]; return grids[NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length, 4)];
} }
/** /**
@@ -57,7 +58,7 @@ public class BiomeZone {
* @return Normalized noise at coordinates * @return Normalized noise at coordinates
*/ */
public int getNoise(int x, int z) { public int getNoise(int x, int z) {
return NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length); return NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length, 4);
} }
/** /**
@@ -1,14 +1,14 @@
package com.dfsek.terra.biome; package com.dfsek.terra.biome;
import com.dfsek.terra.procgen.math.Vector2; import com.dfsek.terra.procgen.math.Vector2;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
/** /**
* Offset a coordinate pair by an amount. * Offset a coordinate pair by an amount.
*/ */
public class CoordinatePerturb { public class CoordinatePerturb {
private final FastNoise perturbX; private final FastNoiseLite perturbX;
private final FastNoise perturbZ; private final FastNoiseLite perturbZ;
private final int amplitude; private final int amplitude;
/** /**
@@ -18,11 +18,11 @@ public class CoordinatePerturb {
* @param seed Noise seed * @param seed Noise seed
*/ */
public CoordinatePerturb(float frequency, int amplitude, long seed) { public CoordinatePerturb(float frequency, int amplitude, long seed) {
perturbX = new FastNoise((int) seed); perturbX = new FastNoiseLite((int) seed);
perturbX.setNoiseType(FastNoise.NoiseType.Simplex); perturbX.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
perturbX.setFrequency(frequency); perturbX.setFrequency(frequency);
perturbZ = new FastNoise((int) seed+1); perturbZ = new FastNoiseLite((int) seed+1);
perturbZ.setNoiseType(FastNoise.NoiseType.Simplex); perturbZ.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
perturbZ.setFrequency(frequency); perturbZ.setFrequency(frequency);
this.amplitude = amplitude; this.amplitude = amplitude;
} }
@@ -1,16 +1,17 @@
package com.dfsek.terra.biome; package com.dfsek.terra.biome;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
/** /**
* Class to hold noise function to determine erosion. * Class to hold noise function to determine erosion.
*/ */
public class ErosionNoise { public class ErosionNoise {
private final double thresh; private final double thresh;
private final FastNoise noise; private final FastNoiseLite noise;
public ErosionNoise(float freq1, double thresh, int octaves, long seed) { public ErosionNoise(float freq1, double thresh, int octaves, long seed) {
FastNoise main = new FastNoise((int) (seed+1)); FastNoiseLite main = new FastNoiseLite((int) (seed+1));
main.setNoiseType(FastNoise.NoiseType.SimplexFractal); main.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
main.setFractalType(FastNoiseLite.FractalType.FBm);
main.setFractalOctaves(octaves); main.setFractalOctaves(octaves);
main.setFrequency(freq1); main.setFrequency(freq1);
this.thresh = thresh; this.thresh = thresh;
@@ -29,7 +29,7 @@ public class UserDefinedGrid extends BiomeGrid {
if(fromImage) { if(fromImage) {
double xi = imageLoader.getNoiseVal(x, z, channelX); double xi = imageLoader.getNoiseVal(x, z, channelX);
double zi = imageLoader.getNoiseVal(x, z, channelZ); double zi = imageLoader.getNoiseVal(x, z, channelZ);
return super.getGrid()[NormalizationUtil.normalize(xi, getSizeX())][NormalizationUtil.normalize(zi, getSizeZ())]; return super.getGrid()[NormalizationUtil.normalize(xi, getSizeX(), 4)][NormalizationUtil.normalize(zi, getSizeZ(), 4)];
} }
return super.getBiome(x, z, phase); return super.getBiome(x, z, phase);
} }
@@ -7,7 +7,7 @@ import com.dfsek.terra.procgen.voxel.VoxelGeometry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.math.MathUtil; import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.world.carving.CarvingData; import org.polydev.gaea.world.carving.CarvingData;
@@ -26,9 +26,9 @@ public class Cavern {
Vector org = node.getNodeLocation((chunkX << 4)+8, (chunkZ << 4)+8).clone().setY(chunk.nextInt(128)); Vector org = node.getNodeLocation((chunkX << 4)+8, (chunkZ << 4)+8).clone().setY(chunk.nextInt(128));
VoxelGeometry carve = VoxelGeometry.getBlank(); VoxelGeometry carve = VoxelGeometry.getBlank();
FastNoise smpl = new FastNoise((int) seedC); FastNoiseLite smpl = new FastNoiseLite((int) seedC);
smpl.setFrequency(0.01f); smpl.setFrequency(0.01f);
smpl.setNoiseType(FastNoise.NoiseType.Simplex); smpl.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
Bukkit.getLogger().info("Cavern: " + org.toString()); Bukkit.getLogger().info("Cavern: " + org.toString());
carve.merge(new DeformedSphere(org.clone(), chunk.nextInt(4)+3, 0.75, smpl)); carve.merge(new DeformedSphere(org.clone(), chunk.nextInt(4)+3, 0.75, smpl));
@@ -2,7 +2,7 @@ package com.dfsek.terra.carving;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.world.carving.Carver; import org.polydev.gaea.world.carving.Carver;
import org.polydev.gaea.world.carving.CarvingData; import org.polydev.gaea.world.carving.CarvingData;
import org.polydev.gaea.world.carving.Worm; import org.polydev.gaea.world.carving.Worm;
@@ -10,29 +10,31 @@ import org.polydev.gaea.world.carving.Worm;
import java.util.Random; import java.util.Random;
public class SimplexCarver extends Carver { public class SimplexCarver extends Carver {
private final FastNoise noise; private final FastNoiseLite noise;
private final FastNoise height; private final FastNoiseLite height;
private final FastNoise column; private final FastNoiseLite column;
private final FastNoise hasCaves; private final FastNoiseLite hasCaves;
private final double root2inverse = 1D/Math.sqrt(2); private final double root2inverse = 1D/Math.sqrt(2);
public SimplexCarver(int minY, int maxY) { public SimplexCarver(int minY, int maxY) {
super(minY, maxY); super(minY, maxY);
noise = new FastNoise(2403); noise = new FastNoiseLite(2403);
noise.setNoiseType(FastNoise.NoiseType.SimplexFractal); noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
noise.setFractalType(FastNoiseLite.FractalType.FBm);
noise.setFractalOctaves(3); noise.setFractalOctaves(3);
noise.setFrequency(0.02f); noise.setFrequency(0.02f);
height = new FastNoise(2404); height = new FastNoiseLite(2404);
height.setNoiseType(FastNoise.NoiseType.Simplex); height.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
height.setFrequency(0.01f); height.setFrequency(0.01f);
column = new FastNoise(2404); column = new FastNoiseLite(2404);
column.setNoiseType(FastNoise.NoiseType.SimplexFractal); column.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
column.setFractalType(FastNoiseLite.FractalType.FBm);
column.setFractalOctaves(5); column.setFractalOctaves(5);
column.setFrequency(0.05f); column.setFrequency(0.05f);
hasCaves = new FastNoise(2405); hasCaves = new FastNoiseLite(2405);
hasCaves.setNoiseType(FastNoise.NoiseType.Simplex); hasCaves.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
hasCaves.setFrequency(0.005f); hasCaves.setFrequency(0.005f);
} }
@@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.command.PlayerCommand; import org.polydev.gaea.command.PlayerCommand;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -43,8 +43,8 @@ public class DeformedSphereCommand extends PlayerCommand {
LangUtil.send("command.geometry.deform.invalid-frequency", sender, args[2]); LangUtil.send("command.geometry.deform.invalid-frequency", sender, args[2]);
return true; return true;
} }
FastNoise n = new FastNoise((int) sender.getWorld().getSeed()); FastNoiseLite n = new FastNoiseLite((int) sender.getWorld().getSeed());
n.setNoiseType(FastNoise.NoiseType.Simplex); n.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
n.setFrequency(freq); n.setFrequency(freq);
DeformedSphere sphere = new DeformedSphere(sender.getLocation().toVector(), radius, deform, n); DeformedSphere sphere = new DeformedSphere(sender.getLocation().toVector(), radius, deform, n);
for(Vector v : sphere.getGeometry()) { for(Vector v : sphere.getGeometry()) {
@@ -68,6 +68,9 @@ public class ConfigPack extends YamlConfiguration {
public final boolean biomeBlend; public final boolean biomeBlend;
public final float blendFreq; public final float blendFreq;
public final int octaves;
public final float frequency;
public ConfigPack(File file) throws IOException, InvalidConfigurationException { public ConfigPack(File file) throws IOException, InvalidConfigurationException {
long l = System.nanoTime(); long l = System.nanoTime();
load(new File(file, "pack.yml")); load(new File(file, "pack.yml"));
@@ -107,6 +110,9 @@ public class ConfigPack extends YamlConfiguration {
erosionThresh = getDouble("erode.threshold", 0.04); erosionThresh = getDouble("erode.threshold", 0.04);
erosionOctaves = getInt("erosion.octaves", 4); erosionOctaves = getInt("erosion.octaves", 4);
octaves = getInt("noise.octaves", 4);
frequency = (float) getDouble("noise.frequency", 1f/96);
erosionName = getString("erode.grid"); erosionName = getString("erode.grid");
// Load BiomeGrids from BiomeZone // Load BiomeGrids from BiomeZone
@@ -1,7 +1,9 @@
package com.dfsek.terra.config.base; package com.dfsek.terra.config.base;
import com.dfsek.terra.Debug;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.debug.gui.DebugGUI;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -47,6 +49,7 @@ public class WorldConfig {
long start = System.nanoTime(); long start = System.nanoTime();
LangUtil.log("world-config.load", Level.INFO, worldID); LangUtil.log("world-config.load", Level.INFO, worldID);
FileConfiguration config = new YamlConfiguration(); FileConfiguration config = new YamlConfiguration();
Debug.info("Loading config " + configID + " for world " + worldID);
try { // Load/create world config file try { // Load/create world config file
if(configID == null || configID.equals("")) throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID); if(configID == null || configID.equals("")) throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID);
File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml"); File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml");
@@ -12,7 +12,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.population.ChunkCoordinate; import org.polydev.gaea.population.ChunkCoordinate;
import java.io.File; import java.io.File;
@@ -64,8 +64,8 @@ public class OreConfig extends TerraConfig {
return r.nextInt(max-min+1)+min; return r.nextInt(max-min+1)+min;
} }
public void doVein(Vector l, Chunk chunk, Random r) { public void doVein(Vector l, Chunk chunk, Random r) {
FastNoise ore = new FastNoise(r.nextInt()); FastNoiseLite ore = new FastNoiseLite(r.nextInt());
ore.setNoiseType(FastNoise.NoiseType.SimplexFractal); ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
ore.setFrequency((float) deformFrequency); ore.setFrequency((float) deformFrequency);
int rad = randomInRange(r); int rad = randomInRange(r);
Map<ChunkCoordinate, Chunk> chunks = new HashMap<>(); // Cache chunks to prevent re-loading chunks every time one is needed. Map<ChunkCoordinate, Chunk> chunks = new HashMap<>(); // Cache chunks to prevent re-loading chunks every time one is needed.
@@ -77,7 +77,7 @@ public class OreConfig extends TerraConfig {
Vector oreLoc = orig.clone().add(new Vector(x, y, z)); Vector oreLoc = orig.clone().add(new Vector(x, y, z));
Vector source = l.clone().add(new Vector(x, y, z)); Vector source = l.clone().add(new Vector(x, y, z));
if(oreLoc.getBlockY() > 255 || oreLoc.getBlockY() < 0) continue; if(oreLoc.getBlockY() > 255 || oreLoc.getBlockY() < 0) continue;
if(source.distance(l) < (rad + 0.5) * ((ore.getSimplexFractal(x, y, z)+1)*deform)) { if(source.distance(l) < (rad + 0.5) * ((ore.getNoise(x, y, z)+1)*deform)) {
ChunkCoordinate coord = new ChunkCoordinate(Math.floorDiv(oreLoc.getBlockX(), 16), Math.floorDiv(oreLoc.getBlockZ(), 16), chunk.getWorld().getUID()); ChunkCoordinate coord = new ChunkCoordinate(Math.floorDiv(oreLoc.getBlockX(), 16), Math.floorDiv(oreLoc.getBlockZ(), 16), chunk.getWorld().getUID());
Block b = chunks.computeIfAbsent(coord, k -> chunk.getWorld().getChunkAt(oreLoc.toLocation(chunk.getWorld()))) Block b = chunks.computeIfAbsent(coord, k -> chunk.getWorld().getChunkAt(oreLoc.toLocation(chunk.getWorld())))
.getBlock(Math.floorMod(source.getBlockX(), 16), source.getBlockY(), Math.floorMod(source.getBlockZ(), 16)); // Chunk caching conditional computation .getBlock(Math.floorMod(source.getBlockX(), 16), source.getBlockY(), Math.floorMod(source.getBlockZ(), 16)); // Chunk caching conditional computation
@@ -88,8 +88,8 @@ public class OreConfig extends TerraConfig {
} }
} }
public void doVeinSingle(Vector l, Chunk chunk, Random r) { public void doVeinSingle(Vector l, Chunk chunk, Random r) {
FastNoise ore = new FastNoise(r.nextInt()); FastNoiseLite ore = new FastNoiseLite(r.nextInt());
ore.setNoiseType(FastNoise.NoiseType.SimplexFractal); ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
ore.setFrequency((float) deformFrequency); ore.setFrequency((float) deformFrequency);
int rad = randomInRange(r); int rad = randomInRange(r);
for(int x = -rad; x <= rad; x++) { for(int x = -rad; x <= rad; x++) {
@@ -97,7 +97,7 @@ public class OreConfig extends TerraConfig {
for(int z = -rad; z <= rad; z++) { for(int z = -rad; z <= rad; z++) {
Vector oreLoc = l.clone().add(new Vector(x, y, z)); Vector oreLoc = l.clone().add(new Vector(x, y, z));
if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > 255 || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < 0) continue; if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > 255 || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < 0) continue;
if(oreLoc.distance(l) < (rad + 0.5) * ((ore.getSimplexFractal(x, y, z)+1)*deform)) { if(oreLoc.distance(l) < (rad + 0.5) * ((ore.getNoise(x, y, z)+1)*deform)) {
Block b = chunk.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ()); Block b = chunk.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ());
if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0) b.setBlockData(oreData, update); if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0) b.setBlockData(oreData, update);
} }
@@ -7,7 +7,7 @@ import com.dfsek.terra.config.exception.ConfigException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.world.palette.Palette; import org.polydev.gaea.world.palette.Palette;
import org.polydev.gaea.world.palette.RandomPalette; import org.polydev.gaea.world.palette.RandomPalette;
@@ -30,8 +30,8 @@ public class PaletteConfig extends TerraConfig {
Palette<BlockData> pal; Palette<BlockData> pal;
if(getBoolean("simplex", false)) { if(getBoolean("simplex", false)) {
useNoise = true; useNoise = true;
FastNoise pNoise = new FastNoise(getInt("seed", 2403)); FastNoiseLite pNoise = new FastNoiseLite(getInt("seed", 2403));
pNoise.setNoiseType(FastNoise.NoiseType.SimplexFractal); pNoise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
pNoise.setFractalOctaves(4); pNoise.setFractalOctaves(4);
pNoise.setFrequency((float) getDouble("frequency", 0.02)); pNoise.setFrequency((float) getDouble("frequency", 0.02));
pal = new SimplexPalette<>(pNoise); pal = new SimplexPalette<>(pNoise);
@@ -8,7 +8,7 @@ import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException; import com.dfsek.terra.config.exception.NotFoundException;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import org.polydev.gaea.world.Flora; import org.polydev.gaea.world.Flora;
@@ -23,7 +23,7 @@ public class BiomeFloraConfig extends TerraConfigSection {
private int floraAttempts; private int floraAttempts;
private int floraChance; private int floraChance;
private boolean floraSimplex; private boolean floraSimplex;
private FastNoise floraNoise; private FastNoiseLite floraNoise;
public BiomeFloraConfig(TerraConfig parent) throws InvalidConfigurationException { public BiomeFloraConfig(TerraConfig parent) throws InvalidConfigurationException {
super(parent); super(parent);
ConfigurationSection cfg = parent.getConfigurationSection("flora.items"); ConfigurationSection cfg = parent.getConfigurationSection("flora.items");
@@ -34,8 +34,8 @@ public class BiomeFloraConfig extends TerraConfigSection {
float floraFreq = (float) parent.getDouble("flora.simplex.frequency", 0.1); float floraFreq = (float) parent.getDouble("flora.simplex.frequency", 0.1);
int floraSeed = parent.getInt("flora.simplex.seed", 0); int floraSeed = parent.getInt("flora.simplex.seed", 0);
if(floraSimplex) { if(floraSimplex) {
floraNoise = new FastNoise(floraSeed); floraNoise = new FastNoiseLite(floraSeed);
floraNoise.setNoiseType(FastNoise.NoiseType.Simplex); floraNoise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
floraNoise.setFrequency(floraFreq); floraNoise.setFrequency(floraFreq);
} }
@@ -74,7 +74,7 @@ public class BiomeFloraConfig extends TerraConfigSection {
return floraHeights; return floraHeights;
} }
public FastNoise getFloraNoise() { public FastNoiseLite getFloraNoise() {
return floraNoise; return floraNoise;
} }
@@ -9,7 +9,7 @@ import com.dfsek.terra.config.exception.NotFoundException;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import org.polydev.gaea.world.Flora; import org.polydev.gaea.world.Flora;
@@ -30,7 +30,7 @@ import org.polydev.gaea.generation.GaeaChunkGenerator;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.generation.GenerationPopulator; import org.polydev.gaea.generation.GenerationPopulator;
import org.polydev.gaea.math.ChunkInterpolator; import org.polydev.gaea.math.ChunkInterpolator;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.population.PopulationManager; import org.polydev.gaea.population.PopulationManager;
import org.polydev.gaea.world.palette.Palette; import org.polydev.gaea.world.palette.Palette;
@@ -47,19 +47,23 @@ import java.util.logging.Level;
public class TerraChunkGenerator extends GaeaChunkGenerator { public class TerraChunkGenerator extends GaeaChunkGenerator {
private final PopulationManager popMan = new PopulationManager(Terra.getInstance()); private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
private boolean needsLoad = true; private boolean needsLoad = true;
private int octaves;
private float frequency;
private static final Map<World, PopulationManager> popMap = new HashMap<>(); private static final Map<World, PopulationManager> popMap = new HashMap<>();
public TerraChunkGenerator() { public TerraChunkGenerator(ConfigPack c) {
super(ChunkInterpolator.InterpolationType.TRILINEAR); super(ChunkInterpolator.InterpolationType.TRILINEAR);
this.frequency = c.frequency;
this.octaves = c.octaves;
popMan.attach(new FloraPopulator()); popMan.attach(new FloraPopulator());
popMan.attach(new OrePopulator()); popMan.attach(new OrePopulator());
popMan.attach(new SnowPopulator()); popMan.attach(new SnowPopulator());
} }
@Override @Override
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, FastNoise fastNoise) { public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, FastNoiseLite fastNoise) {
if(needsLoad) load(world); // Load population data for world. if(needsLoad) load(world); // Load population data for world.
StructureSpawnRequirement.putNoise(world, fastNoise); // Assign noise to world to be used for structures. StructureSpawnRequirement.putNoise(world, fastNoise); // Assign noise to world to be used for structures.
ChunkData chunk = createChunkData(world); ChunkData chunk = createChunkData(world);
@@ -161,11 +165,11 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override @Override
public int getNoiseOctaves(World world) { public int getNoiseOctaves(World world) {
return 4; return octaves;
} }
@Override @Override
public float getNoiseFrequency(World world) { public float getNoiseFrequency(World world) {
return 1f/96; return frequency;
} }
@Override @Override
@@ -186,7 +190,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override @Override
public boolean shouldGenerateStructures() { public boolean shouldGenerateStructures() {
return true; return false;
} }
@@ -6,7 +6,7 @@ import com.dfsek.terra.util.DataUtil;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.polydev.gaea.biome.Generator; import org.polydev.gaea.biome.Generator;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.world.palette.Palette; import org.polydev.gaea.world.palette.Palette;
import parsii.eval.Expression; import parsii.eval.Expression;
import parsii.eval.Parser; import parsii.eval.Parser;
@@ -49,15 +49,15 @@ public class UserDefinedGenerator extends Generator {
this.noiseExp = p.parse(equation, s); this.noiseExp = p.parse(equation, s);
} }
/** /**
* Gets the 2D noise at a pair of coordinates using the provided FastNoise instance. * Gets the 2D noise at a pair of coordinates using the provided FastNoiseLite instance.
* *
* @param gen - The FastNoise instance to use. * @param gen - The FastNoiseLite instance to use.
* @param x - The x coordinate. * @param x - The x coordinate.
* @param z - The z coordinate. * @param z - The z coordinate.
* @return double - Noise value at the specified coordinates. * @return double - Noise value at the specified coordinates.
*/ */
@Override @Override
public double getNoise(FastNoise gen, World w, int x, int z) { public double getNoise(FastNoiseLite gen, World w, int x, int z) {
synchronized(noiseLock) { synchronized(noiseLock) {
xVar.setValue(x); xVar.setValue(x);
yVar.setValue(0); yVar.setValue(0);
@@ -69,16 +69,16 @@ public class UserDefinedGenerator extends Generator {
} }
/** /**
* Gets the 3D noise at a pair of coordinates using the provided FastNoise instance. * Gets the 3D noise at a pair of coordinates using the provided FastNoiseLite instance.
* *
* @param gen - The FastNoise instance to use. * @param gen - The FastNoiseLite instance to use.
* @param x - The x coordinate. * @param x - The x coordinate.
* @param y - The y coordinate. * @param y - The y coordinate.
* @param z - The z coordinate. * @param z - The z coordinate.
* @return double - Noise value at the specified coordinates. * @return double - Noise value at the specified coordinates.
*/ */
@Override @Override
public double getNoise(FastNoise gen, World w, int x, int y, int z) { public double getNoise(FastNoiseLite gen, World w, int x, int y, int z) {
synchronized(noiseLock) { synchronized(noiseLock) {
xVar.setValue(x); xVar.setValue(x);
yVar.setValue(y); yVar.setValue(y);
@@ -54,9 +54,9 @@ public class ImageLoader {
float[] noise; float[] noise;
if(align.equals(Align.CENTER)) noise = tb.getGrid(x - original.getWidth()/2, y - original.getHeight()/2).getRawNoise(x - original.getWidth()/2, y - original.getHeight()/2); if(align.equals(Align.CENTER)) noise = tb.getGrid(x - original.getWidth()/2, y - original.getHeight()/2).getRawNoise(x - original.getWidth()/2, y - original.getHeight()/2);
else noise = tb.getGrid(x, y).getRawNoise(x, y); else noise = tb.getGrid(x, y).getRawNoise(x, y);
newImg.setRGB(x, y, new Color((int) (NormalizationUtil.normalize(noise[0], tb.getGrid(x, y).getSizeX()) * ((double) 255 / tb.getGrid(x, y).getSizeX())), newImg.setRGB(x, y, new Color((int) (NormalizationUtil.normalize(noise[0], tb.getGrid(x, y).getSizeX(), 4) * ((double) 255 / tb.getGrid(x, y).getSizeX())),
(int) (NormalizationUtil.normalize(noise[1], tb.getGrid(x, y).getSizeZ()) * ((double) 255 / tb.getGrid(x, y).getSizeZ())), (int) (NormalizationUtil.normalize(noise[1], tb.getGrid(x, y).getSizeZ(), 4) * ((double) 255 / tb.getGrid(x, y).getSizeZ())),
(int) (NormalizationUtil.normalize(z.getNoise(x, y), z.getSize()) * ((double) 255 / z.getSize()))) (int) (NormalizationUtil.normalize(z.getNoise(x, y), z.getSize(), 4) * ((double) 255 / z.getSize())))
.getRGB()); .getRGB());
} }
} }
@@ -27,9 +27,9 @@ public class WorldImageGenerator {
for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) { for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) {
int imX = 0; int imX = 0;
for(int x = centerX - (draw.getWidth()/2); x < centerX + (draw.getWidth()/2); x++) { for(int x = centerX - (draw.getWidth()/2); x < centerX + (draw.getWidth()/2); x++) {
int zone = NormalizationUtil.normalize(tw.getZone().getRawNoise(x, y), 256); int zone = NormalizationUtil.normalize(tw.getZone().getRawNoise(x, y), 256, 4);
float[] noise = tb.getGrid(x, y).getRawNoise(x, y); float[] noise = tb.getGrid(x, y).getRawNoise(x, y);
Color c = new Color(NormalizationUtil.normalize(noise[0], 256), NormalizationUtil.normalize(noise[1], 256), zone); Color c = new Color(NormalizationUtil.normalize(noise[0], 256, 4), NormalizationUtil.normalize(noise[1], 256, 4), zone);
draw.setRGB(imX, imY, c.getRGB()); draw.setRGB(imX, imY, c.getRGB());
imX++; imX++;
} }
@@ -1,13 +1,13 @@
package com.dfsek.terra.math; package com.dfsek.terra.math;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import parsii.eval.Expression; import parsii.eval.Expression;
import parsii.eval.Function; import parsii.eval.Function;
import java.util.List; import java.util.List;
public class NoiseFunction2 implements Function { public class NoiseFunction2 implements Function {
private FastNoise gen; private FastNoiseLite gen;
@Override @Override
public int getNumberOfArguments() { public int getNumberOfArguments() {
@@ -16,10 +16,10 @@ public class NoiseFunction2 implements Function {
@Override @Override
public double eval(List<Expression> list) { public double eval(List<Expression> list) {
return gen.getSimplexFractal((float) list.get(0).evaluate(), (float) list.get(1).evaluate()); return gen.getNoise((float) list.get(0).evaluate(), (float) list.get(1).evaluate());
} }
public void setNoise(FastNoise gen) { public void setNoise(FastNoiseLite gen) {
this.gen = gen; this.gen = gen;
} }
@@ -1,13 +1,13 @@
package com.dfsek.terra.math; package com.dfsek.terra.math;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import parsii.eval.Expression; import parsii.eval.Expression;
import parsii.eval.Function; import parsii.eval.Function;
import java.util.List; import java.util.List;
public class NoiseFunction3 implements Function { public class NoiseFunction3 implements Function {
private FastNoise gen; private FastNoiseLite gen;
@Override @Override
public int getNumberOfArguments() { public int getNumberOfArguments() {
return 3; return 3;
@@ -15,10 +15,10 @@ public class NoiseFunction3 implements Function {
@Override @Override
public double eval(List<Expression> list) { public double eval(List<Expression> list) {
return gen.getSimplexFractal((float) list.get(0).evaluate(), (float) list.get(1).evaluate(), (float) list.get(2).evaluate()); return gen.getNoise((float) list.get(0).evaluate(), (float) list.get(1).evaluate(), (float) list.get(2).evaluate());
} }
public void setNoise(FastNoise gen) { public void setNoise(FastNoiseLite gen) {
this.gen = gen; this.gen = gen;
} }
@@ -2,10 +2,10 @@ package com.dfsek.terra.procgen.voxel;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
public class DeformedSphere extends VoxelGeometry { public class DeformedSphere extends VoxelGeometry {
public DeformedSphere(Vector start, int rad, double deform, FastNoise noise) { public DeformedSphere(Vector start, int rad, double deform, FastNoiseLite noise) {
for(int x = -rad; x <= rad; x++) { for(int x = -rad; x <= rad; x++) {
for(int y = -rad; y <= rad; y++) { for(int y = -rad; y <= rad; y++) {
for(int z = -rad; z <= rad; z++) { for(int z = -rad; z <= rad; z++) {
@@ -1,7 +1,7 @@
package com.dfsek.terra.procgen.voxel; package com.dfsek.terra.procgen.voxel;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
public class Sphere extends VoxelGeometry { public class Sphere extends VoxelGeometry {
public Sphere(Vector start, int rad) { public Sphere(Vector start, int rad) {
@@ -6,7 +6,7 @@ import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
@@ -42,12 +42,12 @@ public enum StructureSpawnRequirement implements Serializable {
} }
}; };
private static final long serialVersionUID = -175639605885943679L; private static final long serialVersionUID = -175639605885943679L;
private static final transient Map<World, FastNoise> noiseMap = new HashMap<>(); private static final transient Map<World, FastNoiseLite> noiseMap = new HashMap<>();
public abstract boolean matches(World w, int x, int y, int z); public abstract boolean matches(World w, int x, int y, int z);
public static void putNoise(World w, FastNoise noise) { public static void putNoise(World w, FastNoiseLite noise) {
noiseMap.putIfAbsent(w, noise); noiseMap.putIfAbsent(w, noise);
} }
private static FastNoise getNoise(World w) { private static FastNoiseLite getNoise(World w) {
return noiseMap.get(w); return noiseMap.get(w);
} }
} }
File diff suppressed because one or more lines are too long
+8 -10
View File
@@ -1,6 +1,6 @@
import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.BiomeZone;
import com.sun.corba.se.spi.orbutil.threadpool.Work; import com.sun.corba.se.spi.orbutil.threadpool.Work;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoiseLite;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -14,10 +14,9 @@ public class LookupGenerator {
int dist = 4096; int dist = 4096;
List<Double> vals = new ArrayList<>(); List<Double> vals = new ArrayList<>();
FastNoise noise = new FastNoise(); FastNoiseLite noise = new FastNoiseLite();
noise.setNoiseType(FastNoise.NoiseType.SimplexFractal); noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
noise.setFrequency(0.02f); noise.setFrequency(0.02f);
noise.setFractalOctaves(4);
int[] numbers = new int[dist]; int[] numbers = new int[dist];
double min = Integer.MAX_VALUE; double min = Integer.MAX_VALUE;
double max = Integer.MIN_VALUE; double max = Integer.MIN_VALUE;
@@ -25,13 +24,12 @@ public class LookupGenerator {
numbers[i] = 0; numbers[i] = 0;
} }
int workerAmount = 16; int workerAmount = 16;
List<Worker> workers = new ArrayList<>(); List<Worker> workers = new ArrayList<>();
for(int i = 0; i < workerAmount; i++) { for(int i = 0; i < workerAmount; i++) {
workers.add(new Worker(new ArrayList<>(), 10000000, noise)); workers.add(new Worker(new ArrayList<>(), 5000000, noise));
} }
for(Worker w : workers) { for(Worker w : workers) {
@@ -53,7 +51,7 @@ public class LookupGenerator {
} }
for(int i = 0; i < dist; i++) { for(int i = 0; i < dist; i++) {
System.out.print(i + (String.valueOf(i).length() ==1 ? " " : "") + " |"); System.out.print(i + (String.valueOf(i).length() ==1 ? " " : "") + " |");
for(int j = 0; j < numbers[i]/3000; j++) { for(int j = 0; j < numbers[i]/300; j++) {
System.out.print("-"); System.out.print("-");
} }
System.out.println("|"); System.out.println("|");
@@ -74,7 +72,7 @@ public class LookupGenerator {
s.append("}"); s.append("}");
numbers = new int[dist]; numbers = new int[dist];
vals = new ArrayList<>(); vals = new ArrayList<>();
for(int i = 0; i < 50000000; i++) { for(int i = 0; i < 10000000; i++) {
double n = noise.getNoise(0, i); double n = noise.getNoise(0, i);
vals.add(n); vals.add(n);
numbers[normalizeNew(n)]++; numbers[normalizeNew(n)]++;
@@ -109,8 +107,8 @@ public class LookupGenerator {
private static class Worker extends Thread { private static class Worker extends Thread {
private final List<Double> l; private final List<Double> l;
private final int searches; private final int searches;
private final FastNoise noise; private final FastNoiseLite noise;
public Worker(List<Double> l, int searches, FastNoise noise) { public Worker(List<Double> l, int searches, FastNoiseLite noise) {
this.l = l; this.l = l;
this.searches = searches; this.searches = searches;
this.noise = noise; this.noise = noise;