From e9b80420de2e5de91addd15619af4fa7f5514d99 Mon Sep 17 00:00:00 2001 From: piexel Date: Wed, 11 Nov 2026 18:05:43 +0100 Subject: [PATCH] Make native structure imports opt-in and mark them experimental A dimension without importedStructures no longer gets vanilla, mod or datapack structures in new chunks. Declaring the setting imports them, and disabled/disabledExact still narrow it down. Iris placements that place a vanilla structure themselves work without it. The feature is named "Structures (experimental)" and its description says so. The locate message for a blocked structure now says it is not imported by importedStructures or is disabled by a pack module. --- ...risStructureLocateCommandContractTest.java | 4 +-- .../NativeStructureGenerationPolicy.java | 2 +- .../NativeStructureGenerationPolicyTest.java | 29 +++++++++++++++++-- .../structure/ImportedStructuresTest.java | 2 +- .../builtin/structure/StructureSettings.java | 4 +-- .../structure/ImportedStructures.java | 28 ++++++++++++++---- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/adapters/bukkit/plugin/src/test/java/art/arcane/iris/core/commands/IrisStructureLocateCommandContractTest.java b/adapters/bukkit/plugin/src/test/java/art/arcane/iris/core/commands/IrisStructureLocateCommandContractTest.java index 5992e6f20..0356de9ab 100644 --- a/adapters/bukkit/plugin/src/test/java/art/arcane/iris/core/commands/IrisStructureLocateCommandContractTest.java +++ b/adapters/bukkit/plugin/src/test/java/art/arcane/iris/core/commands/IrisStructureLocateCommandContractTest.java @@ -117,7 +117,7 @@ public class IrisStructureLocateCommandContractTest { @Test public void unregisteredDiagnosticExplainsEveryRejectedRoute() { assertEquals( - "Native structure minecraft:village is disabled by this dimension's importedStructures settings or a module of the pack.", + "Native structure minecraft:village is not imported by this dimension's importedStructures settings or is disabled by a module of the pack.", CommandFind.describeStructureExclusion( CommandFind.StructureLookupRoute.POLICY_DISABLED, "minecraft:village", NativeStructureGenerationStatus.DISABLED_BY_PACK, @@ -213,7 +213,7 @@ public class IrisStructureLocateCommandContractTest { @Test public void findNativePolicyMessagesMatchModdedDiagnostics() { assertEquals( - "Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.", + "Native structure minecraft:village_plains is not imported by this dimension's importedStructures settings or is disabled by a module of the pack.", NativeStructureGenerationPolicy.generationStatusMessage( "minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK)); assertEquals( diff --git a/core/src/main/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicy.java b/core/src/main/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicy.java index df06dd73e..fc6ad5b80 100644 --- a/core/src/main/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicy.java +++ b/core/src/main/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicy.java @@ -61,7 +61,7 @@ public final class NativeStructureGenerationPolicy { return switch (Objects.requireNonNull(status, "Native structure status must not be null")) { case GENERATE_NATIVE -> "Native structure " + key + " generates natively."; case DISABLED_BY_PACK -> "Native structure " + key - + " is disabled by this dimension's importedStructures settings or a module of the pack."; + + " is not imported by this dimension's importedStructures settings or is disabled by a module of the pack."; case REPLACED_BY_IRIS -> "Native structure " + key + " is replaced by an Iris placement in this pack and locates through that explicit replacement."; case INVALID_REGISTRY_KEY -> "Native structure registry key is invalid: " + key; diff --git a/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicyTest.java b/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicyTest.java index 5cb5a7477..2ac812e8c 100644 --- a/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicyTest.java +++ b/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureGenerationPolicyTest.java @@ -5,6 +5,7 @@ import art.arcane.iris.builtin.structure.StructureAdjustment; import art.arcane.iris.builtin.structure.StructureSettings; import art.arcane.iris.core.modules.BuiltInPack; import art.arcane.iris.core.modules.IrisPackResources; +import art.arcane.iris.core.modules.ModuleSettings; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.builtin.structure.NativeStructureSource; import art.arcane.iris.engine.object.world.region.IrisRegion; @@ -61,7 +62,7 @@ public class NativeStructureGenerationPolicyTest { @Test public void generationStatusMessagesAreSharedAcrossPlatforms() { assertEquals( - "Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.", + "Native structure minecraft:village_plains is not imported by this dimension's importedStructures settings or is disabled by a module of the pack.", NativeStructureGenerationPolicy.generationStatusMessage( "minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK)); assertEquals( @@ -93,6 +94,25 @@ public class NativeStructureGenerationPolicyTest { assertFalse(NativeStructureGenerationPolicy.generates(engine, "nova_structures:witch_villa")); } + @Test + public void aDimensionWithoutImportedStructuresGeneratesNoNativeStructure() throws IOException { + Engine engine = engine(ModuleSettings.NONE, new KList<>(), List.of()); + + assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK, + NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains")); + assertFalse(NativeStructureGenerationPolicy.generates(engine, "minecraft:stronghold")); + } + + @Test + public void aPlacementOfANativeStructureWorksWithoutImportedStructures() throws IOException { + Engine engine = engine(ModuleSettings.NONE, regionPlacement("minecraft:village_plains"), List.of()); + + assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS, + NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains")); + assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK, + NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_desert")); + } + @Test public void exactDisabledKeyDoesNotDisableSiblingVariant() throws IOException { StructureSettings settings = new StructureSettings(List.of(), List.of("minecraft:ruined_portal"), 0, true, @@ -236,6 +256,11 @@ public class NativeStructureGenerationPolicyTest { /** An engine whose pack serves Iris's built-in modules and {@code packModules}, with the given structure placements. */ private Engine engine(StructureSettings settings, KList regionPlacements, KList dimensionPlacements, List packModules) throws IOException { + return engine(BuiltInPack.settings(settings, placementSettings(dimensionPlacements)), regionPlacements, packModules); + } + + private Engine engine(ModuleSettings dimensionSettings, KList regionPlacements, + List packModules) throws IOException { IrisData data = mock(IrisData.class); Engine engine = mock(Engine.class); when(engine.getGeneration()).thenReturn(new EngineGeneration(engine)); @@ -248,7 +273,7 @@ public class NativeStructureGenerationPolicyTest { packs.add(BuiltInPack.serveWithResources(data, folder, packModules)); when(engine.getData()).thenReturn(data); when(engine.getDimension()).thenReturn(dimension); - when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(settings, placementSettings(dimensionPlacements))); + when(dimension.getModuleSettings()).thenReturn(dimensionSettings); when(dimension.getAllRegions(engine)).thenReturn(regions); when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>()); return engine; diff --git a/core/src/test/java/art/arcane/iris/engine/framework/structure/ImportedStructuresTest.java b/core/src/test/java/art/arcane/iris/engine/framework/structure/ImportedStructuresTest.java index 0c0ab6eaf..30245d82d 100644 --- a/core/src/test/java/art/arcane/iris/engine/framework/structure/ImportedStructuresTest.java +++ b/core/src/test/java/art/arcane/iris/engine/framework/structure/ImportedStructuresTest.java @@ -23,7 +23,7 @@ public class ImportedStructuresTest { private static final Gson JSON = new Gson(); @Test - public void defaultSettingsGenerateEveryStructureAndChangeNothing() { + public void declaredDefaultSettingsImportEveryStructureAndChangeNothing() { ImportedStructures defaults = imported(new StructureSettings()); assertFalse(defaults.disables("minecraft:village_plains")); diff --git a/module/src/main/java/art/arcane/iris/builtin/structure/StructureSettings.java b/module/src/main/java/art/arcane/iris/builtin/structure/StructureSettings.java index 28c180f18..7c0e4048c 100644 --- a/module/src/main/java/art/arcane/iris/builtin/structure/StructureSettings.java +++ b/module/src/main/java/art/arcane/iris/builtin/structure/StructureSettings.java @@ -36,8 +36,8 @@ import java.util.List; * generate are moved and fitted, how often structure sets start, and whether installed data packs may replace the * platform's own definitions. IrisApi types only. */ -@Desc("Controls native vanilla, mod, and ingested datapack structure generation for this dimension. Every registered structure generates through its native placement unless its key matches 'disabled', equals a key in 'disabledExact', or a viable dimension-level Iris placement explicitly replaces its source. Family matching uses namespace, slash, or underscore boundaries, while exact matching compares normalized complete keys only. Run '/iris module structure list' to dump every valid key. Only affects newly generated chunks and is separate from Iris structure placements.") -@Feature(id = "iris:structure", name = "Structures", key = "importedStructures", targets = Level.DIMENSION) +@Desc("Experimental. Opt-in import of native vanilla, mod, and ingested datapack structures into this dimension. Without this setting no native structure generates. With it, every registered structure generates through its native placement unless its key matches 'disabled', equals a key in 'disabledExact', or a viable dimension-level Iris placement explicitly replaces its source. Family matching uses namespace, slash, or underscore boundaries, while exact matching compares normalized complete keys only. Run '/iris module structure list' to dump every valid key. Only affects newly generated chunks. Iris structure placements, including ones that place a vanilla structure, work without it.") +@Feature(id = "iris:structure", name = "Structures (experimental)", key = "importedStructures", targets = Level.DIMENSION) public final class StructureSettings implements IrisFeature { @Ref(Reference.STRUCTURE_PREFIX) @Desc("Structure keys to deny explicitly, e.g. 'minecraft:stronghold'. A namespace:path prefix also matches, so 'minecraft:village' disables every village variant and 'minecraft:ruined_portal' disables every ruined portal. Every key not matched here remains enabled.") diff --git a/module/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java b/module/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java index 9f323742c..85dedb1fb 100644 --- a/module/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java +++ b/module/src/main/java/art/arcane/iris/engine/framework/structure/ImportedStructures.java @@ -32,24 +32,40 @@ 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 RegistryKeyFamily}). + * the starts of the others are adjusted, and how the platform sets them up. Importing is opt-in: a dimension that + * declares no settings disables every platform structure. Keys match ignoring case and surrounding space; a family + * pattern also matches the keys it starts at a namespace, slash or underscore boundary ({@link RegistryKeyFamily}). */ public final class ImportedStructures { + private static final ImportedStructures NOTHING_IMPORTED = new ImportedStructures(new StructureSettings(), false); + private final StructureSettings settings; + private final boolean importsStructures; public ImportedStructures(StructureSettings settings) { + this(settings, true); + } + + private ImportedStructures(StructureSettings settings, boolean importsStructures) { this.settings = settings; + this.importsStructures = importsStructures; } - /** The settings the dimension of {@code settings} declares, or the defaults when it declares none. */ + /** The settings the dimension of {@code settings} declares; nothing imported when it declares none. */ public static ImportedStructures of(PackSettings settings) { - return new ImportedStructures(settings.declared(StructureSettings.class).dimension().orElseGet(StructureSettings::new)); + return settings.declared(StructureSettings.class).dimension() + .map(ImportedStructures::new) + .orElse(NOTHING_IMPORTED); } - /** Whether the dimension disables the platform structure {@code key}, by family or by its exact key. */ + /** + * Whether the dimension disables the platform structure {@code key}: every key when it imports no structures, + * otherwise by family or by its exact key. + */ public boolean disables(String key) { + if (!importsStructures) { + return true; + } String normalizedKey = normalize(key); if (normalizedKey.isEmpty()) { return false;