Merge branch 'wave2/d' into feat/irisapi-host

This commit is contained in:
piexel committed 2026-10-09 22:33:42 +02:00
commit 0b303eb937
63 files changed
+2321 -1187

No files matched your search

@@ -19,10 +19,13 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.framework.structure.StructureLocating;
import art.arcane.iris.engine.loot.LootGiving;
import art.arcane.iris.engine.mantle.components.StructureModule;
import com.volmit.IrisModule;
import com.volmit.host.FeatureCatalog;
import com.volmit.host.LifecycleRegistration;
import com.volmit.service.BlockDrops;
import com.volmit.service.Loot;
import com.volmit.service.ObjectsAt;
import com.volmit.service.StructureLocator;
import org.junit.Test;
@@ -41,6 +44,13 @@ public class BuiltInServicesTest {
assertEquals(1, BUILT_INS.services(ObjectsAt.class).size());
}
@Test
public void lootAndBlockDropsComeFromTheLootModule() {
assertEquals(1, BUILT_INS.services(Loot.class).size());
assertEquals(1, BUILT_INS.services(BlockDrops.class).size());
assertTrue(BUILT_INS.services(Loot.class).getFirst() instanceof LootGiving);
}
@Test
public void structuresAreFoundThroughTheStructureModule() {
List<StructureLocator> locators = BUILT_INS.services(StructureLocator.class);
@@ -87,7 +87,17 @@ public class ModuleServicesTest {
@Override
public void register(FeatureRegistry registry) {
registry.registerService(ObjectsAt.class, (world, chunkX, chunkZ) -> Set.of(object + "@" + chunkX + "," + chunkZ));
registry.registerService(ObjectsAt.class, new ObjectsAt() {
@Override
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
return Set.of(object + "@" + chunkX + "," + chunkZ);
}
@Override
public PlacedBy placedBy(PackWorld world, String objectKey) {
return new PlacedBy(Set.of(object + "-biome"), Set.of(id + "-region"));
}
});
registry.registerService(StructureLocator.class, new StructureLocator() {
@Override
public Set<String> structures(PackResources resources) {
@@ -141,6 +151,14 @@ public class ModuleServicesTest {
assertEquals(List.of("tree@3,-4", "bush@3,-4", "rock@3,-4"), List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
}
@Test
public void objectPlacersCombineTheBiomesAndRegionsOfEveryModule() {
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, "trees/oak");
assertEquals(Set.of("rock-biome", "tree-biome", "bush-biome"), placers.biomes());
assertEquals(Set.of("test:zeta-region", "test:alpha-region", "test:beta-region"), placers.regions());
}
@Test
public void structureListsCombineEveryModule() {
assertEquals(Set.of("tower", "castle"), ModuleServices.locatableStructures(engine));
@@ -1,22 +0,0 @@
package art.arcane.iris.core.service;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TreeSVCFluidHeightTest {
@Test
public void liveWorldTreePlacementConvertsLocalFluidHeightToWorldY() {
Engine engine = mock(Engine.class);
IrisDimension dimension = mock(IrisDimension.class);
when(engine.getMinHeight()).thenReturn(-64);
when(engine.getDimension()).thenReturn(dimension);
when(dimension.getFluidHeight()).thenReturn(127);
assertEquals(63, TreeSVC.worldFluidHeight(engine));
}
}
@@ -10,6 +10,10 @@ import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.placement.IrisTree;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.ModuleResourceFixture;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.mantle.components.ObjectModule;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
@@ -38,6 +42,10 @@ public class TreeDefinitionIndexTest {
biome.setProceduralObjects(proceduralObjects);
when(engine.getDimension()).thenReturn(dimension);
IrisData data = mock(IrisData.class);
when(engine.getData()).thenReturn(data);
ModuleResourceFixture.serveModules(data, new ObjectModule());
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
when(dimension.getAllRegions(engine)).thenReturn(new KList<IrisRegion>().qadd(region));
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<IrisBiome>().qadd(biome));
@@ -4,6 +4,8 @@ import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.core.modules.ModuleResourceFixture;
import art.arcane.iris.engine.mantle.components.ObjectModule;
import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
@@ -92,6 +94,9 @@ public class HintedLocatorTest {
when(engine.isClosed()).thenReturn(false);
when(engine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
when(data.getBiomeLoader()).thenReturn(biomeLoader);
ModuleResourceFixture.serveModules(data, new ObjectModule());
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
stubReachableBiomes();
}
private static IrisBiome biome(String key) {
@@ -137,6 +142,10 @@ public class HintedLocatorTest {
when(biomeLoader.load(biome.getLoadKey())).thenReturn(biome);
}
private void stubReachableBiomes(IrisBiome... biomes) {
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>(biomes));
}
@Test
public void appendRingZeroAddsOnlyOrigin() {
KList<Position2> batch = new KList<>();
@@ -285,6 +294,7 @@ public class HintedLocatorTest {
placements.add(placement);
host.setObjects(placements);
stubBiome(host);
stubReachableBiomes(host);
stubRegions(regionA);
when(complex.getRegionStream()).thenReturn(constantStream(regionA));
@@ -326,6 +336,7 @@ public class HintedLocatorTest {
IrisRegion regionA = region("reg_a");
regionA.setLandBiomes(keys("plains"));
stubBiome(biome("plains"));
stubReachableBiomes(biome("plains"));
stubRegions(regionA);
HintedLocator.SearchPlan plan = HintedLocator.objectPlan(engine, "missing/object");
@@ -416,6 +427,7 @@ public class HintedLocatorTest {
placements.add(placement);
host.setObjects(placements);
stubBiome(host);
stubReachableBiomes(host);
stubRegions(regionA);
when(complex.getRegionStream()).thenReturn(constantStream(regionA));
@@ -44,10 +44,11 @@ public class StructureResourcesTest {
try {
var catalog = data.getModules().pack().catalog();
var kinds = catalog.resourceKinds().stream().map(ResourceKindRegistration::kind)
.filter(kind -> kind.id().toString().startsWith("iris:structure/")).toList();
assertEquals(List.of("iris:structure/piece", "iris:structure/pool", "iris:structure/structure"),
catalog.resourceKinds().stream().map(registration -> registration.kind().id().toString()).toList());
assertEquals(List.of("jigsaw-pieces", "jigsaw-pools", "structures"),
catalog.resourceKinds().stream().map(ResourceKindRegistration::kind).map(kind -> kind.folder()).toList());
kinds.stream().map(kind -> kind.id().toString()).toList());
assertEquals(List.of("jigsaw-pieces", "jigsaw-pools", "structures"), kinds.stream().map(kind -> kind.folder()).toList());
assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(StructureValidator.class::isInstance));
assertFalse(data.getLoaders().containsKey(IrisStructure.class));
assertFalse(data.getLoaders().containsKey(IrisJigsawPool.class));
@@ -146,7 +147,8 @@ public class StructureResourcesTest {
List<JSONObject> entries = ModuleResourceSchemas.entries(data, true);
assertEquals(List.of("./.iris/schema/jigsaw-pieces-schema.json", "./.iris/schema/jigsaw-pools-schema.json",
"./.iris/schema/structures-schema.json"), entries.stream().map(entry -> entry.getString("url")).toList());
"./.iris/schema/structures-schema.json"),
entries.stream().map(entry -> entry.getString("url")).filter(url -> url.contains("jigsaw") || url.contains("structures-")).toList());
JSONObject structures = new JSONObject(Files.readString(pack.resolve(".iris/schema/structures-schema.json")));
JSONObject startPool = structures.getJSONObject("properties").getJSONObject("startPool");
assertEquals("#/definitions/erzjigsaw-pools", startPool.getString("$ref"));
@@ -0,0 +1,106 @@
package art.arcane.iris.engine.loot;
import art.arcane.iris.engine.object.entity.IrisAttributeModifier;
import art.arcane.iris.engine.object.loot.IrisEnchantment;
import art.arcane.iris.engine.object.loot.IrisLoot;
import art.arcane.iris.engine.object.loot.IrisLootTable;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.item.ItemDrop;
import com.volmit.item.ItemRegistry;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import java.util.OptionalInt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** Loot entries turn into items with the random choices made in Iris's order: amount, enchantments, attributes, damage. */
public class LootItemsTest {
private static final long LOOT_SEED = 77L;
private ItemRegistry registry;
@Before
public void knowTheItems() {
registry = mock(ItemRegistry.class);
when(registry.maxDurability(anyString())).thenReturn(OptionalInt.empty());
when(registry.maxDurability("diamond_sword")).thenReturn(OptionalInt.of(1561));
when(registry.maxDurability("diamond")).thenReturn(OptionalInt.of(0));
}
@Test
public void anEntryDrawsAmountEnchantmentsAttributesAndDamageFromOneStreamInThatOrder() {
IrisLoot entry = new IrisLoot().setType("diamond_sword").setMinAmount(1).setMaxAmount(3)
.setMinDurability(0.25).setMaxDurability(0.75)
.setEnchantments(new KList<>(new IrisEnchantment("sharpness", 1, 5, 1D)))
.setAttributes(new KList<>(new IrisAttributeModifier("max_health", "bonus", "ADD_NUMBER", 2, 6, 1D)));
RNG expected = new RNG(5L);
int amount = (int) (1 + expected.nextLong(3));
expected.nextDouble();
int level = (int) (1 + expected.nextLong(5));
expected.nextDouble();
double bonus = expected.d(2, 6);
double damage = 1D - expected.d(0.25, 0.75);
ItemDrop drop = new LootItems(registry, false).give(entry, new RNG(5L));
assertEquals(amount, drop.amount());
assertEquals(level, drop.enchantments().getFirst().level());
assertEquals(bonus, drop.attributes().getFirst().amount(), 0D);
assertEquals(damage, drop.damage(), 0D);
}
@Test
public void anItemThatCannotBeDamagedDrawsNoDamageAndKeepsTheStreamAligned() {
IrisLoot entry = new IrisLoot().setType("diamond").setMinAmount(2).setMaxAmount(2);
RNG rng = new RNG(9L);
RNG untouched = new RNG(9L);
ItemDrop drop = new LootItems(registry, false).give(entry, rng);
assertEquals(2, drop.amount());
assertNull(drop.damage());
assertEquals(untouched.nextLong(), rng.nextLong());
}
@Test
public void anItemThePlatformDoesNotKnowIsNotGivenAndDrawsNothing() {
RNG rng = new RNG(9L);
RNG untouched = new RNG(9L);
assertNull(new LootItems(registry, false).give(new IrisLoot().setType("not_an_item"), rng));
assertNull(new LootItems(registry, false).give(new IrisLoot().setType("air"), rng));
assertEquals(untouched.nextLong(), rng.nextLong());
}
@Test
public void debugItemsSayWhereTheyCameFrom() {
IrisLootTable table = new IrisLootTable().setName("dungeon").setRarity(4);
table.setLoot(new KList<>(new IrisLoot().setType("diamond").setRarity(3)));
table.setMinPicked(1).setMaxPicked(1);
List<ItemDrop> drops = new LootItems(registry, true).draw(table, LOOT_SEED, 0, 64, 0);
for (ItemDrop drop : drops) {
assertEquals(new ItemDrop.Source("dungeon", 4, 3), drop.source());
}
assertTrue(new LootItems(registry, false).draw(table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source() == null));
}
@Test
public void aTableGivesTheSameItemsAtTheSameSpotAndSeed() {
IrisLootTable table = new IrisLootTable().setName("tools").setMinPicked(2).setMaxPicked(4);
table.setLoot(new KList<>(new IrisLoot().setType("diamond").setMaxAmount(5), new IrisLoot().setType("diamond_sword")));
LootItems items = new LootItems(registry, false);
assertEquals(items.draw(table, LOOT_SEED, 10, 64, -30), items.draw(table, LOOT_SEED, 10, 64, -30));
}
}
@@ -1,7 +1,9 @@
package art.arcane.iris.engine.framework;
package art.arcane.iris.engine.loot;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.LootResolver;
import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.object.loot.InventorySlotType;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.loot.IrisLootMode;
@@ -12,6 +14,7 @@ import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.MaxNumber;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.item.ItemRegistry;
import org.junit.Test;
import java.lang.reflect.Field;
@@ -70,12 +73,12 @@ public class LootResolverTest {
IrisLootTable first = new IrisLootTable().setName("first");
IrisLootTable second = new IrisLootTable().setName("second");
long baseline = LootResolver.tableSeed(41L, first, 0, 64, 0);
long baseline = LootTables.seed(41L, first, 0, 64, 0);
assertEquals(baseline, LootResolver.tableSeed(41L, first, 0, 64, 0));
assertNotEquals(baseline, LootResolver.tableSeed(42L, first, 0, 64, 0));
assertNotEquals(baseline, LootResolver.tableSeed(41L, second, 0, 64, 0));
assertNotEquals(baseline, LootResolver.tableSeed(41L, first, 16, 64, 0));
assertEquals(baseline, LootTables.seed(41L, first, 0, 64, 0));
assertNotEquals(baseline, LootTables.seed(42L, first, 0, 64, 0));
assertNotEquals(baseline, LootTables.seed(41L, second, 0, 64, 0));
assertNotEquals(baseline, LootTables.seed(41L, first, 16, 64, 0));
}
@Test
@@ -84,7 +87,7 @@ public class LootResolverTest {
int successes = 0;
for (int x = 0; x < 65_536; x++) {
if (LootResolver.spatialOneIn(91L, table, 3, x, 40, x * 31, 8L)) {
if (LootTables.spatialOneIn(91L, table, 3, x, 40, x * 31, 8L)) {
successes++;
}
}
@@ -92,8 +95,8 @@ public class LootResolverTest {
assertTrue(successes > 7_600);
assertTrue(successes < 8_800);
assertEquals(
LootResolver.spatialOneIn(91L, table, 3, 112, 40, 992, 8L),
LootResolver.spatialOneIn(91L, table, 3, 112, 40, 992, 8L)
LootTables.spatialOneIn(91L, table, 3, 112, 40, 992, 8L),
LootTables.spatialOneIn(91L, table, 3, 112, 40, 992, 8L)
);
}
@@ -102,7 +105,7 @@ public class LootResolverTest {
ResolutionFixture fixture = new ResolutionFixture();
List<IrisLootTable> sources = new ArrayList<>();
LootResolver.resolveEnvironmentSources(
LootTables.resolveEnvironmentSources(
sources,
fixture.engine,
new RNG(19L),
@@ -121,7 +124,7 @@ public class LootResolverTest {
ResolutionFixture fixture = new ResolutionFixture();
List<IrisLootTable> sources = new ArrayList<>();
LootResolver.resolveEnvironmentSources(
LootTables.resolveEnvironmentSources(
sources,
fixture.engine,
new RNG(19L),
@@ -247,7 +250,7 @@ public class LootResolverTest {
public void emptyLootTableReturnsNoItems() {
IrisLootTable table = new IrisLootTable().setName("empty");
assertTrue(table.getLoot(false, 7L, InventorySlotType.STORAGE, null, 0, 64, 0).isEmpty());
assertTrue(new LootItems(mock(ItemRegistry.class), false).draw(table, 7L, 0, 64, 0).isEmpty());
}
@Test
@@ -0,0 +1,113 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.loot;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.project.ModuleResourceSchemas;
import art.arcane.iris.core.project.SchemaTestPlatform;
import art.arcane.iris.engine.object.loot.IrisLootTable;
import art.arcane.volmlib.util.json.JSONObject;
import com.volmit.host.ValidatorRegistration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** Loot tables are a resource kind of module {@code iris:loot}, read from the folder packs have always had. */
public class LootResourcesTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void theLootModuleOwnsTheKindAndItsValidator() throws Exception {
IrisData data = IrisData.openValidation(lootPack("owned").toFile());
try {
var catalog = data.getModules().pack().catalog();
assertEquals(List.of("iris:loot/table"), catalog.resourceKinds().stream().map(registration -> registration.kind().id().toString())
.filter(id -> id.startsWith("iris:loot/")).toList());
assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(LootValidator.class::isInstance));
assertFalse(data.getLoaders().containsKey(IrisLootTable.class));
} finally {
data.close();
}
}
@Test
public void tablesAreReadThroughPackResourcesAndReadAgainAfterAReload() throws Exception {
Path pack = lootPack("tables");
IrisData data = IrisData.openValidation(pack.toFile());
try {
IrisLootTable table = LootResources.table(data, "dungeon/chest");
assertEquals("Chest", table.getName());
assertEquals("dungeon/chest", table.getLoadKey());
assertEquals(pack.resolve("loot/dungeon/chest.json").toFile(), table.getLoadFile());
assertEquals(List.of("dungeon/chest"), LootResources.tableKeys(data));
assertEquals(List.of(table), LootResources.tables(data, List.of("dungeon/chest", "missing")));
assertNull(LootResources.table(data, "missing"));
assertNull(LootResources.table(data, " "));
write(pack, "loot/dungeon/chest.json", "{\"name\":\"Renamed\"}");
data.dump();
assertEquals("Renamed", LootResources.table(data, "dungeon/chest").getName());
} finally {
data.close();
}
}
@Test
public void studioDescribesLootTablesAsIrisDoes() throws Exception {
Path pack = lootPack("studio");
IrisData data = IrisData.openValidation(pack.toFile());
try (SchemaTestPlatform ignored = SchemaTestPlatform.bind(temporaryFolder.getRoot())) {
List<JSONObject> entries = ModuleResourceSchemas.entries(data, true);
assertTrue(entries.stream().anyMatch(entry -> entry.getString("url").equals("./.iris/schema/loot-schema.json")));
assertTrue(Files.exists(pack.resolve(".iris/schema/loot-schema.json")));
} finally {
data.close();
}
}
private Path lootPack(String name) throws Exception {
File pack = temporaryFolder.newFolder(name);
write(pack.toPath(), "dimensions/main.json", "{\"regions\":[\"region\"]}");
write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}");
write(pack.toPath(), "loot/dungeon/chest.json", "{\"name\":\"Chest\",\"loot\":[{\"type\":\"stick\"}]}");
return pack.toPath();
}
private static void write(Path root, String relative, String content) throws Exception {
Path path = root.resolve(relative);
Files.createDirectories(path.getParent());
Files.writeString(path, content, StandardCharsets.UTF_8);
}
}
@@ -1,4 +1,4 @@
package art.arcane.iris.engine.framework;
package art.arcane.iris.engine.loot;
import art.arcane.iris.engine.object.loot.IrisLootMode;
import org.junit.Test;
@@ -9,22 +9,22 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class LootResolverClearModeTest {
public class LootTablesClearModeTest {
@Test
public void clearSuppressesItsOwnTablesAndReplaceDoesNot() {
List<String> cleared = new ArrayList<>(List.of("placement", "dimension"));
LootResolver.injectSources(cleared, List.of("biome"), IrisLootMode.CLEAR, false);
LootTables.injectSources(cleared, List.of("biome"), IrisLootMode.CLEAR, false);
assertTrue("CLEAR must clear parents and contribute nothing", cleared.isEmpty());
List<String> replaced = new ArrayList<>(List.of("placement", "dimension"));
LootResolver.injectSources(replaced, List.of("biome"), IrisLootMode.REPLACE, false);
LootTables.injectSources(replaced, List.of("biome"), IrisLootMode.REPLACE, false);
assertEquals(List.of("biome"), replaced);
}
@Test
public void clearIgnoresTheFallbackFlag() {
List<String> sources = new ArrayList<>(List.of("placement"));
LootResolver.injectSources(sources, List.of("biome"), IrisLootMode.CLEAR, true);
LootTables.injectSources(sources, List.of("biome"), IrisLootMode.CLEAR, true);
assertTrue(sources.isEmpty());
}
}
@@ -1,8 +1,10 @@
package art.arcane.iris.core.pack;
package art.arcane.iris.engine.loot;
import art.arcane.iris.engine.object.loot.IrisLoot;
import art.arcane.iris.engine.object.loot.IrisLootTable;
import art.arcane.iris.engine.object.annotations.MaxNumber;
import com.volmit.validation.Problem;
import com.volmit.validation.Severity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -16,7 +18,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class PackValidatorLootTest {
public class LootValidatorTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -28,7 +30,7 @@ public class PackValidatorLootTest {
write(pack, "dimensions/main.json", "{\"loot\":{\"mode\":\"FALLBACK\",\"multiplier\":0.5,"
+ "\"tables\":[\"global/clutter\"]}}");
assertTrue(PackLootValidator.validateLootGraph(pack).errors().isEmpty());
assertTrue(errors(pack).isEmpty());
}
@Test
@@ -37,7 +39,7 @@ public class PackValidatorLootTest {
write(pack, "dimensions/main.json", "{\"loot\":{\"tables\":[\"missing\"]}}");
assertEquals(List.of("Dimension 'main'.loot.tables[0] references missing loot table 'missing'."),
PackLootValidator.validateLootGraph(pack).errors());
errors(pack));
}
@Test
@@ -47,7 +49,7 @@ public class PackValidatorLootTest {
+ "\"loot\":[{\"type\":\"\",\"rarity\":0,\"minAmount\":3,\"maxAmount\":1,"
+ "\"enchantments\":[{\"enchantment\":\"\",\"minLevel\":4,\"maxLevel\":2,\"chance\":2}]}]}");
List<String> errors = PackLootValidator.validateLootGraph(pack).errors();
List<String> errors = errors(pack);
assertTrue(errors.stream().anyMatch(error -> error.contains(".rarity must be at least 1")));
assertTrue(errors.stream().anyMatch(error -> error.contains(".minPicked must not exceed")));
@@ -63,7 +65,7 @@ public class PackValidatorLootTest {
File pack = temporaryFolder.newFolder("pack");
write(pack, "dimensions/main.json", "{\"loot\":{\"mode\":\"MERGE\",\"multiplier\":-1,\"tables\":[]}}");
List<String> errors = PackLootValidator.validateLootGraph(pack).errors();
List<String> errors = errors(pack);
assertEquals(2, errors.size());
assertTrue(errors.get(0).contains(".mode must be"));
@@ -74,12 +76,12 @@ public class PackValidatorLootTest {
public void enforcesPublishedLootMultiplierCap() throws Exception {
File acceptedPack = temporaryFolder.newFolder("accepted-pack");
write(acceptedPack, "dimensions/main.json", "{\"loot\":{\"multiplier\":16,\"tables\":[]}}");
assertTrue(PackLootValidator.validateLootGraph(acceptedPack).errors().isEmpty());
assertTrue(errors(acceptedPack).isEmpty());
File rejectedPack = temporaryFolder.newFolder("rejected-pack");
write(rejectedPack, "dimensions/main.json", "{\"loot\":{\"multiplier\":16.01,\"tables\":[]}}");
assertEquals(List.of("Dimension 'main'.loot.multiplier must be a finite number from 0 to 16."),
PackLootValidator.validateLootGraph(rejectedPack).errors());
errors(rejectedPack));
}
@Test
@@ -88,7 +90,7 @@ public class PackValidatorLootTest {
write(pack, "loot/boundary.json", "{\"minPicked\":64,\"maxPicked\":64,\"maxTries\":256,"
+ "\"loot\":[{\"type\":\"stone\",\"minAmount\":64,\"maxAmount\":64}]}");
assertTrue(PackLootValidator.validateLootGraph(pack).errors().isEmpty());
assertTrue(errors(pack).isEmpty());
}
@Test
@@ -97,7 +99,7 @@ public class PackValidatorLootTest {
write(pack, "loot/excessive.json", "{\"minPicked\":65,\"maxPicked\":65,\"maxTries\":257,"
+ "\"loot\":[{\"type\":\"stone\",\"minAmount\":65,\"maxAmount\":65}]}");
List<String> errors = PackLootValidator.validateLootGraph(pack).errors();
List<String> errors = errors(pack);
assertTrue(errors.contains("Loot table 'excessive'.minPicked must be at most 64."));
assertTrue(errors.contains("Loot table 'excessive'.maxPicked must be at most 64."));
@@ -127,12 +129,11 @@ public class PackValidatorLootTest {
write(pack, "loot/t.json", "{\"loot\":[{\"type\":\"minecraft:stone\"}]}");
write(pack, "biomes/x.json", "{\"loot\":{\"mode\":\"CLEAR\",\"tables\":[\"t\"]}}");
PackLootValidator.LootGraphIssues issues = PackLootValidator.validateLootGraph(pack);
assertTrue(issues.errors().isEmpty());
assertTrue(errors(pack).isEmpty());
assertEquals(List.of("Biome 'x'.loot uses mode CLEAR and lists 1 table(s); CLEAR clears parent tables"
+ " and contributes no tables of its own, so these entries are dead. Use REPLACE to substitute them."),
issues.warnings());
warnings(pack));
}
@Test
@@ -140,12 +141,23 @@ public class PackValidatorLootTest {
File pack = temporaryFolder.newFolder("clear-dangling");
write(pack, "biomes/x.json", "{\"loot\":{\"mode\":\"CLEAR\",\"tables\":[\"missing\"]}}");
PackLootValidator.LootGraphIssues issues = PackLootValidator.validateLootGraph(pack);
assertTrue(issues.errors().contains(
assertTrue(errors(pack).contains(
"Biome 'x'.loot.tables[0] references missing loot table 'missing'."));
}
private static List<String> errors(File pack) {
return messages(pack, Severity.ERROR);
}
private static List<String> warnings(File pack) {
return messages(pack, Severity.WARNING);
}
private static List<String> messages(File pack, Severity severity) {
return LootValidator.check(pack).stream().filter(problem -> problem.severity() == severity).map(Problem::message).toList();
}
private void write(File root, String relative, String content) throws Exception {
File file = new File(root, relative);
Files.createDirectories(file.toPath().getParent());
@@ -0,0 +1,84 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.procedural.tree.IrisTreeSettings;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import com.volmit.service.SaplingGrowth;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import org.junit.Before;
import org.junit.Test;
import java.util.Optional;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** Trees only replace the platform's growth when the dimension asks for it and a placement of the area grows that species. */
public class TreeGrowingTest {
private static final SaplingGrowth.Sapling OAK_SAPLING = new SaplingGrowth.Sapling(
new BlockPosition(10, 70, 20), new BlockPosition(10, 70, 20), "TREE");
private Engine engine;
private IrisDimension dimension;
private PackWorld world;
@Before
public void buildWorld() {
engine = mock(Engine.class);
dimension = mock(IrisDimension.class);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getData()).thenReturn(mock(IrisData.class));
world = new EngineGeneration(engine).world();
}
@Test
public void aDimensionWithoutTreeOverridesLeavesTheGrowthToThePlatform() {
when(dimension.getTreeSettings()).thenReturn(new IrisTreeSettings());
Optional<SaplingGrowth.Growth> growth = new TreeGrowing().grow(world, OAK_SAPLING, mock(SaplingGrowth.Surroundings.class));
assertTrue(growth.isEmpty());
verify(engine, never()).getBiome(anyInt(), anyInt(), anyInt());
}
@Test
public void withoutAPlacementThatGrowsTheSpeciesTheGrowthIsLeftToThePlatform() {
when(dimension.getTreeSettings()).thenReturn(new IrisTreeSettings().setEnabled(true));
IrisBiome biome = new IrisBiome();
biome.getObjects().add(new IrisObjectPlacement());
when(engine.getBiome(10, 70, 20)).thenReturn(biome);
when(engine.getRegion(10, 20)).thenReturn(new IrisRegion());
Optional<SaplingGrowth.Growth> growth = new TreeGrowing().grow(world, OAK_SAPLING, mock(SaplingGrowth.Surroundings.class));
assertTrue(growth.isEmpty());
}
}
@@ -1,15 +0,0 @@
package art.arcane.iris.engine.object.entity;
import art.arcane.iris.engine.object.entity.IrisEntitySpawn;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import org.junit.Test;
import static org.junit.Assert.assertNull;
public class IrisEntitySpawnTest {
@Test
public void caveSpawnWithoutSafeMarkerIsSkipped() {
assertNull(IrisEntitySpawn.selectCaveSpawnLocation(new KList<>(), null, new RNG(1L)));
}
}
@@ -4,9 +4,10 @@ import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.prefab.IrisObjectPlacementScaleInterpolator;
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.volmlib.util.math.RNG;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -20,13 +21,13 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IrisObjectScaleCacheTest {
private static final IrisObjectScale.ScaleRequest REQUEST = new IrisObjectScale.ScaleRequest(
@@ -37,55 +38,56 @@ public class IrisObjectScaleCacheTest {
IrisObjectPlacementScaleInterpolator.NONE
);
private Engine engine;
@Before
public void setUp() {
IrisObjectScale.invalidate(null);
engine = mock(Engine.class);
when(engine.getData()).thenReturn(mock(IrisData.class));
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
}
@After
public void tearDown() {
IrisObjectScale.invalidate(null);
private int cacheEntryCount() {
return IrisObjectScale.cacheOf(engine).size();
}
private long cacheEstimatedBytes() {
return IrisObjectScale.cacheOf(engine).estimatedBytes();
}
@Test
public void mutatedOriginCreatesStableReplacementAndCanBeReleased() {
public void mutatedOriginCreatesStableReplacement() {
IrisObject origin = new IrisObject(2, 2, 2);
IrisObjectScale scale = new IrisObjectScale().setSize(2D);
IrisObject first = scale.get(new RNG(1L), origin);
IrisObject first = scale.get(new RNG(1L), origin, engine);
IrisObjectScale.ScaleCache keyCache = new IrisObjectScale.ScaleCache(10L);
IrisObjectScale.CacheKey originalKey = keyCache.key(origin, REQUEST, 0);
int originalHash = originalKey.hashCode();
origin.setW(3);
IrisObject second = scale.get(new RNG(1L), origin);
IrisObject second = scale.get(new RNG(1L), origin, engine);
assertEquals(originalHash, originalKey.hashCode());
assertNotEquals(originalKey, keyCache.key(origin, REQUEST, 0));
assertNotSame(first, second);
assertNotEquals(first.getW(), second.getW());
assertEquals(2, IrisObjectScale.cacheEntryCount());
IrisObjectScale.invalidate(null);
assertEquals(0, IrisObjectScale.cacheEntryCount());
assertEquals(0L, IrisObjectScale.cacheEstimatedBytes());
assertFalse(IrisObjectScale.isOriginCached(origin));
assertEquals(2, cacheEntryCount());
}
@Test
public void voxelMutationReplacesCachedVariants() {
IrisObject origin = new IrisObject(2, 2, 2);
IrisObjectScale scale = new IrisObjectScale().setSize(2D);
IrisObject empty = scale.get(new RNG(1L), origin);
IrisObject empty = scale.get(new RNG(1L), origin, engine);
origin.setUnsigned(0, 0, 0, mock(PlatformBlockState.class));
IrisObject populated = scale.get(new RNG(1L), origin);
IrisObject populated = scale.get(new RNG(1L), origin, engine);
assertEquals(0, empty.getBlocks().size());
assertTrue(populated.getBlocks().size() > 0);
assertNotSame(empty, populated);
assertEquals(2, IrisObjectScale.cacheEntryCount());
assertEquals(2, cacheEntryCount());
}
@Test
@@ -97,18 +99,18 @@ public class IrisObjectScaleCacheTest {
.setMaximumScale(2D);
SequenceRng rng = new SequenceRng();
IrisObject first = scale.get(rng, origin);
IrisObject second = scale.get(rng, origin);
IrisObject third = scale.get(rng, origin);
IrisObject fourth = scale.get(rng, origin);
IrisObject repeated = scale.get(rng, origin);
IrisObject first = scale.get(rng, origin, engine);
IrisObject second = scale.get(rng, origin, engine);
IrisObject third = scale.get(rng, origin, engine);
IrisObject fourth = scale.get(rng, origin, engine);
IrisObject repeated = scale.get(rng, origin, engine);
assertSame(first, repeated);
assertNotEquals(first.getW(), second.getW());
assertNotEquals(second.getW(), third.getW());
assertNotEquals(third.getW(), fourth.getW());
assertEquals(4, IrisObjectScale.cacheEntryCount());
assertTrue(IrisObjectScale.cacheEstimatedBytes() > 0L);
assertEquals(4, cacheEntryCount());
assertTrue(cacheEstimatedBytes() > 0L);
}
@Test
@@ -116,12 +118,12 @@ public class IrisObjectScaleCacheTest {
OverweightScaleObject origin = new OverweightScaleObject();
IrisObjectScale scale = new IrisObjectScale().setSize(2D);
IrisObject result = scale.get(new RNG(1L), origin);
IrisObject result = scale.get(new RNG(1L), origin, engine);
assertEquals(1_000, result.getW());
assertEquals(1, origin.scaleCalls.get());
assertEquals(0, IrisObjectScale.cacheEntryCount());
assertEquals(0L, IrisObjectScale.cacheEstimatedBytes());
assertEquals(0, cacheEntryCount());
assertEquals(0L, cacheEstimatedBytes());
}
@Test
@@ -133,12 +135,12 @@ public class IrisObjectScaleCacheTest {
AtomicReference<Thread> secondThread = new AtomicReference<>();
try {
Future<IrisObject> first = executor.submit(() -> scale.get(new RNG(1L), origin));
Future<IrisObject> first = executor.submit(() -> scale.get(new RNG(1L), origin, engine));
assertTrue(origin.firstScaleEntered.await(5L, TimeUnit.SECONDS));
Future<IrisObject> second = executor.submit(() -> {
secondThread.set(Thread.currentThread());
secondInvoked.countDown();
return scale.get(new RNG(1L), origin);
return scale.get(new RNG(1L), origin, engine);
});
assertTrue(secondInvoked.await(5L, TimeUnit.SECONDS));
@@ -171,15 +173,15 @@ public class IrisObjectScaleCacheTest {
put(cache, firstKey, new IrisObject(1, 1, 1), 4L);
put(cache, secondKey, new IrisObject(1, 1, 1), 4L);
assertTrue(cache.lookup(firstKey).variant() != null);
assertTrue(cache.lookup(firstKey) != null);
put(cache, thirdKey, new IrisObject(1, 1, 1), 4L);
assertEquals(2, cache.size());
assertEquals(8L, cache.estimatedBytes());
assertTrue(cache.estimatedBytes() <= cache.maximumEstimatedBytes());
assertTrue(cache.lookup(firstKey).variant() != null);
assertNull(cache.lookup(secondKey).variant());
assertTrue(cache.lookup(thirdKey).variant() != null);
assertTrue(cache.lookup(firstKey) != null);
assertNull(cache.lookup(secondKey));
assertTrue(cache.lookup(thirdKey) != null);
}
@Test
@@ -188,55 +190,14 @@ public class IrisObjectScaleCacheTest {
IrisObject origin = new IrisObject(1, 1, 1);
IrisObjectScale.CacheKey key = key(origin);
IrisObject variant = new IrisObject(1, 1, 1);
IrisObjectScale.CacheLookup lookup = cache.lookup(key);
IrisObject result = cache.putIfCurrent(key, variant, 11L, lookup.generation());
IrisObject result = cache.putIfAbsent(key, variant, 11L);
assertSame(variant, result);
assertEquals(0, cache.size());
assertEquals(0L, cache.estimatedBytes());
}
@Test
public void invalidationReleasesOnlyTheRequestedRuntime() {
IrisObjectScale.ScaleCache cache = new IrisObjectScale.ScaleCache(20L);
IrisData firstOwner = mock(IrisData.class);
IrisData secondOwner = mock(IrisData.class);
IrisObject firstOrigin = new IrisObject(1, 1, 1);
IrisObject secondOrigin = new IrisObject(1, 1, 1);
firstOrigin.setLoader(firstOwner);
secondOrigin.setLoader(secondOwner);
IrisObjectScale.CacheKey firstKey = key(firstOrigin);
IrisObjectScale.CacheKey secondKey = key(secondOrigin);
put(cache, firstKey, new IrisObject(1, 1, 1), 5L);
put(cache, secondKey, new IrisObject(1, 1, 1), 5L);
cache.invalidate(firstOwner);
assertNull(cache.lookup(firstKey).variant());
assertTrue(cache.lookup(secondKey).variant() != null);
assertEquals(1, cache.size());
assertEquals(5L, cache.estimatedBytes());
}
@Test
public void invalidationRejectsAnInFlightStaleInsertion() {
IrisObjectScale.ScaleCache cache = new IrisObjectScale.ScaleCache(10L);
IrisData owner = mock(IrisData.class);
IrisObject origin = new IrisObject(1, 1, 1);
origin.setLoader(owner);
IrisObjectScale.CacheKey key = key(origin);
IrisObjectScale.CacheLookup lookup = cache.lookup(key);
cache.invalidate(owner);
cache.putIfCurrent(key, new IrisObject(1, 1, 1), 5L, lookup.generation());
assertEquals(0, cache.size());
assertEquals(0L, cache.estimatedBytes());
assertNull(cache.lookup(key).variant());
}
@Test
public void collectedOriginReleasesScaledValueWithOwnerReference() {
IrisObjectScale.ScaleCache cache = new IrisObjectScale.ScaleCache(20L);
@@ -261,8 +222,7 @@ public class IrisObjectScaleCacheTest {
private static void put(IrisObjectScale.ScaleCache cache, IrisObjectScale.CacheKey key,
IrisObject variant, long estimatedBytes) {
IrisObjectScale.CacheLookup lookup = cache.lookup(key);
cache.putIfCurrent(key, variant, estimatedBytes, lookup.generation());
cache.putIfAbsent(key, variant, estimatedBytes);
}
private static final class BlockingScaleObject extends IrisObject {
@@ -0,0 +1,169 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.spawn;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.ModuleResourceFixture;
import art.arcane.iris.engine.UsableBlockPlatform;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.object.entity.IrisEntity;
import art.arcane.iris.engine.object.entity.IrisEntitySpawn;
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
import art.arcane.iris.engine.object.marker.IrisMarker;
import art.arcane.iris.engine.object.world.IrisWorld;
import art.arcane.iris.spi.PlatformWorld;
import art.arcane.volmlib.util.collection.KList;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemRegistry;
import com.volmit.service.EntitySpawns;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** What the spawn module plans for markers, and what its markers mean. */
public class EntitySpawningTest {
private static final BlockPosition MARKER_BLOCK = new BlockPosition(40, 70, -12);
private Engine engine;
private ModuleResourceFixture fixture;
private PackWorld world;
@BeforeClass
public static void bindPlatform() {
UsableBlockPlatform.bind();
}
@AfterClass
public static void unbindPlatform() {
UsableBlockPlatform.unbind();
}
@Before
public void buildWorld() {
engine = mock(Engine.class);
IrisData data = mock(IrisData.class);
when(engine.getData()).thenReturn(data);
fixture = ModuleResourceFixture.serve(data);
when(data.getPackResources().items()).thenReturn(mock(ItemRegistry.class));
IrisWorld engineWorld = mock(IrisWorld.class);
when(engineWorld.platformWorld()).thenReturn(mock(PlatformWorld.class));
when(engine.getWorld()).thenReturn(engineWorld);
SeedManager seeds = mock(SeedManager.class);
when(seeds.getEntity()).thenReturn(11L);
when(engine.getSeedManager()).thenReturn(seeds);
world = new EngineGeneration(engine).world();
}
@Test
public void aCaveWithoutFloorMarkersHasNowhereToSpawn() {
EngineMantle mantle = mock(EngineMantle.class);
when(engine.getMantle()).thenReturn(mantle);
when(mantle.findMarkers(2, 3, art.arcane.volmlib.util.matter.slices.MarkerMatter.CAVE_FLOOR)).thenReturn(new KList<>());
assertNull(EntitySpawning.caveSpawnPosition(engine, 2, 3));
}
@Test
public void aMarkerMeansItsSpawnersAndWhetherItGoesAwayWhenItsBlockChanges() {
IrisMarker marker = new IrisMarker();
marker.setSpawners(new KList<>("zombies", "missing")).setEmptyAbove(true).setRemoveOnChange(false);
fixture.resource(SpawnResources.MARKERS, "camp", marker);
fixture.resource(SpawnResources.SPAWNERS, "zombies", new IrisSpawner());
EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, "camp").orElseThrow();
assertEquals(List.of("zombies"), rule.spawners());
assertTrue(rule.emptyAbove());
assertFalse(rule.removeOnChange());
}
@Test
public void markersNoModuleKnowsAndTheCaveMarkersMeanNothing() {
assertTrue(new EntitySpawning().marker(world, "unknown").isEmpty());
assertTrue(new EntitySpawning().marker(world, "cave_floor").isEmpty());
}
@Test
public void aMarkerSpawnPlansEntitiesOneBlockAboveTheMarkerWithoutSurfaceChecks() {
IrisSpawner spawner = new IrisSpawner();
spawner.setLoadKey("camp/zombies");
spawner.getSpawns().add(new IrisEntitySpawn().setEntity("zombie").setMinSpawns(2).setMaxSpawns(2));
fixture.resource(SpawnResources.SPAWNERS, "camp/zombies", spawner);
IrisMarker marker = new IrisMarker();
marker.setExhaustionChance(2);
fixture.resource(SpawnResources.MARKERS, "camp", marker);
IrisEntity zombie = new IrisEntity();
zombie.setType("minecraft:zombie");
fixture.resource(SpawnResources.ENTITIES, "zombie", zombie);
when(engine.getMinHeight()).thenReturn(-64);
EntitySpawns.Plan plan = new EntitySpawning()
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "camp/zombies", false))
.orElseThrow();
assertEquals("camp/zombies", plan.spawner());
assertTrue("an exhaustion chance above 1 always uses the marker up", plan.exhaustsMarker());
assertEquals(2, plan.attempts().size());
for (EntitySpawns.Attempt attempt : plan.attempts()) {
assertEquals(new BlockPosition(40, 71, -12), attempt.at());
assertFalse(attempt.checkSurface());
assertEquals("minecraft:zombie", attempt.entity().type());
}
}
@Test
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
IrisSpawner empty = new IrisSpawner();
fixture.resource(SpawnResources.SPAWNERS, "empty", empty);
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "empty", false));
assertTrue(plan.isEmpty());
}
@Test
public void anEntityOfThePackResolvesToTheSpecTheHostSpawns() {
IrisEntity entity = new IrisEntity();
entity.setType("minecraft:cow").setCustomName("&6Bessie").setBaby(true);
fixture.resource(SpawnResources.ENTITIES, "cow", entity);
EntitySpec spec = new EntitySpawning().entity(world, "cow").orElseThrow();
assertEquals("minecraft:cow", spec.type());
assertEquals("&6Bessie", spec.customName());
assertTrue(spec.flags().baby());
assertTrue(new EntitySpawning().entity(world, "nothing").isEmpty());
}
}
@@ -0,0 +1,104 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.spawn;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.entity.IrisEntity;
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
import art.arcane.iris.engine.object.marker.IrisMarker;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
/** Spawners, entities and markers are resource kinds of module {@code iris:spawn}, read from the folders packs have always had. */
public class SpawnResourcesTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void theSpawnModuleOwnsTheKinds() throws Exception {
IrisData data = IrisData.openValidation(spawnPack("owned").toFile());
try {
var catalog = data.getModules().pack().catalog();
var kinds = catalog.resourceKinds().stream().map(registration -> registration.kind())
.filter(kind -> kind.id().toString().startsWith("iris:spawn/")).toList();
assertEquals(List.of("iris:spawn/entity", "iris:spawn/marker", "iris:spawn/spawner"), kinds.stream().map(kind -> kind.id().toString()).toList());
assertEquals(List.of("entities", "markers", "spawners"), kinds.stream().map(kind -> kind.folder()).toList());
assertFalse(data.getLoaders().containsKey(IrisSpawner.class));
assertFalse(data.getLoaders().containsKey(IrisEntity.class));
assertFalse(data.getLoaders().containsKey(IrisMarker.class));
} finally {
data.close();
}
}
@Test
public void spawnersEntitiesAndMarkersAreReadThroughPackResources() throws Exception {
Path pack = spawnPack("spawns");
IrisData data = IrisData.openValidation(pack.toFile());
try {
IrisSpawner spawner = SpawnResources.spawner(data, "camp/zombies");
assertEquals("camp/zombies", spawner.getLoadKey());
assertEquals(pack.resolve("spawners/camp/zombies.json").toFile(), spawner.getLoadFile());
assertEquals("minecraft:zombie", SpawnResources.entity(data, "zombie").getType());
assertEquals(List.of("camp/zombies"), SpawnResources.marker(data, "camp").getSpawners());
assertEquals(List.of(spawner), SpawnResources.spawners(data, List.of("camp/zombies", "missing")));
assertEquals(List.of("zombie"), SpawnResources.entityKeys(data));
assertEquals(List.of("camp"), SpawnResources.markerKeys(data));
assertEquals(List.of("camp/zombies"), SpawnResources.spawnerKeys(data));
assertNull(SpawnResources.spawner(data, "missing"));
assertNull(SpawnResources.entity(data, " "));
write(pack, "entities/zombie.json", "{\"type\":\"minecraft:husk\"}");
data.dump();
assertEquals("minecraft:husk", SpawnResources.entity(data, "zombie").getType());
} finally {
data.close();
}
}
private Path spawnPack(String name) throws Exception {
File pack = temporaryFolder.newFolder(name);
write(pack.toPath(), "dimensions/main.json", "{\"regions\":[\"region\"]}");
write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}");
write(pack.toPath(), "entities/zombie.json", "{\"type\":\"minecraft:zombie\"}");
write(pack.toPath(), "spawners/camp/zombies.json", "{\"spawns\":[{\"entity\":\"zombie\"}]}");
write(pack.toPath(), "markers/camp.json", "{\"spawners\":[\"camp/zombies\"]}");
return pack.toPath();
}
private static void write(Path root, String relative, String content) throws Exception {
Path path = root.resolve(relative);
Files.createDirectories(path.getParent());
Files.writeString(path, content, StandardCharsets.UTF_8);
}
}
@@ -89,8 +89,7 @@ import static org.junit.Assert.fail;
* deleted) and {@code Particles} (Bukkit registry lookups in a static initializer).
* <p>
* <b>Deliberately not asserted:</b> method and constructor descriptors. These classes legitimately
* expose a Bukkit-typed edge that only the Bukkit adapter calls - {@code IrisEntity.spawn(Engine,
* Location)}, {@code IrisLoot.get(...) -> ItemStack}, {@code IrisObjectRotation.rotate(BlockData,
* expose a Bukkit-typed edge that only the Bukkit adapter calls - {@code IrisObjectRotation.rotate(BlockData,
* ...)}, {@code TileData.toBukkit(Block)} and ~60 more. Method descriptors are resolved at
* invocation, never at class load, field walk or equals/hashCode/toString, so they are not a modded
* boot hazard. Fields and supertypes are, and both are asserted hard below.
@@ -110,15 +109,11 @@ public class PackTypeBukkitPurityGateTest {
* #registeredRootListMatchesIrisData()} fails if the source drifts away from it.
*/
private static final List<String> GSON_REGISTERED_ROOTS = List.of(
"art.arcane.iris.engine.object.loot.IrisLootTable",
"art.arcane.iris.engine.object.entity.spawn.IrisSpawner",
"art.arcane.iris.engine.object.entity.IrisEntity",
"art.arcane.iris.engine.object.world.region.IrisRegion",
"art.arcane.iris.engine.object.world.biome.IrisBiome",
"art.arcane.iris.engine.object.mod.IrisMod",
"art.arcane.iris.engine.object.world.dimension.IrisDimension",
"art.arcane.iris.engine.object.terrain.IrisGenerator",
"art.arcane.iris.engine.object.marker.IrisMarker",
"art.arcane.iris.engine.object.material.IrisBlockData",
"art.arcane.iris.engine.object.noise.expression.IrisExpression",
"art.arcane.iris.engine.object.prefab.IrisObject",
@@ -133,7 +128,11 @@ public class PackTypeBukkitPurityGateTest {
private static final List<String> MODULE_RESOURCE_ROOTS = List.of(
"art.arcane.iris.engine.object.structure.IrisStructure",
"art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool",
"art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece");
"art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece",
"art.arcane.iris.engine.object.loot.IrisLootTable",
"art.arcane.iris.engine.object.entity.spawn.IrisSpawner",
"art.arcane.iris.engine.object.entity.IrisEntity",
"art.arcane.iris.engine.object.marker.IrisMarker");
/**
* Types reachable from a pack that are not roots and carry no {@code @Snippet}, but are
@@ -145,8 +144,9 @@ public class PackTypeBukkitPurityGateTest {
"art.arcane.iris.engine.object.loot.IrisVanillaLootTable");
/**
* Bukkit-registry constant holders that a core pack type references, so their class initializer
* runs on the modded loaders too. {@code Particles} is statically imported by {@code IrisEntity}.
* Bukkit-registry constant holders that a core pack type may reference, so their class initializer
* must run on the modded loaders too. {@code Particles} is used by the Bukkit entity spawner now; it stays in the
* gate so that a pack type importing it again keeps working.
* ({@code Materials} and {@code Attributes} have the same shape but are only reachable from the
* Bukkit adapter, so they stay out of the gate.)
*/
@@ -1,11 +1,10 @@
package art.arcane.iris.util.project.matter;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.core.modules.ModuleResourceFixture;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
import art.arcane.iris.util.project.matter.slices.SpawnerMatter;
import art.arcane.volmlib.util.collection.KMap;
import org.junit.Test;
import java.io.ByteArrayInputStream;
@@ -18,7 +17,6 @@ import java.util.concurrent.Future;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class RegistryMatterContextTest {
@Test
@@ -49,14 +47,9 @@ public class RegistryMatterContextTest {
}
}
@SuppressWarnings("unchecked")
private IrisData dataReturning(IrisSpawner resolved) {
ResourceLoader<IrisSpawner> loader = mock(ResourceLoader.class);
when(loader.load("test-spawner")).thenReturn(resolved);
KMap<Class<? extends IrisRegistrant>, ResourceLoader<? extends IrisRegistrant>> loaders = new KMap<>();
loaders.put(IrisSpawner.class, loader);
IrisData data = mock(IrisData.class);
when(data.getLoaders()).thenReturn(loaders);
ModuleResourceFixture.serve(data).resource(SpawnResources.SPAWNERS, "test-spawner", resolved);
return data;
}
}