diff --git a/source-patterns.txt b/source-patterns.txt index 149aa02d1..6e0d633f7 100644 --- a/source-patterns.txt +++ b/source-patterns.txt @@ -16,3 +16,4 @@ art/arcane/iris/engine/framework/StructurePlacementMarker.java art/arcane/iris/engine/framework/StructureVerticalBounds.java art/arcane/iris/engine/framework/PlacedObject.java art/arcane/iris/engine/framework/PlacedStructurePiece.java +art/arcane/iris/builtin/** diff --git a/src/main/java/art/arcane/iris/builtin/anchor/AnchorHeight.java b/src/main/java/art/arcane/iris/builtin/anchor/AnchorHeight.java new file mode 100644 index 000000000..0b2806875 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/anchor/AnchorHeight.java @@ -0,0 +1,23 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.anchor; + +/** The height an object's anchor is placed at. */ +public record AnchorHeight(int y) { +} diff --git a/src/main/java/art/arcane/iris/builtin/anchor/AnchorStages.java b/src/main/java/art/arcane/iris/builtin/anchor/AnchorStages.java new file mode 100644 index 000000000..06a08a51a --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/anchor/AnchorStages.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.anchor; + +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:anchor}: the height an object is placed at. */ +public final class AnchorStages { + /** The requested or sampled height the checks judge. Rejects {@code carving-anchor}. */ + public static final PlacementStage HEIGHT = Stage.placement("iris:anchor/height", AnchorHeight.class); + /** The height the object's blocks are written at: the checked height plus the random offset. */ + public static final PlacementStage FINAL = Stage.placement("iris:anchor/final", AnchorHeight.class); + + private AnchorStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/blocks/BlocksStages.java b/src/main/java/art/arcane/iris/builtin/blocks/BlocksStages.java new file mode 100644 index 000000000..615043113 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/blocks/BlocksStages.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.blocks; + +import com.volmit.stage.BlockStage; +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:blocks}: writing the object's blocks. */ +public final class BlocksStages { + /** Writes each object block where the placement puts it. */ + public static final BlockStage WRITE = Stage.placementBlock("iris:blocks/write", WrittenBlocks.class); + /** Marks some written blocks with the placement's markers. */ + public static final PlacementStage MARKERS = Stage.placement("iris:blocks/markers"); + /** Milestone: stages requiring it run after the object and its markers are written. */ + public static final PlacementStage COMPLETE = Stage.placement("iris:blocks/complete"); + + private BlocksStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/blocks/ObjectMarkers.java b/src/main/java/art/arcane/iris/builtin/blocks/ObjectMarkers.java new file mode 100644 index 000000000..624e1f3b8 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/blocks/ObjectMarkers.java @@ -0,0 +1,54 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.blocks; + +import com.volmit.placement.PlacedMarker; +import com.volmit.resource.ResourceId; +import com.volmit.world.BlockPosition; + +import java.util.Map; + +/** + * Iris markers as IrisApi placement markers: type {@code iris:marker}, naming the pack's marker under the + * {@code marker} attribute. Iris stores markers of this type only. + */ +public final class ObjectMarkers { + public static final ResourceId TYPE = ResourceId.parse("iris:marker"); + public static final String MARKER_ATTRIBUTE = "marker"; + + private ObjectMarkers() { + } + + /** {@code markerKey} is the pack's marker, such as {@code spawn/zombie}. */ + public static PlacedMarker of(BlockPosition position, String markerKey) { + return new PlacedMarker(position, TYPE, Map.of(MARKER_ATTRIBUTE, markerKey)); + } + + public static String markerKey(PlacedMarker marker) { + requireIrisMarker(marker); + return marker.attributes().get(MARKER_ATTRIBUTE); + } + + public static void requireIrisMarker(PlacedMarker marker) { + if (!marker.type().equals(TYPE) || !marker.attributes().containsKey(MARKER_ATTRIBUTE)) { + throw new IllegalArgumentException("Iris stores markers of type " + TYPE + " with a \"" + MARKER_ATTRIBUTE + + "\" attribute only, not " + marker.type() + " " + marker.attributes()); + } + } +} diff --git a/src/main/java/art/arcane/iris/builtin/blocks/WrittenBlocks.java b/src/main/java/art/arcane/iris/builtin/blocks/WrittenBlocks.java new file mode 100644 index 000000000..df0c6d515 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/blocks/WrittenBlocks.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.blocks; + +import com.volmit.placement.PlacedBlock; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** The object's own blocks a placement wrote, in world positions, in the order they were written. */ +public final class WrittenBlocks { + private final List blocks = new ArrayList<>(); + + public void add(PlacedBlock block) { + blocks.add(block); + } + + public List blocks() { + return Collections.unmodifiableList(blocks); + } + + public boolean isEmpty() { + return blocks.isEmpty(); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/bore/BoreStages.java b/src/main/java/art/arcane/iris/builtin/bore/BoreStages.java new file mode 100644 index 000000000..3d7357387 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/bore/BoreStages.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.bore; + +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:bore}: clearing the object's volume before its blocks are written. */ +public final class BoreStages { + public static final PlacementStage CLEAR = Stage.placement("iris:bore/clear"); + + private BoreStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/package-info.java b/src/main/java/art/arcane/iris/builtin/package-info.java new file mode 100644 index 000000000..a21ac18f4 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/package-info.java @@ -0,0 +1,34 @@ +/* + * 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 . + */ + +/** + * The public face of Iris's built-in modules: their stage constants and the settings and output types + * of those stages. {@link art.arcane.iris.core.modules.IrisModuleHost} exposes this package, with its + * subpackages, to pack modules, so a pack jar can {@code requires(...)} a built-in stage and read its + * output. Everything here is part of what packs compile against. + *

+ * Keep implementation out of it: stage bodies and anything that uses Iris internals live in the + * built-in module classes outside this package, which packs cannot see. One subpackage per built-in + * module, named after the module path, such as {@code art.arcane.iris.builtin.deposit} for + * {@code iris:deposit}. + *

+ * Some built-in stages produce Iris's own types, such as the placement settings of {@code iris:prepare}. A + * pack module can require such a stage to run after it, but cannot read its output: the pack load rejects + * a pack class that uses a type Iris hides. + */ +package art.arcane.iris.builtin; diff --git a/src/main/java/art/arcane/iris/builtin/prepare/PrepareStages.java b/src/main/java/art/arcane/iris/builtin/prepare/PrepareStages.java new file mode 100644 index 000000000..47a67271d --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/prepare/PrepareStages.java @@ -0,0 +1,35 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.prepare; + +import art.arcane.iris.engine.object.placement.IrisObjectPlacement; +import art.arcane.iris.engine.object.placement.PreparedPlacement; +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:prepare}: what a placement decides before it looks for its height. */ +public final class PrepareStages { + /** The settings the placement uses: the requested ones, turned downhill when they ask to face the slope. Rejects {@code slope}. */ + public static final PlacementStage SLOPE = Stage.placement("iris:prepare/slope", IrisObjectPlacement.class); + /** The random rotation, translation and height offset, chosen once per placement. */ + public static final PlacementStage TRANSFORMS = Stage.placement("iris:prepare/transforms", PreparedPlacement.class); + + private PrepareStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/snow/SnowStages.java b/src/main/java/art/arcane/iris/builtin/snow/SnowStages.java new file mode 100644 index 000000000..2a51efd05 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/snow/SnowStages.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.snow; + +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:snow}: snow on the object, after its stilt or terrain bend. */ +public final class SnowStages { + public static final PlacementStage COVER = Stage.placement("iris:snow/cover"); + + private SnowStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/stilt/StiltLayers.java b/src/main/java/art/arcane/iris/builtin/stilt/StiltLayers.java new file mode 100644 index 000000000..5ad22327e --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/stilt/StiltLayers.java @@ -0,0 +1,74 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.stilt; + +import com.volmit.object.ObjectBlock; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * The bottom and top layers of the blocks a stilt can repeat, with their positions already transformed + * around the anchor. Each layer keeps the blocks at its lowest or highest height seen so far. + */ +public final class StiltLayers { + private final List bottom = new ArrayList<>(); + private final List top = new ArrayList<>(); + private int bottomY = Integer.MAX_VALUE; + private int topY = Integer.MIN_VALUE; + + public void include(ObjectBlock transformed) { + int y = transformed.position().y(); + if (y < bottomY) { + bottomY = y; + bottom.clear(); + } + if (y == bottomY) { + bottom.add(transformed); + } + if (y > topY) { + topY = y; + top.clear(); + } + if (y == topY) { + top.add(transformed); + } + } + + public boolean isEmpty() { + return bottom.isEmpty(); + } + + public List bottom() { + return Collections.unmodifiableList(bottom); + } + + public List top() { + return Collections.unmodifiableList(top); + } + + public int bottomY() { + return bottomY; + } + + public int topY() { + return topY; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/stilt/StiltStages.java b/src/main/java/art/arcane/iris/builtin/stilt/StiltStages.java new file mode 100644 index 000000000..a3f9a78f8 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/stilt/StiltStages.java @@ -0,0 +1,34 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.stilt; + +import com.volmit.stage.BlockStage; +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:stilt}: the stilts of the stilt and ceiling placement modes. */ +public final class StiltStages { + /** Finds the layers to repeat. */ + public static final BlockStage LAYERS = Stage.placementBlock("iris:stilt/layers", StiltLayers.class); + /** Grows the stilt once the object is written. */ + public static final PlacementStage FILL = Stage.placement("iris:stilt/fill"); + + private StiltStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/vacuum/VacuumStages.java b/src/main/java/art/arcane/iris/builtin/vacuum/VacuumStages.java new file mode 100644 index 000000000..2c23b4b73 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/vacuum/VacuumStages.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.vacuum; + +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:vacuum}: bending the terrain to meet objects of the vacuum placement modes. */ +public final class VacuumStages { + public static final PlacementStage TERRAIN = Stage.placement("iris:vacuum/terrain"); + + private VacuumStages() { + } +} diff --git a/src/main/java/art/arcane/iris/builtin/validate/ValidateStages.java b/src/main/java/art/arcane/iris/builtin/validate/ValidateStages.java new file mode 100644 index 000000000..3446c39bc --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/validate/ValidateStages.java @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.validate; + +import com.volmit.stage.PlacementStage; +import com.volmit.stage.Stage; + +/** Module {@code iris:validate}: the checks that reject a placement before anything is written, in this order. */ +public final class ValidateStages { + /** Rejects {@code bedrock-anchor} and {@code surface-support}. */ + public static final PlacementStage SURFACE = Stage.placement("iris:validate/surface"); + /** Rejects {@code underwater-anchor}, {@code cave-clearance}, {@code fluid-height} and {@code height-clamp}. */ + public static final PlacementStage LIMITS = Stage.placement("iris:validate/limits"); + /** Rejects {@code native-structure}, even for placements that force their way past the other checks. */ + public static final PlacementStage STRUCTURES = Stage.placement("iris:validate/structures"); + /** Rejects {@code object-collision}. */ + public static final PlacementStage COLLISIONS = Stage.placement("iris:validate/collisions"); + + private ValidateStages() { + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/marker/ObjectMarkerPlacement.java b/src/main/java/art/arcane/iris/engine/object/marker/ObjectMarkerPlacement.java deleted file mode 100644 index 44f27a422..000000000 --- a/src/main/java/art/arcane/iris/engine/object/marker/ObjectMarkerPlacement.java +++ /dev/null @@ -1,108 +0,0 @@ -package art.arcane.iris.engine.object.marker; - -import art.arcane.iris.engine.object.placement.IObjectPlacer; -import art.arcane.iris.engine.object.placement.IrisObjectPlacement; -import art.arcane.iris.engine.object.placement.PlacementContext; -import art.arcane.iris.engine.object.placement.PlacementState; -import art.arcane.iris.engine.object.prefab.IrisObjectShaping; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.BlockPosition; -import art.arcane.volmlib.util.math.RNG; -import art.arcane.volmlib.util.matter.MatterMarker; - -import java.util.ArrayList; -import java.util.List; - -public class ObjectMarkerPlacement { - - private IrisObjectPlacement config; - private PlacementContext context; - private final IObjectPlacer placer; - private RNG markerRng; - List placements; - - public ObjectMarkerPlacement(PlacementContext context, PlacementState state) { - this.config = state.getConfig(); - this.placer = state.getPlacer(); - this.context = context; - this.markerRng = context.getRng().nextParallelRNG(((((long) context.getX()) << 32) | (context.getZ() & 0xFFFFFFFFL)) * 31L + context.getYv()); - this.placements = new ArrayList<>(); - } - - public void loadPossibleMarkers() { - // Marker selection persists into the mantle, so it must be seed-deterministic. - // Derive a side stream keyed on the placement position instead of consuming the - // caller's rng: consuming draws there would shift every later placement in the - // chunk and invalidate existing worlds/goldenhashes. - int index = 0; - for (IrisObjectMarker markerConfig : config.getMarkers()) { - IrisMarker marker = context.getSelf().getLoader().getMarkerLoader().load(markerConfig.getMarker()); - int markerSalt = index++; - if (marker != null) { - placements.add(new ObjectMarkerPlacement.MarkerPlacement(markerConfig, marker, - markerConfig.getMark(context.getRdata()), markerSalt)); - } - } - } - - public List matchMarkers(PlatformBlockState state) { - List matching = new ArrayList<>(); - for (ObjectMarkerPlacement.MarkerPlacement markerPlacement : placements) { - if (markerPlacement.matches(state)) { - matching.add(markerPlacement); - } - } - return matching; - } - - public void placeMarkers() { - for (ObjectMarkerPlacement.MarkerPlacement markerPlacement : placements) { - int max = markerPlacement.config.getMaximumMarkers(); - for (BlockPosition position : markerPlacement.candidates - .shuffleCopy(markerRng.nextParallelRNG(markerPlacement.salt))) { - if (max <= 0) { - break; - } - - boolean firstAboveAir = B.isAir(placer.get(position.getX(), position.getY() + 1, position.getZ())); - boolean secondAboveAir = B.isAir(placer.get(position.getX(), position.getY() + 2, position.getZ())); - if (!markerPlacement.marker.isEmptyAbove() || (firstAboveAir && secondAboveAir)) { - placer.setData(position.getX(), position.getY(), position.getZ(), - new MatterMarker(markerPlacement.config.getMarker())); - max--; - } - } - } - - } - - public static final class MarkerPlacement { - public final IrisObjectMarker config; - public final IrisMarker marker; - public final Iterable targets; - public final int salt; - public final KList candidates = new KList<>(); - - public MarkerPlacement(IrisObjectMarker config, IrisMarker marker, - Iterable targets, int salt) { - this.config = config; - this.marker = marker; - this.targets = targets; - this.salt = salt; - } - - public boolean matches(PlatformBlockState state) { - for (PlatformBlockState target : targets) { - if (config.isExact() - ? target.matches(state) - : IrisObjectShaping.materialKey(target).equals(IrisObjectShaping.materialKey(state))) { - return true; - } - } - return false; - } - } - -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/AnchorModule.java b/src/main/java/art/arcane/iris/engine/object/placement/AnchorModule.java new file mode 100644 index 000000000..4f48b0b8d --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/AnchorModule.java @@ -0,0 +1,163 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.anchor.AnchorHeight; +import art.arcane.iris.builtin.anchor.AnchorStages; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.builtin.validate.ValidateStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.engine.object.terrain.carving.CarvingMode; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; + +/** + * Module {@code iris:anchor}: the height an object is placed at, requested by the caller, counted from the + * bottom of the world, or sampled from the terrain the way the placement mode says. A surface-anchored + * placement rejects a height its carving support forbids. + */ +public final class AnchorModule implements IrisModule { + private static final String CARVING_ANCHOR = "carving-anchor"; + private static final int CARVING_CLEARANCE_BLOCKS = 4; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:anchor", "Placement anchor", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(AnchorStages.HEIGHT) + .requires(PrepareStages.TRANSFORMS) + .produce(AnchorModule::height); + graph.define(AnchorStages.FINAL) + .requires(AnchorStages.HEIGHT, ValidateStages.COLLISIONS) + .produce(AnchorModule::finalHeight); + } + + private static AnchorHeight height(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + boolean structurePiece = prepared.mode() == ObjectPlaceMode.STRUCTURE_PIECE; + if (!config.isFromBottom() && placement.requestedY() < 0) { + return new AnchorHeight(sampled(context, placement, prepared)); + } + IrisObject object = placement.object(); + int y = config.isFromBottom() ? object.getH() + 1 + prepared.rotatedCenterY() : placement.requestedY(); + if (!config.isForcePlace() && !structurePiece && rejectsCarvingAnchor(prepared, placement.x(), y, placement.z())) { + context.reject(CARVING_ANCHOR); + return new AnchorHeight(y); + } + if (placement.requestedY() < 0 || !config.isBottom() || structurePiece) { + return new AnchorHeight(y); + } + y += Math.floorDiv(object.h, 2); + if (!config.isForcePlace() && config.getCarvingSupport() != CarvingMode.CARVING_ONLY + && rejectsCarvingAnchor(prepared, placement.x(), y, placement.z())) { + context.reject(CARVING_ANCHOR); + } + return new AnchorHeight(y); + } + + private static AnchorHeight finalHeight(PlacementStageContext context) { + int y = context.output(AnchorStages.HEIGHT).y() + context.output(PrepareStages.TRANSFORMS).randomY(); + IrisPlacement.current().anchoredAt(y); + return new AnchorHeight(y); + } + + private static int sampled(PlacementStageContext context, IrisPlacement placement, PreparedPlacement prepared) { + return switch (prepared.mode().anchor()) { + case CENTER -> checked(context, prepared, placement.x(), centerSurface(placement, prepared), placement.z()); + case SURFACE -> checked(context, prepared, placement.x(), surface(placement, prepared, placement.x(), placement.z()), placement.z()); + case HIGHEST -> extremeSurface(context, placement, prepared, true, false); + case HIGHEST_CORNER -> extremeSurface(context, placement, prepared, true, true); + case LOWEST -> extremeSurface(context, placement, prepared, false, false); + case LOWEST_CORNER -> extremeSurface(context, placement, prepared, false, true); + case TRANSLATION -> prepared.rotatedCenterY(); + case REQUESTED -> placement.requestedY(); + }; + } + + /** The floor of the cave the object is placed in, otherwise the surface at its center. */ + private static int centerSurface(IrisPlacement placement, PreparedPlacement prepared) { + if (placement.cave() != null) { + return placement.cave().getSurface() + prepared.rotatedCenterY(); + } + return surface(placement, prepared, placement.x(), placement.z()); + } + + private static int surface(IrisPlacement placement, PreparedPlacement prepared, int x, int z) { + return prepared.terrain().getHighest(x, z, placement.object().getLoader(), prepared.config().isUnderwater()) + + prepared.rotatedCenterY(); + } + + private static int checked(PlacementStageContext context, PreparedPlacement prepared, int x, int y, int z) { + if (!prepared.config().isForcePlace() && rejectsCarvingAnchor(prepared, x, y, z)) { + context.reject(CARVING_ANCHOR); + } + return y; + } + + /** The highest or lowest surface under the object's columns, or under its four corners only. */ + private static int extremeSurface(PlacementStageContext context, IrisPlacement placement, PreparedPlacement prepared, + boolean highest, boolean cornersOnly) { + TransformedBounds bounds = prepared.bounds(); + int minX = placement.x() + bounds.minX(); + int maxX = placement.x() + bounds.maxX(); + int minZ = placement.z() + bounds.minZ(); + int maxZ = placement.z() + bounds.maxZ(); + int xStep = cornersOnly ? Math.max(0, (maxX - minX) / 2) + 1 : 1; + int zStep = cornersOnly ? Math.max(0, (maxZ - minZ) / 2) + 1 : 1; + int y = highest ? -1 : Integer.MAX_VALUE; + for (int x = minX; x <= maxX; x += xStep) { + for (int z = minZ; z <= maxZ; z += zStep) { + int column = surface(placement, prepared, x, z); + if (!prepared.config().isForcePlace() && rejectsCarvingAnchor(prepared, x, column, z)) { + context.reject(CARVING_ANCHOR); + return y; + } + y = highest ? Math.max(y, column) : Math.min(y, column); + } + } + return y; + } + + /** Whether the placement's carving support forbids anchoring at this block. */ + private static boolean rejectsCarvingAnchor(PreparedPlacement prepared, int x, int y, int z) { + IObjectPlacer terrain = prepared.terrain(); + return switch (prepared.config().getCarvingSupport()) { + case SURFACE_ONLY -> terrain.isCarved(x, y, z); + case CARVING_ONLY -> !carvedWithin(terrain, x, y, z); + case ANYWHERE -> false; + }; + } + + private static boolean carvedWithin(IObjectPlacer terrain, int x, int y, int z) { + for (int depth = 0; depth < CARVING_CLEARANCE_BLOCKS; depth++) { + if (terrain.isCarved(x, y - depth, z)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/AnchorSampling.java b/src/main/java/art/arcane/iris/engine/object/placement/AnchorSampling.java new file mode 100644 index 000000000..5f7b7d572 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/AnchorSampling.java @@ -0,0 +1,39 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +/** How a placement mode finds the height of an object placed without a requested height. */ +enum AnchorSampling { + /** The surface at the object's center, or the floor of the cave it is placed in. */ + CENTER, + /** The highest surface under any column of the object. */ + HIGHEST, + /** The highest surface under the object's four corners. */ + HIGHEST_CORNER, + /** The lowest surface under any column of the object. */ + LOWEST, + /** The lowest surface under the object's four corners. */ + LOWEST_CORNER, + /** The surface at the object's center, ignoring caves; each block then follows its own column. */ + SURFACE, + /** The translation alone, in open air. */ + TRANSLATION, + /** The requested height, even when negative. */ + REQUESTED +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java b/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java new file mode 100644 index 000000000..2a87834b2 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java @@ -0,0 +1,247 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.anchor.AnchorStages; +import art.arcane.iris.builtin.blocks.BlocksStages; +import art.arcane.iris.builtin.blocks.ObjectMarkers; +import art.arcane.iris.builtin.blocks.WrittenBlocks; +import art.arcane.iris.builtin.bore.BoreStages; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.core.modules.BlockEntities; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.object.marker.IrisMarker; +import art.arcane.iris.engine.object.marker.IrisObjectMarker; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.engine.object.prefab.IrisObjectShaping; +import art.arcane.iris.engine.object.prefab.TileData; +import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; +import art.arcane.iris.engine.object.terrain.carving.CarvingMode; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.object.ObjectBlock; +import com.volmit.placement.PlacedBlock; +import com.volmit.stage.BlockStageContext; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; +import com.volmit.world.BlockPosition; + +import java.util.Set; + +/** + * Module {@code iris:blocks}: writes the object's blocks where the placement puts them, then its markers. + * Each block is turned with the object, edited, warped, painted onto its column when the mode paints, + * waterlogged in water and attached to the faces vines can hang from. Air is not written, except by + * structure pieces, and neither is a vine into a solid block or a melded block into open space. + */ +public final class BlocksModule implements IrisModule { + private static final Set AIR_MATERIALS = Set.of("minecraft:air", "minecraft:cave_air"); + private static final String DISTANCE = "distance"; + private static final String PERSISTENT = "persistent"; + private static final String WATERLOGGED = "waterlogged"; + private static final String TRUE = "true"; + private static final String FALSE = "false"; + private static final int MARKER_HEADROOM_BLOCKS = 2; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:blocks", "Object blocks", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(BlocksStages.WRITE) + .requires(PrepareStages.TRANSFORMS, AnchorStages.FINAL, BoreStages.CLEAR) + .accumulate(WrittenBlocks::new, BlocksModule::write); + graph.define(BlocksStages.MARKERS) + .requires(BlocksStages.WRITE, PrepareStages.TRANSFORMS) + .run(BlocksModule::placeMarkers); + graph.define(BlocksStages.COMPLETE) + .requires(BlocksStages.WRITE, BlocksStages.MARKERS) + .run(context -> { + }); + } + + private static void write(BlockStageContext context, WrittenBlocks written) { + IrisPlacement placement = IrisPlacement.current(); + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + PlacementWorld world = new PlacementWorld(context.access(), placement.states()); + ObjectBlock block = context.block(); + BlockPosition offset = prepared.transform(block.position()); + int anchorY = context.output(AnchorStages.FINAL).y(); + PlatformBlockState data = sourceState(block, placement, prepared); + TileData tile = block.blockEntity().map(BlockEntities::tileOf).orElse(null); + if (!config.getEdit().isEmpty()) { + ObjectEdits.Edited edited = ObjectEdits.apply(config, data, tile, new RNG(context.random().nextLong()), + offset.x() + placement.x(), offset.y() + anchorY, offset.z() + placement.z(), placement.data()); + data = edited.data(); + tile = edited.tile(); + } + data = prepared.rotate(data); + int x = placement.x() + offset.x(); + int y = anchorY + offset.y(); + int z = placement.z() + offset.z(); + if (prepared.isWarped()) { + x += prepared.warpOffset(offset.x() + placement.x(), y, offset.z() + placement.z()); + z += prepared.warpOffset(offset.z() + placement.z(), y, offset.x() + placement.x()); + } + if (WorldVolume.isPainted(placement, prepared) && !B.isVineBlock(data)) { + y = offset.y() + Math.floorDiv(placement.object().h, 2) + + prepared.terrain().getHighest(x, z, placement.object().getLoader(), config.isUnderwater()); + } + boolean structurePiece = prepared.mode() == ObjectPlaceMode.STRUCTURE_PIECE; + if (config.isMeld() && !structurePiece && !world.isSolid(x, y, z)) { + return; + } + if (IrisProceduralBlocks.hasProperty(data, WATERLOGGED) && shouldWaterlog(world, config, placement.requestedY(), x, y, z)) { + data = data.withProperty(WATERLOGGED, TRUE); + } + if (B.isVineBlock(data)) { + data = attachVineFaces(world, data, x, y, z); + } + if (!shouldWrite(world, data, x, y, z, structurePiece)) { + return; + } + PlacedBlock placed = world.set(x, y, z, data, tile); + placement.objectBlockWritten(placed.position()); + written.add(placed); + } + + /** The object block as Iris places it: debug air shows where smart boring bored, and leaves never decay where the placer prevents it. */ + private static PlatformBlockState sourceState(ObjectBlock block, IrisPlacement placement, PreparedPlacement prepared) { + PlatformBlockState data = placement.states().toPlatform(block.state()); + IObjectPlacer terrain = prepared.terrain(); + if (terrain.isDebugSmartBore() && data.matches(IrisObject.States.VAIR)) { + data = IrisObject.States.VAIR_DEBUG; + } + if (terrain.isPreventingDecay() && IrisProceduralBlocks.hasProperty(data, DISTANCE) + && FALSE.equals(IrisProceduralBlocks.propertyValue(data, PERSISTENT))) { + data = data.withProperty(PERSISTENT, TRUE); + } + return data; + } + + private static boolean shouldWrite(PlacementWorld world, PlatformBlockState data, int x, int y, int z, boolean structurePiece) { + if (data.isCustom()) { + return true; + } + boolean vineIntoSolid = B.isVineBlock(data) && world.isSolid(x, y, z); + return shouldPlaceObjectBlock(structurePiece, AIR_MATERIALS.contains(IrisObjectShaping.materialKey(data)), vineIntoSolid); + } + + /** Air is written only by structure pieces, and a vine never replaces a solid block. */ + static boolean shouldPlaceObjectBlock(boolean structurePiece, boolean air, boolean vineIntoSolid) { + return !vineIntoSolid && (structurePiece || !air); + } + + /** Whether a waterloggable block lands in water a waterloggable or underwater placement keeps. */ + static boolean shouldWaterlog(PlacementWorld world, IrisObjectPlacement config, int requestedY, int x, int y, int z) { + if (!(config.isWaterloggable() || config.isUnderwater())) { + return false; + } + if (requestedY >= 0 && config.getCarvingSupport() == CarvingMode.CARVING_ONLY) { + return false; + } + PlatformBlockState existing = world.get(x, y, z); + return B.isWater(existing) || B.isWaterLogged(existing); + } + + /** {@code vine} hanging from each neighboring solid block it has a face property for. */ + static PlatformBlockState attachVineFaces(PlacementWorld world, PlatformBlockState vine, int x, int y, int z) { + PlatformBlockState attached = vine; + for (String face : IrisProceduralBlocks.FACE_PROPERTIES) { + if (!IrisProceduralBlocks.hasProperty(vine, face)) { + continue; + } + int[] offset = IrisProceduralBlocks.faceOffset(face); + PlatformBlockState facing = world.get(x + offset[0], y + offset[1], z + offset[2]); + if (B.isSolid(facing) && !B.isVineBlock(facing)) { + attached = attached.withProperty(face, TRUE); + } + } + return attached; + } + + /** + * Each marker of the placement marks up to its maximum of the written blocks it targets, picked at random, + * where the marker either allows anything above or finds two blocks of air. + */ + private static void placeMarkers(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + if (config.getMarkers().isEmpty() || prepared.terrain().getEngine() == null) { + return; + } + WrittenBlocks written = context.output(BlocksStages.WRITE); + PlacementWorld world = new PlacementWorld(context.access(), placement.states()); + RNG markerRandom = new RNG(context.random().nextLong()); + int salt = 0; + for (IrisObjectMarker markerConfig : config.getMarkers()) { + IrisMarker marker = placement.object().getLoader().getMarkerLoader().load(markerConfig.getMarker()); + int markerSalt = salt++; + if (marker == null) { + continue; + } + KList candidates = candidates(written, markerConfig, markerConfig.getMark(placement.data()), placement); + int remaining = markerConfig.getMaximumMarkers(); + for (BlockPosition position : candidates.shuffleCopy(markerRandom.nextParallelRNG(markerSalt))) { + if (remaining <= 0) { + break; + } + if (!marker.isEmptyAbove() || hasAirAbove(world, position)) { + context.access().marker(ObjectMarkers.of(position, markerConfig.getMarker())); + remaining--; + } + } + } + } + + private static KList candidates(WrittenBlocks written, IrisObjectMarker markerConfig, + KList targets, IrisPlacement placement) { + KList candidates = new KList<>(); + for (PlacedBlock block : written.blocks()) { + PlatformBlockState state = placement.states().toPlatform(block.state()); + if (targets.stream().anyMatch(target -> marks(markerConfig, target, state))) { + candidates.add(block.position()); + } + } + return candidates; + } + + private static boolean marks(IrisObjectMarker markerConfig, PlatformBlockState target, PlatformBlockState state) { + return markerConfig.isExact() + ? target.matches(state) + : IrisObjectShaping.materialKey(target).equals(IrisObjectShaping.materialKey(state)); + } + + private static boolean hasAirAbove(PlacementWorld world, BlockPosition position) { + for (int above = 1; above <= MARKER_HEADROOM_BLOCKS; above++) { + if (!B.isAir(world.get(position.x(), position.y() + above, position.z()))) { + return false; + } + } + return true; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/BoreModule.java b/src/main/java/art/arcane/iris/engine/object/placement/BoreModule.java new file mode 100644 index 000000000..cb8d8dbab --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/BoreModule.java @@ -0,0 +1,63 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.anchor.AnchorStages; +import art.arcane.iris.builtin.bore.BoreStages; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.builtin.validate.ValidateStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.object.prefab.IrisObject; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; + +/** Module {@code iris:bore}: fills the object's volume with air, extended up and down as configured. */ +public final class BoreModule implements IrisModule { + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:bore", "Bore", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(BoreStages.CLEAR) + .requires(AnchorStages.FINAL, ValidateStages.COLLISIONS) + .run(BoreModule::clear); + } + + private static void clear(PlacementStageContext context) { + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + if (!config.isBore()) { + return; + } + IrisPlacement placement = IrisPlacement.current(); + WorldVolume volume = WorldVolume.of(placement, prepared, context.output(AnchorStages.FINAL).y()); + PlacementWorld world = new PlacementWorld(context.access(), placement.states()); + for (int x = volume.minX(); x <= volume.maxX(); x++) { + for (int y = volume.minY() - config.getBoreExtendMinY(); y <= volume.maxY() + config.getBoreExtendMaxY(); y++) { + for (int z = volume.minZ(); z <= volume.maxZ(); z++) { + world.set(x, y, z, IrisObject.States.AIR); + } + } + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java index 3845ec97b..23b508538 100644 --- a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java +++ b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java @@ -18,6 +18,7 @@ package art.arcane.iris.engine.object.placement; +import art.arcane.iris.core.modules.ModuleSettings; import art.arcane.iris.engine.object.loot.IObjectLoot; import art.arcane.iris.engine.object.loot.IrisLootTable; import art.arcane.iris.engine.object.loot.IrisObjectLoot; @@ -197,6 +198,8 @@ public class IrisObjectPlacement { @SerializedName(value = "forcePlace", alternate = {"force"}) private boolean forcePlace = false; private transient AtomicCache cache = new AtomicCache<>(); + /** The pack modules' settings this placement declares, decoded with it. */ + private transient ModuleSettings moduleSettings = ModuleSettings.NONE; public IrisObjectPlacement toPlacement(String... place) { IrisObjectPlacement p = new IrisObjectPlacement(); @@ -241,6 +244,7 @@ public class IrisObjectPlacement { p.setAllowedCollisions(allowedCollisions); p.setForbiddenCollisions(forbiddenCollisions); p.setForcePlace(forcePlace); + p.setModuleSettings(moduleSettings); return p; } diff --git a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacementRunner.java b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacementRunner.java deleted file mode 100644 index c9dae93a5..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacementRunner.java +++ /dev/null @@ -1,43 +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 . - */ - -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.terrain.carving.CarveResult; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.volmlib.util.math.BlockPosition; -import art.arcane.volmlib.util.math.RNG; - -import java.util.function.BiConsumer; - -/** Entry point for executing an engine's resolved placement plan. */ -public final class IrisObjectPlacementRunner { - private final IrisObject self; - - public IrisObjectPlacementRunner(IrisObject self) { - this.self = self; - } - - public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, - BiConsumer listener, CarveResult cave, IrisData data) { - PlacementContext context = new PlacementContext(config, data, placer, cave, rng, self, x, z, yv, listener); - return PlacementLifecycles.forPlacer(placer).get(config.getMode()).execute(context).heightOrRejected(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectVacuum.java b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectVacuum.java index 57a0fb223..82d5cc89d 100644 --- a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectVacuum.java +++ b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectVacuum.java @@ -21,6 +21,8 @@ package art.arcane.iris.engine.object.placement; public final class IrisObjectVacuum { private static final double DEFAULT_WAVE_AMPLITUDE = 3.0; private static final double DEFAULT_WAVE_SCALE = 5.0; + /** The widest bend, as the settings allow it; placements prepare this much around every object. */ + public static final int MAX_RADIUS_BLOCKS = 128; private IrisObjectVacuum() { } @@ -42,7 +44,7 @@ public final class IrisObjectVacuum { if (settings != null && settings.getRadius() > 0) { radius = settings.getRadius(); } - return Math.max(0, radius); + return Math.max(0, Math.min(MAX_RADIUS_BLOCKS, radius)); } public static int resolveStep(ObjectPlaceMode mode) { diff --git a/src/main/java/art/arcane/iris/engine/object/placement/ObjectBlockPass.java b/src/main/java/art/arcane/iris/engine/object/placement/ObjectBlockPass.java deleted file mode 100644 index 0bca2e368..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/ObjectBlockPass.java +++ /dev/null @@ -1,259 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.marker.ObjectMarkerPlacement; -import art.arcane.iris.engine.object.material.BlockDataMergeSupport; -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.prefab.IrisObjectShaping; -import art.arcane.iris.engine.object.prefab.IrisObjectTranslate; -import art.arcane.iris.engine.object.prefab.TileData; -import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; -import art.arcane.iris.engine.object.terrain.carving.CarvingMode; -import art.arcane.iris.core.nms.container.Pair; -import art.arcane.iris.spi.IrisLogging; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.iris.util.common.data.VectorMap; -import art.arcane.iris.util.common.math.IrisBlockVector; -import art.arcane.iris.util.project.noise.CNG; -import art.arcane.volmlib.util.math.BlockPosition; - -import java.util.List; -import java.util.Optional; -import java.util.function.BiConsumer; - -final class ObjectBlockPass { - - private List matchingMarkers; - private final BiConsumer listener; - - private final PlacementContext context; - private final PlacementState state; - private final VectorMap blocks; - private final VectorMap states; - private final ObjectMarkerPlacement markerPlacer; - private final PlacementLifecycle lifecycle; - - ObjectBlockPass( - PlacementContext context, - PlacementState state, - PlacementLifecycle lifecycle, - BiConsumer listener - ) { - this.context = context; - this.state = state; - this.lifecycle = lifecycle; - this.listener = listener; - this.blocks = context.self.blocks; - this.states = context.self.states; - - if (state.config.getMarkers().isNotEmpty() && state.placer.getEngine() != null) { - markerPlacer = new ObjectMarkerPlacement(context, state); - markerPlacer.loadPossibleMarkers(); - } else { - markerPlacer = null; - } - } - - void process() { - VectorMap.Cursor cursor = blocks.cursor(); - IrisObjectTranslate translate = state.config.getTranslate(); - CNG surfaceWarp = !state.config.getWarp().isFlat() ? state.config.getSurfaceWarp(context.rng, context.self.getLoader()) : null; - boolean preventingDecay = state.placer.isPreventingDecay(); - boolean waterlogCandidate = state.config.isWaterloggable() || state.config.isUnderwater(); - boolean hasStates = !states.isEmpty(); - int xx, zz; - - double warpHalf = !state.config.getWarp().isFlat() ? state.config.getWarp().getMultiplier() / 2D : 0D; - - while (cursor.next()) { - var read = readStateFrom(cursor, hasStates); - - PlatformBlockState data = read.getA(); - TileData tile = read.getB(); - IrisBlockVector vector = cursor.key().clone(); - - state.spin.rotate(vector); - PlacementBlock block = new PlacementBlock(data, tile, vector); - lifecycle.run(PlacementStage.TRANSFORM_BLOCK, context, state, block); - if (state.isRejected()) { - return; - } - - if (translate.canTranslate()) { - vector.add(state.translateOffset); - } - - lifecycle.run(PlacementStage.COLLECT_BLOCK, context, state, block); - if (state.isRejected()) { - return; - } - if (preventingDecay && IrisProceduralBlocks.hasProperty(data, "distance") && "false".equals(IrisProceduralBlocks.propertyValue(data, "persistent"))) { - data = data.withProperty("persistent", "true"); - } - - if (!state.config.getEdit().isEmpty()) { - var result = applyEdits(vector, data, tile); - data = result.data(); - tile = result.tile(); - } - - matchingMarkers = markerPlacer != null ? markerPlacer.matchMarkers(data) : null; - - data = state.spin.rotate(data); - xx = context.x + (int) Math.round(vector.getX()); - int yy = state.y + (int) Math.round(vector.getY()); - zz = context.z + (int) Math.round(vector.getZ()); - - if (!state.config.getWarp().isFlat()) { - xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, vector.getX() + context.x, vector.getY() + state.y, vector.getZ() + context.z); - zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, vector.getZ() + context.z, vector.getY() + state.y, vector.getX() + context.x); - } - - if (context.yv < 0 && (is(ObjectPlaceMode.PAINT)) && !B.isVineBlock(data)) { - yy = (int) Math.round(vector.getY()) + Math.floorDiv(context.self.h, 2) + state.placer.getHighest(xx, zz, context.self.getLoader(), state.config.isUnderwater()); - } - - if (state.config.isMeld() && !is(ObjectPlaceMode.STRUCTURE_PIECE) && !state.placer.isSolid(xx, yy, zz)) { - continue; - } - - if (waterlogCandidate && IrisProceduralBlocks.hasProperty(data, "waterlogged") && shouldAutoWaterlogBlock(context, state, xx, yy, zz)) { - data = data.withProperty("waterlogged", "true"); - } - - if (B.isVineBlock(data)) { - data = attachVineFaces(state.placer, data, xx, yy, zz); - } - - if (handleCustomData(data, tile, xx, yy, zz)) { - lifecycle.run(PlacementStage.BLOCK_WRITTEN, context, state, new PlacementBlockWrite(xx, yy, zz, data)); - if (state.isRejected()) { - return; - } - } - } - - if (markerPlacer != null) { - markerPlacer.placeMarkers(); - } - - - } - - private boolean is(ObjectPlaceMode mode) { - return state.config.getMode() == mode; - } - - static boolean shouldPlaceObjectBlock(boolean rawStructurePiece, boolean air, boolean wouldReplace) { - return !wouldReplace && (rawStructurePiece || !air); - } - - private boolean handleCustomData(PlatformBlockState data, TileData tile, int xx, int yy, int zz) { - // Short-circuit order matters for cost only: the mantle read is paid solely - // for vine blocks. Both operands are pure, so the value is unchanged. - boolean wouldReplace = B.isVineBlock(data) && B.isSolid(state.placer.get(xx, yy, zz)); - String material = IrisObjectShaping.materialKey(data); - boolean air = material.equals("minecraft:air") || material.equals("minecraft:cave_air"); - boolean place = shouldPlaceObjectBlock(is(ObjectPlaceMode.STRUCTURE_PIECE), air, wouldReplace); - if (data.isCustom() || place) { - state.placer.set(xx, yy, zz, data); - if (tile != null) { - state.placer.setTile(xx, yy, zz, tile); - } - if (matchingMarkers != null) { - BlockPosition markerPosition = new BlockPosition(xx, yy, zz); - for (ObjectMarkerPlacement.MarkerPlacement markerPlacement : matchingMarkers) { - markerPlacement.candidates.add(markerPosition); - } - } - if (listener != null) { - listener.accept(new BlockPosition(xx, yy, zz), data); - } - return true; - } - return false; - } - - private EditResult applyEdits(IrisBlockVector vector, PlatformBlockState data, TileData tile) { - for (IrisObjectReplace j : state.config.getEdit()) { - if (context.rng.chance(j.getChance())) { - for (PlatformBlockState k : j.getFind(context.rdata)) { - if (j.isExact() ? k.matches(data) : IrisObjectShaping.materialKey(k).equals(IrisObjectShaping.materialKey(data))) { - PlatformBlockState newData = j.getReplace(context.rng, vector.getX() + context.x, vector.getY() + state.y, vector.getZ() + context.z, context.rdata); - - if (IrisObjectShaping.materialKey(newData).equals(IrisObjectShaping.materialKey(data)) && !(newData.isCustom() || data.isCustom())) - data = BlockDataMergeSupport.merge(data, newData); - else - data = newData; - - Optional t = j.getReplace().getTile(context.rng, context.x, state.y, context.z, context.rdata); - if (t.isPresent()) { - tile = t.get(); - } - } - } - } - } - return new EditResult(data, tile); - } - - static boolean shouldAutoWaterlogBlock(PlacementContext context, PlacementState state, int x, int y, int z) { - if (!(state.config.isWaterloggable() || state.config.isUnderwater())) { - return false; - } - - if (context.yv >= 0 && state.config.getCarvingSupport().equals(CarvingMode.CARVING_ONLY)) { - return false; - } - - PlatformBlockState existing = state.placer.get(x, y, z); - if (existing == null) { - return false; - } - - return B.isWater(existing) || B.isWaterLogged(existing); - } - - static PlatformBlockState attachVineFaces(IObjectPlacer placer, PlatformBlockState data, int x, int y, int z) { - PlatformBlockState result = data; - for (String face : IrisProceduralBlocks.FACE_PROPERTIES) { - if (!IrisProceduralBlocks.hasProperty(data, face)) { - continue; - } - int[] mod = IrisProceduralBlocks.faceOffset(face); - PlatformBlockState facing = placer.get(x + mod[0], y + mod[1], z + mod[2]); - if (B.isSolid(facing) && !B.isVineBlock(facing)) { - result = result.withProperty(face, "true"); - } - } - return result; - } - - - private Pair readStateFrom(VectorMap.Cursor cursor, boolean hasStates) { - PlatformBlockState block; - TileData tile = null; - IrisBlockVector vector = cursor.key(); - try { - block = cursor.value(); - if (hasStates) { - tile = states.get(vector); - } - } catch (Throwable e) { - IrisLogging.reportError(e); - IrisLogging.warn("Failed to read block node " + vector.getBlockX() + "," + vector.getBlockY() + "," + vector.getBlockZ() + " in object " + context.self.getLoadKey() + " (cme)"); - block = IrisObject.States.AIR; - } - - if (block == null) { - IrisLogging.warn("Failed to read block node " + vector.getBlockX() + "," + vector.getBlockY() + "," + vector.getBlockZ() + " in object " + context.self.getLoadKey() + " (null)"); - block = IrisObject.States.AIR; - } - if (state.placer.isDebugSmartBore() && IrisObject.States.VAIR.equals(block)) { - block = IrisObject.States.VAIR_DEBUG; - } - return new Pair<>(block, tile); - } - - private record EditResult(PlatformBlockState data, TileData tile) {} -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/ObjectEdits.java b/src/main/java/art/arcane/iris/engine/object/placement/ObjectEdits.java new file mode 100644 index 000000000..122ef4e7f --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/ObjectEdits.java @@ -0,0 +1,73 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.engine.object.material.BlockDataMergeSupport; +import art.arcane.iris.engine.object.prefab.IrisObjectShaping; +import art.arcane.iris.engine.object.prefab.TileData; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.volmlib.util.math.RNG; + +/** + * A placement's block replacements ({@code edit}): each replacement, by its chance, swaps the blocks it + * finds for its palette's block at the block's position, keeping the old block's properties when the + * material stays the same. + */ +final class ObjectEdits { + private ObjectEdits() { + } + + /** {@code tile} may be null; the result's tile is the last replacement's tile, if it has one. */ + static Edited apply(IrisObjectPlacement config, PlatformBlockState data, TileData tile, RNG rng, + double x, double y, double z, IrisData rdata) { + PlatformBlockState edited = data; + TileData editedTile = tile; + for (IrisObjectReplace replace : config.getEdit()) { + if (!rng.chance(replace.getChance())) { + continue; + } + for (PlatformBlockState find : replace.getFind(rdata)) { + if (!finds(replace, find, edited)) { + continue; + } + edited = replaced(edited, replace.getReplace(rng, x, y, z, rdata)); + editedTile = replace.getReplace().getTile(rng, x, y, z, rdata).orElse(editedTile); + } + } + return new Edited(edited, editedTile); + } + + private static boolean finds(IrisObjectReplace replace, PlatformBlockState find, PlatformBlockState data) { + return replace.isExact() + ? find.matches(data) + : IrisObjectShaping.materialKey(find).equals(IrisObjectShaping.materialKey(data)); + } + + private static PlatformBlockState replaced(PlatformBlockState data, PlatformBlockState replacement) { + boolean sameMaterial = IrisObjectShaping.materialKey(replacement).equals(IrisObjectShaping.materialKey(data)); + if (sameMaterial && !replacement.isCustom() && !data.isCustom()) { + return BlockDataMergeSupport.merge(data, replacement); + } + return replacement; + } + + record Edited(PlatformBlockState data, TileData tile) { + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/ObjectModuleCeilingHang.java b/src/main/java/art/arcane/iris/engine/object/placement/ObjectModuleCeilingHang.java deleted file mode 100644 index 4260e704c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/ObjectModuleCeilingHang.java +++ /dev/null @@ -1,11 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -public final class ObjectModuleCeilingHang implements PlacementModule { - static final PlacementLifecycleDependency FLIP = new PlacementLifecycleDependency("ceiling.flip"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(FLIP, PlacementStage.TRANSFORM_BLOCK, - (context, state, block) -> block.vector().setY(-block.vector().getBlockY())); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/ObjectPlaceMode.java b/src/main/java/art/arcane/iris/engine/object/placement/ObjectPlaceMode.java index 7e7392c70..af6f6a335 100644 --- a/src/main/java/art/arcane/iris/engine/object/placement/ObjectPlaceMode.java +++ b/src/main/java/art/arcane/iris/engine/object/placement/ObjectPlaceMode.java @@ -20,130 +20,111 @@ package art.arcane.iris.engine.object.placement; import art.arcane.iris.engine.object.annotations.Desc; -import java.util.function.Supplier; @Desc("Object Place modes are useful for positioning objects just right. The default value is CENTER_HEIGHT.") public enum ObjectPlaceMode { @Desc("The default place mode. This mode picks a center point (where the center of the object will be) and takes the height. That height is used for the whole object.") - CENTER_HEIGHT(PlacementModuleCenterHeight::new), + CENTER_HEIGHT(AnchorSampling.CENTER, StiltShape.NONE), @Desc("Samples a lot of points where the object will cover (horizontally) and picks the highest height, that height is then used to place the object. This mode is useful for preventing any part of your object from being buried though it will float off of cliffs.") - MAX_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MAX, false)), + MAX_HEIGHT(AnchorSampling.HIGHEST, StiltShape.NONE), @Desc("Samples only 4 points where the object will cover (horizontally) and picks the highest height, that height is then used to place the object. This mode is useful for preventing any part of your object from being buried though it will float off of cliffs.\"") - FAST_MAX_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MAX, true)), + FAST_MAX_HEIGHT(AnchorSampling.HIGHEST_CORNER, StiltShape.NONE), @Desc("Samples a lot of points where the object will cover (horizontally) and picks the lowest height, that height is then used to place the object. This mode is useful for preventing any part of your object from overhanging a cliff though it gets buried a lot") - MIN_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MIN, false)), + MIN_HEIGHT(AnchorSampling.LOWEST, StiltShape.NONE), @Desc("Samples only 4 points where the object will cover (horizontally) and picks the lowest height, that height is then used to place the object. This mode is useful for preventing any part of your object from overhanging a cliff though it gets buried a lot") - FAST_MIN_HEIGHT(() -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MIN, true)), + FAST_MIN_HEIGHT(AnchorSampling.LOWEST_CORNER, StiltShape.NONE), @Desc("Stilting is MAX_HEIGHT but it repeats the bottom most block of your object until it hits the surface. This is expensive because it has to first sample every height value for each x,z position of your object. Avoid using this unless its structures for performance reasons.") - STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.DEFAULT, false)), + STILT(AnchorSampling.HIGHEST, StiltShape.STRAIGHT), @Desc("Just like stilting but very inaccurate. Useful for stilting a lot of objects without too much care on accuracy (you can use the over-stilt value to force stilts under ground further)") - FAST_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.DEFAULT, true)), + FAST_STILT(AnchorSampling.HIGHEST_CORNER, StiltShape.STRAIGHT), @Desc("Stilting is MIN_HEIGHT but it repeats the bottom most block of your object until it hits the surface. This is expensive because it has to first sample every height value for each x,z position of your object. Avoid using this unless its structures for performance reasons.") - MIN_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.MIN, false)), + MIN_STILT(AnchorSampling.LOWEST, StiltShape.STRAIGHT), @Desc("Just like MIN_STILT but very inaccurate. Useful for stilting a lot of objects without too much care on accuracy (you can use the over-stilt value to force stilts under ground further)") - FAST_MIN_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.MIN, true)), + FAST_MIN_STILT(AnchorSampling.LOWEST_CORNER, StiltShape.STRAIGHT), @Desc("Stilting is CENTER_HEIGHT but it repeats the bottom most block of your object until it hits the surface. This is expensive because it has to first sample every height value for each x,z position of your object. Avoid using this unless its structures for performance reasons.") - CENTER_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.CENTER, false)), + CENTER_STILT(AnchorSampling.CENTER, StiltShape.STRAIGHT), @Desc("Erode stilting tapers columns downward like an ice cream cone. Blocks near the center extend deepest while edge blocks drop off first. Blocks are randomly skipped in the lower portion for a rough organic eroded texture.") - ERODE_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.ERODE, false)), + ERODE_STILT(AnchorSampling.HIGHEST, StiltShape.ERODE), @Desc("Organic stilting scans straight down from the bottom of the object to the first solid block (the cave floor, or terrain) and fills the gap with the object's own bottom block. Each column stops at a slightly different, noise-varied depth and the lower portion is randomly broken up, so the underside reads as rough organic roots rather than a flat disc. Designed for objects placed inside caves so they connect to the floor instead of floating. Tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).") - ORGANIC_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.ORGANIC, false)), + ORGANIC_STILT(AnchorSampling.CENTER, StiltShape.ORGANIC), @Desc("Hangs the object upside-down from a cave ceiling. The object is flipped vertically (its tip points down like a stalactite) and its top is anchored to the ceiling, while an organic, noise-varied stilt grows up into the ceiling so it never floats below the roof. Use inside caves; tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).") - CEILING_HANG(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.CEILING, false)), + CEILING_HANG(AnchorSampling.CENTER, StiltShape.CEILING), @Desc("Anchors the object at the terrain surface (plus translate.y) like CENTER_HEIGHT, then bends the surrounding terrain to be flush with the object's base. Columns inside the object footprint are raised (or lowered) to meet the base, and the deformation falls off parabolically out to a radius so the terrain smoothly blends back to its natural height. Use this to seat a floating/translated object on the ground without a flat stilt disc, e.g. a cube translated up 10 on a mountain pulls the terrain up to meet it. Tune with vacuum-settings (radius, falloff).") - VACUUM(PlacementModuleCenterHeight::new), + VACUUM(AnchorSampling.CENTER, StiltShape.NONE), @Desc("VACUUM with a larger radius and finer per-column sampling for the smoothest terrain blend. More expensive.") - VACUUM_HIGH(PlacementModuleCenterHeight::new), + VACUUM_HIGH(AnchorSampling.CENTER, StiltShape.NONE), @Desc("VACUUM with a smaller radius and coarser sampling for performance. Use when seating many objects.") - VACUUM_FAST(PlacementModuleCenterHeight::new), + VACUUM_FAST(AnchorSampling.CENTER, StiltShape.NONE), @Desc("VACUUM whose falloff radius is perturbed by noise per column, so the terrain meets the object with an irregular organic edge rather than a clean parabolic bowl.") - VACUUM_ORGANIC(PlacementModuleCenterHeight::new), + VACUUM_ORGANIC(AnchorSampling.CENTER, StiltShape.NONE), @Desc("VACUUM whose terrain bend is bent by smooth coherent simplex noise so the surface meets the object with a gently rolling, wavy slope instead of the ragged white-noise edge of VACUUM_ORGANIC or a clean parabolic bowl. The object itself still seats flush; the waves fade to zero under the object and at the outer rim, peaking across the mid-slope. Tune with vacuum-settings (waveAmplitude, waveScale).") - VACUUM_WAVY(PlacementModuleCenterHeight::new), + VACUUM_WAVY(AnchorSampling.CENTER, StiltShape.NONE), @Desc("Samples the height of the terrain at every x,z position of your object and pushes it down to the surface. It's pretty much like a melt function over the terrain.") - PAINT(PlacementModulePaint::new), + PAINT(AnchorSampling.SURFACE, StiltShape.NONE), @Desc("Places the object in pure air at an absolute Y driven entirely by translate.y (plus optional translate.yRandom). Terrain height, underwater, and carving anchor checks are skipped. Use this for floating islands, sky structures, clouds, or blimps where the object must not be translated to the ground.") - FLOATING(PlacementModuleFloating::new), + FLOATING(AnchorSampling.TRANSLATION, StiltShape.NONE), @Desc("Raw stamp at the caller-supplied (x, y, z). No terrain sampling, no stilting, no Y recomputation, no underwater or carving anchor guards. Used internally to route native Minecraft structure pieces (villages etc.) through the Iris object placer.") - STRUCTURE_PIECE(() -> lifecycle -> PlacementModuleAnchor.install(lifecycle, - (context, state, ignored) -> state.y = context.yv)); + STRUCTURE_PIECE(AnchorSampling.REQUESTED, StiltShape.NONE); + private final AnchorSampling anchor; + private final StiltShape stilt; - private final Supplier factory; - - ObjectPlaceMode(Supplier factory) { - this.factory = factory; + ObjectPlaceMode(AnchorSampling anchor, StiltShape stilt) { + this.anchor = anchor; + this.stilt = stilt; } - PlacementLifecycle createLifecycle() { - PlacementLifecycleBuilder lifecycle = new PlacementLifecycleBuilder(); - install(lifecycle); - return lifecycle.build(); + /** How a placement without a requested height finds one. */ + AnchorSampling anchor() { + return anchor; } - void install(PlacementLifecycleBuilder lifecycle) { - new PlacementModulePreparation().install(lifecycle); - new PlacementModuleSlope().install(lifecycle); - factory.get().install(lifecycle); - new PlacementModuleAnchor().install(lifecycle); - new PlacementModuleSurfaceSupport().install(lifecycle); - new PlacementModuleLimits().install(lifecycle); - new PlacementModuleNativeStructureProtection().install(lifecycle); - new PlacementModuleBounds().install(lifecycle); - new PlacementModuleCollision().install(lifecycle); - new PlacementModuleBore().install(lifecycle); - new PlacementModuleBlocks().install(lifecycle); - PlacementLifecycleDependency finish = switch (this) { - case STILT, FAST_STILT, MIN_STILT, FAST_MIN_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT, CEILING_HANG -> - PlacementModuleStilt.FILL; - case VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC, VACUUM_WAVY -> { - new PlacementModuleVacuum().install(lifecycle); - yield PlacementModuleVacuum.FINISH; - } - default -> PlacementModuleBlocks.COMPLETE; - }; - new PlacementModuleSnow(finish).install(lifecycle); + /** The stilt this mode grows under or above the object. */ + StiltShape stilt() { + return stilt; } - + boolean isVacuum() { + return IrisObjectVacuum.isVacuumMode(this); + } } diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementBlock.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementBlock.java deleted file mode 100644 index 0107574e8..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementBlock.java +++ /dev/null @@ -1,9 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.TileData; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.math.IrisBlockVector; - -/** Source data and a placement-owned vector; changing the vector does not change the cached object. */ -public record PlacementBlock(PlatformBlockState data, TileData tile, IrisBlockVector vector) { -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementBlockWrite.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementBlockWrite.java deleted file mode 100644 index 38a03f78c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementBlockWrite.java +++ /dev/null @@ -1,6 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.spi.PlatformBlockState; - -/** A completed object write, after its tile data and listener have been handled. */ -public record PlacementBlockWrite(int x, int y, int z, PlatformBlockState data) {} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementContext.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementContext.java deleted file mode 100644 index a3f30eccc..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementContext.java +++ /dev/null @@ -1,45 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.terrain.carving.CarveResult; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.volmlib.util.math.BlockPosition; -import art.arcane.volmlib.util.math.RNG; -import lombok.Getter; - -import java.util.Objects; -import java.util.function.BiConsumer; - -/** Caller inputs for one placement. Modules keep derived values in PlacementState. */ -@Getter -public final class PlacementContext { - public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {} - public record WorldBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {} - - final IrisObjectPlacement config; - final IrisData rdata; - final IObjectPlacer placer; - final CarveResult caveResult; - final RNG rng; - final IrisObject self; - final int x; - final int z; - final int yv; - final BiConsumer listener; - - public PlacementContext(IrisObjectPlacement config, IrisData rdata, IObjectPlacer placer, - CarveResult caveResult, RNG rng, IrisObject self, int x, int z, int yv, - BiConsumer listener) { - this.placer = Objects.requireNonNull(placer, "Object placer is required."); - this.config = Objects.requireNonNull(config, "Object placement config is required."); - this.rng = Objects.requireNonNull(rng, "Object placement RNG is required."); - this.rdata = Objects.requireNonNull(rdata, "Object placement data is required."); - this.self = Objects.requireNonNull(self, "Object is required."); - this.caveResult = caveResult; - this.x = x; - this.z = z; - this.yv = yv; - this.listener = listener; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementFunction.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementFunction.java deleted file mode 100644 index 15326a3cc..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementFunction.java +++ /dev/null @@ -1,6 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -@FunctionalInterface -public interface PlacementFunction { - void execute(PlacementContext context, PlacementState state, C input); -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycle.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycle.java deleted file mode 100644 index 378b59ee7..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycle.java +++ /dev/null @@ -1,35 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import java.util.List; - -/** Immutable plan. Placement performs no registration, graph traversal, or sorting. */ -public final class PlacementLifecycle { - private final List>> stages; - - PlacementLifecycle(List> ordered) { - stages = PlacementStage.ALL.stream() - .map(stage -> ordered.stream().filter(step -> step.stage() == stage).toList()).toList(); - } - - public PlacementState execute(PlacementContext context) { - PlacementState state = new PlacementState(context); - for (PlacementStage stage : PlacementStage.BEFORE_PASS) { - run(stage, context, state, null); - } - run(PlacementStage.BLOCKS, context, state, this); - run(PlacementStage.AFTER_BLOCKS, context, state, null); - return state; - } - - public void run(PlacementStage stage, PlacementContext context, PlacementState state, C input) { - for (PlacementLifecycleBuilder.Step step : stages.get(stage.order)) { - if (state.isRejected()) { - return; - } - // Registration pairs each function with its typed stage. - @SuppressWarnings("unchecked") - PlacementFunction function = (PlacementFunction) step.function(); - function.execute(context, state, input); - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycleBuilder.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycleBuilder.java deleted file mode 100644 index 9454cfe8c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycleBuilder.java +++ /dev/null @@ -1,84 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.PriorityQueue; - -/** - * Registers steps and resolves their graph before an engine runtime is published. - * A dependency names a required step, not a Java class: two instances of the same module can - * register distinct work. Declaring a dependency does not install its prerequisite. - * The module composition must register it, in any order, before calling {@link #build()}. - * - *

{@code
- * lifecycle.add(FILL, PlacementStage.AFTER_BLOCKS, this::fill, HEIGHT, BOUNDS);
- * }
- * - * Independent steps retain registration order within their stage. Invalid graphs fail construction; - * the builder never executes functions. Functions must not capture mutable placement state. - */ -public final class PlacementLifecycleBuilder { - private final Map> steps = new LinkedHashMap<>(); - - public void add(PlacementLifecycleDependency id, PlacementStage stage, - PlacementFunction function, PlacementLifecycleDependency... after) { - Objects.requireNonNull(id, "Step id"); - Objects.requireNonNull(stage, "Stage"); - Objects.requireNonNull(function, "Function"); - Step step = new Step<>(id, stage, function, List.of(after), steps.size()); - if (steps.putIfAbsent(id, step) != null) { - throw new IllegalArgumentException("Duplicate placement step '" + id.name() + "'"); - } - } - - /** Stable topological sort; stage barriers do not need all-to-all edges. */ - public PlacementLifecycle build() { - Map remaining = new HashMap<>(); - Map>> dependents = new HashMap<>(); - PriorityQueue> ready = new PriorityQueue<>(Comparator.>comparingInt(step -> step.stage.order).thenComparingInt(Step::index)); - for (Step step : steps.values()) { - var prerequisites = step.after.stream().distinct().toList(); - remaining.put(step.id, prerequisites.size()); - for (PlacementLifecycleDependency id : prerequisites) { - Step prerequisite = steps.get(id); - if (prerequisite == null) { - throw new IllegalArgumentException("Placement step '" + step.id.name() - + "' requires missing step '" + id.name() + "'"); - } - if (prerequisite.stage.order > step.stage.order) { - throw new IllegalArgumentException("Placement step '" + step.id.name() + "' in " + step.stage - + " cannot depend on later step '" + id.name() + "' in " + prerequisite.stage); - } - dependents.computeIfAbsent(id, ignored -> new ArrayList<>()).add(step); - } - if (prerequisites.isEmpty()) { - ready.add(step); - } - } - List> ordered = new ArrayList<>(steps.size()); - while (!ready.isEmpty()) { - Step step = ready.remove(); - ordered.add(step); - for (Step dependent : dependents.getOrDefault(step.id, List.of())) { - if (remaining.compute(dependent.id, (ignored, count) -> count - 1) == 0) { - ready.add(dependent); - } - } - } - if (ordered.size() != steps.size()) { - throw new IllegalArgumentException("Placement dependency cycle; unresolved steps: " - + steps.keySet().stream().filter(id -> remaining.get(id) > 0) - .map(PlacementLifecycleDependency::name).toList()); - } - return new PlacementLifecycle(ordered); - } - - record Step(PlacementLifecycleDependency id, PlacementStage stage, PlacementFunction function, - List after, int index) { - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycleDependency.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycleDependency.java deleted file mode 100644 index 399e7c0de..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycleDependency.java +++ /dev/null @@ -1,13 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import java.util.Objects; - -/** A named prerequisite, scoped to one placement plan. */ -public record PlacementLifecycleDependency(String name) { - public PlacementLifecycleDependency { - Objects.requireNonNull(name, "Dependency name"); - if (name.isBlank()) { - throw new IllegalArgumentException("Placement dependency name cannot be blank"); - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycles.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycles.java deleted file mode 100644 index d59d5eae8..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementLifecycles.java +++ /dev/null @@ -1,43 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import java.util.EnumMap; -import java.util.Map; - -/** One resolved plan per mode in an engine runtime. Engine-less tools share a separate default set. */ -public final class PlacementLifecycles { - private final Map plans; - - private PlacementLifecycles(Map plans) { - this.plans = Map.copyOf(plans); - } - - public static PlacementLifecycles resolve() { - Map plans = new EnumMap<>(ObjectPlaceMode.class); - for (ObjectPlaceMode mode : ObjectPlaceMode.values()) { - try { - plans.put(mode, mode.createLifecycle()); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("Invalid placement lifecycle for " + mode + ": " + e.getMessage(), e); - } - } - return new PlacementLifecycles(plans); - } - - public static PlacementLifecycles defaults() { - return Defaults.INSTANCE; - } - - static PlacementLifecycles forPlacer(IObjectPlacer placer) { - var engine = placer.getEngine(); - PlacementLifecycles plans = engine == null ? null : engine.getPlacementLifecycles(); - return plans == null ? defaults() : plans; - } - - public PlacementLifecycle get(ObjectPlaceMode mode) { - return plans.get(java.util.Objects.requireNonNull(mode, "Placement mode")); - } - - private static final class Defaults { - private static final PlacementLifecycles INSTANCE = resolve(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModule.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModule.java deleted file mode 100644 index e9e0eb433..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModule.java +++ /dev/null @@ -1,9 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -/** - * Registers work during runtime construction. Functions are shared by concurrent placements: - * implementations must receive placement state at execution time, never capture it at installation. - */ -public interface PlacementModule { - void install(PlacementLifecycleBuilder lifecycle); -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleAnchor.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleAnchor.java deleted file mode 100644 index f9a60c738..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleAnchor.java +++ /dev/null @@ -1,43 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.terrain.carving.CarvingMode; -/** Common caller-supplied and from-bottom anchors wrap each mode's sampled height. */ -final class PlacementModuleAnchor implements PlacementModule { - static final PlacementLifecycleDependency HEIGHT = new PlacementLifecycleDependency("anchor.height"); - static final PlacementLifecycleDependency POSITIONED = new PlacementLifecycleDependency("anchor.positioned"); - static final PlacementLifecycleDependency FINAL_HEIGHT = new PlacementLifecycleDependency("anchor.final"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(POSITIONED, PlacementStage.HEIGHT, (context, state, ignored) -> { - if (context.yv >= 0 && state.config.isBottom() - && state.config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE) { - state.y += Math.floorDiv(context.self.h, 2); - if (!state.config.isForcePlace() && state.config.getCarvingSupport() != CarvingMode.CARVING_ONLY - && PlacementModuleSurfaceSupport.rejectsAnchor(context, state, context.x, state.y, context.z)) { - state.reject("carving-anchor"); - } - } - }, HEIGHT); - lifecycle.add(FINAL_HEIGHT, PlacementStage.BEFORE_BLOCKS, - (context, state, ignored) -> state.y += state.yrand, POSITIONED, PlacementModuleCollision.CHECK); - } - - static void install(PlacementLifecycleBuilder lifecycle, PlacementFunction sampledHeight) { - lifecycle.add(HEIGHT, PlacementStage.HEIGHT, (context, state, ignored) -> { - if (state.config.isFromBottom()) { - state.y = context.self.getH() + 1 + state.rty; - } else if (context.yv < 0) { - sampledHeight.execute(context, state, null); - return; - } else { - state.y = context.yv; - } - if (!state.config.isForcePlace() - && state.config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE - && PlacementModuleSurfaceSupport.rejectsAnchor(context, state, context.x, state.y, context.z)) { - state.reject("carving-anchor"); - } - }, PlacementModulePreparation.TRANSFORMS); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBlocks.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBlocks.java deleted file mode 100644 index 5231eb414..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBlocks.java +++ /dev/null @@ -1,18 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -/** Owns block-pass execution and the object read lock. */ -final class PlacementModuleBlocks implements PlacementModule { - static final PlacementLifecycleDependency COMPLETE = new PlacementLifecycleDependency("blocks.complete"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(COMPLETE, PlacementStage.BLOCKS, (context, state, plan) -> { - context.self.readLock.lock(); - try { - new ObjectBlockPass(context, state, plan, context.listener).process(); - } finally { - context.self.readLock.unlock(); - } - }, PlacementModuleBore.BORE); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBore.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBore.java deleted file mode 100644 index 3971388ef..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBore.java +++ /dev/null @@ -1,25 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -/** The first world-writing step; all placement guards must have completed. */ -final class PlacementModuleBore implements PlacementModule { - static final PlacementLifecycleDependency BORE = new PlacementLifecycleDependency("bore"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(BORE, PlacementStage.BEFORE_BLOCKS, (context, state, ignored) -> { - if (!state.config.isBore()) { - return; - } - var bounds = state.worldBounds; - for (int x = bounds.minX(); x <= bounds.maxX(); x++) { - for (int y = bounds.minY() - state.config.getBoreExtendMinY(); - y <= bounds.maxY() + state.config.getBoreExtendMaxY(); y++) { - for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) { - state.placer.set(x, y, z, IrisObject.States.AIR); - } - } - } - }, PlacementModuleBounds.WORLD, PlacementModuleCollision.CHECK, PlacementModuleAnchor.FINAL_HEIGHT); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBounds.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBounds.java deleted file mode 100644 index 50fc4674e..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleBounds.java +++ /dev/null @@ -1,43 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -/** Computes the shared world volume for collision checks and boring, only when needed. */ -final class PlacementModuleBounds implements PlacementModule { - static final PlacementLifecycleDependency WORLD = new PlacementLifecycleDependency("bounds.world"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(WORLD, PlacementStage.VALIDATE, (context, state, ignored) -> { - IrisObjectPlacement config = state.config; - if (config.isBore() || (!config.isForcePlace() && config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE - && (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty()))) { - state.worldBounds = resolve(context, state, context.yv < 0 && config.getMode() == ObjectPlaceMode.PAINT); - } - }, PlacementModuleNativeStructureProtection.CHECK); - } - - private static PlacementContext.WorldBounds resolve(PlacementContext context, PlacementState state, boolean paint) { - int x = context.x; - int z = context.z; - int y = state.y + state.yrand; - int minX = x + state.bounds.minX(); - int maxX = x + state.bounds.maxX(); - int minZ = z + state.bounds.minZ(); - int maxZ = z + state.bounds.maxZ(); - if (!paint) { - return new PlacementContext.WorldBounds(minX, maxX, y + state.bounds.minY(), y + state.bounds.maxY(), minZ, maxZ); - } - - int minimumSurface = Integer.MAX_VALUE; - int maximumSurface = Integer.MIN_VALUE; - for (int worldX = minX; worldX <= maxX; worldX++) { - for (int worldZ = minZ; worldZ <= maxZ; worldZ++) { - int surface = state.placer.getHighest(worldX, worldZ, context.self.getLoader(), state.config.isUnderwater()); - minimumSurface = Math.min(minimumSurface, surface); - maximumSurface = Math.max(maximumSurface, surface); - } - } - int paintOffset = Math.floorDiv(context.self.h, 2); - return new PlacementContext.WorldBounds(minX, maxX, minimumSurface + state.bounds.minY() + paintOffset, - maximumSurface + state.bounds.maxY() + paintOffset, minZ, maxZ); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleCenterHeight.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleCenterHeight.java deleted file mode 100644 index fe9cb93a2..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleCenterHeight.java +++ /dev/null @@ -1,18 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -public final class PlacementModuleCenterHeight implements PlacementModule { - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - PlacementModuleAnchor.install(lifecycle, PlacementModuleCenterHeight::sample); - } - - private static void sample(PlacementContext context, PlacementState state, Void ignored) { - state.y = (context.caveResult != null ? context.caveResult.getSurface() : state.placer.getHighest(context.x, context.z, context.self.getLoader(), state.config.isUnderwater())) + state.rty; - if (!state.config.isForcePlace()) { - if (PlacementModuleSurfaceSupport.rejectsAnchor(context, state, context.x, state.y, context.z)) { - state.reject("carving-anchor"); - } - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleCollision.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleCollision.java deleted file mode 100644 index db589dd06..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleCollision.java +++ /dev/null @@ -1,41 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.PlacedObject; - -/** Owns object collision policy and its data-engine requirement. */ -final class PlacementModuleCollision implements PlacementModule { - static final PlacementLifecycleDependency CHECK = new PlacementLifecycleDependency("validate.collisions"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(CHECK, PlacementStage.VALIDATE, (context, state, ignored) -> { - IrisObjectPlacement config = state.config; - if (config.isForcePlace() || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE - || (config.getAllowedCollisions().isEmpty() && config.getForbiddenCollisions().isEmpty())) { - return; - } - Engine engine = context.rdata.getEngine(); - if (engine == null) { - throw new IllegalStateException("Object placement requires active Iris data for collision settings."); - } - var bounds = state.worldBounds; - for (int x = bounds.minX(); x <= bounds.maxX(); x++) { - for (int y = bounds.minY(); y <= bounds.maxY(); y++) { - for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) { - PlacedObject placed = engine.getObjectPlacement(x, y, z); - if (placed == null || placed.getObject() == null) { - continue; - } - String key = placed.getObject().getLoadKey(); - if (key != null && config.getForbiddenCollisions().contains(key) - && !config.getAllowedCollisions().contains(key)) { - state.reject("object-collision"); - return; - } - } - } - } - }, PlacementModuleBounds.WORLD); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleFloating.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleFloating.java deleted file mode 100644 index f407192ce..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleFloating.java +++ /dev/null @@ -1,10 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -public final class PlacementModuleFloating implements PlacementModule { - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - PlacementModuleAnchor.install(lifecycle, (context, state, ignored) -> state.y = state.rty); - } - -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleHeight.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleHeight.java deleted file mode 100644 index 8ddb2ee9c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleHeight.java +++ /dev/null @@ -1,57 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -public final class PlacementModuleHeight implements PlacementModule { - private final boolean fast; - private final Mode mode; - - public enum Mode { - MIN, - MAX - } - - public PlacementModuleHeight(Mode mode, boolean fast) { - this.fast = fast; - this.mode = mode; - } - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - PlacementModuleAnchor.install(lifecycle, this::sample); - } - - private void sample(PlacementContext context, PlacementState state, Void ignored) { - int minX = context.x + state.bounds.minX(); - int maxX = context.x + state.bounds.maxX(); - int minZ = context.z + state.bounds.minZ(); - int maxZ = context.z + state.bounds.maxZ(); - if (Mode.MIN == mode) { - state.y = Integer.MAX_VALUE; - } - int xStep = fast ? Math.max(0, (maxX - minX) / 2) + 1 : 1; - int zStep = fast ? Math.max(0, (maxZ - minZ) / 2) + 1 : 1; - for (int i = minX; i <= maxX; i += xStep) { - for (int ii = minZ; ii <= maxZ; ii += zStep) { - columnHeight(context, state, i, ii); - if (state.isRejected()) { - return; - } - } - } - } - - private void columnHeight(PlacementContext context, PlacementState state, int i, int ii) { - int h = state.placer.getHighest(i, ii, context.self.getLoader(), state.config.isUnderwater()) + state.rty; - if (!state.config.isForcePlace()) { - if (PlacementModuleSurfaceSupport.rejectsAnchor(context, state, i, h, ii)) { - state.reject("carving-anchor"); - } - } - - if (Mode.MIN == mode && h < state.y) { - state.y = h; - } - if (Mode.MAX == mode && h > state.y) { - state.y = h; - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleLimits.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleLimits.java deleted file mode 100644 index f2ec8852d..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleLimits.java +++ /dev/null @@ -1,34 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -/** Water, cave clearance and height-clamp eligibility. */ -final class PlacementModuleLimits implements PlacementModule { - static final PlacementLifecycleDependency CHECK = new PlacementLifecycleDependency("validate.limits"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(CHECK, PlacementStage.VALIDATE, (context, state, ignored) -> { - IrisObjectPlacement config = state.config; - if (config.isForcePlace() || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) { - return; - } - if (context.yv < 0 && config.getMode() != ObjectPlaceMode.FLOATING - && !config.isUnderwater() && !config.isOnwater() - && state.placer.isUnderwater(context.x, context.z)) { - state.reject("underwater-anchor"); - return; - } - if (context.caveResult != null - && Math.max(0, context.self.h + state.yrand + state.ty) + 1 >= context.caveResult.getHeight()) { - state.reject("cave-clearance"); - return; - } - if (config.isUnderwater() && state.y + state.rty + state.ty >= state.placer.getFluidHeight()) { - state.reject("fluid-height"); - return; - } - if (!config.getClamp().canPlace(state.y + state.rty + state.ty, state.y - state.rty + state.ty)) { - state.reject("height-clamp"); - } - }, PlacementModuleSurfaceSupport.CHECK); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleNativeStructureProtection.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleNativeStructureProtection.java deleted file mode 100644 index d535586ae..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleNativeStructureProtection.java +++ /dev/null @@ -1,113 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.prefab.IrisObjectShaping; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.NativeStructureVolume; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.VectorMap; -import art.arcane.iris.util.common.math.IrisBlockVector; -import art.arcane.volmlib.util.collection.KList; - -/** Native structures remain protected even when forcePlace bypasses optional placement checks. */ -final class PlacementModuleNativeStructureProtection implements PlacementModule { - static final PlacementLifecycleDependency CHECK = new PlacementLifecycleDependency("validate.native-structures"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(CHECK, PlacementStage.VALIDATE, (context, state, ignored) -> { - if (state.config.getMode() != ObjectPlaceMode.STRUCTURE_PIECE && vetoes(context, state)) { - state.reject("native-structure"); - } - }, PlacementModuleLimits.CHECK); - } - - private static boolean vetoes(PlacementContext context, PlacementState state) { - IrisObject self = context.self; - IObjectPlacer placer = state.placer; - IrisObjectPlacement config = state.config; - ObjectSpinKernel spin = state.spin; - IrisBlockVector translateOffset = state.translateOffset; - boolean translating = translateOffset != null; - boolean ceilingHang = config.getMode() == ObjectPlaceMode.CEILING_HANG; - boolean paint = context.yv < 0 && config.getMode() == ObjectPlaceMode.PAINT; - int warpMargin = state.warpMargin; - int x = context.x; - int y = state.y + state.yrand; - int z = context.z; - Engine engine = placer.getEngine(); - if (engine == null) { - return false; - } - - int margin = (Math.max(self.getW(), Math.max(self.getH(), self.getD())) / 2) + 1 + warpMargin; - if (translating) { - margin += Math.max(Math.abs(translateOffset.getBlockX()), - Math.max(Math.abs(translateOffset.getBlockY()), Math.abs(translateOffset.getBlockZ()))); - } - - KList volumes = engine.getNativeStructureVolumes(x - margin, z - margin, x + margin, z + margin); - if (volumes == null || volumes.isEmpty()) { - return false; - } - - int worldY = y + engine.getMinHeight(); - int envelopeMinY = paint ? Integer.MIN_VALUE : worldY - margin; - int envelopeMaxY = paint ? Integer.MAX_VALUE : worldY + margin; - boolean envelopeMeetsPiece = false; - for (NativeStructureVolume volume : volumes) { - if (volume.intersects(x - margin, envelopeMinY, z - margin, x + margin, envelopeMaxY, z + margin)) { - envelopeMeetsPiece = true; - break; - } - } - - if (!envelopeMeetsPiece) { - return false; - } - - self.readLock.lock(); - try { - VectorMap.Cursor cursor = self.blocks.cursor(); - while (cursor.next()) { - PlatformBlockState source = cursor.value(); - if (source == null || isAirBlock(source)) { - continue; - } - - IrisBlockVector i = cursor.key().clone(); - spin.rotate(i); - if (ceilingHang) { - i.setY(-i.getBlockY()); - } - if (translating) { - i.add(translateOffset); - } - - int xx = x + (int) Math.round(i.getX()); - int zz = z + (int) Math.round(i.getZ()); - int yy = paint - ? (int) Math.round(i.getY()) + Math.floorDiv(self.h, 2) - + placer.getHighest(xx, zz, self.getLoader(), config.isUnderwater()) - : y + (int) Math.round(i.getY()); - int worldBlockY = yy + engine.getMinHeight(); - - for (NativeStructureVolume volume : volumes) { - if (volume.containsWithin(xx, worldBlockY, zz, warpMargin)) { - return true; - } - } - } - } finally { - self.readLock.unlock(); - } - - return false; - } - - private static boolean isAirBlock(PlatformBlockState state) { - String material = IrisObjectShaping.materialKey(state); - return material.equals("minecraft:air") || material.equals("minecraft:cave_air"); - } - -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModulePaint.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModulePaint.java deleted file mode 100644 index 4f1404e2a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModulePaint.java +++ /dev/null @@ -1,18 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -public final class PlacementModulePaint implements PlacementModule { - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - PlacementModuleAnchor.install(lifecycle, PlacementModulePaint::sample); - } - - private static void sample(PlacementContext context, PlacementState state, Void ignored) { - state.y = state.placer.getHighest(context.x, context.z, context.self.getLoader(), state.config.isUnderwater()) + state.rty; - if (!state.config.isForcePlace()) { - if (PlacementModuleSurfaceSupport.rejectsAnchor(context, state, context.x, state.y, context.z)) { - state.reject("carving-anchor"); - } - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModulePreparation.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModulePreparation.java deleted file mode 100644 index a3593ccad..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModulePreparation.java +++ /dev/null @@ -1,98 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.prefab.IrisObjectShaping; -import art.arcane.iris.engine.object.prefab.IrisObjectTranslate; -import art.arcane.iris.engine.framework.placer.HeightmapObjectPlacer; -import art.arcane.iris.util.common.math.IrisBlockVector; - -/** Resolves the placer and transforms once, preserving the caller's RNG draw order. */ -final class PlacementModulePreparation implements PlacementModule { - static final PlacementLifecycleDependency PLACER = new PlacementLifecycleDependency("prepare.placer"); - static final PlacementLifecycleDependency TRANSFORMS = new PlacementLifecycleDependency("prepare.transforms"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(PLACER, PlacementStage.PREPARE, (context, state, ignored) -> { - if (state.config.getHeightmap() != null) { - state.placer = new HeightmapObjectPlacer(context.rng, context.x, context.yv, context.z, - state.config, context.placer); - } - }); - lifecycle.add(TRANSFORMS, PlacementStage.PREPARE, PlacementModulePreparation::prepare, - PlacementModuleSlope.SLOPE); - } - - private static void prepare(PlacementContext context, PlacementState state, Void ignored) { - IrisObjectPlacement config = state.config; - IrisObject self = context.self; - if (config.isSmartBore()) { - IrisObjectShaping.ensureSmartBored(self); - } - int spinx = context.rng.imax() / 1000; - int spiny = context.rng.imax() / 1000; - int spinz = context.rng.imax() / 1000; - state.spinX = spinx; - state.spinY = spiny; - state.spinZ = spinz; - state.rty = config.getRotation().rotate(new IrisBlockVector(0, self.getCenter().getBlockY(), 0), spinx, spiny, spinz).getBlockY(); - state.ty = config.getTranslate().translate(new IrisBlockVector(0, self.getCenter().getBlockY(), 0), config.getRotation(), spinx, spiny, spinz).getBlockY(); - state.spin = new ObjectSpinKernel(config.getRotation(), spinx, spiny, spinz); - IrisObjectTranslate translate = config.getTranslate(); - if (translate.canTranslate()) { - state.translateOffset = config.getRotation().rotate( - new IrisBlockVector(translate.getX(), translate.getY(), translate.getZ()), spinx, spiny, spinz); - } - int yrand = translate.getYRandom(); - state.yrand = yrand > 0 ? context.rng.i(0, yrand) : yrand < 0 ? context.rng.i(yrand, 0) : yrand; - state.warpMargin = !config.getWarp().isFlat() ? (int) Math.ceil(Math.abs(config.getWarp().getMultiplier()) / 2D) : 0; - state.bounds = transformedBounds(self, state.spin, state.translateOffset != null, state.translateOffset, - config.getMode() == ObjectPlaceMode.CEILING_HANG, state.warpMargin); - } - - private static PlacementContext.TransformedBounds transformedBounds(IrisObject self, ObjectSpinKernel spin, boolean translating, IrisBlockVector translateOffset, - boolean ceilingHang, int margin) { - int sourceMinX = -self.getCenter().getBlockX(); - int sourceMaxX = self.getW() - self.getCenter().getBlockX() - 1; - int sourceMinY = -self.getCenter().getBlockY(); - int sourceMaxY = self.getH() - self.getCenter().getBlockY() - 1; - int sourceMinZ = -self.getCenter().getBlockZ(); - int sourceMaxZ = self.getD() - self.getCenter().getBlockZ() - 1; - int minX = Integer.MAX_VALUE; - int maxX = Integer.MIN_VALUE; - int minY = Integer.MAX_VALUE; - int maxY = Integer.MIN_VALUE; - int minZ = Integer.MAX_VALUE; - int maxZ = Integer.MIN_VALUE; - - for (int xCorner = 0; xCorner < 2; xCorner++) { - int sourceX = xCorner == 0 ? sourceMinX : sourceMaxX; - for (int yCorner = 0; yCorner < 2; yCorner++) { - int sourceY = yCorner == 0 ? sourceMinY : sourceMaxY; - for (int zCorner = 0; zCorner < 2; zCorner++) { - int sourceZ = zCorner == 0 ? sourceMinZ : sourceMaxZ; - IrisBlockVector corner = new IrisBlockVector(sourceX, sourceY, sourceZ); - spin.rotate(corner); - if (ceilingHang) { - corner.setY(-corner.getBlockY()); - } - if (translating) { - corner.add(translateOffset); - } - int transformedX = (int) Math.round(corner.getX()); - int transformedY = (int) Math.round(corner.getY()); - int transformedZ = (int) Math.round(corner.getZ()); - minX = Math.min(minX, transformedX); - maxX = Math.max(maxX, transformedX); - minY = Math.min(minY, transformedY); - maxY = Math.max(maxY, transformedY); - minZ = Math.min(minZ, transformedZ); - maxZ = Math.max(maxZ, transformedZ); - } - } - } - - return new PlacementContext.TransformedBounds(minX - margin, maxX + margin, minY, maxY, minZ - margin, maxZ + margin); - } - -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSlope.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSlope.java deleted file mode 100644 index bd8618767..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSlope.java +++ /dev/null @@ -1,72 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisAxisRotationClamp; -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.prefab.IrisObjectRotation; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.util.project.stream.ProceduralStream; - -/** Slope checks precede random rotation and leave the caller's configuration intact. */ -final class PlacementModuleSlope implements PlacementModule { - static final PlacementLifecycleDependency SLOPE = new PlacementLifecycleDependency("prepare.slope"); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(SLOPE, PlacementStage.PREPARE, (context, state, ignored) -> { - IrisObjectPlacement config = state.config; - boolean evaluate = !config.isForcePlace() && !config.getSlopeCondition().isDefault(); - if (!evaluate && !config.isRotateTowardsSlope()) { - return; - } - Engine engine = state.placer.getEngine(); - if (engine == null) { - throw new IllegalStateException("Object placement requires an active Iris engine for slope settings."); - } - if (evaluate && !config.getSlopeCondition().isValid( - engine.getComplex().getSlopeStream().get(context.x, context.z))) { - state.reject("slope"); - return; - } - if (config.isRotateTowardsSlope()) { - state.config = rotate(context.self, config, engine, context.x, context.z); - } - }, PlacementModulePreparation.PLACER); - } - - private static IrisObjectPlacement rotate(IrisObject self, IrisObjectPlacement config, Engine engine, int x, int z) { - int slopeRotationY = 0; - ProceduralStream heightStream = engine.getComplex().getHeightStream(); - // Whichever side of the rectangle that bounds the object is lowest is the 'direction' of the slope (simply said). - double hNorth = heightStream.get(x, z + ((float) self.d) / 2); - double hEast = heightStream.get(x + ((float) self.w) / 2, z); - double hSouth = heightStream.get(x, z - ((float) self.d) / 2); - double hWest = heightStream.get(x - ((float) self.w) / 2, z); - double min = Math.min(Math.min(hNorth, hEast), Math.min(hSouth, hWest)); - if (min == hNorth) { - slopeRotationY = 0; - } else if (min == hEast) { - slopeRotationY = 90; - } else if (min == hSouth) { - slopeRotationY = 180; - } else if (min == hWest) { - slopeRotationY = 270; - } - - double newRotation = config.getRotation().getYAxis().getMin() + slopeRotationY; - IrisObjectRotation originalRotation = config.getRotation(); - IrisObjectRotation slopeRotation = new IrisObjectRotation(); - slopeRotation.setXAxis(originalRotation.getXAxis()); - slopeRotation.setZAxis(originalRotation.getZAxis()); - if (newRotation == 0) { - slopeRotation.setYAxis(new IrisAxisRotationClamp(false, false, 0, 0, 90)); - slopeRotation.setEnabled(originalRotation.canRotateX() || originalRotation.canRotateZ()); - } else { - slopeRotation.setYAxis(new IrisAxisRotationClamp(true, false, newRotation, newRotation, 90)); - slopeRotation.setEnabled(true); - } - config = config.toPlacement(config.getPlace().toArray(new String[0])); - config.setRotation(slopeRotation); - return config; - } - -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSnow.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSnow.java deleted file mode 100644 index 0a452c6c9..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSnow.java +++ /dev/null @@ -1,45 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.volmlib.util.collection.KMap; -import art.arcane.volmlib.util.math.Position2; -import art.arcane.volmlib.util.math.RNG; - -/** Snow uses only successful object writes, and follows stilt or vacuum work. */ -final class PlacementModuleSnow implements PlacementModule { - static final PlacementLifecycleDependency COLLECT = new PlacementLifecycleDependency("snow.collect"); - static final PlacementLifecycleDependency FINISH = new PlacementLifecycleDependency("snow.finish"); - private final PlacementLifecycleDependency after; - - PlacementModuleSnow(PlacementLifecycleDependency after) { - this.after = after; - } - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(COLLECT, PlacementStage.BLOCK_WRITTEN, (context, state, block) -> { - if (!(state.config.getSnow() > 0)) { - return; - } - if (state.snowHeights == null) { - state.snowHeights = new KMap<>(); - } - Position2 position = new Position2(block.x(), block.z()); - Integer current = state.snowHeights.get(position); - if (current == null || current < block.y()) { - state.snowHeights.put(position, block.y()); - } - }); - lifecycle.add(FINISH, PlacementStage.AFTER_BLOCKS, (context, state, ignored) -> { - if (state.snowHeights == null) { - return; - } - RNG rng = context.rng.nextParallelRNG(3468854); - for (Position2 position : state.snowHeights.k()) { - int height = rng.i(0, (int) (state.config.getSnow() * 7)); - state.placer.set(position.getX(), state.snowHeights.get(position) + 1, position.getZ(), - IrisObject.States.SNOW_LAYERS[Math.max(Math.min(height, 7), 0)]); - } - }, COLLECT, after); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleStilt.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleStilt.java deleted file mode 100644 index 67fd1b62b..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleStilt.java +++ /dev/null @@ -1,317 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.material.BlockDataMergeSupport; -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.prefab.IrisObjectShaping; -import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.spi.IrisLogging; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.iris.util.common.data.VectorMap; -import art.arcane.iris.util.common.math.IrisBlockVector; -import art.arcane.iris.util.project.noise.CNG; -import art.arcane.volmlib.util.math.RNG; - -/** Stilt preparation observes all transformed blocks before the fill step runs. */ -public final class PlacementModuleStilt implements PlacementModule { - static final PlacementLifecycleDependency BOUNDS = new PlacementLifecycleDependency("stilt.bounds"); - static final PlacementLifecycleDependency FILL = new PlacementLifecycleDependency("stilt.fill"); - - private final boolean fast; - private final Mode mode; - - public enum Mode { - DEFAULT, CENTER, MIN, ERODE, ORGANIC, CEILING - } - - public PlacementModuleStilt(Mode mode, boolean fast) { - this.mode = mode; - this.fast = fast; - } - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - PlacementModule height = switch (mode) { - case CENTER, ORGANIC, CEILING -> new PlacementModuleCenterHeight(); - case MIN -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MIN, fast); - case DEFAULT, ERODE -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MAX, fast); - }; - height.install(lifecycle); - if (mode == Mode.CEILING) { - new ObjectModuleCeilingHang().install(lifecycle); - } - PlacementLifecycleDependency[] prerequisites = mode == Mode.CEILING - ? new PlacementLifecycleDependency[]{PlacementModuleAnchor.HEIGHT, ObjectModuleCeilingHang.FLIP} - : new PlacementLifecycleDependency[]{PlacementModuleAnchor.HEIGHT}; - lifecycle.add(BOUNDS, PlacementStage.COLLECT_BLOCK, (context, state, block) -> { - if (IrisObjectShaping.shouldStilt(block.data())) { - state.stiltLowest = Math.min(state.stiltLowest, block.vector().getBlockY()); - state.stiltHighest = Math.max(state.stiltHighest, block.vector().getBlockY()); - } - }, prerequisites); - lifecycle.add(FILL, PlacementStage.AFTER_BLOCKS, this::fill, PlacementModuleAnchor.HEIGHT, BOUNDS, PlacementModuleBlocks.COMPLETE); - } - - private void fill(PlacementContext context, PlacementState state, Void ignored) { - if (state.stiltLowest == Integer.MAX_VALUE) { - return; - } - IrisObject self = context.self; - IrisObjectPlacement config = state.config; - IObjectPlacer placer = state.placer; - IrisData rdata = context.rdata; - RNG rng = context.rng; - ObjectSpinKernel spin = state.spin; - IrisBlockVector translateOffset = state.translateOffset; - boolean translating = translateOffset != null; - boolean ceilingHang = mode == Mode.CEILING; - boolean organic = mode == Mode.ORGANIC || ceilingHang; - boolean eroding = mode == Mode.ERODE; - boolean hasEdits = !config.getEdit().isEmpty(); - boolean warped = !config.getWarp().isFlat(); - CNG surfaceWarp = warped ? config.getSurfaceWarp(rng, self.getLoader()) : null; - double warpHalf = warped ? config.getWarp().getMultiplier() / 2D : 0D; - int x = context.x; - int z = context.z; - int y = state.y; - int lowest = state.stiltLowest; - int topLayer = state.stiltHighest; - int xx, zz; - self.readLock.lock(); - try { - VectorMap blocks = self.blocks; - IrisStiltSettings settings = config.getStiltSettings(); - - double erodeCentroidX = 0; - double erodeCentroidZ = 0; - double erodeMaxDist = 1; - if (eroding) { - int centroidCount = 0; - VectorMap.Cursor centroidCursor = blocks.cursor(); - while (centroidCursor.next()) { - IrisBlockVector rot = centroidCursor.key().clone(); - spin.rotate(rot); - if (translating) { - rot.add(translateOffset); - } - if (rot.getBlockY() == lowest) { - PlatformBlockState bd = centroidCursor.value(); - if (bd != null && IrisObjectShaping.shouldStilt(bd)) { - erodeCentroidX += rot.getX(); - erodeCentroidZ += rot.getZ(); - centroidCount++; - } - } - } - if (centroidCount > 0) { - erodeCentroidX /= centroidCount; - erodeCentroidZ /= centroidCount; - } - VectorMap.Cursor spreadCursor = blocks.cursor(); - while (spreadCursor.next()) { - IrisBlockVector rot = spreadCursor.key().clone(); - spin.rotate(rot); - if (translating) { - rot.add(translateOffset); - } - if (rot.getBlockY() == lowest) { - PlatformBlockState bd = spreadCursor.value(); - if (bd != null && IrisObjectShaping.shouldStilt(bd)) { - double dx = rot.getX() - erodeCentroidX; - double dz = rot.getZ() - erodeCentroidZ; - double dist = Math.sqrt(dx * dx + dz * dz); - if (dist > erodeMaxDist) { - erodeMaxDist = dist; - } - } - } - } - } - - VectorMap.Cursor stiltCursor = blocks.cursor(); - while (stiltCursor.next()) { - IrisBlockVector g = stiltCursor.key(); - PlatformBlockState sourceData; - try { - sourceData = stiltCursor.value(); - } catch (Throwable e) { - IrisLogging.reportError(e); - IrisLogging.warn("Failed to read block node " + g.getBlockX() + "," + g.getBlockY() + "," + g.getBlockZ() + " in object " + self.getLoadKey() + " (stilt cme)"); - sourceData = IrisObject.States.AIR; - } - - if (sourceData == null) { - IrisLogging.warn("Failed to read block node " + g.getBlockX() + "," + g.getBlockY() + "," + g.getBlockZ() + " in object " + self.getLoadKey() + " (stilt null)"); - sourceData = IrisObject.States.AIR; - } - - if (!IrisObjectShaping.shouldStilt(sourceData)) { - continue; - } - - PlatformBlockState d = sourceData; - if (settings != null && settings.getPalette() != null) { - d = config.getStiltSettings().getPalette().get(rng, x, y, z, rdata); - } else { - String mat = IrisObjectShaping.materialKey(d); - if (mat.equals("minecraft:grass_block") || mat.equals("minecraft:mycelium") || mat.equals("minecraft:podzol") || mat.equals("minecraft:dirt_path")) { - d = B.getState("minecraft:dirt"); - } - } - - IrisBlockVector i = g.clone(); - spin.rotate(i); - if (ceilingHang) { - i.setY(-i.getBlockY()); - } - if (translating) { - i.add(translateOffset); - } - d = spin.rotate(d); - - int targetLayer = ceilingHang ? topLayer : lowest; - if (i.getBlockY() != targetLayer) - continue; - - if (hasEdits) { - for (IrisObjectReplace j : config.getEdit()) { - if (rng.chance(j.getChance())) { - for (PlatformBlockState k : j.getFind(rdata)) { - if (d == null) { - continue; - } - if (j.isExact() ? k.matches(d) : IrisObjectShaping.materialKey(k).equals(IrisObjectShaping.materialKey(d))) { - PlatformBlockState newData = j.getReplace(rng, i.getX() + x, i.getY() + y, i.getZ() + z, rdata); - - if (IrisObjectShaping.materialKey(newData).equals(IrisObjectShaping.materialKey(d))) { - d = BlockDataMergeSupport.merge(d, newData); - } else { - d = newData; - } - } - } - } - } - } - - if (d == null || !d.isOccluding()) - continue; - - xx = x + (int) Math.round(i.getX()); - zz = z + (int) Math.round(i.getZ()); - - if (warped) { - xx += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getX() + x, i.getY() + y, i.getZ() + z); - zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, i.getZ() + z, i.getY() + y, i.getX() + x); - } - - if (organic) { - int startY = targetLayer + y; - int maxScan = settings != null ? Math.max(1, settings.getOrganicMaxScan()) : 48; - int jitterMax = settings != null ? Math.max(0, settings.getOrganicJitter()) : 3; - double scratch = settings != null ? Math.max(0, Math.min(1, settings.getOrganicScratch())) : 0.55; - long colHash = ((long) xx * 341873128712L) ^ ((long) zz * 132897987541L); - int jitter = jitterMax > 0 ? (int) (Math.abs(colHash) % (jitterMax + 1)) : 0; - - if (ceilingHang) { - int scan = 0; - int solidY = startY + 1; - while (scan < maxScan && !placer.isSolid(xx, solidY, zz)) { - solidY++; - scan++; - } - int topBound = (scan < maxScan ? solidY - 1 : startY + Math.min(maxScan, 8)) - jitter; - int total = topBound - startY; - for (int j = startY; j <= topBound; j++) { - if (scratch > 0 && total > 0) { - double ratio = (double) (j - startY) / total; - if (ratio > (1.0 - scratch)) { - long sh = ((long) xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L); - double skipChance = (ratio - (1.0 - scratch)) / scratch; - if ((Math.abs(sh) % 1000) / 1000.0 < skipChance * 0.7) { - continue; - } - } - } - placer.set(xx, j, zz, d); - } - } else { - int scan = 0; - int solidY = startY - 1; - while (scan < maxScan && !placer.isSolid(xx, solidY, zz)) { - solidY--; - scan++; - } - int bottomBound = (scan < maxScan ? solidY + 1 : startY - Math.min(maxScan, 8)) + jitter; - int total = startY - bottomBound; - for (int j = startY; j >= bottomBound; j--) { - if (scratch > 0 && total > 0) { - double ratio = (double) (startY - j) / total; - if (ratio > (1.0 - scratch)) { - long sh = ((long) xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L); - double skipChance = (ratio - (1.0 - scratch)) / scratch; - if ((Math.abs(sh) % 1000) / 1000.0 < skipChance * 0.7) { - continue; - } - } - } - placer.set(xx, j, zz, d); - } - } - continue; - } - - int highest = placer.getHighest(xx, zz, self.getLoader(), true); - - if (IrisProceduralBlocks.hasProperty(d, "waterlogged") && ObjectBlockPass.shouldAutoWaterlogBlock(context, state, xx, highest, zz)) { - d = d.withProperty("waterlogged", "true"); - } - - int lowerBound = highest - 1; - if (settings != null) { - lowerBound -= config.getStiltSettings().getOverStilt() - rng.i(0, config.getStiltSettings().getYRand()); - if (settings.getYMax() != 0) - lowerBound -= Math.min(config.getStiltSettings().getYMax() - (lowest + y - highest), 0); - } - - if (eroding) { - double dx = i.getX() - erodeCentroidX; - double dz = i.getZ() - erodeCentroidZ; - double normalizedDist = Math.sqrt(dx * dx + dz * dz) / erodeMaxDist; - normalizedDist = Math.min(normalizedDist, 1.0); - int totalDepth = (lowest + y) - lowerBound; - int erodeDepth = (int) (totalDepth * Math.pow(1.0 - normalizedDist, 1.5)); - lowerBound = (lowest + y) - erodeDepth; - } - - for (int j = lowest + y; j > lowerBound; j--) { - PlatformBlockState fluidState = placer.get(xx, j, zz); - if (B.isFluid(fluidState)) { - break; - } - if (eroding) { - int depth = (lowest + y) - j; - int totalDepth = (lowest + y) - lowerBound; - double depthRatio = totalDepth > 0 ? (double) depth / totalDepth : 0; - if (depthRatio > 0.4) { - long hash = ((long) (xx * 341873128712L) ^ ((long) j * 132897987541L) ^ ((long) zz * 735791245321L)); - double skipChance = (depthRatio - 0.4) / 0.6; - if ((Math.abs(hash) % 1000) / 1000.0 < skipChance * 0.7) { - continue; - } - } - } - - if (B.isVineBlock(d)) { - d = ObjectBlockPass.attachVineFaces(placer, d, xx, j, zz); - } - placer.set(xx, j, zz, d); - } - - } - } finally { - self.readLock.unlock(); - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSurfaceSupport.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSurfaceSupport.java deleted file mode 100644 index 1bfaf8e91..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleSurfaceSupport.java +++ /dev/null @@ -1,67 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.terrain.carving.CarvingMode; -import art.arcane.iris.spi.IrisLogging; -import java.util.concurrent.ConcurrentHashMap; - -/** Carving and surface support rules, including the bedrock diagnostic. */ -final class PlacementModuleSurfaceSupport implements PlacementModule { - static final PlacementLifecycleDependency CHECK = new PlacementLifecycleDependency("validate.surface"); - private static final long IMPLAUSIBLE_BEDROCK_WARN_THROTTLE_MS = 5000L; - private static final ConcurrentHashMap IMPLAUSIBLE_BEDROCK_WARNS = new ConcurrentHashMap<>(); - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(CHECK, PlacementStage.VALIDATE, (context, state, ignored) -> { - IrisObjectPlacement config = state.config; - boolean rawStructurePiece = config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE; - if (context.yv < 0 && !config.isForcePlace() && !config.isFromBottom() - && config.getMode() != ObjectPlaceMode.FLOATING && !rawStructurePiece - && config.getCarvingSupport().supportsSurface() && state.placer.getEngine() != null - && state.placer.getEngine().getDimension().isBedrock() && state.y <= 1) { - warnImplausibleBedrockPlacement(context.self, state.placer, config, context.x, state.y, context.z); - state.reject("bedrock-anchor"); - return; - } - boolean surfaceAnchored = context.yv < 0 ? config.getCarvingSupport().supportsSurface() - : config.getCarvingSupport() == CarvingMode.SURFACE_ONLY; - if (surfaceAnchored && !config.isForcePlace() && !config.isFromBottom() - && config.getMode() != ObjectPlaceMode.FLOATING && !rawStructurePiece - && !config.isUnderwater() && !config.isOnwater() && config.isRequireSurfaceSupport() - && IrisSurfaceSupport.isUnsupported(context.placer, context.self.getLoader(), context.x, context.z, - config.getTranslate(), config.getRotation(), state.spinX, state.spinY, state.spinZ, - context.self.getSurfaceSupportOffsets(), config.getSurfaceSupportBuffer(), config.getSurfaceSupportDepth())) { - state.reject("surface-support"); - } - }, PlacementModuleAnchor.POSITIONED); - } - - static boolean rejectsAnchor(PlacementContext context, PlacementState state, int x, int y, int z) { - return switch (state.config.getCarvingSupport()) { - case SURFACE_ONLY -> state.placer.isCarved(x, y, z); - case CARVING_ONLY -> !(state.placer.isCarved(x, y, z) || state.placer.isCarved(x, y - 1, z) - || state.placer.isCarved(x, y - 2, z) || state.placer.isCarved(x, y - 3, z)); - case ANYWHERE -> false; - }; - } - - private static void warnImplausibleBedrockPlacement(IrisObject self, IObjectPlacer placer, IrisObjectPlacement config, int x, int y, int z) { - String key = self.getLoadKey(); - String fingerprint = (key == null ? "" : key) + "|" + config.getMode(); - long now = System.currentTimeMillis(); - Long last = IMPLAUSIBLE_BEDROCK_WARNS.get(fingerprint); - if (last != null && now - last < IMPLAUSIBLE_BEDROCK_WARN_THROTTLE_MS) { - return; - } - IMPLAUSIBLE_BEDROCK_WARNS.put(fingerprint, now); - IrisLogging.warn("Implausible object placement rejected: " - + (key == null ? "" : key) - + " resolved anchorY=" + y + " at (" + x + "," + z + ") mode=" + config.getMode() - + " carving=" + config.getCarvingSupport() - + ". Surface-anchored placement should never land on the bedrock row. " - + "Height sampling returned a bogus value — not configured for floor placement " - + "(forcePlace=false, fromBottom=false, mode!=FLOATING). Skipping to protect bedrock."); - } - -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleVacuum.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleVacuum.java deleted file mode 100644 index 564cc2fe9..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModuleVacuum.java +++ /dev/null @@ -1,90 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.IrisComplex; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.iris.util.project.noise.SimplexNoise; - -/** Collects written object bounds, then bends terrain to meet them. Installed for vacuum modes. */ -final class PlacementModuleVacuum implements PlacementModule { - static final PlacementLifecycleDependency COLLECT = new PlacementLifecycleDependency("vacuum.collect"); - static final PlacementLifecycleDependency FINISH = new PlacementLifecycleDependency("vacuum.finish"); - private static final long VACUUM_WAVE_SEED = 7392113L; - - @Override - public void install(PlacementLifecycleBuilder lifecycle) { - lifecycle.add(COLLECT, PlacementStage.BLOCK_WRITTEN, (context, state, block) -> { - state.vacuumLowest = Math.min(state.vacuumLowest, block.y()); - state.vacuumHighest = Math.max(state.vacuumHighest, block.y()); - }); - lifecycle.add(FINISH, PlacementStage.AFTER_BLOCKS, (context, state, ignored) -> { - if (state.vacuumLowest == Integer.MAX_VALUE || state.placer.getEngine() == null) { - return; - } - vacuumTerrain(context.self, state.placer, state.config, context.x, context.z, - state.bounds.minX(), state.bounds.maxX(), state.bounds.minZ(), state.bounds.maxZ(), - state.vacuumLowest, state.vacuumHighest); - }, COLLECT, PlacementModuleBlocks.COMPLETE); - } - - private static void vacuumTerrain(IrisObject self, IObjectPlacer placer, IrisObjectPlacement config, int centerX, int centerZ, int lowX, int highX, int lowZ, int highZ, int baseY, int topY) { - ObjectPlaceMode mode = config.getMode(); - IrisVacuumSettings settings = config.getVacuumSettings(); - int radius = IrisObjectVacuum.resolveRadius(mode, settings); - int step = IrisObjectVacuum.resolveStep(mode); - double falloff = IrisObjectVacuum.resolveFalloff(settings); - int jitter = settings != null ? Math.max(0, settings.getOrganicJitter()) : 4; - boolean organicEdge = mode == ObjectPlaceMode.VACUUM_ORGANIC; - boolean wavyEdge = mode == ObjectPlaceMode.VACUUM_WAVY; - double waveAmplitude = IrisObjectVacuum.resolveWaveAmplitude(settings); - double waveScale = IrisObjectVacuum.resolveWaveScale(settings); - SimplexNoise waveNoise = (wavyEdge && waveAmplitude > 0) ? new SimplexNoise(VACUUM_WAVE_SEED) : null; - int meetY = baseY - 1; - - IrisComplex complex = placer.getEngine().getComplex(); - int worldMin = placer.getEngine().getMinHeight(); - int worldMax = worldMin + placer.getEngine().getHeight() - 1; - - for (int dx = lowX - radius; dx <= highX + radius; dx += step) { - for (int dz = lowZ - radius; dz <= highZ + radius; dz += step) { - int cx = centerX + dx; - int cz = centerZ + dz; - double effRadius = radius; - if (organicEdge && jitter > 0) { - long h = ((long) cx * 341873128712L) ^ ((long) cz * 132897987541L); - double n = ((Math.abs(h) % 1000) / 1000.0) - 0.5; - effRadius = Math.max(1.0, radius + (n * 2.0 * jitter)); - } - int origY = placer.getHighest(cx, cz, self.getLoader(), true); - int targetY = IrisObjectVacuum.columnTargetY(dx, dz, lowX, highX, lowZ, highZ, effRadius, falloff, origY, meetY); - if (waveNoise != null) { - int outX = IrisObjectVacuum.outset(dx, lowX, highX); - int outZ = IrisObjectVacuum.outset(dz, lowZ, highZ); - double waveDistance = Math.sqrt((double) (outX * outX) + (double) (outZ * outZ)); - double sample = waveNoise.noiseSigned(cx * waveScale, cz * waveScale); - targetY += IrisObjectVacuum.waveOffset(waveDistance, effRadius, sample, waveAmplitude); - } - if (targetY == origY) { - continue; - } - targetY = Math.max(worldMin + 1, Math.min(worldMax, targetY)); - if (targetY > origY) { - PlatformBlockState fill = complex != null ? complex.getRockStream().get(cx, cz) : null; - if (B.isAir(fill)) { - fill = IrisObject.States.STONE; - } - for (int yy = origY + 1; yy <= targetY; yy++) { - placer.set(cx, yy, cz, fill); - } - } else if (targetY < origY) { - boolean inside = IrisObjectVacuum.outset(dx, lowX, highX) == 0 && IrisObjectVacuum.outset(dz, lowZ, highZ) == 0; - int carveFloor = IrisObjectVacuum.carveFloorY(targetY, topY, inside); - for (int yy = origY; yy >= carveFloor; yy--) { - placer.set(cx, yy, cz, IrisObject.States.AIR); - } - } - } - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementModules.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModules.java new file mode 100644 index 000000000..7ca2ab130 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/PlacementModules.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import com.volmit.IrisModule; + +import java.util.List; + +/** Iris's built-in object placement, as the IrisApi modules every pack's placement graph starts from. */ +public final class PlacementModules { + static final String VERSION = "built-in"; + + private PlacementModules() { + } + + public static List all() { + return List.of(new PrepareModule(), new AnchorModule(), new ValidateModule(), new BoreModule(), + new BlocksModule(), new StiltModule(), new VacuumModule(), new SnowModule()); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementStage.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementStage.java deleted file mode 100644 index 342918a9b..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementStage.java +++ /dev/null @@ -1,38 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import java.util.List; - -/** - * Whole-placement phases surround a nested block pass. TRANSFORM_BLOCK runs after rotation and - * before translation; COLLECT_BLOCK runs before edits; BLOCK_WRITTEN runs only for successful - * object writes. Block prerequisites refer to the current block. AFTER_BLOCKS waits for the - * entire block pass, including markers. All whole-placement validation precedes world writes. - */ -public final class PlacementStage { - public static final PlacementStage PREPARE = new PlacementStage<>("prepare", 0); - public static final PlacementStage HEIGHT = new PlacementStage<>("height", 1); - public static final PlacementStage VALIDATE = new PlacementStage<>("validate", 2); - public static final PlacementStage BEFORE_BLOCKS = new PlacementStage<>("before-blocks", 3); - public static final PlacementStage TRANSFORM_BLOCK = new PlacementStage<>("transform-block", 4); - public static final PlacementStage COLLECT_BLOCK = new PlacementStage<>("collect-block", 5); - public static final PlacementStage BLOCK_WRITTEN = new PlacementStage<>("block-written", 6); - // BLOCKS denotes completion of the whole pass, so later steps can depend on all block work. - public static final PlacementStage BLOCKS = new PlacementStage<>("blocks", 7); - public static final PlacementStage AFTER_BLOCKS = new PlacementStage<>("after-blocks", 8); - static final List> ALL = List.of(PREPARE, HEIGHT, VALIDATE, BEFORE_BLOCKS, - TRANSFORM_BLOCK, COLLECT_BLOCK, BLOCK_WRITTEN, BLOCKS, AFTER_BLOCKS); - static final List> BEFORE_PASS = List.of(PREPARE, HEIGHT, VALIDATE, BEFORE_BLOCKS); - - private final String name; - final int order; - - private PlacementStage(String name, int order) { - this.name = name; - this.order = order; - } - - @Override - public String toString() { - return name; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementState.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementState.java deleted file mode 100644 index c5def6945..000000000 --- a/src/main/java/art/arcane/iris/engine/object/placement/PlacementState.java +++ /dev/null @@ -1,67 +0,0 @@ -package art.arcane.iris.engine.object.placement; - -import art.arcane.iris.engine.object.placement.PlacementContext.TransformedBounds; -import art.arcane.iris.engine.object.placement.PlacementContext.WorldBounds; -import art.arcane.iris.util.common.math.IrisBlockVector; -import art.arcane.volmlib.util.collection.KMap; -import art.arcane.volmlib.util.math.Position2; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; - -import java.util.Objects; - -/** Results and accumulators owned by one placement, never by a shared module or plan. */ -@Getter -@Setter -public final class PlacementState { - IrisObjectPlacement config; - IObjectPlacer placer; - ObjectSpinKernel spin; - int spinX; - int spinY; - int spinZ; - IrisBlockVector translateOffset; - int rty; - int ty; - int yrand; - int warpMargin; - int y; - TransformedBounds bounds; - WorldBounds worldBounds; - int stiltLowest = Integer.MAX_VALUE; - int stiltHighest = Integer.MIN_VALUE; - int vacuumLowest = Integer.MAX_VALUE; - int vacuumHighest = Integer.MIN_VALUE; - KMap snowHeights; - - @Setter(AccessLevel.NONE) - private String rejection; - - PlacementState(PlacementContext context) { - this(-1, null); - config = context.config; - placer = context.placer; - } - - PlacementState(int y, TransformedBounds bounds) { - this.y = y; - this.bounds = bounds; - } - - /** The first rejection is terminal. Each guard decides whether forcePlace exempts its rule. */ - public void reject(String reason) { - Objects.requireNonNull(reason, "Rejection reason"); - if (rejection == null) { - rejection = reason; - } - } - - public boolean isRejected() { - return rejection != null; - } - - public int heightOrRejected() { - return isRejected() ? -1 : y; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PlacementWorld.java b/src/main/java/art/arcane/iris/engine/object/placement/PlacementWorld.java new file mode 100644 index 000000000..49b0b6625 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/PlacementWorld.java @@ -0,0 +1,64 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.core.modules.BlockEntities; +import art.arcane.iris.core.modules.PlatformBlockStates; +import art.arcane.iris.engine.object.prefab.TileData; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import com.volmit.placement.PlacedBlock; +import com.volmit.placement.PlacementAccess; +import com.volmit.world.BlockPosition; + +import java.util.Optional; + +/** + * A placement stage's buffered world in Iris's block states: reads see the placement's earlier writes, + * writes wait for the placement to commit. + */ +final class PlacementWorld { + private final PlacementAccess access; + private final PlatformBlockStates states; + + PlacementWorld(PlacementAccess access, PlatformBlockStates states) { + this.access = access; + this.states = states; + } + + PlatformBlockState get(int x, int y, int z) { + return states.toPlatform(access.get(x, y, z)); + } + + boolean isSolid(int x, int y, int z) { + return B.isSolid(get(x, y, z)); + } + + PlacedBlock set(int x, int y, int z, PlatformBlockState state) { + return set(x, y, z, state, null); + } + + /** {@code tile} may be null for a block without tile data. */ + PlacedBlock set(int x, int y, int z, PlatformBlockState state, TileData tile) { + PlacedBlock block = new PlacedBlock(new BlockPosition(x, y, z), states.toApi(state), + Optional.ofNullable(tile).map(BlockEntities::of)); + access.set(block); + return block; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PrepareModule.java b/src/main/java/art/arcane/iris/engine/object/placement/PrepareModule.java new file mode 100644 index 000000000..f4b2c725f --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/PrepareModule.java @@ -0,0 +1,176 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.framework.placer.HeightmapObjectPlacer; +import art.arcane.iris.engine.object.prefab.IrisAxisRotationClamp; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.engine.object.prefab.IrisObjectRotation; +import art.arcane.iris.engine.object.prefab.IrisObjectTranslate; +import art.arcane.iris.util.common.math.IrisBlockVector; +import art.arcane.iris.util.project.noise.CNG; +import art.arcane.iris.util.project.stream.ProceduralStream; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; + +/** + * Module {@code iris:prepare}: checks the slope, turns the object downhill when asked, and chooses the + * placement's rotation, translation and random height offset. + */ +public final class PrepareModule implements IrisModule { + private static final int SPIN_DIVISOR = 1000; + private static final double NORTH = 0; + private static final double EAST = 90; + private static final double SOUTH = 180; + private static final double WEST = 270; + private static final double QUARTER_TURN = 90; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:prepare", "Placement preparation", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(PrepareStages.SLOPE).produce(PrepareModule::slope); + graph.define(PrepareStages.TRANSFORMS) + .requires(PrepareStages.SLOPE) + .produce(PrepareModule::transforms); + } + + private static IrisObjectPlacement slope(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + IrisObjectPlacement config = placement.config(); + boolean checksSlope = !config.isForcePlace() && !config.getSlopeCondition().isDefault(); + if (!checksSlope && !config.isRotateTowardsSlope()) { + return config; + } + Engine engine = placement.placer().getEngine(); + if (engine == null) { + throw new IllegalStateException("Object placement requires an active Iris engine for slope settings."); + } + if (checksSlope && !config.getSlopeCondition().isValid(engine.getComplex().getSlopeStream().get(placement.x(), placement.z()))) { + context.reject("slope"); + return config; + } + return config.isRotateTowardsSlope() ? turnedDownhill(placement.object(), config, engine, placement.x(), placement.z()) : config; + } + + /** A copy of {@code config} whose Y rotation faces the lowest side of the rectangle around the object. */ + private static IrisObjectPlacement turnedDownhill(IrisObject object, IrisObjectPlacement config, Engine engine, int x, int z) { + ProceduralStream heights = engine.getComplex().getHeightStream(); + double north = heights.get(x, z + ((float) object.d) / 2); + double east = heights.get(x + ((float) object.w) / 2, z); + double south = heights.get(x, z - ((float) object.d) / 2); + double west = heights.get(x - ((float) object.w) / 2, z); + double lowest = Math.min(Math.min(north, east), Math.min(south, west)); + double downhill = lowest == north ? NORTH : lowest == east ? EAST : lowest == south ? SOUTH : WEST; + + IrisObjectRotation requested = config.getRotation(); + double turn = requested.getYAxis().getMin() + downhill; + IrisObjectRotation rotation = new IrisObjectRotation(); + rotation.setXAxis(requested.getXAxis()); + rotation.setZAxis(requested.getZAxis()); + if (turn == 0) { + rotation.setYAxis(new IrisAxisRotationClamp(false, false, 0, 0, QUARTER_TURN)); + rotation.setEnabled(requested.canRotateX() || requested.canRotateZ()); + } else { + rotation.setYAxis(new IrisAxisRotationClamp(true, false, turn, turn, QUARTER_TURN)); + rotation.setEnabled(true); + } + IrisObjectPlacement turned = config.toPlacement(config.getPlace().toArray(new String[0])); + turned.setRotation(rotation); + return turned; + } + + private static PreparedPlacement transforms(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + IrisObjectPlacement config = context.output(PrepareStages.SLOPE); + IrisObject object = placement.object(); + RNG rng = new RNG(context.random().nextLong()); + IObjectPlacer terrain = config.getHeightmap() == null ? placement.placer() + : new HeightmapObjectPlacer(rng, placement.x(), placement.requestedY(), placement.z(), config, placement.placer()); + int spinX = rng.imax() / SPIN_DIVISOR; + int spinY = rng.imax() / SPIN_DIVISOR; + int spinZ = rng.imax() / SPIN_DIVISOR; + IrisObjectRotation rotation = config.getRotation(); + IrisObjectTranslate translate = config.getTranslate(); + int centerY = object.getCenter().getBlockY(); + int rotatedCenterY = rotation.rotate(new IrisBlockVector(0, centerY, 0), spinX, spinY, spinZ).getBlockY(); + int translatedCenterY = translate.translate(new IrisBlockVector(0, centerY, 0), rotation, spinX, spinY, spinZ).getBlockY(); + ObjectSpinKernel spin = new ObjectSpinKernel(rotation, spinX, spinY, spinZ); + IrisBlockVector translation = translate.canTranslate() + ? rotation.rotate(new IrisBlockVector(translate.getX(), translate.getY(), translate.getZ()), spinX, spinY, spinZ) + : null; + int randomY = randomHeightOffset(translate.getYRandom(), rng); + int warpMargin = config.getWarp().isFlat() ? 0 : (int) Math.ceil(Math.abs(config.getWarp().getMultiplier()) / 2D); + TransformedBounds bounds = transformedBounds(object, spin, translation, config.getMode() == ObjectPlaceMode.CEILING_HANG, warpMargin); + CNG surfaceWarp = config.getWarp().isFlat() ? null : config.getSurfaceWarp(rng, object.getLoader()); + return new PreparedPlacement(config, terrain, spin, spinX, spinY, spinZ, translation, rotatedCenterY, + translatedCenterY, randomY, warpMargin, bounds, surfaceWarp); + } + + /** Within {@code range} of zero, on the side its sign gives. */ + private static int randomHeightOffset(int range, RNG rng) { + if (range > 0) { + return rng.i(0, range); + } + return range < 0 ? rng.i(range, 0) : 0; + } + + private static TransformedBounds transformedBounds(IrisObject object, ObjectSpinKernel spin, IrisBlockVector translation, + boolean ceilingHang, int margin) { + int[] sourceX = {-object.getCenter().getBlockX(), object.getW() - object.getCenter().getBlockX() - 1}; + int[] sourceY = {-object.getCenter().getBlockY(), object.getH() - object.getCenter().getBlockY() - 1}; + int[] sourceZ = {-object.getCenter().getBlockZ(), object.getD() - object.getCenter().getBlockZ() - 1}; + int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE; + int minZ = Integer.MAX_VALUE, maxZ = Integer.MIN_VALUE; + for (int x : sourceX) { + for (int y : sourceY) { + for (int z : sourceZ) { + IrisBlockVector corner = new IrisBlockVector(x, y, z); + spin.rotate(corner); + if (ceilingHang) { + corner.setY(-corner.getBlockY()); + } + if (translation != null) { + corner.add(translation); + } + int cornerX = (int) Math.round(corner.getX()); + int cornerY = (int) Math.round(corner.getY()); + int cornerZ = (int) Math.round(corner.getZ()); + minX = Math.min(minX, cornerX); + maxX = Math.max(maxX, cornerX); + minY = Math.min(minY, cornerY); + maxY = Math.max(maxY, cornerY); + minZ = Math.min(minZ, cornerZ); + maxZ = Math.max(maxZ, cornerZ); + } + } + } + return new TransformedBounds(minX - margin, maxX + margin, minY, maxY, minZ - margin, maxZ + margin); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/PreparedPlacement.java b/src/main/java/art/arcane/iris/engine/object/placement/PreparedPlacement.java new file mode 100644 index 000000000..3aeed4175 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/PreparedPlacement.java @@ -0,0 +1,146 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.math.IrisBlockVector; +import art.arcane.iris.util.project.noise.CNG; +import com.volmit.world.BlockPosition; + +/** + * What one placement chose before it is anchored: the settings it uses, the placer that answers its + * terrain questions, its random rotation and height offsets, and the bounds of the transformed object + * around its anchor. Object blocks are transformed by rotating them, flipping them for a ceiling hang and + * translating them. + */ +public final class PreparedPlacement { + private final IrisObjectPlacement config; + private final IObjectPlacer terrain; + private final ObjectSpinKernel spin; + private final int spinX; + private final int spinY; + private final int spinZ; + private final IrisBlockVector translation; + private final int rotatedCenterY; + private final int translatedCenterY; + private final int randomY; + private final int warpMargin; + private final TransformedBounds bounds; + private final CNG surfaceWarp; + + PreparedPlacement(IrisObjectPlacement config, IObjectPlacer terrain, ObjectSpinKernel spin, int spinX, int spinY, + int spinZ, IrisBlockVector translation, int rotatedCenterY, int translatedCenterY, int randomY, + int warpMargin, TransformedBounds bounds, CNG surfaceWarp) { + this.config = config; + this.terrain = terrain; + this.spin = spin; + this.spinX = spinX; + this.spinY = spinY; + this.spinZ = spinZ; + this.translation = translation; + this.rotatedCenterY = rotatedCenterY; + this.translatedCenterY = translatedCenterY; + this.randomY = randomY; + this.warpMargin = warpMargin; + this.bounds = bounds; + this.surfaceWarp = surfaceWarp; + } + + /** The settings this placement uses, which may differ from the requested ones. */ + public IrisObjectPlacement config() { + return config; + } + + /** Answers height, water and carving questions; a heightmap placement answers heights from its noise. */ + IObjectPlacer terrain() { + return terrain; + } + + ObjectPlaceMode mode() { + return config.getMode(); + } + + int spinX() { + return spinX; + } + + int spinY() { + return spinY; + } + + int spinZ() { + return spinZ; + } + + /** The rotated translation, or null when the placement does not translate. */ + IrisBlockVector translation() { + return translation; + } + + /** The height of the object's center after rotation. */ + int rotatedCenterY() { + return rotatedCenterY; + } + + /** The height of the object's center after translation. */ + int translatedCenterY() { + return translatedCenterY; + } + + /** The random height offset added once the anchor is final. */ + int randomY() { + return randomY; + } + + int warpMargin() { + return warpMargin; + } + + TransformedBounds bounds() { + return bounds; + } + + boolean isWarped() { + return surfaceWarp != null; + } + + /** Moves a world column by the surface warp, along X for {@code x} and along Z for the swapped call. */ + int warpOffset(double along, double y, double across) { + double half = config.getWarp().getMultiplier() / 2D; + return (int) surfaceWarp.fitDouble(-half, half, along, y, across); + } + + /** An object block's offset from the anchor after this placement's transforms. */ + BlockPosition transform(BlockPosition local) { + IrisBlockVector offset = new IrisBlockVector(local.x(), local.y(), local.z()); + spin.rotate(offset); + if (mode() == ObjectPlaceMode.CEILING_HANG) { + offset.setY(-offset.getBlockY()); + } + if (translation != null) { + offset.add(translation); + } + return new BlockPosition((int) Math.round(offset.getX()), (int) Math.round(offset.getY()), (int) Math.round(offset.getZ())); + } + + /** A block state turned with the object, so stairs and logs face the way the object does. */ + PlatformBlockState rotate(PlatformBlockState state) { + return spin.rotate(state); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/SnowModule.java b/src/main/java/art/arcane/iris/engine/object/placement/SnowModule.java new file mode 100644 index 000000000..40dfa641e --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/SnowModule.java @@ -0,0 +1,88 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.blocks.BlocksStages; +import art.arcane.iris.builtin.blocks.WrittenBlocks; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.builtin.snow.SnowStages; +import art.arcane.iris.builtin.stilt.StiltStages; +import art.arcane.iris.builtin.vacuum.VacuumStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.placement.PlacedBlock; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; +import com.volmit.world.BlockPosition; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Module {@code iris:snow}: a random depth of snow on top of each column of the object, deeper the more + * snow the placement asks for. Only the object's own written blocks carry snow. + */ +public final class SnowModule implements IrisModule { + private static final int LAYERS_PER_UNIT_OF_SNOW = 7; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:snow", "Snow", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(SnowStages.COVER) + .requires(BlocksStages.WRITE, BlocksStages.COMPLETE, PrepareStages.TRANSFORMS) + .softAfter(StiltStages.FILL.ref(), VacuumStages.TERRAIN.ref()) + .run(SnowModule::cover); + } + + private static void cover(PlacementStageContext context) { + double snow = context.output(PrepareStages.TRANSFORMS).config().getSnow(); + WrittenBlocks written = context.output(BlocksStages.WRITE); + if (!(snow > 0) || written.isEmpty()) { + return; + } + PlacementWorld world = new PlacementWorld(context.access(), IrisPlacement.current().states()); + RNG rng = new RNG(context.random().nextLong()); + int maxLayer = IrisObject.States.SNOW_LAYERS.length - 1; + for (BlockPosition top : columnTops(written).values()) { + int layer = rng.i(0, (int) (snow * LAYERS_PER_UNIT_OF_SNOW)); + world.set(top.x(), top.y() + 1, top.z(), IrisObject.States.SNOW_LAYERS[Math.max(Math.min(layer, maxLayer), 0)]); + } + } + + /** The highest written block of each column, columns in the order they were first written. */ + private static Map columnTops(WrittenBlocks written) { + Map tops = new LinkedHashMap<>(); + for (PlacedBlock block : written.blocks()) { + BlockPosition position = block.position(); + tops.merge(columnKey(position), position, (current, next) -> next.y() > current.y() ? next : current); + } + return tops; + } + + private static long columnKey(BlockPosition position) { + return ((long) position.x() << Integer.SIZE) | (position.z() & 0xFFFFFFFFL); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/StiltModule.java b/src/main/java/art/arcane/iris/engine/object/placement/StiltModule.java new file mode 100644 index 000000000..096920cf2 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/StiltModule.java @@ -0,0 +1,269 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.anchor.AnchorStages; +import art.arcane.iris.builtin.blocks.BlocksStages; +import art.arcane.iris.builtin.bore.BoreStages; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.builtin.stilt.StiltLayers; +import art.arcane.iris.builtin.stilt.StiltStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.object.prefab.IrisObjectShaping; +import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.object.ObjectBlock; +import com.volmit.stage.BlockStageContext; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; +import com.volmit.world.BlockPosition; + +import java.util.List; +import java.util.Set; + +/** + * Module {@code iris:stilt}: once the object is written, repeats its bottom layer down to the ground, or + * for a ceiling hang its top layer up into the ceiling. Straight stilts reach the surface, eroded ones taper + * toward the edges, organic ones stop at the first solid block with a ragged, broken tip. + */ +public final class StiltModule implements IrisModule { + private static final Set SOIL_MATERIALS = Set.of("minecraft:grass_block", "minecraft:mycelium", + "minecraft:podzol", "minecraft:dirt_path"); + private static final String SOIL_REPLACEMENT = "minecraft:dirt"; + private static final String WATERLOGGED = "waterlogged"; + private static final long HASH_X = 341873128712L; + private static final long HASH_Y = 132897987541L; + private static final long HASH_Z = 735791245321L; + private static final int HASH_BUCKETS = 1000; + private static final double SKIP_CHANCE_SCALE = 0.7; + private static final int DEFAULT_ORGANIC_MAX_SCAN = 48; + private static final int DEFAULT_ORGANIC_JITTER = 3; + private static final double DEFAULT_ORGANIC_SCRATCH = 0.55; + private static final int UNANCHORED_ORGANIC_DEPTH = 8; + private static final double ERODE_SOLID_FRACTION = 0.4; + private static final double ERODE_TAPER_EXPONENT = 1.5; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:stilt", "Stilts", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(StiltStages.LAYERS) + .requires(PrepareStages.TRANSFORMS) + // Ordered after boring only so it shares the block pass that writes the object. + .softAfter(BoreStages.CLEAR.ref()) + .accumulate(StiltLayers::new, StiltModule::collectLayer); + graph.define(StiltStages.FILL) + .requires(StiltStages.LAYERS, AnchorStages.FINAL, BlocksStages.COMPLETE) + .run(StiltModule::fill); + } + + private static void collectLayer(BlockStageContext context, StiltLayers layers) { + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + if (prepared.mode().stilt() == StiltShape.NONE) { + return; + } + ObjectBlock block = context.block(); + if (!IrisObjectShaping.shouldStilt(IrisPlacement.current().states().toPlatform(block.state()))) { + return; + } + layers.include(new ObjectBlock(prepared.transform(block.position()), block.state(), block.blockEntity())); + } + + private static void fill(PlacementStageContext context) { + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + StiltShape shape = prepared.mode().stilt(); + StiltLayers layers = context.output(StiltStages.LAYERS); + if (shape == StiltShape.NONE || layers.isEmpty()) { + return; + } + StiltColumns columns = new StiltColumns(context, prepared, layers); + List layer = shape == StiltShape.CEILING ? layers.top() : layers.bottom(); + for (ObjectBlock block : layer) { + columns.grow(block); + } + } + + /** One placement's stilt, grown column by column under (or above) the blocks of its repeated layer. */ + private static final class StiltColumns { + private final IrisPlacement placement; + private final PreparedPlacement prepared; + private final IrisObjectPlacement config; + private final IrisStiltSettings settings; + private final StiltShape shape; + private final PlacementWorld world; + private final RNG rng; + private final int anchorY; + private final int layerY; + private final ErodeShape erode; + + private StiltColumns(PlacementStageContext context, PreparedPlacement prepared, StiltLayers layers) { + this.placement = IrisPlacement.current(); + this.prepared = prepared; + this.config = prepared.config(); + this.settings = config.getStiltSettings(); + this.shape = prepared.mode().stilt(); + this.world = new PlacementWorld(context.access(), placement.states()); + this.rng = new RNG(context.random().nextLong()); + this.anchorY = context.output(AnchorStages.FINAL).y(); + this.layerY = shape == StiltShape.CEILING ? layers.topY() : layers.bottomY(); + this.erode = shape == StiltShape.ERODE ? ErodeShape.of(layers.bottom()) : null; + } + + private void grow(ObjectBlock block) { + BlockPosition offset = block.position(); + PlatformBlockState state = stiltState(block, offset); + if (state == null || !state.isOccluding()) { + return; + } + int x = placement.x() + offset.x(); + int z = placement.z() + offset.z(); + if (prepared.isWarped()) { + x += prepared.warpOffset(offset.x() + placement.x(), offset.y() + anchorY, offset.z() + placement.z()); + z += prepared.warpOffset(offset.z() + placement.z(), offset.y() + anchorY, offset.x() + placement.x()); + } + switch (shape) { + case ORGANIC -> growOrganic(state, x, z, -1); + case CEILING -> growOrganic(state, x, z, 1); + case STRAIGHT, ERODE -> growToSurface(state, offset, x, z); + case NONE -> { + } + } + } + + /** The block the stilt repeats: the palette's when the settings have one, soil turned to dirt, edited and turned with the object. */ + private PlatformBlockState stiltState(ObjectBlock block, BlockPosition offset) { + PlatformBlockState state = placement.states().toPlatform(block.state()); + if (settings != null && settings.getPalette() != null) { + state = settings.getPalette().get(rng, placement.x(), anchorY, placement.z(), placement.data()); + } else if (SOIL_MATERIALS.contains(IrisObjectShaping.materialKey(state))) { + state = B.getState(SOIL_REPLACEMENT); + } + state = prepared.rotate(state); + if (config.getEdit().isEmpty() || state == null) { + return state; + } + return ObjectEdits.apply(config, state, null, rng, offset.x() + placement.x(), offset.y() + anchorY, + offset.z() + placement.z(), placement.data()).data(); + } + + private void growToSurface(PlatformBlockState state, BlockPosition offset, int x, int z) { + int top = layerY + anchorY; + int highest = prepared.terrain().getHighest(x, z, placement.object().getLoader(), true); + if (IrisProceduralBlocks.hasProperty(state, WATERLOGGED) + && BlocksModule.shouldWaterlog(world, config, placement.requestedY(), x, highest, z)) { + state = state.withProperty(WATERLOGGED, "true"); + } + int lowerBound = highest - 1; + if (settings != null) { + lowerBound -= settings.getOverStilt() - rng.i(0, settings.getYRand()); + if (settings.getYMax() != 0) { + lowerBound -= Math.min(settings.getYMax() - (top - highest), 0); + } + } + if (erode != null) { + lowerBound = top - erode.depth(offset, top - lowerBound); + } + for (int y = top; y > lowerBound; y--) { + if (B.isFluid(world.get(x, y, z))) { + return; + } + if (erode != null && erode.breaksAt(x, y, z, top - y, top - lowerBound)) { + continue; + } + if (B.isVineBlock(state)) { + state = BlocksModule.attachVineFaces(world, state, x, y, z); + } + world.set(x, y, z, state); + } + } + + /** Grows from the layer toward the first solid block in {@code direction}, -1 down or 1 up. */ + private void growOrganic(PlatformBlockState state, int x, int z, int direction) { + int maxScan = settings != null ? Math.max(1, settings.getOrganicMaxScan()) : DEFAULT_ORGANIC_MAX_SCAN; + int jitterMax = settings != null ? Math.max(0, settings.getOrganicJitter()) : DEFAULT_ORGANIC_JITTER; + double scratch = settings != null ? Math.max(0, Math.min(1, settings.getOrganicScratch())) : DEFAULT_ORGANIC_SCRATCH; + long columnHash = ((long) x * HASH_X) ^ ((long) z * HASH_Y); + int jitter = jitterMax > 0 ? (int) (Math.abs(columnHash) % (jitterMax + 1)) : 0; + int start = layerY + anchorY; + int scanned = 0; + int solidY = start + direction; + while (scanned < maxScan && !world.isSolid(x, solidY, z)) { + solidY += direction; + scanned++; + } + int end = (scanned < maxScan ? solidY - direction : start + direction * Math.min(maxScan, UNANCHORED_ORGANIC_DEPTH)) + - direction * jitter; + int length = (end - start) * direction; + for (int step = 0; step <= length; step++) { + int y = start + step * direction; + if (scratch > 0 && length > 0 && isScratched(x, y, z, (double) step / length, scratch)) { + continue; + } + world.set(x, y, z, state); + } + } + + /** Whether the broken tip skips this block: more often the deeper it lies in the scratched fraction. */ + private static boolean isScratched(int x, int y, int z, double depthRatio, double scratch) { + if (depthRatio <= 1.0 - scratch) { + return false; + } + double skipChance = (depthRatio - (1.0 - scratch)) / scratch; + return hashFraction(x, y, z) < skipChance * SKIP_CHANCE_SCALE; + } + } + + /** An eroded stilt: deepest under the layer's centroid, shallower toward its edge, broken up at depth. */ + private record ErodeShape(double centroidX, double centroidZ, double maxDistance) { + static ErodeShape of(List bottom) { + double centroidX = bottom.stream().mapToInt(block -> block.position().x()).average().orElse(0); + double centroidZ = bottom.stream().mapToInt(block -> block.position().z()).average().orElse(0); + double maxDistance = bottom.stream() + .mapToDouble(block -> Math.hypot(block.position().x() - centroidX, block.position().z() - centroidZ)) + .max().orElse(1); + return new ErodeShape(centroidX, centroidZ, Math.max(1, maxDistance)); + } + + int depth(BlockPosition offset, int fullDepth) { + double distance = Math.min(1.0, Math.hypot(offset.x() - centroidX, offset.z() - centroidZ) / maxDistance); + return (int) (fullDepth * Math.pow(1.0 - distance, ERODE_TAPER_EXPONENT)); + } + + boolean breaksAt(int x, int y, int z, int depth, int fullDepth) { + double depthRatio = fullDepth > 0 ? (double) depth / fullDepth : 0; + if (depthRatio <= ERODE_SOLID_FRACTION) { + return false; + } + double skipChance = (depthRatio - ERODE_SOLID_FRACTION) / (1.0 - ERODE_SOLID_FRACTION); + return hashFraction(x, y, z) < skipChance * SKIP_CHANCE_SCALE; + } + } + + private static double hashFraction(int x, int y, int z) { + long hash = ((long) x * HASH_X) ^ ((long) y * HASH_Y) ^ ((long) z * HASH_Z); + return (Math.abs(hash) % HASH_BUCKETS) / (double) HASH_BUCKETS; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/StiltShape.java b/src/main/java/art/arcane/iris/engine/object/placement/StiltShape.java new file mode 100644 index 000000000..121a71cb0 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/StiltShape.java @@ -0,0 +1,32 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +/** What a placement mode grows between the object and the ground or ceiling. */ +enum StiltShape { + NONE, + /** Repeats the bottom layer straight down to the surface. */ + STRAIGHT, + /** Like {@link #STRAIGHT}, tapering toward the edges and broken up at depth. */ + ERODE, + /** Repeats the bottom layer down to the first solid block, each column a little different. */ + ORGANIC, + /** Hangs the flipped object from a ceiling and grows its top layer up into it. */ + CEILING +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/TransformedBounds.java b/src/main/java/art/arcane/iris/engine/object/placement/TransformedBounds.java new file mode 100644 index 000000000..0b9d659e5 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/TransformedBounds.java @@ -0,0 +1,23 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +/** The bounds of a transformed object around its anchor, inclusive, widened by the surface warp along X and Z. */ +record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java b/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java new file mode 100644 index 000000000..929060a14 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java @@ -0,0 +1,173 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.blocks.BlocksStages; +import art.arcane.iris.builtin.blocks.WrittenBlocks; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.builtin.vacuum.VacuumStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.IrisComplex; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import art.arcane.iris.util.project.noise.SimplexNoise; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; + +/** + * Module {@code iris:vacuum}: bends the terrain around an object of a vacuum mode so it meets the object's + * base, raising columns with rock and carving them down, fading out across the bend's radius. + */ +public final class VacuumModule implements IrisModule { + private static final long WAVE_SEED = 7392113L; + private static final int DEFAULT_ORGANIC_JITTER = 4; + private static final long HASH_X = 341873128712L; + private static final long HASH_Z = 132897987541L; + private static final int HASH_BUCKETS = 1000; + private static final double HALF = 0.5; + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:vacuum", "Vacuum", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(VacuumStages.TERRAIN) + .requires(BlocksStages.WRITE, BlocksStages.COMPLETE, PrepareStages.TRANSFORMS) + .reach(IrisObjectVacuum.MAX_RADIUS_BLOCKS) + .run(VacuumModule::bendTerrain); + } + + private static void bendTerrain(PlacementStageContext context) { + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + WrittenBlocks written = context.output(BlocksStages.WRITE); + Engine engine = prepared.terrain().getEngine(); + if (!prepared.mode().isVacuum() || written.isEmpty() || engine == null) { + return; + } + int baseY = written.blocks().stream().mapToInt(block -> block.position().y()).min().orElseThrow(); + int topY = written.blocks().stream().mapToInt(block -> block.position().y()).max().orElseThrow(); + new Bend(context, prepared, engine).apply(baseY, topY); + } + + /** One placement's terrain bend over the columns within its radius of the object's footprint. */ + private static final class Bend { + private final IrisPlacement placement; + private final PreparedPlacement prepared; + private final PlacementWorld world; + private final IrisComplex complex; + private final int radius; + private final int step; + private final double falloff; + private final int jitter; + private final double waveAmplitude; + private final double waveScale; + private final SimplexNoise waves; + private final int worldMin; + private final int worldMax; + + private Bend(PlacementStageContext context, PreparedPlacement prepared, Engine engine) { + ObjectPlaceMode mode = prepared.mode(); + this.placement = IrisPlacement.current(); + this.prepared = prepared; + this.world = new PlacementWorld(context.access(), placement.states()); + this.complex = engine.getComplex(); + IrisVacuumSettings settings = prepared.config().getVacuumSettings(); + this.radius = IrisObjectVacuum.resolveRadius(mode, settings); + this.step = IrisObjectVacuum.resolveStep(mode); + this.falloff = IrisObjectVacuum.resolveFalloff(settings); + this.jitter = settings != null ? Math.max(0, settings.getOrganicJitter()) : DEFAULT_ORGANIC_JITTER; + this.waveAmplitude = IrisObjectVacuum.resolveWaveAmplitude(settings); + this.waveScale = IrisObjectVacuum.resolveWaveScale(settings); + this.waves = mode == ObjectPlaceMode.VACUUM_WAVY && waveAmplitude > 0 ? new SimplexNoise(WAVE_SEED) : null; + this.worldMin = engine.getMinHeight(); + this.worldMax = worldMin + engine.getHeight() - 1; + } + + private void apply(int baseY, int topY) { + TransformedBounds bounds = prepared.bounds(); + for (int dx = bounds.minX() - radius; dx <= bounds.maxX() + radius; dx += step) { + for (int dz = bounds.minZ() - radius; dz <= bounds.maxZ() + radius; dz += step) { + bendColumn(bounds, dx, dz, baseY - 1, topY); + } + } + } + + private void bendColumn(TransformedBounds bounds, int dx, int dz, int meetY, int topY) { + int x = placement.x() + dx; + int z = placement.z() + dz; + double effectiveRadius = effectiveRadius(x, z); + int originalY = prepared.terrain().getHighest(x, z, placement.object().getLoader(), true); + int targetY = IrisObjectVacuum.columnTargetY(dx, dz, bounds.minX(), bounds.maxX(), bounds.minZ(), bounds.maxZ(), + effectiveRadius, falloff, originalY, meetY) + waveOffset(bounds, dx, dz, x, z, effectiveRadius); + if (targetY == originalY) { + return; + } + targetY = Math.max(worldMin + 1, Math.min(worldMax, targetY)); + if (targetY > originalY) { + raise(x, z, originalY, targetY); + } else if (targetY < originalY) { + boolean inside = IrisObjectVacuum.outset(dx, bounds.minX(), bounds.maxX()) == 0 + && IrisObjectVacuum.outset(dz, bounds.minZ(), bounds.maxZ()) == 0; + carve(x, z, originalY, IrisObjectVacuum.carveFloorY(targetY, topY, inside)); + } + } + + /** The radius, perturbed per column for the organic mode. */ + private double effectiveRadius(int x, int z) { + if (prepared.mode() != ObjectPlaceMode.VACUUM_ORGANIC || jitter <= 0) { + return radius; + } + long hash = ((long) x * HASH_X) ^ ((long) z * HASH_Z); + double noise = ((Math.abs(hash) % HASH_BUCKETS) / (double) HASH_BUCKETS) - HALF; + return Math.max(1.0, radius + (noise * 2.0 * jitter)); + } + + private int waveOffset(TransformedBounds bounds, int dx, int dz, int x, int z, double effectiveRadius) { + if (waves == null) { + return 0; + } + int outX = IrisObjectVacuum.outset(dx, bounds.minX(), bounds.maxX()); + int outZ = IrisObjectVacuum.outset(dz, bounds.minZ(), bounds.maxZ()); + double distance = Math.sqrt((double) (outX * outX) + (double) (outZ * outZ)); + return IrisObjectVacuum.waveOffset(distance, effectiveRadius, waves.noiseSigned(x * waveScale, z * waveScale), waveAmplitude); + } + + private void raise(int x, int z, int fromY, int toY) { + PlatformBlockState fill = complex != null ? complex.getRockStream().get(x, z) : null; + if (B.isAir(fill)) { + fill = IrisObject.States.STONE; + } + for (int y = fromY + 1; y <= toY; y++) { + world.set(x, y, z, fill); + } + } + + private void carve(int x, int z, int fromY, int floorY) { + for (int y = fromY; y >= floorY; y--) { + world.set(x, y, z, IrisObject.States.AIR); + } + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/ValidateModule.java b/src/main/java/art/arcane/iris/engine/object/placement/ValidateModule.java new file mode 100644 index 000000000..5e4f0ef66 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/ValidateModule.java @@ -0,0 +1,254 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.builtin.anchor.AnchorStages; +import art.arcane.iris.builtin.prepare.PrepareStages; +import art.arcane.iris.builtin.validate.ValidateStages; +import art.arcane.iris.core.modules.IrisPlacement; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.framework.NativeStructureVolume; +import art.arcane.iris.engine.framework.PlacedObject; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.engine.object.terrain.carving.CarvingMode; +import art.arcane.iris.spi.IrisLogging; +import art.arcane.volmlib.util.collection.KList; +import com.volmit.IrisModule; +import com.volmit.ModuleInfo; +import com.volmit.block.BlockState; +import com.volmit.object.ObjectBlock; +import com.volmit.stage.PlacementStageContext; +import com.volmit.stage.StageGraph; +import com.volmit.world.BlockPosition; + +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Module {@code iris:validate}: the checks that reject a placement before anything is written. Forced + * placements skip all but the native structure check, which only structure pieces skip. + */ +public final class ValidateModule implements IrisModule { + private static final long IMPLAUSIBLE_BEDROCK_WARN_THROTTLE_MS = 5000L; + private static final int BEDROCK_ROW = 1; + private static final Set AIR_MATERIALS = Set.of("minecraft:air", "minecraft:cave_air"); + private static final ConcurrentHashMap IMPLAUSIBLE_BEDROCK_WARNS = new ConcurrentHashMap<>(); + + @Override + public ModuleInfo info() { + return ModuleInfo.of("iris:validate", "Placement checks", PlacementModules.VERSION); + } + + @Override + public void install(StageGraph graph) { + graph.define(ValidateStages.SURFACE) + .requires(AnchorStages.HEIGHT) + .run(ValidateModule::checkSurface); + graph.define(ValidateStages.LIMITS) + .requires(ValidateStages.SURFACE, AnchorStages.HEIGHT) + .run(ValidateModule::checkLimits); + graph.define(ValidateStages.STRUCTURES) + .requires(ValidateStages.LIMITS, AnchorStages.HEIGHT) + .run(ValidateModule::checkNativeStructures); + graph.define(ValidateStages.COLLISIONS) + .requires(ValidateStages.STRUCTURES, AnchorStages.HEIGHT) + .run(ValidateModule::checkCollisions); + } + + private static void checkSurface(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + if (config.isForcePlace() || config.isFromBottom() || prepared.mode() == ObjectPlaceMode.FLOATING + || prepared.mode() == ObjectPlaceMode.STRUCTURE_PIECE) { + return; + } + int y = context.output(AnchorStages.HEIGHT).y(); + boolean sampled = placement.requestedY() < 0; + if (sampled && config.getCarvingSupport().supportsSurface() && isOnBedrock(prepared, y)) { + warnImplausibleBedrockPlacement(placement, config, y); + context.reject("bedrock-anchor"); + return; + } + boolean surfaceAnchored = sampled ? config.getCarvingSupport().supportsSurface() + : config.getCarvingSupport() == CarvingMode.SURFACE_ONLY; + if (surfaceAnchored && !config.isUnderwater() && !config.isOnwater() && config.isRequireSurfaceSupport() + && lacksSurfaceSupport(placement, prepared)) { + context.reject("surface-support"); + } + } + + private static boolean isOnBedrock(PreparedPlacement prepared, int y) { + Engine engine = prepared.terrain().getEngine(); + return engine != null && engine.getDimension().isBedrock() && y <= BEDROCK_ROW; + } + + private static boolean lacksSurfaceSupport(IrisPlacement placement, PreparedPlacement prepared) { + IrisObjectPlacement config = prepared.config(); + IrisObject object = placement.object(); + return IrisSurfaceSupport.isUnsupported(placement.placer(), object.getLoader(), placement.x(), placement.z(), + config.getTranslate(), config.getRotation(), prepared.spinX(), prepared.spinY(), prepared.spinZ(), + object.getSurfaceSupportOffsets(), config.getSurfaceSupportBuffer(), config.getSurfaceSupportDepth()); + } + + private static void checkLimits(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + if (config.isForcePlace() || prepared.mode() == ObjectPlaceMode.STRUCTURE_PIECE) { + return; + } + int y = context.output(AnchorStages.HEIGHT).y(); + int rotated = prepared.rotatedCenterY(); + int translated = prepared.translatedCenterY(); + if (placement.requestedY() < 0 && prepared.mode() != ObjectPlaceMode.FLOATING && !config.isUnderwater() + && !config.isOnwater() && prepared.terrain().isUnderwater(placement.x(), placement.z())) { + context.reject("underwater-anchor"); + } else if (placement.cave() != null + && Math.max(0, placement.object().h + prepared.randomY() + translated) + 1 >= placement.cave().getHeight()) { + context.reject("cave-clearance"); + } else if (config.isUnderwater() && y + rotated + translated >= prepared.terrain().getFluidHeight()) { + context.reject("fluid-height"); + } else if (!config.getClamp().canPlace(y + rotated + translated, y - rotated + translated)) { + context.reject("height-clamp"); + } + } + + private static void checkNativeStructures(PlacementStageContext context) { + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + if (prepared.mode() == ObjectPlaceMode.STRUCTURE_PIECE) { + return; + } + int y = context.output(AnchorStages.HEIGHT).y() + prepared.randomY(); + if (meetsNativeStructure(context, IrisPlacement.current(), prepared, y)) { + context.reject("native-structure"); + } + } + + private static boolean meetsNativeStructure(PlacementStageContext context, IrisPlacement placement, + PreparedPlacement prepared, int y) { + Engine engine = prepared.terrain().getEngine(); + if (engine == null) { + return false; + } + int x = placement.x(); + int z = placement.z(); + int margin = nativeStructureMargin(placement.object(), prepared); + KList volumes = engine.getNativeStructureVolumes(x - margin, z - margin, x + margin, z + margin); + if (volumes == null || volumes.isEmpty()) { + return false; + } + boolean painted = WorldVolume.isPainted(placement, prepared); + int worldY = y + engine.getMinHeight(); + int envelopeMinY = painted ? Integer.MIN_VALUE : worldY - margin; + int envelopeMaxY = painted ? Integer.MAX_VALUE : worldY + margin; + boolean envelopeMeetsPiece = volumes.stream() + .anyMatch(volume -> volume.intersects(x - margin, envelopeMinY, z - margin, x + margin, envelopeMaxY, z + margin)); + if (!envelopeMeetsPiece) { + return false; + } + for (ObjectBlock block : context.request().object().blocks()) { + if (isAir(block.state())) { + continue; + } + BlockPosition offset = prepared.transform(block.position()); + int blockX = x + offset.x(); + int blockZ = z + offset.z(); + int blockY = painted + ? offset.y() + Math.floorDiv(placement.object().h, 2) + + prepared.terrain().getHighest(blockX, blockZ, placement.object().getLoader(), prepared.config().isUnderwater()) + : y + offset.y(); + int worldBlockY = blockY + engine.getMinHeight(); + for (NativeStructureVolume volume : volumes) { + if (volume.containsWithin(blockX, worldBlockY, blockZ, prepared.warpMargin())) { + return true; + } + } + } + return false; + } + + /** How far around the anchor any block of the transformed object can reach. */ + private static int nativeStructureMargin(IrisObject object, PreparedPlacement prepared) { + int margin = (Math.max(object.getW(), Math.max(object.getH(), object.getD())) / 2) + 1 + prepared.warpMargin(); + if (prepared.translation() == null) { + return margin; + } + return margin + Math.max(Math.abs(prepared.translation().getBlockX()), + Math.max(Math.abs(prepared.translation().getBlockY()), Math.abs(prepared.translation().getBlockZ()))); + } + + private static boolean isAir(BlockState state) { + return AIR_MATERIALS.contains(state.material().toString()); + } + + private static void checkCollisions(PlacementStageContext context) { + IrisPlacement placement = IrisPlacement.current(); + PreparedPlacement prepared = context.output(PrepareStages.TRANSFORMS); + IrisObjectPlacement config = prepared.config(); + if (config.isForcePlace() || prepared.mode() == ObjectPlaceMode.STRUCTURE_PIECE + || (config.getAllowedCollisions().isEmpty() && config.getForbiddenCollisions().isEmpty())) { + return; + } + Engine engine = placement.data().getEngine(); + if (engine == null) { + throw new IllegalStateException("Object placement requires active Iris data for collision settings."); + } + WorldVolume volume = WorldVolume.of(placement, prepared, context.output(AnchorStages.HEIGHT).y() + prepared.randomY()); + if (collidesWithForbiddenObject(engine, config, volume)) { + context.reject("object-collision"); + } + } + + private static boolean collidesWithForbiddenObject(Engine engine, IrisObjectPlacement config, WorldVolume volume) { + for (int x = volume.minX(); x <= volume.maxX(); x++) { + for (int y = volume.minY(); y <= volume.maxY(); y++) { + for (int z = volume.minZ(); z <= volume.maxZ(); z++) { + PlacedObject placed = engine.getObjectPlacement(x, y, z); + if (placed == null || placed.getObject() == null) { + continue; + } + String key = placed.getObject().getLoadKey(); + if (key != null && config.getForbiddenCollisions().contains(key) && !config.getAllowedCollisions().contains(key)) { + return true; + } + } + } + } + return false; + } + + private static void warnImplausibleBedrockPlacement(IrisPlacement placement, IrisObjectPlacement config, int y) { + String key = placement.object().getLoadKey(); + String fingerprint = (key == null ? "" : key) + "|" + config.getMode(); + long now = System.currentTimeMillis(); + Long last = IMPLAUSIBLE_BEDROCK_WARNS.get(fingerprint); + if (last != null && now - last < IMPLAUSIBLE_BEDROCK_WARN_THROTTLE_MS) { + return; + } + IMPLAUSIBLE_BEDROCK_WARNS.put(fingerprint, now); + IrisLogging.warn("Implausible object placement rejected: " + + (key == null ? "" : key) + + " resolved anchorY=" + y + " at (" + placement.x() + "," + placement.z() + ") mode=" + config.getMode() + + " carving=" + config.getCarvingSupport() + + ". Surface-anchored placement should never land on the bedrock row. " + + "Height sampling returned a bogus value — not configured for floor placement " + + "(forcePlace=false, fromBottom=false, mode!=FLOATING). Skipping to protect bedrock."); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/placement/WorldVolume.java b/src/main/java/art/arcane/iris/engine/object/placement/WorldVolume.java new file mode 100644 index 000000000..fca0d968c --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/placement/WorldVolume.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.object.placement; + +import art.arcane.iris.core.modules.IrisPlacement; + +/** + * The world blocks a placed object occupies, inclusive: its transformed bounds around the anchor. A painted + * object follows the surface column by column, so its volume spans every surface height under it. + */ +record WorldVolume(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { + static WorldVolume of(IrisPlacement placement, PreparedPlacement prepared, int anchorY) { + TransformedBounds bounds = prepared.bounds(); + int minX = placement.x() + bounds.minX(); + int maxX = placement.x() + bounds.maxX(); + int minZ = placement.z() + bounds.minZ(); + int maxZ = placement.z() + bounds.maxZ(); + if (!isPainted(placement, prepared)) { + return new WorldVolume(minX, maxX, anchorY + bounds.minY(), anchorY + bounds.maxY(), minZ, maxZ); + } + int lowestSurface = Integer.MAX_VALUE; + int highestSurface = Integer.MIN_VALUE; + for (int x = minX; x <= maxX; x++) { + for (int z = minZ; z <= maxZ; z++) { + int surface = prepared.terrain().getHighest(x, z, placement.object().getLoader(), prepared.config().isUnderwater()); + lowestSurface = Math.min(lowestSurface, surface); + highestSurface = Math.max(highestSurface, surface); + } + } + int paintOffset = Math.floorDiv(placement.object().h, 2); + return new WorldVolume(minX, maxX, lowestSurface + bounds.minY() + paintOffset, + highestSurface + bounds.maxY() + paintOffset, minZ, maxZ); + } + + /** Whether each block of the placement follows the surface of its own column. */ + static boolean isPainted(IrisPlacement placement, PreparedPlacement prepared) { + return placement.requestedY() < 0 && prepared.mode() == ObjectPlaceMode.PAINT; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/prefab/IrisObject.java b/src/main/java/art/arcane/iris/engine/object/prefab/IrisObject.java index a4c6102b4..cb6a2e1e7 100644 --- a/src/main/java/art/arcane/iris/engine/object/prefab/IrisObject.java +++ b/src/main/java/art/arcane/iris/engine/object/prefab/IrisObject.java @@ -21,10 +21,11 @@ package art.arcane.iris.engine.object.prefab; import art.arcane.iris.engine.object.placement.FloatingObjectFootprint; import art.arcane.iris.engine.object.placement.IObjectPlacer; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; -import art.arcane.iris.engine.object.placement.IrisObjectPlacementRunner; import art.arcane.iris.engine.object.terrain.carving.CarveResult; import art.arcane.iris.engine.object.value.IrisPosition; import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.modules.ModuleObjectPlacement; +import art.arcane.iris.core.modules.ObjectGeometry; import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.engine.data.cache.AtomicCache; import art.arcane.iris.platform.bukkit.BukkitBlockState; @@ -40,6 +41,7 @@ import art.arcane.iris.util.common.plugin.VolmitSender; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.BlockPosition; import art.arcane.volmlib.util.math.RNG; +import com.volmit.object.GeneratedObject; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -64,7 +66,7 @@ import java.util.function.BiConsumer; *

* The heavy behaviour lives in package-private collaborators that read this state directly: * {@link IrisObjectIO} (binary persistence), {@link IrisObjectShaping} (boring, shrinkwrap, block classification), - * {@link IrisObjectTransforms} (rotation, scaling, interpolated upscaling) and {@link IrisObjectPlacementRunner} + * {@link IrisObjectTransforms} (rotation, scaling, interpolated upscaling) and {@link ModuleObjectPlacement} * (world placement). */ @Accessors(chain = true) @@ -87,6 +89,7 @@ public class IrisObject extends IrisRegistrant { protected transient AtomicCache aabb = new AtomicCache<>(); transient final AtomicCache> surfaceSupportOffsets = new AtomicCache<>(); public transient final AtomicCache floatingFootprint = new AtomicCache<>(); + private transient final AtomicCache geometry = new AtomicCache<>(); @Getter public VectorMap blocks; @Getter @@ -220,8 +223,7 @@ public class IrisObject extends IrisRegistrant { blocks.put(v, block); } - surfaceSupportOffsets.reset(); - floatingFootprint.reset(); + forgetDerivedShapes(); } public void setUnsignedTile(int x, int y, int z, TileData tile) { @@ -232,6 +234,8 @@ public class IrisObject extends IrisRegistrant { } else { states.put(v, tile); } + + forgetDerivedShapes(); } public void setUnsigned(int x, int y, int z, Block block, boolean legacy) { @@ -250,8 +254,7 @@ public class IrisObject extends IrisRegistrant { } } - surfaceSupportOffsets.reset(); - floatingFootprint.reset(); + forgetDerivedShapes(); } public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { @@ -270,8 +273,21 @@ public class IrisObject extends IrisRegistrant { return place(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), placer, config, rng, rdata); } + /** The height the object was placed at, or -1 when the placement rejected it. */ public int place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, BiConsumer listener, CarveResult c, IrisData rdata) { - return new IrisObjectPlacementRunner(this).place(x, yv, z, oplacer, config, rng, listener, c, rdata); + return ModuleObjectPlacement.place(this, x, yv, z, oplacer, config, rng, listener, c, rdata).heightOrRejected(); + } + + /** This object as IrisApi geometry, read once until its blocks change. */ + public GeneratedObject getGeometry() { + return geometry.aquireOrThrow(() -> ObjectGeometry.of(this)); + } + + /** Drops what is computed from the blocks, after they change. */ + void forgetDerivedShapes() { + surfaceSupportOffsets.reset(); + floatingFootprint.reset(); + geometry.reset(); } public KList getSurfaceSupportOffsets() { diff --git a/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectIO.java b/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectIO.java index 338fcc6c1..1cda4d051 100644 --- a/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectIO.java +++ b/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectIO.java @@ -93,8 +93,7 @@ public final class IrisObjectIO { } static void readLegacy(IrisObject self, InputStream in) throws IOException { - self.surfaceSupportOffsets.reset(); - self.floatingFootprint.reset(); + self.forgetDerivedShapes(); DataInputStream din = new DataInputStream(in); self.w = din.readInt(); self.h = din.readInt(); @@ -126,8 +125,7 @@ public final class IrisObjectIO { } static void read(IrisObject self, InputStream in) throws Throwable { - self.surfaceSupportOffsets.reset(); - self.floatingFootprint.reset(); + self.forgetDerivedShapes(); DataInputStream din = new DataInputStream(in); self.w = din.readInt(); self.h = din.readInt(); diff --git a/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectShaping.java b/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectShaping.java index 822a54801..f348832ad 100644 --- a/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectShaping.java +++ b/src/main/java/art/arcane/iris/engine/object/prefab/IrisObjectShaping.java @@ -175,6 +175,7 @@ public final class IrisObjectShaping { try { if (!self.smartBored) { bore.forEach((v, s) -> self.blocks.computeIfAbsent(v, (vv) -> s)); + self.forgetDerivedShapes(); self.smartBored = true; } } finally { @@ -259,8 +260,7 @@ public final class IrisObjectShaping { self.shrinkOffset = offset; self.blocks = b; self.states = s; - self.surfaceSupportOffsets.reset(); - self.floatingFootprint.reset(); + self.forgetDerivedShapes(); } public static void clean(IrisObject self) { @@ -272,8 +272,7 @@ public final class IrisObjectShaping { self.blocks = d; self.states = dx; - self.surfaceSupportOffsets.reset(); - self.floatingFootprint.reset(); + self.forgetDerivedShapes(); } public static boolean shouldStilt(PlatformBlockState state) {