Cave Decorator Changes

- Surface decorators are no longer placed below liquids in caves
- SEA_FLOOR and SEA_SURFACE decorators now function within caves relative to the cave liquid
- Fixed stacked decorators going above the height of caves and the map
This commit is contained in:
StrangeOne101 2021-07-26 20:04:06 +12:00
parent f8ae842971
commit 64f361d4b1
5 changed files with 58 additions and 34 deletions

View File

@ -18,12 +18,14 @@
package com.volmit.iris.engine.actuator; package com.volmit.iris.engine.actuator;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.decorator.*; import com.volmit.iris.engine.decorator.*;
import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineAssignedActuator; import com.volmit.iris.engine.framework.EngineAssignedActuator;
import com.volmit.iris.engine.framework.EngineDecorator; import com.volmit.iris.engine.framework.EngineDecorator;
import com.volmit.iris.engine.hunk.Hunk; import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.engine.object.IrisBiome; 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.documentation.BlockCoordinates;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.scheduling.PrecisionStopwatch;
@ -31,10 +33,12 @@ import lombok.Getter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import java.util.function.BiPredicate;
import java.util.function.Predicate; import java.util.function.Predicate;
public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> { public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
private static final Predicate<BlockData> PREDICATE_SOLID = (b) -> b != null && !b.getMaterial().isAir() && !b.getMaterial().equals(Material.WATER) && !b.getMaterial().equals(Material.LAVA); private static final Predicate<BlockData> PREDICATE_SOLID = (b) -> b != null && !b.getMaterial().isAir() && !b.getMaterial().equals(Material.WATER) && !b.getMaterial().equals(Material.LAVA);
private static BiPredicate<BlockData, Integer> PREDICATE_CAVELIQUID = (d, i) -> false;
private final RNG rng; private final RNG rng;
@Getter @Getter
private final EngineDecorator surfaceDecorator; private final EngineDecorator surfaceDecorator;
@ -57,6 +61,21 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
seaSurfaceDecorator = new IrisSeaSurfaceDecorator(getEngine()); seaSurfaceDecorator = new IrisSeaSurfaceDecorator(getEngine());
shoreLineDecorator = new IrisShoreLineDecorator(getEngine()); shoreLineDecorator = new IrisShoreLineDecorator(getEngine());
seaFloorDecorator = new IrisSeaFloorDecorator(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 @BlockCoordinates
@ -71,10 +90,12 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
int j, realX, realZ, height; int j, realX, realZ, height;
IrisBiome biome, cave; IrisBiome biome, cave;
for (int i = 0; i < output.getWidth(); i++) { for (int i = 0; i < output.getWidth(); i++) {
for (j = 0; j < output.getDepth(); j++) { for (j = 0; j < output.getDepth(); j++) {
boolean solid; boolean solid, liquid;
int emptyFor = 0; int emptyFor = 0;
int liquidFor = 0;
int lastSolid = 0; int lastSolid = 0;
realX = (int) Math.round(modX(x + i)); realX = (int) Math.round(modX(x + i));
realZ = (int) Math.round(modZ(z + j)); realZ = (int) Math.round(modZ(z + j));
@ -90,12 +111,12 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
getShoreLineDecorator().decorate(i, j, getShoreLineDecorator().decorate(i, j,
realX, (int) Math.round(modX(x + i + 1)), (int) Math.round(modX(x + i - 1)), 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)), 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) { } else if (height == getDimension().getFluidHeight() + 1) {
getSeaSurfaceDecorator().decorate(i, j, getSeaSurfaceDecorator().decorate(i, j,
realX, (int) Math.round(modX(x + i + 1)), (int) Math.round(modX(x + i - 1)), 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)), 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()) { } else if (height < getDimension().getFluidHeight()) {
getSeaFloorDecorator().decorate(i, j, realX, realZ, output, biome, height + 1, getDimension().getFluidHeight()); getSeaFloorDecorator().decorate(i, j, realX, realZ, output, biome, height + 1, getDimension().getFluidHeight());
} }
@ -105,16 +126,24 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
if (cave != null && cave.getDecorators().isNotEmpty()) { if (cave != null && cave.getDecorators().isNotEmpty()) {
for (int k = height; k > 0; k--) { for (int k = height; k > 0; k--) {
solid = PREDICATE_SOLID.test(output.get(i, k, j)); solid = PREDICATE_SOLID.test(output.get(i, k, j));
liquid = PREDICATE_CAVELIQUID.test(output.get(i, k + 1, j), k + 1);
if (solid) { if (solid) {
if (emptyFor > 0) { if (emptyFor > 0) {
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); getSurfaceDecorator().decorate(i, j, realX, realZ, output, cave, k, emptyFor);
getCeilingDecorator().decorate(i, j, realX, realZ, output, cave, lastSolid - 1, emptyFor); getCeilingDecorator().decorate(i, j, realX, realZ, output, cave, lastSolid - 1, emptyFor);
}
emptyFor = 0; emptyFor = 0;
liquidFor = 0;
} }
lastSolid = k; lastSolid = k;
} else { } else {
emptyFor++; emptyFor++;
if (liquid) liquidFor++;
} }
} }
} }

View File

@ -35,8 +35,6 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
@BlockCoordinates @BlockCoordinates
@Override @Override
public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk<BlockData> data, IrisBiome biome, int height, int max) { public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk<BlockData> 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 != null) {
@ -46,17 +44,13 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
} }
} else { } else {
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
stack = Math.min(stack, getDimension().getFluidHeight() - height + 2); stack = Math.min(stack, max - height + 1);
BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData()); BlockData top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData());
BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData());
for (int i = 0; i < stack; i++) { for (int i = 0; i < stack; i++) {
if (height - i < 0 || height - i > getEngine().getHeight()) { if (height + i > max || height + i > getEngine().getHeight()) {
continue;
}
if (height + i > getDimension().getFluidHeight()) {
continue; continue;
} }
@ -65,6 +59,6 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
} }
} }
} }
}
} }
} }

View File

@ -40,7 +40,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
if (decorator != null) { if (decorator != null) {
if (!decorator.isStacking()) { if (!decorator.isStacking()) {
if (height >= 0 || height < getEngine().getHeight()) { 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 { } else {
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); 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 top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData());
BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData());
for (int i = 0; i < stack; i++) { for (int i = 0; i < stack; i++) {
if (height - i < 0 || height - i > getEngine().getHeight()) { if (height + i >= max || height + i >= getEngine().getHeight()) {
continue; continue;
} }
double threshold = ((double) i) / (stack - 1); 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);
} }
} }
} }

View File

@ -49,7 +49,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData())); data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, realZ, getData()));
} else { } else {
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); 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 top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData());
BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData());

View File

@ -73,10 +73,11 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
} else { } else {
if (height < getDimension().getFluidHeight()) { if (height < getDimension().getFluidHeight()) {
max = getDimension().getFluidHeight() - height; max = getDimension().getFluidHeight();
} }
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData()); 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 top = decorator.getBlockDataForTop(biome, getRng(), realX, realZ, getData());
BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData()); BlockData fill = decorator.getBlockData100(biome, getRng(), realX, realZ, getData());