Host side of the module surface: planned mantle blocks, VINE and canPlaceOn, fluid height and upper dimension, a chunk sampler over the neighbors, conversions that keep platform identity, stage timings into the named metrics, Iris's pending settings for the built-ins

This commit is contained in:
piexel committed 2026-10-10 13:10:19 +02:00
1 parent f26d438ff0
commit bdf1389d77
20 files changed
+723 -172

No files matched your search

@@ -83,6 +83,8 @@ public class DimensionBottomTest {
private static final int BOTTOM = 0;
private static final int SURFACE_HEIGHT = 10;
private static final BlockBox WHOLE_HEIGHT_OF_ONE_CHUNK = new BlockBox(0, BOTTOM, 0, 16, DIMENSION_HEIGHT, 16);
/** A chunk stage sees the terrain of its chunk and of the 16 blocks around it. */
private static final BlockBox WHOLE_HEIGHT_AROUND_ONE_CHUNK = new BlockBox(-16, BOTTOM, -16, 32, DIMENSION_HEIGHT, 32);
private static final BlockState STONE = BlockState.parse("minecraft:stone");
private static final MantleKey<String> MARKS = new MantleKey<>("test:bottom/mark", String.class);
private static final MantleCodec<String> TEXT = new MantleCodec<>() {
@@ -176,7 +178,9 @@ public class DimensionBottomTest {
assertEquals("minecraft:stone", blocks.get(0, BOTTOM, 0).key());
assertEquals("the chunk's block hunk starts at the bottom, not at the world's minimum height", 1, countBlocks(blocks));
assertSamplesAndBoundsAgree();
assertEquals(List.of(WHOLE_HEIGHT_AROUND_ONE_CHUNK), terrainBounds);
assertEquals(List.of(WHOLE_HEIGHT_OF_ONE_CHUNK), viewBounds);
assertEquals("the terrain samples count from the same bottom", List.of(Double.valueOf(SURFACE_HEIGHT)), surfaces);
}
@Test
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -117,4 +118,27 @@ public class IrisBlockRegistryTest {
verify(stone).canAttach(sand, PlatformFace.valueOf(face.name()));
}
}
@Test
public void vinesAndStandingOnABlockAreThePlatformsAnswers() {
when(sand.isVineBlock()).thenReturn(true);
when(stone.canPlaceOnto(sand)).thenReturn(true);
BlockState stoneState = BlockState.parse("minecraft:stone");
BlockState sandState = BlockState.parse("minecraft:sand");
assertTrue(blocks.hasTrait(sandState, BlockTrait.VINE));
assertFalse(blocks.hasTrait(stoneState, BlockTrait.VINE));
assertTrue(blocks.canPlaceOn(stoneState, sandState));
assertFalse(blocks.canPlaceOn(sandState, stoneState));
}
@Test
public void eachStateIsLookedUpOnceAndAskedAgainFromMemory() {
BlockState stoneState = BlockState.parse("minecraft:stone");
blocks.hasTrait(stoneState, BlockTrait.SOLID);
blocks.hasTrait(BlockState.parse("minecraft:stone"), BlockTrait.AIR);
verify(registries, times(1)).blockOrNull(eq("minecraft:stone"), anyBoolean());
}
}
@@ -111,7 +111,7 @@ public class IrisModuleMantleTest {
}
private IrisModuleMantle mantle(BlockBox bounds) {
return new IrisModuleMantle(bounds, this::chunk, LAYERS);
return new IrisModuleMantle(bounds, this::chunk, LAYERS, PlannedBlocks.none(bounds));
}
@Test
@@ -224,8 +224,9 @@ public class IrisModuleMantleTest {
@Test
public void aCommitThatCannotReachEveryChunkPublishesNothing() {
IrisModuleMantle mantle = new IrisModuleMantle(new BlockBox(0, 0, 0, 32, HEIGHT, 16),
(chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS);
BlockBox bounds = new BlockBox(0, 0, 0, 32, HEIGHT, 16);
IrisModuleMantle mantle = new IrisModuleMantle(bounds, (chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS,
PlannedBlocks.none(bounds));
MantleEdit edit = mantle.edit();
edit.layer(MARKS).set(1, 4, 1, "first");
edit.layer(MARKS).set(20, 4, 1, "unprepared");
@@ -287,7 +288,8 @@ public class IrisModuleMantleTest {
ModuleHost.of(List.of(veins)).copyingJarsTo(folder.newFolder("copies").toPath()))) {
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk);
IrisModuleMantle neighbor = new IrisModuleMantle(new BlockBox(16, 0, 0, 32, HEIGHT, 16), this::chunk, pack.catalog().mantle());
BlockBox neighborBounds = new BlockBox(16, 0, 0, 32, HEIGHT, 16);
IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds));
assertEquals("vein", neighbor.layer(planned).get(20, 34, 3));
}
assertTrue(chunks.containsKey(1L << 32));
@@ -1,144 +0,0 @@
/*
* 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.builtin.IrisStages;
import art.arcane.iris.core.loader.IrisData;
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.modifier.PerfectionModule;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.iris.util.project.hunk.Hunk;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.host.LoadedPack;
import com.volmit.host.ModuleHost;
import com.volmit.stage.StageGraph;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** The built-in iris:perfection chunk stage, run as part of the pack's chunk graph. */
public class PerfectionModuleTest {
private static final int WIDTH = 16;
private static final int HEIGHT = 4;
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private LoadedPack pack;
private Engine engine;
private IrisDimension dimension;
private Hunk<PlatformBlockState> blocks;
private PlatformBlockState ground;
@Before
public void loadPack() throws IOException {
IrisPlatforms.unbind();
PlatformRegistries registries = mock(PlatformRegistries.class);
when(registries.block(anyString())).thenAnswer(call -> block(PlatformBlockStates.namespaced(call.<String>getArgument(0).toLowerCase()), false));
IrisPlatform platform = mock(IrisPlatform.class);
when(platform.registries()).thenReturn(registries);
IrisPlatforms.bind(platform);
pack = LoadedPack.load(folder.newFolder("pack").toPath(),
ModuleHost.of(List.of(new PerfectionModule(), new FloatingDecorationStub())).copyingJarsTo(folder.newFolder("copies").toPath()));
engine = mock(Engine.class);
IrisData data = mock(IrisData.class);
SeedManager seeds = mock(SeedManager.class);
dimension = new IrisDimension();
when(engine.getData()).thenReturn(data);
when(data.getDataFolder()).thenReturn(folder.getRoot());
when(engine.getSeedManager()).thenReturn(seeds);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getMetrics()).thenReturn(new EngineMetrics(1));
blocks = Hunk.newArrayHunk(WIDTH, HEIGHT, WIDTH);
ground = block("minecraft:grass_block", false);
blocks.set(0, 0, 0, ground);
blocks.set(1, 0, 0, ground);
}
@After
public void closePack() {
pack.close();
IrisPlatforms.unbind();
}
@Test
public void chunksLoseDecorationsTheirGroundCannotHold() {
PlatformBlockState floating = decorant(false);
PlatformBlockState rooted = decorant(true);
blocks.set(0, 1, 0, floating);
blocks.set(1, 1, 0, rooted);
generate();
assertNotSame(floating, blocks.get(0, 1, 0));
assertSame(rooted, blocks.get(1, 1, 0));
assertSame(ground, blocks.get(0, 0, 0));
}
private void generate() {
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, false, null, key -> block(key, false));
}
/** The stage perfection runs after; perfection needs it installed, not doing anything. */
private static final class FloatingDecorationStub implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:floating", "Floating islands", "test");
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Floating.DECORATE).run(context -> {
});
}
}
private static PlatformBlockState decorant(boolean held) {
PlatformBlockState decorant = block("minecraft:poppy", true);
when(decorant.canPlaceOnto(any())).thenReturn(held);
return decorant;
}
private static PlatformBlockState block(String key, boolean decorant) {
PlatformBlockState block = mock(PlatformBlockState.class);
when(block.key()).thenReturn(key);
when(block.isDecorant()).thenReturn(decorant);
when(block.isAir()).thenReturn(key.endsWith("air"));
return block;
}
}
@@ -0,0 +1,138 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.UsableBlockPlatform;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.project.hunk.Hunk;
import com.volmit.block.BlockState;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.MantleLayer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* The mantle's planned blocks as IrisApi's {@code Mantle.blocks()}: what placements wrote into the mantle's block slice,
* nothing where the dimension keeps no mantle or the chunk generates without it, read-only, and copied into the chunk
* as the very platform states the mantle held.
*/
public class PlannedBlocksTest {
private static final int SECTIONS = 4;
private static final BlockBox CHUNK = new BlockBox(16, 0, 32, 32, SECTIONS * 16, 48);
private final InMemoryMantle mantle = new InMemoryMantle(SECTIONS);
private PlatformBlockState planks;
@Before
public void bindPlatform() {
UsableBlockPlatform.bind();
planks = UsableBlockPlatform.block("minecraft:oak_planks");
}
@After
public void unbindPlatform() {
UsableBlockPlatform.unbind();
}
@Test
public void placementsBlocksReadInWorldCoordinatesInVisitOrder() {
plan(20, 10, 33, planks);
plan(17, 40, 35, planks);
PlannedBlocks blocks = planned(true, false);
List<String> visited = new ArrayList<>();
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(x + "," + y + "," + z + " " + block.key()));
assertEquals(List.of("17,40,35 minecraft:oak_planks", "20,10,33 minecraft:oak_planks"), visited);
assertEquals(BlockState.parse("minecraft:oak_planks"), blocks.get(20, 10, 33));
assertNull(blocks.get(20, 11, 33));
}
@Test
public void aDimensionWithoutAMantleOrAChunkWithoutItPlansNothing() {
plan(20, 10, 33, planks);
for (PlannedBlocks blocks : List.of(planned(false, false), planned(true, true))) {
List<BlockState> visited = new ArrayList<>();
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(block));
assertEquals(List.of(), visited);
assertNull(blocks.get(20, 10, 33));
}
}
@Test
public void stagesCannotPlanBlocks() {
MantleLayer<BlockState> blocks = planned(true, false);
BlockState stone = BlockState.parse("minecraft:stone");
assertThrows(UnsupportedOperationException.class, () -> blocks.set(20, 10, 33, stone));
assertThrows(UnsupportedOperationException.class, () -> blocks.remove(20, 10, 33));
assertThrows(UnsupportedOperationException.class, () -> blocks.clear(CHUNK));
}
@Test
public void aCopiedBlockIsTheMantlesPlatformStateEvenWhereAnotherHasItsKey() {
PlatformBlockState custom = UsableBlockPlatform.block("minecraft:note_block");
PlatformBlockState vanilla = UsableBlockPlatform.block("minecraft:note_block");
plan(20, 10, 33, custom);
PlatformBlockStates states = new PlatformBlockStates(key -> vanilla);
PlannedBlocks blocks = PlannedBlocks.of(engine(true, false), CHUNK, mantle::chunk, states);
Hunk<PlatformBlockState> chunk = Hunk.newArrayHunk(16, SECTIONS * 16, 16);
BlockStateHunk hunk = new BlockStateHunk(chunk, states);
blocks.visit(CHUNK, (x, y, z, block) -> hunk.set(x - 16, y, z - 32, block));
hunk.set(0, 0, 0, BlockState.parse("minecraft:note_block"));
assertSame("a content plugin's block keeps its identity", custom, chunk.get(4, 10, 1));
assertSame("a block of the same key a stage writes itself is the platform's", vanilla, chunk.get(0, 0, 0));
}
private void plan(int x, int y, int z, PlatformBlockState block) {
mantle.chunk(x >> 4, z >> 4).getOrCreate(y >> 4).slice(PlatformBlockState.class).set(x & 15, y & 15, z & 15, block);
}
private PlannedBlocks planned(boolean useMantle, boolean bypass) {
return PlannedBlocks.of(engine(useMantle, bypass), CHUNK, mantle::chunk, new PlatformBlockStates(UsableBlockPlatform::block));
}
private static Engine engine(boolean useMantle, boolean bypass) {
IrisDimension dimension = mock(IrisDimension.class);
when(dimension.isUseMantle()).thenReturn(useMantle);
EngineGeneration generation = mock(EngineGeneration.class);
when(generation.bypassesMantleStages()).thenReturn(bypass);
Engine engine = mock(Engine.class);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getGeneration()).thenReturn(generation);
return engine;
}
}
@@ -0,0 +1,77 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.framework.EngineMetrics;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.ResolvedStage;
import com.volmit.host.StageGraphBuilder;
import com.volmit.stage.Pipeline;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
/** Iris times the built-in stages it reported under names of their own, post and perfection, around their runs. */
public class StageMetricsTest {
private static final long TWO_MILLISECONDS = 2_000_000L;
@Test
public void namedBuiltInStagesFeedTheirMetricAndOthersNothing() {
EngineMetrics metrics = new EngineMetrics(4);
StageMetrics timings = new StageMetrics(metrics);
for (ResolvedStage stage : stages("iris:post/smooth", "iris:perfection/surface", "iris:other/work")) {
timings.record(stage, TWO_MILLISECONDS);
}
assertEquals(2D, metrics.getPost().getAverage(), 0D);
assertEquals(2D, metrics.getPerfection().getAverage(), 0D);
}
@Test
public void anEngineWithoutMetricsRecordsNothing() {
new StageMetrics(null).record(stages("iris:post/smooth").getFirst(), TWO_MILLISECONDS);
}
private static List<ResolvedStage> stages(String... ids) {
StageGraphBuilder builder = new StageGraphBuilder();
for (String id : ids) {
String module = id.substring(0, id.indexOf('/'));
builder.install(DiscoveredModule.builtIn(new IrisModule() {
@Override
public ModuleInfo info() {
return ModuleInfo.of(module, module, "test");
}
@Override
public void install(StageGraph graph) {
graph.define(Stage.chunk(id)).run(context -> {
});
}
}));
}
return builder.resolve(Pipeline.CHUNK).stages();
}
}