save point 2

This commit is contained in:
piexel committed 2026-08-31 18:47:37 +02:00
1 parent a34f084615
commit b25a479c37
11 files changed
+158 -207

No files matched your search

@@ -34,6 +34,7 @@ import art.arcane.iris.util.project.noise.SimplexNoise;
import art.arcane.iris.util.project.stream.ProceduralStream;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.iris.engine.object.PlacementContext.TransformedBounds;
import art.arcane.volmlib.util.math.BlockPosition;
import art.arcane.volmlib.util.math.Position2;
import art.arcane.volmlib.util.math.RNG;
@@ -43,7 +44,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.stream.StreamSupport;
/**
* One-shot placement of an {@link IrisObject} into the world. Instances are cheap and single use: they exist so
@@ -124,7 +124,8 @@ final class IrisObjectPlacementRunner {
yrand = yrand > 0 ? rng.i(0, yrand) : yrand < 0 ? rng.i(yrand, 0) : yrand;
int warpMargin = warped ? (int) Math.ceil(Math.abs(config.getWarp().getMultiplier()) / 2D) : 0;
TransformedBounds placementBounds = transformedBounds(spin, translating, translateOffset, ceilingHang, warpMargin);
boolean bail = false;
PlacementContext context = new PlacementContext(config, placer, c, rng, self, placementBounds, x, z, y, rty);
// if (config.isFromBottom()) {
// // todo Convert this to a dedicated mode.
@@ -137,111 +138,21 @@ final class IrisObjectPlacementRunner {
// } else
if (yv < 0) {
if (config.getMode().equals(ObjectPlaceMode.CENTER_HEIGHT) || config.getMode() == ObjectPlaceMode.CENTER_STILT
|| organic || vacuuming) {
y = (c != null ? c.getSurface() : placer.getHighest(x, z, self.getLoader(), config.isUnderwater())) + rty;
if (!config.isForcePlace()) {
if (shouldBailForCarvingAnchor(placer, config, x, y, z)) {
bail = true;
}
}
} else if (config.getMode().equals(ObjectPlaceMode.MAX_HEIGHT) || config.getMode().equals(ObjectPlaceMode.STILT)) {
int minX = x + placementBounds.minX();
int maxX = x + placementBounds.maxX();
int minZ = z + placementBounds.minZ();
int maxZ = z + placementBounds.maxZ();
for (int i = minX; i <= maxX; i++) {
for (int ii = minZ; ii <= maxZ; ii++) {
int h = placer.getHighest(i, ii, self.getLoader(), config.isUnderwater()) + rty;
if (!config.isForcePlace()) {
if (shouldBailForCarvingAnchor(placer, config, i, h, ii)) {
bail = true;
break;
}
}
if (h > y)
y = h;
}
}
} else if (config.getMode().equals(ObjectPlaceMode.FAST_MAX_HEIGHT) || config.getMode().equals(ObjectPlaceMode.FAST_STILT)) {
int minX = x + placementBounds.minX();
int maxX = x + placementBounds.maxX();
int minZ = z + placementBounds.minZ();
int maxZ = z + placementBounds.maxZ();
int xRadius = Math.max(0, (maxX - minX) / 2);
int zRadius = Math.max(0, (maxZ - minZ) / 2);
for (int i = minX; i <= maxX; i += Math.abs(xRadius) + 1) {
for (int ii = minZ; ii <= maxZ; ii += Math.abs(zRadius) + 1) {
int h = placer.getHighest(i, ii, self.getLoader(), config.isUnderwater()) + rty;
if (!config.isForcePlace()) {
if (shouldBailForCarvingAnchor(placer, config, i, h, ii)) {
bail = true;
break;
}
}
if (h > y)
y = h;
}
}
} else if (config.getMode().equals(ObjectPlaceMode.MIN_HEIGHT) || config.getMode() == ObjectPlaceMode.MIN_STILT) {
y = requireDataEngine(rdata, "minimum-height mode").getHeight() + 1;
int minX = x + placementBounds.minX();
int maxX = x + placementBounds.maxX();
int minZ = z + placementBounds.minZ();
int maxZ = z + placementBounds.maxZ();
for (int i = minX; i <= maxX; i++) {
for (int ii = minZ; ii <= maxZ; ii++) {
int h = placer.getHighest(i, ii, self.getLoader(), config.isUnderwater()) + rty;
if (!config.isForcePlace()) {
if (shouldBailForCarvingAnchor(placer, config, i, h, ii)) {
bail = true;
break;
}
}
if (h < y) {
y = h;
}
}
}
} else if (config.getMode().equals(ObjectPlaceMode.FAST_MIN_HEIGHT) || config.getMode() == ObjectPlaceMode.FAST_MIN_STILT) {
y = requireDataEngine(rdata, "fast minimum-height mode").getHeight() + 1;
int minX = x + placementBounds.minX();
int maxX = x + placementBounds.maxX();
int minZ = z + placementBounds.minZ();
int maxZ = z + placementBounds.maxZ();
int xRadius = Math.max(0, (maxX - minX) / 2);
int zRadius = Math.max(0, (maxZ - minZ) / 2);
for (int i = minX; i <= maxX; i += Math.abs(xRadius) + 1) {
for (int ii = minZ; ii <= maxZ; ii += Math.abs(zRadius) + 1) {
int h = placer.getHighest(i, ii, self.getLoader(), config.isUnderwater()) + rty;
if (!config.isForcePlace()) {
if (shouldBailForCarvingAnchor(placer, config, i, h, ii)) {
bail = true;
break;
}
}
if (h < y) {
y = h;
}
}
}
} else if (config.getMode().equals(ObjectPlaceMode.PAINT)) {
y = placer.getHighest(x, z, self.getLoader(), config.isUnderwater()) + rty;
if (!config.isForcePlace()) {
if (shouldBailForCarvingAnchor(placer, config, x, y, z)) {
bail = true;
}
}
} else if (config.getMode().equals(ObjectPlaceMode.FLOATING)) {
y = rty;
switch (config.getMode()) {
case MAX_HEIGHT -> ObjectPlaceMode.MAX_HEIGHT.getBehavior().setHeight(context);
case FAST_MAX_HEIGHT -> ObjectPlaceMode.FAST_MAX_HEIGHT.getBehavior().setHeight(context);
case MIN_HEIGHT -> ObjectPlaceMode.MIN_HEIGHT.getBehavior().setHeight(context);
case FAST_MIN_HEIGHT -> ObjectPlaceMode.FAST_MIN_HEIGHT.getBehavior().setHeight(context);
case CENTER_HEIGHT -> ObjectPlaceMode.CENTER_HEIGHT.getBehavior().setHeight(context);
case PAINT -> ObjectPlaceMode.PAINT.getBehavior().setHeight(context);
case FLOATING -> ObjectPlaceMode.FLOATING.getBehavior().setHeight(context);
default -> throw new RuntimeException("Invalid placement mode: " + config.getMode().name());
}
} else {
y = yv;
if (!config.isForcePlace() && !rawStructurePiece) {
if (shouldBailForCarvingAnchor(placer, config, x, y, z)) {
bail = true;
context.bail = true;
}
}
}
@@ -251,7 +162,7 @@ final class IrisObjectPlacementRunner {
CarvingMode carvingMode = config.getCarvingSupport();
if (!config.isForcePlace() && !carvingMode.equals(CarvingMode.CARVING_ONLY)) {
if (shouldBailForCarvingAnchor(placer, config, x, y, z)) {
bail = true;
context.bail = true;
}
}
}
@@ -269,7 +180,7 @@ final class IrisObjectPlacementRunner {
return -1;
}
if (bail && !config.isForcePlace()) {
if (context.bail && !config.isForcePlace()) {
return -1;
}
@@ -361,7 +272,8 @@ final class IrisObjectPlacementRunner {
int vacuumHighest = Integer.MIN_VALUE;
self.readLock.lock();
KMap<IrisBlockVector, String> markers = null;
KList<MarkerPlacement> markerPlacements = null;
RNG markerRng = null;
try {
VectorMap<PlatformBlockState> blocks = self.blocks;
@@ -370,50 +282,20 @@ final class IrisObjectPlacementRunner {
boolean hasStates = !states.isEmpty();
if (config.getMarkers().isNotEmpty() && placer.getEngine() != null) {
markers = new KMap<>();
KList<IrisBlockVector> list = StreamSupport.stream(blocks.keys().spliterator(), false)
.collect(KList.collector());
markerPlacements = new KList<>();
// Marker selection persists into the mantle, so it must be seed-deterministic.
// Derive a side stream keyed on the placement position instead of consuming the
// caller's rng: consuming draws there would shift every later placement in the
// chunk and invalidate existing worlds/goldenhashes.
RNG markerRng = rng.nextParallelRNG(((((long) x) << 32) | (z & 0xFFFFFFFFL)) * 31L + yv);
markerRng = rng.nextParallelRNG(((((long) x) << 32) | (z & 0xFFFFFFFFL)) * 31L + yv);
int markerIndex = 0;
for (IrisObjectMarker j : config.getMarkers()) {
IrisMarker marker = self.getLoader().getMarkerLoader().load(j.getMarker());
for (IrisObjectMarker markerConfig : config.getMarkers()) {
IrisMarker marker = self.getLoader().getMarkerLoader().load(markerConfig.getMarker());
int markerSalt = markerIndex++;
if (marker == null) {
continue;
}
int max = j.getMaximumMarkers();
for (IrisBlockVector i : list.shuffleCopy(markerRng.nextParallelRNG(markerSalt))) {
if (max <= 0) {
break;
}
PlatformBlockState data = blocks.get(i);
if (data == null) {
continue;
}
for (PlatformBlockState k : j.getMark(rdata)) {
if (max <= 0) {
break;
}
if (j.isExact() ? k.matches(data) : IrisObjectShaping.materialKey(k).equals(IrisObjectShaping.materialKey(data))) {
boolean a = !blocks.containsKey((IrisBlockVector) i.clone().add(new IrisBlockVector(0, 1, 0)));
boolean fff = !blocks.containsKey((IrisBlockVector) i.clone().add(new IrisBlockVector(0, 2, 0)));
if (!marker.isEmptyAbove() || (a && fff)) {
markers.put(i, j.getMarker());
max--;
}
}
}
if (marker != null) {
markerPlacements.add(new MarkerPlacement(markerConfig, marker,
markerConfig.getMark(rdata), markerSalt));
}
}
}
@@ -489,6 +371,18 @@ final class IrisObjectPlacementRunner {
}
}
KList<MarkerPlacement> matchingMarkers = null;
if (markerPlacements != null) {
for (MarkerPlacement markerPlacement : markerPlacements) {
if (markerPlacement.matches(data)) {
if (matchingMarkers == null) {
matchingMarkers = new KList<>();
}
matchingMarkers.add(markerPlacement);
}
}
}
data = config.getRotation().rotate(data, spinx, spiny, spinz);
xx = x + (int) Math.round(i.getX());
@@ -535,8 +429,11 @@ final class IrisObjectPlacementRunner {
if (tile != null) {
placer.setTile(xx, yy, zz, tile);
}
if (markers != null && markers.containsKey(g)) {
placer.setData(xx, yy, zz, new MatterMarker(markers.get(g)));
if (matchingMarkers != null) {
BlockPosition markerPosition = new BlockPosition(xx, yy, zz);
for (MarkerPlacement markerPlacement : matchingMarkers) {
markerPlacement.candidates.add(markerPosition);
}
}
if (listener != null) {
listener.accept(new BlockPosition(xx, yy, zz), data);
@@ -549,11 +446,32 @@ final class IrisObjectPlacementRunner {
}
}
}
if (markerPlacements != null) {
for (MarkerPlacement markerPlacement : markerPlacements) {
int max = markerPlacement.config.getMaximumMarkers();
for (BlockPosition position : markerPlacement.candidates
.shuffleCopy(markerRng.nextParallelRNG(markerPlacement.salt))) {
if (max <= 0) {
break;
}
boolean firstAboveAir = B.isAir(placer.get(position.getX(), position.getY() + 1, position.getZ()));
boolean secondAboveAir = B.isAir(placer.get(position.getX(), position.getY() + 2, position.getZ()));
if (!markerPlacement.marker.isEmptyAbove() || (firstAboveAir && secondAboveAir)) {
placer.setData(position.getX(), position.getY(), position.getZ(),
new MatterMarker(markerPlacement.config.getMarker()));
max--;
}
}
}
}
} finally {
self.readLock.unlock();
}
if (stilting) {
}
if (vacuuming && vacuumLowest != Integer.MAX_VALUE && placer.getEngine() != null) {
@@ -917,6 +835,33 @@ final class IrisObjectPlacementRunner {
return result;
}
private static final class MarkerPlacement {
private final IrisObjectMarker config;
private final IrisMarker marker;
private final Iterable<PlatformBlockState> targets;
private final int salt;
private final KList<BlockPosition> candidates = new KList<>();
private MarkerPlacement(IrisObjectMarker config, IrisMarker marker,
Iterable<PlatformBlockState> targets, int salt) {
this.config = config;
this.marker = marker;
this.targets = targets;
this.salt = salt;
}
private boolean matches(PlatformBlockState state) {
for (PlatformBlockState target : targets) {
if (config.isExact()
? target.matches(state)
: IrisObjectShaping.materialKey(target).equals(IrisObjectShaping.materialKey(state))) {
return true;
}
}
return false;
}
}
/**
* Precomputed vector rotation for a single placement.
* <p>
@@ -1066,10 +1011,6 @@ final class IrisObjectPlacementRunner {
}
}
@Deprecated
private record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
}
private record WorldBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
}
}
@@ -19,7 +19,6 @@
package art.arcane.iris.engine.object;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.placer.*;
import lombok.Getter;
@Desc("Object Place modes are useful for positioning objects just right. The default value is CENTER_HEIGHT.")
@@ -0,0 +1,7 @@
package art.arcane.iris.engine.object;
public interface PlacementBehavior {
void setHeight(PlacementContext context);
}
@@ -1,15 +1,14 @@
package art.arcane.iris.engine.object.placer;
package art.arcane.iris.engine.object;
public class PlacementBehaviorCenterHeight implements PlacementBehavior{
@Override
public int getHeight(PlacementContext context) {
public void setHeight(PlacementContext context) {
context.y = (context.caveResult != null ? context.caveResult.getSurface() : context.placer.getHighest(context.x, context.z, context.self.getLoader(), context.config.isUnderwater())) + context.rty;
if (!context.config.isForcePlace()) {
if (context.shouldBailForCarvingAnchor()) {
return -1;
context.bail = true;
}
}
return context.y;
}
}
@@ -0,0 +1,10 @@
package art.arcane.iris.engine.object;
public class PlacementBehaviorFloating implements PlacementBehavior {
@Override
public void setHeight(PlacementContext context) {
context.y = context.rty;
}
}
@@ -1,4 +1,4 @@
package art.arcane.iris.engine.object.placer;
package art.arcane.iris.engine.object;
public class PlacementBehaviorHeight implements PlacementBehavior {
@@ -20,54 +20,53 @@ public class PlacementBehaviorHeight implements PlacementBehavior {
}
@Override
public int getHeight(PlacementContext context) {
public void setHeight(PlacementContext context) {
minX = context.x + context.bounds.minX();
maxX = context.x + context.bounds.maxX();
minZ = context.z + context.bounds.minZ();
maxZ = context.z + context.bounds.maxZ();
if (Mode.MIN == mode) {
context.y = context.placer.getEngine().getHeight() + 1;
}
if (fast) {
return computeFastHeight(context);
computeFastHeight(context);
} else {
return computeHeight(context);
computeHeight(context);
}
}
private int computeFastHeight(PlacementContext context) {
private void computeFastHeight(PlacementContext context) {
int xRadius = Math.max(0, (maxX - minX) / 2);
int zRadius = Math.max(0, (maxZ - minZ) / 2);
for (int i = minX; i <= maxX; i += Math.abs(xRadius) + 1) {
for (int ii = minZ; ii <= maxZ; ii += Math.abs(zRadius) + 1) {
if (columnHeight(context, i, ii)) return -1;
columnHeight(context, i, ii);
}
}
return context.y;
}
private int computeHeight(PlacementContext context) {
private void computeHeight(PlacementContext context) {
for (int i = minX; i <= maxX; i++) {
for (int ii = minZ; ii <= maxZ; ii++) {
if (columnHeight(context, i, ii)) return -1;
columnHeight(context, i, ii);
}
}
return context.y;
}
private boolean columnHeight(PlacementContext context, int i, int ii) {
private void columnHeight(PlacementContext context, int i, int ii) {
int h = context.placer.getHighest(i, ii, context.self.getLoader(), context.config.isUnderwater()) + context.rty;
if (!context.config.isForcePlace()) {
if (context.shouldBailForCarvingAnchor(i, h, ii)) {
return true;
context.bail = true;
}
}
if (Mode.MAX == mode && h < context.y) {
if (Mode.MIN == mode && h < context.y) {
context.y = h;
}
if (Mode.MIN == mode && h > context.y) {
if (Mode.MAX == mode && h > context.y) {
context.y = h;
}
return false;
}
}
@@ -1,16 +1,15 @@
package art.arcane.iris.engine.object.placer;
package art.arcane.iris.engine.object;
public class PlacementBehaviorPaint implements PlacementBehavior {
@Override
public int getHeight(PlacementContext context) {
public void setHeight(PlacementContext context) {
context.y = context.placer.getHighest(context.x, context.z, context.self.getLoader(), context.config.isUnderwater()) + context.rty;
if (!context.config.isForcePlace()) {
if (context.shouldBailForCarvingAnchor(context.x, context.y, context.z)) {
return -1;
context.bail = true;
}
}
return context.y;
}
}
@@ -1,6 +1,5 @@
package art.arcane.iris.engine.object.placer;
package art.arcane.iris.engine.object;
import art.arcane.iris.engine.object.*;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
@@ -25,7 +24,7 @@ public class PlacementBehaviorStilt implements PlacementBehavior {
}
@Override
public int getHeight(PlacementContext context) {
public int setHeight(PlacementContext context) {
return 0;
}
@@ -39,13 +38,13 @@ public class PlacementBehaviorStilt implements PlacementBehavior {
double erodeCentroidX = 0;
double erodeCentroidZ = 0;
double erodeMaxDist = 1;
if (eroding) {
if (context.config.getMode() == ObjectPlaceMode.ERODE_STILT) {
int centroidCount = 0;
VectorMap<PlatformBlockState>.Cursor centroidCursor = blocks.cursor();
while (centroidCursor.next()) {
IrisBlockVector rot = centroidCursor.key().clone();
spin.rotate(rot);
if (translating) {
if (context.config.getTranslate().canTranslate()) {
rot.add(translateOffset);
}
if (rot.getBlockY() == lowest) {
@@ -170,7 +169,7 @@ public class PlacementBehaviorStilt implements PlacementBehavior {
if (ceilingHang) {
int scan = 0;
int solidY = startY + 1;
while (scan < maxScan && !placer.isSolid(xx, solidY, zz)) {
while (scan < maxScan && !context.placer.isSolid(xx, solidY, zz)) {
solidY++;
scan++;
}
@@ -228,7 +227,7 @@ public class PlacementBehaviorStilt implements PlacementBehavior {
lowerBound -= Math.min(context.config.getStiltSettings().getYMax() - (lowest + y - highest), 0);
}
if (eroding) {
if (context.config.getMode() == ObjectPlaceMode.ERODE_STILT) {
double dx = i.getX() - erodeCentroidX;
double dz = i.getZ() - erodeCentroidZ;
double normalizedDist = Math.sqrt(dx * dx + dz * dz) / erodeMaxDist;
@@ -243,7 +242,7 @@ public class PlacementBehaviorStilt implements PlacementBehavior {
if (B.isFluid(fluidState)) {
break;
}
if (eroding) {
if (context.config.getMode() == ObjectPlaceMode.ERODE_STILT) {
int depth = (lowest + context.y) - j;
int totalDepth = (lowest + context.y) - lowerBound;
double depthRatio = totalDepth > 0 ? (double) depth / totalDepth : 0;
@@ -1,15 +1,11 @@
package art.arcane.iris.engine.object.placer;
package art.arcane.iris.engine.object;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.*;
import art.arcane.volmlib.util.math.RNG;
import lombok.AllArgsConstructor;
@AllArgsConstructor
public final class PlacementContext {
public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
}
public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {}
IrisObjectPlacement config;
final IObjectPlacer placer;
@@ -17,14 +13,35 @@ public final class PlacementContext {
final RNG rng;
IrisObject self;
TransformedBounds bounds;
boolean bail;
int x;
int z;
int y;
int rty;
public PlacementContext(
IrisObjectPlacement config,
IObjectPlacer placer,
CarveResult caveResult,
RNG rng,
IrisObject self,
int x,
int y,
int z,
int rty
) {
this.config = config;
this.placer = placer;
this.caveResult = caveResult;
this.rng = rng;
this.self = self;
this.x = x;
this.y = y;
this.z = z;
}
public boolean shouldBailForCarvingAnchor() {
public boolean shouldBailForCarvingAnchor() {
return shouldBailForCarvingAnchor(x,y,z);
}
@@ -1,9 +0,0 @@
package art.arcane.iris.engine.object.placer;
import art.arcane.iris.engine.object.IrisObjectPlacement;
public interface PlacementBehavior {
int getHeight(PlacementContext context);
}
@@ -1,10 +0,0 @@
package art.arcane.iris.engine.object.placer;
public class PlacementBehaviorFloating implements PlacementBehavior {
@Override
public int getHeight(PlacementContext context) {
return context.y = context.rty;
}
}