mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Show which structure piece a dust-inspected block belongs to
Jigsaw pieces record a placement marker only on storage blocks, so the dust called every other piece block "decoration/object/stilt". Where no marker exists, the dust now asks the modules: ObjectsAt.placementAt is a new default API method, and the structure module answers it by assembling the starts within structure reach again and returning the piece whose box holds the block. A lone surface piece takes its height from the terrain when placed, so only its column has to match. The Bukkit and modded dust both print "Placed by: structure '<key>' piece '<object>'", translated in every bundled locale.
This commit is contained in:
1 parent
e9b80420de
commit
f4821f7b0d
29 files changed
+354
-28
No files matched your search
@@ -143,6 +143,7 @@ include art/arcane/iris/modules/floating/**
|
||||
jar structure
|
||||
module art.arcane.iris.engine.mantle.components.StructureModule
|
||||
include art/arcane/iris/engine/mantle/components/StructurePlacing*.class
|
||||
include art/arcane/iris/engine/mantle/components/StructurePiecesAt*.class
|
||||
include art/arcane/iris/engine/mantle/components/StructureCarvingFootprint*.class
|
||||
include art/arcane/iris/engine/mantle/components/StructureCarveEnvelope*.class
|
||||
include art/arcane/iris/engine/mantle/components/StructureFoundationPlanner*.class
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.ModuleSetup;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.stage.MantleStageContext;
|
||||
@@ -37,9 +38,10 @@ import com.volmit.stage.MantleStageContext;
|
||||
* Module {@code iris:structure}: where structures go and how they meet the terrain. It owns the structure placements a
|
||||
* pack declares, the mantle stage that places the structures starting in each chunk, the locator that finds them, the
|
||||
* answers about the platform's own structures ({@link StructureVanillaStructures}: the dimension's
|
||||
* {@code importedStructures} settings disable, move, fit and set them up, and the pack's placements replace them, place
|
||||
* opt-in {@code importedStructures} settings import, disable, move, fit and set them up, and the pack's placements replace them, place
|
||||
* them alongside, start them where their {@code nativeStructures} grids say and fit them into the terrain), the checks of
|
||||
* the placements, and the {@code /iris module structure} commands.
|
||||
* the placements, the piece planned at a block for block inspection ({@link StructurePiecesAt}), and the
|
||||
* {@code /iris module structure} commands.
|
||||
* <p>
|
||||
* It gets the pieces of a structure only from the {@link art.arcane.iris.engine.framework.structure.assembly.StructureAssembly}
|
||||
* providers of the pack's modules, such as {@code iris:jigsaw}, and knows none of them.
|
||||
@@ -63,6 +65,7 @@ public final class StructureModule implements IrisModule {
|
||||
registry.registerValidator(new StructureValidator());
|
||||
registry.registerService(StructureLocator.class, new StructureLocating());
|
||||
registry.registerService(VanillaStructures.class, new StructureVanillaStructures());
|
||||
registry.registerService(ObjectsAt.class, new StructurePiecesAt());
|
||||
setup.tooling().registerCommand(StructureCommands.root());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructurePlacement;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementScope;
|
||||
import art.arcane.iris.engine.framework.structure.assembly.AssembledPiece;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.placement.PlacementRecord;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Which structure piece {@code iris:structure} plans at a block, for the host's block inspection. Generation records
|
||||
* only the storage blocks of a piece ({@link StructurePlacing}), so this assembles the starts within structure reach of
|
||||
* the block again and answers with the piece whose box holds it. A lone surface piece takes its height from the
|
||||
* terrain when it is placed, so for it only the column has to match. The module predicts no objects per chunk.
|
||||
*/
|
||||
public final class StructurePiecesAt implements ObjectsAt {
|
||||
private static final int BLOCKS_PER_CHUNK_SHIFT = 4;
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacedBy placedBy(PackWorld world, ResourceId object) {
|
||||
return PlacedBy.NOTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlacementRecord> placementAt(PackWorld world, int worldX, int y, int worldZ) {
|
||||
int blockY = y + world.minWorldY();
|
||||
int reachChunks = (StructurePlacing.reach(world.settings()) >> BLOCKS_PER_CHUNK_SHIFT) + 1;
|
||||
int chunkX = worldX >> BLOCKS_PER_CHUNK_SHIFT;
|
||||
int chunkZ = worldZ >> BLOCKS_PER_CHUNK_SHIFT;
|
||||
for (int originX = chunkX - reachChunks; originX <= chunkX + reachChunks; originX++) {
|
||||
for (int originZ = chunkZ - reachChunks; originZ <= chunkZ + reachChunks; originZ++) {
|
||||
Optional<PlacementRecord> piece = pieceStartedIn(world, originX, originZ, worldX, blockY, worldZ);
|
||||
if (piece.isPresent()) {
|
||||
return piece;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static Optional<PlacementRecord> pieceStartedIn(PackWorld world, int originChunkX, int originChunkZ,
|
||||
int x, int blockY, int z) {
|
||||
for (StructurePlacement placement : StructurePlacementScope.placementsAt(world, originChunkX, originChunkZ)) {
|
||||
if (!placement.hasIrisStructures()) {
|
||||
continue;
|
||||
}
|
||||
IrisStructureLocator.ResolvedPlacement resolved =
|
||||
IrisStructureLocator.resolvePlacement(world, placement, originChunkX, originChunkZ);
|
||||
if (resolved == null || resolved.pieces() == null) {
|
||||
continue;
|
||||
}
|
||||
Optional<PlacementRecord> piece = pieceCovering(world, resolved, x, blockY, z);
|
||||
if (piece.isPresent()) {
|
||||
return piece;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static Optional<PlacementRecord> pieceCovering(PackWorld world, IrisStructureLocator.ResolvedPlacement resolved,
|
||||
int x, int blockY, int z) {
|
||||
List<AssembledPiece> pieces = resolved.pieces();
|
||||
boolean heightPlanned = !StructurePlacing.samplesPieceHeight(resolved.placement(), resolved.stamp(), pieces);
|
||||
for (AssembledPiece piece : pieces) {
|
||||
if (covers(piece, x, blockY, z, heightPlanned)) {
|
||||
return Optional.ofNullable(recordOf(world, resolved.structureKey(), piece));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static boolean covers(AssembledPiece piece, int x, int blockY, int z, boolean heightPlanned) {
|
||||
boolean inColumn = x >= piece.minX() && x <= piece.maxX() && z >= piece.minZ() && z <= piece.maxZ();
|
||||
return inColumn && (!heightPlanned || (blockY >= piece.minY() && blockY <= piece.maxY()));
|
||||
}
|
||||
|
||||
private static PlacementRecord recordOf(PackWorld world, String structureKey, AssembledPiece piece) {
|
||||
String objectKey = world.resources().objects().object(piece.object()).map(PlaceableObject::name).orElse(null);
|
||||
return StructurePlacing.pieceRecord(world.resources(), structureKey, piece, objectKey);
|
||||
}
|
||||
}
|
||||
+19
-19
@@ -150,30 +150,16 @@ public class StructurePlacing {
|
||||
ColumnHeights foundationColumns = stilt == null
|
||||
? null : new ColumnHeights(0);
|
||||
boolean supportNonOccluding = stilt != null && stilt.supportNonOccluding();
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = mode.placeMode().has(PlaceTrait.CAVE_ANCHORED)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (AssembledPiece p : pieces) {
|
||||
if (placeObject(context, key, stamp, p, undergroundMode, false,
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (mode.placeMode().has(PlaceTrait.FREE_HEIGHT)) {
|
||||
for (AssembledPiece p : pieces) {
|
||||
if (placeObject(context, key, stamp, p, ObjectPlaceMode.STRUCTURE_PIECE, false,
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (pieces.size() == 1) {
|
||||
if (samplesPieceHeight(placement, stamp, pieces)) {
|
||||
if (placeObject(context, key, stamp, pieces.getFirst(), mode, true,
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
} else {
|
||||
ObjectPlaceMode pieceMode = placement.isAnchoredUnderground() && mode.placeMode().has(PlaceTrait.CAVE_ANCHORED)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (AssembledPiece p : pieces) {
|
||||
if (placeObject(context, key, stamp, p, ObjectPlaceMode.STRUCTURE_PIECE, false,
|
||||
if (placeObject(context, key, stamp, p, pieceMode, false,
|
||||
foundationColumns, supportNonOccluding) == REJECTED_PIECE) {
|
||||
failedPieces++;
|
||||
}
|
||||
@@ -636,14 +622,28 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
private PlacementRecord structurePlacementRecord(String structureKey, AssembledPiece piece, String objectKey) {
|
||||
return pieceRecord(world.resources(), structureKey, piece, objectKey);
|
||||
}
|
||||
|
||||
/** What placing the piece object {@code objectKey} records beside its blocks; null without a structure or object. */
|
||||
static PlacementRecord pieceRecord(PackResources pack, String structureKey, AssembledPiece piece, String objectKey) {
|
||||
if (structureKey == null || structureKey.isBlank() || objectKey == null || objectKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
PackResources pack = world.resources();
|
||||
int placementId = structurePlacementId(structureKey, objectKey, piece.x(), piece.y(), piece.z());
|
||||
return PlacementRecord.ofPiece(pack.idOf(objectKey), placementId, pack.idOf(structureKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the placement samples the height of its pieces from the terrain when it places them, rather than placing
|
||||
* them at their planned height: a lone surface piece without free height.
|
||||
*/
|
||||
static boolean samplesPieceHeight(StructurePlacement placement, StructureStamp stamp, List<AssembledPiece> pieces) {
|
||||
return !placement.isAnchoredUnderground()
|
||||
&& !stamp.placeMode().placeMode().has(PlaceTrait.FREE_HEIGHT)
|
||||
&& pieces.size() == 1;
|
||||
}
|
||||
|
||||
/** How far, in blocks along X and Z, placements may write beyond their chunk. */
|
||||
public static int reach(PackSettings settings) {
|
||||
PackResources pack = settings.resources();
|
||||
|
||||
Reference in new issue
Block a user