This commit is contained in:
Daniel Mills 2020-01-25 17:20:32 -05:00
parent 58558732be
commit b49c1e6e47
7 changed files with 396 additions and 50 deletions

View File

@ -42,7 +42,7 @@ public class Settings
public double heightScale = 0.56; public double heightScale = 0.56;
public double baseHeight = 0.065; public double baseHeight = 0.065;
public int seaLevel = 63; public int seaLevel = 63;
public double biomeScale = 1; public double biomeScale = 0.5;
public boolean flatBedrock = false; public boolean flatBedrock = false;
} }
} }

View File

@ -19,6 +19,7 @@ import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.generator.genobject.GenObjectDecorator; import ninja.bytecode.iris.generator.genobject.GenObjectDecorator;
import ninja.bytecode.iris.generator.genobject.PlacedObject; import ninja.bytecode.iris.generator.genobject.PlacedObject;
import ninja.bytecode.iris.generator.layer.GenLayerBiome; import ninja.bytecode.iris.generator.layer.GenLayerBiome;
import ninja.bytecode.iris.generator.layer.GenLayerCaves;
import ninja.bytecode.iris.generator.layer.GenLayerCliffs; import ninja.bytecode.iris.generator.layer.GenLayerCliffs;
import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise; import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise;
import ninja.bytecode.iris.generator.layer.GenLayerSnow; import ninja.bytecode.iris.generator.layer.GenLayerSnow;
@ -50,14 +51,15 @@ public class IrisGenerator extends ParallaxWorldGenerator
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE, 5), MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5), MB.of(Material.STONE, 5),
MB.of(Material.COBBLESTONE), MB.of(Material.STONE, 5),
MB.of(Material.COBBLESTONE), MB.of(Material.STONE, 5),
MB.of(Material.SMOOTH_BRICK), MB.of(Material.STONE, 5),
MB.of(Material.SMOOTH_BRICK, 1), MB.of(Material.STONE, 5)
MB.of(Material.SMOOTH_BRICK, 2),
MB.of(Material.SMOOTH_BRICK, 3),
}); });
//@done //@done
private boolean disposed; private boolean disposed;
@ -70,6 +72,7 @@ public class IrisGenerator extends ParallaxWorldGenerator
private GenLayerBiome glBiome; private GenLayerBiome glBiome;
private GenLayerSnow glSnow; private GenLayerSnow glSnow;
private GenLayerCliffs glCliffs; private GenLayerCliffs glCliffs;
private GenLayerCaves glCaves;
private RNG rTerrain; private RNG rTerrain;
private CompiledDimension dim; private CompiledDimension dim;
private IrisMetrics metrics = new IrisMetrics(0, 512); private IrisMetrics metrics = new IrisMetrics(0, 512);
@ -125,6 +128,7 @@ public class IrisGenerator extends ParallaxWorldGenerator
glBiome = new GenLayerBiome(this, world, random, rTerrain.nextParallelRNG(4), dim.getBiomes()); glBiome = new GenLayerBiome(this, world, random, rTerrain.nextParallelRNG(4), dim.getBiomes());
glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5)); glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5));
glCliffs = new GenLayerCliffs(this, world, random, rTerrain.nextParallelRNG(9)); glCliffs = new GenLayerCliffs(this, world, random, rTerrain.nextParallelRNG(9));
glCaves = new GenLayerCaves(this, world, random, rTerrain.nextParallelRNG(10));
scatter = new CNG(rTerrain.nextParallelRNG(52), 1, 1).scale(10); scatter = new CNG(rTerrain.nextParallelRNG(52), 1, 1).scale(10);
if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX)) if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX))
@ -378,6 +382,7 @@ public class IrisGenerator extends ParallaxWorldGenerator
hl = hl == 0 && !t.equals(Material.AIR) ? i : hl; hl = hl == 0 && !t.equals(Material.AIR) ? i : hl;
} }
glCaves.genCaves(wxxf, wzxf, x, z, data, plan);
plan.setRealHeight(x, z, hl); plan.setRealHeight(x, z, hl);
plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw); plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw);
plan.setBiome(x, z, biome); plan.setBiome(x, z, biome);
@ -394,9 +399,9 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
int x = 0; int x = 0;
int z = 0; int z = 0;
int h = 0; int hhx = 0;
int v = 0; int v = 0;
int border = 0; int borderh = 0;
int above = 0; int above = 0;
int below = 0; int below = 0;
@ -406,20 +411,20 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
for(z = 0; z < 16; z++) for(z = 0; z < 16; z++)
{ {
h = plan.getRealHeight(x, z); hhx = plan.getRealHeight(x, z);
border = 0; borderh = 0;
if(x == 0 || x == 15) if(x == 0 || x == 15)
{ {
border++; borderh++;
} }
if(z == 0 || z == 15) if(z == 0 || z == 15)
{ {
border++; borderh++;
} }
if(h > Iris.settings.gen.seaLevel - 2) if(hhx > Iris.settings.gen.seaLevel - 2)
{ {
above = 0; above = 0;
below = 0; below = 0;
@ -428,12 +433,12 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
v = plan.getRealHeight(x + 1, z); v = plan.getRealHeight(x + 1, z);
if(v > h) if(v > hhx)
{ {
above++; above++;
} }
else if(v < h) else if(v < hhx)
{ {
below++; below++;
} }
@ -443,12 +448,12 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
v = plan.getRealHeight(x - 1, z); v = plan.getRealHeight(x - 1, z);
if(v > h) if(v > hhx)
{ {
above++; above++;
} }
else if(v < h) else if(v < hhx)
{ {
below++; below++;
} }
@ -458,12 +463,12 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
v = plan.getRealHeight(x, z + 1); v = plan.getRealHeight(x, z + 1);
if(v > h) if(v > hhx)
{ {
above++; above++;
} }
else if(v < h) else if(v < hhx)
{ {
below++; below++;
} }
@ -473,63 +478,201 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
v = plan.getRealHeight(x, z - 1); v = plan.getRealHeight(x, z - 1);
if(v > h) if(v > hhx)
{ {
above++; above++;
} }
else if(v < h) else if(v < hhx)
{ {
below++; below++;
} }
} }
// Patch Hole // Patch Hole
if(above >= 4 - border) if(above >= 4 - borderh)
{ {
data.setBlock(x, h + 1, z, data.getMB(x, h, z)); data.setBlock(x, hhx + 1, z, data.getMB(x, hhx, z));
plan.setRealHeight(x, z, h + 1); plan.setRealHeight(x, z, hhx + 1);
} }
// Remove Nipple // Remove Nipple
else if(below >= 4 - border) else if(below >= 4 - borderh)
{ {
data.setBlock(x, h - 1, z, data.getMB(x, h, z)); data.setBlock(x, hhx - 1, z, data.getMB(x, hhx, z));
data.setBlock(x, h, z, Material.AIR); data.setBlock(x, hhx, z, Material.AIR);
plan.setRealHeight(x, z, h - 1); plan.setRealHeight(x, z, hhx - 1);
} }
// Slab Smoothing // Slab Smoothing
else if(below == 0 && above > 0 && f == Iris.settings.gen.blockSmoothing - 1) else if(below == 0 && above > 0 && f == Iris.settings.gen.blockSmoothing - 1)
{ {
MB d = data.getMB(x, h, z); MB d = data.getMB(x, hhx, z);
if(d.material.equals(Material.STAINED_CLAY) && d.data == 1) if(d.material.equals(Material.STAINED_CLAY) && d.data == 1)
{ {
data.setBlock(x, h + 1, z, Material.STONE_SLAB2); data.setBlock(x, hhx + 1, z, Material.STONE_SLAB2);
} }
else if(d.material.equals(Material.SAND)) else if(d.material.equals(Material.SAND))
{ {
if(d.data == 0) if(d.data == 0)
{ {
data.setBlock(x, h + 1, z, Material.STEP, (byte) 1); data.setBlock(x, hhx + 1, z, Material.STEP, (byte) 1);
} }
if(d.data == 1) if(d.data == 1)
{ {
data.setBlock(x, h + 1, z, Material.STONE_SLAB2); data.setBlock(x, hhx + 1, z, Material.STONE_SLAB2);
} }
} }
else if(d.material.equals(Material.SNOW_BLOCK)) else if(d.material.equals(Material.SNOW_BLOCK))
{ {
data.setBlock(x, h + 1, z, Material.SNOW, (byte) 4); data.setBlock(x, hhx + 1, z, Material.SNOW, (byte) 4);
} }
else if(d.material.equals(Material.STONE) || d.material.equals(Material.COBBLESTONE) || d.material.equals(Material.GRAVEL)) else if(d.material.equals(Material.STONE) || d.material.equals(Material.COBBLESTONE) || d.material.equals(Material.GRAVEL))
{ {
data.setBlock(x, h + 1, z, Material.STEP, (byte) 3); data.setBlock(x, hhx + 1, z, Material.STEP, (byte) 3);
}
}
}
KList<Integer> hs = plan.getCaveHeights(x, z);
if(hs != null && !hs.isEmpty())
{
int h = 0;
int border = 0;
for(int hx : hs)
{
h = hx - 1;
border = 0;
if(x == 0 || x == 15)
{
border++;
}
if(z == 0 || z == 15)
{
border++;
}
if(h > 1)
{
above = 0;
below = 0;
if(x + 1 <= 15)
{
v = plan.getRealHeight(x + 1, z);
if(v > h)
{
above++;
}
else if(v < h)
{
below++;
}
}
if(x - 1 >= 0)
{
v = plan.getRealHeight(x - 1, z);
if(v > h)
{
above++;
}
else if(v < h)
{
below++;
}
}
if(z + 1 <= 15)
{
v = plan.getRealHeight(x, z + 1);
if(v > h)
{
above++;
}
else if(v < h)
{
below++;
}
}
if(z - 1 >= 0)
{
v = plan.getRealHeight(x, z - 1);
if(v > h)
{
above++;
}
else if(v < h)
{
below++;
}
}
// Patch Hole
if(above >= 4 - border)
{
data.setBlock(x, h + 1, z, data.getMB(x, h, z));
plan.setRealHeight(x, z, h + 1);
}
// Remove Nipple
else if(below >= 4 - border)
{
data.setBlock(x, h - 1, z, data.getMB(x, h, z));
data.setBlock(x, h, z, Material.AIR);
plan.setRealHeight(x, z, h - 1);
}
// Slab Smoothing
else if(below == 0 && above > 0 && f == Iris.settings.gen.blockSmoothing - 1)
{
MB d = data.getMB(x, h, z);
if(d.material.equals(Material.STAINED_CLAY) && d.data == 1)
{
data.setBlock(x, h + 1, z, Material.STONE_SLAB2);
}
else if(d.material.equals(Material.SAND))
{
if(d.data == 0)
{
data.setBlock(x, h + 1, z, Material.STEP, (byte) 1);
}
if(d.data == 1)
{
data.setBlock(x, h + 1, z, Material.STONE_SLAB2);
}
}
else if(d.material.equals(Material.SNOW_BLOCK))
{
data.setBlock(x, h + 1, z, Material.SNOW, (byte) 4);
}
else if(d.material.equals(Material.STONE) || d.material.equals(Material.SMOOTH_BRICK) || d.material.equals(Material.COBBLESTONE) || d.material.equals(Material.GRAVEL))
{
data.setBlock(x, h + 1, z, Material.STEP, (byte) 5);
}
}
} }
} }
} }

View File

@ -0,0 +1,121 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.Borders;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.iris.util.PolygonGenerator;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerCaves extends GenLayer
{
private PolygonGenerator g;
private CNG gincline;
private CNG gfract;
public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
g = new PolygonGenerator(RNG.r, 3, 0.014, 1, (c) -> c);
gincline = new CNG(RNG.r, 1D, 3).scale(0.00652);
gfract = new CNG(RNG.r, 24D, 1).scale(0.0152);
//@done
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return gnoise;
}
public void genCaves(double xxf, double zzf, int x, int z, AtomicChunkData data, ChunkPlan plan)
{
int wxxf = (int) (xxf + gfract.noise(xxf, zzf));
int wzxf = (int) (zzf - gfract.noise(zzf, xxf));
double itr = 2;
double level = 8;
double incline = 157;
double baseWidth = 11;
double drop = 35;
for(double m = 1; m <= itr; m += 0.65)
{
double w = baseWidth / m;
if(w < 3.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)), 17, 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);
}
}
}
}
if(lowest < 256)
{
plan.setCaveHeight(x, z, lowest);
}
}
}
public boolean dig(int x, int y, int z, AtomicChunkData 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);
}
public boolean can(Material m)
{
return m.isSolid();
}
}

View File

@ -130,10 +130,10 @@ public class IrisBiome
cliffScale = 1; cliffScale = 1;
cliffChance = 0.37; cliffChance = 0.37;
parent = ""; parent = "";
dirtDepth = 2; dirtDepth = 19;
this.realBiome = realBiome; this.realBiome = realBiome;
this.height = IDEAL_HEIGHT; this.height = IDEAL_HEIGHT;
rockDepth = 11; rockDepth = 23;
surfaceScale = 1; surfaceScale = 1;
subSurfaceScale = 1; subSurfaceScale = 1;
rockScale = 1; rockScale = 1;
@ -147,19 +147,21 @@ public class IrisBiome
surface(new MB(Material.GRASS)) surface(new MB(Material.GRASS))
.dirt(new MB(Material.DIRT), new MB(Material.DIRT, 1)) .dirt(new MB(Material.DIRT), new MB(Material.DIRT, 1))
.rock(MB.of(Material.STONE), .rock(MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE), MB.of(Material.STONE),
MB.of(Material.STONE, 5), MB.of(Material.STONE),
MB.of(Material.STONE, 5), MB.of(Material.STONE),
MB.of(Material.COBBLESTONE), MB.of(Material.STONE),
MB.of(Material.COBBLESTONE), MB.of(Material.STONE),
MB.of(Material.SMOOTH_BRICK), MB.of(Material.STONE, 5),
MB.of(Material.SMOOTH_BRICK, 1), MB.of(Material.STONE, 5),
MB.of(Material.SMOOTH_BRICK, 2), MB.of(Material.STONE, 5),
MB.of(Material.SMOOTH_BRICK, 3)); MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5));
//@done //@done
} }

View File

@ -0,0 +1,7 @@
package ninja.bytecode.iris.util;
@FunctionalInterface
public interface BorderCheck<T>
{
public T get(double x, double z);
}

View File

@ -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;
}
}

View File

@ -1,17 +1,20 @@
package ninja.bytecode.iris.util; package ninja.bytecode.iris.util;
import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap; import ninja.bytecode.shuriken.collections.KMap;
public class ChunkPlan public class ChunkPlan
{ {
private final KMap<SChunkVector, Integer> realHeightCache; private final KMap<SChunkVector, Integer> realHeightCache;
private final KMap<SChunkVector, KList<Integer>> caveHeightCache;
private final KMap<SChunkVector, Integer> realWaterHeightCache; private final KMap<SChunkVector, Integer> realWaterHeightCache;
private final KMap<SChunkVector, Double> heightCache; private final KMap<SChunkVector, Double> heightCache;
private final KMap<SChunkVector, IrisBiome> biomeCache; private final KMap<SChunkVector, IrisBiome> biomeCache;
public ChunkPlan() public ChunkPlan()
{ {
this.caveHeightCache = new KMap<>();
this.realHeightCache = new KMap<>(); this.realHeightCache = new KMap<>();
this.realWaterHeightCache = new KMap<>(); this.realWaterHeightCache = new KMap<>();
this.heightCache = new KMap<>(); this.heightCache = new KMap<>();
@ -50,6 +53,17 @@ public class ChunkPlan
return 0; return 0;
} }
public KList<Integer> getCaveHeights(int x, int z)
{
SChunkVector c = new SChunkVector(x, z);
if(caveHeightCache.containsKey(c))
{
return caveHeightCache.get(c);
}
return null;
}
public int getRealWaterHeight(int x, int z) public int getRealWaterHeight(int x, int z)
{ {
SChunkVector c = new SChunkVector(x, z); SChunkVector c = new SChunkVector(x, z);
@ -77,6 +91,16 @@ public class ChunkPlan
heightCache.put(c, h); heightCache.put(c, h);
} }
public void setCaveHeight(SChunkVector c, int h)
{
if(!caveHeightCache.containsKey(c))
{
caveHeightCache.put(c, new KList<>());
}
caveHeightCache.get(c).add(h);
}
public void setRealHeight(SChunkVector c, int h) public void setRealHeight(SChunkVector c, int h)
{ {
realHeightCache.put(c, h); realHeightCache.put(c, h);
@ -87,6 +111,11 @@ public class ChunkPlan
setRealHeight(new SChunkVector(x, z), h); setRealHeight(new SChunkVector(x, z), h);
} }
public void setCaveHeight(int x, int z, int h)
{
setCaveHeight(new SChunkVector(x, z), h);
}
public void setRealWaterHeight(SChunkVector c, int h) public void setRealWaterHeight(SChunkVector c, int h)
{ {
realWaterHeightCache.put(c, h); realWaterHeightCache.put(c, h);