save point 5

This commit is contained in:
piexel committed 2026-09-08 11:25:43 +02:00
1 parent 9eac507b08
commit 635cbf952e
19 files changed
+265 -254

No files matched your search

@@ -68,7 +68,6 @@ final class IrisObjectPlacementRunner {
Objects.requireNonNull(rdata, "Object placement data is required.");
IObjectPlacer placer = config.getHeightmap() != null ? new HeightmapObjectPlacer(rng, x, yv, z, config, oplacer) : oplacer;
ObjectPlacementConditions util = new ObjectPlacementConditions(config, placer, self);
boolean evaluateSlopeCondition = !config.isForcePlace() && !config.getSlopeCondition().isDefault();
if (evaluateSlopeCondition || config.isRotateTowardsSlope()) {
@@ -124,9 +123,9 @@ final class IrisObjectPlacementRunner {
int yrand = config.getTranslate().getYRandom();
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 = util.transformedBounds(spin, translating, translateOffset, ceilingHang, warpMargin);
PlacementContext context = new PlacementContext(config, rdata, placer, c, rng, spin, self, placementBounds, x, -1, z, yv, rty);
PlacementContext context = new PlacementContext(config, rdata, placer, c, rng, spin, self, x, z, yv, rty);
TransformedBounds placementBounds = context.transformedBounds(spin, translating, translateOffset, ceilingHang, warpMargin);
PlacementState state = new PlacementState(-1, placementBounds);
// if (config.isFromBottom()) {
// // todo Convert this to a dedicated mode.
@@ -137,26 +136,26 @@ final class IrisObjectPlacementRunner {
// }
// }
// } else
PlacementBehavior behavior = config.getMode().createBehavior(context, util);
PlacementModule behavior = config.getMode().createBehavior(context, state);
if (yv < 0) {
behavior.setHeight();
} else {
context.y = yv;
state.y = yv;
if (!config.isForcePlace() && !rawStructurePiece) {
if (util.shouldBailForCarvingAnchor(context.x, context.y, context.z)) {
context.bail = true;
if (context.shouldBailForCarvingAnchor(context.x, state.y, context.z)) {
state.bail = true;
}
}
}
if (yv >= 0 && config.isBottom() && !rawStructurePiece) {
context.y += Math.floorDiv(self.h, 2);
state.y += Math.floorDiv(self.h, 2);
CarvingMode carvingMode = config.getCarvingSupport();
if (!config.isForcePlace() && !carvingMode.equals(CarvingMode.CARVING_ONLY)) {
if (util.shouldBailForCarvingAnchor(context.x, context.y, context.z)) {
context.bail = true;
if (context.shouldBailForCarvingAnchor(context.x, state.y, context.z)) {
state.bail = true;
}
}
}
@@ -169,12 +168,12 @@ final class IrisObjectPlacementRunner {
&& config.getCarvingSupport().supportsSurface()
&& placer.getEngine() != null
&& placer.getEngine().getDimension().isBedrock()
&& context.y <= 1) {
warnImplausibleBedrockPlacement(placer, config, context.x, context.y, context.z);
&& state.y <= 1) {
warnImplausibleBedrockPlacement(placer, config, context.x, state.y, context.z);
return -1;
}
if (context.bail && !config.isForcePlace()) {
if (state.bail && !config.isForcePlace()) {
return -1;
}
@@ -208,24 +207,24 @@ final class IrisObjectPlacementRunner {
return -1;
}
if (!config.isForcePlace() && !rawStructurePiece && config.isUnderwater() && context.y + rty + ty >= placer.getFluidHeight()) {
if (!config.isForcePlace() && !rawStructurePiece && config.isUnderwater() && state.y + rty + ty >= placer.getFluidHeight()) {
return -1;
}
if (!config.isForcePlace() && !rawStructurePiece && !config.getClamp().canPlace(context.y + rty + ty, context.y - rty + ty)) {
if (!config.isForcePlace() && !rawStructurePiece && !config.getClamp().canPlace(state.y + rty + ty, state.y - rty + ty)) {
return -1;
}
if (!rawStructurePiece && nativeStructureVetoes(placer, config, spin, translating, translateOffset, ceilingHang,
yv < 0 && config.getMode() == ObjectPlaceMode.PAINT, warpMargin, context.x, context.y + yrand, context.z)) {
yv < 0 && config.getMode() == ObjectPlaceMode.PAINT, warpMargin, context.x, state.y + yrand, context.z)) {
return -1;
}
boolean paint = yv < 0 && config.getMode() == ObjectPlaceMode.PAINT;
ObjectPlacementConditions.WorldBounds worldBounds = null;
PlacementContext.WorldBounds worldBounds = null;
if (config.isBore() || (!config.isForcePlace() && !rawStructurePiece
&& (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty()))) {
worldBounds = util.resolveWorldBounds(placementBounds, paint, context.x, context.y + yrand, context.z);
worldBounds = context.resolveWorldBounds(state.bounds, paint, context.x, state.y + yrand, context.z);
}
if (!config.isForcePlace() && !rawStructurePiece && (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty())) {
@@ -248,7 +247,7 @@ final class IrisObjectPlacementRunner {
}
}
context.y += yrand;
state.y += yrand;
if (config.isBore()) {
for (int i = worldBounds.minX(); i <= worldBounds.maxX(); i++) {
@@ -266,7 +265,7 @@ final class IrisObjectPlacementRunner {
int vacuumHighest = Integer.MIN_VALUE;
self.readLock.lock();
ObjectBlockPass pass = new ObjectBlockPass(context, behavior);
ObjectBlockPass pass = new ObjectBlockPass(context, state, behavior, listener);
ObjectMarkerPlacement markerPlacer = null;
try {
@@ -335,14 +334,14 @@ final class IrisObjectPlacementRunner {
if (rng.chance(j.getChance())) {
for (PlatformBlockState k : j.getFind(rdata)) {
if (j.isExact() ? k.matches(data) : IrisObjectShaping.materialKey(k).equals(IrisObjectShaping.materialKey(data))) {
PlatformBlockState newData = j.getReplace(rng, i.getX() + context.x, i.getY() + context.y, i.getZ() + context.z, rdata);
PlatformBlockState newData = j.getReplace(rng, i.getX() + context.x, i.getY() + state.y, i.getZ() + context.z, rdata);
if (IrisObjectShaping.materialKey(newData).equals(IrisObjectShaping.materialKey(data)) && !(newData.isCustom() || data.isCustom()))
data = BlockDataMergeSupport.merge(data, newData);
else
data = newData;
Optional<TileData> t = j.getReplace().getTile(rng, context.x, context.y, context.z, rdata);
Optional<TileData> t = j.getReplace().getTile(rng, context.x, state.y, context.z, rdata);
if (t.isPresent()) {
tile = t.get();
}
@@ -357,12 +356,12 @@ final class IrisObjectPlacementRunner {
data = config.getRotation().rotate(data, spinx, spiny, spinz);
xx = context.x + (int) Math.round(i.getX());
int yy = context.y + (int) Math.round(i.getY());
int yy = state.y + (int) Math.round(i.getY());
zz = context.z + (int) Math.round(i.getZ());
if (warped) {
xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getX() + context.x, i.getY() + context.y, i.getZ() + context.z);
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getZ() + context.z, i.getY() + context.y, i.getX() + context.x);
xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getX() + context.x, i.getY() + state.y, i.getZ() + context.z);
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getZ() + context.z, i.getY() + state.y, i.getX() + context.x);
}
if (yv < 0 && (config.getMode().equals(ObjectPlaceMode.PAINT)) && !B.isVineBlock(data)) {
@@ -373,7 +372,7 @@ final class IrisObjectPlacementRunner {
continue;
}
if (waterlogCandidate && IrisProceduralBlocks.hasProperty(data, "waterlogged") && util.shouldAutoWaterlogBlock(yv, xx, yy, zz)) {
if (waterlogCandidate && IrisProceduralBlocks.hasProperty(data, "waterlogged") && pass.shouldAutoWaterlogBlock(yv, xx, yy, zz)) {
data = data.withProperty("waterlogged", "true");
}
@@ -455,7 +454,7 @@ final class IrisObjectPlacementRunner {
}
}
return context.y;
return state.y;
}
static boolean shouldPlaceObjectBlock(boolean rawStructurePiece, boolean air, boolean wouldReplace) {
@@ -10,7 +10,6 @@ import art.arcane.iris.util.project.noise.CNG;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.math.BlockPosition;
import art.arcane.volmlib.util.math.Position2;
import org.jspecify.annotations.NonNull;
import java.util.List;
import java.util.Optional;
@@ -23,17 +22,20 @@ class ObjectBlockPass {
private BiConsumer<BlockPosition, PlatformBlockState> listener;
private PlacementContext context;
private PlacementState state;
private VectorMap<PlatformBlockState> blocks;
private VectorMap<TileData> states;
private ObjectMarkerPlacement markerPlacer;
private PlacementBehavior behavior;
private PlacementModule behavior;
ObjectBlockPass(
PlacementContext context,
PlacementBehavior behavior,
PlacementState state,
PlacementModule behavior,
BiConsumer<BlockPosition, PlatformBlockState> listener
) {
this.context = context;
this.state = state;
this.behavior = behavior;
this.listener = listener;
this.blocks = context.self.blocks;
@@ -92,12 +94,12 @@ class ObjectBlockPass {
data = context.spin.rotate(data);
xx = context.x + (int) Math.round(vector.getX());
int yy = context.y + (int) Math.round(vector.getY());
int yy = state.y + (int) Math.round(vector.getY());
zz = context.z + (int) Math.round(vector.getZ());
if (!context.config.getWarp().isFlat()) {
xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, vector.getX() + context.x, vector.getY() + context.y, vector.getZ() + context.z);
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, vector.getZ() + context.z, vector.getY() + context.y, vector.getX() + context.x);
xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, vector.getX() + context.x, vector.getY() + state.y, vector.getZ() + context.z);
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, vector.getZ() + context.z, vector.getY() + state.y, vector.getX() + context.x);
}
if (context.yv < 0 && (is(ObjectPlaceMode.PAINT)) && !B.isVineBlock(data)) {
@@ -177,14 +179,14 @@ class ObjectBlockPass {
if (context.rng.chance(j.getChance())) {
for (PlatformBlockState k : j.getFind(context.rdata)) {
if (j.isExact() ? k.matches(data) : IrisObjectShaping.materialKey(k).equals(IrisObjectShaping.materialKey(data))) {
PlatformBlockState newData = j.getReplace(context.rng, vector.getX() + context.x, vector.getY() + context.y, vector.getZ() + context.z, context.rdata);
PlatformBlockState newData = j.getReplace(context.rng, vector.getX() + context.x, vector.getY() + state.y, vector.getZ() + context.z, context.rdata);
if (IrisObjectShaping.materialKey(newData).equals(IrisObjectShaping.materialKey(data)) && !(newData.isCustom() || data.isCustom()))
data = BlockDataMergeSupport.merge(data, newData);
else
data = newData;
Optional<TileData> t = j.getReplace().getTile(context.rng, context.x, context.y, context.z, context.rdata);
Optional<TileData> t = j.getReplace().getTile(context.rng, context.x, state.y, context.z, context.rdata);
if (t.isPresent()) {
tile = t.get();
}
@@ -4,7 +4,7 @@ import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.VectorMap;
import art.arcane.iris.util.common.math.IrisBlockVector;
public class ObjectBehaviorCeilingHang extends PlacementBehavior {
public class ObjectModuleCeilingHang extends PlacementModule {
@Override
public void onBlock(VectorMap<PlatformBlockState> blocks, VectorMap<TileData> states, PlatformBlockState block, TileData tile, IrisBlockVector vector) {
@@ -19,7 +19,6 @@
package art.arcane.iris.engine.object;
import art.arcane.iris.engine.object.annotations.Desc;
import lombok.Getter;
import java.util.function.Supplier;
@@ -27,50 +26,50 @@ import java.util.function.Supplier;
public enum ObjectPlaceMode {
@Desc("The default place mode. This mode picks a center point (where the center of the object will be) and takes the height. That height is used for the whole object.")
CENTER_HEIGHT(PlacementBehaviorCenterHeight::new),
CENTER_HEIGHT(PlacementModuleCenterHeight::new),
@Desc("Samples a lot of points where the object will cover (horizontally) and picks the highest height, that height is then used to place the object. This mode is useful for preventing any part of your object from being buried though it will float off of cliffs.")
MAX_HEIGHT(() -> new PlacementBehaviorHeight(PlacementBehaviorHeight.Mode.MAX, false)),
MAX_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MAX, false)),
@Desc("Samples only 4 points where the object will cover (horizontally) and picks the highest height, that height is then used to place the object. This mode is useful for preventing any part of your object from being buried though it will float off of cliffs.\"")
FAST_MAX_HEIGHT(() -> new PlacementBehaviorHeight(PlacementBehaviorHeight.Mode.MAX, true)),
FAST_MAX_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MAX, true)),
@Desc("Samples a lot of points where the object will cover (horizontally) and picks the lowest height, that height is then used to place the object. This mode is useful for preventing any part of your object from overhanging a cliff though it gets buried a lot")
MIN_HEIGHT(() -> new PlacementBehaviorHeight(PlacementBehaviorHeight.Mode.MIN, false)),
MIN_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MIN, false)),
@Desc("Samples only 4 points where the object will cover (horizontally) and picks the lowest height, that height is then used to place the object. This mode is useful for preventing any part of your object from overhanging a cliff though it gets buried a lot")
FAST_MIN_HEIGHT(() -> new PlacementBehaviorHeight(PlacementBehaviorHeight.Mode.MIN, true)),
FAST_MIN_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MIN, true)),
@Desc("Stilting is MAX_HEIGHT but it repeats the bottom most block of your object until it hits the surface. This is expensive because it has to first sample every height value for each x,z position of your object. Avoid using this unless its structures for performance reasons.")
STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.DEFAULT, false)),
STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.DEFAULT, false)),
@Desc("Just like stilting but very inaccurate. Useful for stilting a lot of objects without too much care on accuracy (you can use the over-stilt value to force stilts under ground further)")
FAST_STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.DEFAULT, true)),
FAST_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.DEFAULT, true)),
@Desc("Stilting is MIN_HEIGHT but it repeats the bottom most block of your object until it hits the surface. This is expensive because it has to first sample every height value for each x,z position of your object. Avoid using this unless its structures for performance reasons.")
MIN_STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.MIN, false)),
MIN_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.MIN, false)),
@Desc("Just like MIN_STILT but very inaccurate. Useful for stilting a lot of objects without too much care on accuracy (you can use the over-stilt value to force stilts under ground further)")
FAST_MIN_STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.MIN, true)),
FAST_MIN_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.MIN, true)),
@Desc("Stilting is CENTER_HEIGHT but it repeats the bottom most block of your object until it hits the surface. This is expensive because it has to first sample every height value for each x,z position of your object. Avoid using this unless its structures for performance reasons.")
CENTER_STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.CENTER, false)),
CENTER_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.CENTER, false)),
@Desc("Erode stilting tapers columns downward like an ice cream cone. Blocks near the center extend deepest while edge blocks drop off first. Blocks are randomly skipped in the lower portion for a rough organic eroded texture.")
ERODE_STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.ERODE, false)),
ERODE_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.ERODE, false)),
@Desc("Organic stilting scans straight down from the bottom of the object to the first solid block (the cave floor, or terrain) and fills the gap with the object's own bottom block. Each column stops at a slightly different, noise-varied depth and the lower portion is randomly broken up, so the underside reads as rough organic roots rather than a flat disc. Designed for objects placed inside caves so they connect to the floor instead of floating. Tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).")
ORGANIC_STILT(() -> new PlacementBehaviorStilt(PlacementBehaviorStilt.Mode.ORGANIC, false)),
ORGANIC_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.ORGANIC, false)),
@Desc("Hangs the object upside-down from a cave ceiling. The object is flipped vertically (its tip points down like a stalactite) and its top is anchored to the ceiling, while an organic, noise-varied stilt grows up into the ceiling so it never floats below the roof. Use inside caves; tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).")
@@ -98,28 +97,25 @@ public enum ObjectPlaceMode {
@Desc("Samples the height of the terrain at every x,z position of your object and pushes it down to the surface. It's pretty much like a melt function over the terrain.")
PAINT(PlacementBehaviorPaint::new),
PAINT(PlacementModulePaint::new),
@Desc("Places the object in pure air at an absolute Y driven entirely by translate.y (plus optional translate.yRandom). Terrain height, underwater, and carving anchor checks are skipped. Use this for floating islands, sky structures, clouds, or blimps where the object must not be translated to the ground.")
FLOATING(PlacementBehaviorFloating::new),
FLOATING(PlacementModuleFloating::new),
@Desc("Raw stamp at the caller-supplied (x, y, z). No terrain sampling, no stilting, no Y recomputation, no underwater or carving anchor guards. Used internally to route native Minecraft structure pieces (villages etc.) through the Iris object placer.")
STRUCTURE_PIECE;
private final Supplier<? extends PlacementBehavior> factory;
private final Supplier<? extends PlacementModule> factory;
ObjectPlaceMode(Supplier<? extends PlacementBehavior> factory) {
ObjectPlaceMode(Supplier<? extends PlacementModule> factory) {
this.factory = factory;
}
PlacementBehavior createBehavior(
PlacementContext context,
ObjectPlacementConditions conditions
) {
return factory.get().load(context, conditions);
PlacementModule createBehavior(PlacementContext context, PlacementState state) {
return factory.get().load(context, state);
}
@@ -1,110 +0,0 @@
package art.arcane.iris.engine.object;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import art.arcane.iris.util.common.math.IrisBlockVector;
import lombok.Getter;
@Getter
class ObjectPlacementConditions {
record WorldBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
}
private IrisObjectPlacement config;
private IObjectPlacer placer;
private IrisObject self;
ObjectPlacementConditions(IrisObjectPlacement config, IObjectPlacer placer, IrisObject self) {
this.config = config;
this.placer = placer;
this.self = self;
}
public boolean shouldBailForCarvingAnchor(int x, int y, int z) {
CarvingMode carvingMode = config.getCarvingSupport();
return switch (carvingMode) {
case SURFACE_ONLY -> placer.isCarved(x, y, z);
case CARVING_ONLY -> !isCarvedCaveAnchor(x, y, z);
case ANYWHERE -> false;
};
}
public boolean isCarvedCaveAnchor(int x, int y, int z) {
return placer.isCarved(x, y, z)
|| placer.isCarved(x, y - 1, z)
|| placer.isCarved(x, y - 2, z)
|| placer.isCarved(x, y - 3, z);
}
public PlacementContext.TransformedBounds transformedBounds(ObjectSpinKernel spin, boolean translating, IrisBlockVector translateOffset,
boolean ceilingHang, int margin) {
int sourceMinX = -self.getCenter().getBlockX();
int sourceMaxX = self.getW() - self.getCenter().getBlockX() - 1;
int sourceMinY = -self.getCenter().getBlockY();
int sourceMaxY = self.getH() - self.getCenter().getBlockY() - 1;
int sourceMinZ = -self.getCenter().getBlockZ();
int sourceMaxZ = self.getD() - self.getCenter().getBlockZ() - 1;
int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
int minZ = Integer.MAX_VALUE;
int maxZ = Integer.MIN_VALUE;
for (int xCorner = 0; xCorner < 2; xCorner++) {
int sourceX = xCorner == 0 ? sourceMinX : sourceMaxX;
for (int yCorner = 0; yCorner < 2; yCorner++) {
int sourceY = yCorner == 0 ? sourceMinY : sourceMaxY;
for (int zCorner = 0; zCorner < 2; zCorner++) {
int sourceZ = zCorner == 0 ? sourceMinZ : sourceMaxZ;
IrisBlockVector corner = new IrisBlockVector(sourceX, sourceY, sourceZ);
spin.rotate(corner);
if (ceilingHang) {
corner.setY(-corner.getBlockY());
}
if (translating) {
corner.add(translateOffset);
}
int transformedX = (int) Math.round(corner.getX());
int transformedY = (int) Math.round(corner.getY());
int transformedZ = (int) Math.round(corner.getZ());
minX = Math.min(minX, transformedX);
maxX = Math.max(maxX, transformedX);
minY = Math.min(minY, transformedY);
maxY = Math.max(maxY, transformedY);
minZ = Math.min(minZ, transformedZ);
maxZ = Math.max(maxZ, transformedZ);
}
}
}
return new PlacementContext.TransformedBounds(minX - margin, maxX + margin, minY, maxY, minZ - margin, maxZ + margin);
}
ObjectPlacementConditions.WorldBounds resolveWorldBounds(PlacementContext.TransformedBounds bounds,
boolean paint, int x, int y, int z) {
int minX = x + bounds.minX();
int maxX = x + bounds.maxX();
int minZ = z + bounds.minZ();
int maxZ = z + bounds.maxZ();
if (!paint) {
return new ObjectPlacementConditions.WorldBounds(minX, maxX, y + bounds.minY(), y + bounds.maxY(), minZ, maxZ);
}
int minimumSurface = Integer.MAX_VALUE;
int maximumSurface = Integer.MIN_VALUE;
for (int worldX = minX; worldX <= maxX; worldX++) {
for (int worldZ = minZ; worldZ <= maxZ; worldZ++) {
int surface = placer.getHighest(worldX, worldZ, self.getLoader(), config.isUnderwater());
minimumSurface = Math.min(minimumSurface, surface);
maximumSurface = Math.max(maximumSurface, surface);
}
}
int paintOffset = Math.floorDiv(self.h, 2);
return new ObjectPlacementConditions.WorldBounds(minX, maxX, minimumSurface + bounds.minY() + paintOffset,
maximumSurface + bounds.maxY() + paintOffset, minZ, maxZ);
}
}
@@ -1,14 +0,0 @@
package art.arcane.iris.engine.object;
public class PlacementBehaviorCenterHeight extends PlacementBehavior{
@Override
public void setHeight() {
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 (util.shouldBailForCarvingAnchor(context.x, context.y, context.z)) {
context.bail = true;
}
}
}
}
@@ -1,10 +0,0 @@
package art.arcane.iris.engine.object;
public class PlacementBehaviorFloating extends PlacementBehavior {
@Override
public void setHeight() {
context.y = context.rty;
}
}
@@ -1,17 +0,0 @@
package art.arcane.iris.engine.object;
public class PlacementBehaviorPaint extends PlacementBehavior {
private PlacementContext context;
protected ObjectPlacementConditions util;
@Override
public void setHeight() {
context.y = context.placer.getHighest(context.x, context.z, context.self.getLoader(), context.config.isUnderwater()) + context.rty;
if (!context.config.isForcePlace()) {
if (util.shouldBailForCarvingAnchor(context.x, context.y, context.z)) {
context.bail = true;
}
}
}
}
@@ -2,11 +2,15 @@ package art.arcane.iris.engine.object;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.util.common.math.IrisBlockVector;
import art.arcane.volmlib.util.math.RNG;
import lombok.AllArgsConstructor;
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) {
}
public record WorldBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
}
IrisObjectPlacement config;
final IrisData rdata;
@@ -15,12 +19,8 @@ final class PlacementContext {
final RNG rng;
ObjectSpinKernel spin;
IrisObject self;
TransformedBounds bounds;
boolean bail;
int x;
int z;
int y;
int rty;
int yv;
@@ -32,9 +32,7 @@ final class PlacementContext {
RNG rng,
ObjectSpinKernel spin,
IrisObject self,
TransformedBounds bounds,
int x,
int y,
int z,
int yv,
int rty
@@ -46,11 +44,93 @@ final class PlacementContext {
this.rng = rng;
this.spin = spin;
this.self = self;
this.bounds = bounds;
this.x = x;
this.y = y;
this.z = z;
this.yv = yv;
this.rty = rty;
}
}
public boolean shouldBailForCarvingAnchor(int x, int y, int z) {
CarvingMode carvingMode = config.getCarvingSupport();
return switch (carvingMode) {
case SURFACE_ONLY -> placer.isCarved(x, y, z);
case CARVING_ONLY -> !isCarvedCaveAnchor(x, y, z);
case ANYWHERE -> false;
};
}
public boolean isCarvedCaveAnchor(int x, int y, int z) {
return placer.isCarved(x, y, z)
|| placer.isCarved(x, y - 1, z)
|| placer.isCarved(x, y - 2, z)
|| placer.isCarved(x, y - 3, z);
}
public TransformedBounds transformedBounds(ObjectSpinKernel spin, boolean translating, IrisBlockVector translateOffset,
boolean ceilingHang, int margin) {
int sourceMinX = -self.getCenter().getBlockX();
int sourceMaxX = self.getW() - self.getCenter().getBlockX() - 1;
int sourceMinY = -self.getCenter().getBlockY();
int sourceMaxY = self.getH() - self.getCenter().getBlockY() - 1;
int sourceMinZ = -self.getCenter().getBlockZ();
int sourceMaxZ = self.getD() - self.getCenter().getBlockZ() - 1;
int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
int minZ = Integer.MAX_VALUE;
int maxZ = Integer.MIN_VALUE;
for (int xCorner = 0; xCorner < 2; xCorner++) {
int sourceX = xCorner == 0 ? sourceMinX : sourceMaxX;
for (int yCorner = 0; yCorner < 2; yCorner++) {
int sourceY = yCorner == 0 ? sourceMinY : sourceMaxY;
for (int zCorner = 0; zCorner < 2; zCorner++) {
int sourceZ = zCorner == 0 ? sourceMinZ : sourceMaxZ;
IrisBlockVector corner = new IrisBlockVector(sourceX, sourceY, sourceZ);
spin.rotate(corner);
if (ceilingHang) {
corner.setY(-corner.getBlockY());
}
if (translating) {
corner.add(translateOffset);
}
int transformedX = (int) Math.round(corner.getX());
int transformedY = (int) Math.round(corner.getY());
int transformedZ = (int) Math.round(corner.getZ());
minX = Math.min(minX, transformedX);
maxX = Math.max(maxX, transformedX);
minY = Math.min(minY, transformedY);
maxY = Math.max(maxY, transformedY);
minZ = Math.min(minZ, transformedZ);
maxZ = Math.max(maxZ, transformedZ);
}
}
}
return new TransformedBounds(minX - margin, maxX + margin, minY, maxY, minZ - margin, maxZ + margin);
}
WorldBounds resolveWorldBounds(TransformedBounds bounds, boolean paint, int x, int y, int z) {
int minX = x + bounds.minX();
int maxX = x + bounds.maxX();
int minZ = z + bounds.minZ();
int maxZ = z + bounds.maxZ();
if (!paint) {
return new WorldBounds(minX, maxX, y + bounds.minY(), y + bounds.maxY(), minZ, maxZ);
}
int minimumSurface = Integer.MAX_VALUE;
int maximumSurface = Integer.MIN_VALUE;
for (int worldX = minX; worldX <= maxX; worldX++) {
for (int worldZ = minZ; worldZ <= maxZ; worldZ++) {
int surface = placer.getHighest(worldX, worldZ, self.getLoader(), config.isUnderwater());
minimumSurface = Math.min(minimumSurface, surface);
maximumSurface = Math.max(maximumSurface, surface);
}
}
int paintOffset = Math.floorDiv(self.h, 2);
return new WorldBounds(minX, maxX, minimumSurface + bounds.minY() + paintOffset,
maximumSurface + bounds.maxY() + paintOffset, minZ, maxZ);
}
}
@@ -0,0 +1,6 @@
package art.arcane.iris.engine.object;
@FunctionalInterface
interface PlacementFunction<C> {
void execute(C context);
}
@@ -0,0 +1,13 @@
package art.arcane.iris.engine.object;
import lombok.Builder;
import java.util.HashSet;
import java.util.List;
@Builder
public class PlacementLifecycleBuilder {
HashSet<PlacementLifecycleDependency> dependencies;
}
@@ -0,0 +1,10 @@
package art.arcane.iris.engine.object;
import lombok.Builder;
@Builder
public class PlacementLifecycleDependency {
PlacementFunction<PlacementContext> function;
}
@@ -4,16 +4,20 @@ import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.VectorMap;
import art.arcane.iris.util.common.math.IrisBlockVector;
public abstract class PlacementBehavior {
public abstract class PlacementModule {
PlacementContext context;
ObjectPlacementConditions util;
PlacementState state;
final PlacementBehavior load(PlacementContext context, ObjectPlacementConditions util) {
final PlacementModule load(PlacementContext context, PlacementState state) {
this.context = context;
this.util = util;
this.state = state;
return this;
}
void install() {
}
void setHeight() {}
void onBlock(VectorMap<PlatformBlockState> blocks, VectorMap<TileData> states, PlatformBlockState block, TileData tile, IrisBlockVector vector) {}
@@ -0,0 +1,14 @@
package art.arcane.iris.engine.object;
public class PlacementModuleCenterHeight extends PlacementModule {
@Override
public void setHeight() {
state.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(context.x, state.y, context.z)) {
state.bail = true;
}
}
}
}
@@ -0,0 +1,10 @@
package art.arcane.iris.engine.object;
public class PlacementModuleFloating extends PlacementModule {
@Override
public void setHeight() {
state.y = context.rty;
}
}
@@ -1,6 +1,6 @@
package art.arcane.iris.engine.object;
public class PlacementBehaviorHeight extends PlacementBehavior {
public class PlacementModuleHeight extends PlacementModule {
int minX;
int maxX;
@@ -15,19 +15,19 @@ public class PlacementBehaviorHeight extends PlacementBehavior {
MAX
}
public PlacementBehaviorHeight(Mode mode, boolean fast) {
public PlacementModuleHeight(Mode mode, boolean fast) {
this.fast = fast;
this.mode = mode;
}
@Override
public void setHeight() {
minX = context.x + context.bounds.minX();
maxX = context.x + context.bounds.maxX();
minZ = context.z + context.bounds.minZ();
maxZ = context.z + context.bounds.maxZ();
minX = context.x + state.bounds.minX();
maxX = context.x + state.bounds.maxX();
minZ = context.z + state.bounds.minZ();
maxZ = context.z + state.bounds.maxZ();
if (Mode.MIN == mode) {
context.y = context.placer.getEngine().getHeight() + 1;
state.y = context.placer.getEngine().getHeight() + 1;
}
if (fast) {
computeFastHeight(context);
@@ -42,7 +42,7 @@ public class PlacementBehaviorHeight extends PlacementBehavior {
for (int i = minX; i <= maxX; i += Math.abs(xRadius) + 1) {
for (int ii = minZ; ii <= maxZ; ii += Math.abs(zRadius) + 1) {
columnHeight(context, util, i, ii);
columnHeight(context, i, ii);
}
}
}
@@ -50,24 +50,24 @@ public class PlacementBehaviorHeight extends PlacementBehavior {
private void computeHeight(PlacementContext context) {
for (int i = minX; i <= maxX; i++) {
for (int ii = minZ; ii <= maxZ; ii++) {
columnHeight(context, util, i, ii);
columnHeight(context, i, ii);
}
}
}
private void columnHeight(PlacementContext context, ObjectPlacementConditions util, 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 (util.shouldBailForCarvingAnchor(i, h, ii)) {
context.bail = true;
if (context.shouldBailForCarvingAnchor(i, h, ii)) {
state.bail = true;
}
}
if (Mode.MIN == mode && h < context.y) {
context.y = h;
if (Mode.MIN == mode && h < state.y) {
state.y = h;
}
if (Mode.MAX == mode && h > context.y) {
context.y = h;
if (Mode.MAX == mode && h > state.y) {
state.y = h;
}
}
}
@@ -0,0 +1,14 @@
package art.arcane.iris.engine.object;
public class PlacementModulePaint extends PlacementModule {
@Override
public void setHeight() {
state.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, state.y, context.z)) {
state.bail = true;
}
}
}
}
@@ -7,7 +7,7 @@ import art.arcane.iris.util.common.data.VectorMap;
import art.arcane.iris.util.common.math.IrisBlockVector;
import art.arcane.iris.util.project.noise.CNG;
public class PlacementBehaviorStilt extends PlacementBehavior {
public class PlacementModuleStilt extends PlacementModule {
private boolean fast;
private boolean erode;
@@ -20,7 +20,7 @@ public class PlacementBehaviorStilt extends PlacementBehavior {
ORGANIC
}
public PlacementBehaviorStilt(Mode mode, boolean fast) {
public PlacementModuleStilt(Mode mode, boolean fast) {
this.mode = mode;
this.fast = fast;
}
@@ -28,22 +28,22 @@ public class PlacementBehaviorStilt extends PlacementBehavior {
@Override
public void setHeight() {
switch (mode) {
case CENTER, ORGANIC -> ObjectPlaceMode.CENTER_HEIGHT.createBehavior(context, util).setHeight();
case CENTER, ORGANIC -> ObjectPlaceMode.CENTER_HEIGHT.createBehavior(context, state).setHeight();
case ERODE -> {
// Only handled in post
}
case MIN -> {
if (fast) {
ObjectPlaceMode.FAST_MIN_HEIGHT.createBehavior(context, util).setHeight();
ObjectPlaceMode.FAST_MIN_HEIGHT.createBehavior(context, state).setHeight();
} else {
ObjectPlaceMode.MIN_HEIGHT.createBehavior(context, util).setHeight();
ObjectPlaceMode.MIN_HEIGHT.createBehavior(context, state).setHeight();
}
}
case DEFAULT -> {
if (fast) {
ObjectPlaceMode.FAST_MAX_HEIGHT.createBehavior(context, util).setHeight();
ObjectPlaceMode.FAST_MAX_HEIGHT.createBehavior(context, state).setHeight();
} else {
ObjectPlaceMode.MAX_HEIGHT.createBehavior(context, util).setHeight();
ObjectPlaceMode.MAX_HEIGHT.createBehavior(context, state).setHeight();
}
}
}
@@ -101,7 +101,7 @@ public class PlacementBehaviorStilt extends PlacementBehavior {
private void applyOrganic(int targetLayer, boolean ceilingHang) {
var settings = context.config.getStiltSettings();
int startY = targetLayer + context.y;
int startY = targetLayer + state.y;
int maxScan = settings != null ? Math.max(1, settings.getOrganicMaxScan()) : 48;
int jitterMax = settings != null ? Math.max(0, settings.getOrganicJitter()) : 3;
double scratch = settings != null ? Math.max(0, Math.min(1, settings.getOrganicScratch())) : 0.55;
@@ -197,7 +197,7 @@ public class PlacementBehaviorStilt extends PlacementBehavior {
PlatformBlockState d = sourceData;
if (settings != null && settings.getPalette() != null) {
d = context.config.getStiltSettings().getPalette().get(rng, context.x, context.y, context.z, context.rdata);
d = context.config.getStiltSettings().getPalette().get(rng, context.x, state.y, context.z, context.rdata);
} else {
String mat = IrisObjectShaping.materialKey(d);
if (mat.equals("minecraft:grass_block") || mat.equals("minecraft:mycelium") || mat.equals("minecraft:podzol") || mat.equals("minecraft:dirt_path")) {
@@ -247,8 +247,8 @@ public class PlacementBehaviorStilt extends PlacementBehavior {
zz = context.z + (int) Math.round(i.getZ());
if (warped) {
xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getX() + context.x, i.getY() + context.y, i.getZ() + context.z);
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getZ() + context.z, i.getY() + context.y, i.getX() + context.x);
xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getX() + context.x, i.getY() + state.y, i.getZ() + context.z);
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getZ() + context.z, i.getY() + state.y, i.getX() + context.x);
}
if (organic) {
@@ -285,8 +285,8 @@ public class PlacementBehaviorStilt extends PlacementBehavior {
break;
}
if (context.config.getMode() == ObjectPlaceMode.ERODE_STILT) {
int depth = (lowest + context.y) - j;
int totalDepth = (lowest + context.y) - lowerBound;
int depth = (lowest + state.y) - j;
int totalDepth = (lowest + state.y) - lowerBound;
double depthRatio = totalDepth > 0 ? (double) depth / totalDepth : 0;
if (depthRatio > 0.4) {
long hash = ((long) (xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L));
@@ -0,0 +1,14 @@
package art.arcane.iris.engine.object;
import art.arcane.iris.engine.object.PlacementContext.TransformedBounds;
final class PlacementState {
int y;
TransformedBounds bounds;
boolean bail;
PlacementState(int y, TransformedBounds bounds) {
this.y = y;
this.bounds = bounds;
}
}