Iris exposes VolmLib and Gson to pack modules; iris:post, iris:perfection and iris:matter leave the compiled-in built-ins for the built-ins jar; tests load them from a pack's modules folder and through the API alone

This commit is contained in:
piexel committed 2026-10-10 13:10:24 +02:00
1 parent bdf1389d77
commit 213bdf9842
16 files changed
+1165 -200

No files matched your search

+1
View File
@@ -125,6 +125,7 @@ tasks.named('test').configure {
systemProperty('iris.irisToolbeltSource', file('src/main/java/art/arcane/iris/core/tools/IrisToolbelt.java').absolutePath)
systemProperty('iris.irisCreatorSource', file('src/main/java/art/arcane/iris/core/tools/IrisCreator.java').absolutePath)
systemProperty('iris.bukkitChunkGeneratorSource', file('src/main/java/art/arcane/iris/engine/platform/BukkitChunkGenerator.java').absolutePath)
systemProperty('iris.builtinModulesList', rootProject.file('../IrisModule/builtin-modules.txt').absolutePath)
}
java {
@@ -30,9 +30,6 @@ import art.arcane.iris.engine.modifier.CarveModule;
import art.arcane.iris.engine.modifier.CustomModule;
import art.arcane.iris.engine.modifier.DepositModule;
import art.arcane.iris.engine.modifier.FloatingModule;
import art.arcane.iris.engine.modifier.MatterModule;
import art.arcane.iris.engine.modifier.PerfectionModule;
import art.arcane.iris.engine.modifier.PostModule;
import art.arcane.iris.engine.object.placement.PlacementModules;
import art.arcane.iris.spi.IrisPlatforms;
import com.volmit.IrisModule;
@@ -44,14 +41,24 @@ import java.util.List;
import java.util.stream.Stream;
/**
* The one {@link ModuleHost} every pack load uses: Iris's built-in modules, the built-in module API
* package exposed to packs, Iris's own JSON fields, Iris's pack object
* The one {@link ModuleHost} every pack load uses: Iris's built-in modules, the packages exposed to packs (the
* built-in module API and the libraries Iris shares), Iris's own JSON fields, Iris's pack object
* model as host types, the pack folders Iris reads itself, a jar copy directory under the plugin's cache, and
* Iris's log.
* <p>
* The built-in modules that are already ported ship in the built-ins jar ({@code IrisModule/builtin-modules.txt}), which a
* pack puts into its {@code modules} folder like any pack module; they are not listed here.
*/
public final class IrisModuleHost {
/** Exposed to pack modules, with its subpackages; see its package documentation. */
public static final String BUILT_IN_API_PACKAGE = "art.arcane.iris.builtin";
/**
* Libraries pack modules may call besides the IrisApi, each with its subpackages: VolmLib, which Iris shades unrelocated,
* and Gson, which every platform Iris runs on provides.
*/
public static final List<String> SHARED_LIBRARY_PACKAGES = List.of("art.arcane.volmlib", "com.google.gson");
/** Every package pack modules may use besides the IrisApi. {@code exposedHostPackages} in IrisModule's build lists the same. */
public static final List<String> EXPOSED_PACKAGES = Stream.concat(Stream.of(BUILT_IN_API_PACKAGE), SHARED_LIBRARY_PACKAGES.stream()).toList();
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
@@ -71,8 +78,7 @@ public final class IrisModuleHost {
private static List<IrisModule> generationModules() {
return List.of(new BiomeModule(), new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
new PostModule(), new FloatingModule(), new DepositModule(), new MatterModule(), new DecorantModule(),
new PerfectionModule(), new CustomModule(), new LootModule(), new SpawnModule());
new FloatingModule(), new DepositModule(), new DecorantModule(), new CustomModule(), new LootModule(), new SpawnModule());
}
/** Whether {@code type} is one of Iris's own classes that built-in settings may hold. */
@@ -82,7 +88,7 @@ public final class IrisModuleHost {
private static ModuleHost build() {
return ModuleHost.of(builtInModules())
.exposing(BUILT_IN_API_PACKAGE)
.exposing(EXPOSED_PACKAGES.toArray(String[]::new))
.reservingFields(ModuleTargets.reservedFields())
.describingHostTypesIn(HOST_TYPE_PACKAGE)
.reservingFolders(IrisData.ownFolderNames().toArray(String[]::new))
@@ -32,7 +32,7 @@ import com.volmit.block.BlockFace;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.LoadedModules;
import com.volmit.host.ModuleRegistry;
import com.volmit.host.ServiceRegistration;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.ResourceId;
@@ -84,10 +84,11 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
() -> engine.getGeneration().world());
}
/** The built-in modules' registrations only: their stage graph needs the modules of the built-ins jar too. */
public static NativeStructureFitting builtInModules() {
List<DiscoveredModule> modules = IrisModuleHost.builtInModules().stream().map(DiscoveredModule::builtIn).toList();
LoadedModules loaded = LoadedModules.load(modules, Map.of(), List.of(IrisModuleHost.HOST_TYPE_PACKAGE), List.of());
return new ModuleStructureFitting(loaded.catalog().registrations(VanillaStructures.class), () -> {
ModuleRegistry registry = new ModuleRegistry();
IrisModuleHost.builtInModules().forEach(module -> registry.register(DiscoveredModule.builtIn(module)));
return new ModuleStructureFitting(registry.freeze().registrations(VanillaStructures.class), () -> {
throw new IllegalStateException("The built-in modules fit outside a world here: a start needs its memo"
+ " and a fit without palettes");
});
@@ -0,0 +1,92 @@
/*
* 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 java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Stream;
/**
* The built-ins jar as IrisModule's {@code builtinModulesJar} packages it, written from the classes this test run compiled:
* every class {@code builtin-modules.txt} lists ({@code module} lines with their nested classes, {@code include} patterns)
* and the entry points in order. Tests load it from a pack's {@code modules} folder without building IrisModule.
*/
final class BuiltInModulesJar {
private static final String LIST_PROPERTY = "iris.builtinModulesList";
private static final String SERVICE_ENTRY = "META-INF/services/com.volmit.IrisModule";
private static final String JAR_NAME = "iris-builtins.jar";
private BuiltInModulesJar() {
}
/** Writes {@code <pack>/modules/iris-builtins.jar} and returns its entry classes. */
static List<String> writeInto(Path pack) throws IOException {
List<String> modules = new ArrayList<>();
List<PathMatcher> classes = new ArrayList<>();
for (String line : Files.readAllLines(Path.of(System.getProperty(LIST_PROPERTY)))) {
String entry = line.replaceAll("#.*", "").trim();
if (entry.startsWith("module ")) {
String module = entry.substring("module ".length()).trim();
modules.add(module);
String path = module.replace('.', '/');
classes.add(glob(path + ".class"));
classes.add(glob(path + "$*.class"));
} else if (entry.startsWith("include ")) {
classes.add(glob(entry.substring("include ".length()).trim()));
}
}
Path root = classRoot();
Path jar = Files.createDirectories(pack.resolve("modules")).resolve(JAR_NAME);
try (JarOutputStream output = new JarOutputStream(Files.newOutputStream(jar)); Stream<Path> files = Files.walk(root)) {
for (Path file : files.filter(Files::isRegularFile).sorted().toList()) {
Path relative = root.relativize(file);
if (classes.stream().anyMatch(matcher -> matcher.matches(relative))) {
output.putNextEntry(new JarEntry(relative.toString().replace('\\', '/')));
output.write(Files.readAllBytes(file));
output.closeEntry();
}
}
output.putNextEntry(new JarEntry(SERVICE_ENTRY));
output.write((String.join("\n", modules) + "\n").getBytes(StandardCharsets.UTF_8));
output.closeEntry();
}
return modules;
}
private static PathMatcher glob(String pattern) {
return FileSystems.getDefault().getPathMatcher("glob:" + pattern);
}
private static Path classRoot() {
try {
return Path.of(IrisModuleHost.class.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (URISyntaxException e) {
throw new IllegalStateException("Iris's classes are not in a folder this test can read", e);
}
}
}
@@ -0,0 +1,125 @@
/*
* 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.core.loader.IrisData;
import art.arcane.iris.engine.modifier.ApiChunk;
import art.arcane.iris.engine.modifier.MatterModule;
import com.volmit.IrisModule;
import com.volmit.block.BlockState;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.LoadedPack;
import com.volmit.host.ModuleHost;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import static art.arcane.iris.engine.modifier.ApiChunk.block;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.mockito.Mockito.mock;
/**
* The ported built-ins load from a pack's {@code modules/iris-builtins.jar} through the pack loader, seeing only what a pack
* module sees, and generate the same chunk as their compiled-in copies.
*/
public class BuiltInModulesJarTest {
private static final int HEIGHT = 64;
private static final int GROUND = 20;
private static final int UPPER_DIMENSION = 50;
private static final BlockState STONE = block("minecraft:stone");
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Test
public void theJarsModulesComeFromThePackLoaderInTheListedOrder() throws IOException {
Path pack = BuiltInPack.newPackFolder(folder);
List<String> listed = BuiltInModulesJar.writeInto(pack);
try (LoadedPack loaded = loadWithStandIns(pack)) {
List<DiscoveredModule> fromJar = loaded.packModules();
assertEquals(listed, fromJar.stream().map(module -> module.module().getClass().getName()).toList());
fromJar.forEach(module -> assertNotSame(MatterModule.class.getClassLoader(), module.module().getClass().getClassLoader()));
}
}
@Test
public void theJarsModulesGenerateWhatTheirCompiledInCopiesGenerate() throws IOException {
Path pack = BuiltInPack.newPackFolder(folder);
BuiltInModulesJar.writeInto(pack);
ApiChunk compiledIn = scene();
ApiChunk fromJar = scene();
compiledIn.generate(BuiltInPack.jarModules().toArray(IrisModule[]::new));
try (LoadedPack loaded = loadWithStandIns(pack)) {
fromJar.generate(loaded.chunk());
}
assertEquals("ores hide", STONE, fromJar.get(0, 5, 0));
assertEquals("planned blocks arrive below the dimension above", block("minecraft:oak_planks"), fromJar.get(0, UPPER_DIMENSION - 1, 0));
assertEquals(ApiChunk.AIR, fromJar.get(1, UPPER_DIMENSION, 0));
eachBlock(position -> assertEquals(Arrays.toString(position),
compiledIn.get(position[0], position[1], position[2]), fromJar.get(position[0], position[1], position[2])));
}
/** The jar next to stand-ins for the compiled-in stages it orders after, exposing what Iris exposes. */
private LoadedPack loadWithStandIns(Path pack) throws IOException {
return LoadedPack.load(pack, ModuleHost.of(ApiChunk.standIns())
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
.copyingJarsTo(folder.newFolder().toPath()));
}
/** A chunk every ported module has work in: a cliff, a step, a floating nib, ores, plants on stone, planned blocks. */
private static ApiChunk scene() {
ApiChunk chunk = new ApiChunk(0, 0, HEIGHT)
.surface((x, z) -> x < 4 ? GROUND + 6 : x == 8 && z == 8 ? GROUND + 9 : x > 11 ? GROUND + 1 : GROUND)
.upperDimension((x, z) -> UPPER_DIMENSION)
.fluidHeight(GROUND + 2);
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
int top = x < 4 ? GROUND + 6 : x > 11 ? GROUND + 1 : GROUND;
for (int y = 0; y <= top; y++) {
chunk.set(x, y, z, y == 5 ? block("minecraft:iron_ore") : STONE);
}
chunk.set(x, top + 1, z, block("minecraft:poppy"));
chunk.plan(x, UPPER_DIMENSION - 1 + (x & 1), z, block("minecraft:oak_planks"));
}
}
chunk.set(8, GROUND + 9, 8, STONE);
chunk.pending().hidingOres().walls(block("minecraft:cobblestone")).slabs(block("minecraft:stone_slab[type=bottom]"), 1);
return chunk;
}
private static void eachBlock(Consumer<int[]> check) {
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
check.accept(new int[]{x, y, z});
}
}
}
}
}
@@ -21,6 +21,9 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.modifier.MatterModule;
import art.arcane.iris.engine.modifier.PerfectionModule;
import art.arcane.iris.engine.modifier.PostModule;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.host.LoadedPack;
@@ -42,25 +45,43 @@ public final class BuiltInPack {
private BuiltInPack() {
}
/**
* Compiled-in copies of the built-in modules that ship in the built-ins jar ({@code IrisModule/builtin-modules.txt}), so tests
* that need Iris's whole generation graph get it without building the jar. Until the cut-over the classes are compiled
* with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead.
*/
public static List<IrisModule> jarModules() {
return List.of(new PostModule(), new PerfectionModule(), new MatterModule());
}
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
public static List<IrisModule> allBuiltIns() {
return Stream.concat(IrisModuleHost.builtInModules().stream(), jarModules().stream()).toList();
}
/** A new empty pack folder, to put module jars into (see {@link PackModuleJar}) before {@link #serve(IrisData, TemporaryFolder, Path, List)}. */
public static Path newPackFolder(TemporaryFolder folder) throws IOException {
return folder.newFolder().toPath();
}
/** Loads the pack and lets the mocked {@code data} serve it, as a pack's data serves its modules. Close it after the test. */
/**
* Loads every built-in ({@link #allBuiltIns()}) and {@code packModules} and lets the mocked {@code data} serve the pack, as a
* pack's data serves its modules. Close it after the test.
*/
public static LoadedPack serve(IrisData data, TemporaryFolder folder, List<IrisModule> packModules) throws IOException {
return serve(data, folder, newPackFolder(folder), packModules);
return serve(data, folder, newPackFolder(folder), Stream.concat(jarModules().stream(), packModules.stream()).toList());
}
/**
* Like {@link #serve(IrisData, TemporaryFolder, List)} for a pack folder whose {@code modules} folder may hold module jars:
* they load through the pack loader after the compiled-in built-ins and {@code packModules}, as in a real pack. The jars see the
* same packages a real pack's modules see.
* they load through the pack loader after Iris's compiled-in built-ins and {@code packModules}, as in a real pack. The jars see
* the same packages a real pack's modules see. The jar's built-ins are not added here: put them into {@code packModules}
* ({@link #jarModules()}) or the built-ins jar into the pack.
*/
public static LoadedPack serve(IrisData data, TemporaryFolder folder, Path packFolder, List<IrisModule> packModules) throws IOException {
List<IrisModule> modules = Stream.concat(IrisModuleHost.builtInModules().stream(), packModules.stream()).toList();
LoadedPack pack = LoadedPack.load(packFolder, ModuleHost.of(modules)
.exposing(IrisModuleHost.BUILT_IN_API_PACKAGE)
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
.reservingFields(ModuleTargets.reservedFields())
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE)
.copyingJarsTo(folder.newFolder().toPath()));
@@ -58,7 +58,7 @@ public class DecorantSettingsDecodingTest {
Path packFolder = folder.newFolder("pack").toPath();
Path snippets = Files.createDirectories(packFolder.resolve("snippet/decorator"));
Files.writeString(snippets.resolve("bush.json"), "{\"chance\": 0.2, \"palette\": [{\"block\": \"minecraft:fern\"}]}");
pack = LoadedPack.load(packFolder, ModuleHost.of(IrisModuleHost.builtInModules())
pack = LoadedPack.load(packFolder, ModuleHost.of(BuiltInPack.allBuiltIns())
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
}
@@ -62,7 +62,7 @@ public class DepositSettingsDecodingTest {
Path packFolder = folder.newFolder("pack").toPath();
Path snippets = Files.createDirectories(packFolder.resolve("snippet/deposit"));
Files.writeString(snippets.resolve("diamonds.json"), "{\"maxHeight\": 16, \"palette\": [{\"block\": \"minecraft:diamond_ore\"}]}");
pack = LoadedPack.load(packFolder, ModuleHost.of(IrisModuleHost.builtInModules())
pack = LoadedPack.load(packFolder, ModuleHost.of(BuiltInPack.allBuiltIns())
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
}
@@ -67,7 +67,7 @@ public class PackBeforeThePortDecodingTest {
@Before
public void loadBuiltIns() throws IOException, URISyntaxException {
packFolder = Path.of(PackBeforeThePortDecodingTest.class.getResource(PACK).toURI());
pack = LoadedPack.load(packFolder, ModuleHost.of(IrisModuleHost.builtInModules())
pack = LoadedPack.load(packFolder, ModuleHost.of(BuiltInPack.allBuiltIns())
.reservingFields(ModuleTargets.reservedFields())
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
@@ -0,0 +1,90 @@
/*
* 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.volmlib.util.math.RNG;
import com.google.gson.JsonParser;
import com.volmit.host.LoadedPack;
import com.volmit.host.ModuleHost;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
/** Pack modules call the libraries Iris shares with them, VolmLib and Gson, and get Iris's own classes of them. */
public class SharedLibrariesTest {
private static final String MODULE = "pack.shared.Shared";
private static final String SOURCE = """
package pack.shared;
import com.volmit.*;
import com.volmit.stage.*;
public final class Shared implements IrisModule {
public ModuleInfo info() { return ModuleInfo.of("example:shared", "Shared", "1"); }
public void install(StageGraph graph) {
new art.arcane.volmlib.util.math.RNG(7).nextInt();
com.google.gson.JsonParser.parseString("{\\"a\\": 1}");
}
public static Class<?>[] used() {
return new Class<?>[] {art.arcane.volmlib.util.math.RNG.class, com.google.gson.JsonParser.class};
}
}
""";
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Test
public void aPackModuleUsesIrissVolmLibAndGson() throws Exception {
Path pack = packWithSharedModule();
try (LoadedPack loaded = LoadedPack.load(pack, ModuleHost.of(List.of())
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
.copyingJarsTo(folder.newFolder().toPath()))) {
Object used = loaded.packModules().getFirst().module().getClass().getMethod("used").invoke(null);
assertArrayEquals(new Class<?>[]{RNG.class, JsonParser.class}, (Class<?>[]) used);
}
}
@Test
public void withoutTheLibrariesExposedTheyAreIrissHiddenClasses() throws IOException {
Path pack = packWithSharedModule();
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack,
ModuleHost.of(List.of()).exposing(IrisModuleHost.BUILT_IN_API_PACKAGE).copyingJarsTo(folder.newFolder().toPath())));
assertTrue(failure.getMessage(), failure.getMessage().contains("art.arcane.volmlib.util.math.RNG"));
assertTrue(failure.getMessage(), failure.getMessage().contains("com.google.gson.JsonParser"));
}
private Path packWithSharedModule() throws IOException {
Path pack = BuiltInPack.newPackFolder(folder);
PackModuleJar.write(pack, "shared.jar", MODULE, Map.of(MODULE, SOURCE));
return pack;
}
}
@@ -67,7 +67,7 @@ public class StructureSettingsDecodingTest {
@Before
public void loadBuiltIns() throws IOException {
Path packFolder = folder.newFolder("pack").toPath();
pack = LoadedPack.load(packFolder, ModuleHost.of(IrisModuleHost.builtInModules())
pack = LoadedPack.load(packFolder, ModuleHost.of(BuiltInPack.allBuiltIns())
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
}
@@ -66,6 +66,7 @@ import art.arcane.iris.core.modules.ModuleResourceFixture;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.FeatureRegistry;
import art.arcane.iris.core.modules.BuiltInPack;
import art.arcane.iris.core.modules.IrisModuleHost;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
@@ -813,10 +814,10 @@ public class SchemaBuilderParityTest {
/** What the pack tells studio when Iris's built-in modules and {@code extra} are loaded: Iris's classes hold built-in types. */
private static PackSchema schemaOfBuiltInsWith(IrisModule... extra) throws IOException {
Path root = Files.createTempDirectory("schema-pack");
List<IrisModule> modules = Stream.concat(IrisModuleHost.builtInModules().stream(), Stream.of(extra)).toList();
List<IrisModule> modules = Stream.concat(BuiltInPack.allBuiltIns().stream(), Stream.of(extra)).toList();
try (LoadedPack pack = LoadedPack.load(Files.createDirectory(root.resolve("pack")),
ModuleHost.of(modules)
.exposing(IrisModuleHost.BUILT_IN_API_PACKAGE)
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE)
.copyingJarsTo(Files.createDirectory(root.resolve("copies"))))) {
return pack.schema();
@@ -0,0 +1,583 @@
/*
* 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.modifier;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.PendingSettings;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockFace;
import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockSpec;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.block.PaletteSampler;
import com.volmit.block.PaletteSpec;
import com.volmit.config.FeatureSettings;
import com.volmit.config.PackSettings;
import com.volmit.generation.GenerationContext;
import com.volmit.host.ArrayHunk;
import com.volmit.host.ChunkRunner;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.ResolvedGraph;
import com.volmit.host.StageGraphBuilder;
import com.volmit.hunk.Hunk;
import com.volmit.item.ItemRegistry;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey;
import com.volmit.mantle.MantleLayer;
import com.volmit.mantle.MantleVisitor;
import com.volmit.noise.NoiseFactory;
import com.volmit.object.BlockEntityData;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.resource.ResourceKey;
import com.volmit.stage.Pipeline;
import com.volmit.stage.StageGraph;
import com.volmit.world.BiomeSample;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import com.volmit.world.TerrainSample;
import com.volmit.world.TerrainSampler;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
/**
* One chunk as IrisApi shows it to a chunk stage, held in memory, so the ported built-ins are tested through the surface
* alone, without an Iris engine: the chunk's blocks, the blocks placements planned in its mantle, a terrain of given
* heights, a block registry that knows a few plants, and a world with the pending settings Iris still holds.
*/
public final class ApiChunk implements GenerationContext {
public static final int WIDTH = 16;
public static final BlockState AIR = new BlockState("minecraft:air");
private static final long SEED = 1337L;
private static final int TERRAIN_MARGIN = 16;
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
private static final Set<String> FLUIDS = Set.of("minecraft:water", "minecraft:lava");
private static final Set<String> DECORATIONS = Set.of("minecraft:short_grass", "minecraft:poppy", "minecraft:tall_grass",
"minecraft:dead_bush");
private static final Set<String> FOLIAGE = Set.of("minecraft:short_grass", "minecraft:poppy", "minecraft:tall_grass",
"minecraft:fern");
private static final Set<String> SOILS = Set.of("minecraft:grass_block", "minecraft:dirt", "minecraft:sand");
private static final Set<String> VINES = Set.of("minecraft:vine");
private static final Comparator<BlockPosition> VISIT_ORDER = Comparator.comparingInt(BlockPosition::x)
.thenComparingInt(BlockPosition::y).thenComparingInt(BlockPosition::z);
private final int originX;
private final int originZ;
private final ArrayHunk<BlockState> blocks;
private final Map<BlockPosition, BlockState> planned = new HashMap<>();
private final World world = new World();
private IntBinaryOperator surface = (x, z) -> 0;
private IntBinaryOperator upperDimension;
private double slope;
private int fluidHeight;
public ApiChunk(int originX, int originZ, int height) {
this.originX = originX;
this.originZ = originZ;
this.blocks = new ArrayHunk<>(BlockState.class, WIDTH, height, WIDTH, AIR);
}
public static BlockState block(String key) {
return BlockState.parse(key);
}
/** The terrain's surface height of every column, the chunk's and its neighbours'. */
public ApiChunk surface(IntBinaryOperator heights) {
this.surface = heights;
return this;
}
public ApiChunk slope(double slope) {
this.slope = slope;
return this;
}
public ApiChunk fluidHeight(int height) {
this.fluidHeight = height;
return this;
}
/** Where the dimension above begins, per column. */
public ApiChunk upperDimension(IntBinaryOperator heights) {
this.upperDimension = heights;
return this;
}
/** A block a placement planned in the mantle, in world coordinates. */
public ApiChunk plan(int x, int y, int z, BlockState block) {
planned.put(new BlockPosition(x, y, z), block);
return this;
}
/** Sets a block of the chunk, in the chunk's own coordinates. */
public ApiChunk set(int x, int y, int z, BlockState block) {
blocks.set(x, y, z, block);
return this;
}
public BlockState get(int x, int y, int z) {
return blocks.get(x, y, z);
}
public Pending pending() {
return world.pending;
}
/** Empty stand-ins for the built-in stages the ported modules order after: carving and floating islands. */
public static List<IrisModule> standIns() {
return List.of(new CarveStandIn(), new FloatingStandIn());
}
/** Runs {@code modules} as a pack's chunk graph, with the {@link #standIns()}. */
public ApiChunk generate(IrisModule... modules) {
StageGraphBuilder builder = new StageGraphBuilder();
for (IrisModule module : standIns()) {
builder.install(DiscoveredModule.builtIn(module));
}
for (IrisModule module : modules) {
builder.install(DiscoveredModule.builtIn(module));
}
return generate(builder.resolve(Pipeline.CHUNK));
}
/** Runs a resolved chunk graph on this chunk, such as the one of a loaded pack. */
public ApiChunk generate(ResolvedGraph graph) {
new ChunkRunner(graph).generate(this, SEED);
return this;
}
@Override
public int originX() {
return originX;
}
@Override
public int originZ() {
return originZ;
}
@Override
public TerrainSampler terrain() {
return new Terrain();
}
@Override
public FeatureSettings settings() {
return new FeatureSettings() {
@Override
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
return List.of();
}
};
}
@Override
public Mantle mantle() {
return new ChunkMantle();
}
@Override
@SuppressWarnings("unchecked")
public <T> Hunk<T> hunk(Class<T> type) {
if (type != BlockState.class) {
throw new IllegalArgumentException("Only block hunks");
}
return (Hunk<T>) blocks;
}
@Override
public long worldSeed() {
return SEED;
}
@Override
public PackResources resources() {
return world.resources;
}
@Override
public PackWorld world() {
return world;
}
private BlockBox chunkColumns() {
return new BlockBox(originX, 0, originZ, originX + WIDTH, blocks.getHeight(), originZ + WIDTH);
}
/** The settings Iris still holds on its dimension and biomes, as one world returns them. */
public static final class Pending implements PendingSettings {
private boolean hidesOres;
private boolean walls;
private boolean slabs;
private BlockState wall;
private BlockState slabBlock;
private double maxSlabSlope = Double.MAX_VALUE;
public Pending hidingOres() {
hidesOres = true;
return this;
}
public Pending walls(BlockState wall) {
this.walls = true;
this.wall = wall;
return this;
}
public Pending slabs(BlockState slab, double maxSlope) {
this.slabs = true;
this.slabBlock = slab;
this.maxSlabSlope = maxSlope;
return this;
}
@Override
public boolean hidesOres() {
return hidesOres;
}
@Override
public boolean postProcessingWalls() {
return walls;
}
@Override
public boolean postProcessingSlabs() {
return slabs;
}
@Override
public Optional<BiomeLayer> wall(int x, int z) {
return wall == null ? Optional.empty() : Optional.of(layer(wall, Double.MAX_VALUE));
}
@Override
public BiomeLayer slab(int x, int z) {
return layer(slabBlock, maxSlabSlope);
}
private static BiomeLayer layer(BlockState block, double maxSlope) {
return new BiomeLayer() {
@Override
public Optional<BlockState> at(double x, double y, double z) {
return Optional.ofNullable(block);
}
@Override
public boolean allowsSlope(double slope) {
return slope <= maxSlope;
}
};
}
}
private final class Terrain implements TerrainSampler {
@Override
public BlockBox bounds() {
return new BlockBox(originX - TERRAIN_MARGIN, 0, originZ - TERRAIN_MARGIN, originX + WIDTH + TERRAIN_MARGIN,
blocks.getHeight(), originZ + WIDTH + TERRAIN_MARGIN);
}
@Override
public TerrainSample column(int worldX, int worldZ) {
requireInside(worldX, worldZ);
int height = surface.applyAsInt(worldX, worldZ);
return new TerrainSample(height, height < fluidHeight ? OptionalInt.of(fluidHeight) : OptionalInt.empty(), slope);
}
@Override
public BiomeSample biome(int worldX, int y, int worldZ) {
throw new UnsupportedOperationException("The ported built-ins read biomes through their settings");
}
@Override
public int fluidHeight() {
return fluidHeight;
}
@Override
public OptionalInt upperDimensionY(int worldX, int worldZ) {
requireInside(worldX, worldZ);
return upperDimension == null ? OptionalInt.empty() : OptionalInt.of(upperDimension.applyAsInt(worldX, worldZ));
}
private void requireInside(int worldX, int worldZ) {
if (!bounds().contains(worldX, 0, worldZ)) {
throw new IndexOutOfBoundsException(worldX + ", " + worldZ + " is outside " + bounds());
}
}
}
private final class ChunkMantle implements Mantle {
@Override
public BlockBox bounds() {
return chunkColumns();
}
@Override
public <T> MantleLayer<T> layer(MantleKey<T> key) {
throw new IllegalArgumentException("No module layers here");
}
@Override
public MantleLayer<BlockState> blocks() {
return new PlannedLayer();
}
@Override
public MantleEdit edit() {
throw new UnsupportedOperationException("Chunk stages do not edit the mantle");
}
}
private final class PlannedLayer implements MantleLayer<BlockState> {
@Override
public BlockState get(int x, int y, int z) {
return planned.get(new BlockPosition(x, y, z));
}
@Override
public void set(int x, int y, int z, BlockState value) {
throw new UnsupportedOperationException("Planned blocks are read-only");
}
@Override
public void remove(int x, int y, int z) {
throw new UnsupportedOperationException("Planned blocks are read-only");
}
@Override
public void visit(BlockBox area, MantleVisitor<BlockState> visitor) {
if (!chunkColumns().contains(area)) {
throw new IndexOutOfBoundsException(area + " is outside " + chunkColumns());
}
List<BlockPosition> positions = new ArrayList<>(planned.keySet());
positions.sort(VISIT_ORDER);
for (BlockPosition position : positions) {
if (area.contains(position.x(), position.y(), position.z())) {
visitor.accept(position.x(), position.y(), position.z(), planned.get(position));
}
}
}
@Override
public void clear(BlockBox area) {
throw new UnsupportedOperationException("Planned blocks are read-only");
}
}
/** A world of the chunk: its pack's blocks and the pending settings, and a state store. */
private static final class World implements PackWorld, PendingSettings {
private final Pending pending = new Pending();
private final Resources resources = new Resources();
private final Map<Class<?>, Object> states = new HashMap<>();
@Override
public long seed() {
return SEED;
}
@Override
public PackResources resources() {
return resources;
}
@Override
public PackSettings settings() {
throw new UnsupportedOperationException("No pack settings here");
}
@Override
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
return type.cast(states.computeIfAbsent(type, ignored -> create.apply(this)));
}
@Override
public boolean hidesOres() {
return pending.hidesOres();
}
@Override
public boolean postProcessingWalls() {
return pending.postProcessingWalls();
}
@Override
public boolean postProcessingSlabs() {
return pending.postProcessingSlabs();
}
@Override
public Optional<BiomeLayer> wall(int x, int z) {
return pending.wall(x, z);
}
@Override
public BiomeLayer slab(int x, int z) {
return pending.slab(x, z);
}
}
private static final class Resources implements PackResources {
private final UUID snapshot = UUID.randomUUID();
@Override
public ResourceId packId() {
return ResourceId.parse("test:pack");
}
@Override
public UUID snapshotId() {
return snapshot;
}
@Override
public BlockRegistry blocks() {
return new Blocks();
}
@Override
public ItemRegistry items() {
throw new UnsupportedOperationException("No items here");
}
@Override
public NoiseFactory noise() {
throw new UnsupportedOperationException("No noise here");
}
@Override
public <T> Optional<T> find(ResourceKey<T> key) {
return Optional.empty();
}
@Override
public List<ResourceId> ids(Class<?> type) {
return List.of();
}
}
/**
* Blocks by name: air, water and lava, a few decorations and foliage standing on soil (a fern is foliage only, a dead
* bush a decoration only), vines; everything else is a solid cube.
*/
private static final class Blocks implements BlockRegistry {
@Override
public BlockState resolve(String key) {
return BlockState.parse(key);
}
@Override
public BlockState resolve(BlockSpec spec) {
throw new UnsupportedOperationException("No specs here");
}
@Override
public Optional<BlockEntityData> blockEntity(BlockSpec spec) {
return Optional.empty();
}
@Override
public PaletteSampler palette(PaletteSpec spec, long seed) {
throw new UnsupportedOperationException("No palettes here");
}
@Override
public boolean hasTrait(BlockState state, BlockTrait trait) {
String material = state.material().toString();
boolean air = AIRS.contains(material);
boolean fluid = FLUIDS.contains(material);
boolean plant = DECORATIONS.contains(material) || FOLIAGE.contains(material);
boolean vine = VINES.contains(material);
return switch (trait) {
case AIR -> air;
case FLUID -> fluid;
case WATER -> material.equals("minecraft:water");
case SOLID, OCCLUDING -> !air && !fluid && !plant && !vine;
case FOLIAGE -> FOLIAGE.contains(material);
case DECORATION -> DECORATIONS.contains(material);
case VINE -> vine;
default -> false;
};
}
@Override
public boolean inTag(BlockState state, ResourceId tag) {
return false;
}
@Override
public boolean canAttach(BlockState state, BlockState support, BlockFace face) {
return hasTrait(support, BlockTrait.SOLID);
}
@Override
public boolean canPlaceOn(BlockState state, BlockState below) {
if (hasTrait(below, BlockTrait.AIR)) {
return false;
}
String material = state.material().toString();
boolean plant = DECORATIONS.contains(material) || FOLIAGE.contains(material);
return !plant || SOILS.contains(below.material().toString());
}
}
private static final class CarveStandIn implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:carve", "Carving stand-in", "test");
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Carve.APPLY).run(context -> {
});
}
}
private static final class FloatingStandIn implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:floating", "Floating stand-in", "test");
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Floating.SOLIDS).run(context -> {
});
graph.define(IrisStages.Floating.DECORATE).run(context -> {
});
}
}
}
@@ -1,132 +1,61 @@
/*
* 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.modifier;
import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.UpperDimensionContext;
import art.arcane.iris.engine.UsableBlockPlatform;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.project.hunk.Hunk;
import art.arcane.iris.util.project.stream.ProceduralStream;
import art.arcane.volmlib.util.function.Consumer4;
import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.matter.Matter;
import org.junit.After;
import org.junit.Before;
import com.volmit.block.BlockState;
import org.junit.Test;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static art.arcane.iris.engine.modifier.ApiChunk.AIR;
import static art.arcane.iris.engine.modifier.ApiChunk.block;
import static org.junit.Assert.assertEquals;
/** Inserting copies the mantle's blocks of a chunk into it, below the upper dimension's surface where there is one. */
/** iris:matter through IrisApi alone: the mantle's planned blocks go into the chunk, below the dimension above. */
public class MatterModuleTest {
@Before
public void bindPlatform() {
UsableBlockPlatform.bind();
}
@After
public void unbindPlatform() {
UsableBlockPlatform.unbind();
}
private static final int CHUNK_X = 1;
private static final int CHUNK_Z = 2;
private static final int UPPER_SURFACE = 100;
private final PlatformBlockState planned = mock(PlatformBlockState.class);
private final Mantle<Matter> mantle = mockMantle();
private final MantleChunk<Matter> mantleChunk = mockMantleChunk();
@Test
public void aDimensionWithoutAMantleIsLeftAlone() {
IrisDimension dimension = dimension(false);
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 128, 16);
new MatterModule.MatterInsertion(engine(dimension, null)).insert(CHUNK_X, CHUNK_Z, blocks);
verifyNoInteractions(mantle);
assertNull(blocks.get(3, 50, 4));
}
private static final int ORIGIN_X = 16;
private static final int ORIGIN_Z = 32;
private static final int HEIGHT = 128;
private static final int UPPER_DIMENSION = 100;
private static final BlockState PLANNED = block("minecraft:oak_planks");
private static final BlockState GROUND = block("minecraft:dirt");
@Test
public void plannedBlocksAreCopiedIntoTheChunk() {
plan(new int[]{3, 50, 4}, new int[]{3, 120, 4});
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 128, 16);
ApiChunk chunk = new ApiChunk(ORIGIN_X, ORIGIN_Z, HEIGHT).set(3, 50, 4, GROUND)
.plan(ORIGIN_X + 3, 50, ORIGIN_Z + 4, PLANNED).plan(ORIGIN_X + 3, 120, ORIGIN_Z + 4, PLANNED)
.plan(ORIGIN_X + 3, 51, ORIGIN_Z + 4, AIR);
new MatterModule.MatterInsertion(engine(dimension(true), null)).insert(CHUNK_X, CHUNK_Z, blocks);
chunk.generate(new MatterModule());
assertSame(planned, blocks.get(3, 50, 4));
assertSame(planned, blocks.get(3, 120, 4));
verify(mantleChunk).release();
assertEquals(PLANNED, chunk.get(3, 50, 4));
assertEquals(PLANNED, chunk.get(3, 120, 4));
assertEquals(AIR, chunk.get(3, 51, 4));
}
@Test
public void blocksAtOrAboveTheUpperDimensionSurfaceAreLeftOut() {
plan(new int[]{3, UPPER_SURFACE - 1, 4}, new int[]{3, UPPER_SURFACE, 4});
UpperDimensionContext upper = mock(UpperDimensionContext.class);
when(upper.getUpperSurfaceY(anyInt(), anyInt())).thenReturn(UPPER_SURFACE);
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 128, 16);
public void blocksAtOrAboveWhereTheUpperDimensionBeginsAreLeftOut() {
ApiChunk chunk = new ApiChunk(ORIGIN_X, ORIGIN_Z, HEIGHT).upperDimension((x, z) -> UPPER_DIMENSION)
.plan(ORIGIN_X + 3, UPPER_DIMENSION - 1, ORIGIN_Z + 4, PLANNED)
.plan(ORIGIN_X + 3, UPPER_DIMENSION, ORIGIN_Z + 4, PLANNED);
new MatterModule.MatterInsertion(engine(dimension(true), upper)).insert(CHUNK_X, CHUNK_Z, blocks);
chunk.generate(new MatterModule());
assertSame(planned, blocks.get(3, UPPER_SURFACE - 1, 4));
assertNull(blocks.get(3, UPPER_SURFACE, 4));
}
/** The mantle chunk holds {@code planned} at each of the given {@code {x, y, z}} positions. */
private void plan(int[]... positions) {
org.mockito.Mockito.doAnswer(invocation -> {
Consumer4<Integer, Integer, Integer, PlatformBlockState> consumer = invocation.getArgument(1);
for (int[] at : positions) {
consumer.accept(at[0], at[1], at[2], planned);
}
return null;
}).when(mantleChunk).iterate(any(), any());
}
private IrisDimension dimension(boolean useMantle) {
IrisDimension dimension = mock(IrisDimension.class);
when(dimension.isUseMantle()).thenReturn(useMantle);
when(dimension.getUpperDimensionGap()).thenReturn(0);
return dimension;
}
@SuppressWarnings("unchecked")
private Engine engine(IrisDimension dimension, UpperDimensionContext upper) {
EngineMantle engineMantle = mock(EngineMantle.class);
when(engineMantle.getMantle()).thenReturn(mantle);
ProceduralStream<Double> heights = mock(ProceduralStream.class);
when(heights.get(anyDouble(), anyDouble())).thenReturn(0D);
IrisComplex complex = mock(IrisComplex.class);
when(complex.getHeightStream()).thenReturn(heights);
Engine engine = mock(Engine.class);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getMantle()).thenReturn(engineMantle);
when(engine.getUpperContext()).thenReturn(upper);
when(engine.getComplex()).thenReturn(complex);
return engine;
}
@SuppressWarnings("unchecked")
private Mantle<Matter> mockMantle() {
return mock(Mantle.class);
}
@SuppressWarnings("unchecked")
private MantleChunk<Matter> mockMantleChunk() {
MantleChunk<Matter> chunk = mock(MantleChunk.class);
when(chunk.use()).thenReturn(chunk);
when(mantle.getChunk(CHUNK_X, CHUNK_Z)).thenReturn(chunk);
return chunk;
assertEquals(PLANNED, chunk.get(3, UPPER_DIMENSION - 1, 4));
assertEquals(AIR, chunk.get(3, UPPER_DIMENSION, 4));
}
}
@@ -0,0 +1,72 @@
/*
* 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.modifier;
import com.volmit.block.BlockState;
import org.junit.Test;
import static art.arcane.iris.engine.modifier.ApiChunk.AIR;
import static art.arcane.iris.engine.modifier.ApiChunk.block;
import static org.junit.Assert.assertEquals;
/** iris:perfection through IrisApi alone: ores hide when the dimension asks, decorations without ground go. */
public class PerfectionModuleTest {
private static final int HEIGHT = 8;
private static final BlockState GRASS = block("minecraft:grass_block");
private static final BlockState STONE = block("minecraft:stone");
private static final BlockState POPPY = block("minecraft:poppy");
@Test
public void decorationsTheirGroundCannotHoldGo() {
ApiChunk chunk = new ApiChunk(0, 0, HEIGHT).set(0, 0, 0, GRASS).set(0, 1, 0, POPPY)
.set(1, 0, 0, STONE).set(1, 1, 0, POPPY);
chunk.generate(new PerfectionModule());
assertEquals(POPPY, chunk.get(0, 1, 0));
assertEquals(AIR, chunk.get(1, 1, 0));
assertEquals(STONE, chunk.get(1, 0, 0));
}
@Test
public void bothHalvesOfATallPlantWithoutGroundGo() {
BlockState lower = block("minecraft:tall_grass[half=lower]");
BlockState upper = block("minecraft:tall_grass[half=upper]");
ApiChunk chunk = new ApiChunk(0, 0, HEIGHT).set(0, 0, 0, STONE).set(0, 1, 0, lower).set(0, 2, 0, upper);
chunk.generate(new PerfectionModule());
assertEquals(AIR, chunk.get(0, 1, 0));
assertEquals(AIR, chunk.get(0, 2, 0));
}
@Test
public void oresHideOnlyWhenTheDimensionAsks() {
BlockState ore = block("minecraft:deepslate_iron_ore");
ApiChunk shown = new ApiChunk(0, 0, HEIGHT).set(0, 0, 0, ore);
ApiChunk hidden = new ApiChunk(0, 0, HEIGHT).set(0, 0, 0, ore);
hidden.pending().hidingOres();
shown.generate(new PerfectionModule());
hidden.generate(new PerfectionModule());
assertEquals(ore, shown.get(0, 0, 0));
assertEquals(block("minecraft:deepslate"), hidden.get(0, 0, 0));
}
}
@@ -1,88 +1,132 @@
/*
* 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.modifier;
import art.arcane.iris.engine.UsableBlockPlatform;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineMetrics;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.iris.util.project.context.ChunkedDataCache;
import art.arcane.iris.util.project.hunk.Hunk;
import org.junit.After;
import com.volmit.block.BlockState;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static art.arcane.iris.engine.modifier.ApiChunk.AIR;
import static art.arcane.iris.engine.modifier.ApiChunk.block;
import static org.junit.Assert.assertEquals;
/** Smoothing the surface removes a nib that floats above columns two blocks lower and leaves a flat surface alone. */
/**
* iris:post through IrisApi alone: a nib floating above its neighbours goes, a flat surface stays, a step gets a slab,
* a steep face gets its wall, a stair under water is waterlogged and a plant that lost its ground goes.
*/
public class SurfaceSmoothingTest {
private static final int NIB_X = 5;
private static final int NIB_Z = 5;
private static final int NIB_HEIGHT = 10;
private static final int NEIGHBOUR_HEIGHT = 4;
private final PlatformBlockState stone = UsableBlockPlatform.block("minecraft:stone");
@After
public void unbindPlatform() {
UsableBlockPlatform.unbind();
}
private static final int X = 5;
private static final int Z = 5;
private static final int GROUND = 4;
private static final int HEIGHT = 32;
private static final BlockState STONE = block("minecraft:stone");
@Test
public void aNibFloatingAboveItsFourNeighboursIsRemoved() {
UsableBlockPlatform.bind();
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 32, 16);
blocks.set(NIB_X, NIB_HEIGHT, NIB_Z, stone);
int nib = 10;
ApiChunk chunk = ground((x, z) -> GROUND).surface(column(nib)).set(X, nib, Z, STONE);
new SurfaceSmoothing(engine(NIB_X, NIB_Z)).smooth(0, 0, blocks, false, context());
chunk.generate(new PostModule());
assertNotNull(blocks.get(NIB_X, NIB_HEIGHT, NIB_Z));
assertNotSame("the nib is replaced by air", stone, blocks.get(NIB_X, NIB_HEIGHT, NIB_Z));
assertEquals(AIR, chunk.get(X, nib, Z));
}
@Test
public void aFlatSurfaceIsLeftAlone() {
UsableBlockPlatform.bind();
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 32, 16);
blocks.set(NIB_X, NEIGHBOUR_HEIGHT, NIB_Z, stone);
ApiChunk chunk = ground((x, z) -> GROUND);
new SurfaceSmoothing(engine(NIB_X, NIB_Z, NEIGHBOUR_HEIGHT)).smooth(0, 0, blocks, false, context());
chunk.generate(new PostModule());
assertSame(stone, blocks.get(NIB_X, NEIGHBOUR_HEIGHT, NIB_Z));
assertEquals(STONE, chunk.get(X, GROUND, Z));
assertEquals(AIR, chunk.get(X, GROUND + 1, Z));
}
/** The surface is {@code NEIGHBOUR_HEIGHT} everywhere except at {@code nibHeight} at the nib column. */
private Engine engine(int nibX, int nibZ) {
return engine(nibX, nibZ, NIB_HEIGHT);
@Test
public void aStepUpGetsASlabWhereTheSlopeAllowsIt() {
BlockState slab = block("minecraft:stone_slab[type=bottom]");
ApiChunk chunk = ground((x, z) -> x > X ? GROUND + 1 : GROUND);
chunk.pending().slabs(slab, 1);
chunk.generate(new PostModule());
assertEquals(slab, chunk.get(X, GROUND + 1, Z));
}
private Engine engine(int nibX, int nibZ, int nibHeight) {
EngineMantle mantle = mock(EngineMantle.class);
when(mantle.trueHeight(anyInt(), anyInt())).thenAnswer(invocation ->
(int) invocation.getArgument(0) == nibX && (int) invocation.getArgument(1) == nibZ ? nibHeight : NEIGHBOUR_HEIGHT);
IrisDimension dimension = mock(IrisDimension.class);
SeedManager seeds = mock(SeedManager.class);
Engine engine = mock(Engine.class);
when(engine.getMantle()).thenReturn(mantle);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getSeedManager()).thenReturn(seeds);
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
return engine;
@Test
public void slabsWaitForASlopeTheirLayerAllows() {
ApiChunk chunk = ground((x, z) -> x > X ? GROUND + 1 : GROUND).slope(2);
chunk.pending().slabs(block("minecraft:stone_slab[type=bottom]"), 1);
chunk.generate(new PostModule());
assertEquals(AIR, chunk.get(X, GROUND + 1, Z));
}
@SuppressWarnings("unchecked")
private ChunkContext context() {
ChunkedDataCache<IrisBiome> biomes = mock(ChunkedDataCache.class);
when(biomes.get(anyInt(), anyInt())).thenReturn(mock(IrisBiome.class));
ChunkContext context = mock(ChunkContext.class);
when(context.getBiome()).thenReturn(biomes);
return context;
@Test
public void aSteepFaceIsPaintedWithItsWall() {
BlockState wall = block("minecraft:cobblestone");
int cliff = GROUND + 4;
ApiChunk chunk = ground((x, z) -> x <= X ? cliff : GROUND);
chunk.pending().walls(wall);
chunk.generate(new PostModule());
assertEquals(wall, chunk.get(X, cliff, Z));
assertEquals(wall, chunk.get(X, cliff - 1, Z));
}
@Test
public void aStairUnderTheFluidHeightNextToWaterIsWaterlogged() {
BlockState stair = block("minecraft:oak_stairs[facing=east,waterlogged=false]");
ApiChunk chunk = ground((x, z) -> GROUND).fluidHeight(GROUND + 1)
.set(X, GROUND, Z, stair).set(X + 1, GROUND, Z, block("minecraft:water"));
chunk.generate(new PostModule());
assertEquals(stair.withProperty("waterlogged", "true"), chunk.get(X, GROUND, Z));
}
@Test
public void foliageThatLostItsGroundGoesButDecorationsStay() {
BlockState poppy = block("minecraft:poppy");
ApiChunk chunk = ground((x, z) -> GROUND).set(X, GROUND + 1, Z, block("minecraft:fern")).set(X + 2, GROUND + 1, Z, poppy);
chunk.generate(new PostModule());
assertEquals("stone holds no fern", AIR, chunk.get(X, GROUND + 1, Z));
assertEquals("perfection, not post, removes decorations", poppy, chunk.get(X + 2, GROUND + 1, Z));
}
/** A chunk of stone up to {@code heights}, the terrain's surface. */
private static ApiChunk ground(java.util.function.IntBinaryOperator heights) {
ApiChunk chunk = new ApiChunk(0, 0, HEIGHT).surface(heights);
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
for (int y = 0; y <= heights.applyAsInt(x, z); y++) {
chunk.set(x, y, z, STONE);
}
}
}
return chunk;
}
/** The terrain's height: the ground everywhere but the nib column, which the terrain says stands {@code nib} high. */
private static java.util.function.IntBinaryOperator column(int nib) {
return (x, z) -> x == X && z == Z ? nib : GROUND;
}
}