diff --git a/README.md b/README.md index d6adb7459..8f1513f25 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,16 @@ service or hook, `setup.log()` during setup), which labels each line with the mo use `IrisLogging`. Classes of the host's object model (the host-classes list) and code that only has an engine or pack data still log as Iris itself. -Modules also own pack resources and checks of their own. Iris's own module `iris:structure-model` (core -`StructureModelModule`) reads structures, jigsaw pools and jigsaw pieces as resource kinds (`StructureResources`, -`iris:structure-model/structure`, `/pool`, `/piece`), from the folders and files packs have always used, and checks -them with its validator (`StructureValidator`: assembly samples and vanilla structure replacement) wherever Iris -validates a pack. The structure model, assembler, locator, fitting and placing are host: the jigsaw studio, the -structure importers and exporters read them too. `iris:structure` in the built-ins jar declares the structure -placement settings and the mantle stage, and places through the `StructureHost` facade -(`art.arcane.iris.builtin.structure`). +Modules also own pack resources and checks of their own. `iris:structure` (`StructureModule`) reads structures, jigsaw +pools and jigsaw pieces as resource kinds (`StructureResources`, `iris:structure/structure`, `/pool`, `/piece`), from the +folders and files packs have always used, and declares the structure placement settings and the mantle stage. Its +definitions (`IrisStructure`, `IrisJigsawPiece`, `IrisJigsawPool` and their parts in `engine/object/structure`) live +here and build against the API. It is not in the built-ins jar: Iris registers it with its own modules, because Iris's +jigsaw studio, importers and exporters read the structures it registers as the same classes, which a jar's own copy of +a class is not. Iris's own module `iris:structure-model` (core `StructureModelModule`) checks them with its validator +(`StructureValidator`: assembly samples and vanilla structure replacement) wherever Iris validates a pack. The +assembler, locator, fitting and placing are still Iris's, and `iris:structure` places through the `StructureHost` +facade (`art.arcane.iris.builtin.structure`). Built-in modules answer Iris through IrisApi services instead of Iris reading their features: `iris:objects` provides `ObjectsAt` (the objects a chunk would get, for the object search and studio tools) and `iris:structure-model` @@ -163,8 +165,10 @@ compiled these sources itself. Iris includes this build (`includeBuild('../IrisModule')` in its `settings.gradle`) and depends on its classes: Iris core and its adapters still name many of them (the cut-over that ends this comes later). Classes that need Iris itself are Iris's and live in Iris core: the layout model (`IrisBiome`, `IrisRegion`, `IrisDimension`, generators, noise -styles, expressions, images), the pack's objects and blocks, the structure model with its assembler, locator, fitting -and placer (behind `StructureHost`), and the object placers behind `ObjectHost` and `FloatingHost`. +styles, expressions, images), the pack's objects and blocks, the structure assembler, locator, fitting and placer +(behind `StructureHost`), and the object placers behind `ObjectHost` and `FloatingHost`. A module this build holds +but the jar does not, such as `iris:structure`, is one Iris registers with its own modules (`IrisModuleHost`): its +classes are then the ones Iris's own code sees. `./gradlew check` compiles every source and builds the built-ins jar below, which runs the pack class checks. diff --git a/builtin-modules.txt b/builtin-modules.txt index 6e22b08b6..76a7b50f2 100644 --- a/builtin-modules.txt +++ b/builtin-modules.txt @@ -94,4 +94,5 @@ include art/arcane/iris/engine/mantle/components/FloatingObjectPlacing*.class include art/arcane/iris/engine/mantle/components/FloatingIslandSampleResolver*.class include art/arcane/iris/engine/mantle/components/IslandFace*.class include art/arcane/iris/engine/mantle/components/UndersideTurn*.class -module art.arcane.iris.engine.mantle.components.StructureModule +# iris:structure (art.arcane.iris.engine.mantle.components.StructureModule) is not here: Iris registers it with its own +# modules, because its jigsaw studio reads the structure resources the module registers. diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/StructureResources.java b/src/main/java/art/arcane/iris/engine/framework/structure/StructureResources.java new file mode 100644 index 000000000..219c84836 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/framework/structure/StructureResources.java @@ -0,0 +1,92 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.framework.structure; + +import art.arcane.iris.engine.object.structure.IrisStructure; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool; +import com.volmit.resource.PackResources; +import com.volmit.resource.ResourceId; +import com.volmit.resource.ResourceKind; + +import java.util.List; + +/** + * The resource kinds of {@code iris:structure}, which keep the folders and files Iris packs have always used, and + * lookups by pack key for code that names structures, pools and pieces by key. Every lookup goes through the pack's + * {@link PackResources}, so it sees the pack's current snapshot: a hotload, or a tool that rewrote the files and asked + * for a new snapshot, reads them again. + *

+ * Lookups answer null for a blank key, a key the pack has no file for, and a file that fails to load, which was + * reported when it was read. + */ +public final class StructureResources { + /** Jigsaw structures, in {@code structures/}. */ + public static final ResourceKind STRUCTURES = ResourceKind.of("iris:structure/structure", "structures", IrisStructure.class); + /** Jigsaw pools a structure starts from and connectors lead to, in {@code jigsaw-pools/}. */ + public static final ResourceKind POOLS = ResourceKind.of("iris:structure/pool", "jigsaw-pools", IrisJigsawPool.class); + /** Jigsaw pieces pools hold, each an object with connectors, in {@code jigsaw-pieces/}. */ + public static final ResourceKind PIECES = ResourceKind.of("iris:structure/piece", "jigsaw-pieces", IrisJigsawPiece.class); + + private StructureResources() { + } + + /** Every resource kind of the structure model. */ + public static List> kinds() { + return List.of(STRUCTURES, POOLS, PIECES); + } + + public static IrisStructure structure(PackResources pack, String key) { + return find(pack, STRUCTURES, key); + } + + public static IrisJigsawPool pool(PackResources pack, String key) { + return find(pack, POOLS, key); + } + + public static IrisJigsawPiece piece(PackResources pack, String key) { + return find(pack, PIECES, key); + } + + /** The key of every structure of the pack snapshot {@code pack}, in key order. */ + public static List structureKeys(PackResources pack) { + return keys(pack, STRUCTURES); + } + + /** The key of every jigsaw piece of the pack snapshot {@code pack}, in key order. */ + public static List pieceKeys(PackResources pack) { + return keys(pack, PIECES); + } + + private static T find(PackResources pack, ResourceKind kind, String key) { + if (key == null || key.isBlank()) { + return null; + } + try { + return pack.find(kind, pack.idOf(key)).orElse(null); + } catch (IllegalStateException failedToLoad) { + return null; + } + } + + /** A key's id has the key as its path, so the path names the resource again wherever a key is expected. */ + private static List keys(PackResources pack, ResourceKind kind) { + return pack.ids(kind).stream().map(ResourceId::path).toList(); + } +} diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/StructureModule.java b/src/main/java/art/arcane/iris/engine/mantle/components/StructureModule.java index ce5958210..55c1fcc37 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/StructureModule.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/StructureModule.java @@ -22,6 +22,7 @@ import art.arcane.iris.builtin.IrisStages; import art.arcane.iris.builtin.structure.StructureHost; import art.arcane.iris.builtin.structure.StructurePlacementSettings; import art.arcane.iris.builtin.structure.StructureSettings; +import art.arcane.iris.engine.framework.structure.StructureResources; import com.volmit.IrisModule; import com.volmit.ModuleInfo; import com.volmit.ModuleSetup; @@ -29,10 +30,13 @@ import com.volmit.config.PackSettings; import com.volmit.stage.MantleStageContext; /** - * Module {@code iris:structure}: the structure placements a pack declares, and the mantle stage that places the jigsaw - * structures starting in each chunk. Iris builds and places the structures ({@link StructureHost}); the structure - * resources, their validation, the locator and the platform structure answers are Iris's own module - * {@code iris:structure-model}. + * Module {@code iris:structure}: the jigsaw structures, pools and pieces of a pack (its resource kinds), the structure + * placements a pack declares, and the mantle stage that places the structures starting in each chunk. Iris builds and + * places the structures ({@link StructureHost}); their validation, the locator and the platform structure answers are + * Iris's own module {@code iris:structure-model}. + *

+ * It is not in the built-ins jar: Iris registers it with its own modules, because Iris's jigsaw studio, importers and + * exporters read the resources it registers as the same classes. */ public final class StructureModule implements IrisModule { private static final String VERSION = "built-in"; @@ -47,6 +51,7 @@ public final class StructureModule implements IrisModule { setup.stages().define(IrisStages.Structure.PLACE).softAfter(IrisStages.Objects.PLACE, IrisStages.Floating.OBJECTS) .reach(StructureModule::reach).run(StructureModule::place); var registry = setup.registry(); + StructureResources.kinds().forEach(registry::registerResourceKind); registry.registerSettings(StructureSettings.class, StructurePlacementSettings.class); } diff --git a/src/main/java/art/arcane/iris/engine/object/KeyedResource.java b/src/main/java/art/arcane/iris/engine/object/KeyedResource.java new file mode 100644 index 000000000..b42699e90 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/KeyedResource.java @@ -0,0 +1,41 @@ +/* + * Iris is a World Generator for Minecraft Bukkit 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 . + */ + +package art.arcane.iris.engine.object; + +/** + * A resource of Iris's pack object model read from one file of a pack. Iris sets its key, the file's path below the + * folder without {@code .json}, when it reads the file; the folder and type name are what studio and load reports show. + */ +public abstract class KeyedResource { + private transient String loadKey; + + public String getLoadKey() { + return loadKey; + } + + public void setLoadKey(String loadKey) { + this.loadKey = loadKey; + } + + /** The folder below the pack root that holds resources of this type. */ + public abstract String getFolderName(); + + /** The name studio and load reports give a resource of this type, such as {@code Structure}. */ + public abstract String getTypeName(); +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java new file mode 100644 index 000000000..a1e726548 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java @@ -0,0 +1,139 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2022 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 . + */ + +package art.arcane.iris.engine.object.structure; + +import art.arcane.iris.builtin.anchor.PlaceTrait; +import art.arcane.iris.builtin.anchor.ObjectPlaceMode; +import art.arcane.iris.builtin.blocks.ObjectReplace; +import art.arcane.iris.builtin.loot.LootTable; +import art.arcane.iris.engine.object.KeyedResource; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawBranchFailurePolicy; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawCompatibility; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawMode; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawThemeSet; +import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawWorkcell; +import art.arcane.iris.engine.object.value.IrisPosition; +import art.arcane.iris.engine.object.annotations.ArrayType; +import art.arcane.iris.engine.object.annotations.Desc; +import art.arcane.iris.engine.object.annotations.MaxNumber; +import art.arcane.iris.engine.object.annotations.MinNumber; +import art.arcane.iris.engine.object.annotations.RegistryListResource; +import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure; +import art.arcane.iris.engine.object.annotations.Required; +import art.arcane.volmlib.util.collection.KList; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Desc("A jigsaw structure. Starting from a pool, the assembler places a start piece and recursively attaches more pieces through matching connectors until it reaches the max depth or size. Pieces are Iris objects, so they carry the full object placement and block-control feature set.") +@Data +@EqualsAndHashCode(callSuper = false) +public class IrisStructure extends KeyedResource { + @Required + @RegistryListResource(IrisJigsawPool.class) + @Desc("The pool the assembler draws the start piece from.") + private String startPool = ""; + + @MinNumber(1) + @MaxNumber(30) + @Desc("The maximum jigsaw recursion depth. Larger values allow larger structures (e.g. villages) at the cost of generation time.") + private int maxDepth = 7; + + @MinNumber(1) + @MaxNumber(32) + @Desc("The maximum radius of the structure in chunks from its start piece. Acts as a hard bound on assembly size and collision checks.") + private int maxSizeChunks = 8; + + @Desc("Assembly topology. SPATIAL_JIGSAW preserves the existing freeform connector graph; PLANAR_JIGSAW declares a cell-aligned planar graph.") + private IrisJigsawMode mode = IrisJigsawMode.SPATIAL_JIGSAW; + + @Desc("Target compatibility contract for this structure. IRIS_EXTENDED permits Iris-only metadata; VANILLA_PORTABLE requires a graph that can be represented by vanilla jigsaw resources.") + private IrisJigsawCompatibility compatibility = IrisJigsawCompatibility.IRIS_EXTENDED; + + @Desc("How unresolved optional connector branches affect assembly. FAIL_ASSEMBLY preserves strict Iris behavior; TERMINATE_BRANCH matches vanilla jigsaw branch termination.") + private IrisJigsawBranchFailurePolicy branchFailurePolicy = IrisJigsawBranchFailurePolicy.FAIL_ASSEMBLY; + + @Desc("Default Studio cell dimensions. Legacy planar structures use this value for every workcell when planarWorkcells is empty.") + private IrisPosition cellSize = new IrisPosition(15, 15, 15); + + @Desc("Optional author-facing name for the single spatial Jigsaw Studio workcell. Spatial is shown when this is blank.") + private String spatialWorkcellDisplayName = ""; + + @ArrayType(type = IrisJigsawWorkcell.class) + @Desc("The six persistent planar Studio workcells. Leave empty only for the legacy cellSize fallback.") + private KList planarWorkcells = new KList<>(); + + @ArrayType(type = IrisJigsawThemeSet.class, min = 1) + @Desc("Weighted themes available to an assembly. Leave empty for one implicit unthemed assembly path.") + private KList themeSets = new KList<>(); + + @Desc("Whether every open connector must close with a real terminal piece through a mandatory direct fallback.") + private boolean requireCaps = false; + + @Desc("The place mode used when stamping each piece object into the world.") + private ObjectPlaceMode placeMode = ObjectPlaceMode.STRUCTURE_PIECE; + + @ArrayType(min = 1, type = ObjectReplace.class) + @Desc("Find-and-replace block edits applied to every piece of this structure, using the exact same syntax as an object's 'edit'. For example, replace stone bricks with obsidian.") + private KList edit = new KList<>(); + + @ArrayType(type = String.class, min = 1) + @RegistryListResource(LootTable.class) + @Desc("Loot tables applied to containers placed by this structure's pieces.") + private KList loot = new KList<>(); + + @RegistryListVanillaStructure + @Desc("If this structure was generated by importing a vanilla or datapack structure, this is that structure's key (provenance). Empty for hand-authored structures.") + private String vanillaSource = ""; + + /** Whether the structure's pieces are stamped where the assembler put them, as a vanilla jigsaw places them. */ + public boolean stampsPiecesWhereAssembled() { + return placeMode != null && placeMode.placeMode().has(PlaceTrait.RAW_STAMP); + } + + public IrisJigsawMode resolvedMode() { + return mode == null ? IrisJigsawMode.SPATIAL_JIGSAW : mode; + } + + public IrisJigsawCompatibility resolvedCompatibility() { + return compatibility == null ? IrisJigsawCompatibility.IRIS_EXTENDED : compatibility; + } + + public IrisJigsawBranchFailurePolicy resolvedBranchFailurePolicy() { + return branchFailurePolicy == null + ? IrisJigsawBranchFailurePolicy.FAIL_ASSEMBLY + : branchFailurePolicy; + } + + @Override + public String getFolderName() { + return "structures"; + } + + @Override + public String getTypeName() { + return "Structure"; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawConnector.java b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawConnector.java new file mode 100644 index 000000000..dc99b49cc --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawConnector.java @@ -0,0 +1,96 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2022 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 . + */ + +package art.arcane.iris.engine.object.structure.jigsaw; + +import art.arcane.iris.engine.object.value.IrisDirection; +import art.arcane.iris.engine.object.value.IrisPosition; +import art.arcane.iris.engine.object.annotations.Desc; +import art.arcane.iris.engine.object.annotations.RegistryListResource; +import art.arcane.iris.engine.object.annotations.Required; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.Objects; + +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Desc("A jigsaw connection point on a piece. When two connectors face each other and their names match, the assembler may join the pieces.") +@Data +public class IrisJigsawConnector { + public static IrisPosition canonicalPlanarPosition(IrisPosition cellSize, IrisDirection direction) { + IrisPosition dimensions = Objects.requireNonNull(cellSize, "Planar jigsaw cell size"); + IrisDirection face = Objects.requireNonNull(direction, "Planar jigsaw connector direction"); + if (dimensions.getX() < 1 || dimensions.getY() < 1 || dimensions.getZ() < 1) { + throw new IllegalArgumentException("Planar jigsaw cell dimensions must be positive"); + } + int centerX = dimensions.getX() / 2; + int centerY = dimensions.getY() / 2; + int centerZ = dimensions.getZ() / 2; + return switch (face) { + case NORTH_NEGATIVE_Z -> new IrisPosition(centerX, centerY, 0); + case EAST_POSITIVE_X -> new IrisPosition(dimensions.getX() - 1, centerY, centerZ); + case SOUTH_POSITIVE_Z -> new IrisPosition(centerX, centerY, dimensions.getZ() - 1); + case WEST_NEGATIVE_X -> new IrisPosition(0, centerY, centerZ); + case UP_POSITIVE_Y, DOWN_NEGATIVE_Y -> throw new IllegalArgumentException( + "Planar jigsaw connector direction must be horizontal"); + }; + } + + @Required + @Desc("The position of this connector relative to the piece object's origin (0,0,0 is the lowest-corner of the object).") + private IrisPosition position = new IrisPosition(); + + @Required + @Desc("The direction this connector faces. The connecting piece is placed on this side.") + private IrisDirection direction = IrisDirection.NORTH_NEGATIVE_Z; + + @Required + @Desc("The connector's authored top direction, used to preserve aligned vanilla jigsaw orientation.") + private IrisDirection top = IrisDirection.UP_POSITIVE_Y; + + @Required + @RegistryListResource(IrisJigsawPool.class) + @Desc("The jigsaw pool to draw the connecting piece from.") + private String pool = ""; + + @Desc("The identity exposed by this connector. Another connector can attach when its targetName equals this name, matching Minecraft's jigsaw target-to-name contract.") + private String name = ""; + + @Desc("The name this connector wants to connect to on the other piece.") + private String targetName = ""; + + @Desc("Optional Iris-only connection channel. Matching is exact, case-sensitive, and whitespace-sensitive; empty channels match only other empty channels.") + private String channel = ""; + + @Desc("How the connecting piece may be rotated relative to this connector.") + private JigsawJoint joint = JigsawJoint.ROLLABLE; + + @Required + @Desc("Block state placed where this jigsaw marker was authored after assembly. Used when exporting or capturing Mojang-style jigsaw templates.") + private String finalState = "minecraft:air"; + + @Desc("Signed priority for selecting this connector within its piece. Higher values are processed before lower values; equal priorities preserve authored order.") + private int selectionPriority = 0; + + @Desc("Signed priority assigned to a child piece attached through this connector. Higher-priority child pieces expand first; equal priorities preserve attachment order.") + private int placementPriority = 0; +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPiece.java b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPiece.java new file mode 100644 index 000000000..b123f3a0f --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPiece.java @@ -0,0 +1,94 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2022 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 . + */ + +package art.arcane.iris.engine.object.structure.jigsaw; + +import art.arcane.iris.engine.object.KeyedResource; +import com.volmit.object.GeneratedObject; +import art.arcane.iris.engine.object.annotations.ArrayType; +import art.arcane.iris.engine.object.annotations.Desc; +import art.arcane.iris.engine.object.annotations.RegistryListResource; +import art.arcane.iris.engine.object.annotations.Required; +import art.arcane.volmlib.util.collection.KList; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Desc("A jigsaw piece. A piece is a single Iris object plus the connection points (connectors) that let the assembler attach other pieces to it.") +@Data +@EqualsAndHashCode(callSuper = false) +public class IrisJigsawPiece extends KeyedResource { + @Desc("Optional author-facing name shown by Jigsaw Studio. The resource key is shown when this is blank.") + private String displayName = ""; + + @Required + @RegistryListResource(GeneratedObject.class) + @Desc("The object (schematic) that makes up this piece.") + private String object = ""; + + @ArrayType(type = IrisJigsawConnector.class, min = 1) + @Desc("The jigsaw connection points on this piece.") + private KList connectors = new KList<>(); + + @Desc("If true, this piece may be rotated around the Y axis when placed so the assembler can match its connectors. Disable for pieces that must keep a fixed orientation.") + private boolean rotatable = true; + + @Desc("If true, this piece's object bounds block overlapping jigsaw pieces. Disable for connector-only scaffolds whose stored volume is intentionally shared with physical pieces.") + private boolean collidable = true; + + @ArrayType(type = String.class, min = 1) + @Desc("Theme keys that may select this piece. An empty list makes the piece available to every selected theme.") + private KList themes = new KList<>(); + + @Desc("Deterministic depth, placement-count, and terminal-role rules for this piece.") + private IrisJigsawPieceRules rules = new IrisJigsawPieceRules(); + + public boolean supportsTheme(String selectedTheme) { + if (themes == null || themes.isEmpty()) { + return true; + } + if (selectedTheme == null || selectedTheme.isBlank()) { + return false; + } + for (String theme : themes) { + if (selectedTheme.equals(theme)) { + return true; + } + } + return false; + } + + public IrisJigsawPieceRules resolvedRules() { + return rules == null ? new IrisJigsawPieceRules() : rules; + } + + @Override + public String getFolderName() { + return "jigsaw-pieces"; + } + + @Override + public String getTypeName() { + return "Jigsaw Piece"; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPieceEntry.java b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPieceEntry.java new file mode 100644 index 000000000..c022d4de8 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPieceEntry.java @@ -0,0 +1,66 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2022 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 . + */ + +package art.arcane.iris.engine.object.structure.jigsaw; + +import art.arcane.iris.engine.object.annotations.Desc; +import art.arcane.iris.engine.object.annotations.MaxNumber; +import art.arcane.iris.engine.object.annotations.MinNumber; +import art.arcane.iris.engine.object.annotations.RegistryListResource; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Desc("A weighted reference to a jigsaw piece inside a jigsaw pool.") +@Data +public class IrisJigsawPieceEntry { + @RegistryListResource(IrisJigsawPiece.class) + @Desc("The jigsaw piece this entry refers to. Omit when empty is true.") + private String piece; + + @MinNumber(1) + @Desc("The relative weight of this piece within its pool. Higher weights are chosen more often.") + private int weight = 1; + + @MinNumber(0) + @MaxNumber(1) + @Desc("The independent eligibility chance applied to this exact pool membership before weighted selection. Zero never passes and one always passes.") + private double chance = 1D; + + @Desc("When true, choosing this entry successfully terminates the current branch without placing a piece.") + private boolean empty = false; + + public IrisJigsawPieceEntry(String piece, int weight) { + this(piece, weight, 1D, false); + } + + public boolean requiresChanceRoll() { + return chance > 0D && chance < 1D; + } + + public boolean passesChance(double roll) { + if (!Double.isFinite(roll) || roll < 0D || roll >= 1D) { + throw new IllegalArgumentException("Jigsaw chance roll must be finite and within 0 inclusive and 1 exclusive"); + } + return chance >= 1D || chance > 0D && roll < chance; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPool.java b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPool.java new file mode 100644 index 000000000..bc66b71b2 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawPool.java @@ -0,0 +1,63 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2022 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 . + */ + +package art.arcane.iris.engine.object.structure.jigsaw; + +import art.arcane.iris.engine.object.KeyedResource; +import art.arcane.iris.engine.object.annotations.ArrayType; +import art.arcane.iris.engine.object.annotations.Desc; +import art.arcane.iris.engine.object.annotations.RegistryListResource; +import art.arcane.volmlib.util.collection.KList; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Desc("A jigsaw pool. A pool is a weighted set of pieces the assembler chooses from when a connector targets this pool.") +@Data +@EqualsAndHashCode(callSuper = false) +public class IrisJigsawPool extends KeyedResource { + @ArrayType(type = IrisJigsawPieceEntry.class, min = 1) + @Desc("The weighted pieces in this pool.") + private KList pieces = new KList<>(); + + @RegistryListResource(IrisJigsawPool.class) + @Desc("The direct fallback pool tried after this pool, or used alone at maximum depth. The fallback pool's own fallback is not part of the same selection. Leave empty to stop expanding at maximum depth.") + private String fallback = ""; + + @Desc("Whether failure to place from this pool must be resolved through its direct fallback even when the structure does not require every branch to be capped.") + private boolean mandatoryFallback = false; + + public boolean requiresFallback(boolean structureRequiresCaps) { + return structureRequiresCaps || mandatoryFallback; + } + + @Override + public String getFolderName() { + return "jigsaw-pools"; + } + + @Override + public String getTypeName() { + return "Jigsaw Pool"; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawWorkcell.java b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawWorkcell.java new file mode 100644 index 000000000..e998e142e --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawWorkcell.java @@ -0,0 +1,40 @@ +package art.arcane.iris.engine.object.structure.jigsaw; + +import art.arcane.iris.engine.object.annotations.Desc; +import art.arcane.iris.engine.object.annotations.MaxNumber; +import art.arcane.iris.engine.object.annotations.MinNumber; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Data +@Desc("Persistent authoring bounds and runtime availability for one planar jigsaw workcell.") +public class IrisJigsawWorkcell { + @Desc("Optional author-facing name shown by Jigsaw Studio. The canonical archetype name is shown when this is blank.") + private String displayName = ""; + + @Desc("The orientation-independent planar connector shape configured by this workcell.") + private IrisJigsawWorkcellArchetype archetype = IrisJigsawWorkcellArchetype.BLANK; + + @MinNumber(3) + @MaxNumber(128) + @Desc("The maximum canonical variant width that this workcell can contain, in blocks.") + private int width = 16; + + @MinNumber(1) + @MaxNumber(192) + @Desc("The maximum variant height that this workcell can contain, in blocks.") + private int height = 16; + + @MinNumber(3) + @MaxNumber(128) + @Desc("The maximum canonical variant depth that this workcell can contain, in blocks.") + private int depth = 16; + + @Desc("Whether pieces with this planar connector shape participate in assembly and vanilla export.") + private boolean enabled = true; +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawWorkcellArchetype.java b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawWorkcellArchetype.java new file mode 100644 index 000000000..4275be726 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/structure/jigsaw/IrisJigsawWorkcellArchetype.java @@ -0,0 +1,88 @@ +package art.arcane.iris.engine.object.structure.jigsaw; + +import art.arcane.iris.engine.object.annotations.Desc; + +@Desc("The orientation-independent connector shape represented by a planar jigsaw workcell.") +public enum IrisJigsawWorkcellArchetype { + @Desc("Pieces with no horizontal connectors: sealed filler cells that terminate nothing and are excluded from the default piece pool.") + BLANK(0), + + @Desc("One-connector dead-end pieces; the Studio bay seeds a single north connector and new projects mark these as terminal caps.") + END(1), + + @Desc("Two-connector pass-through pieces with openings on opposite sides; the Studio bay seeds north and south connectors.") + STRAIGHT(5), + + @Desc("Two-connector right-angle pieces with openings on adjacent sides; the Studio bay seeds north and east connectors.") + CORNER(3), + + @Desc("Three-connector junction pieces; the Studio bay seeds north, east, and west connectors.") + TEE(11), + + @Desc("Four-connector pieces open on all sides; new projects use this archetype as the structure's start piece.") + CROSS(15); + + private final int canonicalMask; + + IrisJigsawWorkcellArchetype(int canonicalMask) { + this.canonicalMask = canonicalMask; + } + + public static IrisJigsawWorkcellArchetype fromPiece(IrisJigsawPiece piece) { + if (piece == null || piece.getConnectors() == null) { + return BLANK; + } + return fromMask(horizontalMask(piece)); + } + + public static IrisJigsawWorkcellArchetype fromMask(int mask) { + if (mask < 0 || mask > 15) { + throw new IllegalArgumentException("Planar jigsaw topology mask must be between 0 and 15"); + } + int connections = Integer.bitCount(mask); + return switch (connections) { + case 0 -> BLANK; + case 1 -> END; + case 2 -> mask == 5 || mask == 10 ? STRAIGHT : CORNER; + case 3 -> TEE; + case 4 -> CROSS; + default -> throw new IllegalStateException("Unreachable planar jigsaw topology"); + }; + } + + public static int horizontalMask(IrisJigsawPiece piece) { + if (piece == null || piece.getConnectors() == null) { + return 0; + } + int mask = 0; + for (IrisJigsawConnector connector : piece.getConnectors()) { + if (connector == null || connector.getDirection() == null) { + continue; + } + mask |= switch (connector.getDirection()) { + case NORTH_NEGATIVE_Z -> 1; + case EAST_POSITIVE_X -> 2; + case SOUTH_POSITIVE_Z -> 4; + case WEST_NEGATIVE_X -> 8; + case UP_POSITIVE_Y, DOWN_NEGATIVE_Y -> 0; + }; + } + return mask; + } + + public int sourceToCanonicalQuarterTurns(IrisJigsawPiece piece) { + int sourceMask = horizontalMask(piece); + if (fromMask(sourceMask) != this) { + throw new IllegalArgumentException("Jigsaw piece does not match workcell archetype " + name()); + } + for (int quarterTurns = 0; quarterTurns < 4; quarterTurns++) { + int rotated = quarterTurns == 0 + ? sourceMask + : ((sourceMask << quarterTurns) | (sourceMask >>> (4 - quarterTurns))) & 15; + if (rotated == canonicalMask) { + return quarterTurns; + } + } + throw new IllegalStateException("No canonical rotation exists for planar jigsaw piece"); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/value/IrisDirection.java b/src/main/java/art/arcane/iris/engine/object/value/IrisDirection.java new file mode 100644 index 000000000..07cd1b927 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/value/IrisDirection.java @@ -0,0 +1,87 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2022 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 . + */ + +package art.arcane.iris.engine.object.value; + +import art.arcane.iris.engine.object.annotations.Desc; + +/** One of the six axis directions, named by its axis and sign as packs write it. */ +@Desc("A direction object") +public enum IrisDirection { + @Desc("0, 1, 0") + UP_POSITIVE_Y(0, 1, 0), + @Desc("0, -1, 0") + DOWN_NEGATIVE_Y(0, -1, 0), + @Desc("0, 0, -1") + NORTH_NEGATIVE_Z(0, 0, -1), + @Desc("0, 0, 1") + SOUTH_POSITIVE_Z(0, 0, 1), + @Desc("1, 0, 0") + EAST_POSITIVE_X(1, 0, 0), + @Desc("-1, 0, 0") + WEST_NEGATIVE_X(-1, 0, 0); + + private final int x; + private final int y; + private final int z; + + IrisDirection(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public String toString() { + return switch (this) { + case DOWN_NEGATIVE_Y -> "Down"; + case EAST_POSITIVE_X -> "East"; + case NORTH_NEGATIVE_Z -> "North"; + case SOUTH_POSITIVE_Z -> "South"; + case UP_POSITIVE_Y -> "Up"; + case WEST_NEGATIVE_X -> "West"; + }; + } + + public boolean isVertical() { + return this == DOWN_NEGATIVE_Y || this == UP_POSITIVE_Y; + } + + public IrisDirection reverse() { + return switch (this) { + case DOWN_NEGATIVE_Y -> UP_POSITIVE_Y; + case EAST_POSITIVE_X -> WEST_NEGATIVE_X; + case NORTH_NEGATIVE_Z -> SOUTH_POSITIVE_Z; + case SOUTH_POSITIVE_Z -> NORTH_NEGATIVE_Z; + case UP_POSITIVE_Y -> DOWN_NEGATIVE_Y; + case WEST_NEGATIVE_X -> EAST_POSITIVE_X; + }; + } + + public int x() { + return x; + } + + public int y() { + return y; + } + + public int z() { + return z; + } +}