mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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:
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());
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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));
|
||||
|
||||
+20
-5
@@ -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,
|
||||
|
||||
+2
-2
@@ -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();
|
||||
|
||||
@@ -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<String> disabled = List.of();
|
||||
@@ -64,8 +67,10 @@ public final class StructureSettings implements IrisFeature {
|
||||
public StructureSettings() {
|
||||
}
|
||||
|
||||
public StructureSettings(List<String> disabled, List<String> disabledExact, int undergroundYShift, boolean datapackOverrides,
|
||||
List<StructureSetFrequency> frequencyOverrides, List<StructureAdjustment> adjustments) {
|
||||
public StructureSettings(boolean enabled, List<String> disabled, List<String> disabledExact, int undergroundYShift,
|
||||
boolean datapackOverrides, List<StructureSetFrequency> frequencyOverrides,
|
||||
List<StructureAdjustment> 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<String> disabled() {
|
||||
return listOrEmpty(disabled);
|
||||
|
||||
+8
-17
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user