mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Caves
This commit is contained in:
parent
58558732be
commit
b49c1e6e47
@ -42,7 +42,7 @@ public class Settings
|
||||
public double heightScale = 0.56;
|
||||
public double baseHeight = 0.065;
|
||||
public int seaLevel = 63;
|
||||
public double biomeScale = 1;
|
||||
public double biomeScale = 0.5;
|
||||
public boolean flatBedrock = false;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObjectDecorator;
|
||||
import ninja.bytecode.iris.generator.genobject.PlacedObject;
|
||||
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.GenLayerLayeredNoise;
|
||||
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, 5),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.COBBLESTONE),
|
||||
MB.of(Material.COBBLESTONE),
|
||||
MB.of(Material.SMOOTH_BRICK),
|
||||
MB.of(Material.SMOOTH_BRICK, 1),
|
||||
MB.of(Material.SMOOTH_BRICK, 2),
|
||||
MB.of(Material.SMOOTH_BRICK, 3),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5)
|
||||
});
|
||||
//@done
|
||||
private boolean disposed;
|
||||
@ -70,6 +72,7 @@ public class IrisGenerator extends ParallaxWorldGenerator
|
||||
private GenLayerBiome glBiome;
|
||||
private GenLayerSnow glSnow;
|
||||
private GenLayerCliffs glCliffs;
|
||||
private GenLayerCaves glCaves;
|
||||
private RNG rTerrain;
|
||||
private CompiledDimension dim;
|
||||
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());
|
||||
glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5));
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
glCaves.genCaves(wxxf, wzxf, x, z, data, plan);
|
||||
plan.setRealHeight(x, z, hl);
|
||||
plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw);
|
||||
plan.setBiome(x, z, biome);
|
||||
@ -394,9 +399,9 @@ public class IrisGenerator extends ParallaxWorldGenerator
|
||||
{
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
int h = 0;
|
||||
int hhx = 0;
|
||||
int v = 0;
|
||||
int border = 0;
|
||||
int borderh = 0;
|
||||
int above = 0;
|
||||
int below = 0;
|
||||
|
||||
@ -406,7 +411,143 @@ public class IrisGenerator extends ParallaxWorldGenerator
|
||||
{
|
||||
for(z = 0; z < 16; z++)
|
||||
{
|
||||
h = plan.getRealHeight(x, z);
|
||||
hhx = plan.getRealHeight(x, z);
|
||||
borderh = 0;
|
||||
|
||||
if(x == 0 || x == 15)
|
||||
{
|
||||
borderh++;
|
||||
}
|
||||
|
||||
if(z == 0 || z == 15)
|
||||
{
|
||||
borderh++;
|
||||
}
|
||||
|
||||
if(hhx > Iris.settings.gen.seaLevel - 2)
|
||||
{
|
||||
above = 0;
|
||||
below = 0;
|
||||
|
||||
if(x + 1 <= 15)
|
||||
{
|
||||
v = plan.getRealHeight(x + 1, z);
|
||||
|
||||
if(v > hhx)
|
||||
{
|
||||
above++;
|
||||
}
|
||||
|
||||
else if(v < hhx)
|
||||
{
|
||||
below++;
|
||||
}
|
||||
}
|
||||
|
||||
if(x - 1 >= 0)
|
||||
{
|
||||
v = plan.getRealHeight(x - 1, z);
|
||||
|
||||
if(v > hhx)
|
||||
{
|
||||
above++;
|
||||
}
|
||||
|
||||
else if(v < hhx)
|
||||
{
|
||||
below++;
|
||||
}
|
||||
}
|
||||
|
||||
if(z + 1 <= 15)
|
||||
{
|
||||
v = plan.getRealHeight(x, z + 1);
|
||||
|
||||
if(v > hhx)
|
||||
{
|
||||
above++;
|
||||
}
|
||||
|
||||
else if(v < hhx)
|
||||
{
|
||||
below++;
|
||||
}
|
||||
}
|
||||
|
||||
if(z - 1 >= 0)
|
||||
{
|
||||
v = plan.getRealHeight(x, z - 1);
|
||||
|
||||
if(v > hhx)
|
||||
{
|
||||
above++;
|
||||
}
|
||||
|
||||
else if(v < hhx)
|
||||
{
|
||||
below++;
|
||||
}
|
||||
}
|
||||
|
||||
// Patch Hole
|
||||
if(above >= 4 - borderh)
|
||||
{
|
||||
data.setBlock(x, hhx + 1, z, data.getMB(x, hhx, z));
|
||||
plan.setRealHeight(x, z, hhx + 1);
|
||||
}
|
||||
|
||||
// Remove Nipple
|
||||
else if(below >= 4 - borderh)
|
||||
{
|
||||
data.setBlock(x, hhx - 1, z, data.getMB(x, hhx, z));
|
||||
data.setBlock(x, hhx, z, Material.AIR);
|
||||
plan.setRealHeight(x, z, hhx - 1);
|
||||
}
|
||||
|
||||
// Slab Smoothing
|
||||
else if(below == 0 && above > 0 && f == Iris.settings.gen.blockSmoothing - 1)
|
||||
{
|
||||
MB d = data.getMB(x, hhx, z);
|
||||
|
||||
if(d.material.equals(Material.STAINED_CLAY) && d.data == 1)
|
||||
{
|
||||
data.setBlock(x, hhx + 1, z, Material.STONE_SLAB2);
|
||||
}
|
||||
|
||||
else if(d.material.equals(Material.SAND))
|
||||
{
|
||||
if(d.data == 0)
|
||||
{
|
||||
data.setBlock(x, hhx + 1, z, Material.STEP, (byte) 1);
|
||||
}
|
||||
|
||||
if(d.data == 1)
|
||||
{
|
||||
data.setBlock(x, hhx + 1, z, Material.STONE_SLAB2);
|
||||
}
|
||||
}
|
||||
|
||||
else if(d.material.equals(Material.SNOW_BLOCK))
|
||||
{
|
||||
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))
|
||||
{
|
||||
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)
|
||||
@ -419,7 +560,7 @@ public class IrisGenerator extends ParallaxWorldGenerator
|
||||
border++;
|
||||
}
|
||||
|
||||
if(h > Iris.settings.gen.seaLevel - 2)
|
||||
if(h > 1)
|
||||
{
|
||||
above = 0;
|
||||
below = 0;
|
||||
@ -527,9 +668,11 @@ public class IrisGenerator extends ParallaxWorldGenerator
|
||||
data.setBlock(x, h + 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.SMOOTH_BRICK) || d.material.equals(Material.COBBLESTONE) || d.material.equals(Material.GRAVEL))
|
||||
{
|
||||
data.setBlock(x, h + 1, z, Material.STEP, (byte) 3);
|
||||
data.setBlock(x, h + 1, z, Material.STEP, (byte) 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -130,10 +130,10 @@ public class IrisBiome
|
||||
cliffScale = 1;
|
||||
cliffChance = 0.37;
|
||||
parent = "";
|
||||
dirtDepth = 2;
|
||||
dirtDepth = 19;
|
||||
this.realBiome = realBiome;
|
||||
this.height = IDEAL_HEIGHT;
|
||||
rockDepth = 11;
|
||||
rockDepth = 23;
|
||||
surfaceScale = 1;
|
||||
subSurfaceScale = 1;
|
||||
rockScale = 1;
|
||||
@ -147,6 +147,10 @@ public class IrisBiome
|
||||
surface(new MB(Material.GRASS))
|
||||
.dirt(new MB(Material.DIRT), new MB(Material.DIRT, 1))
|
||||
.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),
|
||||
@ -154,12 +158,10 @@ public class IrisBiome
|
||||
MB.of(Material.STONE),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.COBBLESTONE),
|
||||
MB.of(Material.COBBLESTONE),
|
||||
MB.of(Material.SMOOTH_BRICK),
|
||||
MB.of(Material.SMOOTH_BRICK, 1),
|
||||
MB.of(Material.SMOOTH_BRICK, 2),
|
||||
MB.of(Material.SMOOTH_BRICK, 3));
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5),
|
||||
MB.of(Material.STONE, 5));
|
||||
//@done
|
||||
}
|
||||
|
||||
|
7
src/main/java/ninja/bytecode/iris/util/BorderCheck.java
Normal file
7
src/main/java/ninja/bytecode/iris/util/BorderCheck.java
Normal file
@ -0,0 +1,7 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BorderCheck<T>
|
||||
{
|
||||
public T get(double x, double z);
|
||||
}
|
44
src/main/java/ninja/bytecode/iris/util/Borders.java
Normal file
44
src/main/java/ninja/bytecode/iris/util/Borders.java
Normal 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;
|
||||
}
|
||||
}
|
@ -1,17 +1,20 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
|
||||
public class ChunkPlan
|
||||
{
|
||||
private final KMap<SChunkVector, Integer> realHeightCache;
|
||||
private final KMap<SChunkVector, KList<Integer>> caveHeightCache;
|
||||
private final KMap<SChunkVector, Integer> realWaterHeightCache;
|
||||
private final KMap<SChunkVector, Double> heightCache;
|
||||
private final KMap<SChunkVector, IrisBiome> biomeCache;
|
||||
|
||||
public ChunkPlan()
|
||||
{
|
||||
this.caveHeightCache = new KMap<>();
|
||||
this.realHeightCache = new KMap<>();
|
||||
this.realWaterHeightCache = new KMap<>();
|
||||
this.heightCache = new KMap<>();
|
||||
@ -50,6 +53,17 @@ public class ChunkPlan
|
||||
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)
|
||||
{
|
||||
SChunkVector c = new SChunkVector(x, z);
|
||||
@ -77,6 +91,16 @@ public class ChunkPlan
|
||||
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)
|
||||
{
|
||||
realHeightCache.put(c, h);
|
||||
@ -87,6 +111,11 @@ public class ChunkPlan
|
||||
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)
|
||||
{
|
||||
realWaterHeightCache.put(c, h);
|
||||
|
Loading…
x
Reference in New Issue
Block a user