Explicit Y below zero

- Automatic placement is a context flag set by the IrisObject x,z overloads instead of any negative Y
- An explicit world Y below zero places at that Y and skips the provisional guard, so saplings, pastes and structure pieces in -64 worlds land where asked
- Mantle surface, procedural, floating and single-piece structure placements call the automatic overloads
- A structure piece at world Y -1 places at its own height instead of a sampled one
- Tests cover explicit negative Y, the provisional guard on automatic placements only, and saplings growing below zero
- The sapling provisional test throws from the tree placement since explicit growth never reaches the guard
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 06:06:09 -05:00
1 parent 7574e39f39
commit 9f0615a975
25 files changed
+219 -103

No files matched your search

@@ -58,6 +58,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 +66,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 {
@@ -155,26 +157,26 @@ public class IrisStructureComponent extends IrisMantleComponent {
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,
if (placeObject(writer, structure, p, undergroundMode, false, 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,
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, false, rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
}
} else if (pieces.size() == 1) {
if (placeObject(writer, structure, pieces.getFirst(), mode, -1, rng,
if (placeObject(writer, structure, pieces.getFirst(), mode, true, rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
} else {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, p.getY(), rng,
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, false, rng,
foundationColumns, supportNonOccluding) == -1) {
failedPieces++;
}
@@ -558,21 +560,23 @@ public class IrisStructureComponent extends IrisMantleComponent {
}
private int placeObject(MantleWriter writer, IrisStructure structure, PlacedStructurePiece p,
ObjectPlaceMode mode, int y, RNG rng, Long2IntOpenHashMap foundationColumns,
ObjectPlaceMode mode, boolean sampledHeight, RNG rng, Long2IntOpenHashMap foundationColumns,
boolean supportNonOccluding) {
IrisObject object = p.getObject();
String objectKey = object.getLoadKey();
IrisObjectPlacement config = piecePlacement(structure, p, mode);
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) -> {
BiConsumer<BlockPosition, NativeBlockState> listener = (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 sampledHeight
? object.place(p.getX(), p.getZ(), writer, config, rng, listener, null, getData())
: object.place(p.getX(), p.getY() - getEngineMantle().getEngine().getMinHeight(), p.getZ(), writer, config, rng, listener, null, getData());
}
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode) {
@@ -219,7 +219,7 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
writer, placements.next(minX >> 4, minZ >> 4));
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);
@@ -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);
}
@@ -1014,7 +1014,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
try {
String marker = placementMarker(v, id, "surface");
int continuation = writer.beginObjectPlacement(effectivePlacement.isUnderwater());
int result = v.place(xx, -1, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
int result = v.place(xx, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
if (marker != null) {
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
}
@@ -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) {
@@ -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();
}
}
@@ -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);
}
}
@@ -49,7 +49,7 @@ public final class PlacementLifecycle {
}
private static void requireFinalAnswers(PlacementContext context, long revision) {
if (context.yv >= 0 || ProvisionalSampling.revision() == revision) {
if (!context.automatic || ProvisionalSampling.revision() == revision) {
return;
}
String key = context.self.getLoadKey();
@@ -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;
@@ -21,7 +21,7 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
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) {
@@ -29,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
@@ -56,7 +56,7 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
private static String hydrologyRejection(PlacementContext context, PlacementState state) {
IrisObjectPlacement config = state.config;
if (context.yv >= 0 || !config.getCarvingSupport().supportsSurface()
if (!context.automatic || !config.getCarvingSupport().supportsSurface()
|| config.getMode() == ObjectPlaceMode.FLOATING || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
return null;
}
@@ -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;