mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Native placed features are decided by the pack's VanillaFeatures providers, kept per world
NativeFeatureGenerationPolicy asks VanillaFeatureAnswers (new, core/modules, per world in the state store): the pass runs when any provider turns it on; a step or feature any provider refuses is skipped; each asked once per world. ModuleServices.vanillaFeatures. The Bukkit NMS and modded imported-feature stages decide their steps once per table (platform step index) and ask per feature through the policy; the table no longer holds the dimension's control. resolve/generationStatusMessage and their status enum had no caller outside tests and are gone. IrisModuleHost.JAR_MODULE_IDS and BuiltInPack.jarModules() list iris:vanilla-features. Tests: NativeFeatureGenerationPolicyTest (through the built-in module and pack modules, asked once per world, step order), ImportedFeaturesTest (was IrisImportedFeatureControlTest), VanillaFeaturesSettingsDecodingTest, SchemaBuilderParityTest +1 (was ImportedFeatureControlSchemaTest).
This commit is contained in:
1 parent
520cae4a6b
commit
0cfcada4f2
13 files changed
+598
-440
No files matched your search
+23
-19
@@ -4,9 +4,7 @@ import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeFeatureGenerationPolicy;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationStep;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import it.unimi.dsi.fastutil.ints.IntArraySet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
@@ -32,6 +30,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -112,22 +111,22 @@ final class ImportedFeatureStage {
|
||||
}
|
||||
|
||||
private void build(WorldGenLevel level, IrisDimension dimension) {
|
||||
IrisImportedFeatureControl control;
|
||||
boolean enabled;
|
||||
try {
|
||||
control = NativeFeatureGenerationPolicy.control(engine);
|
||||
enabled = NativeFeatureGenerationPolicy.isEnabled(engine);
|
||||
} catch (RuntimeException error) {
|
||||
IrisLogging.error("Iris could not read importedFeatures for this dimension; features off: "
|
||||
+ error);
|
||||
markInert(dimension);
|
||||
return;
|
||||
}
|
||||
if (!control.shouldGenerateFeatures()) {
|
||||
if (!enabled) {
|
||||
markInert(dimension);
|
||||
return;
|
||||
}
|
||||
FeatureTable built;
|
||||
try {
|
||||
built = buildTable(level, control, dimension);
|
||||
built = buildTable(level, dimension);
|
||||
} catch (Throwable error) {
|
||||
IrisLogging.error("Iris importedFeatures is off for " + dimensionKey()
|
||||
+ ": feature table construction failed: " + error);
|
||||
@@ -150,8 +149,7 @@ final class ImportedFeatureStage {
|
||||
inertDimension = dimension;
|
||||
}
|
||||
|
||||
private FeatureTable buildTable(WorldGenLevel level, IrisImportedFeatureControl control,
|
||||
IrisDimension dimension) {
|
||||
private FeatureTable buildTable(WorldGenLevel level, IrisDimension dimension) {
|
||||
Registry<Biome> registry = level.registryAccess().lookupOrThrow(Registries.BIOME);
|
||||
Set<String> visibleKeys = visibleBiomeKeys();
|
||||
// Registry-ordered walk, never a hash-ordered set: FeatureSorter's cycle detection walks this list and
|
||||
@@ -185,9 +183,17 @@ final class ImportedFeatureStage {
|
||||
+ ". Remove or reorder the conflicting content, or leave importedFeatures.enabled false.");
|
||||
return null;
|
||||
}
|
||||
boolean filtered = control.getDisabled() != null && !control.getDisabled().isEmpty();
|
||||
return new FeatureTable(dimension, control, List.copyOf(biomes), Set.copyOf(biomes),
|
||||
Map.copyOf(byKey), steps, Map.copyOf(derivatives), filtered);
|
||||
return new FeatureTable(dimension, List.copyOf(biomes), Set.copyOf(biomes),
|
||||
Map.copyOf(byKey), steps, Map.copyOf(derivatives), generatedSteps(steps.size()));
|
||||
}
|
||||
|
||||
/** The decoration steps whose features generate, by the platform's step index. */
|
||||
private BitSet generatedSteps(int stepCount) {
|
||||
BitSet generated = new BitSet(stepCount);
|
||||
for (int stepIndex = 0; stepIndex < stepCount; stepIndex++) {
|
||||
generated.set(stepIndex, NativeFeatureGenerationPolicy.shouldGenerateStep(engine, stepIndex));
|
||||
}
|
||||
return generated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +296,7 @@ final class ImportedFeatureStage {
|
||||
|
||||
try {
|
||||
for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
|
||||
if (!table.control().shouldGenerateStep(IrisDecorationStep.byOrdinal(stepIndex))) {
|
||||
if (!table.generatedSteps().get(stepIndex)) {
|
||||
continue;
|
||||
}
|
||||
placeStep(level, table, steps.get(stepIndex), featureRegistry, chunkBiomes, owner,
|
||||
@@ -327,11 +333,9 @@ final class ImportedFeatureStage {
|
||||
Arrays.sort(featureIndices);
|
||||
for (int globalIndex : featureIndices) {
|
||||
PlacedFeature feature = stepData.features().get(globalIndex);
|
||||
if (table.filtered()) {
|
||||
Identifier featureId = featureRegistry.getKey(feature);
|
||||
if (featureId != null && !table.control().shouldGenerate(featureId.toString())) {
|
||||
continue;
|
||||
}
|
||||
Identifier featureId = featureRegistry.getKey(feature);
|
||||
if (featureId != null && !NativeFeatureGenerationPolicy.shouldGenerate(engine, featureId.toString())) {
|
||||
continue;
|
||||
}
|
||||
random.setFeatureSeed(decorationSeed, globalIndex, stepIndex);
|
||||
level.setCurrentlyGenerating(() -> describeFeature(featureRegistry, feature));
|
||||
@@ -390,10 +394,10 @@ final class ImportedFeatureStage {
|
||||
return identifier == null ? null : identifier.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private record FeatureTable(IrisDimension dimension, IrisImportedFeatureControl control,
|
||||
private record FeatureTable(IrisDimension dimension,
|
||||
List<Holder<Biome>> biomes, Set<Holder<Biome>> biomeSet,
|
||||
Map<String, Holder<Biome>> byKey,
|
||||
List<FeatureSorter.StepFeatureData> steps,
|
||||
Map<String, Holder<Biome>> derivatives, boolean filtered) {
|
||||
Map<String, Holder<Biome>> derivatives, BitSet generatedSteps) {
|
||||
}
|
||||
}
|
||||
+25
-20
@@ -23,8 +23,6 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.NativeFeatureGenerationPolicy;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationStep;
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import it.unimi.dsi.fastutil.ints.IntArraySet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
@@ -49,6 +47,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -172,23 +171,23 @@ final class ModdedImportedFeatureStage {
|
||||
}
|
||||
|
||||
private void build(Engine engine, long generation) {
|
||||
IrisImportedFeatureControl control;
|
||||
boolean enabled;
|
||||
try {
|
||||
control = NativeFeatureGenerationPolicy.control(engine);
|
||||
enabled = NativeFeatureGenerationPolicy.isEnabled(engine);
|
||||
} catch (RuntimeException error) {
|
||||
ModdedIrisLog.error("Iris could not read importedFeatures for this dimension; features off: {}",
|
||||
error.toString());
|
||||
markInert(generation);
|
||||
return;
|
||||
}
|
||||
if (!control.shouldGenerateFeatures()) {
|
||||
if (!enabled) {
|
||||
markInert(generation);
|
||||
return;
|
||||
}
|
||||
FeatureTable built;
|
||||
try (GenerationSessionLease lease = engine.acquireGenerationLease("modded_imported_features");
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
built = buildTable(engine, control, generation);
|
||||
built = buildTable(engine, generation);
|
||||
} catch (Throwable error) {
|
||||
ModdedIrisLog.error("Iris importedFeatures is off for {}: feature table construction failed: {}",
|
||||
dimensionKey(engine), error.toString());
|
||||
@@ -214,7 +213,7 @@ final class ModdedImportedFeatureStage {
|
||||
inertGeneration = generation;
|
||||
}
|
||||
|
||||
private FeatureTable buildTable(Engine engine, IrisImportedFeatureControl control, long generation) {
|
||||
private FeatureTable buildTable(Engine engine, long generation) {
|
||||
// Registry-ordered biome list. FeatureSorter's cycle detection walks it, so an unordered list makes
|
||||
// detection depend on JVM hash order and turns a real cycle into an intermittent one.
|
||||
List<Holder<Biome>> biomes = biomeSource.orderedPossibleBiomes();
|
||||
@@ -248,9 +247,17 @@ final class ModdedImportedFeatureStage {
|
||||
dimensionKey(engine), message);
|
||||
return null;
|
||||
}
|
||||
boolean filtered = control.getDisabled() != null && !control.getDisabled().isEmpty();
|
||||
return new FeatureTable(generation, control, List.copyOf(biomes), Set.copyOf(biomes),
|
||||
Map.copyOf(byKey), steps, Map.copyOf(derivatives), filtered);
|
||||
return new FeatureTable(generation, List.copyOf(biomes), Set.copyOf(biomes),
|
||||
Map.copyOf(byKey), steps, Map.copyOf(derivatives), generatedSteps(engine, steps.size()));
|
||||
}
|
||||
|
||||
/** The decoration steps whose features generate, by the platform's step index. */
|
||||
private static BitSet generatedSteps(Engine engine, int stepCount) {
|
||||
BitSet generated = new BitSet(stepCount);
|
||||
for (int stepIndex = 0; stepIndex < stepCount; stepIndex++) {
|
||||
generated.set(stepIndex, NativeFeatureGenerationPolicy.shouldGenerateStep(engine, stepIndex));
|
||||
}
|
||||
return generated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,10 +331,10 @@ final class ModdedImportedFeatureStage {
|
||||
|
||||
try {
|
||||
for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
|
||||
if (!table.control().shouldGenerateStep(IrisDecorationStep.byOrdinal(stepIndex))) {
|
||||
if (!table.generatedSteps().get(stepIndex)) {
|
||||
continue;
|
||||
}
|
||||
placeStep(level, table, steps.get(stepIndex), featureRegistry, chunkBiomes, owner,
|
||||
placeStep(level, engine, table, steps.get(stepIndex), featureRegistry, chunkBiomes, owner,
|
||||
random, decorationSeed, origin, stepIndex);
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
@@ -340,7 +347,7 @@ final class ModdedImportedFeatureStage {
|
||||
WorldCheckFeaturePlacement.recordPlacementPass();
|
||||
}
|
||||
|
||||
private void placeStep(WorldGenLevel level, FeatureTable table, FeatureSorter.StepFeatureData stepData,
|
||||
private void placeStep(WorldGenLevel level, Engine engine, FeatureTable table, FeatureSorter.StepFeatureData stepData,
|
||||
Registry<PlacedFeature> featureRegistry, Set<Holder<Biome>> chunkBiomes,
|
||||
IrisModdedChunkGenerator owner, WorldgenRandom random, long decorationSeed,
|
||||
BlockPos origin, int stepIndex) {
|
||||
@@ -363,11 +370,9 @@ final class ModdedImportedFeatureStage {
|
||||
Arrays.sort(featureIndices);
|
||||
for (int globalIndex : featureIndices) {
|
||||
PlacedFeature feature = stepData.features().get(globalIndex);
|
||||
if (table.filtered()) {
|
||||
Identifier featureId = featureRegistry.getKey(feature);
|
||||
if (featureId != null && !table.control().shouldGenerate(featureId.toString())) {
|
||||
continue;
|
||||
}
|
||||
Identifier featureId = featureRegistry.getKey(feature);
|
||||
if (featureId != null && !NativeFeatureGenerationPolicy.shouldGenerate(engine, featureId.toString())) {
|
||||
continue;
|
||||
}
|
||||
random.setFeatureSeed(decorationSeed, globalIndex, stepIndex);
|
||||
level.setCurrentlyGenerating(() -> describeFeature(featureRegistry, feature));
|
||||
@@ -423,10 +428,10 @@ final class ModdedImportedFeatureStage {
|
||||
return identifier == null ? null : identifier.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private record FeatureTable(long generation, IrisImportedFeatureControl control,
|
||||
private record FeatureTable(long generation,
|
||||
List<Holder<Biome>> biomes, Set<Holder<Biome>> biomeSet,
|
||||
Map<String, Holder<Biome>> byKey,
|
||||
List<FeatureSorter.StepFeatureData> steps,
|
||||
Map<String, Holder<Biome>> derivatives, boolean filtered) {
|
||||
Map<String, Holder<Biome>> derivatives, BitSet generatedSteps) {
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public final class IrisModuleHost {
|
||||
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
|
||||
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
|
||||
*/
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter");
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:vanilla-features");
|
||||
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
|
||||
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
|
||||
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.volmit.service.Loot;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.service.VanillaFeatures;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.ArrayList;
|
||||
@@ -84,6 +85,14 @@ public final class ModuleServices {
|
||||
.orElseGet(() -> new CaveBiomeAnswers(owner, null, owner.getGeneration().world())));
|
||||
}
|
||||
|
||||
/** What the modules say about the platform's own placed features in the engine's world, kept for the world. */
|
||||
public static VanillaFeatureAnswers vanillaFeatures(Engine engine) {
|
||||
return engine.getGeneration().state(VanillaFeatureAnswers.class, owner -> new VanillaFeatureAnswers(
|
||||
providers(owner, VanillaFeatures.class).stream()
|
||||
.map(provider -> new VanillaFeatureAnswers.Provider(provider.service(), provider.world()))
|
||||
.toList()));
|
||||
}
|
||||
|
||||
/** The objects every module would place in the chunk at {@code chunkX}, {@code chunkZ}, guessed without generating it. */
|
||||
public static Set<String> objectsAt(Engine engine, int chunkX, int chunkZ) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
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.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* What the world's {@link VanillaFeatures} providers say, kept for the world: whether the platform's placed features run
|
||||
* over its terrain, and which decoration steps and features they leave out. Each answer is asked once per world.
|
||||
*/
|
||||
public final class VanillaFeatureAnswers {
|
||||
private static final DecorationStep[] STEPS = DecorationStep.values();
|
||||
|
||||
/** One provider and the world as its module sees it. */
|
||||
record Provider(VanillaFeatures service, PackWorld world) {
|
||||
}
|
||||
|
||||
private final List<Provider> providers;
|
||||
private final boolean generates;
|
||||
private final Map<Integer, Boolean> steps = new ConcurrentHashMap<>();
|
||||
private final Map<String, Boolean> features = new ConcurrentHashMap<>();
|
||||
|
||||
VanillaFeatureAnswers(List<Provider> providers) {
|
||||
this.providers = List.copyOf(providers);
|
||||
this.generates = this.providers.stream().anyMatch(provider -> provider.service().generates(provider.world()));
|
||||
}
|
||||
|
||||
/** Whether the platform runs its placed features over the world's terrain: some module turned them on. */
|
||||
public boolean generates() {
|
||||
return generates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the platform places the features of its decoration step {@code stepIndex}, counted in the platform's order
|
||||
* (a step past the ones IrisApi names is asked as an unknown step). False while the features are off.
|
||||
*/
|
||||
public boolean generatesStep(int stepIndex) {
|
||||
if (!generates) {
|
||||
return false;
|
||||
}
|
||||
return steps.computeIfAbsent(stepIndex, index -> everyProviderAllows(provider ->
|
||||
provider.service().generatesStep(provider.world(), stepAt(index))));
|
||||
}
|
||||
|
||||
/** Whether the platform places the feature {@code featureKey}; false while the features are off and for a key that is no registry key. */
|
||||
public boolean generatesFeature(String featureKey) {
|
||||
if (!generates || featureKey == null || featureKey.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
Boolean known = features.get(featureKey);
|
||||
if (known != null) {
|
||||
return known;
|
||||
}
|
||||
return features.computeIfAbsent(featureKey, key -> registryId(key)
|
||||
.map(feature -> everyProviderAllows(provider -> provider.service().generatesFeature(provider.world(), feature)))
|
||||
.orElse(false));
|
||||
}
|
||||
|
||||
private boolean everyProviderAllows(Predicate<Provider> allows) {
|
||||
return providers.stream().allMatch(allows);
|
||||
}
|
||||
|
||||
private static Optional<DecorationStep> stepAt(int index) {
|
||||
return index >= 0 && index < STEPS.length ? Optional.of(STEPS[index]) : Optional.empty();
|
||||
}
|
||||
|
||||
private static Optional<ResourceId> registryId(String key) {
|
||||
try {
|
||||
return Optional.of(ResourceId.parse(key.trim()));
|
||||
} catch (IllegalArgumentException notAnId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-52
@@ -18,75 +18,39 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationStep;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.engine.object.decoration.NativeFeatureGenerationStatus;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.core.modules.VanillaFeatureAnswers;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Single decision point for native placed-feature generation, mirroring {@link NativeStructureGenerationPolicy}.
|
||||
* Both platform generators call only through here so the Bukkit and modded feature passes cannot drift.
|
||||
* Single decision point for native placed-feature generation, mirroring {@link NativeStructureGenerationPolicy}: what
|
||||
* the pack's modules say through {@link com.volmit.service.VanillaFeatures}, kept for the engine's world. Both platform
|
||||
* generators call only through here so the Bukkit and modded feature passes cannot drift.
|
||||
*/
|
||||
public final class NativeFeatureGenerationPolicy {
|
||||
/**
|
||||
* Stand-in for a dimension that has no control block. Immutable in practice: nothing here hands it out for
|
||||
* mutation, and every default in {@link IrisImportedFeatureControl} is "off".
|
||||
*/
|
||||
private static final IrisImportedFeatureControl DISABLED = new IrisImportedFeatureControl();
|
||||
|
||||
private NativeFeatureGenerationPolicy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The dimension's control block, or a disabled default when it has none.
|
||||
* <p>
|
||||
* An absent {@code importedFeatures} member deserializes to the field's initializer, but an explicit
|
||||
* {@code "importedFeatures": null} in dimension JSON overwrites that initializer with null - Gson assigns what
|
||||
* the document says. This runs on the generation path for every feature decision, so throwing there turns one
|
||||
* stray null in a pack into a failed chunk rather than a dimension that simply generates no native features.
|
||||
*/
|
||||
public static IrisImportedFeatureControl control(Engine engine) {
|
||||
Engine activeEngine = Objects.requireNonNull(engine, "Native feature policy requires an engine");
|
||||
IrisDimension dimension = Objects.requireNonNull(activeEngine.getDimension(),
|
||||
"Native feature policy requires a bound dimension");
|
||||
IrisImportedFeatureControl control = dimension.getImportedFeatures();
|
||||
return control == null ? DISABLED : control;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when this dimension opted into the native feature pass. Checked before any feature machinery is
|
||||
* built so a disabled dimension never allocates a feature table.
|
||||
* True when a module turned the native feature pass on for this world. Checked before any feature machinery is
|
||||
* built so a world without it never allocates a feature table.
|
||||
*/
|
||||
public static boolean isEnabled(Engine engine) {
|
||||
return control(engine).shouldGenerateFeatures();
|
||||
return answers(engine).generates();
|
||||
}
|
||||
|
||||
public static NativeFeatureGenerationStatus resolve(Engine engine, String placedFeatureKey,
|
||||
IrisDecorationStep step) {
|
||||
return control(engine).resolve(placedFeatureKey, step);
|
||||
/** Whether the features of the platform's decoration step {@code stepIndex} (in the platform's order) generate. */
|
||||
public static boolean shouldGenerateStep(Engine engine, int stepIndex) {
|
||||
return answers(engine).generatesStep(stepIndex);
|
||||
}
|
||||
|
||||
public static boolean shouldGenerateStep(Engine engine, IrisDecorationStep step) {
|
||||
return control(engine).shouldGenerateStep(step);
|
||||
/** Whether the placed feature {@code placedFeatureKey}, such as {@code minecraft:ore_diamond}, generates. */
|
||||
public static boolean shouldGenerate(Engine engine, String placedFeatureKey) {
|
||||
return answers(engine).generatesFeature(placedFeatureKey);
|
||||
}
|
||||
|
||||
public static String generationStatusMessage(String placedFeatureKey,
|
||||
NativeFeatureGenerationStatus status) {
|
||||
String key = placedFeatureKey == null ? "" : placedFeatureKey.trim();
|
||||
return switch (Objects.requireNonNull(status, "Native feature status must not be null")) {
|
||||
case GENERATE_NATIVE -> "Native feature " + key + " generates natively.";
|
||||
case FEATURES_DISABLED -> "Native feature " + key
|
||||
+ " does not generate because this dimension's importedFeatures.enabled is false.";
|
||||
case STEP_DISABLED -> "Native feature " + key
|
||||
+ " does not generate because its decoration step is excluded by importedFeatures.";
|
||||
case DISABLED_BY_PACK -> "Native feature " + key
|
||||
+ " is disabled by this dimension's importedFeatures.disabled list.";
|
||||
case CYCLE_DEGRADED -> "Native feature " + key
|
||||
+ " does not generate because the registered features could not be ordered "
|
||||
+ "(feature order cycle); importedFeatures was degraded to off for this dimension.";
|
||||
case INVALID_REGISTRY_KEY -> "Native feature registry key is invalid: " + key;
|
||||
};
|
||||
private static VanillaFeatureAnswers answers(Engine engine) {
|
||||
return ModuleServices.vanillaFeatures(Objects.requireNonNull(engine, "Native feature policy requires an engine"));
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.framework.vanillafeatures.VanillaFeaturesModule;
|
||||
import art.arcane.iris.engine.modifier.MatterModule;
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.modifier.PostModule;
|
||||
@@ -51,7 +52,7 @@ public final class BuiltInPack {
|
||||
* with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead.
|
||||
*/
|
||||
public static List<IrisModule> jarModules() {
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule());
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new VanillaFeaturesModule());
|
||||
}
|
||||
|
||||
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** A dimension's {@code importedFeatures} as packs have always written it, read into {@link ImportedFeaturesSettings}. */
|
||||
public class VanillaFeaturesSettingsDecodingTest {
|
||||
private static final String DIMENSION = """
|
||||
{"importedFeatures": {
|
||||
"enabled": true,
|
||||
"disabled": ["minecraft:ore", "minecraft:trees_plains"],
|
||||
"steps": ["UNDERGROUND_ORES", "VEGETAL_DECORATION"],
|
||||
"disabledSteps": ["VEGETAL_DECORATION"]
|
||||
}}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private LoadedPack pack;
|
||||
private ModuleSettingsDecoder decoder;
|
||||
|
||||
@Before
|
||||
public void loadBuiltIns() throws IOException {
|
||||
Path packFolder = folder.newFolder("pack").toPath();
|
||||
pack = LoadedPack.load(packFolder, ModuleHost.of(BuiltInPack.allBuiltIns())
|
||||
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyOptionReadsAsPacksWroteIt() {
|
||||
ImportedFeaturesSettings settings = settings(DIMENSION);
|
||||
|
||||
assertTrue(settings.enabled());
|
||||
assertEquals(List.of("minecraft:ore", "minecraft:trees_plains"), settings.disabled());
|
||||
assertEquals(List.of(DecorationStep.UNDERGROUND_ORES, DecorationStep.VEGETAL_DECORATION), settings.steps());
|
||||
assertEquals(List.of(DecorationStep.VEGETAL_DECORATION), settings.disabledSteps());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySettingsAreOffAndTheFeatureIdIsNotAKey() {
|
||||
ImportedFeaturesSettings defaults = settings("{\"importedFeatures\": {}}");
|
||||
JSONObject byId = new JSONObject("{\"iris:vanilla-features\": {\"enabled\": true}}");
|
||||
|
||||
assertFalse(defaults.enabled());
|
||||
assertEquals(List.of(), defaults.disabled());
|
||||
assertEquals(List.of(), defaults.steps());
|
||||
assertEquals(List.of(), defaults.disabledSteps());
|
||||
assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, byId, "dimension overworld"));
|
||||
assertTrue(decoder.keys(Target.DIMENSION).contains("importedFeatures"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBareSwitchIsRefusedNamingTheKey() {
|
||||
JSONObject bare = new JSONObject("{\"importedFeatures\": true}");
|
||||
|
||||
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
|
||||
() -> decoder.decode(Target.DIMENSION, bare, "dimension overworld"));
|
||||
|
||||
assertEquals("Cannot read settings iris:vanilla-features under \"importedFeatures\" in dimension overworld:"
|
||||
+ " write the settings as an object, {\"<option>\": ...}", refused.getMessage());
|
||||
}
|
||||
|
||||
private ImportedFeaturesSettings settings(String dimensionJson) {
|
||||
return decoder.decode(Target.DIMENSION, new JSONObject(dimensionJson), "dimension overworld")
|
||||
.find(ImportedFeaturesSettings.class).orElseThrow();
|
||||
}
|
||||
}
|
||||
@@ -1,91 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationStep;
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ImportedFeatureControlSchemaTest {
|
||||
@Test
|
||||
public void everyDecorationStepIsSchemaDescribed() throws NoSuchFieldException {
|
||||
assertNotNull(IrisDecorationStep.class.getAnnotation(Desc.class));
|
||||
for (IrisDecorationStep step : IrisDecorationStep.values()) {
|
||||
assertNotNull(step.name(),
|
||||
IrisDecorationStep.class.getField(step.name()).getAnnotation(Desc.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void controlSchemaExposesEnabledFlagAndStepEnums() {
|
||||
JSONObject schema = new SchemaBuilder(IrisImportedFeatureControl.class, null).construct();
|
||||
JSONObject properties = schema.getJSONObject("properties");
|
||||
|
||||
assertEquals("boolean", properties.getJSONObject("enabled").getString("type"));
|
||||
assertEquals("array", properties.getJSONObject("disabled").getString("type"));
|
||||
assertEquals(1, properties.getJSONObject("disabled").getInt("minItems"));
|
||||
|
||||
for (String field : List.of("steps", "disabledSteps")) {
|
||||
JSONObject list = properties.getJSONObject(field);
|
||||
assertEquals("array", list.getString("type"));
|
||||
String definitionKey = list.getJSONObject("items")
|
||||
.getString("$ref").substring("#/definitions/".length());
|
||||
JSONArray values = schema.getJSONObject("definitions")
|
||||
.getJSONObject(definitionKey)
|
||||
.getJSONArray("oneOf");
|
||||
List<String> constants = new ArrayList<>();
|
||||
for (int index = 0; index < values.length(); index++) {
|
||||
JSONObject entry = values.getJSONObject(index);
|
||||
constants.add(entry.getString("const"));
|
||||
assertTrue(field + " " + entry.getString("const"),
|
||||
entry.getString("description").length() > 0);
|
||||
}
|
||||
List<String> expected = new ArrayList<>();
|
||||
for (IrisDecorationStep step : IrisDecorationStep.values()) {
|
||||
expected.add(step.name());
|
||||
}
|
||||
assertEquals(expected, constants);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dimensionSchemaCarriesTheControlBlock() {
|
||||
JSONObject schema = new SchemaBuilder(ControlHolder.class, null).construct();
|
||||
JSONObject importedFeatures = schema.getJSONObject("properties").getJSONObject("importedFeatures");
|
||||
|
||||
assertTrue(importedFeatures.has("$ref") || importedFeatures.has("properties")
|
||||
|| importedFeatures.has("anyOf"));
|
||||
}
|
||||
|
||||
@Desc("Schema model for the imported feature control block.")
|
||||
public static class ControlHolder {
|
||||
@Desc("Controls native placed feature generation.")
|
||||
private IrisImportedFeatureControl importedFeatures = new IrisImportedFeatureControl();
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ import com.volmit.host.ModuleHost;
|
||||
import com.volmit.host.schema.PackSchema;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -87,8 +88,10 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -275,6 +278,29 @@ public class SchemaBuilderParityTest {
|
||||
values(definitions.getJSONObject("enum-native-jigsaw-pool").getJSONArray("enum")));
|
||||
}
|
||||
|
||||
/** {@code importedFeatures} comes from {@code iris:vanilla-features}; its steps keep the descriptions studio showed. */
|
||||
@Test
|
||||
public void importedFeaturesListTheDecorationStepsWithTheirDescriptions() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisDimension.class, structureSchemaData()).construct();
|
||||
JSONObject definitions = schema.getJSONObject("definitions");
|
||||
JSONObject settings = definitions.getJSONObject(definitionKey(rootProperties(schema).getJSONObject("importedFeatures")))
|
||||
.getJSONObject("properties");
|
||||
|
||||
assertEquals("boolean", settings.getJSONObject("enabled").getString("type"));
|
||||
assertEquals(1, settings.getJSONObject("disabled").getInt("minItems"));
|
||||
for (String field : List.of("steps", "disabledSteps")) {
|
||||
JSONObject items = settings.getJSONObject(field).getJSONObject("items");
|
||||
JSONObject steps = items.has("$ref") ? definitions.getJSONObject(definitionKey(items)) : items;
|
||||
assertEquals(1, settings.getJSONObject(field).getInt("minItems"));
|
||||
assertEquals(Arrays.stream(DecorationStep.values()).map(step -> "\"" + step.name() + "\"").collect(Collectors.joining(",")),
|
||||
steps.getJSONArray("enum").join(","));
|
||||
JSONArray descriptions = steps.getJSONArray("enumDescriptions");
|
||||
for (int index = 0; index < descriptions.length(); index++) {
|
||||
assertFalse(field + " " + index, descriptions.getString(index).isBlank());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structureSettingsRenderTheirFitsWithTheModulesDefinitions() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisDimension.class, structureSchemaData(structureSettingsSchema())).construct();
|
||||
|
||||
+161
-67
@@ -18,102 +18,163 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationStep;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.engine.object.decoration.NativeFeatureGenerationStatus;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.VanillaFeatures;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The platform's placed features as the pack's modules decide them through {@link VanillaFeatures}, kept per world. */
|
||||
public class NativeFeatureGenerationPolicyTest {
|
||||
private static Engine engineWith(IrisDimension dimension) {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
return engine;
|
||||
private static final int UNDERGROUND_ORES = DecorationStep.UNDERGROUND_ORES.ordinal();
|
||||
private static final int VEGETAL_DECORATION = DecorationStep.VEGETAL_DECORATION.ordinal();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<LoadedPack> packs = new ArrayList<>();
|
||||
|
||||
@After
|
||||
public void closePacks() {
|
||||
packs.forEach(LoadedPack::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dimensionDefaultsToFeaturesOff() {
|
||||
Engine engine = engineWith(new IrisDimension());
|
||||
public void aDimensionWithoutImportedFeaturesRunsNone() throws IOException {
|
||||
Engine engine = engine(ModuleSettings.NONE, List.of());
|
||||
|
||||
assertFalse(NativeFeatureGenerationPolicy.isEnabled(engine));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerateStep(engine,
|
||||
IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertEquals(NativeFeatureGenerationStatus.FEATURES_DISABLED,
|
||||
NativeFeatureGenerationPolicy.resolve(engine, "minecraft:ore_diamond",
|
||||
IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerateStep(engine, UNDERGROUND_ORES));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:ore_diamond"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledDimensionResolvesThroughItsControl() {
|
||||
KList<String> disabled = new KList<>();
|
||||
disabled.add("minecraft:trees");
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setImportedFeatures(new IrisImportedFeatureControl()
|
||||
.setEnabled(true)
|
||||
.setDisabled(disabled));
|
||||
Engine engine = engineWith(dimension);
|
||||
public void theDimensionsImportedFeaturesDecideThroughTheBuiltInModule() throws IOException {
|
||||
Engine engine = engine(BuiltInPack.settings(TestSettings.with(new ImportedFeaturesSettings(),
|
||||
"enabled", true, "disabled", List.of("minecraft:trees"), "disabledSteps", List.of(DecorationStep.LAKES))), List.of());
|
||||
|
||||
assertTrue(NativeFeatureGenerationPolicy.isEnabled(engine));
|
||||
assertEquals(NativeFeatureGenerationStatus.GENERATE_NATIVE,
|
||||
NativeFeatureGenerationPolicy.resolve(engine, "minecraft:ore_diamond",
|
||||
IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertEquals(NativeFeatureGenerationStatus.DISABLED_BY_PACK,
|
||||
NativeFeatureGenerationPolicy.resolve(engine, "minecraft:trees_plains",
|
||||
IrisDecorationStep.VEGETAL_DECORATION));
|
||||
assertTrue(NativeFeatureGenerationPolicy.shouldGenerateStep(engine, UNDERGROUND_ORES));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerateStep(engine, DecorationStep.LAKES.ordinal()));
|
||||
assertTrue(NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:ore_diamond"));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:trees_plains"));
|
||||
assertFalse("a blank key is no feature", NativeFeatureGenerationPolicy.shouldGenerate(engine, " "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingEngineOrDimensionFailsLoudly() {
|
||||
assertTrue(assertThrows(NullPointerException.class,
|
||||
() -> NativeFeatureGenerationPolicy.control(null))
|
||||
.getMessage().contains("requires an engine"));
|
||||
assertTrue(assertThrows(NullPointerException.class,
|
||||
() -> NativeFeatureGenerationPolicy.control(engineWith(null)))
|
||||
.getMessage().contains("requires a bound dimension"));
|
||||
}
|
||||
public void aStepPastTheOnesTheApiNamesGeneratesUnlessTheStepsWereNarrowed() throws IOException {
|
||||
Engine open = engine(BuiltInPack.settings(TestSettings.with(new ImportedFeaturesSettings(), "enabled", true)), List.of());
|
||||
Engine narrowed = engine(BuiltInPack.settings(TestSettings.with(new ImportedFeaturesSettings(),
|
||||
"enabled", true, "steps", List.of(DecorationStep.UNDERGROUND_ORES))), List.of());
|
||||
int newerStep = DecorationStep.values().length;
|
||||
|
||||
/**
|
||||
* The field initializer gives every dimension a control block, but an explicit
|
||||
* {@code "importedFeatures": null} in dimension JSON overwrites it - Gson assigns what the document says. This
|
||||
* policy is consulted per feature decision on the generation path, so a stray null must disable native features,
|
||||
* not fail the chunk.
|
||||
*/
|
||||
@Test
|
||||
public void nullControlBlockDisablesNativeFeaturesInsteadOfFailingGeneration() {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setImportedFeatures(null);
|
||||
Engine engine = engineWith(dimension);
|
||||
|
||||
assertFalse(NativeFeatureGenerationPolicy.isEnabled(engine));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerateStep(engine, IrisDecorationStep.VEGETAL_DECORATION));
|
||||
assertEquals(NativeFeatureGenerationStatus.FEATURES_DISABLED,
|
||||
NativeFeatureGenerationPolicy.resolve(engine, "minecraft:ore_diamond",
|
||||
IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertTrue(NativeFeatureGenerationPolicy.shouldGenerateStep(open, newerStep));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerateStep(narrowed, newerStep));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generationStatusMessagesAreSharedAcrossPlatforms() {
|
||||
assertEquals("Native feature minecraft:ore_diamond is disabled by this dimension's"
|
||||
+ " importedFeatures.disabled list.",
|
||||
NativeFeatureGenerationPolicy.generationStatusMessage("minecraft:ore_diamond",
|
||||
NativeFeatureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals("Native feature minecraft:ore_diamond does not generate because this dimension's"
|
||||
+ " importedFeatures.enabled is false.",
|
||||
NativeFeatureGenerationPolicy.generationStatusMessage("minecraft:ore_diamond",
|
||||
NativeFeatureGenerationStatus.FEATURES_DISABLED));
|
||||
assertEquals("Native feature minecraft:ore_diamond does not generate because its decoration step is"
|
||||
+ " excluded by importedFeatures.",
|
||||
NativeFeatureGenerationPolicy.generationStatusMessage("minecraft:ore_diamond",
|
||||
NativeFeatureGenerationStatus.STEP_DISABLED));
|
||||
public void aPackModuleMayTurnFeaturesOnAndAnyModuleMayRefuseAStepOrAFeature() throws IOException {
|
||||
VanillaFeatures packModule = new VanillaFeatures() {
|
||||
@Override
|
||||
public boolean generates(PackWorld world) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generatesStep(PackWorld world, Optional<DecorationStep> step) {
|
||||
return !step.equals(Optional.of(DecorationStep.VEGETAL_DECORATION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generatesFeature(PackWorld world, ResourceId feature) {
|
||||
return !feature.path().startsWith("ore_");
|
||||
}
|
||||
};
|
||||
Engine engine = engine(BuiltInPack.settings(TestSettings.with(new ImportedFeaturesSettings(),
|
||||
"disabled", List.of("minecraft:spring"))), List.of(new ProviderModule(packModule)));
|
||||
|
||||
assertTrue(NativeFeatureGenerationPolicy.isEnabled(engine));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerateStep(engine, VEGETAL_DECORATION));
|
||||
assertTrue(NativeFeatureGenerationPolicy.shouldGenerateStep(engine, UNDERGROUND_ORES));
|
||||
assertFalse(NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:ore_diamond"));
|
||||
assertFalse("the dimension's own list still applies", NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:spring_water"));
|
||||
assertTrue(NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:trees_plains"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eachStepAndFeatureIsAskedOncePerWorld() throws IOException {
|
||||
AtomicInteger steps = new AtomicInteger();
|
||||
AtomicInteger features = new AtomicInteger();
|
||||
VanillaFeatures counting = new VanillaFeatures() {
|
||||
@Override
|
||||
public boolean generates(PackWorld world) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generatesStep(PackWorld world, Optional<DecorationStep> step) {
|
||||
steps.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generatesFeature(PackWorld world, ResourceId feature) {
|
||||
features.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Engine engine = engine(ModuleSettings.NONE, List.of(new ProviderModule(counting)));
|
||||
|
||||
for (int chunk = 0; chunk < 3; chunk++) {
|
||||
NativeFeatureGenerationPolicy.shouldGenerateStep(engine, UNDERGROUND_ORES);
|
||||
NativeFeatureGenerationPolicy.shouldGenerate(engine, "minecraft:ore_diamond");
|
||||
}
|
||||
|
||||
assertEquals(1, steps.get());
|
||||
assertEquals(1, features.get());
|
||||
}
|
||||
|
||||
/** The platforms convert their decoration steps by index, so a drift here silently mislabels every step gate. */
|
||||
@Test
|
||||
public void decorationStepsAreInTheOrderOfTheVanillaTable() {
|
||||
String[] vanilla = {
|
||||
"raw_generation", "lakes", "local_modifications", "underground_structures",
|
||||
"surface_structures", "strongholds", "underground_ores", "underground_decoration",
|
||||
"fluid_springs", "vegetal_decoration", "top_layer_modification"
|
||||
};
|
||||
assertEquals(vanilla.length, DecorationStep.values().length);
|
||||
for (int index = 0; index < vanilla.length; index++) {
|
||||
assertEquals(vanilla[index], DecorationStep.values()[index].name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,4 +201,37 @@ public class NativeFeatureGenerationPolicyTest {
|
||||
modded.setDerivative("somemod:alien_waste");
|
||||
assertEquals("somemod:alien_waste", modded.getVanillaDerivativeKey());
|
||||
}
|
||||
|
||||
/** An engine whose dimension declares {@code dimensionSettings}, its pack loading the built-ins and {@code packModules}. */
|
||||
private Engine engine(ModuleSettings dimensionSettings, List<IrisModule> packModules) throws IOException {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, packModules));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
when(dimension.getLoadKey()).thenReturn("overworld");
|
||||
when(dimension.getModuleSettings()).thenReturn(dimensionSettings);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<>());
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** A pack module whose only part is a vanilla features provider. */
|
||||
private record ProviderModule(VanillaFeatures provider) implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("test:features", "Features", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerService(VanillaFeatures.class, provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework.vanillafeatures;
|
||||
|
||||
import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** What a dimension's {@code importedFeatures} decide about the platform's own placed features. */
|
||||
public class ImportedFeaturesTest {
|
||||
private static final ResourceId DIAMONDS = ResourceId.parse("minecraft:ore_diamond");
|
||||
private static final ResourceId PLAINS_TREES = ResourceId.parse("minecraft:trees_plains");
|
||||
private static final ImportedFeatures FEATURES = new ImportedFeatures();
|
||||
|
||||
@Test
|
||||
public void aDimensionWithoutTheSettingsRunsNoFeatures() {
|
||||
assertFalse(FEATURES.generates(worldWith(null)));
|
||||
assertFalse(FEATURES.generates(worldWith(new ImportedFeaturesSettings())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledSettingsWithoutFiltersAllowEveryStepAndFeature() {
|
||||
PackWorld world = worldWith(enabled(List.of(), List.of(), List.of()));
|
||||
|
||||
assertTrue(FEATURES.generates(world));
|
||||
for (DecorationStep step : DecorationStep.values()) {
|
||||
assertTrue(step.name(), FEATURES.generatesStep(world, Optional.of(step)));
|
||||
}
|
||||
assertTrue(FEATURES.generatesFeature(world, DIAMONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledPatternsMatchWholeFamiliesAtABoundaryOnly() {
|
||||
PackWorld world = worldWith(enabled(List.of("minecraft:ore", "minecraft:trees"), List.of(), List.of()));
|
||||
|
||||
assertFalse(FEATURES.generatesFeature(world, DIAMONDS));
|
||||
assertFalse(FEATURES.generatesFeature(world, PLAINS_TREES));
|
||||
assertTrue(FEATURES.generatesFeature(world, ResourceId.parse("minecraft:orefoo")));
|
||||
assertTrue(FEATURES.generatesFeature(world, ResourceId.parse("minecraft:spring_water")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepsNarrowGenerationAndDisabledStepsApplyAfterThem() {
|
||||
PackWorld narrowed = worldWith(enabled(List.of(), List.of(DecorationStep.UNDERGROUND_ORES), List.of()));
|
||||
PackWorld overruled = worldWith(enabled(List.of(),
|
||||
List.of(DecorationStep.UNDERGROUND_ORES, DecorationStep.VEGETAL_DECORATION), List.of(DecorationStep.VEGETAL_DECORATION)));
|
||||
|
||||
assertTrue(FEATURES.generatesStep(narrowed, Optional.of(DecorationStep.UNDERGROUND_ORES)));
|
||||
assertFalse(FEATURES.generatesStep(narrowed, Optional.of(DecorationStep.VEGETAL_DECORATION)));
|
||||
assertFalse(FEATURES.generatesStep(narrowed, Optional.of(DecorationStep.LAKES)));
|
||||
assertTrue(FEATURES.generatesStep(overruled, Optional.of(DecorationStep.UNDERGROUND_ORES)));
|
||||
assertFalse(FEATURES.generatesStep(overruled, Optional.of(DecorationStep.VEGETAL_DECORATION)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStepTheApiDoesNotNameGeneratesUnlessTheStepsWereNarrowed() {
|
||||
PackWorld open = worldWith(enabled(List.of(), List.of(), List.of()));
|
||||
PackWorld narrowed = worldWith(enabled(List.of(), List.of(DecorationStep.UNDERGROUND_ORES), List.of()));
|
||||
|
||||
assertTrue(FEATURES.generatesStep(open, Optional.empty()));
|
||||
assertFalse(FEATURES.generatesStep(narrowed, Optional.empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listsWrittenAsNullReadAsEmpty() {
|
||||
PackWorld world = worldWith(enabled(null, null, null));
|
||||
|
||||
assertTrue(FEATURES.generatesStep(world, Optional.of(DecorationStep.LAKES)));
|
||||
assertTrue(FEATURES.generatesFeature(world, DIAMONDS));
|
||||
}
|
||||
|
||||
private static ImportedFeaturesSettings enabled(List<String> disabled, List<DecorationStep> steps,
|
||||
List<DecorationStep> disabledSteps) {
|
||||
return TestSettings.with(new ImportedFeaturesSettings(),
|
||||
"enabled", true, "disabled", disabled, "steps", steps, "disabledSteps", disabledSteps);
|
||||
}
|
||||
|
||||
/** A world whose dimension declares {@code settings}, or nothing when null. */
|
||||
private static PackWorld worldWith(ImportedFeaturesSettings settings) {
|
||||
PackWorld world = mock(PackWorld.class);
|
||||
when(world.settings()).thenReturn(new PackSettings() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
if (settings == null || featureType != ImportedFeaturesSettings.class) {
|
||||
return List.of();
|
||||
}
|
||||
return List.of((Entry<F>) new Entry<>(Target.DIMENSION, ResourceId.parse("test:overworld"), settings));
|
||||
}
|
||||
});
|
||||
return world;
|
||||
}
|
||||
}
|
||||
-189
@@ -1,189 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.decoration;
|
||||
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationStep;
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.engine.object.decoration.NativeFeatureGenerationStatus;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IrisImportedFeatureControlTest {
|
||||
private static KList<String> keys(String... values) {
|
||||
KList<String> list = new KList<>();
|
||||
for (String value : values) {
|
||||
list.add(value);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static KList<IrisDecorationStep> steps(IrisDecorationStep... values) {
|
||||
KList<IrisDecorationStep> list = new KList<>();
|
||||
for (IrisDecorationStep value : values) {
|
||||
list.add(value);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultControlIsOffAndGeneratesNothing() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl();
|
||||
|
||||
assertFalse(control.isEnabled());
|
||||
assertFalse(control.shouldGenerateFeatures());
|
||||
assertFalse(control.shouldGenerate("minecraft:ore_diamond"));
|
||||
assertFalse(control.shouldGenerateStep(IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertEquals(NativeFeatureGenerationStatus.FEATURES_DISABLED,
|
||||
control.resolve("minecraft:ore_diamond", IrisDecorationStep.UNDERGROUND_ORES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledControlGeneratesEveryStepAndKeyByDefault() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl().setEnabled(true);
|
||||
|
||||
assertTrue(control.shouldGenerateFeatures());
|
||||
assertTrue(control.shouldGenerate("minecraft:ore_diamond"));
|
||||
assertTrue(control.shouldGenerate("somemod:weird_ore"));
|
||||
for (IrisDecorationStep step : IrisDecorationStep.values()) {
|
||||
assertTrue(step.name(), control.shouldGenerateStep(step));
|
||||
}
|
||||
assertEquals(NativeFeatureGenerationStatus.GENERATE_NATIVE,
|
||||
control.resolve("minecraft:ore_diamond", IrisDecorationStep.UNDERGROUND_ORES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledKeyPrefixMatchesOnFamilyBoundariesOnly() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl()
|
||||
.setEnabled(true)
|
||||
.setDisabled(keys("minecraft:ore"));
|
||||
|
||||
assertFalse(control.shouldGenerate("minecraft:ore_diamond"));
|
||||
assertFalse(control.shouldGenerate("minecraft:ore"));
|
||||
assertFalse(control.shouldGenerate("minecraft:ore/deep"));
|
||||
assertTrue(control.shouldGenerate("minecraft:orebody"));
|
||||
assertTrue(control.shouldGenerate("somemod:ore_diamond"));
|
||||
assertEquals(NativeFeatureGenerationStatus.DISABLED_BY_PACK,
|
||||
control.resolve("minecraft:ore_diamond", IrisDecorationStep.UNDERGROUND_ORES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepAllowListNarrowsGenerationToListedStepsOnly() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl()
|
||||
.setEnabled(true)
|
||||
.setSteps(steps(IrisDecorationStep.UNDERGROUND_ORES));
|
||||
|
||||
assertTrue(control.shouldGenerateStep(IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertFalse(control.shouldGenerateStep(IrisDecorationStep.VEGETAL_DECORATION));
|
||||
assertFalse(control.shouldGenerateStep(IrisDecorationStep.LAKES));
|
||||
assertEquals(NativeFeatureGenerationStatus.STEP_DISABLED,
|
||||
control.resolve("minecraft:trees_plains", IrisDecorationStep.VEGETAL_DECORATION));
|
||||
assertEquals(NativeFeatureGenerationStatus.GENERATE_NATIVE,
|
||||
control.resolve("minecraft:ore_diamond", IrisDecorationStep.UNDERGROUND_ORES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledStepsWinOverTheAllowList() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl()
|
||||
.setEnabled(true)
|
||||
.setSteps(steps(IrisDecorationStep.UNDERGROUND_ORES, IrisDecorationStep.VEGETAL_DECORATION))
|
||||
.setDisabledSteps(steps(IrisDecorationStep.VEGETAL_DECORATION));
|
||||
|
||||
assertTrue(control.shouldGenerateStep(IrisDecorationStep.UNDERGROUND_ORES));
|
||||
assertFalse(control.shouldGenerateStep(IrisDecorationStep.VEGETAL_DECORATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownStepGeneratesUnlessAnAllowListNarrowedGeneration() {
|
||||
IrisImportedFeatureControl open = new IrisImportedFeatureControl().setEnabled(true);
|
||||
IrisImportedFeatureControl narrowed = new IrisImportedFeatureControl()
|
||||
.setEnabled(true)
|
||||
.setSteps(steps(IrisDecorationStep.UNDERGROUND_ORES));
|
||||
|
||||
assertTrue(open.shouldGenerateStep(null));
|
||||
assertFalse(narrowed.shouldGenerateStep(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullStepInResolveSkipsTheStepGate() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl()
|
||||
.setEnabled(true)
|
||||
.setSteps(steps(IrisDecorationStep.UNDERGROUND_ORES));
|
||||
|
||||
assertEquals(NativeFeatureGenerationStatus.GENERATE_NATIVE,
|
||||
control.resolve("minecraft:trees_plains", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blankKeyIsInvalidRatherThanGenerated() {
|
||||
IrisImportedFeatureControl control = new IrisImportedFeatureControl().setEnabled(true);
|
||||
|
||||
assertEquals(NativeFeatureGenerationStatus.INVALID_REGISTRY_KEY, control.resolve(null, null));
|
||||
assertEquals(NativeFeatureGenerationStatus.INVALID_REGISTRY_KEY, control.resolve(" ", null));
|
||||
assertFalse(control.shouldGenerate(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullCollectionsFailLoudlyNamingTheField() {
|
||||
IrisImportedFeatureControl nullDisabled = new IrisImportedFeatureControl()
|
||||
.setEnabled(true).setDisabled(null);
|
||||
IrisImportedFeatureControl nullSteps = new IrisImportedFeatureControl()
|
||||
.setEnabled(true).setSteps(null);
|
||||
IrisImportedFeatureControl nullDisabledSteps = new IrisImportedFeatureControl()
|
||||
.setEnabled(true).setDisabledSteps(null);
|
||||
|
||||
assertTrue(assertThrows(NullPointerException.class,
|
||||
() -> nullDisabled.shouldGenerate("minecraft:ore_diamond"))
|
||||
.getMessage().contains("importedFeatures.disabled"));
|
||||
assertTrue(assertThrows(NullPointerException.class,
|
||||
() -> nullSteps.shouldGenerateStep(IrisDecorationStep.LAKES))
|
||||
.getMessage().contains("importedFeatures.steps"));
|
||||
assertTrue(assertThrows(NullPointerException.class,
|
||||
() -> nullDisabledSteps.shouldGenerateStep(IrisDecorationStep.LAKES))
|
||||
.getMessage().contains("importedFeatures.disabledSteps"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decorationStepOrdinalsMatchTheVanillaTable() {
|
||||
// Verified against MC 26.2 GenerationStep.Decoration. The platform converts by ordinal, so a drift
|
||||
// here silently mislabels every step gate.
|
||||
String[] expected = {
|
||||
"raw_generation", "lakes", "local_modifications", "underground_structures",
|
||||
"surface_structures", "strongholds", "underground_ores", "underground_decoration",
|
||||
"fluid_springs", "vegetal_decoration", "top_layer_modification"
|
||||
};
|
||||
|
||||
assertEquals(expected.length, IrisDecorationStep.values().length);
|
||||
for (int ordinal = 0; ordinal < expected.length; ordinal++) {
|
||||
IrisDecorationStep step = IrisDecorationStep.byOrdinal(ordinal);
|
||||
assertEquals(expected[ordinal], step.getSerializedName());
|
||||
assertEquals(ordinal, step.ordinal());
|
||||
assertEquals(step, IrisDecorationStep.byKey(expected[ordinal]));
|
||||
assertEquals(step, IrisDecorationStep.byKey(step.name()));
|
||||
}
|
||||
assertEquals(null, IrisDecorationStep.byOrdinal(expected.length));
|
||||
assertEquals(null, IrisDecorationStep.byOrdinal(-1));
|
||||
assertEquals(null, IrisDecorationStep.byKey("not_a_step"));
|
||||
assertEquals(null, IrisDecorationStep.byKey(null));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user