Port perfection to an IrisApi chunk module

- iris:perfection/surface does what IrisPerfectionModifier did on
  overworld chunks: hide ores when the dimension asks, then remove
  decorations whose block below cannot hold them until none is left.
- It runs in the pack's chunk graph on Iris's block hunk, after the
  world mode's stages, so it now follows the custom block stage instead
  of preceding it. ModeOverworld no longer registers it and
  IrisPerfectionModifier is deleted.
- The passes run on the generating thread instead of fanning columns out
  to the burst executor.
This commit is contained in:
piexel committed 2026-10-08 08:50:51 +02:00
1 parent 522a9c85b6
commit 90f5181a88
4 files changed
+218 -204

No files matched your search

@@ -0,0 +1,31 @@
/*
* 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.builtin.perfection;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.Stage;
/** Module {@code iris:perfection}: the last touches on an overworld chunk's blocks. */
public final class PerfectionStages {
/** Hides ores when the dimension asks, then removes decorations that nothing holds up. */
public static final ChunkStage<Void> SURFACE = Stage.chunk("iris:perfection/surface");
private PerfectionStages() {
}
}
@@ -30,7 +30,6 @@ import art.arcane.iris.engine.modifier.IrisCarveModifier;
import art.arcane.iris.engine.modifier.IrisCustomModifier;
import art.arcane.iris.engine.modifier.IrisDepositModifier;
import art.arcane.iris.engine.modifier.IrisFloatingChildBiomeModifier;
import art.arcane.iris.engine.modifier.IrisPerfectionModifier;
import art.arcane.iris.engine.modifier.IrisPostModifier;
import art.arcane.iris.spi.IrisLogging;
@@ -49,7 +48,6 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
IrisCarveModifier cave = new IrisCarveModifier(getEngine());
IrisPostModifier post = new IrisPostModifier(getEngine());
IrisDepositModifier deposit = new IrisDepositModifier(getEngine());
IrisPerfectionModifier perfection = new IrisPerfectionModifier(getEngine());
IrisCustomModifier custom = new IrisCustomModifier(getEngine());
IrisFloatingChildBiomeModifier floatingChildBiomes = new IrisFloatingChildBiomeModifier(getEngine());
EngineStage sBiome = (x, z, k, p, m, c) -> biome.actuate(x, z, p, m, c);
@@ -91,7 +89,6 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
};
EngineStage sFloatingTerrainSolid = (x, z, k, p, m, c) -> floatingChildBiomes.modify(x, z, k, m, c);
EngineStage sFloatingDecorate = (x, z, k, p, m, c) -> floatingChildBiomes.decorateColumns(x, z, k, m, c);
EngineStage sPerfection = (x, z, k, p, m, c) -> perfection.modify(x, z, k, m, c);
EngineStage sCustom = (x, z, k, p, m, c) -> {
if (shouldBypassMantleStages()) {
return;
@@ -115,7 +112,6 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
registerStage(sInsertMatter);
registerStage(sDecorant);
registerStage(sFloatingDecorate);
registerStage(sPerfection);
registerStage(sCustom);
}
@@ -1,200 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.framework.Engine;
import art.arcane.iris.engine.framework.EngineAssignedModifier;
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.iris.util.common.data.B;
import art.arcane.iris.util.project.hunk.Hunk;
import art.arcane.iris.util.common.parallel.BurstExecutor;
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
import art.arcane.iris.spi.PlatformBlockState;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
public class IrisPerfectionModifier extends EngineAssignedModifier<PlatformBlockState> {
private static final class States {
private static final PlatformBlockState AIR = B.getState("AIR");
private static final PlatformBlockState WATER = B.getState("WATER");
private static final Map<String, PlatformBlockState> ORE_BASES = buildOreBases();
}
public IrisPerfectionModifier(Engine engine) {
super(engine, "Perfection");
}
private static Map<String, PlatformBlockState> buildOreBases() {
Map<String, PlatformBlockState> map = new HashMap<>();
PlatformBlockState stone = B.getState("STONE");
PlatformBlockState deepslate = B.getState("DEEPSLATE");
PlatformBlockState netherrack = B.getState("NETHERRACK");
PlatformBlockState blackstone = B.getState("BLACKSTONE");
map.put("minecraft:coal_ore", stone);
map.put("minecraft:copper_ore", stone);
map.put("minecraft:iron_ore", stone);
map.put("minecraft:gold_ore", stone);
map.put("minecraft:redstone_ore", stone);
map.put("minecraft:lapis_ore", stone);
map.put("minecraft:diamond_ore", stone);
map.put("minecraft:emerald_ore", stone);
map.put("minecraft:deepslate_coal_ore", deepslate);
map.put("minecraft:deepslate_copper_ore", deepslate);
map.put("minecraft:deepslate_iron_ore", deepslate);
map.put("minecraft:deepslate_gold_ore", deepslate);
map.put("minecraft:deepslate_redstone_ore", deepslate);
map.put("minecraft:deepslate_lapis_ore", deepslate);
map.put("minecraft:deepslate_diamond_ore", deepslate);
map.put("minecraft:deepslate_emerald_ore", deepslate);
map.put("minecraft:nether_gold_ore", netherrack);
map.put("minecraft:nether_quartz_ore", netherrack);
map.put("minecraft:ancient_debris", netherrack);
map.put("minecraft:gilded_blackstone", blackstone);
return map;
}
private static String baseKey(PlatformBlockState state) {
String key = state.key();
int bracket = key.indexOf('[');
return bracket < 0 ? key : key.substring(0, bracket);
}
@Override
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
PrecisionStopwatch p = PrecisionStopwatch.start();
if (getDimension().isHideOresForHiddenOre()) {
hideOres(output, multicore);
}
AtomicBoolean changed = new AtomicBoolean(true);
BurstExecutor burst = burst().burst(multicore);
while (changed.get()) {
changed.set(false);
for (int i = 0; i < 16; i++) {
int finalI = i;
burst.queue(() -> {
List<Integer> surfaces = new ArrayList<>();
List<Integer> ceilings = new ArrayList<>();
for (int j = 0; j < 16; j++) {
surfaces.clear();
ceilings.clear();
int top = getHeight(output, finalI, j);
boolean inside = true;
surfaces.add(top);
for (int k = top; k >= 0; k--) {
PlatformBlockState b = output.get(finalI, k, j);
boolean now = b != null && !(B.isAir(b) || B.isFluid(b));
if (now != inside) {
inside = now;
if (inside) {
surfaces.add(k);
} else {
ceilings.add(k + 1);
}
}
}
for (int k : surfaces) {
PlatformBlockState tip = output.get(finalI, k, j);
if (tip == null) {
continue;
}
boolean remove = false;
boolean remove2 = false;
if (B.isDecorant(tip)) {
PlatformBlockState bel = output.get(finalI, k - 1, j);
if (bel == null) {
remove = true;
} else if (!B.canPlaceOnto(tip, bel)) {
remove = true;
} else if (IrisProceduralBlocks.hasProperty(bel, "half")) {
PlatformBlockState bb = output.get(finalI, k - 2, j);
if (bb == null || !B.canPlaceOnto(bel, bb)) {
remove = true;
remove2 = true;
}
}
if (remove) {
changed.set(true);
output.set(finalI, k, j, States.AIR);
if (remove2) {
output.set(finalI, k - 1, j, States.AIR);
}
}
}
}
}
});
}
burst.complete();
}
getEngine().getMetrics().getPerfection().put(p.getMilliseconds());
}
private void hideOres(Hunk<PlatformBlockState> output, boolean multicore) {
BurstExecutor burst = burst().burst(multicore);
int height = output.getHeight();
for (int i = 0; i < 16; i++) {
int finalI = i;
burst.queue(() -> {
for (int j = 0; j < 16; j++) {
for (int k = height - 1; k >= 0; k--) {
PlatformBlockState block = output.get(finalI, k, j);
if (block == null) {
continue;
}
PlatformBlockState base = States.ORE_BASES.get(baseKey(block));
if (base != null) {
output.set(finalI, k, j, base);
}
}
}
});
}
burst.complete();
}
private int getHeight(Hunk<PlatformBlockState> output, int x, int z) {
for (int i = output.getHeight() - 1; i >= 0; i--) {
PlatformBlockState b = output.get(x, i, z);
if (b != null) {
if (!B.isAir(b) && !B.isFluid(b)) {
return i;
}
}
}
return 0;
}
}
@@ -0,0 +1,187 @@
/*
* 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.perfection.PerfectionStages;
import art.arcane.iris.core.modules.IrisChunk;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.world.dimension.IrisDimensionModeType;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import art.arcane.iris.util.project.hunk.Hunk;
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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Module {@code iris:perfection}: on overworld chunks, turns ores back into the stone around them when the
* dimension hides its ores, then removes decorations whose block below cannot hold them, again until none
* is left, since removing one can strand the one above.
*/
public final class PerfectionModule implements IrisModule {
private static final String VERSION = "built-in";
private static final String HALF = "half";
private static final char PROPERTIES_START = '[';
private static final class States {
private static final PlatformBlockState AIR = B.getState("AIR");
private static final Map<String, PlatformBlockState> ORE_BASES = oreBases();
}
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:perfection", "Perfection", VERSION);
}
@Override
public void install(StageGraph graph) {
graph.define(PerfectionStages.SURFACE).run(PerfectionModule::perfect);
}
private static void perfect(ChunkStageContext context) {
IrisChunk chunk = IrisChunk.current();
Engine engine = chunk.engine();
IrisDimension dimension = engine.getDimension();
if (dimension.getMode().getType() != IrisDimensionModeType.OVERWORLD) {
return;
}
PrecisionStopwatch stopwatch = PrecisionStopwatch.start();
Hunk<PlatformBlockState> blocks = chunk.blocks();
if (dimension.isHideOresForHiddenOre()) {
hideOres(blocks);
}
boolean removed;
do {
removed = removeUnsupportedDecorants(blocks);
} while (removed);
engine.getMetrics().getPerfection().put(stopwatch.getMilliseconds());
}
private static void hideOres(Hunk<PlatformBlockState> blocks) {
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
for (int y = blocks.getHeight() - 1; y >= 0; y--) {
PlatformBlockState block = blocks.get(x, y, z);
PlatformBlockState base = block == null ? null : States.ORE_BASES.get(materialOf(block));
if (base != null) {
blocks.set(x, y, z, base);
}
}
}
}
}
/** One pass over every column; whether it removed anything. */
private static boolean removeUnsupportedDecorants(Hunk<PlatformBlockState> blocks) {
boolean removed = false;
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
for (int surface : surfaces(blocks, x, z)) {
removed |= removeIfUnsupported(blocks, x, surface, z);
}
}
}
return removed;
}
/** The topmost solid block of a column and each solid block with open space above it below that. */
private static List<Integer> surfaces(Hunk<PlatformBlockState> blocks, int x, int z) {
List<Integer> surfaces = new ArrayList<>();
int top = topSolid(blocks, x, z);
surfaces.add(top);
boolean inside = true;
for (int y = top; y >= 0; y--) {
boolean solid = isSolid(blocks.get(x, y, z));
if (solid != inside) {
inside = solid;
if (inside) {
surfaces.add(y);
}
}
}
return surfaces;
}
private static boolean removeIfUnsupported(Hunk<PlatformBlockState> blocks, int x, int y, int z) {
PlatformBlockState tip = blocks.get(x, y, z);
if (tip == null || !B.isDecorant(tip)) {
return false;
}
PlatformBlockState below = blocks.get(x, y - 1, z);
if (below == null || !B.canPlaceOnto(tip, below)) {
blocks.set(x, y, z, States.AIR);
return true;
}
if (!IrisProceduralBlocks.hasProperty(below, HALF)) {
return false;
}
PlatformBlockState belowBelow = blocks.get(x, y - 2, z);
if (belowBelow != null && B.canPlaceOnto(below, belowBelow)) {
return false;
}
blocks.set(x, y, z, States.AIR);
blocks.set(x, y - 1, z, States.AIR);
return true;
}
private static int topSolid(Hunk<PlatformBlockState> blocks, int x, int z) {
for (int y = blocks.getHeight() - 1; y >= 0; y--) {
if (isSolid(blocks.get(x, y, z))) {
return y;
}
}
return 0;
}
private static boolean isSolid(PlatformBlockState block) {
return block != null && !(B.isAir(block) || B.isFluid(block));
}
private static String materialOf(PlatformBlockState state) {
String key = state.key();
int properties = key.indexOf(PROPERTIES_START);
return properties < 0 ? key : key.substring(0, properties);
}
private static Map<String, PlatformBlockState> oreBases() {
Map<String, PlatformBlockState> bases = new HashMap<>();
PlatformBlockState stone = B.getState("STONE");
PlatformBlockState deepslate = B.getState("DEEPSLATE");
PlatformBlockState netherrack = B.getState("NETHERRACK");
PlatformBlockState blackstone = B.getState("BLACKSTONE");
for (String ore : List.of("coal", "copper", "iron", "gold", "redstone", "lapis", "diamond", "emerald")) {
bases.put("minecraft:" + ore + "_ore", stone);
bases.put("minecraft:deepslate_" + ore + "_ore", deepslate);
}
bases.put("minecraft:nether_gold_ore", netherrack);
bases.put("minecraft:nether_quartz_ore", netherrack);
bases.put("minecraft:ancient_debris", netherrack);
bases.put("minecraft:gilded_blackstone", blackstone);
return bases;
}
}