mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
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:
1 parent
43aafc743e
commit
621e0e65bc
11 files changed
+344
-41
No files matched your search
+2
-2
@@ -118,7 +118,7 @@ public class IrisStructureLocateCommandContractTest {
|
||||
@Test
|
||||
public void unregisteredDiagnosticExplainsEveryRejectedRoute() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village is disabled by this dimension's importedStructures settings.",
|
||||
"Native structure minecraft:village is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
CommandFind.describeStructureExclusion(
|
||||
CommandFind.StructureLookupRoute.POLICY_DISABLED, "minecraft:village",
|
||||
NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
@@ -214,7 +214,7 @@ public class IrisStructureLocateCommandContractTest {
|
||||
@Test
|
||||
public void findNativePolicyMessagesMatchModdedDiagnostics() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings.",
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
NativeStructureGenerationPolicy.generationStatusMessage(
|
||||
"minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals(
|
||||
|
||||
@@ -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");
|
||||
|
||||
+21
-12
@@ -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;
|
||||
|
||||
@@ -51,6 +51,13 @@ public final class BuiltInPack {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/** {@link #serve} and the pack's resources ({@link PackResourceFixture#serve}), which a world's vanilla structure hooks read. */
|
||||
public static LoadedPack serveWithResources(IrisData data, TemporaryFolder folder, List<IrisModule> packModules) throws IOException {
|
||||
LoadedPack pack = serve(data, folder, packModules);
|
||||
PackResourceFixture.serve(data);
|
||||
return pack;
|
||||
}
|
||||
|
||||
/** Placements into a world of {@code engine} derive their seeds from its world seed. */
|
||||
public static void seedWorld(Engine engine, long seed) {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
|
||||
@@ -4,10 +4,12 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.DiscoveredModule;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleRegistry;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
@@ -52,6 +54,20 @@ public final class ModuleResourceFixture {
|
||||
return served != null ? served : serve(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes {@code data} (a mock) a pack folder named {@code pack} whose modules are {@code modules}, as built-ins, so what
|
||||
* reads the pack's catalog (vanilla structure hooks, validators) finds their registrations.
|
||||
*/
|
||||
public static void serveModules(IrisData data, IrisModule... modules) {
|
||||
LoadedPack pack = mock(LoadedPack.class);
|
||||
PackModuleSet moduleSet = mock(PackModuleSet.class);
|
||||
FeatureCatalog catalog = catalogOf(modules);
|
||||
when(pack.catalog()).thenReturn(catalog);
|
||||
when(moduleSet.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(moduleSet);
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
}
|
||||
|
||||
/** The catalog of a pack with only {@code modules}, as built-ins: their resource kinds, validators and other registrations. */
|
||||
public static FeatureCatalog catalogOf(IrisModule... modules) {
|
||||
ModuleRegistry registry = new ModuleRegistry();
|
||||
|
||||
@@ -288,6 +288,9 @@ public class SchemaBuilderParityTest {
|
||||
assertEquals("obj-art-arcane-iris-engine-object-noise-irisgeneratorstyle", definitionKey(style.getJSONObject(0)));
|
||||
assertEquals("a style may be a snippet, as Iris's styles may", "^snippet/", style.getJSONObject(1).getString("pattern"));
|
||||
assertEquals("any JSON value", 0, tint.getJSONObject("extra").getJSONObject("additionalProperties").length());
|
||||
JSONObject mode = tint.getJSONObject("mode");
|
||||
assertEquals("\"SOFT\",\"HARD\"", mode.getJSONArray("enum").join(","));
|
||||
assertEquals("\"Blends into the ground\",\"\"", mode.getJSONArray("enumDescriptions").join(","));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -675,6 +678,12 @@ public class SchemaBuilderParityTest {
|
||||
private List<com.volmit.block.BlockSpec> palette = List.of();
|
||||
private com.volmit.noise.NoiseStyle style = com.volmit.noise.NoiseStyle.of("SIMPLEX");
|
||||
private java.util.Map<String, Object> extra = java.util.Map.of();
|
||||
private TintMode mode = TintMode.SOFT;
|
||||
}
|
||||
|
||||
public enum TintMode {
|
||||
@com.volmit.config.Desc("Blends into the ground") SOFT,
|
||||
HARD
|
||||
}
|
||||
|
||||
public static final class TintModule implements IrisModule {
|
||||
|
||||
+148
-16
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
@@ -8,19 +10,47 @@ import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecisi
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
|
||||
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.stage.StageGraph;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
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.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;
|
||||
|
||||
public class NativeStructureGenerationPolicyTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<LoadedPack> packs = new ArrayList<>();
|
||||
|
||||
@After
|
||||
public void closePacks() {
|
||||
packs.forEach(LoadedPack::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generationStatusMessagesAreSharedAcrossPlatforms() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings.",
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
NativeStructureGenerationPolicy.generationStatusMessage(
|
||||
"minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals(
|
||||
@@ -36,7 +66,7 @@ public class NativeStructureGenerationPolicyTest {
|
||||
* /iris structure verify locate the placement instead of claiming the key is disabled.
|
||||
*/
|
||||
@Test
|
||||
public void disabledKeyWithActivePlacementResolvesAsReplacedByIris() {
|
||||
public void disabledKeyWithActivePlacementResolvesAsReplacedByIris() throws IOException {
|
||||
Engine engine = engineWithDisabledNamespaceAndRegionPlacement("nova_structures:tavern_oak");
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS,
|
||||
@@ -44,7 +74,7 @@ public class NativeStructureGenerationPolicyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledKeyWithoutPlacementStaysDisabled() {
|
||||
public void disabledKeyWithoutPlacementStaysDisabled() throws IOException {
|
||||
Engine engine = engineWithDisabledNamespaceAndRegionPlacement("nova_structures:tavern_oak");
|
||||
|
||||
IrisNativeStructureDecision decision =
|
||||
@@ -54,10 +84,11 @@ public class NativeStructureGenerationPolicyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactDisabledKeyDoesNotDisableSiblingVariant() {
|
||||
public void exactDisabledKeyDoesNotDisableSiblingVariant() throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().clear();
|
||||
control.getDisabledExact().add("minecraft:ruined_portal");
|
||||
Engine engine = engineWithControlAndRegionPlacement(control, "nova_structures:tavern_oak");
|
||||
Engine engine = engine(control, regionPlacement("nova_structures:tavern_oak"), new KList<>(), List.of());
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:ruined_portal", false).status());
|
||||
@@ -65,32 +96,133 @@ public class NativeStructureGenerationPolicyTest {
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:ruined_portal_nether", false).status());
|
||||
}
|
||||
|
||||
private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("nova_structures:");
|
||||
return engineWithControlAndRegionPlacement(control, placedKey);
|
||||
/** The pilot of the vanilla structure hook: suppression now comes from the iris:structure module's rule. */
|
||||
@Test
|
||||
public void aStructureAnIrisPlacementReplacesIsBlockedByTheStructureModule() throws IOException {
|
||||
IrisStructurePlacement replacement = new IrisStructurePlacement().setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE);
|
||||
replacement.getNativeStructures().add(new IrisNativeStructure().setStructure("minecraft:village_plains"));
|
||||
KList<IrisStructurePlacement> dimensionPlacements = new KList<>();
|
||||
dimensionPlacements.add(replacement);
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), dimensionPlacements, List.of());
|
||||
|
||||
IrisNativeStructureDecision decision = NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains", false);
|
||||
assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS, decision.status());
|
||||
assertFalse(decision.generate());
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_desert", false).status());
|
||||
}
|
||||
|
||||
private Engine engineWithControlAndRegionPlacement(IrisImportedStructureControl control, String placedKey) {
|
||||
@Test
|
||||
public void aStructureAPlacementAlsoPlacesStillGeneratesNatively() throws IOException {
|
||||
Engine engine = engine(allowingEverything(), regionPlacement("minecraft:village_plains"), new KList<>(), List.of());
|
||||
|
||||
assertTrue(NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains", false).generate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packModulesBlockOrReplaceStructuresThroughTheirHooks() throws IOException {
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), new KList<>(), List.of(new HookModule((structure, world) ->
|
||||
switch (structure.path()) {
|
||||
case "pillager_outpost" -> VanillaStructureRule.BLOCK;
|
||||
case "igloo" -> VanillaStructureRule.REPLACE;
|
||||
default -> VanillaStructureRule.GENERATE;
|
||||
})));
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:pillager_outpost", false).status());
|
||||
assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false).status());
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:mansion", false).status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hooksAreAskedOncePerStructureAndPackSnapshot() throws IOException {
|
||||
AtomicInteger asked = new AtomicInteger();
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), new KList<>(), List.of(new HookModule((structure, world) -> {
|
||||
asked.incrementAndGet();
|
||||
return VanillaStructureRule.GENERATE;
|
||||
})));
|
||||
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false);
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", true);
|
||||
assertEquals(1, asked.get());
|
||||
|
||||
IrisData data = engine.getData();
|
||||
IrisPackResources reloaded = new IrisPackResources(data);
|
||||
when(data.getPackResources()).thenReturn(reloaded);
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false);
|
||||
assertEquals("a new snapshot asks again", 2, asked.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aHookThatFailsNamesItsModule() throws IOException {
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), new KList<>(), List.of(new HookModule((structure, world) -> {
|
||||
throw new IllegalArgumentException("broken");
|
||||
})));
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().startsWith(
|
||||
"Module test:hook from host classpath failed deciding over vanilla structure minecraft:igloo: "));
|
||||
}
|
||||
|
||||
private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("nova_structures:");
|
||||
return engine(control, regionPlacement(placedKey), new KList<>(), List.of());
|
||||
}
|
||||
|
||||
private static IrisImportedStructureControl allowingEverything() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().clear();
|
||||
control.getDisabledExact().clear();
|
||||
return control;
|
||||
}
|
||||
|
||||
private static KList<IrisStructurePlacement> regionPlacement(String placedKey) {
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
placement.getNativeStructures().add(new IrisNativeStructure().setStructure(placedKey));
|
||||
KList<IrisStructurePlacement> placements = new KList<>();
|
||||
placements.add(placement);
|
||||
return placements;
|
||||
}
|
||||
|
||||
/** An engine whose pack serves Iris's built-in modules and {@code packModules}, with the given structure placements. */
|
||||
private Engine engine(IrisImportedStructureControl control, KList<IrisStructurePlacement> regionPlacements,
|
||||
KList<IrisStructurePlacement> dimensionPlacements, List<IrisModule> packModules) throws IOException {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
placement.getNativeStructures().add(new IrisNativeStructure().setStructure(placedKey));
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
KList<IrisStructurePlacement> regionPlacements = new KList<>();
|
||||
regionPlacements.add(placement);
|
||||
when(region.getStructures()).thenReturn(regionPlacements);
|
||||
KList<IrisRegion> regions = new KList<>();
|
||||
regions.add(region);
|
||||
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, packModules));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getStructures()).thenReturn(new KList<>());
|
||||
when(dimension.getStructures()).thenReturn(dimensionPlacements);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(regions);
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** A pack module whose only part is a vanilla structure hook. */
|
||||
private record HookModule(VanillaStructureHook hook) implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("test:hook", "Hook", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerVanillaStructureHook(hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-4
@@ -1,13 +1,22 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.StructureDistribution;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.host.LoadedPack;
|
||||
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 static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -19,8 +28,18 @@ import static org.mockito.Mockito.when;
|
||||
* contributes no piece volumes, so it can never veto an object placement.
|
||||
*/
|
||||
public class NativeStructureVolumeSuppressionTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<LoadedPack> packs = new ArrayList<>();
|
||||
|
||||
@After
|
||||
public void closePacks() {
|
||||
packs.forEach(LoadedPack::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packDisabledStructuresContributeNoVolumes() {
|
||||
public void packDisabledStructuresContributeNoVolumes() throws IOException {
|
||||
Engine engine = engine();
|
||||
|
||||
assertFalse(NativeStructureGenerationPolicy
|
||||
@@ -30,7 +49,7 @@ public class NativeStructureVolumeSuppressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledStructuresContributeVolumes() {
|
||||
public void enabledStructuresContributeVolumes() throws IOException {
|
||||
Engine engine = engine();
|
||||
|
||||
assertTrue(NativeStructureGenerationPolicy
|
||||
@@ -51,12 +70,14 @@ public class NativeStructureVolumeSuppressionTest {
|
||||
assertTrue(NativeStructurePlacementPlanner.decisionFor(plan).generate());
|
||||
}
|
||||
|
||||
private Engine engine() {
|
||||
private Engine engine() throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("minecraft:village");
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
IrisData data = mock(IrisData.class);
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, List.of()));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getStructures()).thenReturn(new KList<>());
|
||||
|
||||
+3
@@ -2,6 +2,7 @@ package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
@@ -104,6 +105,7 @@ public class StructureHandlerTest {
|
||||
custom.setLoadKey("iris:custom");
|
||||
IrisStructure collision = new IrisStructure();
|
||||
collision.setLoadKey("pack:collision");
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:custom_definition", custom);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:collision_definition", collision);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
@@ -175,6 +177,7 @@ public class StructureHandlerTest {
|
||||
placements.add(editablePlacement("iris:replacement_definition"));
|
||||
placements.add(nativePlacement("minecraft:explicit", StructureDistribution.RANDOM_SPREAD, 1.0));
|
||||
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:editable_definition", editable);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:replacement_definition", replacement);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
|
||||
Reference in new issue
Block a user