From 715e17099dca091a7e521e877e3c966cfbb4543c Mon Sep 17 00:00:00 2001 From: piexel Date: Mon, 31 Aug 2026 22:12:37 +0200 Subject: [PATCH] save point 3 --- .../object/IrisObjectPlacementRunner.java | 132 +++-------- .../engine/object/ObjectMarkerPlacement.java | 99 ++++++++ .../engine/object/PlacementBehaviorStilt.java | 221 ++++++++++-------- .../iris/engine/object/PlacementContext.java | 6 + 4 files changed, 258 insertions(+), 200 deletions(-) create mode 100644 core/src/main/java/art/arcane/iris/engine/object/ObjectMarkerPlacement.java diff --git a/core/src/main/java/art/arcane/iris/engine/object/IrisObjectPlacementRunner.java b/core/src/main/java/art/arcane/iris/engine/object/IrisObjectPlacementRunner.java index 3d74cc0c8..60a8830d1 100644 --- a/core/src/main/java/art/arcane/iris/engine/object/IrisObjectPlacementRunner.java +++ b/core/src/main/java/art/arcane/iris/engine/object/IrisObjectPlacementRunner.java @@ -40,6 +40,7 @@ import art.arcane.volmlib.util.math.Position2; import art.arcane.volmlib.util.math.RNG; import art.arcane.volmlib.util.matter.MatterMarker; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -118,20 +119,20 @@ final class IrisObjectPlacementRunner { ? config.getRotation().rotate(new IrisBlockVector(translate.getX(), translate.getY(), translate.getZ()), spinx, spiny, spinz) : null; boolean hasEdits = !config.getEdit().isEmpty(); - int y = -1; + //int y = -1; int xx, zz; 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 = transformedBounds(spin, translating, translateOffset, ceilingHang, warpMargin); - PlacementContext context = new PlacementContext(config, placer, c, rng, self, placementBounds, x, z, y, rty); + PlacementContext context = new PlacementContext(config, rdata, placer, c, rng, self, placementBounds, x, -1, z, rty); // if (config.isFromBottom()) { // // todo Convert this to a dedicated mode. // y = (self.getH() + 1) + rty; // if (!config.isForcePlace()) { -// if (shouldBailForCarvingAnchor(placer, config, x, y, z)) { +// if (shouldBailForCarvingAnchor(placer, config, context.x, y, context.z)) { // bail = true; // } // } @@ -149,19 +150,19 @@ final class IrisObjectPlacementRunner { default -> throw new RuntimeException("Invalid placement mode: " + config.getMode().name()); } } else { - y = yv; + context.y = yv; if (!config.isForcePlace() && !rawStructurePiece) { - if (shouldBailForCarvingAnchor(placer, config, x, y, z)) { + if (shouldBailForCarvingAnchor(placer, config, context.x, context.y, context.z)) { context.bail = true; } } } if (yv >= 0 && config.isBottom() && !rawStructurePiece) { - y += Math.floorDiv(self.h, 2); + context.y += Math.floorDiv(self.h, 2); CarvingMode carvingMode = config.getCarvingSupport(); if (!config.isForcePlace() && !carvingMode.equals(CarvingMode.CARVING_ONLY)) { - if (shouldBailForCarvingAnchor(placer, config, x, y, z)) { + if (shouldBailForCarvingAnchor(placer, config, context.x, context.y, context.z)) { context.bail = true; } } @@ -175,8 +176,8 @@ final class IrisObjectPlacementRunner { && config.getCarvingSupport().supportsSurface() && placer.getEngine() != null && placer.getEngine().getDimension().isBedrock() - && y <= 1) { - warnImplausibleBedrockPlacement(placer, config, x, y, z); + && context.y <= 1) { + warnImplausibleBedrockPlacement(placer, config, context.x, context.y, context.z); return -1; } @@ -198,14 +199,14 @@ final class IrisObjectPlacementRunner { && !config.isUnderwater() && !config.isOnwater() && config.isRequireSurfaceSupport() - && IrisSurfaceSupport.isUnsupported(oplacer, self.getLoader(), x, z, config.getTranslate(), + && IrisSurfaceSupport.isUnsupported(oplacer, self.getLoader(), context.x, context.z, config.getTranslate(), config.getRotation(), spinx, spiny, spinz, self.getSurfaceSupportOffsets(), config.getSurfaceSupportBuffer(), config.getSurfaceSupportDepth())) { return -1; } if (yv < 0 && !config.getMode().equals(ObjectPlaceMode.FLOATING) && !rawStructurePiece) { - if (!config.isForcePlace() && !config.isUnderwater() && !config.isOnwater() && placer.isUnderwater(x, z)) { + if (!config.isForcePlace() && !config.isUnderwater() && !config.isOnwater() && placer.isUnderwater(context.x, context.z)) { return -1; } } @@ -214,16 +215,16 @@ final class IrisObjectPlacementRunner { return -1; } - if (!config.isForcePlace() && !rawStructurePiece && config.isUnderwater() && y + rty + ty >= placer.getFluidHeight()) { + if (!config.isForcePlace() && !rawStructurePiece && config.isUnderwater() && context.y + rty + ty >= placer.getFluidHeight()) { return -1; } - if (!config.isForcePlace() && !rawStructurePiece && !config.getClamp().canPlace(y + rty + ty, y - rty + ty)) { + if (!config.isForcePlace() && !rawStructurePiece && !config.getClamp().canPlace(context.y + rty + ty, context.y - rty + ty)) { return -1; } if (!rawStructurePiece && nativeStructureVetoes(placer, config, spin, translating, translateOffset, ceilingHang, - yv < 0 && config.getMode() == ObjectPlaceMode.PAINT, warpMargin, x, y + yrand, z)) { + yv < 0 && config.getMode() == ObjectPlaceMode.PAINT, warpMargin, context.x, context.y + yrand, context.z)) { return -1; } @@ -231,7 +232,7 @@ final class IrisObjectPlacementRunner { WorldBounds worldBounds = null; if (config.isBore() || (!config.isForcePlace() && !rawStructurePiece && (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty()))) { - worldBounds = resolveWorldBounds(placer, config, placementBounds, paint, x, y + yrand, z); + worldBounds = resolveWorldBounds(placer, config, placementBounds, paint, context.x, context.y + yrand, context.z); } if (!config.isForcePlace() && !rawStructurePiece && (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty())) { @@ -254,7 +255,7 @@ final class IrisObjectPlacementRunner { } } - y += yrand; + context.y += yrand; if (config.isBore()) { for (int i = worldBounds.minX(); i <= worldBounds.maxX(); i++) { @@ -272,7 +273,8 @@ final class IrisObjectPlacementRunner { int vacuumHighest = Integer.MIN_VALUE; self.readLock.lock(); - KList markerPlacements = null; + List markerPlacements = null; + ObjectMarkerPlacement markerPlacer = null; RNG markerRng = null; try { @@ -282,22 +284,9 @@ final class IrisObjectPlacementRunner { boolean hasStates = !states.isEmpty(); if (config.getMarkers().isNotEmpty() && placer.getEngine() != null) { - 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. + markerPlacer = new ObjectMarkerPlacement(config, context); markerRng = rng.nextParallelRNG(((((long) x) << 32) | (z & 0xFFFFFFFFL)) * 31L + yv); - - int markerIndex = 0; - for (IrisObjectMarker markerConfig : config.getMarkers()) { - IrisMarker marker = self.getLoader().getMarkerLoader().load(markerConfig.getMarker()); - int markerSalt = markerIndex++; - if (marker != null) { - markerPlacements.add(new MarkerPlacement(markerConfig, marker, - markerConfig.getMark(rdata), markerSalt)); - } - } + markerPlacements = markerPlacer.possibleMarkers(); } VectorMap.Cursor cursor = blocks.cursor(); @@ -354,14 +343,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() + x, i.getY() + y, i.getZ() + z, rdata); + PlatformBlockState newData = j.getReplace(rng, i.getX() + context.x, i.getY() + context.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 t = j.getReplace().getTile(rng, x, y, z, rdata); + Optional t = j.getReplace().getTile(rng, context.x, context.y, context.z, rdata); if (t.isPresent()) { tile = t.get(); } @@ -371,27 +360,17 @@ final class IrisObjectPlacementRunner { } } - KList matchingMarkers = null; - if (markerPlacements != null) { - for (MarkerPlacement markerPlacement : markerPlacements) { - if (markerPlacement.matches(data)) { - if (matchingMarkers == null) { - matchingMarkers = new KList<>(); - } - matchingMarkers.add(markerPlacement); - } - } - } + List matchingMarkers = markerPlacements != null ? markerPlacer.matchMarkers(markerPlacements, data) : null; data = config.getRotation().rotate(data, spinx, spiny, spinz); - xx = x + (int) Math.round(i.getX()); + xx = context.x + (int) Math.round(i.getX()); - int yy = y + (int) Math.round(i.getY()); - zz = z + (int) Math.round(i.getZ()); + int yy = context.y + (int) Math.round(i.getY()); + zz = context.z + (int) Math.round(i.getZ()); if (warped) { - xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getX() + x, i.getY() + y, i.getZ() + z); - zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getZ() + z, i.getY() + y, i.getX() + x); + 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); } if (yv < 0 && (config.getMode().equals(ObjectPlaceMode.PAINT)) && !B.isVineBlock(data)) { @@ -431,7 +410,7 @@ final class IrisObjectPlacementRunner { } if (matchingMarkers != null) { BlockPosition markerPosition = new BlockPosition(xx, yy, zz); - for (MarkerPlacement markerPlacement : matchingMarkers) { + for (ObjectMarkerPlacement.MarkerPlacement markerPlacement : matchingMarkers) { markerPlacement.candidates.add(markerPosition); } } @@ -448,34 +427,20 @@ 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--; - } - } - } + markerPlacer.placeMarkers(markerPlacements, markerRng); } + } finally { self.readLock.unlock(); } if (stilting) { + // todo stilting } if (vacuuming && vacuumLowest != Integer.MAX_VALUE && placer.getEngine() != null) { - vacuumTerrain(placer, config, x, z, placementBounds.minX(), placementBounds.maxX(), + vacuumTerrain(placer, config, context.x, context.z, placementBounds.minX(), placementBounds.maxX(), placementBounds.minZ(), placementBounds.maxZ(), vacuumLowest, vacuumHighest); } @@ -494,7 +459,7 @@ final class IrisObjectPlacementRunner { } } - return y; + return context.y; } static boolean shouldPlaceObjectBlock(boolean rawStructurePiece, boolean air, boolean wouldReplace) { @@ -835,33 +800,6 @@ final class IrisObjectPlacementRunner { return result; } - private static final class MarkerPlacement { - private final IrisObjectMarker config; - private final IrisMarker marker; - private final Iterable targets; - private final int salt; - private final KList candidates = new KList<>(); - - private MarkerPlacement(IrisObjectMarker config, IrisMarker marker, - Iterable 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. *

diff --git a/core/src/main/java/art/arcane/iris/engine/object/ObjectMarkerPlacement.java b/core/src/main/java/art/arcane/iris/engine/object/ObjectMarkerPlacement.java new file mode 100644 index 000000000..430d1b626 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/engine/object/ObjectMarkerPlacement.java @@ -0,0 +1,99 @@ +package art.arcane.iris.engine.object; + +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.math.BlockPosition; +import art.arcane.volmlib.util.math.RNG; +import art.arcane.volmlib.util.matter.MatterMarker; +import lombok.AllArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class ObjectMarkerPlacement { + + private IrisObjectPlacement config; + private PlacementContext context; + + + public List possibleMarkers() { + List placements = new ArrayList<>(); + // 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. + int index = 0; + for (IrisObjectMarker markerConfig : config.getMarkers()) { + IrisMarker marker = context.self.getLoader().getMarkerLoader().load(markerConfig.getMarker()); + int markerSalt = index++; + if (marker != null) { + placements.add(new ObjectMarkerPlacement.MarkerPlacement(markerConfig, marker, + markerConfig.getMark(context.rdata), markerSalt)); + } + } + return placements; + } + + public List matchMarkers(List placements, PlatformBlockState state) { + List matching = new ArrayList<>(); + for (ObjectMarkerPlacement.MarkerPlacement markerPlacement : placements) { + if (markerPlacement.matches(state)) { + matching.add(markerPlacement); + } + } + return matching; + } + + public void placeMarkers(List placements, RNG rng) { + for (ObjectMarkerPlacement.MarkerPlacement markerPlacement : placements) { + int max = markerPlacement.config.getMaximumMarkers(); + for (BlockPosition position : markerPlacement.candidates + .shuffleCopy(rng.nextParallelRNG(markerPlacement.salt))) { + if (max <= 0) { + break; + } + + boolean firstAboveAir = B.isAir(context.placer.get(position.getX(), position.getY() + 1, position.getZ())); + boolean secondAboveAir = B.isAir(context.placer.get(position.getX(), position.getY() + 2, position.getZ())); + if (!markerPlacement.marker.isEmptyAbove() || (firstAboveAir && secondAboveAir)) { + context.placer.setData(position.getX(), position.getY(), position.getZ(), + new MatterMarker(markerPlacement.config.getMarker())); + max--; + } + } + } + + } + + + public static final class MarkerPlacement { + final IrisObjectMarker config; + final IrisMarker marker; + final Iterable targets; + final int salt; + final KList candidates = new KList<>(); + + MarkerPlacement(IrisObjectMarker config, IrisMarker marker, + Iterable targets, int salt) { + this.config = config; + this.marker = marker; + this.targets = targets; + this.salt = salt; + } + + 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; + } + } + +} + diff --git a/core/src/main/java/art/arcane/iris/engine/object/PlacementBehaviorStilt.java b/core/src/main/java/art/arcane/iris/engine/object/PlacementBehaviorStilt.java index b38154c60..01a1edcdd 100644 --- a/core/src/main/java/art/arcane/iris/engine/object/PlacementBehaviorStilt.java +++ b/core/src/main/java/art/arcane/iris/engine/object/PlacementBehaviorStilt.java @@ -5,6 +5,7 @@ import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.util.common.data.B; 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 implements PlacementBehavior { @@ -24,64 +25,129 @@ public class PlacementBehaviorStilt implements PlacementBehavior { } @Override - public int setHeight(PlacementContext context) { - return 0; + public void setHeight(PlacementContext context) { + } + private void erodeStilt(PlacementContext context) { + int centroidCount = 0; + VectorMap.Cursor centroidCursor = blocks.cursor(); + while (centroidCursor.next()) { + IrisBlockVector rot = centroidCursor.key().clone(); + spin.rotate(rot); + if (context.config.getTranslate().canTranslate()) { + rot.add(translateOffset); + } + if (rot.getBlockY() == lowest) { + PlatformBlockState bd = centroidCursor.value(); + if (bd != null && IrisObjectShaping.shouldStilt(bd)) { + erodeCentroidX += rot.getX(); + erodeCentroidZ += rot.getZ(); + centroidCount++; + } + } + } + if (centroidCount > 0) { + erodeCentroidX /= centroidCount; + erodeCentroidZ /= centroidCount; + } + VectorMap.Cursor spreadCursor = blocks.cursor(); + while (spreadCursor.next()) { + IrisBlockVector rot = spreadCursor.key().clone(); + spin.rotate(rot); + if (context.config.getTranslate().canTranslate()) { + rot.add(translateOffset); + } + if (rot.getBlockY() == lowest) { + PlatformBlockState bd = spreadCursor.value(); + if (bd != null && IrisObjectShaping.shouldStilt(bd)) { + double dx = rot.getX() - erodeCentroidX; + double dz = rot.getZ() - erodeCentroidZ; + double dist = Math.sqrt(dx * dx + dz * dz); + if (dist > erodeMaxDist) { + erodeMaxDist = dist; + } + } + } + } + } + + private void applyOrganic(PlacementContext context, IrisStiltSettings settings, int targetLayer, boolean ceilingHang) { + int startY = targetLayer + context.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; + long colHash = ((long) xx * 341873128712L) ^ ((long) zz * 132897987541L); + int jitter = jitterMax > 0 ? (int) (Math.abs(colHash) % (jitterMax + 1)) : 0; + + if (ceilingHang) { + int scan = 0; + int solidY = startY + 1; + while (scan < maxScan && !context.placer.isSolid(xx, solidY, zz)) { + solidY++; + scan++; + } + int topBound = (scan < maxScan ? solidY - 1 : startY + Math.min(maxScan, 8)) - jitter; + int total = topBound - startY; + for (int j = startY; j <= topBound; j++) { + if (scratch > 0 && total > 0) { + double ratio = (double) (j - startY) / total; + if (ratio > (1.0 - scratch)) { + long sh = ((long) xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L); + double skipChance = (ratio - (1.0 - scratch)) / scratch; + if ((Math.abs(sh) % 1000) / 1000.0 < skipChance * 0.7) { + continue; + } + } + } + context.placer.set(xx, j, zz, d); + } + } else { + int scan = 0; + int solidY = startY - 1; + while (scan < maxScan && !context.placer.isSolid(xx, solidY, zz)) { + solidY--; + scan++; + } + int bottomBound = (scan < maxScan ? solidY + 1 : startY - Math.min(maxScan, 8)) + jitter; + int total = startY - bottomBound; + for (int j = startY; j >= bottomBound; j--) { + if (scratch > 0 && total > 0) { + double ratio = (double) (startY - j) / total; + if (ratio > (1.0 - scratch)) { + long sh = ((long) xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L); + double skipChance = (ratio - (1.0 - scratch)) / scratch; + if ((Math.abs(sh) % 1000) / 1000.0 < skipChance * 0.7) { + continue; + } + } + } + context.placer.set(xx, j, zz, d); + } + } + } + private void stilt(PlacementContext context) { context.self.readLock.lock(); try { VectorMap blocks = context.self.blocks; + + boolean ceilingHang = context.config.getMode() == ObjectPlaceMode.CEILING_HANG; IrisStiltSettings settings = context.config.getStiltSettings(); double erodeCentroidX = 0; double erodeCentroidZ = 0; double erodeMaxDist = 1; + if (context.config.getMode() == ObjectPlaceMode.ERODE_STILT) { - int centroidCount = 0; - VectorMap.Cursor centroidCursor = blocks.cursor(); - while (centroidCursor.next()) { - IrisBlockVector rot = centroidCursor.key().clone(); - spin.rotate(rot); - if (context.config.getTranslate().canTranslate()) { - rot.add(translateOffset); - } - if (rot.getBlockY() == lowest) { - PlatformBlockState bd = centroidCursor.value(); - if (bd != null && IrisObjectShaping.shouldStilt(bd)) { - erodeCentroidX += rot.getX(); - erodeCentroidZ += rot.getZ(); - centroidCount++; - } - } - } - if (centroidCount > 0) { - erodeCentroidX /= centroidCount; - erodeCentroidZ /= centroidCount; - } - VectorMap.Cursor spreadCursor = blocks.cursor(); - while (spreadCursor.next()) { - IrisBlockVector rot = spreadCursor.key().clone(); - spin.rotate(rot); - if (translating) { - rot.add(translateOffset); - } - if (rot.getBlockY() == lowest) { - PlatformBlockState bd = spreadCursor.value(); - if (bd != null && IrisObjectShaping.shouldStilt(bd)) { - double dx = rot.getX() - erodeCentroidX; - double dz = rot.getZ() - erodeCentroidZ; - double dist = Math.sqrt(dx * dx + dz * dz); - if (dist > erodeMaxDist) { - erodeMaxDist = dist; - } - } - } - } + erodeStilt(context); } VectorMap.Cursor stiltCursor = blocks.cursor(); + boolean warped = !context.config.getWarp().isFlat(); + CNG surfaceWarp = warped ? context.config.getSurfaceWarp(context.rng, context.self.getLoader()) : null; + while (stiltCursor.next()) { IrisBlockVector g = stiltCursor.key(); PlatformBlockState sourceData; @@ -89,12 +155,12 @@ public class PlacementBehaviorStilt implements PlacementBehavior { sourceData = stiltCursor.value(); } catch (Throwable e) { IrisLogging.reportError(e); - IrisLogging.warn("Failed to read block node " + g.getBlockX() + "," + g.getBlockY() + "," + g.getBlockZ() + " in object " + self.getLoadKey() + " (stilt cme)"); + IrisLogging.warn("Failed to read block node " + g.getBlockX() + "," + g.getBlockY() + "," + g.getBlockZ() + " in object " + context.self.getLoadKey() + " (stilt cme)"); sourceData = IrisObject.States.AIR; } if (sourceData == null) { - IrisLogging.warn("Failed to read block node " + g.getBlockX() + "," + g.getBlockY() + "," + g.getBlockZ() + " in object " + self.getLoadKey() + " (stilt null)"); + IrisLogging.warn("Failed to read block node " + g.getBlockX() + "," + g.getBlockY() + "," + g.getBlockZ() + " in object " + context.self.getLoadKey() + " (stilt null)"); sourceData = IrisObject.States.AIR; } @@ -104,7 +170,7 @@ public class PlacementBehaviorStilt implements PlacementBehavior { PlatformBlockState d = sourceData; if (settings != null && settings.getPalette() != null) { - d = context.config.getStiltSettings().getPalette().get(rng, context.x, context.y, context.z, rdata); + d = context.config.getStiltSettings().getPalette().get(rng, context.x, context.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")) { @@ -117,24 +183,24 @@ public class PlacementBehaviorStilt implements PlacementBehavior { if (ceilingHang) { i.setY(-i.getBlockY()); } - if (translating) { + if (context.config.getTranslate().canTranslate()) { i.add(translateOffset); } - d = config.getRotation().rotate(d, spinx, spiny, spinz); + d = context.config.getRotation().rotate(d, spinx, spiny, spinz); - int targetLayer = ceilingHang ? topLayer : lowest; + int targetLayer = context.config.getMode() == ObjectPlaceMode.CEILING_HANG ? topLayer : lowest; if (i.getBlockY() != targetLayer) continue; - if (hasEdits) { + if (!context.config.getEdit().isEmpty()) { for (IrisObjectReplace j : context.config.getEdit()) { - if (rng.chance(j.getChance())) { - for (PlatformBlockState k : j.getFind(rdata)) { + if (context.rng.chance(j.getChance())) { + for (PlatformBlockState k : j.getFind(context.rdata)) { if (d == null) { continue; } if (j.isExact() ? k.matches(d) : IrisObjectShaping.materialKey(k).equals(IrisObjectShaping.materialKey(d))) { - PlatformBlockState newData = j.getReplace(rng, i.getX() + context.x, i.getY() + y, i.getZ() + context.z, rdata); + PlatformBlockState newData = j.getReplace(context.rng, i.getX() + context.x, i.getY() + y, i.getZ() + context.z, context.rdata); if (IrisObjectShaping.materialKey(newData).equals(IrisObjectShaping.materialKey(d))) { d = BlockDataMergeSupport.merge(d, newData); @@ -159,58 +225,7 @@ public class PlacementBehaviorStilt implements PlacementBehavior { } if (organic) { - int startY = targetLayer + 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; - long colHash = ((long) xx * 341873128712L) ^ ((long) zz * 132897987541L); - int jitter = jitterMax > 0 ? (int) (Math.abs(colHash) % (jitterMax + 1)) : 0; - if (ceilingHang) { - int scan = 0; - int solidY = startY + 1; - while (scan < maxScan && !context.placer.isSolid(xx, solidY, zz)) { - solidY++; - scan++; - } - int topBound = (scan < maxScan ? solidY - 1 : startY + Math.min(maxScan, 8)) - jitter; - int total = topBound - startY; - for (int j = startY; j <= topBound; j++) { - if (scratch > 0 && total > 0) { - double ratio = (double) (j - startY) / total; - if (ratio > (1.0 - scratch)) { - long sh = ((long) xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L); - double skipChance = (ratio - (1.0 - scratch)) / scratch; - if ((Math.abs(sh) % 1000) / 1000.0 < skipChance * 0.7) { - continue; - } - } - } - context.placer.set(xx, j, zz, d); - } - } else { - int scan = 0; - int solidY = startY - 1; - while (scan < maxScan && !context.placer.isSolid(xx, solidY, zz)) { - solidY--; - scan++; - } - int bottomBound = (scan < maxScan ? solidY + 1 : startY - Math.min(maxScan, 8)) + jitter; - int total = startY - bottomBound; - for (int j = startY; j >= bottomBound; j--) { - if (scratch > 0 && total > 0) { - double ratio = (double) (startY - j) / total; - if (ratio > (1.0 - scratch)) { - long sh = ((long) xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L); - double skipChance = (ratio - (1.0 - scratch)) / scratch; - if ((Math.abs(sh) % 1000) / 1000.0 < skipChance * 0.7) { - continue; - } - } - } - context.placer.set(xx, j, zz, d); - } - } continue; } diff --git a/core/src/main/java/art/arcane/iris/engine/object/PlacementContext.java b/core/src/main/java/art/arcane/iris/engine/object/PlacementContext.java index 1b364e89d..fd22be56c 100644 --- a/core/src/main/java/art/arcane/iris/engine/object/PlacementContext.java +++ b/core/src/main/java/art/arcane/iris/engine/object/PlacementContext.java @@ -1,6 +1,7 @@ package art.arcane.iris.engine.object; +import art.arcane.iris.core.loader.IrisData; import art.arcane.volmlib.util.math.RNG; import lombok.AllArgsConstructor; @@ -8,6 +9,7 @@ public final class PlacementContext { public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {} IrisObjectPlacement config; + final IrisData rdata; final IObjectPlacer placer; final CarveResult caveResult; final RNG rng; @@ -22,20 +24,24 @@ public final class PlacementContext { public PlacementContext( IrisObjectPlacement config, + IrisData rdata, IObjectPlacer placer, CarveResult caveResult, RNG rng, IrisObject self, + TransformedBounds bounds, int x, int y, int z, int rty ) { this.config = config; + this.rdata = rdata; this.placer = placer; this.caveResult = caveResult; this.rng = rng; this.self = self; + this.bounds = bounds; this.x = x; this.y = y; this.z = z;