Import native structures only when importedStructures sets enabled

Declaring importedStructures used to opt in by itself, so a block that
only set datapackOverrides to false turned vanilla structures on. The
new enabled option, false by default, is now the only switch; the other
options shape the import once it is on.
This commit is contained in:
piexel committed 2026-11-11 18:15:57 +01:00
1 parent f4821f7b0d
commit 547edabfdf
7 files changed
+58 -33

No files matched your search

@@ -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());
}
}
@@ -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<StructurePlacement> regionPlacement(String placedKey) {
@@ -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));
@@ -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<String> disabled, List<String> disabledExact, int undergroundYShift,
boolean datapackOverrides, List<StructureSetFrequency> frequencies,
List<StructureAdjustment> 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<String> match, int yShift, StructureYBand band, boolean preserveSourceY,
@@ -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<StructurePlacement> 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();