mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +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
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user