iris:biome and iris:custom are Iris's own modules in core, registered by IrisModuleHost ahead of the feature modules; same stage ids and order

This commit is contained in:
piexel committed 2026-10-10 14:25:56 +02:00
1 parent 95283099fe
commit 9147acca0c
5 files changed
+254 -8

No files matched your search

@@ -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.builtin.IrisStages;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBiome;
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 art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterBiomeInject;
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.StageGraph;
/**
* Module {@code iris:biome}: writes each column's biome into the chunk's biome hunk, a custom biome under the
* dimension's namespace, and records the biome id in the mantle for platforms that inject biomes later.
*/
public final class BiomeModule implements IrisModule {
private static final String VERSION = "built-in";
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:biome", "Biomes", VERSION);
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Biome.WRITE).run(BiomeModule::write);
}
private static void write(ChunkStageContext context) {
IrisChunk chunk = IrisChunk.current();
chunk.state(BiomeWriter.class, BiomeWriter::new).write(chunk.originX(), chunk.originZ(), chunk.biomes(), chunk.context());
}
/** What writing biomes keeps for one engine runtime: the biome stream's random and the platform biomes resolved so far. */
static final class BiomeWriter {
private final Engine engine;
private final RNG rng;
private final KMap<String, ResolvedBiome> resolvedBiomes = new KMap<>();
BiomeWriter(Engine engine) {
this.engine = engine;
this.rng = new RNG(engine.getSeedManager().getBiome());
}
/** A partial biome write fails the chunk: a chunk flagged done with default biomes would keep them forever. */
void write(int originX, int originZ, Hunk<PlatformBiome> biomes, ChunkContext context) {
PrecisionStopwatch stopwatch = PrecisionStopwatch.start();
Mantle<Matter> mantle = engine.getMantle().getMantle();
ChunkedDataCache<IrisBiome> biomeCache = context.getBiome();
for (int localX = 0; localX < biomes.getWidth(); localX++) {
for (int localZ = 0; localZ < biomes.getDepth(); localZ++) {
int worldX = originX + localX;
int worldZ = originZ + localZ;
ResolvedBiome resolved = resolve(keyOf(biomeCache.get(localX, localZ), worldX, worldZ));
if (resolved.biome() != null) {
biomes.set(localX, 0, localZ, localX, biomes.getHeight() - 1, localZ, resolved.biome());
}
mantle.set(worldX, 0, worldZ, resolved.matter());
}
}
engine.getMetrics().getBiome().put(stopwatch.getMilliseconds());
}
private String keyOf(IrisBiome biome, int worldX, int worldZ) {
if (!biome.isCustom()) {
return biome.getSkyBiomeKey(rng, engine, worldX, 0, worldZ);
}
IrisBiomeCustom custom = biome.getCustomBiome(rng, engine, worldX, 0, worldZ);
return engine.getDimension().getLoadKey() + ":" + custom.getId();
}
/**
* The registry lookup and the biome id depend only on the key, so the pair is cached instead of paying two
* string-keyed lookups per column. Unresolved biomes are never cached, so a biome registered later still
* resolves.
*/
private ResolvedBiome resolve(String key) {
ResolvedBiome cached = key == null ? null : resolvedBiomes.get(key);
if (cached != null) {
return cached;
}
IrisPlatform platform = IrisPlatforms.get();
PlatformBiome biome = platform.registries().biome(key);
ResolvedBiome resolved = new ResolvedBiome(biome, BiomeInjectMatter.get(platform.biomeWriter().biomeIdFor(key)));
if (key != null && biome != null) {
resolvedBiomes.put(key, resolved);
}
return resolved;
}
}
private record ResolvedBiome(PlatformBiome biome, MatterBiomeInject matter) {
}
}
@@ -0,0 +1,118 @@
/*
* 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.link.Identifier;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.parallel.BurstExecutor;
import art.arcane.iris.util.common.parallel.MultiBurst;
import art.arcane.iris.util.project.hunk.Hunk;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.matter.Matter;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.StageGraph;
/**
* Module {@code iris:custom}: records the chunk's content-plugin blocks for the server to place later: each
* custom block's placement key goes into the mantle and the block itself is replaced by its base state. Skipped
* while maintenance regeneration bypasses the mantle.
*/
public final class CustomModule implements IrisModule {
private static final String VERSION = "built-in";
private static final int CHUNK_SHIFT = 4;
private static final int SECTION_MASK = 15;
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:custom", "Custom blocks", VERSION);
}
@Override
public void install(StageGraph graph) {
// Ordering only: iris:perfection ships in the built-ins jar, which a pack may not have.
graph.define(IrisStages.Custom.BLOCKS).softAfter(IrisStages.Perfection.SURFACE.ref()).run(CustomModule::record);
}
private static void record(ChunkStageContext context) {
IrisChunk chunk = IrisChunk.current();
if (chunk.bypassesMantleStages()) {
return;
}
chunk.state(CustomBlockRecording.class, CustomBlockRecording::new).record(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore());
}
/** Moves the custom blocks of a chunk into the mantle for one engine runtime. */
static final class CustomBlockRecording {
private final Engine engine;
CustomBlockRecording(Engine engine) {
this.engine = engine;
}
/** Records the custom blocks of the chunk whose first block is {@code x}, {@code z}, when its mantle chunk is flagged as having some. */
void record(int x, int z, Hunk<PlatformBlockState> output, boolean multicore) {
MantleChunk<Matter> mc = engine.getMantle().getMantle().getChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
if (!mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) {
return;
}
mc.use();
BurstExecutor burst = MultiBurst.burst.burst(output.getHeight());
burst.setMulticore(multicore);
// complete() must run before release() even when queueing throws — detached burst
// tasks must never write into a released chunk, and a lost permit wedges close().
try {
for (int y = 0; y < output.getHeight(); y++) {
int finalY = y;
burst.queue(() -> {
for (int rX = 0; rX < output.getWidth(); rX++) {
for (int rZ = 0; rZ < output.getDepth(); rZ++) {
PlatformBlockState b = output.get(rX, finalY, rZ);
if (b == null || !b.isCustom()) {
continue;
}
String placementKey = b.deferredPlacementKey();
PlatformBlockState baseState = b.placementBaseState();
if (placementKey == null || baseState == null) {
continue;
}
mc.getOrCreate(finalY >> CHUNK_SHIFT)
.slice(Identifier.class)
.set(rX, finalY & SECTION_MASK, rZ, Identifier.fromString(placementKey));
output.set(rX, finalY, rZ, baseState);
}
}
});
}
} finally {
try {
burst.complete();
} finally {
mc.release();
}
}
}
}
}
@@ -19,7 +19,6 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.actuator.BiomeModule;
import art.arcane.iris.engine.actuator.DecorantModule;
import art.arcane.iris.engine.actuator.TerrainModule;
import art.arcane.iris.engine.loot.LootModule;
@@ -27,7 +26,6 @@ import art.arcane.iris.engine.mantle.components.ObjectModule;
import art.arcane.iris.engine.spawn.SpawnModule;
import art.arcane.iris.engine.mantle.components.StructureModule;
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.object.placement.PlacementModules;
@@ -72,14 +70,19 @@ public final class IrisModuleHost {
return Holder.HOST;
}
/** The modules every pack loads before its own: Iris's built-in features, placement and the chunk generation every world runs. */
/** The modules every pack loads before its own: Iris's own, placement and the chunk generation every world runs. */
public static List<IrisModule> builtInModules() {
return Stream.concat(PlacementModules.all().stream(), generationModules().stream()).toList();
return Stream.of(hostModules(), PlacementModules.all(), generationModules()).flatMap(List::stream).toList();
}
/** Modules that are Iris itself, not features: they write the layout's platform biomes and record the platform's custom blocks. A pack never replaces them and the built-ins jar does not hold them. */
private static List<IrisModule> hostModules() {
return List.of(new BiomeModule(), new CustomModule());
}
private static List<IrisModule> generationModules() {
return List.of(new BiomeModule(), new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
new FloatingModule(), new DepositModule(), new DecorantModule(), new CustomModule(), new LootModule(), new SpawnModule());
return List.of(new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
new FloatingModule(), new DepositModule(), new DecorantModule(), new LootModule(), new SpawnModule());
}
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
@@ -1,4 +1,4 @@
package art.arcane.iris.engine.actuator;
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineMetrics;
@@ -1,4 +1,4 @@
package art.arcane.iris.engine.modifier;
package art.arcane.iris.core.modules;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.link.Identifier;