Merge lane B structures

This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 14:11:01 -05:00
commit b08d181823
68 files changed
+2268 -319

No files matched your search

@@ -35,6 +35,7 @@ import java.util.function.Supplier;
import java.util.Objects;
import art.arcane.volmlib.util.matter.IrisMatter;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterCavern;
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
import java.util.Map;
@@ -43,14 +44,18 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
private final ObjectContinuationBundle.PlacementKey placementKey;
private final KList<BufferedMutation> mutations;
private final Map<PositionKey, NativeBlockState> bufferedBlocks;
private final boolean entersWater;
private ObjectHydrologyVeto waterVeto;
private int blockWrites;
private BlockPosition canopyPosition;
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey) {
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey,
boolean entersWater) {
this.delegate = Objects.requireNonNull(delegate);
this.placementKey = Objects.requireNonNull(placementKey);
this.mutations = new KList<>();
this.bufferedBlocks = new HashMap<>();
this.entersWater = entersWater;
}
CommitResult commit() {
@@ -156,7 +161,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
@Override
public void set(int x, int y, int z, NativeBlockState state) {
if (state == null) {
if (state == null || waterVeto().keepsBlock(x, y, z, state, entersWater)) {
return;
}
mutations.add(new BlockMutation(x, y, z, state, isCanopy(x, y, z)));
@@ -234,7 +239,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
@Override
public <T> void setData(int x, int y, int z, T data) {
if (data == null) {
if (data == null || keepsWater(x, y, z, data)) {
return;
}
mutations.add(new DataMutation(x, y, z, data, isCanopy(x, y, z)));
@@ -244,6 +249,20 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
}
}
private boolean keepsWater(int x, int y, int z, Object data) {
if (data instanceof NativeBlockState state) {
return waterVeto().keepsBlock(x, y, z, state, entersWater);
}
return data instanceof MatterCavern && waterVeto().keeps(x, y, z, false, entersWater);
}
private ObjectHydrologyVeto waterVeto() {
if (waterVeto == null) {
waterVeto = ObjectHydrologyVeto.of(delegate.getEngine());
}
return waterVeto;
}
@Override
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
for (int i = mutations.size() - 1; i >= 0; i--) {
@@ -22,11 +22,14 @@ import art.arcane.volmlib.util.structure.StructureCarvingFootprint;
import art.arcane.volmlib.util.structure.StructureCarveEnvelope;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
import art.arcane.iris.configuration.IrisSettings;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.cache.Cache;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.structure.placement.IrisStructureLocator;
import art.arcane.iris.structure.placement.IrisStructureWater;
import art.arcane.iris.structure.placement.PlacedStructurePiece;
import art.arcane.iris.structure.placement.StructurePlacementScope;
import art.arcane.iris.structure.placement.StructurePlacementMarker;
@@ -58,6 +61,7 @@ import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterCavern;
import art.arcane.volmlib.util.matter.MatterStructurePOI;
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
import art.arcane.volmlib.util.math.BlockPosition;
import art.arcane.volmlib.util.math.RNG;
import it.unimi.dsi.fastutil.longs.Long2IntMap;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
@@ -65,6 +69,7 @@ import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer;
@ComponentFlag(ReservedFlag.JIGSAW)
public class IrisStructureComponent extends IrisMantleComponent {
@@ -145,51 +150,51 @@ public class IrisStructureComponent extends IrisMantleComponent {
+ " is not implemented for structure '" + key + "'");
}
ObjectPlaceMode mode = structure.getPlaceMode();
int failedPieces = 0;
IrisStructureStiltSettings stilt = placement.getStilt();
Long2IntOpenHashMap foundationColumns = stilt == null
? null : new Long2IntOpenHashMap();
boolean supportNonOccluding = stilt != null && stilt.isSupportNonOccluding();
if (placement.isAnchoredUnderground()) {
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, structure, p, undergroundMode, p.getY(), rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
}
} else if (mode == ObjectPlaceMode.STRUCTURE_PIECE || mode == ObjectPlaceMode.FLOATING) {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, p.getY(), rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
}
} else if (pieces.size() == 1) {
if (placeObject(writer, structure, pieces.getFirst(), mode, -1, rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
} else {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, p.getY(), rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
}
}
int failedPieces = placePieces(writer, placement, structure, pieces, rng);
requireAppliedPieces(resolved, cx, cz, failedPieces);
if (failedPieces == 0 && stilt != null) {
placeFoundation(writer, foundationColumns, stilt, rng, !placement.isAnchoredUnderground());
}
if (failedPieces == 0) {
capture.commit();
}
}
}
int placePieces(MantleWriter writer, IrisStructurePlacement placement, IrisStructure structure,
KList<PlacedStructurePiece> pieces, RNG rng) {
IrisStructureStiltSettings stilt = placement.getStilt();
PieceRun run = new PieceRun(structure, rng, stilt == null ? null : new Long2IntOpenHashMap(),
stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater());
ObjectPlaceMode mode = structure.getPlaceMode();
int failedPieces = 0;
int water = writer.beginObjectPlacement(run.allowWater());
try {
if (placement.isAnchoredUnderground()) {
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, run, p, undergroundMode, false) == -1) {
failedPieces++;
}
}
} else if (pieces.size() == 1 && mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
if (placeObject(writer, run, pieces.getFirst(), mode, true) == -1) {
failedPieces++;
}
} else {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, run, p, ObjectPlaceMode.STRUCTURE_PIECE, false) == -1) {
failedPieces++;
}
}
}
if (failedPieces == 0 && stilt != null) {
placeFoundation(writer, run.foundationColumns(), stilt, rng, !placement.isAnchoredUnderground());
}
} finally {
writer.endObjectPlacement(water);
}
return failedPieces;
}
private void placeFoundation(MantleWriter writer, Long2IntOpenHashMap columns,
IrisStructureStiltSettings settings, RNG rng,
boolean surfaceStructure) {
@@ -268,8 +273,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
+ " assembled piece(s)");
}
private void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
IrisStructureTerrain terrain) {
void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
IrisStructureTerrain terrain) {
int[] bounds = computePieceBounds(pieces);
if (bounds == null) {
return;
@@ -289,17 +294,11 @@ public class IrisStructureComponent extends IrisMantleComponent {
return;
}
int mantleOffset = getEngineMantle().getEngine().getMinHeight();
for (int bx = minX; bx <= maxX; bx++) {
for (int by = minY; by <= maxY; by++) {
for (int bz = minZ; bz <= maxZ; bz++) {
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
}
}
}
carveBox(writer, minX, minY, minZ, maxX, maxY, maxZ, mantleOffset);
}
private void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
IrisStructureTerrain terrain) {
void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
IrisStructureTerrain terrain) {
int[] bounds = computePieceBounds(pieces);
if (bounds == null) {
return;
@@ -342,6 +341,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
+ " margin=" + margin + " head=" + head + " floorCut=" + floorCut + " work=" + work);
}
StructureWaterRules.Carve water = StructureWaterRules.carve(IrisStructureWater.mantle(getEngineMantle().getComplex()),
footprint.minX(), footprint.minZ(), footprint.maxX(), footprint.maxZ());
double sideReachSquared = (double) margin * margin;
double downReach = Math.max(1D, floorCut);
for (int bz = footprint.minZ(); bz <= footprint.maxZ(); bz++) {
@@ -363,6 +364,9 @@ public class IrisStructureComponent extends IrisMantleComponent {
int minY = Math.max(worldMin, sourceMinY - floorCut);
int maxY = Math.min(worldMax, sourceMaxY + columnUpExtension);
for (int by = minY; by <= maxY; by++) {
if (water.keeps(bx, by - mantleOffset, bz)) {
continue;
}
double normalizedY = StructureCarveEnvelope.normalizedVerticalDistance(
by, sourceMinY, sourceMaxY, upReach, downReach);
double distanceSquared = normalizedHorizontalDistanceSquared
@@ -391,16 +395,20 @@ public class IrisStructureComponent extends IrisMantleComponent {
private void carveOverboreBox(MantleWriter writer, int[] bounds, int margin, int head, int floorCut,
int mantleOffset, int worldMin, int worldMax) {
int minX = bounds[0] - margin;
int minY = Math.max(worldMin, bounds[1] - floorCut);
int minZ = bounds[2] - margin;
int maxX = bounds[3] + margin;
int maxY = Math.min(worldMax, bounds[4] + head);
int maxZ = bounds[5] + margin;
carveBox(writer, bounds[0] - margin, Math.max(worldMin, bounds[1] - floorCut), bounds[2] - margin,
bounds[3] + margin, Math.min(worldMax, bounds[4] + head), bounds[5] + margin, mantleOffset);
}
private void carveBox(MantleWriter writer, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int mantleOffset) {
StructureWaterRules.Carve water = StructureWaterRules.carve(IrisStructureWater.mantle(getEngineMantle().getComplex()),
minX, minZ, maxX, maxZ);
for (int bx = minX; bx <= maxX; bx++) {
for (int by = minY; by <= maxY; by++) {
for (int bz = minZ; bz <= maxZ; bz++) {
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
for (int bz = minZ; bz <= maxZ; bz++) {
for (int by = minY; by <= maxY; by++) {
int mantleY = by - mantleOffset;
if (!water.keeps(bx, mantleY, bz)) {
writer.setForcedCarve(bx, mantleY, bz, CARVE_CAVERN);
}
}
}
}
@@ -557,30 +565,38 @@ public class IrisStructureComponent extends IrisMantleComponent {
return new int[]{minX, minY, minZ, maxX, maxY, maxZ};
}
private int placeObject(MantleWriter writer, IrisStructure structure, PlacedStructurePiece p,
ObjectPlaceMode mode, int y, RNG rng, Long2IntOpenHashMap foundationColumns,
boolean supportNonOccluding) {
private int placeObject(MantleWriter writer, PieceRun run, PlacedStructurePiece p, ObjectPlaceMode mode,
boolean sampledHeight) {
IrisObject object = p.getObject();
String objectKey = object.getLoadKey();
IrisObjectPlacement config = structure.createLootPlacement(objectKey);
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode, run.allowWater());
String marker = structurePlacementMarker(run.structure(), p, objectKey);
BiConsumer<BlockPosition, NativeBlockState> listener = (position, state) -> {
StructureFoundationPlanner.recordBaseCell(
run.foundationColumns(), position.getX(), position.getY(), position.getZ(), state,
run.supportNonOccluding());
if (marker != null && shouldWriteStructureMarker(state)) {
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
}
};
return sampledHeight
? object.place(p.getX(), p.getZ(), writer, config, run.rng(), listener, null, getData())
: object.place(p.getX(), p.getY() - getEngineMantle().getEngine().getMinHeight(), p.getZ(), writer, config, run.rng(), listener, null, getData());
}
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode,
boolean allowWater) {
IrisObjectPlacement config = structure.createLootPlacement(piece.getObject().getLoadKey());
config.setMode(mode);
config.setRotation(p.getRotation());
config.setRotation(piece.getRotation());
if (!structure.getEdit().isEmpty()) {
config.setEdit(structure.getEdit());
}
if (mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
config.setForcePlace(true);
config.setForcedByStructure(!allowWater);
}
int placeY = (y == -1) ? -1 : y - getEngineMantle().getEngine().getMinHeight();
String marker = structurePlacementMarker(structure, p, objectKey);
return object.place(p.getX(), placeY, p.getZ(), writer, config, rng, (position, state) -> {
StructureFoundationPlanner.recordBaseCell(
foundationColumns, position.getX(), position.getY(), position.getZ(), state,
supportNonOccluding);
if (marker != null && shouldWriteStructureMarker(state)) {
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
}
}, null, getData());
return config;
}
static boolean shouldWriteStructureMarker(NativeBlockState state) {
@@ -703,4 +719,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
private record ObjectBlockPosition(int x, int y, int z) {
}
private record PieceRun(IrisStructure structure, RNG rng, Long2IntOpenHashMap foundationColumns,
boolean supportNonOccluding, boolean allowWater) {
}
}
@@ -217,9 +217,9 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
int id = rng.i(0, Integer.MAX_VALUE);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
writer, placements.next(minX >> 4, minZ >> 4));
writer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
try {
int resultY = obj.place(xx, -1, zz, transaction, floatingPlacement, rng, (b, bd) -> {
int resultY = obj.place(xx, zz, transaction, floatingPlacement, rng, (b, bd) -> {
String marker = placementMarker(obj, id);
if (marker != null && shouldWritePlacementMarker(transaction, bd, b.getX(), b.getY(), b.getZ())) {
transaction.setData(b.getX(), b.getY(), b.getZ(), marker);
@@ -311,7 +311,8 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
int yv = pickTopY + 1 - fp.getLowestSolidKeyY();
IslandObjectPlacer islandPlacer = IslandObjectPlacer.top(writer, sampleProvider, entry, pickTopY);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer, placements.next(minX >> 4, minZ >> 4));
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
int id = rng.i(0, Integer.MAX_VALUE);
try {
@@ -424,7 +425,8 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
int yv = invertedBaseY(pickBottomY, fp, invertedRotation);
IslandObjectPlacer islandPlacer = IslandObjectPlacer.bottom(writer, sampleProvider, entry, pickBottomY);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer, placements.next(minX >> 4, minZ >> 4));
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
int id = rng.i(0, Integer.MAX_VALUE);
try {
@@ -751,7 +751,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
try {
int placeResult = -1;
CaveObjectPlacementTransaction.CommitResult commitResult = CaveObjectPlacementTransaction.CommitResult.EMPTY;
int continuation = writer.beginObjectPlacement();
int continuation = writer.beginObjectPlacement(placement.entersWater());
if (carving) {
int caveFloorY = caveAnchor.y();
if (golden) {
@@ -784,7 +784,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
continue;
}
String marker = placementMarker(variant, id, "procedural");
placeResult = variant.place(xx, -1, zz, placer, placement, rng, (b, data) -> {
placeResult = variant.place(xx, zz, placer, placement, rng, (b, data) -> {
if (marker != null) {
placer.setData(b.getX(), b.getY(), b.getZ(), marker);
}
@@ -1013,8 +1013,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
try {
String marker = placementMarker(v, id, "surface");
int continuation = writer.beginObjectPlacement();
int result = v.place(xx, -1, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
int result = v.place(xx, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
if (marker != null) {
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
}
@@ -1198,7 +1198,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
IrisObjectPlacement effectivePlacement = resolveCavePlacement(objectPlacement, object, caveProfile);
try {
int continuation = writer.beginObjectPlacement();
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
ContainedPlacementResult contained = placeContainedCaveObject(
writer,
object,
@@ -1394,7 +1394,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
boolean treePlacement = isTreePlacement(v, objectPlacement);
String marker = placementMarker(v, id, "upper");
int continuation = writer.beginObjectPlacement();
int continuation = writer.beginObjectPlacement(placement.entersWater());
int result = v.place(xx, anchorY, zz, writer, placement, rng, (b, data) -> {
if (marker != null) {
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
@@ -90,6 +90,11 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
@Setter(AccessLevel.NONE)
@EqualsAndHashCode.Exclude
@ToString.Exclude
private final ThreadLocal<ObjectWater> objectWater = new ThreadLocal<>();
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
@EqualsAndHashCode.Exclude
@ToString.Exclude
private TerrainAccess terrainAccess;
public MantleWriter(EngineMantle engineMantle, Mantle<Matter> mantle, int x, int z, int radius, boolean multicore) {
@@ -215,6 +220,28 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
return capture;
}
@Override
public int beginObjectPlacement(boolean entersWater) {
objectWater.set(new ObjectWater(ObjectHydrologyVeto.of(getEngine()), entersWater));
return -1;
}
@Override
public void endObjectPlacement(int checkpoint) {
objectWater.remove();
}
private boolean keepsWater(int x, int y, int z, Object value) {
ObjectWater water = objectWater.get();
if (water == null) {
return false;
}
if (value instanceof NativeBlockState state) {
return water.veto().keepsBlock(x, y, z, state, water.entersWater());
}
return value instanceof MatterCavern && water.veto().keeps(x, y, z, false, water.entersWater());
}
private void recordObjectValue(int x, int y, int z, Class<?> type, Object value) {
ObjectPlacementCapture capture = objectPlacementCapture.get();
if (capture != null) {
@@ -241,7 +268,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
MantleChunk<Matter> chunk = acquireChunk(cx, cz);
if (chunk == null) return;
if (protectsSubterrainPlacement(x, y, z)) {
if (protectsSubterrainPlacement(x, y, z) || keepsWater(x, y, z, t)) {
return;
}
synchronized (chunk) {
@@ -611,7 +638,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
}
MantleChunk<Matter> chunk = acquireChunk(x >> 4, z >> 4);
if (chunk == null) {
if (chunk == null || keepsWater(x, y, z, baseState)) {
return;
}
@@ -1007,6 +1034,9 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
naturalOpening ? ALWAYS : NEVER, cavern ? ALWAYS : NEVER) ? (byte) 1 : 0;
}
private record ObjectWater(ObjectHydrologyVeto veto, boolean entersWater) {
}
public final class ObjectPlacementCapture implements AutoCloseable {
private final ObjectContinuationBundle.PlacementKey key;
private final Long2ObjectOpenHashMap<Matter> fragments = new Long2ObjectOpenHashMap<>();
@@ -9,6 +9,7 @@ import java.util.Objects;
final class MutationLog {
private static final byte CUSTOM = 1;
private static final byte CANOPY = 2;
private static final byte ENTERS_WATER = 4;
private int size;
private int[] x = new int[32];
@@ -29,16 +30,16 @@ final class MutationLog {
throw new IllegalArgumentException("Object mutation type " + key.type().getName()
+ " does not match its value " + value.getClass().getName());
}
log.add(key.x(), key.y(), key.z(), value, false, set.canopy());
log.add(key.x(), key.y(), key.z(), value, false, set.canopy(), false);
}
case ObjectDestinationTransaction.CustomBlockMutation block -> log.add(key.x(), key.y(), key.z(),
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy());
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy(), false);
}
}
return log;
}
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy) {
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, boolean entersWater) {
if (size == values.length) {
int capacity = size * 2;
x = Arrays.copyOf(x, capacity);
@@ -51,7 +52,7 @@ final class MutationLog {
y[size] = blockY;
z[size] = blockZ;
values[size] = value;
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0));
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (entersWater ? ENTERS_WATER : 0));
size++;
}
@@ -83,6 +84,10 @@ final class MutationLog {
return (flags[index] & CANOPY) != 0;
}
boolean entersWater(int index) {
return (flags[index] & ENTERS_WATER) != 0;
}
Class<?> type(int index) {
return custom(index) ? NativeBlockState.class : ObjectSourcePlan.typeOf(values[index]);
}
@@ -5,10 +5,6 @@ import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
import art.arcane.iris.generation.block.TileData;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
@@ -30,7 +26,6 @@ import java.util.Map;
final class ObjectDestinationTransaction implements ObjectPassPlacer {
private static final Object CLEARED = new Object();
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
private final MantleWriter writer;
private final int destinationChunkX;
@@ -45,8 +40,8 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
private int subterrainY;
private int subterrainZ;
private boolean subterrainProtects;
private boolean hydrologyKnown;
private HydrologyRuntime hydrology;
private ObjectHydrologyVeto waterVeto;
private boolean waterPlacement;
ObjectDestinationTransaction(MantleWriter writer, int destinationChunkX, int destinationChunkZ) {
this.writer = writer;
@@ -78,12 +73,14 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
}
@Override
public int beginObjectPlacement() {
public int beginObjectPlacement(boolean entersWater) {
waterPlacement = entersWater;
return log.size();
}
@Override
public void endObjectPlacement(int checkpoint) {
waterPlacement = false;
if (checkpoint >= 0 && checkpoint < log.size()) {
placements.add(new PlacementRange(checkpoint, log.size()));
}
@@ -106,6 +103,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
Object value = plan.valueAt(index);
boolean custom = ObjectSourcePlan.isCustom(cell);
boolean canopy = ObjectSourcePlan.isCanopy(cell);
boolean entersWater = ObjectSourcePlan.entersWater(cell);
if (custom || value instanceof NativeBlockState) {
NativeBlockState existing = canopy ? get(x, y, z) : null;
skipCanopy = existing != null && existing.isSolid();
@@ -114,9 +112,9 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
continue;
}
if (custom) {
set(x, y, z, (NativeBlockState) value, true, canopy);
set(x, y, z, (NativeBlockState) value, canopy, entersWater);
} else {
setData(x, y, z, value, true, canopy);
setData(x, y, z, value, canopy, entersWater);
}
}
}
@@ -181,17 +179,17 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
@Override
public void set(int x, int y, int z, NativeBlockState state) {
set(x, y, z, state, false, false);
set(x, y, z, state, isCanopy(x, y, z), waterPlacement);
}
private void set(int x, int y, int z, NativeBlockState state, boolean replayed, boolean replayedCanopy) {
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, boolean entersWater) {
if (state == null) {
return;
}
String placementKey = state.deferredPlacementKey();
NativeBlockState baseState = state.placementBaseState();
if (state.isCustom() && placementKey != null && baseState != null) {
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid())) {
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid(), entersWater)) {
return;
}
Identifier identifier = Identifier.fromString(placementKey);
@@ -199,10 +197,10 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
cell.block = baseState;
cell.tile = CLEARED;
cell.identifier = identifier;
log.add(x, y, z, state, true, replayed ? replayedCanopy : isCanopy(x, y, z));
log.add(x, y, z, state, true, canopy, entersWater);
return;
}
setData(x, y, z, state);
setData(x, y, z, state, canopy, entersWater);
}
@Override
@@ -293,18 +291,18 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
@Override
public <T> void setData(int x, int y, int z, T data) {
setData(x, y, z, data, false, false);
setData(x, y, z, data, isCanopy(x, y, z), waterPlacement);
}
private void setData(int x, int y, int z, Object data, boolean replayed, boolean replayedCanopy) {
private void setData(int x, int y, int z, Object data, boolean canopy, boolean entersWater) {
if (data == null || y < 0 || y >= worldHeight
|| protectsSubterrain(x, y, z)) {
return;
}
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid()))) {
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid(), entersWater))) {
return;
}
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false))) {
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, entersWater))) {
return;
}
Class<?> type = data instanceof NativeBlockState ? NativeBlockState.class : data.getClass();
@@ -316,7 +314,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
} else {
cell.put(type, data);
}
log.add(x, y, z, data, false, replayed ? replayedCanopy : isCanopy(x, y, z));
log.add(x, y, z, data, false, canopy, entersWater);
}
@Override
@@ -413,67 +411,11 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
&& !protectsSubterrain(x, y, z);
}
private boolean hydrologyKeeps(int x, int y, int z, boolean holdsWater) {
HydrologyRuntime runtime = hydrology();
if (runtime == null) {
return false;
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean entersWater) {
if (waterVeto == null) {
waterVeto = ObjectHydrologyVeto.of(getEngine());
}
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
if (raster.empty()) {
return false;
}
WaterRole role = raster.role(x & 15, z & 15);
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= getEngine().getComplex().naturalTrueHeight(x, z)) {
return true;
}
if (role.wet()) {
int surface = raster.waterHead(x & 15, z & 15);
int fallTop = highestHead(runtime, raster, x, z);
if (fallTop > surface && y >= surface && y <= fallTop) {
return true;
}
return !holdsWater && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
}
if (holdsWater || role == WaterRole.NONE) {
return false;
}
int head = Integer.MIN_VALUE;
int bed = Integer.MAX_VALUE;
for (int[] side : SIDES) {
int nx = x + side[0];
int nz = z + side[1];
ChunkWaterRaster neighbour = neighbour(runtime, raster, x, z, nx, nz);
if (neighbour.role(nx & 15, nz & 15).wet()) {
head = Math.max(head, neighbour.waterHead(nx & 15, nz & 15));
bed = Math.min(bed, neighbour.terrainHeight(nx & 15, nz & 15));
}
}
return y > bed && y <= head;
}
private static int highestHead(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z) {
int top = Integer.MIN_VALUE;
for (int[] side : SIDES) {
int nx = x + side[0];
int nz = z + side[1];
top = Math.max(top, neighbour(runtime, raster, x, z, nx, nz).waterHead(nx & 15, nz & 15));
}
return top;
}
private static ChunkWaterRaster neighbour(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z, int nx, int nz) {
return (nx >> 4) == (x >> 4) && (nz >> 4) == (z >> 4) ? raster : runtime.raster(nx >> 4, nz >> 4);
}
private HydrologyRuntime hydrology() {
if (!hydrologyKnown) {
Engine engine = getEngine();
IrisComplex complex = engine == null ? null : engine.getComplex();
HydrologyRuntime runtime = complex == null ? null : complex.getHydrologyRuntime();
hydrology = runtime != null && runtime.enabled() ? runtime : null;
hydrologyKnown = true;
}
return hydrology;
return waterVeto.keeps(x, y, z, solid, entersWater);
}
private boolean protectsSubterrain(int x, int y, int z) {
@@ -0,0 +1,94 @@
package art.arcane.iris.generation.mantle;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
final class ObjectHydrologyVeto {
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
private static final ObjectHydrologyVeto NONE = new ObjectHydrologyVeto(null, null);
private final IrisComplex complex;
private final HydrologyRuntime runtime;
private ObjectHydrologyVeto(IrisComplex complex, HydrologyRuntime runtime) {
this.complex = complex;
this.runtime = runtime;
}
static ObjectHydrologyVeto of(Engine engine) {
IrisComplex complex = engine == null ? null : engine.getComplex();
HydrologyRuntime runtime = complex == null ? null : complex.getHydrologyRuntime();
return runtime != null && runtime.enabled() ? new ObjectHydrologyVeto(complex, runtime) : NONE;
}
boolean keepsBlock(int x, int y, int z, NativeBlockState state, boolean entersWater) {
NativeBlockState base = state.isCustom() && state.placementBaseState() != null ? state.placementBaseState() : state;
return keeps(x, y, z, base.isSolid(), entersWater);
}
boolean keeps(int x, int y, int z, boolean solid, boolean entersWater) {
if (runtime == null) {
return false;
}
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
if (raster.empty()) {
return false;
}
WaterRole role = raster.role(x & 15, z & 15);
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= complex.naturalTrueHeight(x, z)) {
return true;
}
if (solid && !entersWater && fillsWater(x, y, z)) {
return true;
}
if (role.wet()) {
int surface = raster.waterHead(x & 15, z & 15);
int fallTop = highestHead(raster, x, z);
if (fallTop > surface && y >= surface && y <= fallTop) {
return true;
}
return !solid && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
}
if (solid || role == WaterRole.NONE) {
return false;
}
int head = Integer.MIN_VALUE;
int bed = Integer.MAX_VALUE;
for (int[] side : SIDES) {
int nx = x + side[0];
int nz = z + side[1];
ChunkWaterRaster neighbour = neighbour(raster, x, z, nx, nz);
if (neighbour.role(nx & 15, nz & 15).wet()) {
head = Math.max(head, neighbour.waterHead(nx & 15, nz & 15));
bed = Math.min(bed, neighbour.terrainHeight(nx & 15, nz & 15));
}
}
return y > bed && y <= head;
}
private boolean fillsWater(int x, int y, int z) {
if (!complex.getWaterRoleStream().get(x, z).wet()) {
return false;
}
return y > complex.getRoundedHeighteightStream().get(x, z)
&& y <= (int) Math.round(complex.getWaterHeadStream().getDouble(x, z));
}
private int highestHead(ChunkWaterRaster raster, int x, int z) {
int top = Integer.MIN_VALUE;
for (int[] side : SIDES) {
int nx = x + side[0];
int nz = z + side[1];
top = Math.max(top, neighbour(raster, x, z, nx, nz).waterHead(nx & 15, nz & 15));
}
return top;
}
private ChunkWaterRaster neighbour(ChunkWaterRaster raster, int x, int z, int nx, int nz) {
return (nx >> 4) == (x >> 4) && (nz >> 4) == (z >> 4) ? raster : runtime.raster(nx >> 4, nz >> 4);
}
}
@@ -8,7 +8,7 @@ public interface ObjectPassPlacer extends IObjectPlacer {
byte[] getCarvedColumn(int x, int z, int height);
default int beginObjectPlacement() {
default int beginObjectPlacement(boolean entersWater) {
return -1;
}
@@ -32,7 +32,8 @@ final class ObjectSourcePlan {
private static final int UNKNOWN_PAYLOAD_BYTES = 256;
private static final int CUSTOM_BIT = 1 << 8;
private static final int CANOPY_BIT = 1 << 9;
private static final int Y_SHIFT = 10;
private static final int ENTERS_WATER_BIT = 1 << 10;
private static final int Y_SHIFT = 11;
private static final int MAXIMUM_Y = (1 << (31 - Y_SHIFT)) - 1;
private final long[] destinations;
@@ -90,7 +91,7 @@ final class ObjectSourcePlan {
throw new IllegalArgumentException("Object mutation height is outside the plan range: " + y);
}
cells[position] = (y << Y_SHIFT) | (log.custom(logged) ? CUSTOM_BIT : 0) | (log.canopy(logged) ? CANOPY_BIT : 0)
| ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
| (log.entersWater(logged) ? ENTERS_WATER_BIT : 0) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
valueIndexes[position] = table.indexOf(log.value(logged));
}
values = table.values.toArray();
@@ -241,6 +242,10 @@ final class ObjectSourcePlan {
return (cell & CANOPY_BIT) != 0;
}
static boolean entersWater(int cell) {
return (cell & ENTERS_WATER_BIT) != 0;
}
ObjectDestinationTransaction.Mutation mutationAt(int chunkX, int chunkZ, int index) {
int cell = cells[index];
int x = (chunkX << 4) | cellX(cell);
@@ -1,5 +1,6 @@
package art.arcane.iris.generation.runtime;
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
import art.arcane.iris.world.history.SavedBiomeUnavailableException;
import art.arcane.volmlib.util.mantle.MantleClosedException;
@@ -25,6 +26,7 @@ public final class GenerationFailures {
public static boolean isEngineFailure(Throwable failure) {
return isShutdownFailure(failure) || hasCause(failure, (Throwable cause) -> cause instanceof Error
|| cause instanceof WrongEngineBroException
|| cause instanceof ProvisionalAnswerException
|| cause instanceof SavedBiomeUnavailableException unavailable && unavailable.isLoading()
|| cause instanceof TimeoutException);
}
@@ -0,0 +1,7 @@
package art.arcane.iris.generation.stream;
public final class ProvisionalAnswerException extends IllegalStateException {
public ProvisionalAnswerException(String message) {
super(message);
}
}
@@ -14,6 +14,7 @@ import art.arcane.iris.structure.nativegen.NativeStructureStartPlan;
import art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex;
import art.arcane.iris.structure.nativegen.StructureLocateSearch;
import art.arcane.iris.structure.placement.IrisStructureLocator;
import art.arcane.iris.structure.placement.IrisStructureWater;
import art.arcane.volmlib.nativelib.terrain.NativeBlockChangeSet;
import art.arcane.volmlib.nativelib.terrain.NativeBlockPositionPredicate;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
@@ -23,6 +24,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.StructurePlacementDecision
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
import art.arcane.volmlib.nativelib.terrain.structure.StructureSeaSurface;
import art.arcane.volmlib.nativelib.terrain.structure.StructureVolumePolicy;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
import art.arcane.volmlib.util.math.RNG;
import java.util.concurrent.ConcurrentHashMap;
@@ -126,6 +128,11 @@ public final class BukkitStructureStagePolicy implements StructureStagePolicy<
return GenerationWritePolicy.seaSurface(context);
}
@Override
public StructureWater water(Engine context) {
return IrisStructureWater.world(context);
}
@Override
public IntBinaryOperator worldgenHeight(Engine context, int runtimeMinY, boolean floor) {
return (x, z) -> Engine.hostHeight(context, x, z, floor) + runtimeMinY + 1;
@@ -31,6 +31,11 @@ public record NativeStructureStartPlan(
return placement.isUnderground();
}
@Override
public boolean allowWater() {
return placement.isAllowWater();
}
@Override
public boolean replacesSource() {
return placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE;
@@ -328,11 +328,16 @@ public class IrisObject extends IrisRegistrant {
}
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) {
return place(x, -1, z, placer, config, rng, rdata);
return place(x, z, placer, config, rng, null, null, rdata);
}
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, CarveResult c, IrisData rdata) {
return place(x, -1, z, placer, config, rng, null, c, rdata);
return place(x, z, placer, config, rng, null, c, rdata);
}
public int place(int x, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, BiConsumer<BlockPosition, NativeBlockState> listener, CarveResult c, IrisData rdata) {
IrisObject placedObject = config.isSmartBore() ? IrisObjectShaping.smartBoredVariant(this) : this;
return new IrisObjectPlacementRunner(placedObject, IrisObjectPlacementAlignment.CENTER).placeAutomatic(x, z, oplacer, config, rng, listener, c, rdata);
}
public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) {
@@ -201,6 +201,7 @@ public class IrisObjectPlacement {
@Description("Ignore any placement restrictions for this object")
@SerializedName(value = "forcePlace", alternate = {"force"})
private boolean forcePlace = false;
private transient boolean forcedByStructure = false;
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
private transient AtomicCache<CompatStatus> compatCache = new AtomicCache<>();
@Getter(AccessLevel.NONE)
@@ -306,6 +307,10 @@ public class IrisObjectPlacement {
return place.size() == 1 ? place.getFirst() : place.toString(", ");
}
public boolean entersWater() {
return underwater || onwater || forcePlace && !forcedByStructure;
}
public IrisObjectPlacement toPlacement(String... place) {
IrisObjectPlacement p = new IrisObjectPlacement();
p.setPlace(new KList<>(place));
@@ -349,6 +354,7 @@ public class IrisObjectPlacement {
p.setAllowedCollisions(allowedCollisions);
p.setForbiddenCollisions(forbiddenCollisions);
p.setForcePlace(forcePlace);
p.setForcedByStructure(forcedByStructure);
return p;
}
@@ -39,7 +39,15 @@ final class IrisObjectPlacementRunner {
int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng,
BiConsumer<BlockPosition, NativeBlockState> listener, CarveResult cave, IrisData data) {
PlacementContext context = new PlacementContext(config, data, placer, cave, rng, self, alignment, x, z, yv, listener);
return PlacementLifecycles.defaults().get(config.getMode()).execute(context).heightOrRejected();
return execute(new PlacementContext(config, data, placer, cave, rng, self, alignment, x, z, yv, listener));
}
int placeAutomatic(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng,
BiConsumer<BlockPosition, NativeBlockState> listener, CarveResult cave, IrisData data) {
return execute(PlacementContext.automatic(config, data, placer, cave, rng, self, alignment, x, z, listener));
}
private static int execute(PlacementContext context) {
return PlacementLifecycles.defaults().get(context.config.getMode()).execute(context).heightOrRejected();
}
}
@@ -9,6 +9,8 @@ import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.geometry.IrisBlockVector;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.volmlib.util.stream.ProceduralStream;
import java.util.Arrays;
import java.util.List;
@@ -60,6 +62,21 @@ public final class IrisSurfaceSupport {
return stencil.anyColumnIntersectsHydrology(engine.getComplex(), x, z);
}
public static boolean intersectsUnevenWater(IObjectPlacer placer, int x, int z,
IrisObjectTranslate translate, IrisObjectRotation rotation,
int spinX, int spinY, int spinZ,
List<IrisBlockVector> supportOffsets) {
Engine engine = placer.getEngine();
if (engine == null || engine.getComplex() == null) {
return false;
}
Stencil stencil = STENCIL.get();
if (!stencil.build(supportOffsets, translate, rotation, spinX, spinY, spinZ, 0)) {
return true;
}
return stencil.anyColumnIntersectsUnevenWater(engine.getComplex(), x, z);
}
private static IrisBlockVector transform(IrisBlockVector offset, IrisObjectTranslate translate,
IrisObjectRotation rotation, int spinX, int spinY, int spinZ) {
IrisBlockVector transformed = offset.clone();
@@ -228,6 +245,44 @@ public final class IrisSurfaceSupport {
return false;
}
private boolean anyColumnIntersectsUnevenWater(IrisComplex complex, int x, int z) {
ProceduralStream<WaterRole> roles = complex.getWaterRoleStream();
ProceduralStream<Double> heads = complex.getWaterHeadStream();
boolean anchorKnown = false;
long anchorHead = 0L;
for (int stencilX = 0; stencilX < width; stencilX++) {
for (int stencilZ = 0; stencilZ < depth; stencilZ++) {
if (!cells[(stencilX * depth) + stencilZ]) {
continue;
}
int columnX = x + minX + stencilX;
int columnZ = z + minZ + stencilZ;
WaterRole role = roles.get(columnX, columnZ);
if (breaksFlatWater(role)) {
return true;
}
if (!role.wet()) {
continue;
}
if (!anchorKnown) {
anchorHead = Math.round(heads.getDouble(x, z));
anchorKnown = true;
}
if (Math.round(heads.getDouble(columnX, columnZ)) != anchorHead) {
return true;
}
}
}
return false;
}
private static boolean breaksFlatWater(WaterRole role) {
return switch (role) {
case DAM, CASCADE, WATERFALL -> true;
case NONE, CHANNEL, BANK, SHORE, POND, POND_SHORE, MOUTH, INLET -> false;
};
}
private boolean isColumnUnsupported(IObjectPlacer placer, IrisData data, int x, int z,
int stencilX, int stencilZ, int minSolidDepth,
IrisPaintSurfaceProjection projection) {
@@ -19,6 +19,8 @@ public final class PlacementContext {
public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {}
public record WorldBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {}
private static final int AUTOMATIC_Y = -1;
final IrisObjectPlacement config;
final IrisData rdata;
final IObjectPlacer placer;
@@ -29,6 +31,7 @@ public final class PlacementContext {
final int x;
final int z;
final int yv;
final boolean automatic;
final BiConsumer<BlockPosition, NativeBlockState> listener;
public PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
@@ -40,6 +43,12 @@ public final class PlacementContext {
public PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
CarveResult caveResult, RNG rng, IrisObject self, IrisObjectPlacementAlignment alignment,
int x, int z, int yv, BiConsumer<BlockPosition, NativeBlockState> listener) {
this(config, rdata, placer, caveResult, rng, self, alignment, x, z, yv, false, listener);
}
private PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
CarveResult caveResult, RNG rng, IrisObject self, IrisObjectPlacementAlignment alignment,
int x, int z, int yv, boolean automatic, BiConsumer<BlockPosition, NativeBlockState> listener) {
this.placer = Objects.requireNonNull(placer, "Object placer is required.");
this.config = Objects.requireNonNull(config, "Object placement config is required.");
this.rng = Objects.requireNonNull(rng, "Object placement RNG is required.");
@@ -50,6 +59,13 @@ public final class PlacementContext {
this.x = x;
this.z = z;
this.yv = yv;
this.automatic = automatic;
this.listener = listener;
}
public static PlacementContext automatic(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer,
CarveResult caveResult, RNG rng, IrisObject self, IrisObjectPlacementAlignment alignment,
int x, int z, BiConsumer<BlockPosition, NativeBlockState> listener) {
return new PlacementContext(config, rdata, placer, caveResult, rng, self, alignment, x, z, AUTOMATIC_Y, true, listener);
}
}
@@ -1,5 +1,7 @@
package art.arcane.iris.structure.object;
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
import art.arcane.iris.generation.stream.ProvisionalSampling;
import java.util.List;
@@ -15,9 +17,12 @@ public final class PlacementLifecycle {
/** The block pass and everything after it read one consistent object snapshot. */
public PlacementState execute(PlacementContext context) {
PlacementState state = new PlacementState(context);
for (PlacementStage<Void> stage : PlacementStage.BEFORE_PASS) {
long revision = ProvisionalSampling.revision();
for (PlacementStage<Void> stage : PlacementStage.DECISION) {
run(stage, context, state, null);
}
requireFinalAnswers(context, revision);
run(PlacementStage.BEFORE_BLOCKS, context, state, null);
if (state.isRejected()) {
return state;
}
@@ -42,4 +47,13 @@ public final class PlacementLifecycle {
function.execute(context, state, input);
}
}
private static void requireFinalAnswers(PlacementContext context, long revision) {
if (!context.automatic || ProvisionalSampling.revision() == revision) {
return;
}
String key = context.self.getLoadKey();
throw new ProvisionalAnswerException("Object " + (key == null ? "<no loadKey>" : key) + " at " + context.x + "," + context.z
+ " read a provisional terrain or water answer; automatic placements are only made from final terrain.");
}
}
@@ -14,7 +14,7 @@ final class PlacementModuleAnchor implements PlacementModule {
@Override
public void install(PlacementLifecycleBuilder lifecycle) {
lifecycle.add(POSITIONED, PlacementStage.HEIGHT, (context, state, ignored) -> {
if (context.yv >= 0 && state.config.isBottom()
if (!context.automatic && state.config.isBottom()
&& state.config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE
&& context.alignment != IrisObjectPlacementAlignment.FLOOR) {
state.y += Math.floorDiv(context.self.h, 2);
@@ -36,7 +36,7 @@ final class PlacementModuleAnchor implements PlacementModule {
}
if (state.config.isFromBottom()) {
state.y = context.self.getH() + 1 + state.rty;
} else if (context.yv < 0) {
} else if (context.automatic) {
sampledHeight.execute(context, state, null);
return;
} else {
@@ -52,7 +52,7 @@ final class PlacementModuleAnchor implements PlacementModule {
/** Seats the lowest occupied block on the caller's first air Y. */
private static void alignToFloor(PlacementContext context, PlacementState state) {
if (context.yv < 0 || state.ceilingHang || state.config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
if (context.automatic || state.ceilingHang || state.config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
throw new IllegalArgumentException("Floor alignment requires an explicit floor Y and a floor placement mode.");
}
int minimumY = minimumOccupiedY(context.self, state.spin);
@@ -10,7 +10,7 @@ final class PlacementModuleBounds implements PlacementModule {
IrisObjectPlacement config = state.config;
if (config.isBore() || (!config.isForcePlace() && config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE
&& (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty()))) {
state.worldBounds = resolve(context, state, context.yv < 0 && config.getMode() == ObjectPlaceMode.PAINT);
state.worldBounds = resolve(context, state, context.automatic && config.getMode() == ObjectPlaceMode.PAINT);
}
}, PlacementModuleNativeStructureProtection.CHECK);
}
@@ -11,13 +11,13 @@ final class PlacementModuleLimits implements PlacementModule {
if (config.isForcePlace() || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
return;
}
if (context.yv < 0 && config.getMode() != ObjectPlaceMode.FLOATING
if (context.automatic && config.getMode() != ObjectPlaceMode.FLOATING
&& !config.isUnderwater() && !config.isOnwater()
&& state.placer.isUnderwater(context.x, context.z)) {
state.reject("underwater-anchor");
return;
}
if (context.yv < 0 && config.getMode() != ObjectPlaceMode.FLOATING
if (context.automatic && config.getMode() != ObjectPlaceMode.FLOATING
&& config.isOnwater() && !state.placer.isUnderwater(context.x, context.z)) {
state.reject("onwater-anchor");
return;
@@ -31,7 +31,7 @@ final class PlacementModuleNativeStructureProtection implements PlacementModule
IrisBlockVector translateOffset = state.translateOffset;
boolean translating = translateOffset != null;
boolean ceilingHang = state.ceilingHang;
boolean paint = context.yv < 0 && config.getMode() == ObjectPlaceMode.PAINT;
boolean paint = context.automatic && config.getMode() == ObjectPlaceMode.PAINT;
int warpMargin = state.warpMargin;
int x = context.x;
int y = state.y + state.yrand;
@@ -26,7 +26,7 @@ public final class PlacementModulePaint implements PlacementModule {
}
static void installProjection(PlacementLifecycleBuilder lifecycle) {
lifecycle.add(PROJECT, PlacementStage.VALIDATE, (context, state, ignored) -> {
if (context.yv >= 0 || state.config.getMode() != ObjectPlaceMode.PAINT) {
if (!context.automatic || state.config.getMode() != ObjectPlaceMode.PAINT) {
return;
}
int buffer = state.config.isRequireSurfaceSupport() ? Math.max(0, state.config.getSurfaceSupportBuffer()) : 0;
@@ -15,17 +15,13 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
public void install(PlacementLifecycleBuilder lifecycle) {
lifecycle.add(CHECK, PlacementStage.VALIDATE, (context, state, ignored) -> {
IrisObjectPlacement config = state.config;
if (context.yv < 0 && config.getCarvingSupport().supportsSurface()
&& config.getMode() != ObjectPlaceMode.FLOATING && config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE
&& (state.paintProjection != null
? IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
: IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, config.getTranslate(),
config.getRotation(), state.spinX, state.spinY, state.spinZ, context.self.getSurfaceSupportOffsets()))) {
state.reject("hydrology-support");
String hydrologyRejection = hydrologyRejection(context, state);
if (hydrologyRejection != null) {
state.reject(hydrologyRejection);
return;
}
boolean rawStructurePiece = config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE;
if (context.yv < 0 && !config.isForcePlace() && !config.isFromBottom()
if (context.automatic && !config.isForcePlace() && !config.isFromBottom()
&& config.getMode() != ObjectPlaceMode.FLOATING && !rawStructurePiece
&& config.getCarvingSupport().supportsSurface() && state.placer.getEngine() != null
&& state.placer.getEngine().getDimension().isBedrock() && state.y <= 1) {
@@ -33,7 +29,7 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
state.reject("bedrock-anchor");
return;
}
boolean surfaceAnchored = context.yv < 0 ? config.getCarvingSupport().supportsSurface()
boolean surfaceAnchored = context.automatic ? config.getCarvingSupport().supportsSurface()
: config.getCarvingSupport() == CarvingMode.SURFACE_ONLY;
if (surfaceAnchored && !config.isForcePlace() && !config.isFromBottom()
&& config.getMode() != ObjectPlaceMode.FLOATING && !rawStructurePiece
@@ -58,6 +54,27 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
};
}
private static String hydrologyRejection(PlacementContext context, PlacementState state) {
IrisObjectPlacement config = state.config;
if (!context.automatic || !config.getCarvingSupport().supportsSurface()
|| config.getMode() == ObjectPlaceMode.FLOATING || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
return null;
}
boolean painted = state.paintProjection != null;
if (config.entersWater()) {
return (painted
? IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
: IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, config.getTranslate(),
config.getRotation(), state.spinX, state.spinY, state.spinZ, context.self.getSurfaceSupportOffsets()))
? "uneven-water" : null;
}
return (painted
? IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
: IrisSurfaceSupport.intersectsHydrology(context.placer, context.x, context.z, config.getTranslate(),
config.getRotation(), state.spinX, state.spinY, state.spinZ, context.self.getSurfaceSupportOffsets()))
? "hydrology-support" : null;
}
private static void warnImplausibleBedrockPlacement(IrisObject self, IObjectPlacer placer, IrisObjectPlacement config, int x, int y, int z) {
String key = self.getLoadKey();
String fingerprint = (key == null ? "<null>" : key) + "|" + config.getMode();
@@ -32,7 +32,7 @@ final class PlacementModuleTreeGrounding implements PlacementModule {
private static boolean isSurfaceTreePlacement(PlacementContext context, PlacementState state) {
IrisObjectPlacement config = state.config;
ObjectPlaceMode mode = config.getMode();
return context.yv < 0 && config.getCarvingSupport().supportsSurface()
return context.automatic && config.getCarvingSupport().supportsSurface()
&& !config.isForcePlace() && !config.isFromBottom() && !state.ceilingHang
&& mode != ObjectPlaceMode.PAINT && mode != ObjectPlaceMode.FLOATING
&& mode != ObjectPlaceMode.STRUCTURE_PIECE;
@@ -20,7 +20,7 @@ public final class PlacementStage<C> {
public static final PlacementStage<Void> AFTER_BLOCKS = new PlacementStage<>("after-blocks", 6);
static final List<PlacementStage<?>> ALL = List.of(PREPARE, HEIGHT, VALIDATE, BEFORE_BLOCKS,
BLOCK_WRITTEN, BLOCKS, AFTER_BLOCKS);
static final List<PlacementStage<Void>> BEFORE_PASS = List.of(PREPARE, HEIGHT, VALIDATE, BEFORE_BLOCKS);
static final List<PlacementStage<Void>> DECISION = List.of(PREPARE, HEIGHT, VALIDATE);
private final String name;
final int order;
@@ -19,6 +19,8 @@
package art.arcane.iris.structure.placement;
import art.arcane.volmlib.nativelib.terrain.structure.StructureLocateCandidate;
import art.arcane.volmlib.nativelib.terrain.structure.StructureStagePolicy;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
import art.arcane.volmlib.nativelib.terrain.StructureLocateLimitException;
@@ -590,6 +592,10 @@ public final class IrisStructureLocator {
"assembled pieces exceed the configured structure or world bounds")) {
return null;
}
if (!placement.isAnchoredUnderground() && !placement.isAllowWater()
&& !StructureWaterRules.admitsFootprint(IrisStructureWater.mantle(engine.getComplex()), pieceFootprints(pieces))) {
return null;
}
if (!allowsResolvedFootprint(engine, placement, structure, pieces)) {
return null;
}
@@ -935,6 +941,14 @@ public final class IrisStructureLocator {
);
}
private static List<StructureStagePolicy.Footprint> pieceFootprints(KList<PlacedStructurePiece> pieces) {
List<StructureStagePolicy.Footprint> footprints = new ArrayList<>(pieces.size());
for (PlacedStructurePiece piece : pieces) {
footprints.add(new StructureStagePolicy.Footprint(piece.getMinX(), piece.getMinZ(), piece.getMaxX(), piece.getMaxZ()));
}
return footprints;
}
private static int saturatedOffset(int coordinate, int offset) {
long result = (long) coordinate + offset;
return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, result));
@@ -130,6 +130,9 @@ public class IrisStructurePlacement {
@Description("If false, the placement is skipped when its selected surface or cave column is submerged.")
private boolean underwater = false;
@Description("If true, a surface structure may cover river, stream, pond and lake water, and its pieces and stilts may fill it. If false, a surface placement is skipped when more than 10% of its footprint columns are channel, pond, cascade or waterfall water, and its pieces keep their solid blocks out of the water they touch.")
private boolean allowWater = false;
public IrisStructureTerrain resolvedTerrain() {
return terrain == null ? new IrisStructureTerrain() : terrain;
}
@@ -0,0 +1,51 @@
package art.arcane.iris.structure.placement;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
import art.arcane.iris.generation.stream.ProvisionalSampling;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
public final class IrisStructureWater implements StructureWater {
private final IrisComplex complex;
private final int offsetY;
private IrisStructureWater(IrisComplex complex, int offsetY) {
this.complex = complex;
this.offsetY = offsetY;
}
public static StructureWater mantle(IrisComplex complex) {
return complex == null ? StructureWater.DRY : new IrisStructureWater(complex, 0);
}
public static StructureWater world(Engine engine) {
IrisComplex complex = engine.getComplex();
return complex == null ? StructureWater.DRY : new IrisStructureWater(complex, engine.getMinHeight());
}
@Override
public StructureWaterColumn column(int x, int z) {
long revision = ProvisionalSampling.revision();
WaterRole role = complex.getWaterRoleStream().get(x, z);
StructureWaterColumn column = role.wet()
? new StructureWaterColumn(true, river(role),
complex.getRoundedHeighteightStream().get(x, z) + offsetY,
(int) Math.round(complex.getWaterHeadStream().getDouble(x, z)) + offsetY)
: StructureWaterColumn.DRY;
if (ProvisionalSampling.revision() != revision && !complex.isPlatformMainThread()) {
throw new ProvisionalAnswerException("Structure water at " + x + "," + z
+ " read a provisional answer; structures are only placed and carved around final water.");
}
return column;
}
static boolean river(WaterRole role) {
return switch (role) {
case CHANNEL, POND, CASCADE, WATERFALL -> true;
case NONE, BANK, SHORE, POND_SHORE, DAM, MOUTH, INLET -> false;
};
}
}
@@ -159,6 +159,9 @@ public final class StructurePlacementGrid {
signature = appendLong(signature, placement.isUnderwater() ? 1L : 0L);
signature = appendSources(signature, placement);
signature = appendAnchor(signature, placement);
if (placement.isAllowWater()) {
signature = appendLong(signature, 1L);
}
}
return signature;
}
@@ -158,7 +158,6 @@ public class TreeSVC implements IrisService {
return;
}
saplingPlane.forEach(block -> block.setType(Material.AIR));
IrisObject object = placement.scaleObject(RNG.r,
worldAccess.getData().getObjectLoader().load(pool.getRandom(RNG.r)), dimension);
@@ -268,6 +267,11 @@ public class TreeSVC implements IrisService {
);
event.setCancelled(true);
if (blockStateList.isEmpty()) {
IrisLogging.debug("Tree placement " + object.getLoadKey() + " placed nothing at " + event.getLocation() + "; the sapling stays");
return;
}
saplingPlane.forEach(block -> block.setType(Material.AIR));
Runnable growTask = () -> {