From fd16fd28904337b34939bcd85854073cf9a99cda Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Wed, 1 Jan 2020 20:52:10 -0500 Subject: [PATCH] Pops --- .../ninja/bytecode/iris/IrisGenerator.java | 27 ++++- .../bytecode/iris/ParallelChunkGenerator.java | 57 +++++++-- .../java/ninja/bytecode/iris/Settings.java | 13 +- .../java/ninja/bytecode/iris/biome/CBI.java | 108 +++++++++++++++-- .../bytecode/iris/gen/GenLayerBiome.java | 33 +++++- .../bytecode/iris/gen/GenLayerCaves.java | 26 ---- .../iris/gen/GenLayerLayeredNoise.java | 43 +++++++ .../bytecode/iris/gen/GenLayerRidge.java | 55 +++++++++ .../bytecode/iris/pop/PopulatorLakes.java | 112 ++++++++++++++++++ .../bytecode/iris/pop/PopulatorTrees.java | 61 ++++++++++ 10 files changed, 468 insertions(+), 67 deletions(-) delete mode 100644 src/main/java/ninja/bytecode/iris/gen/GenLayerCaves.java create mode 100644 src/main/java/ninja/bytecode/iris/gen/GenLayerLayeredNoise.java create mode 100644 src/main/java/ninja/bytecode/iris/gen/GenLayerRidge.java create mode 100644 src/main/java/ninja/bytecode/iris/pop/PopulatorLakes.java create mode 100644 src/main/java/ninja/bytecode/iris/pop/PopulatorTrees.java diff --git a/src/main/java/ninja/bytecode/iris/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/IrisGenerator.java index ae0775ff3..98a4f03d8 100644 --- a/src/main/java/ninja/bytecode/iris/IrisGenerator.java +++ b/src/main/java/ninja/bytecode/iris/IrisGenerator.java @@ -9,15 +9,16 @@ import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; import org.bukkit.util.Vector; +import ninja.bytecode.iris.atomics.AtomicChunkData; import ninja.bytecode.iris.biome.CBI; import ninja.bytecode.iris.gen.GenLayerBase; import ninja.bytecode.iris.gen.GenLayerBiome; -import ninja.bytecode.iris.util.MaxingGenerator; +import ninja.bytecode.iris.gen.GenLayerLayeredNoise; +import ninja.bytecode.iris.gen.GenLayerRidge; +import ninja.bytecode.iris.pop.PopulatorLakes; +import ninja.bytecode.iris.pop.PopulatorTrees; import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GMap; -import ninja.bytecode.shuriken.execution.ChronoLatch; -import ninja.bytecode.shuriken.format.F; -import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.math.M; import ninja.bytecode.shuriken.math.RNG; @@ -27,6 +28,8 @@ public class IrisGenerator extends ParallelChunkGenerator private MB WATER = new MB(Material.STATIONARY_WATER); private MB BEDROCK = new MB(Material.BEDROCK); private GenLayerBase glBase; + private GenLayerLayeredNoise glLNoise; + private GenLayerRidge glRidge; private GenLayerBiome glBiome; private RNG rng; private World world; @@ -38,8 +41,15 @@ public class IrisGenerator extends ParallelChunkGenerator heightCache = new GMap<>(); rng = new RNG(world.getSeed()); glBase = new GenLayerBase(this, world, random, rng.nextRNG()); + glLNoise = new GenLayerLayeredNoise(this, world, random, rng.nextRNG()); + glRidge = new GenLayerRidge(this, world, random, rng.nextRNG()); glBiome = new GenLayerBiome(this, world, random, rng.nextRNG()); } + + public World getWorld() + { + return world; + } public int getHeight(double h) { @@ -140,6 +150,8 @@ public class IrisGenerator extends ParallelChunkGenerator int wz = (int) Math.round((double) wzx * Iris.settings.gen.horizontalZoom); CBI biome = glBiome.getBiome(wx * Iris.settings.gen.biomeScale, wz * Iris.settings.gen.biomeScale); double hv = getBicubicNoise(wxx, wzx); + hv += glLNoise.generateLayer(hv, wxx, wzx); + hv -= glRidge.generateLayer(hv, wxx, wzx); int height = getHeight(hv); for(int i = 0; i < Math.max(height, seaLevel); i++) @@ -191,7 +203,8 @@ public class IrisGenerator extends ParallelChunkGenerator public List getDefaultPopulators(World world) { GList p = new GList(); - + p.add(new PopulatorTrees()); + p.add(new PopulatorLakes()); return p; } @@ -212,8 +225,10 @@ public class IrisGenerator extends ParallelChunkGenerator } @Override - public void onPostChunk(World world, int x, int z, Random random) + public GList onPostChunk(World world, int x, int z, Random random, AtomicChunkData data) { + GList jobs = new GList<>(); + return jobs; } } \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/ParallelChunkGenerator.java b/src/main/java/ninja/bytecode/iris/ParallelChunkGenerator.java index ef1913b29..8f4bacddb 100644 --- a/src/main/java/ninja/bytecode/iris/ParallelChunkGenerator.java +++ b/src/main/java/ninja/bytecode/iris/ParallelChunkGenerator.java @@ -2,17 +2,23 @@ package ninja.bytecode.iris; import java.util.Random; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator; import ninja.bytecode.iris.atomics.AtomicChunkData; +import ninja.bytecode.iris.pop.PopulatorLakes; +import ninja.bytecode.iris.pop.PopulatorTrees; import ninja.bytecode.shuriken.Shuriken; +import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.execution.ChronoLatch; +import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult; import ninja.bytecode.shuriken.format.F; +import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.math.RollingSequence; public abstract class ParallelChunkGenerator extends ChunkGenerator @@ -24,11 +30,49 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator private AtomicChunkData data; private TaskGroup tg; private boolean ready = false; + int cg = 0; private ChronoLatch cl = new ChronoLatch(1000); + private ChronoLatch cs = new ChronoLatch(1000); private RollingSequence rs = new RollingSequence(512); + private RollingSequence cps = new RollingSequence(3); + private World world; + + @SuppressWarnings("deprecation") + public ParallelChunkGenerator() + { + Bukkit.getScheduler().scheduleAsyncRepeatingTask(Iris.instance, () -> + { + J.attempt(() -> + { + if(world.getPlayers().isEmpty()) + { + return; + } + + if(cs.flip()) + { + cps.put(cg); + cg = 0; + } + + double total = rs.getAverage() + PopulatorTrees.timings.getAverage() + PopulatorLakes.timings.getAverage(); + double rcs = (1000D / total); + double work = cps.getAverage() / (rcs + 1); + L.i("Terrain Gen for " + world.getName()); + L.i("- Terrain (MLTC): " + F.duration(rs.getAverage(), 2)); + L.i("- Trees (SGLC): " + F.duration(PopulatorTrees.timings.getAverage(), 2)); + L.i("- Lakes (SGLC): " + F.duration(PopulatorLakes.timings.getAverage(), 2)); + L.i("Total: " + F.duration(total, 3) + " Work: " + F.f(cps.getAverage(), 0) + "/s of " + F.f(rcs, 0) + "/s (" + F.pc(work, 0) + " utilization)"); + L.flush(); + System.out.println(""); + }); + + }, 20, 5); + } public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { + this.world = world; Shuriken.profiler.start("chunkgen-" + world.getName()); data = new AtomicChunkData(world); @@ -59,15 +103,10 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator onInitChunk(world, x, z, random); TaskResult r = tg.execute(); - onPostChunk(world, x, z, random); - + onPostChunk(world, x, z, random, data); rs.put(r.timeElapsed); Shuriken.profiler.stop("chunkgen-" + world.getName()); - - if(cl.flip()) - { - System.out.println("Total MS: " + F.duration(rs.getAverage(), 2)); - } + cg++; } catch(Throwable e) @@ -76,7 +115,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator { e.printStackTrace(); } - + for(int i = 0; i < 16; i++) { for(int j = 0; j < 16; j++) @@ -93,7 +132,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator public abstract void onInitChunk(World world, int x, int z, Random random); - public abstract void onPostChunk(World world, int x, int z, Random random); + public abstract GList onPostChunk(World world, int x, int z, Random random, AtomicChunkData data2); public abstract Biome genColumn(int wx, int wz, int x, int z); diff --git a/src/main/java/ninja/bytecode/iris/Settings.java b/src/main/java/ninja/bytecode/iris/Settings.java index 344502842..92ca5ff6c 100644 --- a/src/main/java/ninja/bytecode/iris/Settings.java +++ b/src/main/java/ninja/bytecode/iris/Settings.java @@ -21,18 +21,9 @@ public class Settings public double heightExponentMultiplier = 1.41; public double heightScale = 1; public double superHeightScale = 0.65; - public double altBiomeScale = 1; - public double baseHeight = 0.22; - public double superSamplerRadius = 32; - public int superSamplerIterations = 14; - public int superSamples = 12; - public double superSamplerMultiplier = 1; - public double superSampleThreshold = 0.00984; - public double superSampleOpacity = 1; + public double baseHeight = 0.165; public int seaLevel = 63; - public double biomeScale = 1.31; - public double landChance = 0.75; - + public double biomeScale = 2.41; public boolean flatBedrock = false; } } diff --git a/src/main/java/ninja/bytecode/iris/biome/CBI.java b/src/main/java/ninja/bytecode/iris/biome/CBI.java index 591949711..d088a5db2 100644 --- a/src/main/java/ninja/bytecode/iris/biome/CBI.java +++ b/src/main/java/ninja/bytecode/iris/biome/CBI.java @@ -1,7 +1,8 @@ package ninja.bytecode.iris.biome; +import java.lang.reflect.Field; + import org.bukkit.Material; -import org.bukkit.TreeSpecies; import org.bukkit.TreeType; import org.bukkit.block.Biome; @@ -9,6 +10,7 @@ import ninja.bytecode.iris.MB; import ninja.bytecode.iris.util.PolygonGenerator; import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GMap; +import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.math.CNG; import ninja.bytecode.shuriken.math.M; import ninja.bytecode.shuriken.math.RNG; @@ -17,8 +19,13 @@ public class CBI { //@builder public static final CBI RIVER = new CBI("River", Biome.RIVER) - .surface(MB.of(Material.SAND)) - .height(0.085); + .surface(MB.of(Material.SAND)); + public static final CBI ROAD_GRAVEL = new CBI("Gravel Road", Biome.PLAINS) + .surface(MB.of(Material.GRAVEL), MB.of(Material.COBBLESTONE)) + .scatter(MB.of(Material.TORCH), 0.05); + public static final CBI ROAD_GRASSY = new CBI("Grass Path", Biome.PLAINS) + .surface(MB.of(Material.GRASS_PATH)) + .scatter(MB.of(Material.TORCH), 0.05); public static final CBI OCEAN = new CBI("Ocean", Biome.OCEAN) .surface(MB.of(Material.SAND)) .height(-0.07); @@ -48,21 +55,28 @@ public class CBI .dirt(MB.of(Material.CLAY), MB.of(Material.SAND), MB.of(Material.SAND, 1)) .simplexSurface(); public static final CBI SAVANNA = new CBI("Savanna", Biome.SAVANNA) - .scatter(MB.of(Material.LONG_GRASS, 1), 0.18) - .tree(TreeType.ACACIA, 0.2); + .tree(TreeType.ACACIA, 0.102) + .scatter(MB.of(Material.LONG_GRASS, 1), 0.18); public static final CBI SAVANNA_HILLS = new CBI("Savanna Hills", Biome.SAVANNA_ROCK) .scatter(MB.of(Material.LONG_GRASS, 1), 0.18) - .amp(0.75) - .tree(TreeType.ACACIA, 0.2); + .tree(TreeType.ACACIA, 0.102) + .amp(0.75); public static final CBI JUNGLE = new CBI("Jungle", Biome.JUNGLE) - .scatter(MB.of(Material.LONG_GRASS, 1), 0.58) - .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); + .scatter(MB.of(Material.LONG_GRASS, 1), 0.058) + .tree(TreeType.JUNGLE, 0.8) + .tree(TreeType.JUNGLE_BUSH, 0.3) + .tree(TreeType.SMALL_JUNGLE, 0.1) + .scatter(MB.of(Material.LONG_GRASS, 2), 0.013); public static final CBI JUNGLE_HILLS = new CBI("Jungle Hills", Biome.JUNGLE_HILLS) - .scatter(MB.of(Material.LONG_GRASS, 1), 0.58) + .scatter(MB.of(Material.LONG_GRASS, 1), 0.081) + .tree(TreeType.JUNGLE, 0.8) + .tree(TreeType.JUNGLE_BUSH, 0.3) + .tree(TreeType.SMALL_JUNGLE, 0.1) .amp(0.75) - .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); + .scatter(MB.of(Material.LONG_GRASS, 2), 0.02); public static final CBI SWAMP = new CBI("Swamp", Biome.SWAMPLAND) .scatter(MB.of(Material.LONG_GRASS, 1), 0.04) + .tree(TreeType.SWAMP, 0.25) .scatter(MB.of(Material.LONG_GRASS, 2), 0.03); public static final CBI PLAINS = new CBI("Plains", Biome.PLAINS) .scatter(MB.of(Material.LONG_GRASS, 1), 0.38) @@ -74,37 +88,51 @@ public class CBI .simplexSurface(); public static final CBI FOREST = new CBI("Forest", Biome.FOREST) .scatter(MB.of(Material.LONG_GRASS, 1), 0.23) + .tree(TreeType.TREE, 0.7) .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); public static final CBI FOREST_HILLS = new CBI("Forest Hills", Biome.FOREST_HILLS) .scatter(MB.of(Material.LONG_GRASS, 1), 0.23) .amp(0.75) + .tree(TreeType.TREE, 0.7) .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); public static final CBI BIRCH_FOREST = new CBI("Birch Forest", Biome.BIRCH_FOREST) .scatter(MB.of(Material.LONG_GRASS, 1), 0.23) + .tree(TreeType.BIRCH, 0.7) .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); public static final CBI BIRCH_FOREST_HILLS = new CBI("Birch Forest Hills", Biome.BIRCH_FOREST_HILLS) .scatter(MB.of(Material.LONG_GRASS, 1), 0.23) + .tree(TreeType.BIRCH, 0.7) .amp(0.75) .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); public static final CBI ROOFED_FOREST = new CBI("Roofed Forest", Biome.ROOFED_FOREST) .scatter(MB.of(Material.LONG_GRASS, 1), 0.23) + .tree(TreeType.DARK_OAK, 0.9) .scatter(MB.of(Material.LONG_GRASS, 2), 0.13); public static final CBI TAIGA = new CBI("Taiga", Biome.TAIGA) + + .tree(TreeType.REDWOOD, 0.4) .scatter(MB.of(Material.LONG_GRASS, 2), 0.07); public static final CBI EXTREME_HILLS = new CBI("Extreme Hills", Biome.EXTREME_HILLS) .scatter(MB.of(Material.LONG_GRASS, 2), 0.04); public static final CBI EXTREME_HILLS_TREES = new CBI("Extreme Hills +", Biome.EXTREME_HILLS_WITH_TREES) .scatter(MB.of(Material.LONG_GRASS, 2), 0.09) + + .tree(TreeType.REDWOOD, 0.1) .amp(1.25); public static final CBI TAIGA_COLD = new CBI("Taiga Cold", Biome.TAIGA_COLD) + .tree(TreeType.REDWOOD, 0.3) .scatter(MB.of(Material.LONG_GRASS, 2), 0.04); public static final CBI TAIGA_COLD_HILLS = new CBI("Taiga Cold Hills", Biome.TAIGA_COLD_HILLS) - .amp(0.75); + + .tree(TreeType.REDWOOD, 0.15).amp(0.75); public static final CBI ICE_FLATS = new CBI("Ice Flats", Biome.ICE_FLATS); public static final CBI ICE_MOUNTAINS = new CBI("Ice Mountains", Biome.ICE_MOUNTAINS) .amp(1.45); public static final CBI REDWOOD_TAIGA = new CBI("Redwood Taiga", Biome.REDWOOD_TAIGA) .surface(MB.of(Material.DIRT, 2), MB.of(Material.DIRT, 1)) + .tree(TreeType.TALL_REDWOOD, 0.7) + .tree(TreeType.MEGA_REDWOOD, 0.6) + .tree(TreeType.REDWOOD, 0.3) .simplexSurface(); public static final CBI REDWOOD_TAIGA_HILLS = new CBI("Redwood Taiga Hills", Biome.REDWOOD_TAIGA_HILLS) .surface(MB.of(Material.DIRT, 2), MB.of(Material.DIRT, 1)) @@ -112,7 +140,7 @@ public class CBI .simplexSurface(); //@done - + private static final GMap map = build(); private String name; private Biome realBiome; private double height; @@ -122,6 +150,7 @@ public class CBI private GList dirt; private GMap scatterChance; private boolean simplexScatter; + private GMap schematicGroups; private PolygonGenerator.EnumPolygonGenerator poly; public CBI(String name, Biome realBiome) @@ -131,10 +160,33 @@ public class CBI this.height = 0.125; this.amp = 0.5; scatterChance = new GMap<>(); + schematicGroups = new GMap<>(); treeChance = new GMap<>(); surface(new MB(Material.GRASS)).dirt(new MB(Material.DIRT), new MB(Material.DIRT, 1)); } + private static GMap build() + { + GMap g = new GMap(); + + for(Field i : CBI.class.getDeclaredFields()) + { + J.attempt(() -> + { + i.setAccessible(true); + + CBI bb = (CBI) i.get(null); + + if(!g.containsKey(bb.realBiome)) + { + g.put(bb.realBiome, bb); + } + }); + } + + return g; + } + public CBI scatter(MB mb, Double chance) { scatterChance.put(mb, chance); @@ -149,6 +201,13 @@ public class CBI return this; } + public CBI schematic(String t, Double chance) + { + schematicGroups.put(t, chance); + + return this; + } + public CBI simplexSurface() { simplexScatter = true; @@ -267,4 +326,27 @@ public class CBI return null; } + + public String getSchematicChanceSingle() + { + for(String i : schematicGroups.keySet()) + { + if(M.r(schematicGroups.get(i))) + { + return i; + } + } + + return null; + } + + public static CBI find(Biome biome) + { + if(map.containsKey(biome)) + { + return map.get(biome); + } + + return CBI.PLAINS; + } } diff --git a/src/main/java/ninja/bytecode/iris/gen/GenLayerBiome.java b/src/main/java/ninja/bytecode/iris/gen/GenLayerBiome.java index 1e6deb3be..a50fa1c99 100644 --- a/src/main/java/ninja/bytecode/iris/gen/GenLayerBiome.java +++ b/src/main/java/ninja/bytecode/iris/gen/GenLayerBiome.java @@ -3,11 +3,13 @@ package ninja.bytecode.iris.gen; import java.util.Random; import java.util.function.Function; +import org.bukkit.Material; import org.bukkit.World; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.IrisGenerator; import ninja.bytecode.iris.biome.CBI; +import ninja.bytecode.iris.util.MaxingGenerator; import ninja.bytecode.iris.util.MaxingGenerator.EnumMaxingGenerator; import ninja.bytecode.shuriken.math.CNG; import ninja.bytecode.shuriken.math.RNG; @@ -15,15 +17,21 @@ import ninja.bytecode.shuriken.math.RNG; public class GenLayerBiome extends GenLayer { private EnumMaxingGenerator biomeGenerator; + private MaxingGenerator roads; private Function factory; + private CNG pathCheck; private CNG riverCheck; + private CNG fracture; public GenLayerBiome(IrisGenerator iris, World world, Random random, RNG rng) { //@builder super(iris, world, random, rng); + fracture = new CNG(rng.nextRNG(), 1D, 7).scale(0.004).fractureWith(new CNG(rng.nextRNG(), 1D, 3).scale(0.19), 277D); factory = (g) -> g.fractureWith(new CNG(rng.nextRNG(), 1D, 4).scale(0.02), 56); riverCheck = new CNG(rng.nextRNG(), 1D, 2).scale(0.00096); + pathCheck = new CNG(rng.nextRNG(), 1D, 1).scale(0.00096); + roads = new MaxingGenerator(rng.nextRNG(), 5, 0.00055, 8, factory); biomeGenerator = new EnumMaxingGenerator(rng.nextRNG(), 0.00755 * Iris.settings.gen.biomeScale, 1, new CBI[] { CBI.DESERT, @@ -57,8 +65,11 @@ public class GenLayerBiome extends GenLayer //@done } - public CBI getBiome(double x, double z) + public CBI getBiome(double xx, double zz) { + double x = xx + (fracture.noise(zz, xx) * 866); + double z = zz - (fracture.noise(xx, zz) * 866); + if(riverCheck.noise(x, z) > 0.75) { if(biomeGenerator.hasBorder(3, 3 + Math.pow(riverCheck.noise(x, z), 1.25) * 16, x, z)) @@ -67,7 +78,25 @@ public class GenLayerBiome extends GenLayer } } - return biomeGenerator.getChoice(x, z); + CBI cbi = biomeGenerator.getChoice(x, z); + + if(pathCheck.noise(x, z) > 0.5) + { + CBI road = CBI.ROAD_GRAVEL; + + if(cbi.getSurface().get(0).material.equals(Material.GRASS)) + { + road = CBI.ROAD_GRASSY; + } + + if(Math.abs(road.getHeight() - cbi.getHeight()) < 0.0001 && roads.hasBorder(4, 8, xx, zz)) + { + return road; + } + + } + + return cbi; } @Override diff --git a/src/main/java/ninja/bytecode/iris/gen/GenLayerCaves.java b/src/main/java/ninja/bytecode/iris/gen/GenLayerCaves.java deleted file mode 100644 index 3b24efc0a..000000000 --- a/src/main/java/ninja/bytecode/iris/gen/GenLayerCaves.java +++ /dev/null @@ -1,26 +0,0 @@ -package ninja.bytecode.iris.gen; - -import java.util.Random; - -import org.bukkit.World; - -import ninja.bytecode.iris.IrisGenerator; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerCaves extends GenLayer -{ - public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - - //@done - } - - @Override - public double generateLayer(double noise, double dx, double dz) - { - return noise; - } -} diff --git a/src/main/java/ninja/bytecode/iris/gen/GenLayerLayeredNoise.java b/src/main/java/ninja/bytecode/iris/gen/GenLayerLayeredNoise.java new file mode 100644 index 000000000..226c297b9 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/gen/GenLayerLayeredNoise.java @@ -0,0 +1,43 @@ +package ninja.bytecode.iris.gen; + +import java.util.Random; + +import org.bukkit.World; + +import ninja.bytecode.iris.IrisGenerator; +import ninja.bytecode.shuriken.math.CNG; +import ninja.bytecode.shuriken.math.RNG; + +public class GenLayerLayeredNoise extends GenLayer +{ + private CNG gen; + private CNG fract; + + public GenLayerLayeredNoise(IrisGenerator iris, World world, Random random, RNG rng) + { + //@builder + super(iris, world, random, rng); + fract = new CNG(rng.nextRNG(), 1D, 9).scale(0.0181); + gen = new CNG(rng.nextRNG(), 0.19D, 16) + .scale(0.012) + .amp(0.5) + .freq(1.1) + .fractureWith(new CNG(rng.nextRNG(), 1, 6) + .scale(0.018) + .child(new CNG(rng.nextRNG(), 0.745, 2) + .scale(0.1)) + .fractureWith(new CNG(rng.nextRNG(), 1, 3) + .scale(0.15), 24), 44); + } + + public double getHeight(double x, double z) + { + return 0.65* gen.noise(x, z); + } + + @Override + public double generateLayer(double gnoise, double dx, double dz) + { + return 0.65* gen.noise(gnoise, dx + (fract.noise(gnoise, dx, dz) * 333), dz - (fract.noise(dz, dx, gnoise) * 333)); + } +} diff --git a/src/main/java/ninja/bytecode/iris/gen/GenLayerRidge.java b/src/main/java/ninja/bytecode/iris/gen/GenLayerRidge.java new file mode 100644 index 000000000..c4b05ab05 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/gen/GenLayerRidge.java @@ -0,0 +1,55 @@ +package ninja.bytecode.iris.gen; + +import java.util.Random; + +import org.bukkit.World; + +import ninja.bytecode.iris.IrisGenerator; +import ninja.bytecode.shuriken.math.CNG; +import ninja.bytecode.shuriken.math.RNG; + +public class GenLayerRidge extends GenLayer +{ + private CNG gen; + private CNG fract; + private CNG g; + private CNG q; + + public GenLayerRidge(IrisGenerator iris, World world, Random random, RNG rng) + { + //@builder + super(iris, world, random, rng); + q = new CNG(rng.nextRNG(), 1D, 2).scale(0.0211); + g = new CNG(rng.nextRNG(), 1D, 2).scale(0.0011); + fract = new CNG(rng.nextRNG(), 1D, 5).scale(0.0011); + gen = new CNG(rng.nextRNG(), 0.19D, 16) + .scale(0.012) + .injectWith(CNG.MAX) + .amp(0.5) + .freq(1.1) + .fractureWith(new CNG(rng.nextRNG(), 1, 6) + .scale(0.018) + .child(new CNG(rng.nextRNG(), 0.745, 2) + .scale(0.1)) + .fractureWith(new CNG(rng.nextRNG(), 1, 3) + .scale(0.15), 24), 44); + } + + public double getHeight(double x, double z) + { + return gen.noise(x, z); + } + + @Override + public double generateLayer(double gnoise, double dx, double dz) + { + double d = gen.noise(gnoise, dx + (fract.noise(gnoise, dx, dz) * 1555), dz - (fract.noise(dz, dx, gnoise) * 1555)); + + if(d > g.noise(dx, dz) / 8D) + { + return q.noise(dx, dz, d) * (d / (7D * (g.noise(dz, dx, gnoise) + 0.1))) * (Math.PI / 2.78); + } + + return 0; + } +} diff --git a/src/main/java/ninja/bytecode/iris/pop/PopulatorLakes.java b/src/main/java/ninja/bytecode/iris/pop/PopulatorLakes.java new file mode 100644 index 000000000..f68d804bb --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/pop/PopulatorLakes.java @@ -0,0 +1,112 @@ +package ninja.bytecode.iris.pop; + +import java.util.Random; + +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.generator.BlockPopulator; + +import ninja.bytecode.shuriken.bench.PrecisionStopwatch; +import ninja.bytecode.shuriken.math.RollingSequence; + +public class PopulatorLakes extends BlockPopulator +{ + public static RollingSequence timings = new RollingSequence(512); + + @Override + public void populate(World world, Random random, Chunk chunk) + { + PrecisionStopwatch f = PrecisionStopwatch.start(); + + if(random.nextInt(100) < 10) + { + Block block; + int chunkX = chunk.getX(); + int chunkZ = chunk.getZ(); + int X = chunkX * 16 + random.nextInt(15) - 8; + int Z = chunkZ * 16 + random.nextInt(15) - 8; + int Y; + for(Y = world.getMaxHeight() - 1; chunk.getBlock(X, Y, Z).getType() == Material.AIR; Y--) + ; + Y -= 7; + block = world.getBlockAt(Z + 8, Y, Z + 8); + if(random.nextInt(100) < 90) + block.setType(Material.WATER); + else + block.setType(Material.LAVA); + boolean[] aboolean = new boolean[2048]; + int i = random.nextInt(4) + 4; + + int j, j1, k1; + + for(j = 0; j < i; ++j) + { + double d0 = random.nextDouble() * 6.0D + 3.0D; + double d1 = random.nextDouble() * 4.0D + 2.0D; + double d2 = random.nextDouble() * 6.0D + 3.0D; + double d3 = random.nextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D; + double d4 = random.nextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D; + double d5 = random.nextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D; + + for(int k = 1; k < 15; ++k) + { + for(int l = 1; l < 15; ++l) + { + for(int i1 = 1; i1 < 7; ++i1) + { + double d6 = ((double) k - d3) / (d0 / 2.0D); + double d7 = ((double) i1 - d4) / (d1 / 2.0D); + double d8 = ((double) l - d5) / (d2 / 2.0D); + double d9 = d6 * d6 + d7 * d7 + d8 * d8; + + if(d9 < 1.0D) + { + aboolean[(k * 16 + l) * 8 + i1] = true; + } + } + } + } + } + + for(j = 0; j < 16; ++j) + { + for(k1 = 0; k1 < 16; ++k1) + { + for(j1 = 0; j1 < 8; ++j1) + { + if(aboolean[(j * 16 + k1) * 8 + j1]) + { + world.getBlockAt(X + j, Y + j1, Z + k1).setType(j1 > 4 ? Material.AIR : block.getType()); + } + } + } + } + + for(j = 0; j < 16; ++j) + { + for(k1 = 0; k1 < 16; ++k1) + { + for(j1 = 4; j1 < 8; ++j1) + { + if(aboolean[(j * 16 + k1) * 8 + j1]) + { + int X1 = X + j; + int Y1 = Y + j1 - 1; + int Z1 = Z + k1; + if(world.getBlockAt(X1, Y1, Z1).getType() == Material.DIRT) + { + world.getBlockAt(X1, Y1, Z1).setType(Material.GRASS, false); + } + } + } + } + } + } + + f.end(); + timings.put(f.getMilliseconds()); + } + +} diff --git a/src/main/java/ninja/bytecode/iris/pop/PopulatorTrees.java b/src/main/java/ninja/bytecode/iris/pop/PopulatorTrees.java new file mode 100644 index 000000000..9cb280efe --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/pop/PopulatorTrees.java @@ -0,0 +1,61 @@ +package ninja.bytecode.iris.pop; + +import java.util.Random; + +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.TreeType; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; + +import ninja.bytecode.iris.biome.CBI; +import ninja.bytecode.shuriken.bench.PrecisionStopwatch; +import ninja.bytecode.shuriken.math.RollingSequence; + +public class PopulatorTrees extends BlockPopulator +{ + public static RollingSequence timings = new RollingSequence(512); + + @Override + public void populate(World world, Random random, Chunk source) + { + PrecisionStopwatch f = PrecisionStopwatch.start(); + int debuff = 0; + + for(int i = 0; i < 16; i++) + { + if(debuff > 0) + { + debuff--; + continue; + } + + int x = random.nextInt(15) + (source.getX() * 16); + int z = random.nextInt(15) + (source.getZ() * 16); + int y = world.getHighestBlockYAt(x, z); + Location l = new Location(world, x, y, z); + + if(!l.getBlock().getType().isSolid()) + { + l.getBlock().setType(Material.AIR, false); + } + + CBI biome = CBI.find(world.getBiome(x, z)); + TreeType tt = biome.getTreeChanceSingle(); + + if(tt != null) + { + world.generateTree(l, tt); + } + + else + { + debuff += 4; + } + } + + f.end(); + timings.put(f.getMilliseconds()); + } +}