Apply vanilla structure hooks on every platform: ModuleVanillaStructures asks the pack's hooks once per engine, structure and snapshot, and NativeStructureGenerationPolicy takes suppression and module placement from them instead of reading the structure locator; also render module enums in studio without failing

This commit is contained in:
piexel committed 2026-10-09 14:41:06 +02:00
1 parent 43aafc743e
commit 621e0e65bc
11 files changed
+344 -41

No files matched your search

@@ -33,10 +33,9 @@ import java.util.ArrayList;
import java.util.List;
/**
* The settings an engine's pack declares, for working out mantle stage reaches when the pack loads: the
* engine's dimension, then every region it can reach, then every biome. Iris's built-in mantle stages size
* their reach from Iris's own pack data instead of module settings; they reach the engine through
* {@link #of(PackSettings)}.
* The settings an engine's pack declares, for working out mantle stage reaches when the pack loads and for vanilla
* structure hooks: the engine's dimension, then every region it can reach, then every biome. Iris's built-in modules
* decide from Iris's own pack data instead of module settings; they reach the engine through {@link #of(PackSettings)}.
*/
public final class IrisPackSettings implements PackSettings {
static final String DIMENSION = "dimension";
@@ -54,7 +53,7 @@ public final class IrisPackSettings implements PackSettings {
/** Iris's own view of {@code settings}, which Iris hands to every reach it works out. */
public static IrisPackSettings of(PackSettings settings) {
if (!(settings instanceof IrisPackSettings irisSettings)) {
throw new IllegalArgumentException("Built-in reaches are worked out from an Iris engine's pack, not " + settings);
throw new IllegalArgumentException("Built-in modules read an Iris engine's pack, not " + settings);
}
return irisSettings;
}
@@ -0,0 +1,107 @@
/*
* 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.engine.framework.Engine;
import com.volmit.config.PackSettings;
import com.volmit.host.VanillaStructureHookRegistration;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.vanilla.VanillaStructureContext;
import com.volmit.vanilla.VanillaStructureRule;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
/**
* What the pack's modules want for each of the platform's own structures in one engine's world: every vanilla structure
* hook of the pack asked once per structure, the rules combined ({@link VanillaStructureRule#and}). Kept per engine and
* pack snapshot, so a hotload or a reload of the pack's resources asks the hooks again. The platform side
* ({@code NativeStructureGenerationPolicy}) applies the result on Bukkit and the modded platforms alike.
*/
public final class ModuleVanillaStructures {
private static final Map<Engine, ModuleVanillaStructures> WORLDS = Collections.synchronizedMap(new WeakHashMap<>());
private final PackResources snapshot;
private final List<VanillaStructureHookRegistration> hooks;
private final VanillaStructureContext world;
private final Map<String, VanillaStructureRule> rules = new ConcurrentHashMap<>();
private ModuleVanillaStructures(Engine engine, PackResources snapshot) {
this.snapshot = snapshot;
this.hooks = engine.getData().getModules().pack().catalog().vanillaStructureHooks();
this.world = new World(snapshot, new IrisPackSettings(engine));
}
/** The combined rule of the pack's modules for the platform structure {@code structureKey} in {@code engine}'s world. */
public static VanillaStructureRule ruleFor(Engine engine, String structureKey) {
return of(engine).rule(structureKey);
}
private static ModuleVanillaStructures of(Engine engine) {
PackResources current = engine.getData().getPackResources();
ModuleVanillaStructures known = WORLDS.get(engine);
if (known != null && known.snapshot == current) {
return known;
}
ModuleVanillaStructures fresh = new ModuleVanillaStructures(engine, current);
WORLDS.put(engine, fresh);
return fresh;
}
private VanillaStructureRule rule(String structureKey) {
return rules.computeIfAbsent(structureKey, this::askHooks);
}
/** A key that is no resource id names no structure a module could decide over. */
private VanillaStructureRule askHooks(String structureKey) {
ResourceId structure;
try {
structure = ResourceId.parse(structureKey);
} catch (IllegalArgumentException notAnId) {
return VanillaStructureRule.GENERATE;
}
VanillaStructureRule combined = VanillaStructureRule.GENERATE;
for (VanillaStructureHookRegistration registration : hooks) {
combined = combined.and(ask(registration, structure));
}
return combined;
}
private VanillaStructureRule ask(VanillaStructureHookRegistration registration, ResourceId structure) {
VanillaStructureRule rule;
try {
rule = registration.hook().rule(structure, world);
} catch (RuntimeException failure) {
throw new IllegalStateException("Module " + registration.module() + " failed deciding over vanilla structure "
+ structure + ": " + failure, failure);
}
if (rule == null) {
throw new IllegalStateException("Module " + registration.module() + " gave no rule for vanilla structure " + structure);
}
return rule;
}
/** The world the hooks decide for: the engine's pack snapshot and the settings its dimension reaches. */
private record World(PackResources resources, PackSettings settings) implements VanillaStructureContext {
}
}
@@ -222,8 +222,8 @@ final class ModuleSchemaRenderer {
}
case ValueKind.EnumKind enumKind -> {
value.put("type", "string");
value.put("enum", new JSONArray(enumKind.constants().stream().map(ValueKind.EnumConstant::name).toList()));
value.put("enumDescriptions", new JSONArray(enumKind.constants().stream().map(ValueKind.EnumConstant::description).toList()));
value.put("enum", new JSONArray(enumKind.constants().stream().<Object>map(ValueKind.EnumConstant::name).toList()));
value.put("enumDescriptions", new JSONArray(enumKind.constants().stream().<Object>map(ValueKind.EnumConstant::description).toList()));
}
case ValueKind.ListKind list -> {
value.put("type", "array");
@@ -18,13 +18,21 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.core.modules.ModuleVanillaStructures;
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
import com.volmit.vanilla.VanillaStructureRule;
import java.util.Objects;
/**
* Whether the platform generates one of its own structures in an engine's world, the same on every platform: the
* dimension's {@code importedStructures} settings first, then the rule the pack's modules give the structure through
* their vanilla structure hooks ({@link ModuleVanillaStructures}). A structure a module blocks does not generate; one a
* module places itself is reported as replaced, so find, goto and verify locate the module's placement.
*/
public final class NativeStructureGenerationPolicy {
private NativeStructureGenerationPolicy() {
}
@@ -38,20 +46,21 @@ public final class NativeStructureGenerationPolicy {
dimension.getImportedStructures(),
"Dimension importedStructures must not be null");
IrisNativeStructureDecision decision = control.resolve(structureKey, undergroundStep);
if (!decision.generate()) {
// A disabled key with an active Iris placement is the "blanket-disable, re-place
// explicitly" pattern: the placement planner ignores the disable list, so generation
// places it — report REPLACED_BY_IRIS so find/goto/verify locate the placement.
if (decision.status() == NativeStructureGenerationStatus.DISABLED_BY_PACK
&& IrisStructureLocator.isPlaced(activeEngine, structureKey)) {
return decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS);
}
if (decision.status() == NativeStructureGenerationStatus.INVALID_REGISTRY_KEY) {
return decision;
}
if (IrisStructureLocator.suppressesVanilla(activeEngine, structureKey)) {
return decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS);
VanillaStructureRule modules = ModuleVanillaStructures.ruleFor(activeEngine, structureKey);
if (!decision.generate()) {
// A key the dimension disables that a module places is the "blanket-disable, re-place explicitly"
// pattern: report REPLACED_BY_IRIS so find/goto/verify locate the module's placement.
return modules.placedByModule() ? decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS) : decision;
}
return decision;
if (!modules.blocksPlatform()) {
return decision;
}
return decision.withStatus(modules.placedByModule()
? NativeStructureGenerationStatus.REPLACED_BY_IRIS
: NativeStructureGenerationStatus.DISABLED_BY_PACK);
}
public static String generationStatusMessage(String structureKey,
@@ -60,7 +69,7 @@ public final class NativeStructureGenerationPolicy {
return switch (Objects.requireNonNull(status, "Native structure status must not be null")) {
case GENERATE_NATIVE -> "Native structure " + key + " generates natively.";
case DISABLED_BY_PACK -> "Native structure " + key
+ " is disabled by this dimension's importedStructures settings.";
+ " is disabled by this dimension's importedStructures settings or a module of the pack.";
case REPLACED_BY_IRIS -> "Native structure " + key
+ " is replaced by an Iris placement in this pack and locates through that explicit replacement.";
case INVALID_REGISTRY_KEY -> "Native structure registry key is invalid: " + key;