From 7d4b980e596acef315daff8a1709b311432a9f50 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 28 Jul 2020 20:49:35 -0400 Subject: [PATCH] Speed --- src/main/java/com/volmit/iris/Iris.java | 19 ++++++ .../java/com/volmit/iris/IrisMetrics.java | 6 ++ .../iris/generator/BiomeChunkGenerator.java | 4 +- .../iris/generator/IrisChunkGenerator.java | 12 ++++ .../generator/ParallaxChunkGenerator.java | 59 ++++++++++++++++--- .../generator/ParallelChunkGenerator.java | 25 ++++++++ .../generator/PostBlockChunkGenerator.java | 24 +++++++- .../iris/generator/TerrainChunkGenerator.java | 29 ++++++++- .../layer/post/PostFloatingNippleDeleter.java | 52 ++++++++++++++++ .../iris/layer/post/PostNippleSmoother.java | 8 ++- .../iris/layer/post/PostPotholeFiller.java | 8 ++- .../volmit/iris/layer/post/PostSlabber.java | 16 ++--- .../iris/layer/post/PostWallPatcher.java | 18 ++++-- .../iris/layer/post/PostWaterlogger.java | 54 +++++++++++++++++ .../volmit/iris/util/IPostBlockAccess.java | 4 ++ .../volmit/iris/util/IrisPostBlockFilter.java | 25 ++++++++ 16 files changed, 337 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/volmit/iris/layer/post/PostFloatingNippleDeleter.java create mode 100644 src/main/java/com/volmit/iris/layer/post/PostWaterlogger.java diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 034aea957..33a38cf75 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -257,6 +257,25 @@ public class Iris extends JavaPlugin implements BoardProvider } } + if(args[0].equalsIgnoreCase("metrics")) + { + if(sender instanceof Player) + { + Player p = (Player) sender; + World world = p.getWorld(); + IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); + IrisMetrics m = g.getMetrics(); + + imsg(sender, "Thread Count: " + ChatColor.BOLD + "" + ChatColor.WHITE + g.getThreads()); + imsg(sender, "Total : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTotal().getAverage(), 2)); + imsg(sender, " Terrain : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTerrain().getAverage(), 2)); + imsg(sender, " Parallax: " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getParallax().getAverage(), 2)); + imsg(sender, " Post : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getPost().getAverage(), 2)); + + return true; + } + } + if(args[0].equalsIgnoreCase("what")) { if(args.length != 2) diff --git a/src/main/java/com/volmit/iris/IrisMetrics.java b/src/main/java/com/volmit/iris/IrisMetrics.java index b60c4cc47..a849ea99c 100644 --- a/src/main/java/com/volmit/iris/IrisMetrics.java +++ b/src/main/java/com/volmit/iris/IrisMetrics.java @@ -7,6 +7,9 @@ import lombok.Data; @Data public class IrisMetrics { + private final RollingSequence parallax; + private final RollingSequence terrain; + private final RollingSequence post; private final RollingSequence total; private final RollingSequence perSecond; private final RollingSequence loss; @@ -15,6 +18,9 @@ public class IrisMetrics public IrisMetrics(int memory) { + parallax = new RollingSequence(memory); + terrain = new RollingSequence(memory); + post = new RollingSequence(memory); total = new RollingSequence(memory); perSecond = new RollingSequence(5); loss = new RollingSequence(memory); diff --git a/src/main/java/com/volmit/iris/generator/BiomeChunkGenerator.java b/src/main/java/com/volmit/iris/generator/BiomeChunkGenerator.java index 13a2cf10a..a49b1d401 100644 --- a/src/main/java/com/volmit/iris/generator/BiomeChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/BiomeChunkGenerator.java @@ -57,12 +57,12 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator masterFracture = CNG.signature(rng.nextParallelRNG(13)).scale(0.12); } - protected IrisBiome getCachedBiome(int x, int z) + protected IrisBiome getCachedInternalBiome(int x, int z) { return biomeCache[(z << 4) | x]; } - protected void cacheBiome(int x, int z, IrisBiome b) + protected void cacheInternalBiome(int x, int z, IrisBiome b) { biomeCache[(z << 4) | x] = b; } diff --git a/src/main/java/com/volmit/iris/generator/IrisChunkGenerator.java b/src/main/java/com/volmit/iris/generator/IrisChunkGenerator.java index 2d102cfee..850496fd1 100644 --- a/src/main/java/com/volmit/iris/generator/IrisChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/IrisChunkGenerator.java @@ -1,6 +1,7 @@ package com.volmit.iris.generator; import java.lang.reflect.Method; +import java.util.concurrent.locks.ReentrantLock; import org.bukkit.Chunk; import org.bukkit.entity.Player; @@ -11,6 +12,7 @@ import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisRegion; import com.volmit.iris.util.BiomeResult; import com.volmit.iris.util.KMap; +import com.volmit.iris.util.RNG; import lombok.Data; import lombok.EqualsAndHashCode; @@ -20,11 +22,21 @@ import lombok.EqualsAndHashCode; public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisContext { private Method initLighting; + private ReentrantLock lock; private KMap b = new KMap<>(); public IrisChunkGenerator(String dimensionName, int threads) { super(dimensionName, threads); + lock = new ReentrantLock(); + } + + @Override + protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) + { + lock.lock(); + super.onGenerate(random, x, z, data, grid); + lock.unlock(); } @Override diff --git a/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java b/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java index c01378908..98c5c09c1 100644 --- a/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java @@ -22,6 +22,8 @@ import com.volmit.iris.util.HeightMap; import com.volmit.iris.util.IObjectPlacer; import com.volmit.iris.util.KList; import com.volmit.iris.util.KMap; +import com.volmit.iris.util.NastyRunnable; +import com.volmit.iris.util.PrecisionStopwatch; import com.volmit.iris.util.RNG; import lombok.Data; @@ -37,6 +39,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple protected AtomicWorldData ceilingParallaxMap; private MasterLock masterLock; private ReentrantLock lock = new ReentrantLock(); + private ReentrantLock lockq = new ReentrantLock(); private int sliverBuffer; public ParallaxChunkGenerator(String dimensionName, int threads) @@ -154,7 +157,10 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple @Override protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) { + setCaching(false); + getSliverCache().clear(); super.onPostGenerate(random, x, z, data, grid, height, biomeMap); + PrecisionStopwatch p = PrecisionStopwatch.start(); getBiomeHitCache().clear(); if(getDimension().isPlaceObjects()) @@ -164,11 +170,13 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple getParallaxChunk(x, z).inject(data); setSliverBuffer(getSliverCache().size()); getParallaxChunk(x, z).setWorldGenerated(true); - getSliverCache().clear(); getMasterLock().clear(); } + p.end(); + getMetrics().getParallax().put(p.getMilliseconds()); super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap); + setCaching(true); } protected void injectBiomeSky(int x, int z, BiomeGrid grid) @@ -193,7 +201,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple if(min < max) { - IrisBiome biome = getCachedBiome(i, j); + IrisBiome biome = getCachedInternalBiome(i, j); for(int g = min; g <= max; g++) { @@ -208,6 +216,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple { String key = "par." + x + "." + "z"; ChunkPosition rad = Iris.data.getObjectLoader().getParallaxSize(); + KList q = new KList<>(); for(int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++) { @@ -237,14 +246,25 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple for(IrisObjectPlacement k : b.getObjects()) { - placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 3569222)); + int gg = g++; + lockq.lock(); + q.add(() -> + { + placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222)); + }); + lockq.unlock(); } for(IrisDepositGenerator k : getDimension().getDeposits()) { for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) { - k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); + lockq.lock(); + q.add(() -> + { + k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); + }); + lockq.unlock(); } } @@ -252,7 +272,12 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple { for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) { - k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); + lockq.lock(); + q.add(() -> + { + k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); + }); + lockq.unlock(); } } @@ -260,7 +285,12 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple { for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) { - k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); + lockq.lock(); + q.add(() -> + { + k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); + }); + lockq.unlock(); } } @@ -283,7 +313,13 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple for(IrisObjectPlacement k : biome.getObjects()) { - placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 1869322)); + int gg = g++; + lockq.lock(); + q.add(() -> + { + placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322)); + }); + lockq.unlock(); } } }); @@ -293,6 +329,15 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple } getAccelerant().waitFor(key); + + lockq.lock(); + for(NastyRunnable i : q) + { + getAccelerant().queue(key + "-obj", i); + } + lockq.unlock(); + + getAccelerant().waitFor(key + "-obj"); } public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng) diff --git a/src/main/java/com/volmit/iris/generator/ParallelChunkGenerator.java b/src/main/java/com/volmit/iris/generator/ParallelChunkGenerator.java index 8e3a32dae..f0f23cdd8 100644 --- a/src/main/java/com/volmit/iris/generator/ParallelChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/ParallelChunkGenerator.java @@ -1,5 +1,7 @@ package com.volmit.iris.generator; +import java.util.concurrent.locks.ReentrantLock; + import org.bukkit.World; import com.volmit.iris.Iris; @@ -8,6 +10,7 @@ import com.volmit.iris.object.atomics.AtomicSliverMap; import com.volmit.iris.util.BiomeMap; import com.volmit.iris.util.GroupedExecutor; import com.volmit.iris.util.HeightMap; +import com.volmit.iris.util.PrecisionStopwatch; import com.volmit.iris.util.RNG; import lombok.Data; @@ -19,11 +22,19 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator { private GroupedExecutor accelerant; private int threads; + protected boolean unsafe; + protected int cacheX; + protected int cacheZ; + private ReentrantLock genlock; public ParallelChunkGenerator(String dimensionName, int threads) { super(dimensionName); + unsafe = false; + cacheX = 0; + cacheZ = 0; this.threads = threads; + genlock = new ReentrantLock(); } public void changeThreadCount(int tc) @@ -52,11 +63,16 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) { + genlock.lock(); + cacheX = x; + cacheZ = z; + PrecisionStopwatch p = PrecisionStopwatch.start(); AtomicSliverMap map = new AtomicSliverMap(); HeightMap height = new HeightMap(); String key = "c" + x + "," + z; BiomeMap biomeMap = new BiomeMap(); int ii, jj; + unsafe = true; for(ii = 0; ii < 16; ii++) { @@ -78,7 +94,11 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator accelerant.waitFor(key); map.write(data, grid, height); + getMetrics().getTerrain().put(p.getMilliseconds()); + p = PrecisionStopwatch.start(); + unsafe = false; onPostGenerate(random, x, z, data, grid, height, biomeMap); + genlock.unlock(); } protected void onClose() @@ -92,6 +112,11 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator changeThreadCount(threads); } + public boolean isSafe() + { + return !unsafe; + } + @Override public boolean isParallelCapable() { diff --git a/src/main/java/com/volmit/iris/generator/PostBlockChunkGenerator.java b/src/main/java/com/volmit/iris/generator/PostBlockChunkGenerator.java index 381ac8bfe..d278ac1e5 100644 --- a/src/main/java/com/volmit/iris/generator/PostBlockChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/PostBlockChunkGenerator.java @@ -6,14 +6,18 @@ import org.bukkit.World; import org.bukkit.block.data.BlockData; import com.volmit.iris.Iris; +import com.volmit.iris.layer.post.PostFloatingNippleDeleter; import com.volmit.iris.layer.post.PostNippleSmoother; import com.volmit.iris.layer.post.PostPotholeFiller; import com.volmit.iris.layer.post.PostSlabber; import com.volmit.iris.layer.post.PostWallPatcher; +import com.volmit.iris.layer.post.PostWaterlogger; import com.volmit.iris.object.IrisDimension; +import com.volmit.iris.util.CaveResult; import com.volmit.iris.util.IPostBlockAccess; import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.KList; +import com.volmit.iris.util.PrecisionStopwatch; import com.volmit.iris.util.RNG; public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess @@ -41,9 +45,11 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp { super.onInit(world, rng); filters.add(new PostNippleSmoother(this)); + filters.add(new PostFloatingNippleDeleter(this)); filters.add(new PostPotholeFiller(this)); - filters.add(new PostWallPatcher(this)); filters.add(new PostSlabber(this)); + filters.add(new PostWallPatcher(this)); + filters.add(new PostWaterlogger(this)); } @Override @@ -61,6 +67,8 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp currentPostZ = z; int rx, i, j; + PrecisionStopwatch p = PrecisionStopwatch.start(); + for(i = 0; i < 16; i++) { rx = (x * 16) + i; @@ -84,6 +92,14 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp } getAccelerant().waitFor(postKey); + p.end(); + getMetrics().getPost().put(p.getMilliseconds()); + } + + @Override + public void updateHeight(int x, int z, int h) + { + getCacheHeightMap()[(z << 4) | x] = h; } @Override @@ -127,4 +143,10 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp { return getHighest(x, z, true); } + + @Override + public KList caveFloors(int x, int z) + { + return getCaves(x, z); + } } diff --git a/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java b/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java index 655231c89..ea311ce18 100644 --- a/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java @@ -1,5 +1,7 @@ package com.volmit.iris.generator; +import java.util.concurrent.locks.ReentrantLock; + import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.data.Bisected; @@ -33,10 +35,18 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator private long lastChunkLoad = M.ms(); private GenLayerCave glCave; private RNG rockRandom; + private int[] cacheHeightMap; + private IrisBiome[] cacheTrueBiome; + private ReentrantLock cacheLock; + private boolean caching; public TerrainChunkGenerator(String dimensionName, int threads) { super(dimensionName, threads); + cacheHeightMap = new int[256]; + cacheTrueBiome = new IrisBiome[256]; + caching = true; + cacheLock = new ReentrantLock(); } public void onInit(World world, RNG rng) @@ -67,9 +77,16 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator int height = (int) Math.round(noise) + fluidHeight; IrisRegion region = sampleRegion(rx, rz); IrisBiome biome = sampleTrueBiome(rx, rz).getBiome(); + if(caching) + { + cacheLock.lock(); + cacheTrueBiome[(z << 4) | x] = biome; + cacheHeightMap[(z << 4) | x] = height; + cacheLock.unlock(); + } KList layers = biome.generateLayers(wx, wz, masterRandom, height, height - getFluidHeight()); KList seaLayers = biome.isSea() ? biome.generateSeaLayers(wx, wz, masterRandom, fluidHeight - height) : new KList<>(); - cacheBiome(x, z, biome); + cacheInternalBiome(x, z, biome); // Set ground biome (color) to HEIGHT - HEIGHT+3 for(int k = Math.max(height, fluidHeight); k < Math.max(height, fluidHeight) + 3; k++) @@ -461,6 +478,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator return focus(); } + if(isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) + { + return new BiomeResult(cacheTrueBiome[((z & 15) << 4) | (x & 15)], 0); + } + double wx = getModifiedX(x, z); double wz = getModifiedZ(x, z); IrisRegion region = sampleRegion(x, z); @@ -508,6 +530,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator public double getTerrainHeight(int x, int z) { + if(isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) + { + return cacheHeightMap[((z & 15) << 4) | (x & 15)]; + } + return getNoiseHeight(x, z) + getFluidHeight(); } diff --git a/src/main/java/com/volmit/iris/layer/post/PostFloatingNippleDeleter.java b/src/main/java/com/volmit/iris/layer/post/PostFloatingNippleDeleter.java new file mode 100644 index 000000000..7fda60402 --- /dev/null +++ b/src/main/java/com/volmit/iris/layer/post/PostFloatingNippleDeleter.java @@ -0,0 +1,52 @@ +package com.volmit.iris.layer.post; + +import org.bukkit.block.data.BlockData; + +import com.volmit.iris.generator.PostBlockChunkGenerator; +import com.volmit.iris.util.BlockDataTools; +import com.volmit.iris.util.IrisPostBlockFilter; + +public class PostFloatingNippleDeleter extends IrisPostBlockFilter +{ + private static final BlockData AIR = BlockDataTools.getBlockData("AIR"); + + public PostFloatingNippleDeleter(PostBlockChunkGenerator gen) + { + super(gen); + } + + @Override + public void onPost(int x, int z) + { + int g = 0; + int h = highestTerrainBlock(x, z); + + if(h < 1) + { + return; + } + + int ha = highestTerrainBlock(x + 1, z); + int hb = highestTerrainBlock(x, z + 1); + int hc = highestTerrainBlock(x - 1, z); + int hd = highestTerrainBlock(x, z - 1); + g += ha < h - 1 ? 1 : 0; + g += hb < h - 1 ? 1 : 0; + g += hc < h - 1 ? 1 : 0; + g += hd < h - 1 ? 1 : 0; + + if(g == 4 && isAir(x, h - 1, z)) + { + setPostBlock(x, h, z, AIR); + + for(int i = h - 1; i > 0; i--) + { + if(!isAir(x, i, z)) + { + updateHeight(x, z, i); + break; + } + } + } + } +} diff --git a/src/main/java/com/volmit/iris/layer/post/PostNippleSmoother.java b/src/main/java/com/volmit/iris/layer/post/PostNippleSmoother.java index 84a50c95a..239f5f0f1 100644 --- a/src/main/java/com/volmit/iris/layer/post/PostNippleSmoother.java +++ b/src/main/java/com/volmit/iris/layer/post/PostNippleSmoother.java @@ -16,13 +16,18 @@ public class PostNippleSmoother extends IrisPostBlockFilter @Override public void onPost(int x, int z) { + int g = 0; int h = highestTerrainBlock(x, z); int ha = highestTerrainBlock(x + 1, z); int hb = highestTerrainBlock(x, z + 1); int hc = highestTerrainBlock(x - 1, z); int hd = highestTerrainBlock(x, z - 1); + g += ha == h - 1 ? 1 : 0; + g += hb == h - 1 ? 1 : 0; + g += hc == h - 1 ? 1 : 0; + g += hd == h - 1 ? 1 : 0; - if(ha == h - 1 && hb == h - 1 && hc == h - 1 && hd == h - 1) + if(g >= 3) { BlockData bc = getPostBlock(x, h, z); BlockData b = getPostBlock(x, h + 1, z); @@ -31,6 +36,7 @@ public class PostNippleSmoother extends IrisPostBlockFilter if(m.isSolid()) { setPostBlock(x, h, z, b); + updateHeight(x, z, h - 1); } } } diff --git a/src/main/java/com/volmit/iris/layer/post/PostPotholeFiller.java b/src/main/java/com/volmit/iris/layer/post/PostPotholeFiller.java index 536f4a386..678886b24 100644 --- a/src/main/java/com/volmit/iris/layer/post/PostPotholeFiller.java +++ b/src/main/java/com/volmit/iris/layer/post/PostPotholeFiller.java @@ -13,15 +13,21 @@ public class PostPotholeFiller extends IrisPostBlockFilter @Override public void onPost(int x, int z) { + int g = 0; int h = highestTerrainBlock(x, z); int ha = highestTerrainBlock(x + 1, z); int hb = highestTerrainBlock(x, z + 1); int hc = highestTerrainBlock(x - 1, z); int hd = highestTerrainBlock(x, z - 1); + g += ha == h + 1 ? 1 : 0; + g += hb == h + 1 ? 1 : 0; + g += hc == h + 1 ? 1 : 0; + g += hd == h + 1 ? 1 : 0; - if(ha == h + 1 && hb == h + 1 && hc == h + 1 && hd == h + 1) + if(g >= 3) { setPostBlock(x, h + 1, z, getPostBlock(x, h, z)); + updateHeight(x, z, h + 1); } } } diff --git a/src/main/java/com/volmit/iris/layer/post/PostSlabber.java b/src/main/java/com/volmit/iris/layer/post/PostSlabber.java index de23419a3..e8d8cdff6 100644 --- a/src/main/java/com/volmit/iris/layer/post/PostSlabber.java +++ b/src/main/java/com/volmit/iris/layer/post/PostSlabber.java @@ -2,7 +2,6 @@ package com.volmit.iris.layer.post; import org.bukkit.Material; import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Waterlogged; import com.volmit.iris.generator.PostBlockChunkGenerator; import com.volmit.iris.util.IrisPostBlockFilter; @@ -24,10 +23,15 @@ public class PostSlabber extends IrisPostBlockFilter public void onPost(int x, int z) { int h = highestTerrainBlock(x, z); + int ha = highestTerrainBlock(x + 1, z); + int hb = highestTerrainBlock(x, z + 1); + int hc = highestTerrainBlock(x - 1, z); + int hd = highestTerrainBlock(x, z - 1); - if(highestTerrainBlock(x + 1, z) == h + 1 || highestTerrainBlock(x, z + 1) == h + 1 || highestTerrainBlock(x - 1, z) == h + 1 || highestTerrainBlock(x, z - 1) == h + 1) + if(ha == h + 1 || hb == h + 1 || hc == h + 1 || hd == h + 1) { BlockData d = gen.sampleTrueBiome(x, z).getBiome().getSlab().get(rng, x, h, z); + if(d != null) { if(d.getMaterial().equals(AIR)) @@ -35,14 +39,10 @@ public class PostSlabber extends IrisPostBlockFilter return; } - if(d instanceof Waterlogged) - { - ((Waterlogged) d).setWaterlogged(getPostBlock(x, h + 1, z).getMaterial().equals(Material.WATER)); - } - - if(getPostBlock(x, h + 2, z).getMaterial().equals(AIR) || getPostBlock(x, h + 2, z).getMaterial().equals(WATER)) + if(isAir(x, h + 2, z) || getPostBlock(x, h + 2, z).getMaterial().equals(WATER)) { setPostBlock(x, h + 1, z, d); + updateHeight(x, z, h + 1); } } } diff --git a/src/main/java/com/volmit/iris/layer/post/PostWallPatcher.java b/src/main/java/com/volmit/iris/layer/post/PostWallPatcher.java index 4747c52fc..77467ab47 100644 --- a/src/main/java/com/volmit/iris/layer/post/PostWallPatcher.java +++ b/src/main/java/com/volmit/iris/layer/post/PostWallPatcher.java @@ -23,18 +23,26 @@ public class PostWallPatcher extends IrisPostBlockFilter public void onPost(int x, int z) { IrisBiome biome = gen.sampleTrueBiome(x, z).getBiome(); + int h, ha, hb, hc, hd; if(!biome.getWall().getPalette().isEmpty()) { - int h = highestTerrainBlock(x, z); - int ha = highestTerrainBlock(x + 1, z); - int hb = highestTerrainBlock(x, z + 1); - int hc = highestTerrainBlock(x - 1, z); - int hd = highestTerrainBlock(x, z - 1); + h = highestTerrainBlock(x, z); + ha = highestTerrainBlock(x + 1, z); + hb = highestTerrainBlock(x, z + 1); + hc = highestTerrainBlock(x - 1, z); + hd = highestTerrainBlock(x, z - 1); if(ha < h - 2 || hb < h - 2 || hc < h - 2 || hd < h - 2) { int max = Math.abs(Math.max(h - ha, Math.max(h - hb, Math.max(h - hc, h - hd)))); + BlockData s = gen.sampleTrueBiome(x, z).getBiome().getSlab().get(rng, x, h, z); + + if(s != null) + { + setPostBlock(x, h + 1, z, s); + updateHeight(x, z, h + 1); + } for(int i = h; i > h - max; i--) { diff --git a/src/main/java/com/volmit/iris/layer/post/PostWaterlogger.java b/src/main/java/com/volmit/iris/layer/post/PostWaterlogger.java new file mode 100644 index 000000000..c32863c4a --- /dev/null +++ b/src/main/java/com/volmit/iris/layer/post/PostWaterlogger.java @@ -0,0 +1,54 @@ +package com.volmit.iris.layer.post; + +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; + +import com.volmit.iris.Iris; +import com.volmit.iris.generator.PostBlockChunkGenerator; +import com.volmit.iris.util.IrisPostBlockFilter; + +public class PostWaterlogger extends IrisPostBlockFilter +{ + public PostWaterlogger(PostBlockChunkGenerator gen) + { + super(gen); + } + + @Override + public void onPost(int x, int z) + { + int h = highestTerrainBlock(x, z); + BlockData b = getPostBlock(x, h, z); + + if(b instanceof Waterlogged) + { + Waterlogged ww = (Waterlogged) b; + boolean w = ww.isWaterlogged(); + + if(isWater(x, h + 1, z)) + { + ww.setWaterlogged(true); + } + + else if(h < 98) + { + Iris.info("Data is " + getPostBlock(x, h + 1, z).getAsString()); + } + + else if(isWater(x + 1, h, z) || isWater(x - 1, h, z) || isWater(x, h, z + 1) || isWater(x, h, z - 1)) + { + ww.setWaterlogged(true); + } + + else + { + ww.setWaterlogged(false); + } + + if(ww.isWaterlogged() != w) + { + setPostBlock(x, h, z, ww); + } + } + } +} diff --git a/src/main/java/com/volmit/iris/util/IPostBlockAccess.java b/src/main/java/com/volmit/iris/util/IPostBlockAccess.java index 040cfe60b..ba3c314ed 100644 --- a/src/main/java/com/volmit/iris/util/IPostBlockAccess.java +++ b/src/main/java/com/volmit/iris/util/IPostBlockAccess.java @@ -11,4 +11,8 @@ public interface IPostBlockAccess public int highestTerrainOrFluidBlock(int x, int z); public int highestTerrainBlock(int x, int z); + + public void updateHeight(int x, int z, int h); + + public KList caveFloors(int x, int z); } diff --git a/src/main/java/com/volmit/iris/util/IrisPostBlockFilter.java b/src/main/java/com/volmit/iris/util/IrisPostBlockFilter.java index 3b88f7635..7b306fda5 100644 --- a/src/main/java/com/volmit/iris/util/IrisPostBlockFilter.java +++ b/src/main/java/com/volmit/iris/util/IrisPostBlockFilter.java @@ -1,5 +1,6 @@ package com.volmit.iris.util; +import org.bukkit.Material; import org.bukkit.block.data.BlockData; import com.volmit.iris.generator.PostBlockChunkGenerator; @@ -38,4 +39,28 @@ public abstract class IrisPostBlockFilter implements IPostBlockAccess { return gen.highestTerrainBlock(x, z); } + + public boolean isAir(int x, int y, int z) + { + BlockData d = getPostBlock(x, y, z); + return d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR); + } + + public boolean isWater(int x, int y, int z) + { + BlockData d = getPostBlock(x, y, z); + return d.getMaterial().equals(Material.WATER); + } + + @Override + public KList caveFloors(int x, int z) + { + return gen.caveFloors(x, z); + } + + @Override + public void updateHeight(int x, int z, int h) + { + gen.updateHeight(x, z, h); + } }