mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Run built-in chunk modules on Iris's own block hunk
- IrisChunk gives Iris's built-in chunk stages the engine, Iris's block hunk and the chunk context, bound on the generating thread while the pack's chunk graph runs. - iris:perfection joins the built-in modules every pack loads. - PerfectionModuleTest runs it through the chunk graph.
This commit is contained in:
1 parent
2aab5ae9a3
commit
f052960e2f
5 files changed
+231
-5
No files matched your search
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Iris's own view of the chunk whose module stages are running: the engine, Iris's block hunk and the
|
||||
* chunk's sampled context. Iris's built-in chunk stages read them through {@link #current()}, bound on the
|
||||
* generating thread while the chunk graph runs, and work on Iris's block states directly; pack modules
|
||||
* cannot see this class.
|
||||
*/
|
||||
public final class IrisChunk {
|
||||
private static final ScopedValue<IrisChunk> CURRENT = ScopedValue.newInstance();
|
||||
|
||||
private final Engine engine;
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final Hunk<PlatformBlockState> blocks;
|
||||
private final ChunkContext context;
|
||||
|
||||
IrisChunk(Engine engine, int originX, int originZ, Hunk<PlatformBlockState> blocks, ChunkContext context) {
|
||||
this.engine = engine;
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.blocks = blocks;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/** The chunk generating on this thread. */
|
||||
public static IrisChunk current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris chunk is generating on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
void runBound(Runnable generation) {
|
||||
ScopedValue.where(CURRENT, this).run(generation);
|
||||
}
|
||||
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** The chunk's first block along X. */
|
||||
public int originX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
/** The chunk's first block along Z. */
|
||||
public int originZ() {
|
||||
return originZ;
|
||||
}
|
||||
|
||||
/** The chunk's blocks, indexed from its first block; Iris leaves unset blocks null. */
|
||||
public Hunk<PlatformBlockState> blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** What the engine sampled for this chunk, such as its biomes and heights. */
|
||||
public ChunkContext context() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.object.placement.PlacementModules;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -26,6 +27,7 @@ import com.volmit.host.PackModules;
|
||||
|
||||
import java.nio.file.Path;
|
||||
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
|
||||
@@ -48,7 +50,7 @@ public final class IrisModuleHost {
|
||||
|
||||
/** The modules every pack loads before its own: Iris's built-in features. */
|
||||
public static List<IrisModule> builtInModules() {
|
||||
return PlacementModules.all();
|
||||
return Stream.concat(PlacementModules.all().stream(), Stream.of(new PerfectionModule())).toList();
|
||||
}
|
||||
|
||||
private static ModuleHost build() {
|
||||
|
||||
@@ -49,11 +49,11 @@ public final class ModuleChunkGeneration {
|
||||
|
||||
/** {@code x} and {@code z} are the chunk's first block, as engine stages receive them. */
|
||||
public static void generate(Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, ChunkContext context) {
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, blocks,
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, blocks, context,
|
||||
context.getRegion().get(CHUNK_CENTER, CHUNK_CENTER), context.getBiome().get(CHUNK_CENTER, CHUNK_CENTER), B::getState);
|
||||
}
|
||||
|
||||
static void generate(LoadedPack pack, Engine engine, int x, int z, Hunk<PlatformBlockState> blocks,
|
||||
static void generate(LoadedPack pack, Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, ChunkContext context,
|
||||
IrisRegion centerRegion, IrisBiome centerBiome, Function<String, PlatformBlockState> platformStates) {
|
||||
ResolvedGraph chunk = pack.chunk();
|
||||
if (chunk.stages().isEmpty()) {
|
||||
@@ -63,6 +63,6 @@ public final class ModuleChunkGeneration {
|
||||
IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z,
|
||||
new BlockStateHunk(blocks, platformStates), chunk.reach().blocks());
|
||||
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), x >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
|
||||
new ChunkRunner(chunk).generate(inputs, seed, settings);
|
||||
new IrisChunk(engine, x, z, blocks, context).runBound(() -> new ChunkRunner(chunk).generate(inputs, seed, settings));
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class ModuleChunkGenerationTest {
|
||||
}
|
||||
|
||||
private void generate(IrisBiome biome) {
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, new IrisRegion(), biome, ModuleChunkGenerationTest::platformState);
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, new IrisRegion(), biome, ModuleChunkGenerationTest::platformState);
|
||||
}
|
||||
|
||||
private static PillarSettings pillar(int x) {
|
||||
|
||||
@@ -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.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.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimensionModeType;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
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.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
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 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(IrisModuleHost.builtInModules()).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 overworldChunksLoseDecorationsTheirGroundCannotHold() {
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void otherWorldModesKeepEveryDecoration() {
|
||||
dimension.getMode().setType(IrisDimensionModeType.SUPERFLAT);
|
||||
PlatformBlockState floating = decorant(false);
|
||||
blocks.set(0, 1, 0, floating);
|
||||
|
||||
generate();
|
||||
|
||||
assertSame(floating, blocks.get(0, 1, 0));
|
||||
}
|
||||
|
||||
private void generate() {
|
||||
ModuleChunkGeneration.generate(pack, engine, 0, 0, blocks, null, new IrisRegion(), new IrisBiome(), key -> block(key, false));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user