diff --git a/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java b/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java index 60d1986d7..16d174679 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java @@ -129,7 +129,7 @@ public class BuiltInGenerationGraphTest { assertEquals("importedStructures", structures.key()); assertEquals(Optional.empty(), structures.root()); - assertEquals(List.of("disabled", "disabledExact", "undergroundYShift", "datapackOverrides", "frequencyOverrides", "adjustments"), + assertEquals(List.of("enabled", "disabled", "disabledExact", "undergroundYShift", "datapackOverrides", "frequencyOverrides", "adjustments"), structures.settings().options().stream().map(SchemaOption::name).toList()); } } 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 2ac812e8c..6aab365d2 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 @@ -103,6 +103,15 @@ public class NativeStructureGenerationPolicyTest { assertFalse(NativeStructureGenerationPolicy.generates(engine, "minecraft:stronghold")); } + @Test + public void importedStructuresThatAreNotEnabledGenerateNoNativeStructure() throws IOException { + StructureSettings datapacksOnly = new StructureSettings(false, List.of(), List.of(), 0, false, List.of(), List.of()); + Engine engine = engine(datapacksOnly, new KList<>(), new KList<>(), List.of()); + + assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK, + NativeStructureGenerationPolicy.resolve(engine, "minecraft:trial_chambers")); + } + @Test public void aPlacementOfANativeStructureWorksWithoutImportedStructures() throws IOException { Engine engine = engine(ModuleSettings.NONE, regionPlacement("minecraft:village_plains"), List.of()); @@ -115,7 +124,7 @@ public class NativeStructureGenerationPolicyTest { @Test public void exactDisabledKeyDoesNotDisableSiblingVariant() throws IOException { - StructureSettings settings = new StructureSettings(List.of(), List.of("minecraft:ruined_portal"), 0, true, + StructureSettings settings = new StructureSettings(true, List.of(), List.of("minecraft:ruined_portal"), 0, true, List.of(), List.of()); Engine engine = engine(settings, regionPlacement("nova_structures:tavern_oak"), new KList<>(), List.of()); @@ -199,7 +208,7 @@ public class NativeStructureGenerationPolicyTest { @Test public void shiftsAndReachesOfTheSettingsAndOfPackModulesAddUpPerModule() throws IOException { StructureTerrain bore = new Gson().fromJson("{\"mode\":\"BORE\",\"horizontalPadding\":6}", StructureTerrain.class); - StructureSettings settings = new StructureSettings(List.of(), List.of(), -32, true, List.of(), List.of( + StructureSettings settings = new StructureSettings(true, List.of(), List.of(), -32, true, List.of(), List.of( new StructureAdjustment(List.of("minecraft:stronghold"), 4, null, true, null, bore))); Engine engine = engine(settings, new KList<>(), new KList<>(), List.of(new ProviderModule(new VanillaStructures() { @Override @@ -236,13 +245,13 @@ public class NativeStructureGenerationPolicyTest { } private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) throws IOException { - StructureSettings settings = new StructureSettings(List.of("nova_structures:"), List.of(), 0, true, + StructureSettings settings = new StructureSettings(true, List.of("nova_structures:"), List.of(), 0, true, List.of(), List.of()); return engine(settings, regionPlacement(placedKey), new KList<>(), List.of()); } private static StructureSettings allowingEverything() { - return new StructureSettings(); + return new StructureSettings(true, List.of(), List.of(), 0, true, List.of(), List.of()); } private static KList regionPlacement(String placedKey) { diff --git a/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureVolumeSuppressionTest.java b/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureVolumeSuppressionTest.java index d4c5a1b87..aad96ea9e 100644 --- a/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureVolumeSuppressionTest.java +++ b/core/src/test/java/art/arcane/iris/engine/framework/NativeStructureVolumeSuppressionTest.java @@ -54,7 +54,7 @@ public class NativeStructureVolumeSuppressionTest { } private Engine engine() throws IOException { - StructureSettings settings = new StructureSettings(List.of("minecraft:village"), List.of(), 0, true, List.of(), List.of()); + StructureSettings settings = new StructureSettings(true, List.of("minecraft:village"), List.of(), 0, true, List.of(), List.of()); IrisDimension dimension = mock(IrisDimension.class); Engine engine = mock(Engine.class); when(engine.getGeneration()).thenReturn(new EngineGeneration(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 30245d82d..5c3362c62 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,16 +23,31 @@ public class ImportedStructuresTest { private static final Gson JSON = new Gson(); @Test - public void declaredDefaultSettingsImportEveryStructureAndChangeNothing() { + public void defaultSettingsImportNoStructureAndChangeNothing() { ImportedStructures defaults = imported(new StructureSettings()); - assertFalse(defaults.disables("minecraft:village_plains")); - assertFalse(defaults.disables("nova_structures:desert_temple")); + assertTrue(defaults.disables("minecraft:village_plains")); + assertTrue(defaults.disables("nova_structures:desert_temple")); assertEquals(NativeStructureFit.NONE, defaults.adjustment("minecraft:stronghold", true)); assertEquals(1D, defaults.setup().frequency(ResourceId.parse("minecraft:villages")), 0D); assertFalse(defaults.setup().protectsVanillaDefinitions()); } + @Test + public void enabledSettingsImportEveryStructureTheyDoNotDisable() { + ImportedStructures enabled = imported(settings(List.of(), List.of(), 0, true, List.of(), List.of())); + + assertFalse(enabled.disables("minecraft:village_plains")); + assertFalse(enabled.disables("nova_structures:desert_temple")); + } + + @Test + public void settingsThatOnlyKeepDatapacksOffDefinitionsImportNothing() { + StructureSettings datapacksOnly = JSON.fromJson("{\"datapackOverrides\": false}", StructureSettings.class); + + assertTrue(imported(datapacksOnly).disables("minecraft:village_plains")); + } + @Test public void disabledMatchesFamiliesAtResourceBoundariesAndWholeNamespaces() { ImportedStructures imported = imported(settings(List.of("minecraft:village", "example:", "", " "), List.of(), 0, true, @@ -134,7 +149,7 @@ public class ImportedStructuresTest { @Test public void nullListsInThePacksJsonReadAsEmpty() { StructureSettings nulls = new Gson().fromJson( - "{\"disabled\": null, \"disabledExact\": null, \"adjustments\": null, \"frequencyOverrides\": null}", + "{\"enabled\": true, \"disabled\": null, \"disabledExact\": null, \"adjustments\": null, \"frequencyOverrides\": null}", StructureSettings.class); ImportedStructures imported = imported(nulls); @@ -162,7 +177,7 @@ public class ImportedStructuresTest { private static StructureSettings settings(List disabled, List disabledExact, int undergroundYShift, boolean datapackOverrides, List frequencies, List adjustments) { - return new StructureSettings(disabled, disabledExact, undergroundYShift, datapackOverrides, frequencies, adjustments); + return new StructureSettings(true, disabled, disabledExact, undergroundYShift, datapackOverrides, frequencies, adjustments); } private static StructureAdjustment adjustment(List match, int yShift, StructureYBand band, boolean preserveSourceY, diff --git a/core/src/test/java/art/arcane/iris/util/common/director/specialhandlers/StructureHandlerTest.java b/core/src/test/java/art/arcane/iris/util/common/director/specialhandlers/StructureHandlerTest.java index c855fe63e..73ea8331f 100644 --- a/core/src/test/java/art/arcane/iris/util/common/director/specialhandlers/StructureHandlerTest.java +++ b/core/src/test/java/art/arcane/iris/util/common/director/specialhandlers/StructureHandlerTest.java @@ -90,7 +90,7 @@ public class StructureHandlerTest { PlatformWorld platformWorld = mock(PlatformWorld.class); IrisPlatform platform = mock(IrisPlatform.class); PlatformStructureHooks hooks = mock(PlatformStructureHooks.class); - StructureSettings settings = new StructureSettings(List.of("pack:disabled", "pack:replacement", "pack:dormant_replacement"), + StructureSettings settings = new StructureSettings(true, List.of("pack:disabled", "pack:replacement", "pack:dormant_replacement"), List.of(), 0, true, List.of(), List.of()); KList placements = new KList<>(); @@ -163,7 +163,7 @@ public class StructureHandlerTest { PlatformWorld platformWorld = mock(PlatformWorld.class); IrisPlatform platform = mock(IrisPlatform.class); PlatformStructureHooks hooks = mock(PlatformStructureHooks.class); - StructureSettings settings = new StructureSettings(List.of("minecraft:replacement"), List.of(), 0, true, List.of(), List.of()); + StructureSettings settings = new StructureSettings(true, List.of("minecraft:replacement"), List.of(), 0, true, List.of(), List.of()); IrisStructure editable = new IrisStructure(); IrisStructure replacement = new IrisStructure(); 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 7c0e4048c..236c7c131 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,9 +36,12 @@ 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("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.") +@Desc("Experimental. Opt-in import of native vanilla, mod, and ingested datapack structures into this dimension. No native structure generates unless 'enabled' is true. Then 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 { + @Desc("Experimental. Set to true to import native vanilla, mod, and datapack structures into this dimension. Off by default.") + private boolean enabled = false; + @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.") private List disabled = List.of(); @@ -64,8 +67,10 @@ public final class StructureSettings implements IrisFeature { public StructureSettings() { } - public StructureSettings(List disabled, List disabledExact, int undergroundYShift, boolean datapackOverrides, - List frequencyOverrides, List adjustments) { + public StructureSettings(boolean enabled, List disabled, List disabledExact, int undergroundYShift, + boolean datapackOverrides, List frequencyOverrides, + List adjustments) { + this.enabled = enabled; this.disabled = List.copyOf(disabled); this.disabledExact = List.copyOf(disabledExact); this.undergroundYShift = undergroundYShift; @@ -74,6 +79,11 @@ public final class StructureSettings implements IrisFeature { this.adjustments = List.copyOf(adjustments); } + /** Whether the dimension imports the platform's own structures at all. */ + public boolean enabled() { + return enabled; + } + /** Family patterns of the structures the dimension disables. */ public List disabled() { return listOrEmpty(disabled); 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 85dedb1fb..d49d7c774 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,38 +32,29 @@ 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. 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}). + * the starts of the others are adjusted, and how the platform sets them up. Importing is opt-in: unless the settings + * are {@link StructureSettings#enabled}, every platform structure is disabled. 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; nothing imported when it declares none. */ + /** The settings the dimension of {@code settings} declares, or the defaults when it declares none. */ public static ImportedStructures of(PackSettings settings) { - return settings.declared(StructureSettings.class).dimension() - .map(ImportedStructures::new) - .orElse(NOTHING_IMPORTED); + return new ImportedStructures(settings.declared(StructureSettings.class).dimension().orElseGet(StructureSettings::new)); } /** - * Whether the dimension disables the platform structure {@code key}: every key when it imports no structures, + * Whether the dimension disables the platform structure {@code key}: every key unless it imports structures, * otherwise by family or by its exact key. */ public boolean disables(String key) { - if (!importsStructures) { + if (!settings.enabled()) { return true; } String normalizedKey = normalize(key);