This commit is contained in:
Daniel Mills 2020-09-08 19:29:19 -04:00
parent 0b9ea265f0
commit 649becb98e
28 changed files with 1080 additions and 1580 deletions

View File

@ -101,7 +101,6 @@ public class IrisBoardManager implements BoardProvider, Listener
int z = player.getLocation().getBlockZ();
IrisBiome b = g.sampleTrueBiome(x, y, z);
IrisStructureResult st = g.getStructure(x, y, z);
tp.put(g.getMetrics().getSpeed());
v.add("&7&m------------------");
v.add(C.GREEN + "Speed" + C.GRAY + ": " + C.BOLD + "" + C.GRAY + Form.f(g.getMetrics().getPerSecond().getAverage(), 0) + "/s " + Form.duration(g.getMetrics().getTotal().getAverage(), 1) + "");

View File

@ -7,6 +7,7 @@ import org.bukkit.inventory.Inventory;
import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.gen.scaffold.IrisWorlds;
import com.volmit.iris.object.InventorySlotType;
import com.volmit.iris.object.IrisLootTable;
import com.volmit.iris.util.KList;
@ -37,7 +38,8 @@ public class CommandIrisStudioLoot extends MortarCommand
if(sender.isPlayer())
{
Player p = sender.player();
KList<IrisLootTable> tables = Iris.proj.getCurrentProject().getGlUpdate().getLootTables(RNG.r, p.getLocation().getBlock());
IrisWorlds.getProvider(sender.player().getWorld()).getPopulators();
KList<IrisLootTable> tables = IrisWorlds.getProvider(sender.player().getWorld()).getGlUpdate().getLootTables(RNG.r, p.getLocation().getBlock());
Inventory inv = Bukkit.createInventory(null, 27 * 2);
Iris.proj.getCurrentProject().getGlUpdate().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1);
p.openInventory(inv);

View File

@ -60,7 +60,7 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List
private boolean failing;
private int task;
private boolean dev;
private boolean initialized;
private volatile boolean initialized;
private RNG masterRandom;
private ChronoLatch perSecond;
private ChronoLatch tickLatch;
@ -156,10 +156,10 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List
return;
}
setInitialized(true);
setData(new IrisDataManager(getTarget().getFolder()));
setMasterRandom(new RNG(getTarget().getSeed()));
setMetrics(new IrisMetrics(128));
setInitialized(true);
setTask(Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::tick, 0, 0));
Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance);
onInit(masterRandom);

View File

@ -20,7 +20,6 @@ import com.volmit.iris.object.InferredType;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisBiomeDecorator;
import com.volmit.iris.object.IrisBiomeGeneratorLink;
import com.volmit.iris.object.IrisDepositGenerator;
import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.object.IrisGenerator;
import com.volmit.iris.object.IrisRegion;
@ -65,8 +64,9 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
public void onInit(RNG rng)
{
super.onInit(rng);
loadGenerators();
getData().preferFolder(getDimension().getLoadFile().getParentFile().getParentFile().getName());
buildGenLayers(getMasterRandom());
loadGenerators();
}
private void buildGenLayers(RNG rng)
@ -347,30 +347,6 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
protected void onGenerate(RNG random, int x, int z, TerrainChunk terrain)
{
super.onGenerate(random, x, z, terrain);
RNG ro = random.nextParallelRNG((x * x * x) - z);
IrisRegion region = sampleRegion((x * 16) + 7, (z * 16) + 7);
IrisBiome biome = sampleTrueBiome((x * 16) + 7, (z * 16) + 7);
for(IrisDepositGenerator k : getDimension().getDeposits())
{
k.generate(terrain, ro, this, x, z);
}
for(IrisDepositGenerator k : region.getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(terrain, ro, this, x, z);
}
}
for(IrisDepositGenerator k : biome.getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(terrain, ro, this, x, z);
}
}
}
private void decorateLand(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz, BlockData block)
@ -836,6 +812,7 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
{
if(dim == null)
{
Iris.warn("Cannot load generators, Dimension is null!");
return;
}
@ -868,6 +845,8 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
loadQueue.addAll(biome.getChildren());
}
}
Iris.info("Loaded " + generators.size() + " Generators");
}
public IrisBiome sampleBiome(int x, int z)

View File

@ -6,10 +6,10 @@ import org.bukkit.block.data.BlockData;
import com.volmit.iris.gen.DimensionalTerrainProvider;
import com.volmit.iris.gen.IrisTerrainProvider;
import com.volmit.iris.gen.atomics.AtomicSliver;
import com.volmit.iris.noise.FastNoise;
import com.volmit.iris.noise.FastNoise.CellularDistanceFunction;
import com.volmit.iris.noise.FastNoise.CellularReturnType;
import com.volmit.iris.noise.FastNoise.NoiseType;
import com.volmit.iris.noise.FastNoiseDouble;
import com.volmit.iris.noise.FastNoiseDouble.CellularDistanceFunction;
import com.volmit.iris.noise.FastNoiseDouble.CellularReturnType;
import com.volmit.iris.noise.FastNoiseDouble.NoiseType;
import com.volmit.iris.object.IrisCaveLayer;
import com.volmit.iris.util.B;
import com.volmit.iris.util.CaveResult;
@ -23,13 +23,13 @@ public class GenLayerCave extends GenLayer
public static final BlockData CAVE_AIR = B.getBlockData("CAVE_AIR");
public static final BlockData AIR = B.getBlockData("AIR");
private static final KList<CaveResult> EMPTY = new KList<>();
private FastNoise gg;
private FastNoiseDouble gg;
public GenLayerCave(DimensionalTerrainProvider iris, RNG rng)
{
//@builder
super(iris, rng);
gg = new FastNoise(324895 * rng.nextParallelRNG(49678).imax());
gg = new FastNoiseDouble(324895 * rng.nextParallelRNG(49678).imax());
//@done
}
@ -71,7 +71,7 @@ public class GenLayerCave extends GenLayer
for(double tunnelHeight = 1; tunnelHeight <= baseWidth; tunnelHeight++)
{
double distance = (gg.GetCellular((float) ((wx + (10000 * seed)) / layer.getCaveZoom()), (float) ((wz - (10000 * seed)) / layer.getCaveZoom())) + 1D) / 2D;
double distance = (gg.GetCellular(((wx + (10000 * seed)) / layer.getCaveZoom()), ((wz - (10000 * seed)) / layer.getCaveZoom())) + 1D) / 2D;
if(distance < distanceCheck - (tunnelHeight * distanceTake))
{
int caveHeight = (int) Math.round(caveHeightNoise);

View File

@ -16,8 +16,10 @@ import com.volmit.iris.Iris;
import com.volmit.iris.gen.IrisTerrainProvider;
import com.volmit.iris.gen.ParallaxTerrainProvider;
import com.volmit.iris.gen.atomics.AtomicSliverMap;
import com.volmit.iris.gen.scaffold.ChunkWrapper;
import com.volmit.iris.object.InventorySlotType;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisDepositGenerator;
import com.volmit.iris.object.IrisLootReference;
import com.volmit.iris.object.IrisLootTable;
import com.volmit.iris.object.IrisRegion;
@ -45,7 +47,51 @@ public class GenLayerUpdate extends BlockPopulator
PrecisionStopwatch p = PrecisionStopwatch.start();
AtomicSliverMap map = gen.getParallaxChunk(c.getX(), c.getZ());
RNG rx = rng.nextParallelRNG(c.getX() + r.nextInt()).nextParallelRNG(c.getZ() + r.nextInt());
generateDeposits(w, rx, c);
updateBlocks(w, rx, c, map);
spawnInitials(c, rx);
p.end();
gen.getMetrics().getUpdate().put(p.getMilliseconds());
}
public void spawnInitials(Chunk c, RNG rx)
{
((IrisTerrainProvider) gen).spawnInitials(c, rx);
}
public void generateDeposits(World w, RNG rx, Chunk c)
{
int x = c.getX();
int z = c.getZ();
RNG ro = rx.nextParallelRNG((x * x * x) - z);
IrisRegion region = gen.sampleRegion((x * 16) + 7, (z * 16) + 7);
IrisBiome biome = gen.sampleTrueBiome((x * 16) + 7, (z * 16) + 7);
ChunkWrapper terrain = new ChunkWrapper(c);
for(IrisDepositGenerator k : gen.getDimension().getDeposits())
{
k.generate(terrain, ro, gen, x, z);
}
for(IrisDepositGenerator k : region.getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(terrain, ro, gen, x, z);
}
}
for(IrisDepositGenerator k : biome.getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(terrain, ro, gen, x, z);
}
}
}
private void updateBlocks(World w, RNG rx, Chunk c, AtomicSliverMap map)
{
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
@ -61,11 +107,6 @@ public class GenLayerUpdate extends BlockPopulator
}
}
}
((IrisTerrainProvider) gen).spawnInitials(c, rx);
p.end();
gen.getMetrics().getUpdate().put(p.getMilliseconds());
}
public void update(Chunk c, int x, int y, int z, int rx, int rz, RNG rng)

View File

@ -0,0 +1,84 @@
package com.volmit.iris.gen.scaffold;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
@SuppressWarnings("deprecation")
public class ChunkWrapper implements ChunkData
{
private final Chunk chunk;
public ChunkWrapper(Chunk chunk)
{
this.chunk = chunk;
}
@Override
public int getMaxHeight()
{
return chunk.getWorld().getMaxHeight();
}
@Override
public void setBlock(int x, int y, int z, Material material)
{
chunk.getBlock(x, y, z).setType(material, false);
}
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
throw new UnsupportedOperationException();
}
@Override
public void setBlock(int x, int y, int z, BlockData blockData)
{
chunk.getBlock(x, y, z).setBlockData(blockData, false);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
throw new UnsupportedOperationException();
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
throw new UnsupportedOperationException();
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
throw new UnsupportedOperationException();
}
@Override
public Material getType(int x, int y, int z)
{
return chunk.getBlock(x, y, z).getType();
}
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
throw new UnsupportedOperationException();
}
@Override
public BlockData getBlockData(int x, int y, int z)
{
return chunk.getBlock(x, y, z).getBlockData();
}
@Override
public byte getData(int x, int y, int z)
{
throw new UnsupportedOperationException();
}
}

View File

@ -6,12 +6,12 @@ import com.volmit.iris.gen.IrisTerrainProvider;
public class IrisWorlds
{
public boolean isIrisWorld(World world)
public static boolean isIrisWorld(World world)
{
return world.getGenerator() instanceof Provisioned;
}
public IrisTerrainProvider getProvider(World world)
public static IrisTerrainProvider getProvider(World world)
{
if(isIrisWorld(world))
{

View File

@ -1,231 +0,0 @@
package com.volmit.iris.noise;
/**
* Base class for all noise generators
*/
public abstract class BaseNoiseGenerator
{
protected final int perm[] = new int[512];
protected double offsetX;
protected double offsetY;
protected double offsetZ;
/**
* Speedy floor, faster than (int)Math.floor(x)
*
* @param x
* Value to floor
* @return Floored value
*/
public static int floor(double x)
{
return x >= 0 ? (int) x : (int) x - 1;
}
protected static double fade(double x)
{
return x * x * x * (x * (x * 6 - 15) + 10);
}
protected static double lerp(double x, double y, double z)
{
return y + x * (z - y);
}
protected static double grad(int hash, double x, double y, double z)
{
hash &= 15;
double u = hash < 8 ? x : y;
double v = hash < 4 ? y : hash == 12 || hash == 14 ? x : z;
return ((hash & 1) == 0 ? u : -u) + ((hash & 2) == 0 ? v : -v);
}
/**
* Computes and returns the 1D noise for the given coordinate in 1D space
*
* @param x
* X coordinate
* @return Noise at given location, from range -1 to 1
*/
public double noise(double x)
{
return noise(x, 0, 0);
}
/**
* Computes and returns the 2D noise for the given coordinates in 2D space
*
* @param x
* X coordinate
* @param y
* Y coordinate
* @return Noise at given location, from range -1 to 1
*/
public double noise(double x, double y)
{
return noise(x, y, 0);
}
/**
* Computes and returns the 3D noise for the given coordinates in 3D space
*
* @param x
* X coordinate
* @param y
* Y coordinate
* @param z
* Z coordinate
* @return Noise at given location, from range -1 to 1
*/
public abstract double noise(double x, double y, double z);
/**
* Generates noise for the 1D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public double noise(double x, int octaves, double frequency, double amplitude)
{
return noise(x, 0, 0, octaves, frequency, amplitude);
}
/**
* Generates noise for the 1D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @param normalized
* If true, normalize the value to [-1, 1]
* @return Resulting noise
*/
public double noise(double x, int octaves, double frequency, double amplitude, boolean normalized)
{
return noise(x, 0, 0, octaves, frequency, amplitude, normalized);
}
/**
* Generates noise for the 2D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public double noise(double x, double y, int octaves, double frequency, double amplitude)
{
return noise(x, y, 0, octaves, frequency, amplitude);
}
/**
* Generates noise for the 2D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @param normalized
* If true, normalize the value to [-1, 1]
* @return Resulting noise
*/
public double noise(double x, double y, int octaves, double frequency, double amplitude, boolean normalized)
{
return noise(x, y, 0, octaves, frequency, amplitude, normalized);
}
/**
* Generates noise for the 3D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param z
* Z-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public double noise(double x, double y, double z, int octaves, double frequency, double amplitude)
{
return noise(x, y, z, octaves, frequency, amplitude, false);
}
/**
* Generates noise for the 3D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param z
* Z-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @param normalized
* If true, normalize the value to [-1, 1]
* @return Resulting noise
*/
public double noise(double x, double y, double z, int octaves, double frequency, double amplitude, boolean normalized)
{
double result = 0;
double amp = 1;
double freq = 1;
double max = 0;
for(int i = 0; i < octaves; i++)
{
result += noise(x * freq, y * freq, z * freq) * amp;
max += amp;
freq *= frequency;
amp *= amplitude;
}
if(normalized)
{
result /= max;
}
return result;
}
}

View File

@ -1,219 +0,0 @@
package com.volmit.iris.noise;
import java.util.Random;
/**
* Generates noise using the "classic" perlin generator
*
* @see SimplexNoiseC "Improved" and faster version with slighly
* different results
*/
public class BasePerlinNoiseGenerator extends BaseNoiseGenerator
{
protected static final int grad3[][] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}};
private static final BasePerlinNoiseGenerator instance = new BasePerlinNoiseGenerator();
protected BasePerlinNoiseGenerator()
{
int p[] = {151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
for(int i = 0; i < 512; i++)
{
perm[i] = p[i & 255];
}
}
/**
* Creates a seeded perlin noise generator for the given seed
*
* @param seed
* Seed to construct this generator for
*/
public BasePerlinNoiseGenerator(long seed)
{
this(new Random(seed));
}
/**
* Creates a seeded perlin noise generator with the given Random
*
* @param rand
* Random to construct with
*/
public BasePerlinNoiseGenerator(Random rand)
{
offsetX = rand.nextDouble() * 256;
offsetY = rand.nextDouble() * 256;
offsetZ = rand.nextDouble() * 256;
for(int i = 0; i < 256; i++)
{
perm[i] = rand.nextInt(256);
}
for(int i = 0; i < 256; i++)
{
int pos = rand.nextInt(256 - i) + i;
int old = perm[i];
perm[i] = perm[pos];
perm[pos] = old;
perm[i + 256] = perm[i];
}
}
/**
* Computes and returns the 1D unseeded perlin noise for the given coordinates
* in 1D space
*
* @param x
* X coordinate
* @return Noise at given location, from range -1 to 1
*/
public static double getNoise(double x)
{
return instance.noise(x);
}
/**
* Computes and returns the 2D unseeded perlin noise for the given coordinates
* in 2D space
*
* @param x
* X coordinate
* @param y
* Y coordinate
* @return Noise at given location, from range -1 to 1
*/
public static double getNoise(double x, double y)
{
return instance.noise(x, y);
}
/**
* Computes and returns the 3D unseeded perlin noise for the given coordinates
* in 3D space
*
* @param x
* X coordinate
* @param y
* Y coordinate
* @param z
* Z coordinate
* @return Noise at given location, from range -1 to 1
*/
public static double getNoise(double x, double y, double z)
{
return instance.noise(x, y, z);
}
/**
* Gets the singleton unseeded instance of this generator
*
* @return Singleton
*/
public static BasePerlinNoiseGenerator getInstance()
{
return instance;
}
@Override
public double noise(double x, double y, double z)
{
x += offsetX;
y += offsetY;
z += offsetZ;
int floorX = floor(x);
int floorY = floor(y);
int floorZ = floor(z);
// Find unit cube containing the point
int X = floorX & 255;
int Y = floorY & 255;
int Z = floorZ & 255;
// Get relative xyz coordinates of the point within the cube
x -= floorX;
y -= floorY;
z -= floorZ;
// Compute fade curves for xyz
double fX = fade(x);
double fY = fade(y);
double fZ = fade(z);
// Hash coordinates of the cube corners
int A = perm[X] + Y;
int AA = perm[A] + Z;
int AB = perm[A + 1] + Z;
int B = perm[X + 1] + Y;
int BA = perm[B] + Z;
int BB = perm[B + 1] + Z;
return lerp(fZ, lerp(fY, lerp(fX, grad(perm[AA], x, y, z), grad(perm[BA], x - 1, y, z)), lerp(fX, grad(perm[AB], x, y - 1, z), grad(perm[BB], x - 1, y - 1, z))), lerp(fY, lerp(fX, grad(perm[AA + 1], x, y, z - 1), grad(perm[BA + 1], x - 1, y, z - 1)), lerp(fX, grad(perm[AB + 1], x, y - 1, z - 1), grad(perm[BB + 1], x - 1, y - 1, z - 1))));
}
/**
* Generates noise for the 1D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public static double getNoise(double x, int octaves, double frequency, double amplitude)
{
return instance.noise(x, octaves, frequency, amplitude);
}
/**
* Generates noise for the 2D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public static double getNoise(double x, double y, int octaves, double frequency, double amplitude)
{
return instance.noise(x, y, octaves, frequency, amplitude);
}
/**
* Generates noise for the 3D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param z
* Z-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public static double getNoise(double x, double y, double z, int octaves, double frequency, double amplitude)
{
return instance.noise(x, y, z, octaves, frequency, amplitude);
}
}

View File

@ -2,6 +2,7 @@ package com.volmit.iris.noise;
import java.util.List;
import com.volmit.iris.Iris;
import com.volmit.iris.util.IRare;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.KList;
@ -293,9 +294,20 @@ public class CNG
return v.get(0);
}
try
{
return v.get(fit(0, v.size() - 1, dim));
}
catch(Throwable e)
{
Iris.error("Failed to sample noise into array " + v.size() + " nodes");
Iris.error("Noise Source: " + generator.getClass().getSimpleName());
}
return v.get(0);
}
public int fit(int min, int max, double... dim)
{
if(min == max)

View File

@ -7,8 +7,8 @@ import lombok.Setter;
public class CellGenerator
{
private FastNoise fn;
private FastNoise fd;
private FastNoiseDouble fn;
private FastNoiseDouble fd;
private CNG cng;
@Getter
@ -25,49 +25,45 @@ public class CellGenerator
cellScale = 0.73;
cng = CNG.signature(rng.nextParallelRNG(3204));
RNG rx = rng.nextParallelRNG(8735652);
int s = rx.nextInt();
fn = new FastNoise(s);
fn.setNoiseType(FastNoise.NoiseType.Cellular);
fn.setCellularReturnType(FastNoise.CellularReturnType.CellValue);
fn.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
fd = new FastNoise(s);
fd.setNoiseType(FastNoise.NoiseType.Cellular);
fd.setCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
fd.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
long s = rx.lmax();
fn = new FastNoiseDouble(s);
fn.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
fn.setCellularReturnType(FastNoiseDouble.CellularReturnType.CellValue);
fn.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
fd = new FastNoiseDouble(s);
fd.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
fd.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Sub);
fd.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
}
public float getDistance(double x, double z)
public double getDistance(double x, double z)
{
return ((fd.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle)))) + 1f) / 2f;
return ((fd.GetCellular(((x * cellScale) + (cng.noise(x, z) * shuffle)), ((z * cellScale) + (cng.noise(z, x) * shuffle)))) + 1f) / 2f;
}
public float getDistance(double x, double y, double z)
public double getDistance(double x, double y, double z)
{
return ((fd.GetCellular((float) ((x * cellScale) + (cng.noise(x, y, z) * shuffle)), (float) ((y * cellScale) + (cng.noise(x, y, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, y, x) * shuffle)))) + 1f) / 2f;
return ((fd.GetCellular(((x * cellScale) + (cng.noise(x, y, z) * shuffle)), ((y * cellScale) + (cng.noise(x, y, z) * shuffle)), ((z * cellScale) + (cng.noise(z, y, x) * shuffle)))) + 1f) / 2f;
}
public float getValue(double x, double z, int possibilities)
public double getValue(double x, double z, int possibilities)
{
if(possibilities == 1)
{
return 0;
}
return ((fn.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
return ((fn.GetCellular(((x * cellScale) + (cng.noise(x, z) * shuffle)), ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
}
public float getValue(double x, double y, double z, int possibilities)
public double getValue(double x, double y, double z, int possibilities)
{
if(possibilities == 1)
{
return 0;
}
return ((fn.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)),
(float) ((y * 8 * cellScale) + (cng.noise(x, y * 8) * shuffle))
, (float) ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
return ((fn.GetCellular(((x * cellScale) + (cng.noise(x, z) * shuffle)), ((y * 8 * cellScale) + (cng.noise(x, y * 8) * shuffle)), ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
}
public int getIndex(double x, double z, int possibilities)

View File

@ -1,33 +1,40 @@
package com.volmit.iris.noise;
import com.volmit.iris.util.M;
import com.volmit.iris.util.RNG;
public class CellHeightNoise implements NoiseGenerator {
private final FastNoise n;
public class CellHeightNoise implements NoiseGenerator
{
private final FastNoiseDouble n;
public CellHeightNoise(long seed) {
this.n = new FastNoise((int) seed);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
public CellHeightNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Sub);
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
}
private double filter(double noise) {
private double filter(double noise)
{
return M.clip(1D - ((noise / 2D) + 0.5D), 0D, 1D);
}
@Override
public double noise(double x) {
return filter(n.GetCellular((float) x, 0));
public double noise(double x)
{
return filter(n.GetCellular(x, 0));
}
@Override
public double noise(double x, double z) {
return filter(n.GetCellular((float) x, (float) z));
public double noise(double x, double z)
{
return filter(n.GetCellular(x, z));
}
@Override
public double noise(double x, double y, double z) {
return filter(n.GetCellular((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return filter(n.GetCellular(x, y, z));
}
}

View File

@ -1,32 +1,34 @@
package com.volmit.iris.noise;
import com.volmit.iris.util.RNG;
public class CellularNoise implements NoiseGenerator
{
private final FastNoise n;
private final FastNoiseDouble n;
public CellularNoise(long seed)
{
this.n = new FastNoise((int) seed);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.CellValue);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.CellValue);
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
}
@Override
public double noise(double x)
{
return (n.GetCellular((float) x, 0) / 2D) + 0.5D;
return (n.GetCellular(x, 0) / 2D) + 0.5D;
}
@Override
public double noise(double x, double z)
{
return (n.GetCellular((float) x, (float) z) / 2D) + 0.5D;
return (n.GetCellular(x, z) / 2D) + 0.5D;
}
@Override
public double noise(double x, double y, double z)
{
return (n.GetCellular((float) x, (float) y, (float) z) / 2D) + 0.5D;
return (n.GetCellular(x, y, z) / 2D) + 0.5D;
}
}

View File

@ -1,28 +1,36 @@
package com.volmit.iris.noise;
public class CubicNoise implements NoiseGenerator {
private final FastNoise n;
import com.volmit.iris.util.RNG;
public CubicNoise(long seed) {
this.n = new FastNoise((int) seed);
public class CubicNoise implements NoiseGenerator
{
private final FastNoiseDouble n;
public CubicNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
}
private double f(double n) {
private double f(double n)
{
return (n / 2D) + 0.5D;
}
@Override
public double noise(double x) {
return f(n.GetCubic((float) x, 0));
public double noise(double x)
{
return f(n.GetCubic(x, 0));
}
@Override
public double noise(double x, double z) {
return f(n.GetCubic((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetCubic(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetCubic((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetCubic(x, y, z));
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,38 +1,45 @@
package com.volmit.iris.noise;
import com.volmit.iris.noise.FastNoise.FractalType;
import com.volmit.iris.noise.FastNoiseDouble.FractalType;
import com.volmit.iris.util.RNG;
public class FractalBillowPerlinNoise implements NoiseGenerator, OctaveNoise {
private final FastNoise n;
public class FractalBillowPerlinNoise implements NoiseGenerator, OctaveNoise
{
private final FastNoiseDouble n;
public FractalBillowPerlinNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
public FractalBillowPerlinNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setFractalOctaves(1);
n.setFractalType(FractalType.Billow);
}
public double f(double v) {
public double f(double v)
{
return (v / 2D) + 0.5D;
}
@Override
public double noise(double x) {
return f(n.GetPerlinFractal((float) x, 0f));
public double noise(double x)
{
return f(n.GetPerlinFractal(x, 0f));
}
@Override
public double noise(double x, double z) {
return f(n.GetPerlinFractal((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetPerlinFractal(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetPerlinFractal((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetPerlinFractal(x, y, z));
}
@Override
public void setOctaves(int o) {
public void setOctaves(int o)
{
n.setFractalOctaves(o);
}
}

View File

@ -1,38 +1,45 @@
package com.volmit.iris.noise;
import com.volmit.iris.noise.FastNoise.FractalType;
import com.volmit.iris.noise.FastNoiseDouble.FractalType;
import com.volmit.iris.util.RNG;
public class FractalBillowSimplexNoise implements NoiseGenerator, OctaveNoise {
private final FastNoise n;
public class FractalBillowSimplexNoise implements NoiseGenerator, OctaveNoise
{
private final FastNoiseDouble n;
public FractalBillowSimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
public FractalBillowSimplexNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setFractalOctaves(1);
n.setFractalType(FractalType.Billow);
}
public double f(double v) {
public double f(double v)
{
return (v / 2D) + 0.5D;
}
@Override
public double noise(double x) {
return f(n.GetSimplexFractal((float) x, 0f));
public double noise(double x)
{
return f(n.GetSimplexFractal(x, 0d));
}
@Override
public double noise(double x, double z) {
return f(n.GetSimplexFractal((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetSimplexFractal(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetSimplexFractal((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetSimplexFractal(x, y, z));
}
@Override
public void setOctaves(int o) {
public void setOctaves(int o)
{
n.setFractalOctaves(o);
}
}

View File

@ -1,31 +1,38 @@
package com.volmit.iris.noise;
import com.volmit.iris.noise.FastNoise.FractalType;
import com.volmit.iris.noise.FastNoiseDouble.FractalType;
import com.volmit.iris.util.RNG;
public class FractalCubicNoise implements NoiseGenerator {
private final FastNoise n;
public class FractalCubicNoise implements NoiseGenerator
{
private final FastNoiseDouble n;
public FractalCubicNoise(long seed) {
this.n = new FastNoise((int) seed);
public FractalCubicNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setFractalType(FractalType.Billow);
}
private double f(double n) {
private double f(double n)
{
return (n / 2D) + 0.5D;
}
@Override
public double noise(double x) {
return f(n.GetCubicFractal((float) x, 0));
public double noise(double x)
{
return f(n.GetCubicFractal(x, 0));
}
@Override
public double noise(double x, double z) {
return f(n.GetCubicFractal((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetCubicFractal(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetCubicFractal((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetCubicFractal(x, y, z));
}
}

View File

@ -1,38 +1,45 @@
package com.volmit.iris.noise;
import com.volmit.iris.noise.FastNoise.FractalType;
import com.volmit.iris.noise.FastNoiseDouble.FractalType;
import com.volmit.iris.util.RNG;
public class FractalFBMSimplexNoise implements NoiseGenerator, OctaveNoise {
private final FastNoise n;
public class FractalFBMSimplexNoise implements NoiseGenerator, OctaveNoise
{
private final FastNoiseDouble n;
public FractalFBMSimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
public FractalFBMSimplexNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setFractalOctaves(1);
n.setFractalType(FractalType.FBM);
}
public double f(double v) {
public double f(double v)
{
return (v / 2D) + 0.5D;
}
@Override
public double noise(double x) {
return f(n.GetSimplexFractal((float) x, 0f));
public double noise(double x)
{
return f(n.GetSimplexFractal(x, 0d));
}
@Override
public double noise(double x, double z) {
return f(n.GetSimplexFractal((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetSimplexFractal(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetSimplexFractal((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetSimplexFractal(x, y, z));
}
@Override
public void setOctaves(int o) {
public void setOctaves(int o)
{
n.setFractalOctaves(o);
}
}

View File

@ -1,38 +1,45 @@
package com.volmit.iris.noise;
import com.volmit.iris.noise.FastNoise.FractalType;
import com.volmit.iris.noise.FastNoiseDouble.FractalType;
import com.volmit.iris.util.RNG;
public class FractalRigidMultiSimplexNoise implements NoiseGenerator, OctaveNoise {
private final FastNoise n;
public class FractalRigidMultiSimplexNoise implements NoiseGenerator, OctaveNoise
{
private final FastNoiseDouble n;
public FractalRigidMultiSimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
public FractalRigidMultiSimplexNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setFractalOctaves(1);
n.setFractalType(FractalType.RigidMulti);
}
public double f(double v) {
public double f(double v)
{
return (v / 2D) + 0.5D;
}
@Override
public double noise(double x) {
return f(n.GetSimplexFractal((float) x, 0f));
public double noise(double x)
{
return f(n.GetSimplexFractal(x, 0d));
}
@Override
public double noise(double x, double z) {
return f(n.GetSimplexFractal((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetSimplexFractal(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetSimplexFractal((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetSimplexFractal(x, y, z));
}
@Override
public void setOctaves(int o) {
public void setOctaves(int o)
{
n.setFractalOctaves(o);
}
}

View File

@ -1,32 +1,39 @@
package com.volmit.iris.noise;
public class GlobNoise implements NoiseGenerator {
private final FastNoise n;
import com.volmit.iris.util.RNG;
public GlobNoise(long seed) {
this.n = new FastNoise((int) seed);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.Distance2Div);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
public class GlobNoise implements NoiseGenerator
{
private final FastNoiseDouble n;
public GlobNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Div);
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
}
private double f(double n)
{
return n+1D;
return n + 1D;
}
@Override
public double noise(double x) {
return f(n.GetCellular((float) x, 0));
public double noise(double x)
{
return f(n.GetCellular(x, 0));
}
@Override
public double noise(double x, double z) {
return f(n.GetCellular((float) x, (float) z));
public double noise(double x, double z)
{
return f(n.GetCellular(x, z));
}
@Override
public double noise(double x, double y, double z) {
return f(n.GetCellular((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return f(n.GetCellular(x, y, z));
}
}

View File

@ -2,32 +2,37 @@ package com.volmit.iris.noise;
import com.volmit.iris.util.RNG;
public class PerlinNoise implements NoiseGenerator, OctaveNoise {
private final FastNoise n;
public class PerlinNoise implements NoiseGenerator, OctaveNoise
{
private final FastNoiseDouble n;
private int octaves;
public PerlinNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.setNoiseType(FastNoise.NoiseType.Perlin);
public PerlinNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
octaves = 1;
}
public double f(double v) {
public double f(double v)
{
return (v / 2D) + 0.5D;
}
@Override
public double noise(double x) {
if (octaves <= 1) {
return f(n.GetPerlin((float) x, 0f));
public double noise(double x)
{
if(octaves <= 1)
{
return f(n.GetPerlin(x, 0));
}
double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
v += n.GetPerlin((float) (x * (f == 1 ? f++ : (f *= 2))), 0f) * f;
for(int i = 0; i < octaves; i++)
{
v += n.GetPerlin((x * (f == 1 ? f++ : (f *= 2))), 0) * f;
m += f;
}
@ -35,17 +40,20 @@ public class PerlinNoise implements NoiseGenerator, OctaveNoise {
}
@Override
public double noise(double x, double z) {
if (octaves <= 1) {
return f(n.GetPerlin((float) x, (float) z));
public double noise(double x, double z)
{
if(octaves <= 1)
{
return f(n.GetPerlin(x, z));
}
double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
for(int i = 0; i < octaves; i++)
{
f = f == 1 ? f + 1 : f * 2;
v += n.GetPerlin((float) (x * f), (float) (z * f)) * f;
v += n.GetPerlin((x * f), (z * f)) * f;
m += f;
}
@ -53,17 +61,20 @@ public class PerlinNoise implements NoiseGenerator, OctaveNoise {
}
@Override
public double noise(double x, double y, double z) {
if (octaves <= 1) {
return f(n.GetPerlin((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
if(octaves <= 1)
{
return f(n.GetPerlin(x, y, z));
}
double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
for(int i = 0; i < octaves; i++)
{
f = f == 1 ? f + 1 : f * 2;
v += n.GetPerlin((float) (x * f), (float) (y * f), (float) (z * f)) * f;
v += n.GetPerlin((x * f), (y * f), (z * f)) * f;
m += f;
}
@ -71,7 +82,8 @@ public class PerlinNoise implements NoiseGenerator, OctaveNoise {
}
@Override
public void setOctaves(int o) {
public void setOctaves(int o)
{
octaves = o;
}
}

View File

@ -1,219 +0,0 @@
package com.volmit.iris.noise;
import java.util.function.Function;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.M;
import com.volmit.iris.util.RNG;
public class PolygonGenerator
{
private double[] rarity;
private CNG[] gen;
private int bits;
private int possibilities;
private boolean useRarity;
public PolygonGenerator(RNG rng, int possibilities, double scale, int octaves, Function<CNG, CNG> factory)
{
useRarity = false;
bits = 1;
this.possibilities = possibilities;
while(Math.pow(2, bits) <= possibilities)
{
bits++;
}
bits++;
bits = bits > 32 ? 32 : bits;
rarity = new double[possibilities];
gen = new CNG[bits];
for(int i = 0; i < bits; i++)
{
gen[i] = new CNG(rng.nextParallelRNG(2118 + (i * 3305)), 1D, 1).scale(scale / possibilities);
gen[i] = factory.apply(gen[i]);
}
}
public PolygonGenerator useRarity()
{
useRarity = true;
return this;
}
public void setRarity(int index, double r)
{
rarity[index] = 1D - Math.pow(0.5, r);
}
public boolean hasBorder(int checks, double distance, double... dims)
{
int current = getIndex(dims);
double ajump = 360D / (double) checks;
if(dims.length == 2)
{
for(int i = 0; i < checks; i++)
{
double dx = M.sin((float) Math.toRadians(ajump * i));
double dz = M.cos((float) Math.toRadians(ajump * i));
if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1]))
{
return true;
}
}
}
if(dims.length == 3)
{
for(int i = 0; i < checks; i++)
{
double dx = M.sin((float) Math.toRadians(ajump * i));
double dz = M.cos((float) Math.toRadians(ajump * i));
double dy = Math.tan(Math.toRadians(ajump * i));
if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2]))
{
return true;
}
}
}
return false;
}
public boolean hasBorder3D(int checks, double distance, double... dims)
{
int current = getIndex(dims);
double ajump = 360D / (double) checks;
int hit = -1;
if(dims.length == 3)
{
for(int i = 0; i < checks; i++)
{
double dx = M.sin((float) Math.toRadians(ajump * i));
double dz = M.cos((float) Math.toRadians(ajump * i));
double dy = Math.tan(Math.toRadians(ajump * i));
int d = getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2]);
if(current != d)
{
if(hit >= 0 && hit != current && hit != d)
{
return true;
}
if(hit < 0)
{
hit = d;
}
}
}
}
return false;
}
/**
* Returns 0.0 to 1.0 where 0.0 is directly on the border of another region and
* 1.0 is perfectly in the center of a region
*
* @param x
* the x
* @param z
* the z
* @return the closest neighbor threshold.
*/
public double getClosestNeighbor(double... dim)
{
double closest = 0.5;
for(int i = 0; i < gen.length; i++)
{
double distance = Math.abs(gen[i].noise(dim) - 0.5);
if(distance < closest)
{
closest = distance;
}
}
return (closest * 2);
}
public int getIndex(double... dim)
{
int data = 0;
int adjusted = 0;
double[] noise = new double[gen.length];
for(int i = 0; i < gen.length; i++)
{
data |= (noise[i] = gen[i].noise(dim)) > 0.5 ? i == 0 ? 1 : 1 << i : 0;
}
if(!useRarity)
{
return data % possibilities;
}
double r = rarity[data % possibilities];
for(int i = 0; i < gen.length; i++)
{
adjusted |= noise[i] > r ? i == 0 ? 1 : 1 << i : 0;
}
return adjusted % possibilities;
}
public static class EnumPolygonGenerator<T> extends PolygonGenerator
{
private T[] choices;
public EnumPolygonGenerator(RNG rng, double scale, int octaves, T[] choices, Function<CNG, CNG> factory)
{
super(rng, choices.length, scale / (double) choices.length, octaves, factory);
this.choices = choices;
}
public EnumPolygonGenerator<T> useRarity()
{
super.useRarity();
return this;
}
@SuppressWarnings("unchecked")
public EnumPolygonGenerator(RNG rng, double scale, int octaves, KList<T> c, KMap<T, Double> choiceRarities, Function<CNG, CNG> factory)
{
super(rng, choiceRarities.size(), scale / (double) choiceRarities.size(), octaves, factory);
this.choices = (T[]) c.toArray();
int m = 0;
for(T i : c)
{
setRarity(m++, choiceRarities.get(i));
}
}
public void setRarity(T t, double rarity)
{
for(int i = 0; i < choices.length; i++)
{
if(choices[i].equals(t))
{
setRarity(i, rarity);
return;
}
}
}
public T getChoice(double... dim)
{
return choices[getIndex(dim)];
}
}
}

View File

@ -2,32 +2,37 @@ package com.volmit.iris.noise;
import com.volmit.iris.util.RNG;
public class SimplexNoise implements NoiseGenerator, OctaveNoise {
private final FastNoise n;
public class SimplexNoise implements NoiseGenerator, OctaveNoise
{
private final FastNoiseDouble n;
private int octaves;
public SimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.setNoiseType(FastNoise.NoiseType.Simplex);
public SimplexNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
octaves = 1;
}
public double f(double v) {
public double f(double v)
{
return (v / 2D) + 0.5D;
}
@Override
public double noise(double x) {
if (octaves <= 1) {
return f(n.GetNoise((float) x, 0f));
public double noise(double x)
{
if(octaves <= 1)
{
return f(n.GetSimplex(x, 0d));
}
double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
v += n.GetNoise((float) (x * (f == 1 ? f++ : (f *= 2))), 0f) * f;
for(int i = 0; i < octaves; i++)
{
v += n.GetSimplex((x * (f == 1 ? f++ : (f *= 2))), 0d) * f;
m += f;
}
@ -35,17 +40,20 @@ public class SimplexNoise implements NoiseGenerator, OctaveNoise {
}
@Override
public double noise(double x, double z) {
if (octaves <= 1) {
return f(n.GetNoise((float) x, (float) z));
public double noise(double x, double z)
{
if(octaves <= 1)
{
return f(n.GetSimplex(x, z));
}
double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
for(int i = 0; i < octaves; i++)
{
f = f == 1 ? f + 1 : f * 2;
v += n.GetNoise((float) (x * f), (float) (z * f)) * f;
v += n.GetSimplex((x * f), (z * f)) * f;
m += f;
}
@ -53,17 +61,20 @@ public class SimplexNoise implements NoiseGenerator, OctaveNoise {
}
@Override
public double noise(double x, double y, double z) {
if (octaves <= 1) {
return f(n.GetNoise((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
if(octaves <= 1)
{
return f(n.GetSimplex(x, y, z));
}
double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
for(int i = 0; i < octaves; i++)
{
f = f == 1 ? f + 1 : f * 2;
v += n.GetNoise((float) (x * f), (float) (y * f), (float) (z * f)) * f;
v += n.GetSimplex((x * f), (y * f), (z * f)) * f;
m += f;
}
@ -71,7 +82,8 @@ public class SimplexNoise implements NoiseGenerator, OctaveNoise {
}
@Override
public void setOctaves(int o) {
public void setOctaves(int o)
{
octaves = o;
}
}

View File

@ -1,33 +1,40 @@
package com.volmit.iris.noise;
import com.volmit.iris.util.M;
import com.volmit.iris.util.RNG;
public class VascularNoise implements NoiseGenerator {
private final FastNoise n;
public class VascularNoise implements NoiseGenerator
{
private final FastNoiseDouble n;
public VascularNoise(long seed) {
this.n = new FastNoise((int) seed);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
public VascularNoise(long seed)
{
this.n = new FastNoiseDouble(new RNG(seed).lmax());
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Sub);
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
}
private double filter(double noise) {
private double filter(double noise)
{
return M.clip((noise / 2D) + 0.5D, 0D, 1D);
}
@Override
public double noise(double x) {
return filter(n.GetCellular((float) x, 0));
public double noise(double x)
{
return filter(n.GetCellular(x, 0));
}
@Override
public double noise(double x, double z) {
return filter(n.GetCellular((float) x, (float) z));
public double noise(double x, double z)
{
return filter(n.GetCellular(x, z));
}
@Override
public double noise(double x, double y, double z) {
return filter(n.GetCellular((float) x, (float) y, (float) z));
public double noise(double x, double y, double z)
{
return filter(n.GetCellular(x, y, z));
}
}

View File

@ -1,12 +1,14 @@
package com.volmit.iris.noise;
import com.volmit.iris.util.RNG;
public class WhiteNoise implements NoiseGenerator
{
private final FastNoise n;
private final FastNoiseDouble n;
public WhiteNoise(long seed)
{
n = new FastNoise((int) seed);
n = new FastNoiseDouble(new RNG(seed).lmax());
}
private double f(double m)
@ -17,18 +19,18 @@ public class WhiteNoise implements NoiseGenerator
@Override
public double noise(double x)
{
return (n.DGetWhiteNoise(f(x), 0d) / 2D) + 0.5D;
return (n.GetWhiteNoise(f(x), 0d) / 2D) + 0.5D;
}
@Override
public double noise(double x, double z)
{
return (n.DGetWhiteNoise(f(x), f(z)) / 2D) + 0.5D;
return (n.GetWhiteNoise(f(x), f(z)) / 2D) + 0.5D;
}
@Override
public double noise(double x, double y, double z)
{
return (n.DGetWhiteNoise(f(x), f(y), f(z)) / 2D) + 0.5D;
return (n.GetWhiteNoise(f(x), f(y), f(z)) / 2D) + 0.5D;
}
}

View File

@ -1,6 +1,5 @@
package com.volmit.iris.object;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.util.BlockVector;
@ -203,15 +202,27 @@ public class IrisDepositGenerator
continue;
}
BlockData b = data.getBlockData(nx, ny, nz);
boolean allow = true;
if(b.getMaterial().equals(Material.ICE) || b.getMaterial().equals(Material.PACKED_ICE) || b.getMaterial().equals(B.mat("BLUE_ICE")) || b.getMaterial().equals(B.mat("FROSTED_ICE")) || b.getMaterial().equals(Material.SAND) || b.getMaterial().equals(Material.RED_SAND) || !B.isSolid(b.getMaterial()))
if(g.getDimension().isVanillaCaves())
{
continue;
allow = false;
BlockData b = data.getBlockData(nx, ny, nz);
for(BlockData f : g.getDimension().getRockData())
{
if(f.getMaterial().equals(b.getMaterial()))
{
allow = true;
break;
}
}
}
if(allow)
{
data.setBlock(nx, ny, nz, clump.getBlocks().get(j));
}
}
}
}
}