diff --git a/README.md b/README.md index 49c385c3d..26288a72b 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,19 @@ replacement) wherever Iris validates a pack; Iris core has no loader or validato 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` provides `StructureLocator` (`StructureLocating`: the pack's structure keys for Iris's structure index, the ones a -world places, and their nearest start for the find commands). `iris:structure` also has a lifecycle hook that drops a -world's structure index when the world stops, which includes every reload of the pack's structure files. +world places, and their nearest start for the find commands). A world's structure index lives in the world's state +(`engine.getGeneration().state(...)`), so every reload of the pack's structure files, which starts a new world, builds +it again. `iris:structure` also provides `VanillaStructures` (`StructureVanillaStructures`) for the platform's own structures: which ones its placements replace or the dimension's `importedStructures` disables, the starts its `nativeStructures` -placements make, the shift and band of the platform's starts, and the whole terrain fit of every start (SOURCE, +placements make (`startedStructures`, `locatableStarts`, `locateStart`), the shift and band of the platform's starts, and the whole terrain fit of every start (SOURCE, PRESERVE, VACUUM, ENCASE, BORE, FORCE_CARVE, stilts) in `engine/framework/structure/fit`, written against IrisApi's `StructureFit` and `BlockAccess` only. A start carries its fit as a memo (its terrain and stilts JSON), so every -chunk it reaches and every restart fits it the same way. Object place modes are data (`PlaceMode`: height sampling, +chunk it reaches and every restart fits it the same way. `iris:vanilla-features` (`VanillaFeaturesModule`, no stages) +reads the dimension's `importedFeatures` (`ImportedFeaturesSettings`) and provides `VanillaFeatures` (`ImportedFeatures`): +whether the platform's own placed features run over the terrain and which decoration steps and features they leave out; +the family patterns of `disabled` and of `importedStructures` share one rule (`art.arcane.iris.builtin.RegistryKeyFamily`). +Object place modes are data (`PlaceMode`: height sampling, stilt, `VacuumProfile`, `PlaceTrait`s) that the placement stages ask; the pack JSON keeps the mode names. `iris:objects` also provides `SaplingGrowth` (`TreeGrowing`: the tree a sapling grows into, as placed blocks, and which objects are trees) and says which biomes and regions place an object (`ObjectLocating`, for the object search). @@ -105,7 +110,8 @@ dimension reaches learn of them without reading the settings classes; and `iris: (`CaveBiomeBands`), which Iris asks for the dimension's carving band at a position and for a biome's minimum cave depth. Packs write each settings feature under the short key it declares: `deposits` (dimension, region, biome; a list), `decorators` -(biome; a list) and `importedStructures` (dimension; an object of `disabled`, `adjustments` and the rest). The feature ids +(biome; a list), `importedStructures` (dimension; an object of `disabled`, `adjustments` and the rest) and `structures` +(dimension, region, biome; a list of `StructurePlacement`s, `StructurePlacementSettings`). The feature ids (`iris:deposit`, `iris:decorant`, `iris:structure`) stay the modules' identity in the stage graph and logs. A key is unique per target across all modules and Iris's own fields, so a new built-in or pack module picks a key no field of the target uses. @@ -139,7 +145,7 @@ naming the class and what it uses. A VolmLib class that Iris's Bukkit jar strips `core/volmlib-left-out-of-bukkit-jar.txt`, which its shadowJar reads too) is on that classpath but missing on a server, so the check treats it as missing and fails the task naming it. `check` runs the task. -The jar holds `iris:post`, `iris:perfection`, `iris:matter`, `iris:loot` and `iris:spawn`, and the object placement stages +The jar holds `iris:post`, `iris:perfection`, `iris:matter`, `iris:loot`, `iris:spawn` and `iris:vanilla-features`, and the object placement stages `iris:prepare`, `iris:anchor`, `iris:validate`, `iris:bore`, `iris:blocks`, `iris:stilt`, `iris:vacuum` and `iris:snow`. They are written against IrisApi and `art.arcane.iris.builtin` alone: the chunk's `BlockState` hunk, the block registry's traits and `canPlaceOn`, the terrain sampler (heights around the chunk, slope, fluid height, where the upper dimension begins) and the diff --git a/builtin-modules.txt b/builtin-modules.txt index 08d542385..98dfa38a6 100644 --- a/builtin-modules.txt +++ b/builtin-modules.txt @@ -37,3 +37,5 @@ include art/arcane/iris/engine/object/placement/ObjectEdits*.class include art/arcane/iris/engine/object/placement/ResolvedReplace*.class include art/arcane/iris/engine/object/placement/IrisSurfaceSupport*.class include art/arcane/iris/engine/object/placement/IrisObjectVacuum.class +module art.arcane.iris.engine.framework.vanillafeatures.VanillaFeaturesModule +include art/arcane/iris/engine/framework/vanillafeatures/** diff --git a/source-patterns.txt b/source-patterns.txt index c42d04a72..78bd0fcb1 100644 --- a/source-patterns.txt +++ b/source-patterns.txt @@ -6,10 +6,10 @@ art/arcane/iris/engine/mantle/components/** art/arcane/iris/engine/object/** art/arcane/iris/engine/image/** art/arcane/iris/engine/framework/structure/** +art/arcane/iris/engine/framework/vanillafeatures/** art/arcane/iris/engine/framework/StructureAssembler.java art/arcane/iris/engine/framework/IrisStructureLocator.java art/arcane/iris/engine/framework/StructureCaveAnchorResolver.java -art/arcane/iris/engine/framework/StructureReachability.java art/arcane/iris/engine/framework/StructurePlacementScope.java art/arcane/iris/engine/framework/StructurePlacementGrid.java art/arcane/iris/engine/framework/StructurePlacementMarker.java diff --git a/src/main/java/art/arcane/iris/builtin/RegistryKeyFamily.java b/src/main/java/art/arcane/iris/builtin/RegistryKeyFamily.java new file mode 100644 index 000000000..eec55b733 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/RegistryKeyFamily.java @@ -0,0 +1,57 @@ +/* + * 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.builtin; + +import java.util.Locale; + +/** + * How the settings of Iris's built-ins name families of the platform's registry keys, such as structures and placed + * features: a pattern matches the keys equal to it and the keys it starts at a namespace, slash or underscore boundary, + * ignoring case and surrounding space. So {@code minecraft:village} matches {@code minecraft:village_plains}, + * {@code minecraft:ore} every vanilla ore, and {@code nova_structures:} a whole namespace. + */ +public final class RegistryKeyFamily { + private RegistryKeyFamily() { + } + + /** Whether the family pattern {@code pattern} matches the registry key {@code key}. */ + public static boolean matches(String pattern, String key) { + if (pattern == null || key == null) { + return false; + } + String normalizedPattern = normalize(pattern); + String normalizedKey = normalize(key); + if (normalizedPattern.isEmpty() || !normalizedKey.startsWith(normalizedPattern)) { + return false; + } + if (normalizedKey.length() == normalizedPattern.length()) { + return true; + } + char patternEnd = normalizedPattern.charAt(normalizedPattern.length() - 1); + if (patternEnd == ':' || patternEnd == '/' || patternEnd == '_') { + return true; + } + char boundary = normalizedKey.charAt(normalizedPattern.length()); + return boundary == '/' || boundary == '_'; + } + + private static String normalize(String key) { + return key.trim().toLowerCase(Locale.ROOT); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/structure/NativeStructureSource.java b/src/main/java/art/arcane/iris/builtin/structure/NativeStructureSource.java new file mode 100644 index 000000000..8cb515fdd --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/structure/NativeStructureSource.java @@ -0,0 +1,64 @@ +/* + * 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.builtin.structure; + +import com.volmit.config.Desc; +import com.volmit.config.MinNumber; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.Required; +import com.volmit.vanilla.JigsawOverrides; + +import java.util.Optional; + +/** + * One platform structure a structure placement starts itself, written as + * {@code {"structure": "minecraft:ancient_city", "weight": 2, "jigsaw": {...}}}. IrisApi types only. + */ +@Desc("A live vanilla, datapack, or modded structure generated by Minecraft at an Iris-controlled placement.") +public final class NativeStructureSource { + @Required + @Ref(Reference.STRUCTURE) + @Desc("Registered structure key. The source retains its native generator, pieces, templates, processors, entities, markers, and data.") + private String structure = ""; + + @MinNumber(1) + @Desc("Relative selection weight when a placement offers multiple native structure sources.") + private int weight = 1; + + @Desc("Optional jigsaw-only assembly overrides. Null preserves the complete registered structure definition.") + private JigsawOverrides jigsaw = null; + + public NativeStructureSource() { + } + + /** The registry key of the platform structure, as the pack wrote it. */ + public String structure() { + return structure; + } + + public int weight() { + return weight; + } + + /** The overrides of the platform's jigsaw assembly; empty to keep its own. */ + public Optional jigsaw() { + return Optional.ofNullable(jigsaw); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/decoration/NativeFeatureGenerationStatus.java b/src/main/java/art/arcane/iris/builtin/structure/NativeStructureSuppression.java similarity index 58% rename from src/main/java/art/arcane/iris/engine/object/decoration/NativeFeatureGenerationStatus.java rename to src/main/java/art/arcane/iris/builtin/structure/NativeStructureSuppression.java index 8c828b99d..8522a480e 100644 --- a/src/main/java/art/arcane/iris/engine/object/decoration/NativeFeatureGenerationStatus.java +++ b/src/main/java/art/arcane/iris/builtin/structure/NativeStructureSuppression.java @@ -16,13 +16,16 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.decoration; +package art.arcane.iris.builtin.structure; -public enum NativeFeatureGenerationStatus { - GENERATE_NATIVE, - FEATURES_DISABLED, - STEP_DISABLED, - DISABLED_BY_PACK, - CYCLE_DEGRADED, - INVALID_REGISTRY_KEY +import com.volmit.config.Desc; + +/** Whether a structure placement replaces the platform structure its structures stand in for. */ +@Desc("Controls whether an Iris structure placement suppresses its imported native source.") +public enum NativeStructureSuppression { + @Desc("Leaves native generation enabled alongside this Iris structure placement.") + NONE, + + @Desc("Suppresses the structure's vanillaSource when used by a validated dimension-level replacement placement.") + REPLACE_SOURCE } diff --git a/src/main/java/art/arcane/iris/builtin/structure/StructureAnchorMode.java b/src/main/java/art/arcane/iris/builtin/structure/StructureAnchorMode.java new file mode 100644 index 000000000..7fbeb7900 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/structure/StructureAnchorMode.java @@ -0,0 +1,54 @@ +/* + * 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.builtin.structure; + +import com.volmit.config.Desc; + +/** How a structure placement picks the height it anchors a structure at. The placement identity hashes the order. */ +@Desc("Selects the vertical environment used to anchor an Iris structure placement.") +public enum StructureAnchorMode { + @Desc("Preserve the historical underground boolean behavior.") + LEGACY, + + @Desc("Anchor to the terrain surface and use minHeight/maxHeight as a surface gate.") + SURFACE, + + @Desc("Choose a deterministic Y inside the minHeight/maxHeight band.") + HEIGHT_BAND, + + @Desc("Anchor in carved space with solid support below.") + CAVE_FLOOR, + + @Desc("Anchor in carved space with solid support above.") + CAVE_CEILING, + + @Desc("Anchor in carved space without nearby floor or ceiling support.") + CAVE_CENTER, + + @Desc("Anchor at any carved-space position.") + CAVE_ANY; + + /** Whether the anchor looks for carved space. */ + public boolean isCave() { + return switch (this) { + case CAVE_FLOOR, CAVE_CEILING, CAVE_CENTER, CAVE_ANY -> true; + default -> false; + }; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/StructureDistribution.java b/src/main/java/art/arcane/iris/builtin/structure/StructureDistribution.java similarity index 81% rename from src/main/java/art/arcane/iris/engine/object/structure/StructureDistribution.java rename to src/main/java/art/arcane/iris/builtin/structure/StructureDistribution.java index 9add7fdf5..9a42c935a 100644 --- a/src/main/java/art/arcane/iris/engine/object/structure/StructureDistribution.java +++ b/src/main/java/art/arcane/iris/builtin/structure/StructureDistribution.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,10 +16,11 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.structure; +package art.arcane.iris.builtin.structure; -import art.arcane.iris.engine.object.annotations.Desc; +import com.volmit.config.Desc; +/** How a structure placement scatters its starts. The placement identity hashes the order. */ @Desc("Controls how structure start positions are scattered across the world.") public enum StructureDistribution { @Desc("Vanilla-style spacing/separation grid. One placement attempt per grid cell, randomly offset within it by the separation. Use spacing, separation and salt.") diff --git a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructurePlacement.java b/src/main/java/art/arcane/iris/builtin/structure/StructurePlacement.java similarity index 55% rename from src/main/java/art/arcane/iris/engine/object/structure/IrisStructurePlacement.java rename to src/main/java/art/arcane/iris/builtin/structure/StructurePlacement.java index d7d5315c9..465b30ceb 100644 --- a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructurePlacement.java +++ b/src/main/java/art/arcane/iris/builtin/structure/StructurePlacement.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,39 +16,37 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.structure; +package art.arcane.iris.builtin.structure; -import art.arcane.iris.builtin.structure.StructureStilts; -import art.arcane.iris.builtin.structure.StructureTerrain; -import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure; -import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -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.RegistryListStructure; -import art.arcane.volmlib.util.collection.KList; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; +import art.arcane.iris.engine.object.structure.IrisStructure; +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinItems; +import com.volmit.config.MinNumber; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.ResourceRef; -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Where and how often the structures of a dimension, region or biome start, written as one entry of its + * {@code "structures": [...]}: the pack's own structures to assemble or the platform's to start natively, the + * distribution of the starts, the height they anchor at, and how they meet the terrain. IrisApi types only, besides + * the structure resource kind the {@code structures} keys name. + */ @Desc("Attaches structures to a biome, region or dimension and controls where and how often they generate. This is independent of a structure's own native generation, so you can add custom placements in tandem with native generation or instead of it.") -@Data -public class IrisStructurePlacement { - @ArrayType(type = String.class, min = 1) - @RegistryListStructure +public final class StructurePlacement { + @MinItems(1) + @ResourceRef(IrisStructure.class) @Desc("Editable Iris assembly resources offered by this placement. Leave empty when nativeStructures supplies the source.") - private KList structures = new KList<>(); + private List structures = List.of(); - @ArrayType(type = IrisNativeStructure.class, min = 1) + @MinItems(1) @Desc("Live registered vanilla, datapack, and modded structures offered by this placement. Minecraft runs their native generator directly, independent of normal biome or dimension eligibility.") - private KList nativeStructures = new KList<>(); + private List nativeStructures = List.of(); @Desc("Stable authored identity for this placement. Set this when multiple placements use the same structure and settings. When empty, Iris derives identity from the placement content so list reordering does not move generated structures.") private String placementId = ""; @@ -98,12 +96,12 @@ public class IrisStructurePlacement { private boolean underground = false; @Desc("Vertical anchor policy. LEGACY preserves the underground boolean. Cave modes search existing carved-space data and implicitly behave as underground placements.") - private IrisStructureAnchorMode anchor = IrisStructureAnchorMode.LEGACY; + private StructureAnchorMode anchor = StructureAnchorMode.LEGACY; - @RegistryListResource(IrisBiome.class) - @ArrayType(type = String.class, min = 1) + @MinItems(1) + @Ref(Reference.PACK_BIOME) @Desc("Optional cave-biome allowlist for cave anchor modes. Empty accepts the cave biome resolved at the selected anchor. Entries match by load key, including prefix matches.") - private KList caveBiomes = new KList<>(); + private List caveBiomes = List.of(); @MinNumber(1) @MaxNumber(64) @@ -129,27 +127,129 @@ public class IrisStructurePlacement { @Desc("If false, the placement is skipped when its selected surface or cave column is submerged.") private boolean underwater = false; + public StructurePlacement() { + } + + /** Keys of the pack's structures the placement assembles, one picked per start. */ + public List structures() { + return listOrEmpty(structures); + } + + /** The platform structures the placement starts natively, one picked per start by weight. */ + public List nativeStructures() { + return listOrEmpty(nativeStructures); + } + + public String placementId() { + return placementId; + } + + public NativeStructureSuppression nativeSuppression() { + return nativeSuppression == null ? NativeStructureSuppression.NONE : nativeSuppression; + } + + public StructureDistribution distribution() { + return distribution == null ? StructureDistribution.RANDOM_SPREAD : distribution; + } + + public int spacing() { + return spacing; + } + + public int separation() { + return separation; + } + + public int salt() { + return salt; + } + + public double density() { + return density; + } + + public int ringCount() { + return ringCount; + } + + public int ringDistance() { + return ringDistance; + } + + public int ringSpread() { + return ringSpread; + } + + public int minHeight() { + return minHeight; + } + + public int maxHeight() { + return maxHeight; + } + + public boolean underground() { + return underground; + } + + /** The anchor as written; {@link #resolvedAnchor} says what {@code LEGACY} means for this placement. */ + public StructureAnchorMode anchor() { + return anchor == null ? StructureAnchorMode.LEGACY : anchor; + } + + /** Cave biome keys or key prefixes a cave anchor accepts; empty for any. */ + public List caveBiomes() { + return listOrEmpty(caveBiomes); + } + + public int caveAnchorAttempts() { + return caveAnchorAttempts; + } + + public int caveAnchorScanStep() { + return caveAnchorScanStep; + } + + public int caveMinimumClearance() { + return caveMinimumClearance; + } + + /** How the placement's structures meet the terrain; the defaults when the pack wrote none. */ public StructureTerrain resolvedTerrain() { return terrain == null ? new StructureTerrain() : terrain; } + /** The foundation columns under the structures; empty for none. */ + public Optional stilt() { + return Optional.ofNullable(stilt); + } + + public boolean underwater() { + return underwater; + } + public boolean hasIrisStructures() { - return structures != null && !structures.isEmpty(); + return !structures().isEmpty(); } public boolean hasNativeStructures() { - return nativeStructures != null && !nativeStructures.isEmpty(); + return !nativeStructures().isEmpty(); } - public IrisStructureAnchorMode resolvedAnchor() { - if (anchor == null || anchor == IrisStructureAnchorMode.LEGACY) { - return underground ? IrisStructureAnchorMode.HEIGHT_BAND : IrisStructureAnchorMode.SURFACE; + /** The anchor this placement uses: {@code LEGACY} is the band when {@link #underground}, else the surface. */ + public StructureAnchorMode resolvedAnchor() { + if (anchor() == StructureAnchorMode.LEGACY) { + return underground ? StructureAnchorMode.HEIGHT_BAND : StructureAnchorMode.SURFACE; } - return anchor; + return anchor(); } public boolean isAnchoredUnderground() { - IrisStructureAnchorMode activeAnchor = resolvedAnchor(); - return activeAnchor == IrisStructureAnchorMode.HEIGHT_BAND || activeAnchor.isCave(); + StructureAnchorMode activeAnchor = resolvedAnchor(); + return activeAnchor == StructureAnchorMode.HEIGHT_BAND || activeAnchor.isCave(); + } + + private static List listOrEmpty(List list) { + return list == null ? List.of() : Collections.unmodifiableList(list); } } diff --git a/src/main/java/art/arcane/iris/builtin/structure/StructurePlacementSettings.java b/src/main/java/art/arcane/iris/builtin/structure/StructurePlacementSettings.java new file mode 100644 index 000000000..32eaffff3 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/structure/StructurePlacementSettings.java @@ -0,0 +1,48 @@ +/* + * 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.builtin.structure; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; + +import java.util.Collections; +import java.util.List; + +/** + * The structure placements of a dimension, region or biome, written as {@code "structures": [...]}: one + * {@link StructurePlacement} per entry. IrisApi types only. + */ +@Desc("Iris structure placements of this dimension, region or biome: where and how often its structures start.") +@Feature(id = "iris:structure/placements", name = "Structure placements", key = "structures", root = "placements", + targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class StructurePlacementSettings implements IrisFeature { + @MinItems(1) + @Desc("Iris structure placements, each independent of the others.") + private List placements = List.of(); + + public StructurePlacementSettings() { + } + + public List placements() { + return placements == null ? List.of() : Collections.unmodifiableList(placements); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/vanillafeatures/ImportedFeaturesSettings.java b/src/main/java/art/arcane/iris/builtin/vanillafeatures/ImportedFeaturesSettings.java new file mode 100644 index 000000000..cf5bfaf2b --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/vanillafeatures/ImportedFeaturesSettings.java @@ -0,0 +1,80 @@ +/* + * 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.builtin.vanillafeatures; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; +import com.volmit.vanilla.DecorationStep; + +import java.util.Collections; +import java.util.List; + +/** + * Whether a dimension runs the platform's own placed features over its terrain, written as + * {@code "importedFeatures": {"enabled": true, "disabledSteps": ["VEGETAL_DECORATION"]}}: the switch, and the features and + * decoration steps it leaves out. IrisApi types only. + */ +@Desc("Controls native vanilla, mod, and ingested datapack PLACED FEATURE generation for this dimension. Placed features are ores, trees, plants, springs, geodes and every other decoration entry a biome declares. This is OFF by default: with 'enabled' false Iris generates exactly the terrain it always has and no native feature runs. With it true, every placed feature the biome's vanilla derivative declares runs over Iris terrain, in vanilla step order, on the same worldgen thread vanilla uses. Carvers are never imported - Iris has no NoiseGeneratorSettings, so there is nothing for a carver to carve against. Family matching on 'disabled' uses namespace, slash, or underscore boundaries, so 'minecraft:ore' covers every vanilla ore feature without matching unrelated names.") +@Feature(id = "iris:vanilla-features", name = "Vanilla features", key = "importedFeatures", targets = Target.DIMENSION) +public final class ImportedFeaturesSettings implements IrisFeature { + @Desc("Master switch. False (the default) means no native placed feature generates and chunk output is identical to a pack without this block at all. True runs the vanilla decoration feature pass over Iris terrain.") + private boolean enabled = false; + + @MinItems(1) + @Desc("Placed feature keys to deny explicitly, e.g. 'minecraft:ore_diamond'. A namespace:path prefix also matches, so 'minecraft:ore' denies every vanilla ore and 'minecraft:trees' denies every tree placement. Every key not matched here generates while 'enabled' is true.") + private List disabled = List.of(); + + @MinItems(1) + @Desc("Restrict feature generation to these decoration steps only. Empty (the default) means every step is eligible. Use this to import ores without importing vegetation: set it to UNDERGROUND_ORES.") + private List steps = List.of(); + + @MinItems(1) + @Desc("Decoration steps to deny. Applied after 'steps', so a step listed here never generates even if 'steps' allows it. VEGETAL_DECORATION is the usual entry for packs that grow their own trees.") + private List disabledSteps = List.of(); + + public ImportedFeaturesSettings() { + } + + /** Whether the platform's placed features run over the dimension's terrain. */ + public boolean enabled() { + return enabled; + } + + /** Family patterns of the placed features the dimension leaves out. */ + public List disabled() { + return listOrEmpty(disabled); + } + + /** The only decoration steps whose features generate; empty for every step. */ + public List steps() { + return listOrEmpty(steps); + } + + /** Decoration steps whose features never generate, whatever {@link #steps} says. */ + public List disabledSteps() { + return listOrEmpty(disabledSteps); + } + + private static List listOrEmpty(List list) { + return list == null ? List.of() : Collections.unmodifiableList(list); + } +} diff --git a/src/main/java/art/arcane/iris/engine/framework/IrisStructureLocator.java b/src/main/java/art/arcane/iris/engine/framework/IrisStructureLocator.java index dbfd240ee..f9b7df408 100644 --- a/src/main/java/art/arcane/iris/engine/framework/IrisStructureLocator.java +++ b/src/main/java/art/arcane/iris/engine/framework/IrisStructureLocator.java @@ -26,22 +26,20 @@ import art.arcane.iris.engine.framework.structure.StructureGraphCatalog; import art.arcane.iris.engine.framework.structure.StructureGraphCompilation; import art.arcane.iris.engine.framework.structure.StructureAssemblyResult; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure; +import art.arcane.iris.builtin.structure.NativeStructureSource; import art.arcane.iris.engine.object.value.IrisPosition; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.engine.object.structure.IrisStructure; -import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode; +import art.arcane.iris.builtin.structure.StructureAnchorMode; import art.arcane.iris.builtin.structure.StructureCarveShape; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; +import art.arcane.iris.builtin.structure.StructurePlacement; import art.arcane.iris.builtin.structure.StructureTerrain; import art.arcane.iris.builtin.structure.StructureTerrainMode; -import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression; -import art.arcane.iris.engine.object.structure.StructureDistribution; +import art.arcane.iris.builtin.structure.NativeStructureSuppression; +import art.arcane.iris.builtin.structure.StructureDistribution; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.core.modules.IrisModuleHost; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; import com.volmit.ModuleLog; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; @@ -59,7 +57,7 @@ import java.util.regex.Pattern; * Finds where Iris assembly and native jigsaw placements generate. A structure key matches * an Iris structure load key, its {@code vanillaSource}, or a configured native registry key. * - * A per-engine index of placed keys is cached so {@code /locate} and {@code /iris goto} skip + * Each world keeps an index of placed keys in its state, so {@code /locate} and {@code /iris goto} skip * the grid scan entirely for keys that are not placed (keeping them as fast as vanilla). * * For RANDOM_SPREAD placements (the common, vanilla-style spaced grid) the locator jumps @@ -75,9 +73,6 @@ public final class IrisStructureLocator { private static final long CAVE_ANCHOR_DOMAIN = 0x43415645414E4348L; private static final Pattern NAMESPACED_RESOURCE_KEY = Pattern.compile("[a-z0-9_.-]+:[a-z0-9/._-]+"); - private static final Cache INDEX_CACHE = Caffeine.newBuilder().weakKeys().build(); - private static final Cache LOCATABLE_INDEX_CACHE = - Caffeine.newBuilder().weakKeys().build(); private static final PlacementIndex EMPTY_INDEX = new PlacementIndex( Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptyList()); @@ -99,6 +94,28 @@ public final class IrisStructureLocator { return index(engine).loadKeys; } + /** + * Every key under which a structure the engine's placements place can be found: the placed keys and the platform + * structures Iris structures stand in for ({@code vanillaSource}), the latter in lower case. + */ + public static Set placedKeysAndAliases(Engine engine) { + if (engine == null) { + return Collections.emptySet(); + } + PlacementIndex placementIndex = index(engine); + Set keys = new LinkedHashSet<>(placementIndex.loadKeys); + keys.addAll(placementIndex.vanillaAliases); + return Collections.unmodifiableSet(keys); + } + + /** The platform structures the engine's placements start natively ({@code nativeStructures}), in lower case. */ + public static Set nativeKeys(Engine engine) { + if (engine == null) { + return Collections.emptySet(); + } + return index(engine).nativeKeys; + } + public static boolean isPlaced(Engine engine, String key) { if (engine == null || key == null || key.isEmpty()) { return false; @@ -153,7 +170,7 @@ public final class IrisStructureLocator { if (engine == null || key == null || key.isBlank()) { return false; } - for (IrisStructurePlacement placement : index(engine).placements) { + for (StructurePlacement placement : index(engine).placements) { if (placement.hasIrisStructures() && matches(placement, key, engine.getData())) { return true; } @@ -168,13 +185,6 @@ public final class IrisStructureLocator { return index(engine).suppressedVanillaSources.contains(normalize(vanillaKey)); } - public static void invalidate(Engine engine) { - if (engine != null) { - INDEX_CACHE.invalidate(engine); - LOCATABLE_INDEX_CACHE.invalidate(engine); - } - } - public static boolean startsInChunk(Engine engine, String key, int cx, int cz) { if (!isPlaced(engine, key)) { return false; @@ -272,8 +282,8 @@ public final class IrisStructureLocator { CandidateBudget candidateBudget) { LocatedCandidate best = null; Set checkedChunks = new LinkedHashSet<>(); - for (IrisStructurePlacement placement : catalog.concentricRings()) { - int count = Math.max(1, placement.getRingCount()); + for (StructurePlacement placement : catalog.concentricRings()) { + int count = Math.max(1, placement.ringCount()); for (int placementIndex = 0; placementIndex < count; placementIndex++) { candidateBudget.claim(); int[] candidate = StructurePlacementGrid.concentricRingChunk( @@ -411,8 +421,8 @@ public final class IrisStructureLocator { } Set checkedRingChunks = new LinkedHashSet<>(); - for (IrisStructurePlacement placement : catalog.concentricRings) { - int count = Math.max(1, placement.getRingCount()); + for (StructurePlacement placement : catalog.concentricRings) { + int count = Math.max(1, placement.ringCount()); for (int placementIndex = 0; placementIndex < count; placementIndex++) { candidateBudget.claim(); int[] candidate = StructurePlacementGrid.concentricRingChunk(placement, placementIndex, seed); @@ -478,13 +488,13 @@ public final class IrisStructureLocator { && Math.abs((long) chunkZ - centerChunkZ) <= radius; } - public static ResolvedPlacement resolvePlacement(Engine engine, IrisStructurePlacement placement, int cx, int cz) { + public static ResolvedPlacement resolvePlacement(Engine engine, StructurePlacement placement, int cx, int cz) { if (engine == null || engine.getData() == null || engine.getSeedManager() == null) { throw new IllegalStateException("Iris structure placement requires a fully bound engine"); } NativeStartPlanner.validateBackend(placement); - if (!placement.hasIrisStructures() || placement.getDistribution() == null) { - throw new IllegalStateException("Iris structure placement is missing its distribution or structure list"); + if (!placement.hasIrisStructures()) { + throw new IllegalStateException("Iris structure placement is missing its structure list"); } long seed = engine.getSeedManager().getMantle(); if (!StructurePlacementGrid.startsInChunk(placement, cx, cz, seed)) { @@ -570,18 +580,18 @@ public final class IrisStructureLocator { return new ResolvedPlacement(placement, selectedKey, structure, pieces, rng, originX, baseY, originZ, exactY); } - public static boolean requirePlacementOutput(IrisStructurePlacement placement, String structureKey, + public static boolean requirePlacementOutput(StructurePlacement placement, String structureKey, int chunkX, int chunkZ, boolean outputPresent, String failureReason) { if (outputPresent) { return true; } if (placement == null - || NativeStructureSuppression.REPLACE_SOURCE != placement.getNativeSuppression()) { + || NativeStructureSuppression.REPLACE_SOURCE != placement.nativeSuppression()) { return false; } String key = structureKey == null || structureKey.isBlank() - ? String.valueOf(placement.getStructures()) : structureKey; + ? String.valueOf(placement.structures()) : structureKey; String reason = failureReason == null || failureReason.isBlank() ? "placement produced no output" : failureReason; throw new IllegalStateException("REPLACE_SOURCE placement for Iris structure '" + key @@ -604,13 +614,13 @@ public final class IrisStructureLocator { String normalizedKey = normalize(key); if (hasNativePlacement(engine, key)) { for (NativeStartPlanner.Plan plan : NativeStartPlanner.plansAt(engine, cx, cz)) { - if (normalize(plan.source().getStructure()).equals(normalizedKey)) { + if (normalize(plan.source().structure()).equals(normalizedKey)) { return new ResolvedStart(cx << 4, plan.baseY(), cz << 4); } } } - KList placements = StructurePlacementScope.placementsAt(engine, cx, cz); - for (IrisStructurePlacement placement : placements) { + KList placements = StructurePlacementScope.placementsAt(engine, cx, cz); + for (StructurePlacement placement : placements) { if (!matches(placement, key, data)) { continue; } @@ -628,7 +638,7 @@ public final class IrisStructureLocator { private static PlacementAnchor resolveAnchor( Engine engine, - IrisStructurePlacement placement, + StructurePlacement placement, int chunkX, int chunkZ, int originX, @@ -644,29 +654,29 @@ public final class IrisStructureLocator { return baseY == null ? null : new PlacementAnchor(originX, baseY, originZ); } - private static Integer resolveBaseY(Engine engine, IrisStructurePlacement placement, int originX, int originZ, RNG rng) { + private static Integer resolveBaseY(Engine engine, StructurePlacement placement, int originX, int originZ, RNG rng) { int worldMin = engine.getMinHeight() + 1; int worldMax = engine.getMinHeight() + engine.getHeight() - 1; if (worldMin > worldMax) { return null; } - if (!placement.isUnderwater() + if (!placement.underwater() && NativeStartPlanner.isSubmerged(engine, originX, originZ)) { return null; } - if (placement.resolvedAnchor() == IrisStructureAnchorMode.SURFACE) { + if (placement.resolvedAnchor() == StructureAnchorMode.SURFACE) { int surfaceY = engine.getHeight(originX, originZ, true) + engine.getMinHeight(); - return surfaceY < placement.getMinHeight() || surfaceY > placement.getMaxHeight() ? null : surfaceY; + return surfaceY < placement.minHeight() || surfaceY > placement.maxHeight() ? null : surfaceY; } - int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight())); - int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight())); + int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight())); + int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight())); if (bandMin > bandMax) { return null; } return randomInclusive(rng, bandMin, bandMax); } - static Integer resolveVerticalShift(KList pieces, IrisStructurePlacement placement, + static Integer resolveVerticalShift(KList pieces, StructurePlacement placement, int baseY, int worldMin, int worldMax) { int[] bounds = computeBounds(pieces); if (bounds == null) { @@ -675,8 +685,8 @@ public final class IrisStructureLocator { if (!placement.isAnchoredUnderground() || placement.resolvedAnchor().isCave()) { return bounds[1] >= worldMin && bounds[4] <= worldMax ? 0 : null; } - int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight())); - int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight())); + int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight())); + int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight())); int minimumShift = Math.max(worldMin - bounds[1], bandMin - baseY); int maximumShift = Math.min(worldMax - bounds[4], bandMax - baseY); if (minimumShift > maximumShift) { @@ -692,7 +702,7 @@ public final class IrisStructureLocator { } static Integer resolveUndergroundBurialShift(Engine engine, KList pieces, - IrisStructurePlacement placement, int baseY, + StructurePlacement placement, int baseY, int worldMin, int worldMax) { int[] bounds = computeBounds(pieces); if (engine == null || bounds == null || placement == null || !placement.isAnchoredUnderground() @@ -711,8 +721,8 @@ public final class IrisStructureLocator { terrain.ceilingPadding(), terrain.resolvedErosionStrength()) : bore ? Math.max(0, terrain.ceilingPadding()) : 0; int bottomExtension = forceCarve || bore ? Math.max(0, terrain.floorPadding()) : 0; - int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight())); - int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight())); + int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight())); + int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight())); int minimumShift = Math.max(worldMin - (bounds[1] - bottomExtension), bandMin - baseY); int maximumShift = Math.min(0, Math.min(worldMax - (bounds[4] + topExtension), bandMax - baseY)); if (minimumShift > maximumShift) { @@ -776,19 +786,19 @@ public final class IrisStructureLocator { return maximumShift; } - static String selectStructureKey(IrisStructurePlacement placement, RNG rng) { - if (placement == null || placement.getStructures() == null || placement.getStructures().isEmpty()) { + static String selectStructureKey(StructurePlacement placement, RNG rng) { + if (placement == null || placement.structures().isEmpty()) { return null; } - return placement.getStructures().get(rng.nextInt(placement.getStructures().size())); + return placement.structures().get(rng.nextInt(placement.structures().size())); } static KList alignCavePieces( KList pieces, - IrisStructurePlacement placement, + StructurePlacement placement, int anchorY ) { - IrisStructureAnchorMode mode = placement.resolvedAnchor(); + StructureAnchorMode mode = placement.resolvedAnchor(); if (!mode.isCave()) { return pieces; } @@ -806,7 +816,7 @@ public final class IrisStructureLocator { } private static KList alignSurfacePieces(KList pieces, - IrisStructurePlacement placement, + StructurePlacement placement, IrisStructure structure, int baseY) { if (placement.isAnchoredUnderground() || pieces.size() <= 1 || structure.getPlaceMode().placeMode().has(PlaceTrait.FREE_HEIGHT)) { @@ -816,7 +826,7 @@ public final class IrisStructureLocator { return bounds == null ? pieces : shiftPieces(pieces, baseY - bounds[1]); } - static boolean hasExactY(IrisStructurePlacement placement, IrisStructure structure, + static boolean hasExactY(StructurePlacement placement, IrisStructure structure, KList pieces) { return placement.isAnchoredUnderground() || pieces.size() > 1 || structure.getPlaceMode().placeMode().has(PlaceTrait.FREE_HEIGHT); @@ -883,39 +893,38 @@ public final class IrisStructureLocator { private static PlacementCatalog collectPlacementCatalog(Engine engine, String key) { Set randomSpread = new LinkedHashSet<>(); - List concentricRings = new ArrayList<>(); + List concentricRings = new ArrayList<>(); boolean hasDensity = false; - for (IrisStructurePlacement placement : index(engine).placements) { + for (StructurePlacement placement : index(engine).placements) { if (!isSearchablePlacement(engine, placement) || !matches(placement, key, engine.getData())) { continue; } - if (placement.getDistribution() == StructureDistribution.RANDOM_SPREAD) { + if (placement.distribution() == StructureDistribution.RANDOM_SPREAD) { randomSpread.add(new RandomSpreadParameters( - Math.max(1, placement.getSpacing()), placement.getSeparation(), + Math.max(1, placement.spacing()), placement.separation(), StructurePlacementGrid.placementSalt(placement))); - } else if (placement.getDistribution() == StructureDistribution.CONCENTRIC_RINGS) { + } else if (placement.distribution() == StructureDistribution.CONCENTRIC_RINGS) { concentricRings.add(placement); - } else if (placement.getDistribution() == StructureDistribution.DENSITY) { + } else if (placement.distribution() == StructureDistribution.DENSITY) { hasDensity = true; } } return new PlacementCatalog(List.copyOf(randomSpread), List.copyOf(concentricRings), hasDensity); } - static boolean isSearchableDensityPlacement(Engine engine, IrisStructurePlacement placement) { + static boolean isSearchableDensityPlacement(Engine engine, StructurePlacement placement) { return placement != null - && placement.getDistribution() == StructureDistribution.DENSITY + && placement.distribution() == StructureDistribution.DENSITY && isSearchablePlacement(engine, placement); } - static boolean isSearchablePlacement(Engine engine, IrisStructurePlacement placement) { - if (engine == null || placement == null || placement.getDistribution() == null - || engine.getHeight() <= 0) { + static boolean isSearchablePlacement(Engine engine, StructurePlacement placement) { + if (engine == null || placement == null || engine.getHeight() <= 0) { return false; } - if (placement.getDistribution() == StructureDistribution.DENSITY - && !(placement.getDensity() > 0.0)) { + if (placement.distribution() == StructureDistribution.DENSITY + && !(placement.density() > 0.0)) { return false; } long worldMin = (long) engine.getMinHeight() + (placement.isAnchoredUnderground() ? 1L : 0L); @@ -925,11 +934,11 @@ public final class IrisStructureLocator { return false; } long configuredMin = placement.isAnchoredUnderground() - ? Math.min(placement.getMinHeight(), placement.getMaxHeight()) - : placement.getMinHeight(); + ? Math.min(placement.minHeight(), placement.maxHeight()) + : placement.minHeight(); long configuredMax = placement.isAnchoredUnderground() - ? Math.max(placement.getMinHeight(), placement.getMaxHeight()) - : placement.getMaxHeight(); + ? Math.max(placement.minHeight(), placement.maxHeight()) + : placement.maxHeight(); return configuredMin <= configuredMax && configuredMin <= worldMax && configuredMax >= worldMin; } @@ -1007,22 +1016,17 @@ public final class IrisStructureLocator { private record PlacementAnchor(int x, int y, int z) { } - private static boolean matches(IrisStructurePlacement placement, String key, IrisData data) { + private static boolean matches(StructurePlacement placement, String key, IrisData data) { if (placement == null || key == null || data == null) { return false; } String normalizedKey = normalize(key); - if (placement.getNativeStructures() != null) { - for (IrisNativeStructure source : placement.getNativeStructures()) { - if (source != null && normalize(source.getStructure()).equals(normalizedKey)) { - return true; - } + for (NativeStructureSource source : placement.nativeStructures()) { + if (source != null && normalize(source.structure()).equals(normalizedKey)) { + return true; } } - if (placement.getStructures() == null) { - return false; - } - for (String structureKey : placement.getStructures()) { + for (String structureKey : placement.structures()) { if (structureKey == null || structureKey.isBlank()) { continue; } @@ -1057,14 +1061,14 @@ public final class IrisStructureLocator { if (engine.getData() == null || engine.getDimension() == null) { throw new IllegalStateException("Iris structure index requires a fully bound engine and dimension"); } - return INDEX_CACHE.get(engine, ignored -> build(engine)); + return engine.getGeneration().state(PlacementIndex.class, IrisStructureLocator::build); } private static LocatableIndex locatableIndex(Engine engine) { if (engine == null) { return EMPTY_LOCATABLE_INDEX; } - return LOCATABLE_INDEX_CACHE.get(engine, ignored -> buildLocatableIndex(engine)); + return engine.getGeneration().state(LocatableIndex.class, IrisStructureLocator::buildLocatableIndex); } private static LocatableIndex buildLocatableIndex(Engine engine) { @@ -1075,18 +1079,18 @@ public final class IrisStructureLocator { Set normalizedEditableKeys = new LinkedHashSet<>(); Set nativeKeys = new LinkedHashSet<>(); Set normalizedNativeKeys = new LinkedHashSet<>(); - for (IrisStructurePlacement placement : index(engine).placements) { + for (StructurePlacement placement : index(engine).placements) { if (!isSearchablePlacement(engine, placement)) { continue; } if (placement.hasNativeStructures()) { - for (IrisNativeStructure source : placement.getNativeStructures()) { - addLocatableKey(source.getStructure(), keys, normalizedKeys); - addLocatableKey(source.getStructure(), nativeKeys, normalizedNativeKeys); + for (NativeStructureSource source : placement.nativeStructures()) { + addLocatableKey(source.structure(), keys, normalizedKeys); + addLocatableKey(source.structure(), nativeKeys, normalizedNativeKeys); } continue; } - for (String structureKey : placement.getStructures()) { + for (String structureKey : placement.structures()) { IrisStructure structure = StructureResources.structure(data, structureKey); if (structure == null) { throw new IllegalStateException( @@ -1125,13 +1129,13 @@ public final class IrisStructureLocator { Set normalizedLoadKeys = new LinkedHashSet<>(); Set vanillaAliases = new LinkedHashSet<>(); Set suppressedVanillaSources = new LinkedHashSet<>(); - List placements = new ArrayList<>(); - collect(engine.getDimension().getStructures(), data, log, loadKeys, normalizedLoadKeys, vanillaAliases, + List placements = new ArrayList<>(); + collect(StructurePlacementScope.placementsOf(engine.getDimension()), data, log, loadKeys, normalizedLoadKeys, vanillaAliases, suppressedVanillaSources, placements, true); KList regions = engine.getDimension().getAllRegions(engine); if (regions != null) { for (IrisRegion region : regions) { - collect(region == null ? null : region.getStructures(), data, log, + collect(StructurePlacementScope.placementsOf(region), data, log, loadKeys, normalizedLoadKeys, vanillaAliases, suppressedVanillaSources, placements, false); } @@ -1139,7 +1143,7 @@ public final class IrisStructureLocator { KList biomes = engine.getDimension().getReachableBiomes(engine); if (biomes != null) { for (IrisBiome biome : biomes) { - collect(biome == null ? null : biome.getStructures(), data, log, + collect(StructurePlacementScope.placementsOf(biome), data, log, loadKeys, normalizedLoadKeys, vanillaAliases, suppressedVanillaSources, placements, false); } @@ -1153,48 +1157,42 @@ public final class IrisStructureLocator { List.copyOf(placements)); } - private static Set nativeKeys(List placements) { + private static Set nativeKeys(List placements) { Set nativeKeys = new LinkedHashSet<>(); - for (IrisStructurePlacement placement : placements) { + for (StructurePlacement placement : placements) { if (!placement.hasNativeStructures()) { continue; } - for (IrisNativeStructure source : placement.getNativeStructures()) { + for (NativeStructureSource source : placement.nativeStructures()) { if (source != null) { - nativeKeys.add(normalize(source.getStructure())); + nativeKeys.add(normalize(source.structure())); } } } return Collections.unmodifiableSet(nativeKeys); } - private static void collect(KList source, IrisData data, ModuleLog log, Set loadKeys, + private static void collect(List source, IrisData data, ModuleLog log, Set loadKeys, Set normalizedLoadKeys, Set vanillaAliases, Set suppressedVanillaSources, - List placements, boolean allowNativeSuppression) { - if (source == null) { - return; - } - for (IrisStructurePlacement placement : source) { + List placements, boolean allowNativeSuppression) { + for (StructurePlacement placement : source) { if (placement == null) { throw new IllegalStateException("Iris structure placement list contains a null placement"); } - if (placement.getDistribution() == null) { - throw new IllegalStateException("Iris structure placement is missing its distribution"); - } NativeStartPlanner.validateBackend(placement); - boolean replacesNative = NativeStructureSuppression.REPLACE_SOURCE == placement.getNativeSuppression(); + boolean replacesNative = NativeStructureSuppression.REPLACE_SOURCE == placement.nativeSuppression(); if (replacesNative && !allowNativeSuppression) { throw new IllegalStateException("REPLACE_SOURCE is only valid on dimension-level structure placements"); } if (placement.hasNativeStructures()) { - for (IrisNativeStructure nativeStructure : placement.getNativeStructures()) { + for (NativeStructureSource nativeStructure : placement.nativeStructures()) { if (nativeStructure == null - || nativeStructure.getStructure() == null - || !NAMESPACED_RESOURCE_KEY.matcher(nativeStructure.getStructure()).matches()) { + || nativeStructure.structure() == null + || !NAMESPACED_RESOURCE_KEY.matcher(nativeStructure.structure()).matches()) { throw new IllegalStateException("Native structure placement contains an invalid structure key"); } - String sourceKey = nativeStructure.getStructure(); + String sourceKey = nativeStructure.structure(); loadKeys.add(sourceKey); normalizedLoadKeys.add(normalize(sourceKey)); vanillaAliases.add(normalize(sourceKey)); @@ -1205,7 +1203,7 @@ public final class IrisStructureLocator { placements.add(placement); continue; } - for (String structureKey : placement.getStructures()) { + for (String structureKey : placement.structures()) { if (structureKey == null || structureKey.isBlank()) { throw new IllegalStateException(replacesNative ? "REPLACE_SOURCE contains a blank Iris structure reference" @@ -1244,7 +1242,7 @@ public final class IrisStructureLocator { } } - public record ResolvedPlacement(IrisStructurePlacement placement, String structureKey, IrisStructure structure, + public record ResolvedPlacement(StructurePlacement placement, String structureKey, IrisStructure structure, KList pieces, RNG rng, int originX, int baseY, int originZ, boolean exactY) { } @@ -1276,7 +1274,7 @@ public final class IrisStructureLocator { } private record PlacementCatalog(List randomSpread, - List concentricRings, boolean hasDensity) { + List concentricRings, boolean hasDensity) { } private record LocatableIndex(Set keys, Set normalizedKeys, @@ -1307,12 +1305,12 @@ public final class IrisStructureLocator { private final Set vanillaAliases; private final Set suppressedVanillaSources; private final Set nativeKeys; - private final List placements; + private final List placements; private PlacementIndex(Set loadKeys, Set normalizedLoadKeys, Set vanillaAliases, Set suppressedVanillaSources, Set nativeKeys, - List placements) { + List placements) { this.loadKeys = loadKeys; this.normalizedLoadKeys = normalizedLoadKeys; this.vanillaAliases = vanillaAliases; diff --git a/src/main/java/art/arcane/iris/engine/framework/StructureCaveAnchorResolver.java b/src/main/java/art/arcane/iris/engine/framework/StructureCaveAnchorResolver.java index 599b4bd88..163d6618d 100644 --- a/src/main/java/art/arcane/iris/engine/framework/StructureCaveAnchorResolver.java +++ b/src/main/java/art/arcane/iris/engine/framework/StructureCaveAnchorResolver.java @@ -1,8 +1,8 @@ package art.arcane.iris.engine.framework; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; +import art.arcane.iris.builtin.structure.StructureAnchorMode; +import art.arcane.iris.builtin.structure.StructurePlacement; import art.arcane.volmlib.util.math.RNG; import art.arcane.volmlib.util.matter.MatterCavern; @@ -23,26 +23,26 @@ public final class StructureCaveAnchorResolver { private StructureCaveAnchorResolver() { } - public static Anchor resolve(Engine engine, IrisStructurePlacement placement, int chunkX, int chunkZ, RNG rng) { + public static Anchor resolve(Engine engine, StructurePlacement placement, int chunkX, int chunkZ, RNG rng) { Objects.requireNonNull(engine, "Cave structure anchor requires an engine"); Objects.requireNonNull(placement, "Cave structure anchor requires a placement"); Objects.requireNonNull(rng, "Cave structure anchor requires a random source"); - IrisStructureAnchorMode mode = placement.resolvedAnchor(); + StructureAnchorMode mode = placement.resolvedAnchor(); if (!mode.isCave() || engine.getMantle() == null || engine.getMantle().getMantle() == null) { return null; } int worldMin = engine.getMinHeight() + 1; int worldMax = engine.getMinHeight() + engine.getHeight() - 2; - int minimumY = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight())); - int maximumY = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight())); + int minimumY = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight())); + int maximumY = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight())); if (minimumY > maximumY) { return null; } - int attempts = Math.min(MAX_ATTEMPTS, Math.max(1, placement.getCaveAnchorAttempts())); - int scanStep = Math.min(MAX_SCAN_STEP, Math.max(1, placement.getCaveAnchorScanStep())); - int clearance = Math.min(MAX_CLEARANCE, Math.max(1, placement.getCaveMinimumClearance())); + int attempts = Math.min(MAX_ATTEMPTS, Math.max(1, placement.caveAnchorAttempts())); + int scanStep = Math.min(MAX_SCAN_STEP, Math.max(1, placement.caveAnchorScanStep())); + int clearance = Math.min(MAX_CLEARANCE, Math.max(1, placement.caveMinimumClearance())); int chunkMinX = chunkX << 4; int chunkMinZ = chunkZ << 4; int[] candidateColumns = candidateColumnIndices(rng, attempts); @@ -73,8 +73,8 @@ public final class StructureCaveAnchorResolver { static List anchorsInColumn( Engine engine, - IrisStructurePlacement placement, - IrisStructureAnchorMode mode, + StructurePlacement placement, + StructureAnchorMode mode, int blockX, int blockZ, int minimumY, @@ -82,7 +82,7 @@ public final class StructureCaveAnchorResolver { int scanStep, int clearance ) { - if (mode == IrisStructureAnchorMode.CAVE_CENTER) { + if (mode == StructureAnchorMode.CAVE_CENTER) { return centerAnchorsInColumn( engine, placement, blockX, blockZ, minimumY, maximumY, scanStep, clearance); @@ -107,7 +107,7 @@ public final class StructureCaveAnchorResolver { private static List centerAnchorsInColumn( Engine engine, - IrisStructurePlacement placement, + StructurePlacement placement, int blockX, int blockZ, int minimumY, @@ -153,7 +153,7 @@ public final class StructureCaveAnchorResolver { private static void addCenterAnchor( List anchors, Engine engine, - IrisStructurePlacement placement, + StructurePlacement placement, int blockX, int blockZ, int worldY, @@ -172,14 +172,14 @@ public final class StructureCaveAnchorResolver { static boolean matchesGeometry( Engine engine, - IrisStructureAnchorMode mode, + StructureAnchorMode mode, int blockX, int mantleY, int blockZ, int clearance ) { IntPredicate carved = y -> isCarved(engine, blockX, y, blockZ); - if (mode == IrisStructureAnchorMode.CAVE_CENTER) { + if (mode == StructureAnchorMode.CAVE_CENTER) { return matchesCenterGeometry( carved, mantleY, Math.max(1, clearance), 0, engine.getHeight() - 1); } @@ -188,7 +188,7 @@ public final class StructureCaveAnchorResolver { static boolean matchesGeometry( IntPredicate carved, - IrisStructureAnchorMode mode, + StructureAnchorMode mode, int mantleY, int clearance ) { @@ -281,14 +281,14 @@ public final class StructureCaveAnchorResolver { private static boolean matchesAnchorFluid( Engine engine, - IrisStructurePlacement placement, + StructurePlacement placement, int blockX, int mantleY, int blockZ ) { MatterCavern cavern = cavernAt(engine, blockX, mantleY, blockZ); return acceptsAnchorFluid( - placement.isUnderwater(), + placement.underwater(), cavern, mantleY, engine.getDimension().getCaveLavaHeight()); @@ -322,12 +322,12 @@ public final class StructureCaveAnchorResolver { private static boolean matchesBiome( Engine engine, - IrisStructurePlacement placement, + StructurePlacement placement, int blockX, int mantleY, int blockZ ) { - if (placement.getCaveBiomes() == null || placement.getCaveBiomes().isEmpty()) { + if (placement.caveBiomes().isEmpty()) { return true; } IrisBiome biome = engine.getCaveOrMantleBiome(blockX, mantleY, blockZ); @@ -335,7 +335,7 @@ public final class StructureCaveAnchorResolver { return false; } String actual = biome.getLoadKey().toLowerCase(Locale.ROOT); - for (String allowed : placement.getCaveBiomes()) { + for (String allowed : placement.caveBiomes()) { if (matchesBiomeKey(actual, allowed)) { return true; } diff --git a/src/main/java/art/arcane/iris/engine/framework/StructurePlacementGrid.java b/src/main/java/art/arcane/iris/engine/framework/StructurePlacementGrid.java index e02ad2288..bc477f26b 100644 --- a/src/main/java/art/arcane/iris/engine/framework/StructurePlacementGrid.java +++ b/src/main/java/art/arcane/iris/engine/framework/StructurePlacementGrid.java @@ -18,9 +18,9 @@ package art.arcane.iris.engine.framework; -import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure; -import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; +import art.arcane.iris.builtin.structure.NativeStructureSource; +import art.arcane.iris.builtin.structure.StructureAnchorMode; +import art.arcane.iris.builtin.structure.StructurePlacement; import art.arcane.volmlib.util.math.RNG; import java.util.Locale; @@ -33,16 +33,16 @@ public final class StructurePlacementGrid { private StructurePlacementGrid() { } - public static boolean startsInChunk(IrisStructurePlacement placement, int cx, int cz, long seed) { - return switch (placement.getDistribution()) { - case RANDOM_SPREAD -> randomSpreadStart(cx, cz, placement.getSpacing(), placement.getSeparation(), + public static boolean startsInChunk(StructurePlacement placement, int cx, int cz, long seed) { + return switch (placement.distribution()) { + case RANDOM_SPREAD -> randomSpreadStart(cx, cz, placement.spacing(), placement.separation(), placementSalt(placement), seed); case DENSITY -> densityStart(placement, cx, cz, seed); case CONCENTRIC_RINGS -> concentricRingsStart(cx, cz, placement, seed); }; } - public static RNG placementRng(IrisStructurePlacement placement, int cx, int cz, long seed) { + public static RNG placementRng(StructurePlacement placement, int cx, int cz, long seed) { return new RNG(placementSeed(placement, cx, cz, seed)); } @@ -69,13 +69,13 @@ public final class StructurePlacementGrid { return new int[]{startCx, startCz}; } - public static int[] concentricRingChunk(IrisStructurePlacement placement, int placementIndex, long seed) { - int count = Math.max(1, placement.getRingCount()); + public static int[] concentricRingChunk(StructurePlacement placement, int placementIndex, long seed) { + int count = Math.max(1, placement.ringCount()); if (placementIndex < 0 || placementIndex >= count) { return null; } - int distance = Math.max(1, placement.getRingDistance()); - int spread = Math.max(1, placement.getRingSpread()); + int distance = Math.max(1, placement.ringDistance()); + int spread = Math.max(1, placement.ringSpread()); int ring = Math.floorDiv(placementIndex, spread) + 1; int firstIndex = (ring - 1) * spread; int slots = Math.min(spread, count - firstIndex); @@ -94,13 +94,13 @@ public final class StructurePlacementGrid { }; } - private static boolean concentricRingsStart(int cx, int cz, IrisStructurePlacement placement, long seed) { + private static boolean concentricRingsStart(int cx, int cz, StructurePlacement placement, long seed) { if (cx == 0 && cz == 0) { return false; } - int distance = Math.max(1, placement.getRingDistance()); - int count = Math.max(1, placement.getRingCount()); - int spread = Math.max(1, placement.getRingSpread()); + int distance = Math.max(1, placement.ringDistance()); + int count = Math.max(1, placement.ringCount()); + int spread = Math.max(1, placement.ringSpread()); double dist = Math.sqrt((double) cx * cx + (double) cz * cz); int estimatedRing = (int) Math.round(dist / distance); int ringCount = Math.ceilDiv(count, spread); @@ -127,8 +127,8 @@ public final class StructurePlacementGrid { return false; } - private static boolean densityStart(IrisStructurePlacement placement, int cx, int cz, long seed) { - double density = placement.getDensity(); + private static boolean densityStart(StructurePlacement placement, int cx, int cz, long seed) { + double density = placement.density(); if (density <= 0.0) { return false; } @@ -139,33 +139,33 @@ public final class StructurePlacementGrid { return rng.chance(density); } - public static long placementIdentity(IrisStructurePlacement placement) { + public static long placementIdentity(StructurePlacement placement) { long signature = 1469598103934665603L; - signature = appendLong(signature, placement.getDistribution().ordinal()); - signature = appendLong(signature, placement.getSalt()); - String placementId = placement.getPlacementId(); + signature = appendLong(signature, placement.distribution().ordinal()); + signature = appendLong(signature, placement.salt()); + String placementId = placement.placementId(); if (placementId != null && !placementId.isBlank()) { signature = appendLong(signature, 1L); signature = appendSignature(signature, placementId.trim()); } else { signature = appendLong(signature, 0L); - signature = appendLong(signature, placement.getSpacing()); - signature = appendLong(signature, placement.getSeparation()); - signature = appendLong(signature, Double.doubleToLongBits(placement.getDensity())); - signature = appendLong(signature, placement.getRingCount()); - signature = appendLong(signature, placement.getRingDistance()); - signature = appendLong(signature, placement.getRingSpread()); - signature = appendLong(signature, placement.getMinHeight()); - signature = appendLong(signature, placement.getMaxHeight()); - signature = appendLong(signature, placement.isUnderground() ? 1L : 0L); - signature = appendLong(signature, placement.isUnderwater() ? 1L : 0L); + signature = appendLong(signature, placement.spacing()); + signature = appendLong(signature, placement.separation()); + signature = appendLong(signature, Double.doubleToLongBits(placement.density())); + signature = appendLong(signature, placement.ringCount()); + signature = appendLong(signature, placement.ringDistance()); + signature = appendLong(signature, placement.ringSpread()); + signature = appendLong(signature, placement.minHeight()); + signature = appendLong(signature, placement.maxHeight()); + signature = appendLong(signature, placement.underground() ? 1L : 0L); + signature = appendLong(signature, placement.underwater() ? 1L : 0L); signature = appendSources(signature, placement); signature = appendAnchor(signature, placement); } return signature; } - private static long placementSeed(IrisStructurePlacement placement, int cx, int cz, long seed) { + private static long placementSeed(StructurePlacement placement, int cx, int cz, long seed) { long signature = placementIdentity(placement); int identitySalt = (int) (signature ^ (signature >>> 32)); return mix(seed ^ signature, cx, cz, placementSalt(placement) ^ identitySalt); @@ -189,37 +189,34 @@ public final class StructurePlacementGrid { return result; } - private static long appendSources(long signature, IrisStructurePlacement placement) { + private static long appendSources(long signature, StructurePlacement placement) { long result = signature; if (placement.hasIrisStructures()) { result = appendLong(result, 1L); - result = appendLong(result, placement.getStructures().size()); - for (String key : placement.getStructures()) { + result = appendLong(result, placement.structures().size()); + for (String key : placement.structures()) { result = appendSignature(result, key == null ? "" : key); } return result; } result = appendLong(result, 2L); - if (placement.getNativeStructures() == null) { - return appendLong(result, 0L); - } - result = appendLong(result, placement.getNativeStructures().size()); - for (IrisNativeStructure source : placement.getNativeStructures()) { + result = appendLong(result, placement.nativeStructures().size()); + for (NativeStructureSource source : placement.nativeStructures()) { if (source == null) { result = appendSignature(result, ""); result = appendLong(result, 0L); continue; } result = appendSignature(result, - source.getStructure() == null ? "" : source.getStructure()); - result = appendLong(result, source.getWeight()); + source.structure() == null ? "" : source.structure()); + result = appendLong(result, source.weight()); } return result; } - private static long appendAnchor(long signature, IrisStructurePlacement placement) { - IrisStructureAnchorMode anchor = placement.getAnchor(); - if (anchor == null || anchor == IrisStructureAnchorMode.LEGACY) { + private static long appendAnchor(long signature, StructurePlacement placement) { + StructureAnchorMode anchor = placement.anchor(); + if (anchor == StructureAnchorMode.LEGACY) { return signature; } long result = appendLong(signature, 0x4A49475341574C41L); @@ -227,14 +224,11 @@ public final class StructurePlacementGrid { if (!anchor.isCave()) { return result; } - result = appendLong(result, placement.getCaveAnchorAttempts()); - result = appendLong(result, placement.getCaveAnchorScanStep()); - result = appendLong(result, placement.getCaveMinimumClearance()); - if (placement.getCaveBiomes() == null) { - return appendLong(result, 0L); - } + result = appendLong(result, placement.caveAnchorAttempts()); + result = appendLong(result, placement.caveAnchorScanStep()); + result = appendLong(result, placement.caveMinimumClearance()); Set biomes = new TreeSet<>(); - for (String biome : placement.getCaveBiomes()) { + for (String biome : placement.caveBiomes()) { if (biome != null && !biome.isBlank()) { biomes.add(biome.trim().toLowerCase(Locale.ROOT)); } @@ -246,28 +240,28 @@ public final class StructurePlacementGrid { return result; } - static int placementSalt(IrisStructurePlacement placement) { - String placementId = placement.getPlacementId(); + static int placementSalt(StructurePlacement placement) { + String placementId = placement.placementId(); long identity; if (placementId != null && !placementId.isBlank()) { identity = appendSignature(1469598103934665603L, placementId.trim()); } else { identity = 1469598103934665603L; - identity = appendLong(identity, placement.getDistribution().ordinal()); - identity = appendLong(identity, placement.getSpacing()); - identity = appendLong(identity, placement.getSeparation()); - identity = appendLong(identity, Double.doubleToLongBits(placement.getDensity())); - identity = appendLong(identity, placement.getRingCount()); - identity = appendLong(identity, placement.getRingDistance()); - identity = appendLong(identity, placement.getRingSpread()); - identity = appendLong(identity, placement.getMinHeight()); - identity = appendLong(identity, placement.getMaxHeight()); - identity = appendLong(identity, placement.isUnderground() ? 1L : 0L); - identity = appendLong(identity, placement.isUnderwater() ? 1L : 0L); + identity = appendLong(identity, placement.distribution().ordinal()); + identity = appendLong(identity, placement.spacing()); + identity = appendLong(identity, placement.separation()); + identity = appendLong(identity, Double.doubleToLongBits(placement.density())); + identity = appendLong(identity, placement.ringCount()); + identity = appendLong(identity, placement.ringDistance()); + identity = appendLong(identity, placement.ringSpread()); + identity = appendLong(identity, placement.minHeight()); + identity = appendLong(identity, placement.maxHeight()); + identity = appendLong(identity, placement.underground() ? 1L : 0L); + identity = appendLong(identity, placement.underwater() ? 1L : 0L); identity = appendSources(identity, placement); identity = appendAnchor(identity, placement); } - return placement.getSalt() ^ (int) (identity ^ (identity >>> 32)); + return placement.salt() ^ (int) (identity ^ (identity >>> 32)); } private static double unitDouble(long value) { diff --git a/src/main/java/art/arcane/iris/engine/framework/StructurePlacementScope.java b/src/main/java/art/arcane/iris/engine/framework/StructurePlacementScope.java index 9e35719af..bc99627de 100644 --- a/src/main/java/art/arcane/iris/engine/framework/StructurePlacementScope.java +++ b/src/main/java/art/arcane/iris/engine/framework/StructurePlacementScope.java @@ -1,75 +1,68 @@ package art.arcane.iris.engine.framework; +import art.arcane.iris.builtin.structure.StructurePlacement; +import art.arcane.iris.builtin.structure.StructurePlacementSettings; +import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.region.IrisRegion; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; import art.arcane.volmlib.util.collection.KList; -import java.lang.ref.WeakReference; -import java.util.ArrayList; import java.util.Collections; import java.util.IdentityHashMap; import java.util.List; import java.util.Objects; import java.util.Set; +/** + * The structure placements that apply at a chunk: its biome's, its cave biome's cave-anchored ones, its region's and + * the dimension's. Each world keeps which of those levels declare placements at all, so chunks skip the biome and + * region lookups a pack never needs. + */ public final class StructurePlacementScope { - private static final List SCOPE_INDEXES = new ArrayList<>(); - private StructurePlacementScope() { } - public static KList placementsAt(Engine engine, int chunkX, int chunkZ) { + /** The placements {@code owner} declares in its {@code "structures"} settings; empty for none. */ + public static List placementsOf(IrisRegistrant owner) { + if (owner == null) { + return List.of(); + } + return owner.getModuleSettings().find(StructurePlacementSettings.class) + .map(StructurePlacementSettings::placements) + .orElse(List.of()); + } + + public static KList placementsAt(Engine engine, int chunkX, int chunkZ) { Engine activeEngine = Objects.requireNonNull(engine, "Structure placement scope requires an engine"); IrisComplex complex = activeEngine.getComplex(); int blockX = (chunkX << 4) + 8; int blockZ = (chunkZ << 4) + 8; - KList placements = new KList<>(); - Set seen = Collections.newSetFromMap(new IdentityHashMap<>()); + KList placements = new KList<>(); + Set seen = Collections.newSetFromMap(new IdentityHashMap<>()); ScopeIndex index = scopeIndex(activeEngine); if (complex != null) { if (index.biome()) { IrisBiome biome = complex.getTrueBiomeStream().get(blockX, blockZ); - addUnique(placements, seen, biome == null ? null : biome.getStructures()); + addUnique(placements, seen, placementsOf(biome)); } if (index.caveBiome()) { IrisBiome caveBiome = complex.getCaveBiomeStream().get(blockX, blockZ); - addCaveUnique(placements, seen, caveBiome == null ? null : caveBiome.getStructures()); + addCaveUnique(placements, seen, placementsOf(caveBiome)); } if (index.region()) { IrisRegion region = complex.getRegionStream().get(blockX, blockZ); - addUnique(placements, seen, region == null ? null : region.getStructures()); + addUnique(placements, seen, placementsOf(region)); } } if (index.dimension()) { - addUnique(placements, seen, activeEngine.getDimension().getStructures()); + addUnique(placements, seen, placementsOf(activeEngine.getDimension())); } return placements; } private static ScopeIndex scopeIndex(Engine engine) { - int revision = engine.getCacheID(); - synchronized (SCOPE_INDEXES) { - for (int i = SCOPE_INDEXES.size() - 1; i >= 0; i--) { - CachedScopeIndex cached = SCOPE_INDEXES.get(i); - Engine indexedEngine = cached.engine().get(); - if (indexedEngine == null) { - SCOPE_INDEXES.remove(i); - continue; - } - if (indexedEngine == engine) { - if (cached.revision() == revision) { - return cached.index(); - } - SCOPE_INDEXES.remove(i); - break; - } - } - ScopeIndex index = buildScopeIndex(engine); - SCOPE_INDEXES.add(new CachedScopeIndex(new WeakReference<>(engine), revision, index)); - return index; - } + return engine.getGeneration().state(ScopeIndex.class, StructurePlacementScope::buildScopeIndex); } private static ScopeIndex buildScopeIndex(Engine engine) { @@ -81,68 +74,42 @@ public final class StructurePlacementScope { caveBiome = true; } else { for (IrisBiome candidate : allBiomes) { - KList structures = candidate.getStructures(); - if (structures == null || structures.isEmpty()) { + List structures = placementsOf(candidate); + if (structures.isEmpty()) { continue; } biome = true; - for (IrisStructurePlacement placement : structures) { - if (placement != null && placement.resolvedAnchor().isCave()) { - caveBiome = true; - break; - } - } + caveBiome |= structures.stream().anyMatch(placement -> placement.resolvedAnchor().isCave()); } } boolean region = false; if (engine.getDimension() != null) { KList allRegions = engine.getDimension().getAllRegions(engine); - if (allRegions == null) { - region = true; - } else { - for (IrisRegion candidate : allRegions) { - if (candidate.getStructures() != null && !candidate.getStructures().isEmpty()) { - region = true; - break; - } - } - } + region = allRegions == null + || allRegions.stream().anyMatch(candidate -> !placementsOf(candidate).isEmpty()); } - boolean dimension = engine.getDimension() != null - && engine.getDimension().getStructures() != null - && !engine.getDimension().getStructures().isEmpty(); + boolean dimension = !placementsOf(engine.getDimension()).isEmpty(); return new ScopeIndex(biome, caveBiome, region, dimension); } - private static void addUnique(KList destination, - Set seen, - KList source) { - if (source == null) { - return; - } - for (IrisStructurePlacement placement : source) { + private static void addUnique(KList destination, Set seen, + List source) { + for (StructurePlacement placement : source) { if (placement != null && seen.add(placement)) { destination.add(placement); } } } - private static void addCaveUnique(KList destination, - Set seen, - KList source) { - if (source == null) { - return; - } - for (IrisStructurePlacement placement : source) { + private static void addCaveUnique(KList destination, Set seen, + List source) { + for (StructurePlacement placement : source) { if (placement != null && placement.resolvedAnchor().isCave() && seen.add(placement)) { destination.add(placement); } } } - private record CachedScopeIndex(WeakReference engine, int revision, ScopeIndex index) { - } - private record ScopeIndex(boolean biome, boolean caveBiome, boolean region, boolean dimension) { } } diff --git a/src/main/java/art/arcane/iris/engine/framework/StructureReachability.java b/src/main/java/art/arcane/iris/engine/framework/StructureReachability.java deleted file mode 100644 index 15910aa36..000000000 --- a/src/main/java/art/arcane/iris/engine/framework/StructureReachability.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.framework; - -import art.arcane.iris.engine.object.world.IrisWorld; -import art.arcane.iris.spi.IrisPlatforms; -import art.arcane.volmlib.util.collection.KList; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; - -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Locale; -import java.util.Objects; -import java.util.Set; - -/** - * Determines which vanilla/datapack structures can ever generate in a world, using the same biome - * gate vanilla applies: a structure is reachable when its biome filter intersects the set of vanilla - * biomes the pack actually produces (its {@code possibleBiomes}). Structures whose required biomes are - * never produced cannot generate and must not be scanned for by {@code /locate} or {@code /iris find} - * (an unbounded scan for an absent biome is what stalls the server). - * - *

The reachable set is fixed per live engine/world and is rebuilt after hotload. - */ -public final class StructureReachability { - private static final Cache> REACHABLE_CACHE = Caffeine.newBuilder().weakKeys().build(); - - private StructureReachability() { - } - - public static Set reachableKeys(Engine engine) { - Engine activeEngine = Objects.requireNonNull(engine, "Structure reachability requires an engine"); - if (activeEngine.getData() == null) { - throw new IllegalStateException("Structure reachability requires a bound pack data loader"); - } - return REACHABLE_CACHE.get(activeEngine, ignored -> build(activeEngine)); - } - - public static boolean isReachable(Engine engine, String structureKey) { - String normalizedStructureKey = normalizeStructureKey(structureKey); - return reachableKeys(engine).contains(normalizedStructureKey); - } - - public static void invalidate(Engine engine) { - if (engine == null) { - return; - } - REACHABLE_CACHE.invalidate(engine); - } - - private static Set build(Engine engine) { - IrisWorld world = engine.getWorld(); - if (world == null) { - throw new IllegalStateException("Structure reachability requires a bound Iris world"); - } - if (world.platformWorld() == null) { - throw new IllegalStateException("Structure reachability requires a bound platform world"); - } - Set reachable = new LinkedHashSet<>(); - for (String key : IrisPlatforms.get().structureHooks().reachableStructureKeys(world.platformWorld())) { - if (key == null || key.isBlank()) { - throw new IllegalStateException("Platform structure reachability returned a blank registry key"); - } - reachable.add(key.toLowerCase(Locale.ROOT)); - } - return Collections.unmodifiableSet(reachable); - } - - /** - * The vanilla biome keys (e.g. {@code minecraft:taiga}) from a structure's filter that the pack - * does not produce. An empty list means the structure is reachable. Used by the structure verify - * diagnostic to explain why a structure cannot generate. - */ - public static KList missingBiomeKeys(Engine engine, String structureKey) { - KList missing = new KList<>(); - Engine activeEngine = Objects.requireNonNull(engine, "Structure biome diagnostics require an engine"); - String normalizedStructureKey = normalizeStructureKey(structureKey); - IrisWorld world = activeEngine.getWorld(); - if (world == null) { - throw new IllegalStateException("Structure biome diagnostics require a bound Iris world"); - } - if (world.platformWorld() == null) { - throw new IllegalStateException("Structure biome diagnostics require a bound platform world"); - } - Set possible = new LinkedHashSet<>(); - for (String key : IrisPlatforms.get().structureHooks().possibleBiomeKeys(world.platformWorld())) { - if (key == null || key.isBlank()) { - throw new IllegalStateException("Platform structure biome query returned a blank possible-biome key"); - } - possible.add(key.toLowerCase(Locale.ROOT)); - } - for (String biomeKey : IrisPlatforms.get().structureHooks().structureBiomeKeys(normalizedStructureKey)) { - if (biomeKey == null || biomeKey.isBlank()) { - throw new IllegalStateException("Platform structure biome query returned a blank required-biome key for " - + normalizedStructureKey); - } - if (!possible.contains(biomeKey.toLowerCase(Locale.ROOT))) { - missing.add(biomeKey); - } - } - return missing; - } - - private static String normalizeStructureKey(String structureKey) { - if (structureKey == null || structureKey.isBlank()) { - throw new IllegalArgumentException("Registered structure key must not be blank"); - } - return structureKey.trim().toLowerCase(Locale.ROOT); - } -} diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java b/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java index a7d215973..fd4680bfd 100644 --- a/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java +++ b/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java @@ -18,6 +18,7 @@ package art.arcane.iris.engine.framework.structure; +import art.arcane.iris.builtin.RegistryKeyFamily; import art.arcane.iris.builtin.structure.StructureAdjustment; import art.arcane.iris.builtin.structure.StructureSetFrequency; import art.arcane.iris.builtin.structure.StructureSettings; @@ -34,7 +35,7 @@ import java.util.Optional; * What a dimension's {@link StructureSettings} say about the platform's own structures: which ones it disables, how * the starts of the others are adjusted, and how the platform sets them up. Keys match ignoring case and surrounding * space; a family pattern also matches the keys it starts at a namespace, slash or underscore boundary - * ({@link #matchesKey}). + * ({@link RegistryKeyFamily}). */ public final class ImportedStructures { private final StructureSettings settings; @@ -55,7 +56,7 @@ public final class ImportedStructures { if (normalizedKey.isEmpty()) { return false; } - return settings.disabled().stream().anyMatch(pattern -> matchesKey(pattern, key)) + return settings.disabled().stream().anyMatch(pattern -> RegistryKeyFamily.matches(pattern, key)) || settings.disabledExact().stream().map(ImportedStructures::normalize) .anyMatch(exact -> !exact.isEmpty() && exact.equals(normalizedKey)); } @@ -99,33 +100,8 @@ public final class ImportedStructures { } } - /** - * Whether the family pattern {@code pattern} matches the structure {@code key}: equal keys, or a pattern the key - * starts with that ends in, or is followed in the key by, {@code :}, {@code /} or {@code _}. So - * {@code minecraft:village} matches {@code minecraft:village_plains} and {@code nova_structures:} a whole namespace. - */ - public static boolean matchesKey(String pattern, String key) { - if (pattern == null || key == null) { - return false; - } - String normalizedPattern = normalize(pattern); - String normalizedKey = normalize(key); - if (normalizedPattern.isEmpty() || !normalizedKey.startsWith(normalizedPattern)) { - return false; - } - if (normalizedKey.length() == normalizedPattern.length()) { - return true; - } - char patternEnd = normalizedPattern.charAt(normalizedPattern.length() - 1); - if (patternEnd == ':' || patternEnd == '/' || patternEnd == '_') { - return true; - } - char boundary = normalizedKey.charAt(normalizedPattern.length()); - return boundary == '/' || boundary == '_'; - } - private static boolean matchesAny(List patterns, String key) { - return patterns.stream().anyMatch(pattern -> matchesKey(pattern, key)); + return patterns.stream().anyMatch(pattern -> RegistryKeyFamily.matches(pattern, key)); } private static NativeStructureFit asAdjustment(StructureAdjustment entry) { diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/NativeStartPlanner.java b/src/main/java/art/arcane/iris/engine/framework/structure/NativeStartPlanner.java index bc21cf3d7..c5f273b39 100644 --- a/src/main/java/art/arcane/iris/engine/framework/structure/NativeStartPlanner.java +++ b/src/main/java/art/arcane/iris/engine/framework/structure/NativeStartPlanner.java @@ -21,10 +21,9 @@ package art.arcane.iris.engine.framework.structure; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.StructurePlacementGrid; import art.arcane.iris.engine.framework.StructurePlacementScope; -import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; -import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure; -import art.arcane.volmlib.util.collection.KList; +import art.arcane.iris.builtin.structure.StructureAnchorMode; +import art.arcane.iris.builtin.structure.StructurePlacement; +import art.arcane.iris.builtin.structure.NativeStructureSource; import art.arcane.volmlib.util.math.RNG; import java.util.LinkedHashMap; @@ -46,17 +45,17 @@ public final class NativeStartPlanner { } /** One start a {@code nativeStructures} placement makes: the placement, its chosen source and world base Y. */ - public record Plan(IrisStructurePlacement placement, IrisNativeStructure source, int chunkX, int chunkZ, int baseY) { + public record Plan(StructurePlacement placement, NativeStructureSource source, int chunkX, int chunkZ, int baseY) { } public static List plansAt(Engine engine, int chunkX, int chunkZ) { Map plansByStructure = new LinkedHashMap<>(); - for (IrisStructurePlacement placement : StructurePlacementScope.placementsAt(engine, chunkX, chunkZ)) { + for (StructurePlacement placement : StructurePlacementScope.placementsAt(engine, chunkX, chunkZ)) { Plan plan = planAt(engine, placement, chunkX, chunkZ); if (plan == null) { continue; } - String structureKey = normalize(plan.source().getStructure()); + String structureKey = normalize(plan.source().structure()); Plan current = plansByStructure.get(structureKey); if (current == null || comparePlacementPriority(plan.placement(), current.placement()) < 0) { plansByStructure.put(structureKey, plan); @@ -65,7 +64,7 @@ public final class NativeStartPlanner { return List.copyOf(plansByStructure.values()); } - public static Plan planAt(Engine engine, IrisStructurePlacement placement, int chunkX, int chunkZ) { + public static Plan planAt(Engine engine, StructurePlacement placement, int chunkX, int chunkZ) { validateBackend(placement); if (!placement.hasNativeStructures()) { return null; @@ -80,7 +79,7 @@ public final class NativeStartPlanner { } RNG placementRng = StructurePlacementGrid.placementRng( placement, chunkX, chunkZ, mantleSeed).nextParallelRNG(NATIVE_SELECTION_DOMAIN); - IrisNativeStructure source = selectSource(placement.getNativeStructures(), placementRng); + NativeStructureSource source = selectSource(placement.nativeStructures(), placementRng); Integer baseY = resolveBaseY(activeEngine, placement, chunkX, chunkZ, placementRng); if (baseY == null) { return null; @@ -88,7 +87,7 @@ public final class NativeStartPlanner { return new Plan(placement, source, chunkX, chunkZ, baseY); } - public static void validateBackend(IrisStructurePlacement placement) { + public static void validateBackend(StructurePlacement placement) { if (placement == null) { throw new IllegalStateException("Structure placement must not be null"); } @@ -98,8 +97,7 @@ public final class NativeStartPlanner { throw new IllegalStateException("Structure placement must declare exactly one backend: " + "structures or nativeStructures"); } - if (nativeStructure && placement.getAnchor() != null - && placement.getAnchor() != IrisStructureAnchorMode.LEGACY) { + if (nativeStructure && placement.anchor() != StructureAnchorMode.LEGACY) { throw new IllegalStateException("Native structure placements do not support the Iris anchor field"); } } @@ -108,26 +106,26 @@ public final class NativeStartPlanner { return engine.getHeight(blockX, blockZ, true) < engine.getDimension().getFluidHeight(); } - static IrisNativeStructure selectSource(KList sources, RNG rng) { + static NativeStructureSource selectSource(List sources, RNG rng) { Objects.requireNonNull(sources, "Native structure sources must not be null"); Objects.requireNonNull(rng, "Native structure selection requires an RNG"); long totalWeight = 0L; - for (IrisNativeStructure source : sources) { - if (source == null || source.getStructure() == null || source.getStructure().isBlank()) { + for (NativeStructureSource source : sources) { + if (source == null || source.structure() == null || source.structure().isBlank()) { throw new IllegalStateException("Native structure placement contains a blank source"); } - if (source.getWeight() < 1) { - throw new IllegalStateException("Native structure source '" + source.getStructure() - + "' has invalid weight " + source.getWeight()); + if (source.weight() < 1) { + throw new IllegalStateException("Native structure source '" + source.structure() + + "' has invalid weight " + source.weight()); } - totalWeight = Math.addExact(totalWeight, source.getWeight()); + totalWeight = Math.addExact(totalWeight, source.weight()); } if (totalWeight > Integer.MAX_VALUE) { throw new IllegalStateException("Native structure source weights exceed " + Integer.MAX_VALUE); } int roll = rng.nextInt((int) totalWeight); - for (IrisNativeStructure source : sources) { - roll -= source.getWeight(); + for (NativeStructureSource source : sources) { + roll -= source.weight(); if (roll < 0) { return source; } @@ -135,7 +133,7 @@ public final class NativeStartPlanner { throw new IllegalStateException("Native structure source selection produced no result"); } - private static Integer resolveBaseY(Engine engine, IrisStructurePlacement placement, + private static Integer resolveBaseY(Engine engine, StructurePlacement placement, int chunkX, int chunkZ, RNG rng) { int worldMin = engine.getMinHeight() + 1; int worldMax = engine.getMinHeight() + engine.getHeight() - 1; @@ -144,25 +142,25 @@ public final class NativeStartPlanner { } int blockX = (chunkX << 4) + 8; int blockZ = (chunkZ << 4) + 8; - if (!placement.isUnderwater() && isSubmerged(engine, blockX, blockZ)) { + if (!placement.underwater() && isSubmerged(engine, blockX, blockZ)) { return null; } - if (!placement.isUnderground()) { + if (!placement.underground()) { int surfaceY = engine.getHeight(blockX, blockZ, true) + engine.getMinHeight(); - if (surfaceY < placement.getMinHeight() || surfaceY > placement.getMaxHeight()) { + if (surfaceY < placement.minHeight() || surfaceY > placement.maxHeight()) { return null; } return surfaceY; } - int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight())); - int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight())); + int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight())); + int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight())); if (bandMin > bandMax) { return null; } return bandMin == bandMax ? bandMin : bandMin + rng.nextInt((bandMax - bandMin) + 1); } - private static int comparePlacementPriority(IrisStructurePlacement left, IrisStructurePlacement right) { + private static int comparePlacementPriority(StructurePlacement left, StructurePlacement right) { long leftIdentity = StructurePlacementGrid.placementIdentity(left); long rightIdentity = StructurePlacementGrid.placementIdentity(right); return Long.compareUnsigned(leftIdentity, rightIdentity); diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/StructureLocating.java b/src/main/java/art/arcane/iris/engine/framework/structure/StructureLocating.java index 3f45eb15b..a3842ec4f 100644 --- a/src/main/java/art/arcane/iris/engine/framework/structure/StructureLocating.java +++ b/src/main/java/art/arcane/iris/engine/framework/structure/StructureLocating.java @@ -32,8 +32,9 @@ import java.util.Set; /** * How {@code iris:structure} lets Iris find its structures: the structures of the pack's {@code structures} folder, * the ones the world's placements assemble from jigsaw pools, and their nearest start, searched with - * {@link IrisStructureLocator}. Vanilla structures that Iris places through native placements are not among them; the - * host's vanilla structure handling finds those. + * {@link IrisStructureLocator}. The keys it places also name the platform structures its native placements start and + * the ones its structures stand in for; it locates those too. The platform's own locate of a natively started + * structure goes through {@link StructureVanillaStructures#locateStart} instead. */ public final class StructureLocating implements StructureLocator { @Override @@ -46,6 +47,11 @@ public final class StructureLocating implements StructureLocator { return IrisStructureLocator.locatableEditableKeys(engine(world)); } + @Override + public Set placed(PackWorld world) { + return IrisStructureLocator.placedKeysAndAliases(engine(world)); + } + @Override public LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks) { Engine engine = engine(world); diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/StructureVanillaStructures.java b/src/main/java/art/arcane/iris/engine/framework/structure/StructureVanillaStructures.java index ccaf5a5a4..b19815e41 100644 --- a/src/main/java/art/arcane/iris/engine/framework/structure/StructureVanillaStructures.java +++ b/src/main/java/art/arcane/iris/engine/framework/structure/StructureVanillaStructures.java @@ -25,9 +25,10 @@ import art.arcane.iris.engine.framework.IrisStructureLocator; import art.arcane.iris.engine.framework.StructurePlacementGrid; import art.arcane.iris.engine.framework.structure.fit.StartLayouts; import art.arcane.iris.engine.framework.structure.fit.StructureFitting; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; -import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression; +import art.arcane.iris.builtin.structure.StructurePlacement; +import art.arcane.iris.builtin.structure.NativeStructureSuppression; import com.volmit.resource.ResourceId; +import com.volmit.service.LocateResult; import com.volmit.service.VanillaStructures; import com.volmit.vanilla.PlatformStart; import com.volmit.vanilla.StartMemo; @@ -38,16 +39,22 @@ import com.volmit.vanilla.VanillaStructureRule; import com.volmit.vanilla.VanillaStructureSetup; import com.volmit.vanilla.VanillaStructureStart; import com.volmit.vanilla.VanillaStructureStartContext; +import com.volmit.world.BlockPosition; +import com.volmit.world.PackWorld; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Optional; +import java.util.Set; /** * What {@code iris:structure} says about the platform's own structures. The dimension's {@code importedStructures} * settings ({@link ImportedStructures}) disable, move, fit and set them up; the pack's structure placements replace * them ({@code vanillaSource} with native suppression), place them alongside ({@link IrisStructureLocator#isPlaced}), * start them where their {@code nativeStructures} grids say ({@link NativeStartPlanner}) and fit those starts the way - * the placement says, which their memo carries to every chunk they reach ({@link StructureFitting}). + * the placement says, which their memo carries to every chunk they reach ({@link StructureFitting}). It names the + * structures its native placements start and finds their starts for the platform's own locate. */ public final class StructureVanillaStructures implements VanillaStructures { /** @@ -68,7 +75,7 @@ public final class StructureVanillaStructures implements VanillaStructures { @Override public List starts(int chunkX, int chunkZ, VanillaStructureStartContext context) { - Engine engine = IrisPackWorld.of(context.world()).engine(); + Engine engine = engine(context.world()); return NativeStartPlanner.plansAt(engine, chunkX, chunkZ).stream() .map(plan -> start(plan, engine.getMinHeight())) .toList(); @@ -103,23 +110,56 @@ public final class StructureVanillaStructures implements VanillaStructures { return ImportedStructures.of(context.settings()).setup(); } + @Override + public Set startedStructures(PackWorld world) { + return structureIds(IrisStructureLocator.nativeKeys(engine(world))); + } + + @Override + public Set locatableStarts(PackWorld world) { + return structureIds(IrisStructureLocator.locatableNativeKeys(engine(world))); + } + + /** Searches the rings of the placements that start {@code structure} natively, as the platform's own locate does. */ + @Override + public LocateResult locateStart(PackWorld world, ResourceId structure, int fromX, int fromZ, int maxRings, + ChunkFilter accepts) { + Engine engine = engine(world); + IrisStructureLocator.LocateResult result = IrisStructureLocator.locateInPlacementRings( + engine, structure.toString(), fromX, fromZ, maxRings, accepts::accepts); + return switch (result.status()) { + case FOUND -> LocateResult.found(new BlockPosition(result.originX(), result.baseY() - engine.getMinHeight(), result.originZ())); + case NOT_FOUND -> LocateResult.NOT_FOUND; + case SEARCH_LIMIT_REACHED -> LocateResult.SEARCH_LIMIT_REACHED; + }; + } + + private static Engine engine(PackWorld world) { + return IrisPackWorld.of(world).engine(); + } + + private static Set structureIds(Set keys) { + Set ids = new LinkedHashSet<>(); + for (String key : keys) { + ids.add(ResourceId.parse(key.toLowerCase(Locale.ROOT))); + } + return ids; + } + /** {@code plan} as the start the platform generates: heights above the bottom, the placement's identity and fit. */ static VanillaStructureStart start(NativeStartPlanner.Plan plan, int minHeight) { - IrisStructurePlacement placement = plan.placement(); - NativeStructureFit fit = new NativeStructureFit(0, null, false, placement.getStilt(), placement.resolvedTerrain()); - VanillaStructureStart start = VanillaStructureStart.at(ResourceId.parse(plan.source().getStructure()), + StructurePlacement placement = plan.placement(); + NativeStructureFit fit = new NativeStructureFit(0, null, false, placement.stilt().orElse(null), placement.resolvedTerrain()); + VanillaStructureStart start = VanillaStructureStart.at(ResourceId.parse(plan.source().structure()), plan.chunkX(), plan.chunkZ(), plan.baseY() - minHeight) .withIdentity(StructurePlacementGrid.placementIdentity(placement)) .withMemo(fit.memo()); - if (placement.isUnderground()) { + if (placement.underground()) { start = start.underground(); } - if (placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE) { + if (placement.nativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE) { start = start.replacingPlatformStart(); } - if (plan.source().getJigsaw() != null) { - start = start.withJigsaw(plan.source().getJigsaw()); - } - return start; + return plan.source().jigsaw().map(start::withJigsaw).orElse(start); } } diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/fit/FitStart.java b/src/main/java/art/arcane/iris/engine/framework/structure/fit/FitStart.java index 07c9187ca..bad24142e 100644 --- a/src/main/java/art/arcane/iris/engine/framework/structure/fit/FitStart.java +++ b/src/main/java/art/arcane/iris/engine/framework/structure/fit/FitStart.java @@ -20,8 +20,8 @@ package art.arcane.iris.engine.framework.structure.fit; import art.arcane.iris.builtin.structure.StructureTerrain; import art.arcane.iris.engine.framework.structure.NativeStructureFit; +import com.volmit.vanilla.DecorationStep; import com.volmit.vanilla.StructureFit; -import com.volmit.vanilla.StructureStep; import com.volmit.vanilla.TerrainAdaptation; import java.util.ArrayList; @@ -63,7 +63,7 @@ final class FitStart { return start.adaptation(); } - StructureStep step() { + DecorationStep step() { return start.step(); } diff --git a/src/main/java/art/arcane/iris/engine/framework/structure/fit/SurfaceFitting.java b/src/main/java/art/arcane/iris/engine/framework/structure/fit/SurfaceFitting.java index baa1d1ff0..504a2cc20 100644 --- a/src/main/java/art/arcane/iris/engine/framework/structure/fit/SurfaceFitting.java +++ b/src/main/java/art/arcane/iris/engine/framework/structure/fit/SurfaceFitting.java @@ -22,7 +22,7 @@ import art.arcane.iris.builtin.structure.StructureTerrainMode; import art.arcane.iris.engine.object.placement.IrisObjectVacuum; import com.volmit.ModuleLog; import com.volmit.block.BlockState; -import com.volmit.vanilla.StructureStep; +import com.volmit.vanilla.DecorationStep; import com.volmit.vanilla.TemplateCells; import com.volmit.vanilla.TerrainAdaptation; import com.volmit.world.BlockPosition; @@ -114,8 +114,8 @@ final class SurfaceFitting { } } - static boolean shouldPrepareSurfaceTerrain(TerrainAdaptation adaptation, StructureStep step) { - return step == StructureStep.SURFACE_STRUCTURES + static boolean shouldPrepareSurfaceTerrain(TerrainAdaptation adaptation, DecorationStep step) { + return step == DecorationStep.SURFACE_STRUCTURES && (adaptation == TerrainAdaptation.BEARD_THIN || adaptation == TerrainAdaptation.BEARD_BOX); } diff --git a/src/main/java/art/arcane/iris/engine/framework/vanillafeatures/ImportedFeatures.java b/src/main/java/art/arcane/iris/engine/framework/vanillafeatures/ImportedFeatures.java new file mode 100644 index 000000000..0cafe0ba5 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/framework/vanillafeatures/ImportedFeatures.java @@ -0,0 +1,67 @@ +/* + * 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.vanillafeatures; + +import art.arcane.iris.builtin.RegistryKeyFamily; +import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings; +import com.volmit.config.FeatureSettings.Entry; +import com.volmit.resource.ResourceId; +import com.volmit.service.VanillaFeatures; +import com.volmit.vanilla.DecorationStep; +import com.volmit.world.PackWorld; + +import java.util.List; +import java.util.Optional; + +/** + * What a dimension's {@link ImportedFeaturesSettings} say about the platform's own placed features: whether they run, + * and which decoration steps and features they leave out. A dimension without the settings runs none. + */ +public final class ImportedFeatures implements VanillaFeatures { + private static final ImportedFeaturesSettings NONE = new ImportedFeaturesSettings(); + + @Override + public boolean generates(PackWorld world) { + return settings(world).enabled(); + } + + /** A step the API does not name is allowed unless the dimension narrowed generation to listed steps. */ + @Override + public boolean generatesStep(PackWorld world, Optional step) { + ImportedFeaturesSettings settings = settings(world); + if (step.isEmpty()) { + return settings.steps().isEmpty(); + } + if (!settings.steps().isEmpty() && !settings.steps().contains(step.get())) { + return false; + } + return !settings.disabledSteps().contains(step.get()); + } + + @Override + public boolean generatesFeature(PackWorld world, ResourceId feature) { + String key = feature.toString(); + return settings(world).disabled().stream().noneMatch(pattern -> RegistryKeyFamily.matches(pattern, key)); + } + + private static ImportedFeaturesSettings settings(PackWorld world) { + List> declared = world.settings().declared(ImportedFeaturesSettings.class); + return declared.isEmpty() ? NONE : declared.getFirst().value(); + } +} diff --git a/src/main/java/art/arcane/iris/engine/framework/vanillafeatures/VanillaFeaturesModule.java b/src/main/java/art/arcane/iris/engine/framework/vanillafeatures/VanillaFeaturesModule.java new file mode 100644 index 000000000..035b15463 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/framework/vanillafeatures/VanillaFeaturesModule.java @@ -0,0 +1,51 @@ +/* + * 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.vanillafeatures; + +import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings; +import com.volmit.FeatureRegistry; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.service.VanillaFeatures; +import com.volmit.stage.StageGraph; + +/** + * Module {@code iris:vanilla-features}: whether the platform's own placed features (ores, trees, plants, springs) run + * over a dimension's terrain, and which steps and features they leave out, decided from the dimension's + * {@code importedFeatures} settings and answered through {@link VanillaFeatures} ({@link ImportedFeatures}). The + * platform runs the feature pass itself; the module has no stages. + */ +public final class VanillaFeaturesModule implements IrisModule { + private static final String VERSION = "built-in"; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:vanilla-features", "Vanilla features", VERSION); + } + + @Override + public void install(StageGraph graph) { + } + + @Override + public void register(FeatureRegistry registry) { + registry.registerSettings(ImportedFeaturesSettings.class); + registry.registerService(VanillaFeatures.class, new ImportedFeatures()); + } +} 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 e97c60212..f614d0ef0 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 @@ -19,14 +19,11 @@ package art.arcane.iris.engine.mantle.components; import art.arcane.iris.builtin.IrisStages; +import art.arcane.iris.builtin.structure.StructurePlacementSettings; import art.arcane.iris.builtin.structure.StructureSettings; -import art.arcane.iris.builtin.structure.StructureStilts; -import art.arcane.iris.builtin.structure.StructureTerrain; import art.arcane.iris.core.modules.IrisMantleChunk; import art.arcane.iris.core.modules.IrisPackSettings; -import art.arcane.iris.core.modules.IrisPackWorld; import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.IrisStructureLocator; import art.arcane.iris.engine.framework.structure.StructureLocating; import art.arcane.iris.engine.framework.structure.StructureResources; import art.arcane.iris.engine.framework.structure.StructureValidator; @@ -34,15 +31,12 @@ import art.arcane.iris.engine.framework.structure.StructureVanillaStructures; import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; -import com.volmit.ModuleLifecycle; import com.volmit.ModuleLog; import com.volmit.config.PackSettings; import com.volmit.service.StructureLocator; import com.volmit.service.VanillaStructures; import com.volmit.stage.MantleStageContext; import com.volmit.stage.StageGraph; -import com.volmit.vanilla.JigsawOverrides; -import com.volmit.world.PackWorld; /** * Module {@code iris:structure}: Iris structures, written into the mantle after objects, whose trees they clear @@ -52,16 +46,16 @@ import com.volmit.world.PackWorld; * The module owns the pack's structures, jigsaw pools and jigsaw pieces as resource kinds * ({@link StructureResources}), read from the folders packs have always used, and checks them with * {@link StructureValidator} wherever Iris validates a pack. It lets Iris find its structures through - * {@link StructureLocating}, and forgets a world's structure index when the world stops, which includes every reload of - * the pack's structure files. + * {@link StructureLocating}; a world's structure index lives in the world's state, so a reload of the pack's structure + * files, which starts a new world, builds it again. *

* It decides over the platform's own structures through its {@link VanillaStructures} provider * ({@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. It describes the fit settings Iris's structure - * placements hold. + * {@code nativeStructures} grids say and fit them into the terrain. The pack's structure placements are its + * {@code "structures"} settings ({@link StructurePlacementSettings}) of the dimension, its regions and biomes. */ -public final class StructureModule implements IrisModule, ModuleLifecycle { +public final class StructureModule implements IrisModule { private static final String VERSION = "built-in"; private ModuleLog log; @@ -81,20 +75,11 @@ public final class StructureModule implements IrisModule, ModuleLifecycle { public void register(FeatureRegistry registry) { log = registry.log(); registry.registerSettings(StructureSettings.class); + registry.registerSettings(StructurePlacementSettings.class); StructureResources.kinds().forEach(registry::registerResourceKind); registry.registerValidator(new StructureValidator()); registry.registerService(StructureLocator.class, new StructureLocating()); - registry.registerLifecycle(this); registry.registerService(VanillaStructures.class, new StructureVanillaStructures()); - registry.registerHeldType(StructureTerrain.class); - registry.registerHeldType(StructureStilts.class); - registry.registerHeldType(JigsawOverrides.class); - } - - /** The structure index is still kept per engine rather than in the world's state, so a stopping world drops it. */ - @Override - public void worldStopped(PackWorld world) { - IrisStructureLocator.invalidate(IrisPackWorld.of(world).engine()); } private static void place(MantleStageContext context) { diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/StructurePlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/StructurePlacing.java index f461f23f8..c0acf37e2 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/StructurePlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/StructurePlacing.java @@ -37,7 +37,7 @@ import art.arcane.iris.engine.object.prefab.IrisObject; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.engine.object.structure.IrisStructure; import art.arcane.iris.builtin.structure.StructureCarveShape; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; +import art.arcane.iris.builtin.structure.StructurePlacement; import art.arcane.iris.builtin.structure.StructureStilts; import com.volmit.ModuleLog; import com.volmit.block.PaletteSampler; @@ -61,6 +61,7 @@ import it.unimi.dsi.fastutil.longs.Long2IntMap; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -82,7 +83,7 @@ public class StructurePlacing { /** Places what originates in the chunk at chunk coordinates {@code x}, {@code z} into {@code writer}. */ @ChunkCoordinates public void place(MantleWriter writer, int x, int z, ChunkContext context) { - for (IrisStructurePlacement placement : StructurePlacementScope.placementsAt( + for (StructurePlacement placement : StructurePlacementScope.placementsAt( engine, x, z)) { if (!placement.hasIrisStructures()) { continue; @@ -92,7 +93,7 @@ public class StructurePlacing { } @ChunkCoordinates - private void placeFromPlacement(MantleWriter writer, IrisStructurePlacement placement, int cx, int cz) { + private void placeFromPlacement(MantleWriter writer, StructurePlacement placement, int cx, int cz) { IrisStructureLocator.ResolvedPlacement resolved = IrisStructureLocator.resolvePlacement( engine, placement, cx, cz); if (resolved == null) { @@ -101,8 +102,8 @@ public class StructurePlacing { boolean trace = IrisSettings.get().getGeneral().isDebug(); if (trace) { - log.debug("[StructTrace] ORIGIN chunk=" + cx + "," + cz + " structures=" + placement.getStructures() - + " anchor=" + placement.resolvedAnchor() + " band=" + placement.getMinHeight() + ".." + placement.getMaxHeight()); + log.debug("[StructTrace] ORIGIN chunk=" + cx + "," + cz + " structures=" + placement.structures() + + " anchor=" + placement.resolvedAnchor() + " band=" + placement.minHeight() + ".." + placement.maxHeight()); } String key = resolved.structureKey(); @@ -135,7 +136,7 @@ public class StructurePlacing { ObjectPlaceMode mode = structure.getPlaceMode(); int failedPieces = 0; - StructureStilts stilt = placement.getStilt(); + StructureStilts stilt = placement.stilt().orElse(null); Long2IntOpenHashMap foundationColumns = stilt == null ? null : new Long2IntOpenHashMap(); boolean supportNonOccluding = stilt != null && stilt.supportNonOccluding(); @@ -590,19 +591,19 @@ public class StructurePlacing { int maxBlocks = 0; for (IrisRegion region : dimension.getAllRegions(engine)) { - maxBlocks = Math.max(maxBlocks, maxBlocksFrom(region.getStructures())); + maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(region))); } for (IrisBiome biome : dimension.getReachableBiomes(engine)) { - maxBlocks = Math.max(maxBlocks, maxBlocksFrom(biome.getStructures())); + maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(biome))); } - maxBlocks = Math.max(maxBlocks, maxBlocksFrom(dimension.getStructures())); + maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(dimension))); return maxBlocks; } - private int maxBlocksFrom(KList placements) { + private int maxBlocksFrom(List placements) { int max = 0; - for (IrisStructurePlacement placement : placements) { + for (StructurePlacement placement : placements) { if (!placement.hasIrisStructures()) { continue; } @@ -610,7 +611,7 @@ public class StructurePlacing { int carvePadding = terrain.resolvedMode() == StructureTerrainMode.FORCE_CARVE || terrain.resolvedMode() == StructureTerrainMode.BORE ? Math.max(0, terrain.horizontalPadding()) : 0; - for (String key : placement.getStructures()) { + for (String key : placement.structures()) { IrisStructure structure = StructureResources.structure(engine.getData(), key); if (structure != null) { max = Math.max(max, Math.max(1, structure.getMaxSizeChunks()) * 16 + carvePadding); diff --git a/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListStructure.java b/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListStructure.java deleted file mode 100644 index 8f985907c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListStructure.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.annotations; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Retention(RUNTIME) -@Target({PARAMETER, TYPE, FIELD}) -public @interface RegistryListStructure { - -} diff --git a/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorationStep.java b/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorationStep.java deleted file mode 100644 index a2ee1d3ab..000000000 --- a/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorationStep.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.object.decoration; - -import art.arcane.iris.engine.object.annotations.Desc; - -import java.util.Locale; - -/** - * Pure-JVM mirror of Minecraft's decoration generation steps, in registry (ordinal) order. The ordinals and - * serialized names match {@code GenerationStep.Decoration} on MC 26.2 so a platform can convert either way - * without core depending on a Minecraft type. Verified against MC 26.2 GenerationStep.Decoration. - */ -@Desc("A vanilla decoration generation step. Placed features are grouped into these steps and run in this order.") -public enum IrisDecorationStep { - @Desc("Raw generation - the earliest step, before lakes.") - RAW_GENERATION("raw_generation"), - - @Desc("Lakes.") - LAKES("lakes"), - - @Desc("Local modifications such as amethyst geodes, icebergs and dripstone clusters.") - LOCAL_MODIFICATIONS("local_modifications"), - - @Desc("Underground structure features (not the structure system - features tagged as underground structures).") - UNDERGROUND_STRUCTURES("underground_structures"), - - @Desc("Surface structure features.") - SURFACE_STRUCTURES("surface_structures"), - - @Desc("Stronghold step.") - STRONGHOLDS("strongholds"), - - @Desc("Underground ores. This is the step that carries vanilla and mod ore veins.") - UNDERGROUND_ORES("underground_ores"), - - @Desc("Underground decoration such as glow lichen, sculk patches and cave vegetation.") - UNDERGROUND_DECORATION("underground_decoration"), - - @Desc("Fluid springs - the small water and lava spring features.") - FLUID_SPRINGS("fluid_springs"), - - @Desc("Vegetal decoration - trees, grass, flowers, kelp and most surface plant life.") - VEGETAL_DECORATION("vegetal_decoration"), - - @Desc("Top layer modification - freezing and snow placement.") - TOP_LAYER_MODIFICATION("top_layer_modification"); - - private final String serializedName; - - IrisDecorationStep(String serializedName) { - this.serializedName = serializedName; - } - - public String getSerializedName() { - return serializedName; - } - - /** - * Resolves a step by its vanilla ordinal. Returns null when the running Minecraft version declares more - * decoration steps than this enum knows about, which the callers treat as "unknown step, generate it". - */ - public static IrisDecorationStep byOrdinal(int ordinal) { - IrisDecorationStep[] values = values(); - return ordinal < 0 || ordinal >= values.length ? null : values[ordinal]; - } - - public static IrisDecorationStep byKey(String key) { - if (key == null || key.isBlank()) { - return null; - } - String normalized = key.trim().toLowerCase(Locale.ROOT); - for (IrisDecorationStep step : values()) { - if (step.serializedName.equals(normalized) || step.name().toLowerCase(Locale.ROOT).equals(normalized)) { - return step; - } - } - return null; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/decoration/IrisImportedFeatureControl.java b/src/main/java/art/arcane/iris/engine/object/decoration/IrisImportedFeatureControl.java deleted file mode 100644 index 28a572d6c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/decoration/IrisImportedFeatureControl.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.object.decoration; - -import art.arcane.iris.engine.framework.structure.ImportedStructures; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.volmlib.util.collection.KList; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.util.Objects; - -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Controls native vanilla, mod, and ingested datapack PLACED FEATURE generation for this dimension (set as the dimension's 'importedFeatures' field). Placed features are ores, trees, plants, springs, geodes and every other decoration entry a biome declares. This is OFF by default: with 'enabled' false Iris generates exactly the terrain it always has and no native feature runs. With it true, every placed feature the biome's vanilla derivative declares runs over Iris terrain, in vanilla step order, on the same worldgen thread vanilla uses. Carvers are never imported - Iris has no NoiseGeneratorSettings, so there is nothing for a carver to carve against. Family matching on 'disabled' uses namespace, slash, or underscore boundaries, so 'minecraft:ore' covers every vanilla ore feature without matching unrelated names.") -@Data -public class IrisImportedFeatureControl { - @Desc("Master switch. False (the default) means no native placed feature generates and chunk output is identical to a pack without this block at all. True runs the vanilla decoration feature pass over Iris terrain.") - private boolean enabled = false; - - @ArrayType(type = String.class, min = 1) - @Desc("Placed feature keys to deny explicitly, e.g. 'minecraft:ore_diamond'. A namespace:path prefix also matches, so 'minecraft:ore' denies every vanilla ore and 'minecraft:trees' denies every tree placement. Every key not matched here generates while 'enabled' is true.") - private KList disabled = new KList<>(); - - @ArrayType(type = IrisDecorationStep.class, min = 1) - @Desc("Restrict feature generation to these decoration steps only. Empty (the default) means every step is eligible. Use this to import ores without importing vegetation: set it to UNDERGROUND_ORES.") - private KList steps = new KList<>(); - - @ArrayType(type = IrisDecorationStep.class, min = 1) - @Desc("Decoration steps to deny. Applied after 'steps', so a step listed here never generates even if 'steps' allows it. VEGETAL_DECORATION is the usual entry for packs that grow their own trees.") - private KList disabledSteps = new KList<>(); - - /** - * True when this dimension wants the native feature pass at all. Every other accessor on this class is - * meaningless while this is false, and the platform must not build any feature machinery. - */ - public boolean shouldGenerateFeatures() { - return enabled; - } - - public boolean shouldGenerateStep(IrisDecorationStep step) { - if (!enabled) { - return false; - } - KList allowed = Objects.requireNonNull( - steps, "importedFeatures.steps must not be null"); - KList denied = Objects.requireNonNull( - disabledSteps, "importedFeatures.disabledSteps must not be null"); - if (step == null) { - // A step this Iris build does not know about (newer Minecraft): allow it unless the pack - // narrowed generation to an explicit step list. - return allowed.isEmpty(); - } - if (!allowed.isEmpty() && !allowed.contains(step)) { - return false; - } - return !denied.contains(step); - } - - public boolean shouldGenerate(String placedFeatureKey) { - return resolve(placedFeatureKey, null) == NativeFeatureGenerationStatus.GENERATE_NATIVE; - } - - /** - * Resolves one placed feature against this control. A null step skips the step gate, which is what the - * key-only query does. - */ - public NativeFeatureGenerationStatus resolve(String placedFeatureKey, IrisDecorationStep step) { - if (!enabled) { - return NativeFeatureGenerationStatus.FEATURES_DISABLED; - } - if (placedFeatureKey == null || placedFeatureKey.isBlank()) { - return NativeFeatureGenerationStatus.INVALID_REGISTRY_KEY; - } - if (step != null && !shouldGenerateStep(step)) { - return NativeFeatureGenerationStatus.STEP_DISABLED; - } - KList deniedKeys = Objects.requireNonNull( - disabled, "importedFeatures.disabled must not be null"); - for (String entry : deniedKeys) { - if (ImportedStructures.matchesKey(entry, placedFeatureKey)) { - return NativeFeatureGenerationStatus.DISABLED_BY_PACK; - } - } - return NativeFeatureGenerationStatus.GENERATE_NATIVE; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructureAnchorMode.java b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructureAnchorMode.java deleted file mode 100644 index b7d17991a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructureAnchorMode.java +++ /dev/null @@ -1,34 +0,0 @@ -package art.arcane.iris.engine.object.structure; - -import art.arcane.iris.engine.object.annotations.Desc; - -@Desc("Selects the vertical environment used to anchor an Iris structure placement.") -public enum IrisStructureAnchorMode { - @Desc("Preserve the historical underground boolean behavior.") - LEGACY, - - @Desc("Anchor to the terrain surface and use minHeight/maxHeight as a surface gate.") - SURFACE, - - @Desc("Choose a deterministic Y inside the minHeight/maxHeight band.") - HEIGHT_BAND, - - @Desc("Anchor in carved space with solid support below.") - CAVE_FLOOR, - - @Desc("Anchor in carved space with solid support above.") - CAVE_CEILING, - - @Desc("Anchor in carved space without nearby floor or ceiling support.") - CAVE_CENTER, - - @Desc("Anchor at any carved-space position.") - CAVE_ANY; - - public boolean isCave() { - return switch (this) { - case CAVE_FLOOR, CAVE_CEILING, CAVE_CENTER, CAVE_ANY -> true; - default -> false; - }; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/vanilla/IrisNativeStructure.java b/src/main/java/art/arcane/iris/engine/object/structure/vanilla/IrisNativeStructure.java deleted file mode 100644 index 357b0002d..000000000 --- a/src/main/java/art/arcane/iris/engine/object/structure/vanilla/IrisNativeStructure.java +++ /dev/null @@ -1,30 +0,0 @@ -package art.arcane.iris.engine.object.structure.vanilla; - -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.MinNumber; -import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure; -import art.arcane.iris.engine.object.annotations.Required; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; -import com.volmit.vanilla.JigsawOverrides; - -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Data -@Desc("A live vanilla, datapack, or modded structure generated by Minecraft at an Iris-controlled placement.") -public class IrisNativeStructure { - @Required - @RegistryListVanillaStructure - @Desc("Registered structure key. The source retains its native generator, pieces, templates, processors, entities, markers, and data.") - private String structure = ""; - - @MinNumber(1) - @Desc("Relative selection weight when a placement offers multiple native structure sources.") - private int weight = 1; - - @Desc("Optional jigsaw-only assembly overrides. Null preserves the complete registered structure definition.") - private JigsawOverrides jigsaw = null; -} diff --git a/src/main/java/art/arcane/iris/engine/object/structure/vanilla/NativeStructureSuppression.java b/src/main/java/art/arcane/iris/engine/object/structure/vanilla/NativeStructureSuppression.java deleted file mode 100644 index 35051cc68..000000000 --- a/src/main/java/art/arcane/iris/engine/object/structure/vanilla/NativeStructureSuppression.java +++ /dev/null @@ -1,12 +0,0 @@ -package art.arcane.iris.engine.object.structure.vanilla; - -import art.arcane.iris.engine.object.annotations.Desc; - -@Desc("Controls whether an Iris structure placement suppresses its imported native source.") -public enum NativeStructureSuppression { - @Desc("Leaves native generation enabled alongside this Iris structure placement.") - NONE, - - @Desc("Suppresses the structure's vanillaSource when used by a validated dimension-level replacement placement.") - REPLACE_SOURCE -} diff --git a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java index 659bec501..3a1a3d934 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java +++ b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java @@ -22,7 +22,6 @@ import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; import art.arcane.iris.engine.object.noise.NoiseStyle; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; import art.arcane.iris.engine.object.value.IRare; import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom; import art.arcane.iris.engine.object.world.dimension.IrisDimension; @@ -146,9 +145,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { private KList objects = new KList<>(); @Desc("Procedural objects (such as trees) iris generates from scratch and places in this biome, instead of loading them from iob files") private IrisProceduralObjects proceduralObjects = new IrisProceduralObjects(); - @ArrayType(min = 1, type = IrisStructurePlacement.class) - @Desc("Structures define jigsaw or vanilla/datapack structures iris will place in this biome") - private KList structures = new KList<>(); @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") private KList generators = new KList().qadd(new IrisBiomeGeneratorLink()); diff --git a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java index 327edb132..cb4d0c812 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java +++ b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java @@ -18,7 +18,6 @@ package art.arcane.iris.engine.object.world.dimension; -import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl; import art.arcane.iris.engine.object.image.IrisImageMap; import art.arcane.iris.engine.object.image.IrisImageMapApplication; import art.arcane.iris.engine.object.image.IrisImageMapBinding; @@ -27,7 +26,6 @@ import art.arcane.iris.engine.object.noise.IrisShapedGeneratorStyle; import art.arcane.iris.engine.object.noise.NoiseStyle; import art.arcane.iris.engine.object.procedural.tree.IrisTreeSettings; import art.arcane.iris.engine.object.runtime.StudioMode; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; import art.arcane.iris.engine.object.value.IrisRange; import art.arcane.iris.engine.object.world.IrisEnvironment; import art.arcane.iris.engine.object.world.IrisWorldBoundary; @@ -237,11 +235,6 @@ public class IrisDimension extends IrisRegistrant { @ArrayType(min = 1, type = IrisShapedGeneratorStyle.class) @Desc("Overlay additional noise on top of the interoplated terrain.") private KList overlayNoise = new KList<>(); - @Desc("Dimension-wide Iris structure placements, independent of biome/region placements") - @ArrayType(type = IrisStructurePlacement.class, min = 1) - private KList structures = new KList<>(); - @Desc("Controls native vanilla, mod, and ingested datapack PLACED FEATURE generation (ores, trees, plants, springs, geodes) for this dimension. Disabled by default: leaving this out generates exactly the terrain Iris always has. Set 'enabled' true to run the vanilla decoration feature pass over Iris terrain. Carvers are never imported.") - private IrisImportedFeatureControl importedFeatures = new IrisImportedFeatureControl(); @ArrayType(type = String.class, min = 1) @Desc("External datapack sources owned by this dimension. Bukkit registers their resources server-wide, but Iris excludes their structure sets and definitions from generation and locate state in vanilla worlds and Iris dimensions that do not declare the same source. Editable auto-import is limited to resources supplied by the URLs declared by each Iris pack. Any registered datapack structure can be placed directly through nativeStructures without conversion. Replacing native generation requires a dimension-level structure placement with nativeSuppression set to REPLACE_SOURCE; provenance alone never disables native structures.") private KList datapackImports = new KList<>(); diff --git a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java index e57c3b9f9..4b70f84e7 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java +++ b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java @@ -20,7 +20,6 @@ package art.arcane.iris.engine.object.world.region; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; -import art.arcane.iris.engine.object.structure.IrisStructurePlacement; import art.arcane.iris.engine.object.value.IRare; import art.arcane.iris.engine.object.world.biome.InferredType; import art.arcane.iris.engine.object.world.biome.IrisBiome; @@ -81,9 +80,6 @@ public class IrisRegion extends IrisRegistrant implements IRare { private KList objects = new KList<>(); @Desc("Procedural objects (trees, ruins, formations, coral, fungi, crystals) iris generates from scratch and places across this region") private IrisProceduralObjects proceduralObjects = new IrisProceduralObjects(); - @ArrayType(min = 1, type = IrisStructurePlacement.class) - @Desc("Structures define jigsaw or vanilla/datapack structures iris will place in this region") - private KList structures = new KList<>(); @MinNumber(0) @Desc("The min shore height") private double shoreHeightMin = 1.2;