Show the biome that placed a structure in dust

Structures start from their origin chunk's biome, cave biome, region or
dimension, then reach into neighbouring biomes. Dust on a structure piece
now names that owner, found from the structure plan, so it works on chunks
generated before this change too. Chest markers that structures record
carry the owner as well, and a placement can now be owned by the dimension.
This commit is contained in:
piexel committed 2026-11-12 17:29:31 +01:00
1 parent ecc08197e8
commit 573e631bb8
32 files changed
+176 -48

No files matched your search

@@ -6,6 +6,7 @@ import art.arcane.iris.engine.framework.structure.StructureWorld;
import com.volmit.config.FeatureSettings;
import com.volmit.config.Level;
import com.volmit.config.SettingsStack;
import com.volmit.placement.PlacementOwner;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import com.volmit.world.RunningWorld;
@@ -62,13 +63,54 @@ public final class StructurePlacementScope {
}
}
/**
* The biome, cave biome, region or dimension whose settings make {@link #placementsAt} name {@code placement} for
* the chunk, looked for in the order that adds them; empty when none of them declares it.
*/
public static Optional<PlacementOwner> ownerOf(PackWorld world, StructurePlacement placement, int chunkX, int chunkZ) {
RunningWorld running = StructureWorld.running(world);
int blockX = (chunkX << 4) + CHUNK_CENTER_OFFSET_BLOCKS;
int blockZ = (chunkZ << 4) + CHUNK_CENTER_OFFSET_BLOCKS;
SettingsStack<StructurePlacementSettings> declared = running.settings().at(StructurePlacementSettings.class, blockX, blockZ);
return declaringEntry(declared, Level.BIOME, placement)
.or(() -> declaringCaveBiome(running, blockX, blockZ, placement))
.or(() -> declaringEntry(declared, Level.REGION, placement))
.or(() -> declaringEntry(declared, Level.DIMENSION, placement));
}
private static Optional<PlacementOwner> declaringEntry(SettingsStack<StructurePlacementSettings> declared, Level level,
StructurePlacement placement) {
return declared.entries().stream()
.filter(entry -> entry.level() == level && declares(entry.value().placements(), placement))
.findFirst()
.map(entry -> new PlacementOwner(level, entry.source()));
}
private static Optional<PlacementOwner> declaringCaveBiome(RunningWorld running, int blockX, int blockZ,
StructurePlacement placement) {
if (!placement.resolvedAnchor().isCave()) {
return Optional.empty();
}
return caveBiomeAt(running, blockX, blockZ)
.filter(cave -> declares(placementsOf(running.settings().declaredBy(cave, StructurePlacementSettings.class)), placement))
.map(PlacementOwner::biome);
}
private static boolean declares(List<StructurePlacement> placements, StructurePlacement placement) {
return placements.stream().anyMatch(declared -> declared == placement);
}
private static Optional<StructurePlacementSettings> caveBiomeSettings(RunningWorld running, int blockX, int blockZ) {
FeatureSettings settings = running.settings();
return caveBiomeAt(running, blockX, blockZ).flatMap(cave -> settings.declaredBy(cave, StructurePlacementSettings.class));
}
/** The column's cave biome, when it is another than its surface biome. */
private static Optional<ResourceId> caveBiomeAt(RunningWorld running, int blockX, int blockZ) {
TerrainSampler layout = running.layout();
ResourceId surfaceBiome = layout.surfaceBiome(blockX, blockZ);
Optional<ResourceId> caveBiome = layout.caveBiome(blockX, layout.bounds().minY(), blockZ)
return layout.caveBiome(blockX, layout.bounds().minY(), blockZ)
.filter(cave -> !cave.equals(surfaceBiome));
FeatureSettings settings = running.settings();
return caveBiome.flatMap(cave -> settings.declaredBy(cave, StructurePlacementSettings.class));
}
private static ScopeIndex buildScopeIndex(PackWorld world) {
@@ -81,12 +81,17 @@ public final class StructurePiecesAt implements ObjectsAt {
}
Optional<PlacementRecord> piece = pieceCovering(world, resolved, x, blockY, z);
if (piece.isPresent()) {
return piece;
return piece.map(record -> ownedByOrigin(world, placement, originChunkX, originChunkZ, record));
}
}
return Optional.empty();
}
private static PlacementRecord ownedByOrigin(PackWorld world, StructurePlacement placement, int originChunkX, int originChunkZ,
PlacementRecord piece) {
return StructurePlacementScope.ownerOf(world, placement, originChunkX, originChunkZ).map(piece::ownedBy).orElse(piece);
}
private static Optional<PlacementRecord> pieceCovering(PackWorld world, IrisStructureLocator.ResolvedPlacement resolved,
int x, int blockY, int z) {
List<AssembledPiece> pieces = resolved.pieces();
@@ -57,6 +57,7 @@ import com.volmit.noise.NoiseStyle;
import com.volmit.object.ObjectBlock;
import com.volmit.object.PlaceableObject;
import com.volmit.placement.PlacementOutcome;
import com.volmit.placement.PlacementOwner;
import com.volmit.placement.PlacementRecord;
import com.volmit.placement.PlacementTerrain;
import com.volmit.config.PackSettings;
@@ -118,6 +119,7 @@ public class StructurePlacing {
}
String key = resolved.structureKey();
StructureOrigin origin = new StructureOrigin(key, StructurePlacementScope.ownerOf(world, placement, cx, cz));
StructureStamp stamp = resolved.stamp();
KList<AssembledPiece> pieces = resolvedPiecesOrNull(resolved, cx, cz);
if (pieces == null) {
@@ -151,7 +153,7 @@ public class StructurePlacing {
? null : new ColumnHeights(0);
boolean supportNonOccluding = stilt != null && stilt.supportNonOccluding();
if (samplesPieceHeight(placement, stamp, pieces)) {
if (placeObject(context, key, stamp, pieces.getFirst(), mode, true,
if (placeObject(context, origin, stamp, pieces.getFirst(), mode, true,
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
failedPieces++;
}
@@ -159,7 +161,7 @@ public class StructurePlacing {
ObjectPlaceMode pieceMode = placement.isAnchoredUnderground() && mode.placeMode().has(PlaceTrait.CAVE_ANCHORED)
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
for (AssembledPiece p : pieces) {
if (placeObject(context, key, stamp, p, pieceMode, false,
if (placeObject(context, origin, stamp, p, pieceMode, false,
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
failedPieces++;
}
@@ -560,7 +562,7 @@ public class StructurePlacing {
return placement.loot(loot);
}
private int placeObject(MantleStageContext context, String structureKey, StructureStamp stamp, AssembledPiece p,
private int placeObject(MantleStageContext context, StructureOrigin origin, StructureStamp stamp, AssembledPiece p,
ObjectPlaceMode mode, boolean sampledHeight, ColumnHeights foundationColumns,
boolean supportNonOccluding) {
PlaceableObject object = objectOf(p);
@@ -581,16 +583,16 @@ public class StructurePlacing {
if (!outcome.isPlaced()) {
return REJECTED_PIECE;
}
recordPieceBlocks(terrain, run, structureKey, p, objectKey, foundationColumns, supportNonOccluding);
recordPieceBlocks(terrain, run, origin, p, objectKey, foundationColumns, supportNonOccluding);
return run.anchorY().orElseThrow(() -> new IllegalStateException(
"The placement graph placed " + objectKey + " without anchoring it"));
}
/** Notes each block the piece wrote as a base cell of the foundation, and marks its storage blocks as the structure's. */
private void recordPieceBlocks(PlacementTerrain terrain, ObjectRun run, String structureKey, AssembledPiece piece,
private void recordPieceBlocks(PlacementTerrain terrain, ObjectRun run, StructureOrigin origin, AssembledPiece piece,
String objectKey, ColumnHeights foundationColumns, boolean supportNonOccluding) {
BlockRegistry blocks = world.resources().blocks();
PlacementRecord record = structurePlacementRecord(structureKey, piece, objectKey);
PlacementRecord record = structurePlacementRecord(origin, piece, objectKey);
for (BlockPosition position : run.objectBlocks()) {
BlockState state = terrain.get(position.x(), position.y(), position.z());
StructureFoundationPlanner.recordBaseCell(
@@ -621,8 +623,16 @@ public class StructurePlacing {
return hash & Integer.MAX_VALUE;
}
private PlacementRecord structurePlacementRecord(String structureKey, AssembledPiece piece, String objectKey) {
return pieceRecord(world.resources(), structureKey, piece, objectKey);
private PlacementRecord structurePlacementRecord(StructureOrigin origin, AssembledPiece piece, String objectKey) {
PlacementRecord record = pieceRecord(world.resources(), origin.structureKey(), piece, objectKey);
if (record == null || origin.owner().isEmpty()) {
return record;
}
return record.ownedBy(origin.owner().get());
}
/** The structure a placement placed, and the biome, region or dimension whose settings placed it. */
private record StructureOrigin(String structureKey, Optional<PlacementOwner> owner) {
}
/** What placing the piece object {@code objectKey} records beside its blocks; null without a structure or object. */