diff --git a/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java b/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java index 51aaefb61..398413ff0 100644 --- a/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java +++ b/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java @@ -18,12 +18,14 @@ package com.volmit.iris.engine.actuator; +import com.volmit.iris.Iris; import com.volmit.iris.engine.decorator.*; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedActuator; import com.volmit.iris.engine.framework.EngineDecorator; import com.volmit.iris.engine.hunk.Hunk; import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisCaveLayer; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.PrecisionStopwatch; @@ -31,10 +33,12 @@ import lombok.Getter; import org.bukkit.Material; import org.bukkit.block.data.BlockData; +import java.util.function.BiPredicate; import java.util.function.Predicate; public class IrisDecorantActuator extends EngineAssignedActuator { private static final Predicate PREDICATE_SOLID = (b) -> b != null && !b.getMaterial().isAir() && !b.getMaterial().equals(Material.WATER) && !b.getMaterial().equals(Material.LAVA); + private static BiPredicate PREDICATE_CAVELIQUID = (d, i) -> false; private final RNG rng; @Getter private final EngineDecorator surfaceDecorator; @@ -57,6 +61,21 @@ public class IrisDecorantActuator extends EngineAssignedActuator { seaSurfaceDecorator = new IrisSeaSurfaceDecorator(getEngine()); shoreLineDecorator = new IrisShoreLineDecorator(getEngine()); seaFloorDecorator = new IrisSeaFloorDecorator(getEngine()); + + PREDICATE_CAVELIQUID = (b, y) -> { + for (IrisCaveLayer layer : getEngine().getDimension().getCaveLayers()) { + if (!layer.getFluid().hasFluid(getData())) { + continue; + } + + if (layer.getFluid().isInverseHeight() && y >= layer.getFluid().getFluidHeight()) { + if (b.matches(layer.getFluid().getFluid(getData()))) return true; + } else if (!layer.getFluid().isInverseHeight() && y <= layer.getFluid().getFluidHeight()) { + if (b.matches(layer.getFluid().getFluid(getData()))) return true; + } + } + return false; + }; } @BlockCoordinates @@ -71,10 +90,12 @@ public class IrisDecorantActuator extends EngineAssignedActuator { int j, realX, realZ, height; IrisBiome biome, cave; + for (int i = 0; i < output.getWidth(); i++) { for (j = 0; j < output.getDepth(); j++) { - boolean solid; + boolean solid, liquid; int emptyFor = 0; + int liquidFor = 0; int lastSolid = 0; realX = (int) Math.round(modX(x + i)); realZ = (int) Math.round(modZ(z + j)); @@ -90,12 +111,12 @@ public class IrisDecorantActuator extends EngineAssignedActuator { getShoreLineDecorator().decorate(i, j, realX, (int) Math.round(modX(x + i + 1)), (int) Math.round(modX(x + i - 1)), realZ, (int) Math.round(modZ(z + j + 1)), (int) Math.round(modZ(z + j - 1)), - output, biome, height, getEngine().getHeight() - height); + output, biome, height, getEngine().getHeight()); } else if (height == getDimension().getFluidHeight() + 1) { getSeaSurfaceDecorator().decorate(i, j, realX, (int) Math.round(modX(x + i + 1)), (int) Math.round(modX(x + i - 1)), realZ, (int) Math.round(modZ(z + j + 1)), (int) Math.round(modZ(z + j - 1)), - output, biome, height, getEngine().getHeight() - getDimension().getFluidHeight()); + output, biome, height, getEngine().getHeight()); } else if (height < getDimension().getFluidHeight()) { getSeaFloorDecorator().decorate(i, j, realX, realZ, output, biome, height + 1, getDimension().getFluidHeight()); } @@ -105,16 +126,24 @@ public class IrisDecorantActuator extends EngineAssignedActuator { if (cave != null && cave.getDecorators().isNotEmpty()) { for (int k = height; k > 0; k--) { solid = PREDICATE_SOLID.test(output.get(i, k, j)); + liquid = PREDICATE_CAVELIQUID.test(output.get(i, k + 1, j), k + 1); if (solid) { if (emptyFor > 0) { - getSurfaceDecorator().decorate(i, j, realX, realZ, output, cave, k, emptyFor); - getCeilingDecorator().decorate(i, j, realX, realZ, output, cave, lastSolid - 1, emptyFor); + if (liquid) { + getSeaFloorDecorator().decorate(i, j, realX, realZ, output, cave, k + 1, liquidFor + lastSolid - emptyFor); + getSeaSurfaceDecorator().decorate(i, j, realX, realZ, output, cave, k + liquidFor + 1, emptyFor - liquidFor + lastSolid); + } else { + getSurfaceDecorator().decorate(i, j, realX, realZ, output, cave, k, emptyFor); + getCeilingDecorator().decorate(i, j, realX, realZ, output, cave, lastSolid - 1, emptyFor); + } emptyFor = 0; + liquidFor = 0; } lastSolid = k; } else { emptyFor++; + if (liquid) liquidFor++; } } } diff --git a/src/main/java/com/volmit/iris/engine/decorator/IrisSeaFloorDecorator.java b/src/main/java/com/volmit/iris/engine/decorator/IrisSeaFloorDecorator.java index 5caa572d0..b0a45e309 100644 --- a/src/main/java/com/volmit/iris/engine/decorator/IrisSeaFloorDecorator.java +++ b/src/main/java/com/volmit/iris/engine/decorator/IrisSeaFloorDecorator.java @@ -35,36 +35,30 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator { @BlockCoordinates @Override public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk data, IrisBiome biome, int height, int max) { - if (height <= getDimension().getFluidHeight()) { + IrisDecorator decorator = getDecorator(biome, realX, realZ); - IrisDecorator decorator = getDecorator(biome, realX, realZ); + if (decorator != null) { + if (!decorator.isStacking()) { + if (height >= 0 || height < getEngine().getHeight()) { + data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData())); + } + } else { + int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); + stack = Math.min(stack, max - height + 1); - if (decorator != null) { - if (!decorator.isStacking()) { - if (height >= 0 || height < getEngine().getHeight()) { - data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData())); + BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData()); + BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); + + for (int i = 0; i < stack; i++) { + if (height + i > max || height + i > getEngine().getHeight()) { + continue; } - } else { - int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); - stack = Math.min(stack, getDimension().getFluidHeight() - height + 2); - BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData()); - BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); - - for (int i = 0; i < stack; i++) { - if (height - i < 0 || height - i > getEngine().getHeight()) { - continue; - } - - if (height + i > getDimension().getFluidHeight()) { - continue; - } - - double threshold = ((double) i) / (stack - 1); - data.set(x, height + i, z, threshold >= decorator.getTopThreshold() ? top : fill); - } + double threshold = ((double) i) / (stack - 1); + data.set(x, height + i, z, threshold >= decorator.getTopThreshold() ? top : fill); } } } + } } diff --git a/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java b/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java index 6c19c5825..a00280bcf 100644 --- a/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java +++ b/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java @@ -40,7 +40,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { if (decorator != null) { if (!decorator.isStacking()) { if (height >= 0 || height < getEngine().getHeight()) { - data.set(x, getDimension().getFluidHeight() + 1, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData())); + data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData())); } } else { int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); @@ -48,12 +48,12 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); for (int i = 0; i < stack; i++) { - if (height - i < 0 || height - i > getEngine().getHeight()) { + if (height + i >= max || height + i >= getEngine().getHeight()) { continue; } double threshold = ((double) i) / (stack - 1); - data.set(x, getDimension().getFluidHeight() + 1 + i, z, threshold >= decorator.getTopThreshold() ? top : fill); + data.set(x, height + 1 + i, z, threshold >= decorator.getTopThreshold() ? top : fill); } } } diff --git a/src/main/java/com/volmit/iris/engine/decorator/IrisShoreLineDecorator.java b/src/main/java/com/volmit/iris/engine/decorator/IrisShoreLineDecorator.java index 7cd34c40a..768e89c87 100644 --- a/src/main/java/com/volmit/iris/engine/decorator/IrisShoreLineDecorator.java +++ b/src/main/java/com/volmit/iris/engine/decorator/IrisShoreLineDecorator.java @@ -49,7 +49,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator { data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData())); } else { int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); - + stack = Math.min(max - height + 1, stack); BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); diff --git a/src/main/java/com/volmit/iris/engine/decorator/IrisSurfaceDecorator.java b/src/main/java/com/volmit/iris/engine/decorator/IrisSurfaceDecorator.java index caff5114e..e6d10a507 100644 --- a/src/main/java/com/volmit/iris/engine/decorator/IrisSurfaceDecorator.java +++ b/src/main/java/com/volmit/iris/engine/decorator/IrisSurfaceDecorator.java @@ -73,10 +73,11 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator { } else { if (height < getDimension().getFluidHeight()) { - max = getDimension().getFluidHeight() - height; + max = getDimension().getFluidHeight(); } int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); + stack = Math.min(height - max + 1, stack); BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData());