This commit is contained in:
Daniel Mills
2020-07-21 02:25:36 -04:00
parent aa168fab8c
commit 921e5912b3
10 changed files with 206 additions and 5 deletions
@@ -54,7 +54,6 @@ import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.format.Form; import ninja.bytecode.shuriken.format.Form;
import ninja.bytecode.shuriken.json.JSONException; import ninja.bytecode.shuriken.json.JSONException;
import ninja.bytecode.shuriken.json.JSONObject; import ninja.bytecode.shuriken.json.JSONObject;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.RollingSequence; import ninja.bytecode.shuriken.math.RollingSequence;
import ninja.bytecode.shuriken.reaction.O; import ninja.bytecode.shuriken.reaction.O;
import ninja.bytecode.shuriken.tools.JarScanner; import ninja.bytecode.shuriken.tools.JarScanner;
@@ -63,7 +63,7 @@ public class IrisChunkGenerator extends ParallaxChunkGenerator implements IrisCo
@Override @Override
protected void onChunkLoaded(Chunk c) protected void onChunkLoaded(Chunk c)
{ {
// TODO: updateLights(); better updateLights();
} }
@Override @Override
@@ -120,8 +120,9 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
@Override @Override
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap)
{ {
super.onPostGenerate(random, x, z, data, grid, height, biomeMap);
biomeHitCache.clear(); biomeHitCache.clear();
if(getDimension().isPlaceObjects()) if(getDimension().isPlaceObjects())
{ {
onGenerateParallax(random, x, z); onGenerateParallax(random, x, z);
@@ -11,6 +11,7 @@ import org.bukkit.block.data.BlockData;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import ninja.bytecode.iris.layer.GenLayerCave;
import ninja.bytecode.iris.object.IrisBiome; import ninja.bytecode.iris.object.IrisBiome;
import ninja.bytecode.iris.object.IrisBiomeDecorator; import ninja.bytecode.iris.object.IrisBiomeDecorator;
import ninja.bytecode.iris.object.IrisRegion; import ninja.bytecode.iris.object.IrisRegion;
@@ -18,6 +19,7 @@ import ninja.bytecode.iris.object.atomics.AtomicSliver;
import ninja.bytecode.iris.util.BiomeMap; import ninja.bytecode.iris.util.BiomeMap;
import ninja.bytecode.iris.util.BiomeResult; import ninja.bytecode.iris.util.BiomeResult;
import ninja.bytecode.iris.util.BlockPosition; import ninja.bytecode.iris.util.BlockPosition;
import ninja.bytecode.iris.util.HeightMap;
import ninja.bytecode.iris.util.RNG; import ninja.bytecode.iris.util.RNG;
import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.math.M; import ninja.bytecode.shuriken.math.M;
@@ -33,6 +35,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
private ReentrantLock relightLock = new ReentrantLock(); private ReentrantLock relightLock = new ReentrantLock();
private long lastUpdateRequest = M.ms(); private long lastUpdateRequest = M.ms();
private long lastChunkLoad = M.ms(); private long lastChunkLoad = M.ms();
private GenLayerCave glCaves;
public TerrainChunkGenerator(String dimensionName, int threads) public TerrainChunkGenerator(String dimensionName, int threads)
{ {
@@ -42,6 +45,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
public void onInit(World world, RNG rng) public void onInit(World world, RNG rng)
{ {
super.onInit(world, rng); super.onInit(world, rng);
glCaves = new GenLayerCave(this, rng);
} }
public void queueUpdate(int x, int y, int z) public void queueUpdate(int x, int y, int z)
@@ -215,14 +219,14 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
if(stack == 1) if(stack == 1)
{ {
sliver.set(k + 1, d); sliver.setSilently(k + 1, d);
} }
else if(k < 255 - stack) else if(k < 255 - stack)
{ {
for(int l = 0; l < stack; l++) for(int l = 0; l < stack; l++)
{ {
sliver.set(k + l + 1, d); sliver.setSilently(k + l + 1, d);
} }
} }
} }
@@ -240,6 +244,18 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
} }
@Override
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap)
{
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
glCaves.genCaves((x << 4) + i, (z << 4) + j, i, j, data, height);
}
}
}
protected double getNoiseHeight(int rx, int rz) protected double getNoiseHeight(int rx, int rz)
{ {
double wx = getZoomed(rx); double wx = getZoomed(rx);
@@ -0,0 +1,114 @@
package ninja.bytecode.iris.layer;
import org.bukkit.Material;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import ninja.bytecode.iris.generator.DimensionChunkGenerator;
import ninja.bytecode.iris.util.Borders;
import ninja.bytecode.iris.util.CNG;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.iris.util.HeightMap;
import ninja.bytecode.iris.util.PolygonGenerator;
import ninja.bytecode.iris.util.RNG;
public class GenLayerCave extends GenLayer
{
private PolygonGenerator g;
private CNG gincline;
public GenLayerCave(DimensionChunkGenerator iris, RNG rng)
{
//@builder
super(iris, rng);
g = new PolygonGenerator(rng.nextParallelRNG(1111), 3, 0.024, 8, (c) -> c);
gincline = new CNG(rng.nextParallelRNG(1112), 1D, 3).scale(0.00652);
//@done
}
public void genCaves(double wxxf, double wzxf, int x, int z, ChunkData data, HeightMap height)
{
if(!iris.getDimension().isCaves())
{
return;
}
double itr = 2;
double level = 8;
double incline = 157;
double baseWidth = 16 * iris.getDimension().getCaveScale();
double drop = 44 + iris.getDimension().getCaveShift();
for(double m = 1; m <= itr; m += 0.45)
{
double w = baseWidth / m;
if(w < 5)
{
break;
}
int lowest = 325;
double n = incline * gincline.noise((wxxf + (m * 10000)), (wzxf - (m * 10000)));
for(double i = 1; i <= w / 3D; i++)
{
if(Borders.isBorderWithin((wxxf + (m * 10000)), (wzxf - (m * 10000)), 32, w / 2D / i, (wxxf / 3D) + (wzxf / 3D), (xx, zz) -> g.getIndex(xx, zz)))
{
int h = (int) ((level + n) - drop);
if(dig(x, (int) (h + i), z, data) && h + i < lowest)
{
lowest = (int) (h + i);
}
if(dig(x, (int) (h - i), z, data) && h - i < lowest)
{
lowest = (int) (h - i);
}
if(i == 1)
{
if(dig(x, (int) (h), z, data) && h < lowest)
{
lowest = (int) (h);
}
}
}
}
}
}
public boolean dig(int x, int y, int z, ChunkData data)
{
Material a = data.getType(x, y, z);
Material b = data.getType(x, y, z + 1);
Material c = data.getType(x, y + 1, z);
Material d = data.getType(x + 1, y, z);
Material e = data.getType(x, y, z - 1);
Material f = data.getType(x, y - 1, z);
Material g = data.getType(x - 1, y, z);
if(can(a) && cann(b) && cann(c) && cann(d) && cann(e) && cann(f) && cann(g))
{
data.setBlock(x, y, z, Material.AIR);
return true;
}
return false;
}
public boolean cann(Material m)
{
return m.isSolid() || m.equals(Material.AIR) && !m.equals(Material.BEDROCK);
}
public boolean can(Material m)
{
return m.isSolid() && !m.equals(Material.BEDROCK);
}
@Override
public double generate(double x, double z)
{
return 0;
}
}
@@ -23,6 +23,11 @@ public class IrisDimension extends IrisRegistrant
@Desc("The interpolation distance scale. Increase = more smooth, less detail") @Desc("The interpolation distance scale. Increase = more smooth, less detail")
private double interpolationScale = 63; private double interpolationScale = 63;
private double caveThickness = 1D;
private double caveScale = 1D;
private double caveShift = 0D;
private boolean caves = true;
@Desc("The world environment") @Desc("The world environment")
private Environment environment = Environment.NORMAL; private Environment environment = Environment.NORMAL;
@@ -44,6 +44,16 @@ public class AtomicSliver
highestBlock = h > highestBlock ? h : highestBlock; highestBlock = h > highestBlock ? h : highestBlock;
} }
public void setSilently(int h, BlockData d)
{
if(d == null)
{
return;
}
block.put(h, d);
}
public void set(int h, Biome d) public void set(int h, Biome d)
{ {
biome.put(h, d); biome.put(h, d);
@@ -0,0 +1,7 @@
package ninja.bytecode.iris.util;
@FunctionalInterface
public interface BorderCheck<T>
{
public T get(double x, double z);
}
@@ -0,0 +1,44 @@
package ninja.bytecode.iris.util;
import ninja.bytecode.shuriken.math.M;
public class Borders
{
public static <T> double getDistanceToBorder(double x, double z, int samples, double minRadius, double maxRadius, double jump, BorderCheck<T> check)
{
double offset = 0;
double fract = 1;
for(double i = minRadius; i < maxRadius; i += jump * fract)
{
offset += jump / 3D;
fract += 0.333;
if(isBorderWithin(x, z, samples, maxRadius, offset, check))
{
return minRadius;
}
}
return maxRadius;
}
public static <T> boolean isBorderWithin(double x, double z, int samples, double radius, double offset, BorderCheck<T> check)
{
T center = check.get(x, z);
double ajump = Math.toRadians(360D / (double) samples) + offset;
for(int i = 0; i < samples; i++)
{
double dx = M.sin((float) ajump * i) * radius;
double dz = M.cos((float) ajump * i) * radius;
if(!center.equals(check.get(x + dx, z + dz)))
{
return true;
}
}
return false;
}
}
@@ -42,6 +42,11 @@ public class CellGenerator
return ((fd.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle)))) + 1f) / 2f; return ((fd.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle)))) + 1f) / 2f;
} }
public float 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;
}
public float getValue(double x, double z, int possibilities) public float getValue(double x, double z, int possibilities)
{ {
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((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);