mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Run the pack's chunk graph inside Iris's chunk generation
- After the world mode's stages, ModuleChunkGeneration runs the pack's resolved chunk graph with IrisApi's ChunkRunner on the chunk's block hunk. - Stages are active where the chunk's dimension, region or biome at its center configures their settings; per settings type the most specific declaration wins (biome over region over dimension). - The block hunk is Iris's chunk hunk seen as IrisApi block states: unset blocks read as air, a write beyond the chunk fails instead of clipping. - Terrain samples come from Iris's height, slope and biome streams, bounded by the chunk widened by the pipeline's reach. Pack dimensions, regions and biomes become ResourceIds under the pack folder's name. - The invocation seed mixes the world seed with the chunk position. - Mantle access and pack resources are not bridged yet and fail with an error that says so.
This commit is contained in:
1 parent
88ddf66e6e
commit
da71e0e921
9 files changed
+675
No files matched your search
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
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 art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.stage.Stage;
|
||||
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 java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModuleChunkGenerationTest {
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
private static final int HEIGHT = 4;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private LoadedPack pack;
|
||||
private Engine engine;
|
||||
private Hunk<PlatformBlockState> blocks;
|
||||
|
||||
@Feature(id = "iris:pillar", name = "Pillar", alias = "pillar", targets = {Target.BIOME, Target.REGION, Target.DIMENSION})
|
||||
public static final class PillarSettings implements IrisFeature {
|
||||
private BlockState block = BlockState.parse("minecraft:stone");
|
||||
private int x;
|
||||
}
|
||||
|
||||
/** Copies the block below the chunk's corner up one, and writes the configured block at {@code x}. */
|
||||
public static final class PillarModule implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("iris:pillar", "Pillar", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.chunk("iris:pillar/raise")).when(PillarSettings.class).run((context, pillar) -> {
|
||||
com.volmit.hunk.Hunk<BlockState> chunk = context.hunk(BlockState.class);
|
||||
chunk.set(0, 1, 0, chunk.get(0, 0, 0));
|
||||
chunk.set(pillar.x, 2, 0, pillar.block);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void loadPack() throws IOException {
|
||||
pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
||||
ModuleHost.of(List.of(new PillarModule())).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
engine = mock(Engine.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(data.getDataFolder()).thenReturn(folder.getRoot());
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(seeds.getSeed()).thenReturn(1L);
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
blocks = Hunk.newArrayHunk(CHUNK_WIDTH, HEIGHT, CHUNK_WIDTH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stagesRunWhereTheChunksBiomeConfiguresThemAndWriteIrisBlocks() {
|
||||
blocks.set(0, 0, 0, platformState("minecraft:dirt"));
|
||||
|
||||
generate(configured(new IrisBiome(), pillar(3)));
|
||||
|
||||
assertEquals("minecraft:dirt", blocks.get(0, 1, 0).key());
|
||||
assertEquals("minecraft:oak_log[axis=y]", blocks.get(3, 2, 0).key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsetIrisBlocksReadAsAir() {
|
||||
generate(configured(new IrisBiome(), pillar(3)));
|
||||
|
||||
assertEquals("minecraft:air", blocks.get(0, 1, 0).key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stagesStayInactiveWhereNothingConfiguresThem() {
|
||||
generate(new IrisBiome());
|
||||
|
||||
assertNull(blocks.get(3, 2, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBlockOutsideTheChunkFailsInsteadOfBeingClipped() {
|
||||
IndexOutOfBoundsException failure = assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> generate(configured(new IrisBiome(), pillar(CHUNK_WIDTH))));
|
||||
|
||||
assertEquals("Block 16, 2, 0 is outside the 16x4x16 chunk hunk", failure.getMessage());
|
||||
}
|
||||
|
||||
private void generate(IrisBiome biome) {
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, new IrisRegion(), biome, ModuleChunkGenerationTest::platformState);
|
||||
}
|
||||
|
||||
private static PillarSettings pillar(int x) {
|
||||
PillarSettings pillar = new PillarSettings();
|
||||
pillar.block = BlockState.parse("minecraft:oak_log[axis=y]");
|
||||
pillar.x = x;
|
||||
return pillar;
|
||||
}
|
||||
|
||||
private static <T extends art.arcane.iris.core.loader.IrisRegistrant> T configured(T owner, IrisFeature settings) {
|
||||
owner.setModuleSettings(ModuleSettings.of(Map.of(settings.getClass(), settings)));
|
||||
return owner;
|
||||
}
|
||||
|
||||
private static PlatformBlockState platformState(String key) {
|
||||
PlatformBlockState state = mock(PlatformBlockState.class);
|
||||
when(state.key()).thenReturn(key);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user