Register structure list, info and verify through the tooling api

StructureModelModule mounts /iris structure list|info|verify as a module Command:
list writes the structure index through ToolPack.edit, info takes the structure as a
pack resource, and verify reads the world the sender stands in and reports in plain
text. The tests run list, info and verify through the dispatcher and pin that no other
module can take the structure root name or its aliases.
This commit is contained in:
piexel committed 2026-11-06 10:51:12 +01:00
1 parent bcec8e474d
commit a5d0229417
6 files changed
+535

No files matched your search

@@ -0,0 +1,95 @@
/*
* 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.core.modules;
import art.arcane.iris.core.structure.StructureIndexService;
import art.arcane.iris.core.tooling.IrisToolPack;
import art.arcane.iris.engine.framework.PlacedStructurePiece;
import art.arcane.iris.engine.framework.structure.StructureAssemblyResult;
import art.arcane.iris.engine.framework.structure.StructureResources;
import art.arcane.iris.engine.object.structure.IrisStructure;
import art.arcane.iris.engine.object.value.IrisPosition;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.resource.ResourceId;
import com.volmit.tooling.Argument;
import com.volmit.tooling.Command;
import com.volmit.tooling.CommandContext;
import java.io.File;
import java.io.IOException;
import java.util.List;
/** The {@code /iris structure} commands of {@link StructureModelModule}: the index, one structure's graph, and the verification of a world's structures. */
final class StructureCommands {
private static final String ROOT_NAME = "structure";
private static final long INFO_SAMPLE_SEED = 1234L;
private static final int INFO_ORIGIN_Y = 64;
private static final Argument<ResourceId> STRUCTURE = Argument.resource("structure", StructureResources.STRUCTURES)
.describe("The Iris structure to inspect");
private StructureCommands() {
}
static Command root() {
return Command.named(ROOT_NAME).alias("struct", "str")
.describe("Iris structure tools")
.child(Command.named("list").alias("ls")
.describe("Write the index of every vanilla, datapack and Iris structure of the pack")
.runs(StructureCommands::list))
.child(Command.named("info")
.describe("Resolve an Iris structure's jigsaw graph and report its piece count and footprint")
.argument(STRUCTURE)
.runs(StructureCommands::info))
.child(Command.named("verify").alias("locateall")
.describe("Verify native structure eligibility and locate Iris-placed structures in the world you stand in")
.argument(StructureVerification.RADIUS)
.runs(StructureVerification::run));
}
private static void list(CommandContext context) throws IOException {
File index = context.pack().edit(packRoot -> StructureIndexService.write(IrisToolPack.dataOf(context.pack())));
context.sender().success("Wrote the structure index: " + index.getPath());
}
private static void info(CommandContext context) {
ResourceId id = context.get(STRUCTURE);
IrisStructure structure = context.pack().resources().require(StructureResources.STRUCTURES, id);
StructureAssemblyResult assembly = StructureAssemblies
.forData(IrisToolPack.dataOf(context.pack()), structure, new IrisPosition(0, INFO_ORIGIN_Y, 0))
.assemble(new RNG(INFO_SAMPLE_SEED));
if (!assembly.hasOutput()) {
context.sender().error("Structure " + id + " assembled 0 pieces (check startPool '" + structure.getStartPool() + "')");
return;
}
List<PlacedStructurePiece> pieces = assembly.pieces();
int minX = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
for (PlacedStructurePiece piece : pieces) {
minX = Math.min(minX, piece.getMinX());
minZ = Math.min(minZ, piece.getMinZ());
maxX = Math.max(maxX, piece.getMaxX());
maxZ = Math.max(maxZ, piece.getMaxZ());
}
context.sender().success("Structure " + id + ": " + pieces.size() + " pieces, footprint " + (maxX - minX + 1) + "x"
+ (maxZ - minZ + 1) + " blocks (sample seed " + INFO_SAMPLE_SEED + ")");
}
}
@@ -40,6 +40,8 @@ import com.volmit.service.VanillaStructures;
* ({@link StructureVanillaStructures}): the dimension's {@code importedStructures} settings disable, move, fit and set
* them up, and the pack's structure placements replace them, place them alongside, start them where their
* {@code nativeStructures} grids say and fit them into the terrain.
* <p>
* It mounts {@code /iris structure list|info|verify} ({@link StructureCommands}) through the tooling api.
*/
public final class StructureModelModule implements IrisModule {
private static final String VERSION = "built-in";
@@ -55,5 +57,6 @@ public final class StructureModelModule implements IrisModule {
registry.registerValidator(new StructureValidator());
registry.registerService(StructureLocator.class, new StructureLocating());
registry.registerService(VanillaStructures.class, new StructureVanillaStructures());
setup.tooling().registerCommand(StructureCommands.root());
}
}
@@ -0,0 +1,163 @@
/*
* 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.core.modules;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
import art.arcane.iris.engine.framework.NativeStructureGenerationStatus;
import art.arcane.iris.engine.framework.StructureReachability;
import com.volmit.config.Reference;
import com.volmit.tooling.Argument;
import com.volmit.tooling.CommandContext;
import com.volmit.tooling.Sender;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
/**
* {@code /iris structure verify}: for every structure the platform registers and every structure the pack's modules place,
* whether it can generate in the world the sender stands in, searching around the world origin for those the pack places.
* Native eligibility is decided without the platform's blocking locate.
*/
final class StructureVerification {
private static final long DEFAULT_RADIUS_CHUNKS = 48L;
private static final long MAX_RADIUS_CHUNKS = 1000L;
private static final int ORIGIN_BLOCK = 0;
static final Argument<Long> RADIUS = Argument.integer("radius", 1, MAX_RADIUS_CHUNKS)
.orElse(DEFAULT_RADIUS_CHUNKS)
.describe("Search radius in chunks around the world origin (larger is much slower)");
private final Engine engine;
private final CommandContext context;
private final int radiusChunks;
private final List<String> lines = new ArrayList<>();
private int located;
private int nativeEligible;
private int disabled;
private int unreachable;
private int searchLimited;
private int errors;
private StructureVerification(Engine engine, CommandContext context, int radiusChunks) {
this.engine = engine;
this.context = context;
this.radiusChunks = radiusChunks;
}
static void run(CommandContext context) {
Sender sender = context.sender();
Engine engine = context.world().flatMap(world -> world.extension(Engine.class)).orElse(null);
if (engine == null) {
sender.error("Stand in a world generated with this pack: verify reads the running world");
return;
}
int radiusChunks = Math.toIntExact(context.get(RADIUS));
sender.info("Verifying structures within " + radiusChunks + " chunks of the world origin...");
new StructureVerification(engine, context, radiusChunks).report();
}
private void report() {
List<String> structureKeys = structureKeys();
if (!verifyAll(structureKeys)) {
return;
}
lines.add("Structure verify: " + located + " Iris placement plans found, " + nativeEligible + " native structures eligible, "
+ disabled + " disabled by policy, " + unreachable + " biome-unreachable, " + searchLimited
+ " density searches safety-limited, " + errors + " errors. Native eligibility is checked without running blocking live locates.");
lines.forEach(context.sender()::info);
}
private List<String> structureKeys() {
Set<String> keys = new TreeSet<>();
context.platform().ifPresent(registries -> registries.ids(Reference.STRUCTURE).forEach(id -> keys.add(id.toString())));
List<String> ordered = new ArrayList<>(keys);
for (String placed : ModuleServices.placedStructures(engine)) {
if (!keys.contains(placed)) {
ordered.add(placed);
}
}
return ordered;
}
private boolean verifyAll(List<String> structureKeys) {
Set<String> reachable;
try {
reachable = reachableNativeKeys(structureKeys);
} catch (RuntimeException failure) {
context.pack().log().error("Could not resolve native biome reachability for verification", failure);
context.sender().error("Structure verification could not resolve native biome reachability.");
return false;
}
for (String key : structureKeys) {
verify(key, reachable);
}
return true;
}
private Set<String> reachableNativeKeys(List<String> structureKeys) {
boolean needsReachability = structureKeys.stream().anyMatch(key -> !ModuleServices.placesStructure(engine, key)
&& NativeStructureGenerationPolicy.resolve(engine, key) == NativeStructureGenerationStatus.GENERATE_NATIVE);
return needsReachability ? StructureReachability.reachableKeys(engine) : Set.of();
}
private void verify(String key, Set<String> reachable) {
if (ModuleServices.placesStructure(engine, key)) {
locatePlaced(key);
return;
}
if (NativeStructureGenerationPolicy.resolve(engine, key) != NativeStructureGenerationStatus.GENERATE_NATIVE) {
disabled++;
lines.add("[disabled] " + key);
return;
}
if (!reachable.contains(key.toLowerCase(Locale.ROOT))) {
unreachable++;
List<String> missing = StructureReachability.missingBiomeKeys(engine, key);
lines.add("[unreachable] " + key + (missing.isEmpty() ? "" : " needs " + String.join("/", missing)));
return;
}
nativeEligible++;
lines.add("[native-eligible] " + key);
}
private void locatePlaced(String key) {
try {
ModuleServices.StructureSearch result = ModuleServices.locateStructure(engine, key, ORIGIN_BLOCK, ORIGIN_BLOCK, radiusChunks);
if (result.outcome() == ModuleServices.StructureSearch.Outcome.SEARCH_LIMIT_REACHED) {
searchLimited++;
lines.add("[iris-search-limit] " + key + ": unable to complete the density search before its safety limit was reached");
return;
}
if (!result.found()) {
lines.add("[iris-not-found] " + key);
return;
}
located++;
lines.add("[iris-planned] " + key + " @ " + result.x() + "," + result.y() + "," + result.z());
} catch (RuntimeException failure) {
errors++;
lines.add("[error] " + key + ": " + failure.getClass().getSimpleName());
context.pack().log().error("Could not verify Iris-placed structure '" + key + "'", failure);
}
}
}