Merge branch 'wave3b/3' into feat/irisapi-host

# Conflicts:
#	core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java
#	core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java
This commit is contained in:
piexel committed 2026-10-15 07:09:43 +02:00
commit 4928a80035
61 files changed
+1784 -1307

No files matched your search

@@ -60,8 +60,9 @@ 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", "iris:loot", "iris:spawn",
"iris:prepare", "iris:anchor", "iris:validate", "iris:bore", "iris:blocks", "iris:stilt", "iris:vacuum", "iris:snow");
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:loot",
"iris:spawn", "iris:prepare", "iris:anchor", "iris:validate", "iris:bore", "iris:blocks", "iris:stilt", "iris:vacuum",
"iris:snow", "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"};
@@ -24,6 +24,7 @@ import com.volmit.host.FeatureCatalog;
import com.volmit.host.ServiceRegistration;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemDrop;
import com.volmit.resource.ResourceId;
import com.volmit.service.AmbientEffects;
import com.volmit.service.BlockDrops;
import com.volmit.service.CaveBiomes;
@@ -33,6 +34,8 @@ 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.service.VanillaStructures;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.ArrayList;
@@ -41,6 +44,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiFunction;
/**
* What Iris core asks the pack's modules through their services ({@link com.volmit.service.Service}) instead of reading
@@ -84,6 +88,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<>();
@@ -227,26 +239,90 @@ public final class ModuleServices {
/** Whether a module of the world can locate structure {@code key}, matched without regard to case. */
public static boolean canLocateStructure(Engine engine, String key) {
return structureLocatorOf(engine, key).isPresent();
return structureLocatorOf(engine, key, StructureLocator::locatable).isPresent();
}
/**
* Every key under which the world's modules find what they place, locatable or not: their own structures and the
* platform structures they start or stand in for.
*/
public static Set<String> placedStructures(Engine engine) {
Set<String> keys = new LinkedHashSet<>();
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
keys.addAll(provider.service().placed(provider.world()));
}
return keys;
}
/** Whether a module of the world places structure {@code key}, located or not, matched without regard to case. */
public static boolean placesStructure(Engine engine, String key) {
return structureLocatorOf(engine, key, StructureLocator::placed).isPresent();
}
/**
* Searches for the start of structure {@code key} nearest to {@code fromX}, {@code fromZ} with the first module that
* can locate it, in the world's own coordinates; not found when none can.
* places it, in the world's own coordinates; not found when none does.
*/
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
LocateResult result = structureLocatorOf(engine, key)
LocateResult result = structureLocatorOf(engine, key, StructureLocator::placed)
.map(provider -> provider.service().locate(provider.world(), key, fromX, fromZ, maxRadiusChunks))
.orElse(LocateResult.NOT_FOUND);
return StructureSearch.of(result, engine);
}
/** The platform structures the world's modules start themselves, as lower-case registry keys. */
public static Set<String> startedStructures(Engine engine) {
return platformStructures(engine, VanillaStructures::startedStructures);
}
/** Whether a module of the world starts the platform structure {@code key} itself. */
public static boolean startsStructure(Engine engine, String key) {
return key != null && startedStructures(engine).contains(normalized(key));
}
/** Whether a module of the world can find the starts it makes of the platform structure {@code key}. */
public static boolean canLocateStart(Engine engine, String key) {
return key != null && platformStructures(engine, VanillaStructures::locatableStarts).contains(normalized(key));
}
/**
* Searches ring by ring, up to {@code maxRings} rings, for the start the first module that can find them makes of the
* platform structure {@code key} nearest to {@code fromX}, {@code fromZ}, trying only chunks {@code candidates}
* accepts, in the world's own coordinates. A {@link StructureSearchLimitException} from {@code candidates} ends the
* search as {@link StructureSearch.Outcome#SEARCH_LIMIT_REACHED}.
*/
public static StructureSearch locateStart(Engine engine, String key, int fromX, int fromZ, int maxRings,
CandidateChunks candidates) {
Optional<ResourceId> structure = registryId(key);
if (structure.isEmpty()) {
return StructureSearch.NOT_FOUND;
}
for (Provider<VanillaStructures> provider : providers(engine, VanillaStructures.class)) {
if (!provider.service().locatableStarts(provider.world()).contains(structure.get())) {
continue;
}
try {
return StructureSearch.of(provider.service().locateStart(provider.world(), structure.get(), fromX, fromZ,
maxRings, candidates::accepts), engine);
} catch (StructureSearchLimitException limit) {
return StructureSearch.SEARCH_LIMIT_REACHED;
}
}
return StructureSearch.NOT_FOUND;
}
/** The chunks a search for a module's start of a platform structure may answer with. */
@FunctionalInterface
public interface CandidateChunks {
boolean accepts(int chunkX, int chunkZ);
}
/** How a structure search ended. A found start is at {@code x}, {@code y}, {@code z}: world coordinates, Y the world's own. */
public record StructureSearch(Outcome outcome, int x, int y, int z) {
public enum Outcome { FOUND, NOT_FOUND, SEARCH_LIMIT_REACHED }
private static final StructureSearch NOT_FOUND = new StructureSearch(Outcome.NOT_FOUND, 0, 0, 0);
private static final StructureSearch SEARCH_LIMIT_REACHED = new StructureSearch(Outcome.SEARCH_LIMIT_REACHED, 0, 0, 0);
public static final StructureSearch NOT_FOUND = new StructureSearch(Outcome.NOT_FOUND, 0, 0, 0);
public static final StructureSearch SEARCH_LIMIT_REACHED = new StructureSearch(Outcome.SEARCH_LIMIT_REACHED, 0, 0, 0);
public boolean found() {
return outcome == Outcome.FOUND;
@@ -263,20 +339,41 @@ public final class ModuleServices {
}
}
/** The first provider, in the catalog's order, whose locatable structures hold {@code key}. */
private static Optional<Provider<StructureLocator>> structureLocatorOf(Engine engine, String key) {
/** The first provider, in the catalog's order, whose structures of the kind {@code keys} lists hold {@code key}. */
private static Optional<Provider<StructureLocator>> structureLocatorOf(Engine engine, String key,
BiFunction<StructureLocator, PackWorld, Set<String>> keys) {
if (key == null || key.isBlank()) {
return Optional.empty();
}
String wanted = normalized(key);
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
if (provider.service().locatable(provider.world()).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
if (keys.apply(provider.service(), provider.world()).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
return Optional.of(provider);
}
}
return Optional.empty();
}
/** The platform structures every provider lists with {@code structures}, as lower-case registry keys. */
private static Set<String> platformStructures(Engine engine, BiFunction<VanillaStructures, PackWorld, Set<ResourceId>> structures) {
Set<String> keys = new LinkedHashSet<>();
for (Provider<VanillaStructures> provider : providers(engine, VanillaStructures.class)) {
structures.apply(provider.service(), provider.world()).forEach(id -> keys.add(id.toString()));
}
return keys;
}
private static Optional<ResourceId> registryId(String key) {
if (key == null || key.isBlank()) {
return Optional.empty();
}
try {
return Optional.of(ResourceId.parse(normalized(key.trim())));
} catch (IllegalArgumentException notAnId) {
return Optional.empty();
}
}
private static String normalized(String key) {
return key.toLowerCase(Locale.ROOT);
}
@@ -37,10 +37,10 @@ import com.volmit.host.ServiceRegistration;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.ResourceId;
import com.volmit.service.VanillaStructures;
import com.volmit.vanilla.DecorationStep;
import com.volmit.vanilla.PieceKind;
import com.volmit.vanilla.StartMemo;
import com.volmit.vanilla.StructureFit;
import com.volmit.vanilla.StructureStep;
import com.volmit.vanilla.TemplateCells;
import com.volmit.vanilla.TerrainAdaptation;
import com.volmit.ModuleLog;
@@ -337,8 +337,8 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
}
@Override
public StructureStep step() {
return StructureStep.valueOf(start.step());
public DecorationStep step() {
return DecorationStep.valueOf(start.step());
}
@Override
@@ -0,0 +1,29 @@
/*
* 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;
/**
* Thrown by a host's {@link ModuleServices.CandidateChunks} to end a search for a module's start of a platform structure
* when the host's own checks ran out of budget; {@link ModuleServices#locateStart} reports it as a reached search limit.
*/
public final class StructureSearchLimitException extends RuntimeException {
public StructureSearchLimitException() {
super(null, null, false, false);
}
}
@@ -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();
}
}
}
@@ -43,6 +43,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* The resources of the pack's module resource kinds that a pack export has to carry: what the settings of the
@@ -59,6 +60,7 @@ public final class ModuleResourceClosure {
private final Map<Class<?>, ResourceKind<?>> kindsByType = new HashMap<>();
private final Map<ResourceKind<?>, Map<String, Object>> found = new LinkedHashMap<>();
private final Set<Object> visited = java.util.Collections.newSetFromMap(new IdentityHashMap<>());
private final Map<Class<?>, Set<String>> exportedElsewhere = new HashMap<>();
public ModuleResourceClosure(IrisData data) {
this.data = data;
@@ -67,6 +69,16 @@ public final class ModuleResourceClosure {
}
}
/**
* Leaves the resources that read into {@code type} to another exporter, such as Iris's structure closure that
* copies structures with their pools, pieces and loot: {@link #keysOf} names the ones referenced, but they are
* not loaded, followed or written. Call before following anything.
*/
public ModuleResourceClosure exportingElsewhere(Class<?> type) {
exportedElsewhere.putIfAbsent(type, new TreeSet<>());
return this;
}
/** Adds the resources that the module settings of {@code owner} reference, and those they reference. */
public void followSettingsOf(IrisRegistrant owner) {
owner.getModuleSettings().values().forEach(this::follow);
@@ -108,6 +120,9 @@ public final class ModuleResourceClosure {
/** The keys of the resources found of the kind that reads into {@code type}, in key order. */
public List<String> keysOf(Class<?> type) {
if (exportedElsewhere.containsKey(type)) {
return new ArrayList<>(exportedElsewhere.get(type));
}
ResourceKind<?> kind = kindsByType.get(type);
return kind == null || !found.containsKey(kind) ? List.of() : new ArrayList<>(new TreeMap<>(found.get(kind)).keySet());
}
@@ -175,6 +190,11 @@ public final class ModuleResourceClosure {
if (kind == null || key == null || key.isBlank()) {
return;
}
Set<String> elsewhere = exportedElsewhere.get(type);
if (elsewhere != null) {
elsewhere.add(key);
return;
}
Map<String, Object> ofKind = found.computeIfAbsent(kind, ignored -> new LinkedHashMap<>());
if (ofKind.containsKey(key)) {
return;
@@ -34,7 +34,7 @@ import art.arcane.iris.engine.object.material.IrisBlockData;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.terrain.IrisGenerator;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.engine.object.structure.IrisStructure;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.util.common.plugin.VolmitSender;
@@ -52,8 +52,7 @@ import org.zeroturnaround.zip.ZipUtil;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("ALL")
@@ -105,7 +104,7 @@ public class IrisPackageCompiler {
KSet<IrisRegion> regions = new KSet<>();
KSet<IrisBiome> biomes = new KSet<>();
KSet<IrisGenerator> generators = new KSet<>();
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm);
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm).exportingElsewhere(IrisStructure.class);
KSet<IrisBlockData> blocks = new KSet<>();
// KSet is ConcurrentHashMap-backed: both add(null) and remove(null) throw NPE, so a
@@ -125,10 +124,7 @@ public class IrisPackageCompiler {
regions.forEach((r) -> allPlacements.addAll(r.getObjects()));
biomes.forEach((i) -> allPlacements.addAll(i.getObjects()));
moduleResources.follow(allPlacements);
Set<String> structureKeys = new LinkedHashSet<>();
collectStructureKeys(structureKeys, dimension.getStructures());
regions.forEach((region) -> collectStructureKeys(structureKeys, region.getStructures()));
biomes.forEach((biome) -> collectStructureKeys(structureKeys, biome.getStructures()));
List<String> structureKeys = moduleResources.keysOf(IrisStructure.class);
KMap<String, String> renameObjects = new KMap<>();
String a;
StringBuilder b = new StringBuilder();
@@ -265,18 +261,4 @@ public class IrisPackageCompiler {
settings.keySet().forEach(key -> json.put(key, settings.get(key)));
return json;
}
private static void collectStructureKeys(Set<String> keys, KList<IrisStructurePlacement> placements) {
if (placements == null) {
return;
}
for (IrisStructurePlacement placement : placements) {
if (placement == null || placement.getStructures() == null) {
continue;
}
for (String structureKey : placement.getStructures()) {
keys.add(structureKey);
}
}
}
}
@@ -28,14 +28,12 @@ import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.core.modules.IrisValues;
import art.arcane.iris.core.modules.ModuleResourceFiles;
import art.arcane.iris.core.modules.ModuleTargets;
import art.arcane.iris.engine.framework.structure.StructureResources;
import art.arcane.iris.engine.object.image.IrisImageMap;
import art.arcane.iris.engine.object.noise.NoiseStyle;
import art.arcane.iris.engine.object.noise.expression.IrisExpression;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.core.structure.StructureSchemaKeys;
import art.arcane.iris.engine.framework.ListFunction;
import art.arcane.iris.engine.object.annotations.ArrayType;
import art.arcane.iris.engine.object.annotations.Desc;
@@ -51,7 +49,6 @@ import art.arcane.iris.engine.object.annotations.RegistryListItemType;
import art.arcane.iris.engine.object.annotations.RegistryListPotionEffect;
import art.arcane.iris.engine.object.annotations.RegistryListResource;
import art.arcane.iris.engine.object.annotations.RegistryListSpecialEntity;
import art.arcane.iris.engine.object.annotations.RegistryListStructure;
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure;
import art.arcane.iris.engine.object.annotations.RegistryMapBlockState;
import art.arcane.iris.engine.object.annotations.Required;
@@ -601,21 +598,6 @@ public class SchemaBuilder {
} else {
IrisLogging.error("Cannot find Registry Loader for type " + rr.value() + " used in " + k.getDeclaringClass().getCanonicalName() + " in field " + k.getName());
}
} else if (k.isAnnotationPresent(RegistryListStructure.class)) {
String key = "enum-iris-structure-placement";
if (!definitions.containsKey(key)) {
JSONObject j = new JSONObject();
j.put("enum", new JSONArray(StructureSchemaKeys.collect(
StructureResources.structureKeys(data),
StructureResources.pieceKeys(data)).toArray(new String[0])));
definitions.put(key, j);
}
fancyType = "Structure";
prop.put("$ref", "#/definitions/" + key);
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla, datapack, or imported Iris structure (use ctrl+space for auto complete!)");
} else if (k.isAnnotationPresent(RegistryListBlockType.class)) {
fancyType = "Block Type";
putRegistryEnumRef(prop, "enum-block-type", this::blockTypes);
@@ -777,22 +759,6 @@ public class SchemaBuilder {
} else {
IrisLogging.error("Cannot find Registry Loader for type (list schema) " + rr.value() + " used in " + k.getDeclaringClass().getCanonicalName() + " in field " + k.getName());
}
} else if (k.isAnnotationPresent(RegistryListStructure.class)) {
fancyType = "List<Structure>";
String key = "enum-iris-structure-placement";
if (!definitions.containsKey(key)) {
JSONObject j = new JSONObject();
j.put("enum", new JSONArray(StructureSchemaKeys.collect(
StructureResources.structureKeys(data),
StructureResources.pieceKeys(data)).toArray(new String[0])));
definitions.put(key, j);
}
JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + key);
prop.put("items", items);
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla, datapack, or imported Iris structure (use ctrl+space for auto complete!)");
} else if (k.isAnnotationPresent(RegistryListVanillaStructure.class)) {
fancyType = "List<Vanilla Structure>";
putRegistryEnumItems(prop, "enum-vanilla-structure", this::vanillaStructures);
@@ -1,57 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.structure;
import art.arcane.volmlib.util.collection.KList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
public final class StructureSchemaKeys {
private StructureSchemaKeys() {
}
public static KList<String> collect(Collection<String> structureKeys, Collection<String> jigsawPieceKeys) {
Set<String> pieces = new HashSet<>();
if (jigsawPieceKeys != null) {
for (String piece : jigsawPieceKeys) {
if (piece != null && !piece.isBlank()) {
pieces.add(piece);
}
}
}
TreeSet<String> merged = new TreeSet<>();
if (structureKeys != null) {
for (String key : structureKeys) {
if (key == null || key.isBlank()) {
continue;
}
if (pieces.contains(key)) {
continue;
}
merged.add(key);
}
}
return new KList<>(merged);
}
}
@@ -24,8 +24,6 @@ import art.arcane.iris.engine.EngineRuntime.BiomeMaxes;
import art.arcane.iris.engine.EngineRuntimeBuilder.RuntimeAssembly;
import art.arcane.iris.engine.IrisEngine.LifecycleState;
import art.arcane.iris.engine.framework.EngineTarget;
import art.arcane.iris.engine.framework.IrisStructureLocator;
import art.arcane.iris.engine.framework.StructureReachability;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisServices;
@@ -117,8 +115,6 @@ final class EngineHotloader {
}
engine.getPlatformHooks().validateDimensionHotload(engine, replacement);
replacementData.registerEngine(engine);
IrisStructureLocator.invalidate(engine);
StructureReachability.invalidate(engine);
EngineTarget replacementTarget = new EngineTarget(engine.getWorld(), replacement, replacementData);
EngineRuntime nextRuntime = engine.runtimeBuilder.buildRuntime(replacementTarget);
engine.runtimeBuilder.publishRuntime(nextRuntime, previousRuntime);
@@ -151,8 +147,6 @@ final class EngineHotloader {
e.addSuppressed(replacementDataFailure);
}
}
IrisStructureLocator.invalidate(engine);
StructureReachability.invalidate(engine);
if (engine.lifecycleState != LifecycleState.FAILED) {
Throwable rollbackFailure = runCleanup(null, engine.getMantle()::hotload);
if (rollbackFailure == null) {
@@ -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"));
}
}
@@ -0,0 +1,124 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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;
import art.arcane.iris.engine.object.world.IrisWorld;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.volmlib.util.collection.KList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
/**
* Determines which vanilla/datapack structures can ever generate in a world, using the same biome
* gate vanilla applies: a structure is reachable when its biome filter intersects the set of vanilla
* biomes the pack actually produces (its {@code possibleBiomes}). Structures whose required biomes are
* never produced cannot generate and must not be scanned for by {@code /locate} or {@code /iris find}
* (an unbounded scan for an absent biome is what stalls the server).
*
* <p>The reachable set is fixed per world: it is kept in the world's state, so a hotload's new world builds it again.
* It is the platform's answer, so Iris core asks it, not a module.
*/
public final class StructureReachability {
private StructureReachability() {
}
public static Set<String> reachableKeys(Engine engine) {
Engine activeEngine = Objects.requireNonNull(engine, "Structure reachability requires an engine");
if (activeEngine.getData() == null) {
throw new IllegalStateException("Structure reachability requires a bound pack data loader");
}
return activeEngine.getGeneration().state(ReachableKeys.class, ReachableKeys::of).keys();
}
public static boolean isReachable(Engine engine, String structureKey) {
String normalizedStructureKey = normalizeStructureKey(structureKey);
return reachableKeys(engine).contains(normalizedStructureKey);
}
private static Set<String> build(Engine engine) {
IrisWorld world = engine.getWorld();
if (world == null) {
throw new IllegalStateException("Structure reachability requires a bound Iris world");
}
if (world.platformWorld() == null) {
throw new IllegalStateException("Structure reachability requires a bound platform world");
}
Set<String> reachable = new LinkedHashSet<>();
for (String key : IrisPlatforms.get().structureHooks().reachableStructureKeys(world.platformWorld())) {
if (key == null || key.isBlank()) {
throw new IllegalStateException("Platform structure reachability returned a blank registry key");
}
reachable.add(key.toLowerCase(Locale.ROOT));
}
return Collections.unmodifiableSet(reachable);
}
/**
* The vanilla biome keys (e.g. {@code minecraft:taiga}) from a structure's filter that the pack
* does not produce. An empty list means the structure is reachable. Used by the structure verify
* diagnostic to explain why a structure cannot generate.
*/
public static KList<String> missingBiomeKeys(Engine engine, String structureKey) {
KList<String> missing = new KList<>();
Engine activeEngine = Objects.requireNonNull(engine, "Structure biome diagnostics require an engine");
String normalizedStructureKey = normalizeStructureKey(structureKey);
IrisWorld world = activeEngine.getWorld();
if (world == null) {
throw new IllegalStateException("Structure biome diagnostics require a bound Iris world");
}
if (world.platformWorld() == null) {
throw new IllegalStateException("Structure biome diagnostics require a bound platform world");
}
Set<String> possible = new LinkedHashSet<>();
for (String key : IrisPlatforms.get().structureHooks().possibleBiomeKeys(world.platformWorld())) {
if (key == null || key.isBlank()) {
throw new IllegalStateException("Platform structure biome query returned a blank possible-biome key");
}
possible.add(key.toLowerCase(Locale.ROOT));
}
for (String biomeKey : IrisPlatforms.get().structureHooks().structureBiomeKeys(normalizedStructureKey)) {
if (biomeKey == null || biomeKey.isBlank()) {
throw new IllegalStateException("Platform structure biome query returned a blank required-biome key for "
+ normalizedStructureKey);
}
if (!possible.contains(biomeKey.toLowerCase(Locale.ROOT))) {
missing.add(biomeKey);
}
}
return missing;
}
/** The world's reachable structure keys, in lower case. */
private record ReachableKeys(Set<String> keys) {
static ReachableKeys of(Engine engine) {
return new ReachableKeys(build(engine));
}
}
private static String normalizeStructureKey(String structureKey) {
if (structureKey == null || structureKey.isBlank()) {
throw new IllegalArgumentException("Registered structure key must not be blank");
}
return structureKey.trim().toLowerCase(Locale.ROOT);
}
}
@@ -12,7 +12,7 @@ public interface NativeFitStart<S> {
int chunkZ();
/** The name of the platform's decoration step, as the API's {@code StructureStep} names it. */
/** The name of the platform's decoration step, as the API's {@code DecorationStep} names it. */
String step();
/** The name of the structure definition's terrain adaptation, as the API's {@code TerrainAdaptation} names it. */
@@ -20,7 +20,6 @@ package art.arcane.iris.util.common.director.specialhandlers;
import art.arcane.iris.core.modules.ModuleServices;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.IrisStructureLocator;
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
import art.arcane.iris.engine.framework.StructureReachability;
import art.arcane.iris.engine.framework.NativeStructureGenerationStatus;
@@ -62,7 +61,7 @@ public class StructureHandler implements DirectorParameterHandler<String> {
String normalizedKey = normalizeKey(key);
if (!normalizedKey.isEmpty()
&& !registeredKeys.containsKey(normalizedKey)
&& !IrisStructureLocator.hasNativePlacement(activeEngine, key)) {
&& !ModuleServices.startsStructure(activeEngine, key)) {
suggestions.putIfAbsent(normalizedKey, key.trim());
}
}
@@ -116,9 +115,9 @@ public class StructureHandler implements DirectorParameterHandler<String> {
private static boolean isEligibleRegisteredKey(Engine engine, String key, String normalizedKey,
Set<String> reachableKeys, boolean nativeGenerationEnabled) {
NativeStructureGenerationStatus status = NativeStructureGenerationPolicy.resolve(engine, key);
boolean nativePlacement = IrisStructureLocator.hasNativePlacement(engine, key);
boolean nativePlacement = ModuleServices.startsStructure(engine, key);
boolean locatableNativePlacement = nativePlacement
&& IrisStructureLocator.hasLocatableNativePlacement(engine, key);
&& ModuleServices.canLocateStart(engine, key);
boolean locatableEditableReplacement = !nativePlacement
&& status == NativeStructureGenerationStatus.REPLACED_BY_IRIS
&& ModuleServices.canLocateStructure(engine, key);