diff --git a/src/main/java/ninja/bytecode/iris/Settings.java b/src/main/java/ninja/bytecode/iris/Settings.java index b6929625d..c3cfa8192 100644 --- a/src/main/java/ninja/bytecode/iris/Settings.java +++ b/src/main/java/ninja/bytecode/iris/Settings.java @@ -41,10 +41,10 @@ public class Settings public double caveScale = 1.45; public double biomeScale = 2; public boolean flatBedrock = true; - public boolean genObjects = true; - public boolean genCarving = true; - public boolean genCaverns = true; - public boolean genCaves = true; + public boolean genObjects = false; + public boolean genCarving = false; + public boolean genCaverns = false; + public boolean genCaves = false; public double carvingChance = 0.352; public double cavernChance = 0.321; public int minCarvingHeight = 75; diff --git a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java index 6dfa1db48..bea22957c 100644 --- a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java +++ b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java @@ -2,6 +2,7 @@ package ninja.bytecode.iris.generator; import java.util.List; import java.util.Random; +import java.util.concurrent.locks.ReentrantLock; import org.bukkit.Material; import org.bukkit.World; @@ -18,6 +19,7 @@ import ninja.bytecode.iris.generator.layer.GenLayerBiome; import ninja.bytecode.iris.generator.layer.GenLayerCarving; import ninja.bytecode.iris.generator.layer.GenLayerCaverns; 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; import ninja.bytecode.iris.pack.CompiledDimension; @@ -69,6 +71,7 @@ public class IrisGenerator extends ParallelChunkGenerator private GenLayerCaverns glCaverns; private GenLayerSnow glSnow; private GenLayerBase glBase; + private GenLayerCliffs glCliffs; private RNG rTerrain; private CompiledDimension dim; private World world; @@ -137,6 +140,7 @@ public class IrisGenerator extends ParallelChunkGenerator glCarving = new GenLayerCarving(this, world, random, rTerrain.nextParallelRNG(-2)); glCaverns = new GenLayerCaverns(this, world, random, rTerrain.nextParallelRNG(-3)); glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5)); + glCliffs = new GenLayerCliffs(this, world, random, rTerrain.nextParallelRNG(9)); scatterCache = new double[16][][]; scatter = new CNG(rTerrain.nextParallelRNG(52), 1, 1).scale(10); @@ -183,76 +187,83 @@ public class IrisGenerator extends ParallelChunkGenerator { return Math.round((double) z * (Iris.settings.gen.horizontalZoom / 1.90476190476)); } - + + public IrisBiome getOcean(IrisBiome biome, int height) + { + if(height < 36) + { + return biome("Deep Ocean"); + } + + else + { + return biome("Ocean"); + } + } + + public IrisBiome getBeach(IrisBiome biome) + { + IrisBiome beach = null; + IrisRegion region = glBiome.getRegion(biome.getRegion()); + + if(region != null) + { + beach = region.getBeach(); + } + + if(beach == null) + { + beach = biome("Beach"); + } + + return beach; + } + + public int computeHeight(int x, int z, ChunkPlan plan, IrisBiome biome) + { + return (int) Math.round(M.clip(getANoise((int) x, (int) z, plan, biome), 0D, 1D) * 253); + } + + public double getANoise(int x, int z, ChunkPlan plan, IrisBiome biome) + { + double hv = IrisInterpolation.getNoise(x, z, Iris.settings.gen.hermiteSampleRadius, (xf, zf) -> getBiomedHeight((int) Math.round(xf), (int) Math.round(zf), plan)); + hv += glLNoise.generateLayer(hv * Iris.settings.gen.roughness * 215, (double) x * Iris.settings.gen.roughness * 0.82, (double) z * Iris.settings.gen.roughness * 0.82) * (1.6918 * (hv * 2.35)); + + if(biome.hasCliffs()) + { + hv = glCliffs.generateLayer(hv, x, z, biome.getCliffScale(), biome.getCliffChance()); + } + + return hv; + } + @Override public Biome genColumn(int wxx, int wzx, int x, int z, ChunkPlan plan) { - //@builder int highest = 0; int seaLevel = Iris.settings.gen.seaLevel; double wx = getOffsetX(wxx); double wz = getOffsetZ(wzx); IrisBiome biome = getBiome(wxx, wzx); - double hv = IrisInterpolation.getNoise(wxx, wzx, - Iris.settings.gen.hermiteSampleRadius, - (xf, zf) -> getBiomedHeight((int) Math.round(xf), (int) Math.round(zf), plan)); - hv += glLNoise.generateLayer(hv * Iris.settings.gen.roughness * 215, wxx * Iris.settings.gen.roughness * 0.82, wzx * Iris.settings.gen.roughness * 0.82) * (1.6918 * (hv * 2.35)); - int height = (int) Math.round(M.clip(hv, 0D, 1D) * 253); + int height = computeHeight(wxx, wzx, plan, biome); int max = Math.max(height, seaLevel); - IrisBiome override = null; - //@done - - if(height > 61 && height < 65 + (glLNoise.getHeight(wz, wx) * Iris.settings.gen.beachScale)) - { - IrisBiome beach = null; - IrisRegion region = glBiome.getRegion(biome.getRegion()); - - if(region != null) - { - beach = region.getBeach(); - } - - if(beach == null) - { - beach = biome("Beach"); - } - - override = beach; - } - - else if(height < 63) - { - if(height < 36) - { - override = biome("Deep Ocean"); - } - - else - { - override = biome("Ocean"); - } - } - - if(override != null) - { - biome = override; - } + biome = height > 61 && height < 65 ? getBeach(biome) : biome; + biome = height < 63 ? getOcean(biome, height) : biome; for(int i = 0; i < max; i++) { MB mb = ROCK.get(scatterInt(wzx, i, wxx, ROCK.size())); boolean underwater = i >= height && i < seaLevel; boolean underground = i < height; - - if(underwater) - { - mb = WATER; - } - - if(underground && (height - 1) - i < scatterInt(x, i, z, 4) + 2) - { - mb = biome.getDirtRNG(); - } + int dheight = biome.getDirtDepth(); + int rheight = biome.getRockDepth(); + boolean dirt = (height - 1) - i < (dheight > 0 ? scatterInt(x, i, z, 4) : 0) + dheight; + boolean rocky = i > height - rheight && !dirt; + boolean bedrock = i == 0 || !Iris.settings.gen.flatBedrock ? i <= 2 : i < scatterInt(x, i, z, 3); + mb = underwater ? WATER : mb; + mb = underground && dirt ? biome.getSubSurface(wxx, i, wzx, rTerrain) : mb; + mb = underground && rocky ? biome.getRock(wxx, i, wzx, rTerrain) : mb; + mb = bedrock ? BEDROCK : mb; if(i == height - 1) { @@ -268,17 +279,8 @@ public class IrisGenerator extends ParallelChunkGenerator for(int j = 0; j < snowHeight; j++) { - if(j == snowHeight - 1) - { - highest = highest < j ? j : highest; - setBlock(x, i + j + 1, z, Material.SNOW, (byte) layers); - } - - else - { - highest = highest < j + 1 ? j + 1 : highest; - setBlock(x, i + j + 1, z, Material.SNOW_BLOCK); - } + highest = j == snowHeight - 1 ? highest < j ? j : highest : highest < j + 1 ? j + 1 : highest; + setBlock(x, i + j + 1, z, j == snowHeight - 1 ? Material.SNOW : Material.SNOW_BLOCK, j == snowHeight - 1 ? (byte) layers : (byte) 0); } } @@ -288,24 +290,14 @@ public class IrisGenerator extends ParallelChunkGenerator if(!mbx.material.equals(Material.AIR)) { - setBlock(x, i + 1, z, mbx.material, mbx.data); highest = i > highest ? i : highest; + setBlock(x, i + 1, z, mbx.material, mbx.data); } } } - if(i == 0) - { - mb = BEDROCK; - } - - if(!Iris.settings.gen.flatBedrock ? i <= 2 : i < scatterInt(x, i, z, 3)) - { - mb = BEDROCK; - } - - setBlock(x, i, z, mb.material, mb.data); highest = i > highest ? i : highest; + setBlock(x, i, z, mb.material, mb.data); } glCaves.genCaves(wxx, wzx, x, z, height, this); @@ -317,16 +309,8 @@ public class IrisGenerator extends ParallelChunkGenerator for(int i = highest; i > 0; i--) { Material t = getType(x, i, z); - - if(i > seaLevel && hw == 0 && (t.equals(Material.WATER) || t.equals(Material.STATIONARY_WATER))) - { - hw = i; - } - - else if(hl == 0 && !t.equals(Material.AIR)) - { - hl = i; - } + hw = i > seaLevel && hw == 0 && (t.equals(Material.WATER) || t.equals(Material.STATIONARY_WATER)) ? i : hw; + hl = hl == 0 && !t.equals(Material.AIR) ? i : hl; } plan.setRealHeight(x, z, hl); diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java index 09d92ccdf..79cb40831 100644 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java @@ -150,7 +150,7 @@ public class GenLayerCarving extends GenLayer { if(!fail) { - MB mb = biome.getDirtRNG(); + MB mb = biome.getSubSurface(wxx, i, wzx, g.getRTerrain()); g.setBlock(x, i, z, mb.material, mb.data); } diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaverns.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaverns.java index 26bd717ee..ed0d20926 100644 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaverns.java +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaverns.java @@ -150,7 +150,7 @@ public class GenLayerCaverns extends GenLayer { if(!fail) { - MB mb = biome.getDirtRNG(); + MB mb = biome.getSubSurface(wxx, i, wzx, g.getRTerrain()); g.setBlock(x, i, z, mb.material, mb.data); } diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java new file mode 100644 index 000000000..ebaca5b0d --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java @@ -0,0 +1,67 @@ +package ninja.bytecode.iris.generator.layer; + +import java.util.Random; + +import org.bukkit.World; + +import ninja.bytecode.iris.generator.IrisGenerator; +import ninja.bytecode.iris.util.GenLayer; +import ninja.bytecode.shuriken.math.CNG; +import ninja.bytecode.shuriken.math.RNG; + +public class GenLayerCliffs extends GenLayer +{ + private double block; + private CNG gen; + private CNG sh; + private CNG ch; + + public GenLayerCliffs(IrisGenerator iris, World world, Random random, RNG rng) + { + //@builder + super(iris, world, random, rng); + block = 1D / 255D; + gen = new CNG(rng.nextParallelRNG(128), 1D, 4).scale(0.02); + sh = new CNG(rng.nextParallelRNG(127), 1D, 1).scale(0.00367); + ch = new CNG(rng.nextParallelRNG(127), 1D, 1).scale(0.00413); + //@done + } + + @Override + public double generateLayer(double gnoise, double dx, double dz) + { + return generateLayer(gnoise, dx, dz, 1D, 0.37D); + } + + public double generateLayer(double gnoise, double dx, double dz, double cliffs, double chance) + { + if(gnoise < block * 66) + { + return gnoise; + } + + double shift = 10.25 + (sh.noise(dx, dz) * 2.25) * cliffs; + double hits = 183D / shift; + double n = gnoise; + + for(int i = (int) hits; i > 0; i--) + { + if(ch.noise(dx + (i * -1000), dz + (i * 1000)) >= chance) + { + continue; + } + + double var = 6.2 * block; + double varCombined = 15.45 * block; + double sep = (shift / 1.8D) * block; + double height = (47 + (i * shift)) * block; + double sh = ((gen.noise(dx + dz, dz - dx) - 0.5D) * 2D) * varCombined; + double shv = ((gen.noise(dz + dx, dx - dz) - 0.5D) * 2D) * varCombined; + double lo = (gen.noise(dx + (i * -1000), dz + (i * 1000)) * var) + height + sh; + double hi = (gen.noise(dz + (i * 1000), dx + (i * -1000)) * var) + height + sep + shv; + n = n > lo && n < hi ? lo : n; + } + + return n; + } +} diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java index e46b98b5a..f372787da 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java @@ -42,16 +42,28 @@ public class IrisBiome private Biome realBiome; private double height; private double amp; + private GList rock; + private int rockDepth; private GList surface; private GList dirt; private GMap scatterChance; private boolean scatterSurface; + private boolean scatterSurfaceRock; + private boolean scatterSurfaceSub; private boolean core; + private int dirtDepth; private boolean simplexScatter; + private boolean simplexScatterRock; + private boolean simplexScatterSub; private double snow; + private double cliffChance; + private double cliffScale; + private boolean cliffs; private String region; private GMap schematicGroups; private PolygonGenerator.EnumPolygonGenerator poly; + private PolygonGenerator.EnumPolygonGenerator polySub; + private PolygonGenerator.EnumPolygonGenerator polyRock; public static double getMaxHeight() { @@ -114,12 +126,38 @@ public class IrisBiome this.region = "default"; this.core = false; this.name = name; + cliffs = false; + cliffScale = 1; + cliffChance = 0.37; + dirtDepth = 2; this.realBiome = realBiome; this.height = IDEAL_HEIGHT; this.amp = 0.31; + rockDepth = 11; + simplexScatterRock = false; + scatterSurfaceRock = true; + simplexScatterSub = false; + scatterSurfaceSub = true; scatterChance = new GMap<>(); schematicGroups = new GMap<>(); - surface(new MB(Material.GRASS)).dirt(new MB(Material.DIRT), new MB(Material.DIRT, 1)); + //@builder + 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, 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)); + //@done } public void fromJSON(JSONObject o) @@ -134,18 +172,30 @@ public class IrisBiome J.attempt(() -> region = o.getString("region")); J.attempt(() -> height = o.getDouble("height")); J.attempt(() -> snow = o.getDouble("snow")); + J.attempt(() -> dirtDepth = o.getInt("subSurfaceDepth")); + J.attempt(() -> dirtDepth = o.getInt("dirtDepth")); + J.attempt(() -> rockDepth = o.getInt("rockDepth")); + J.attempt(() -> cliffScale = o.getDouble("cliffScale")); + J.attempt(() -> cliffChance = o.getDouble("cliffChance")); + J.attempt(() -> cliffs = o.getBoolean("cliffs")); J.attempt(() -> surface = mbListFromJSON(o.getJSONArray("surface"))); + J.attempt(() -> rock = mbListFromJSON(o.getJSONArray("rock"))); + J.attempt(() -> dirt = mbListFromJSON(o.getJSONArray("subSurface"))); J.attempt(() -> dirt = mbListFromJSON(o.getJSONArray("dirt"))); J.attempt(() -> scatterChance = scatterFromJSON(o.getJSONArray("scatter"))); J.attempt(() -> simplexScatter = o.getString("surfaceType").equalsIgnoreCase("simplex")); J.attempt(() -> scatterSurface = o.getString("surfaceType").equalsIgnoreCase("scatter")); + J.attempt(() -> simplexScatterRock = o.getString("rockType").equalsIgnoreCase("simplex")); + J.attempt(() -> scatterSurfaceRock = o.getString("rockType").equalsIgnoreCase("scatter")); + J.attempt(() -> simplexScatterSub = o.getString("subSurfaceType").equalsIgnoreCase("simplex")); + J.attempt(() -> scatterSurfaceSub = o.getString("subSurfaceType").equalsIgnoreCase("scatter")); J.attempt(() -> { if(Iris.settings.gen.genObjects) { schematicGroups = strFromJSON(o.getJSONArray("objects")); } - + else { schematicGroups = new GMap<>(); @@ -172,10 +222,18 @@ public class IrisBiome J.attempt(() -> j.put("derivative", realBiome.name().toLowerCase().replaceAll("_", " "))); J.attempt(() -> j.put("height", height)); J.attempt(() -> j.put("snow", snow)); + J.attempt(() -> j.put("cliffs", cliffs)); + J.attempt(() -> j.put("cliffScale", cliffScale)); + J.attempt(() -> j.put("cliffChance", cliffChance)); J.attempt(() -> j.put("surface", mbListToJSON(surface))); - J.attempt(() -> j.put("dirt", mbListToJSON(dirt))); + J.attempt(() -> j.put("rock", mbListToJSON(rock))); + J.attempt(() -> j.put("subSurfaceDepth", dirtDepth)); + J.attempt(() -> j.put("rockDepth", rockDepth)); + J.attempt(() -> j.put("subSurface", mbListToJSON(dirt))); J.attempt(() -> j.put("scatter", scatterToJson(scatterChance))); J.attempt(() -> j.put("surfaceType", simplexScatter ? "simplex" : scatterSurface ? "scatter" : "na")); + J.attempt(() -> j.put("subSurfaceType", simplexScatterSub ? "simplex" : scatterSurfaceSub ? "scatter" : "na")); + J.attempt(() -> j.put("rockType", simplexScatterRock ? "simplex" : scatterSurfaceRock ? "scatter" : "na")); J.attempt(() -> j.put("objects", strToJson(schematicGroups))); return j; @@ -321,6 +379,12 @@ public class IrisBiome return this; } + public IrisBiome rock(MB... mbs) + { + rock = new GList<>(mbs); + return this; + } + public IrisBiome height(double height) { if(height >= 0) @@ -367,6 +431,11 @@ public class IrisBiome return surface; } + public GList getRock() + { + return rock; + } + public GList getDirt() { return dirt; @@ -405,9 +474,70 @@ public class IrisBiome return getSurface().getRandom(); } - public MB getDirtRNG() + public MB getSubSurface(double x, double i, double z, RNG rng) { - return getDirt().getRandom(); + double wx = x + 1000D; + double wz = z + 1000D; + if(simplexScatterSub) + { + if(polySub == null) + { + polySub = new PolygonGenerator.EnumPolygonGenerator(rng, 0.125, 2, getDirt().toArray(new MB[getDirt().size()]), (g) -> + { + return g.scale(0.05).fractureWith(new CNG(rng.nextParallelRNG(526), 1D, 2).scale(0.0955), 55); + }); + } + + return polySub.getChoice(wx / 3, i / 3, wz / 3); + } + + if(scatterSurfaceSub) + { + if(polySub == null) + { + polySub = new PolygonGenerator.EnumPolygonGenerator(rng, 15.05, 2, getDirt().toArray(new MB[getDirt().size()]), (g) -> + { + return g.fractureWith(new CNG(rng.nextParallelRNG(515), 1D, 2).scale(0.0155), 224); + }); + } + + return polySub.getChoice(wx * 0.2D, i / 3, wz * 0.2D); + } + + return getSurface().getRandom(); + } + + public MB getRock(double x, double i, double z, RNG rng) + { + double wx = x + 1000D; + double wz = z + 1000D; + if(simplexScatterRock) + { + if(polyRock == null) + { + polyRock = new PolygonGenerator.EnumPolygonGenerator(rng, 0.125, 2, getRock().toArray(new MB[getRock().size()]), (g) -> + { + return g.scale(0.05).fractureWith(new CNG(rng.nextParallelRNG(562), 1D, 2).scale(0.0955), 55); + }); + } + + return polyRock.getChoice(wx / 3, i / 3, wz / 3); + } + + if(scatterSurfaceRock) + { + if(polyRock == null) + { + polyRock = new PolygonGenerator.EnumPolygonGenerator(rng, 15.05, 2, getRock().toArray(new MB[getRock().size()]), (g) -> + { + return g.fractureWith(new CNG(rng.nextParallelRNG(551), 1D, 2).scale(0.0155), 224); + }); + } + + return polyRock.getChoice(wx * 0.2D, i * 0.2D, wz * 0.2D); + } + + return getSurface().getRandom(); } public GMap getScatterChance() @@ -480,4 +610,34 @@ public class IrisBiome { return snow; } + + public double getCliffScale() + { + return cliffScale; + } + + public boolean hasCliffs() + { + return cliffs; + } + + public int getDirtDepth() + { + return dirtDepth; + } + + public int getRockDepth() + { + return rockDepth; + } + + public boolean isCliffs() + { + return cliffs; + } + + public double getCliffChance() + { + return cliffChance; + } }