Merge branch 'wave3b/1'

# Conflicts:
#	README.md
#	builtin-modules.txt
#	src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java
This commit is contained in:
piexel committed 2026-10-15 07:08:13 +02:00
commit f7e8b74745
35 files changed
+1190 -570

No files matched your search

+20 -10
View File
@@ -6,7 +6,7 @@ direct dependencies on Iris internals.
Ported features are IrisApi modules that every pack loads before its own: object placement
(`iris:prepare`, `iris:anchor`, `iris:validate`, `iris:bore`, `iris:blocks`, `iris:stilt`,
`iris:vacuum`, `iris:snow`), the mantle, and chunk generation. Every mantle stage is a pass of Iris's
`iris:vacuum`, `iris:snow`, shipped in the built-ins jar), the mantle, and chunk generation. Every mantle stage is a pass of Iris's
mantle of its own, in the stage graph's order: `iris:carve/caves`, `iris:objects/place`,
`iris:floating/objects`, `iris:structure/place`, so a pack's mantle stage can order itself after any of
them. Chunk generation then runs, in this order: `iris:biome`, `iris:terrain`, `iris:carve` (cutting the
@@ -68,8 +68,10 @@ palette, ore checks, clump shapes per world seed) lives in the module's own code
Settings that live inside a class of Iris's own, such as an object placement's clamp, stilt, vacuum and edit settings, its slope condition
or a procedural coral, are module-owned classes too (`art.arcane.iris.builtin.validate`,
`.stilt`, `.vacuum`, `.blocks`, `.prepare`, `.carve`, `.floating`, `.objects.*`). The module registers each with
`registry.registerHeldType(...)` so studio describes it from the module's own annotations; packs write the same JSON as before. Behaviour
`.stilt`, `.vacuum`, `.blocks`, `.prepare`, `.carve`, `.floating`, `.objects.*`). A module compiled into Iris registers each with
`registry.registerHeldType(...)` so studio describes it from the module's own annotations; only such a module may, so the classes
Iris's `IrisObjectPlacement` holds are described by the host module `iris:placement-settings` (the placement stages ship in the
built-ins jar). Packs write the same JSON as before. Behaviour
that needs Iris (noise built from the styles, blocks resolved through the pack, baked object variants) lives in `Resolved*` classes beside the
worker (`ResolvedReplace`, `ResolvedCaveProfile`, `ResolvedFloatingChild`, `ResolvedProceduralPlacement`).
@@ -137,12 +139,14 @@ naming the class and what it uses. A VolmLib class that Iris's Bukkit jar strips
`core/volmlib-left-out-of-bukkit-jar.txt`, which its shadowJar reads too) is on that classpath but missing on a
server, so the check treats it as missing and fails the task naming it. `check` runs the task.
The jar holds `iris:post`, `iris:perfection`, `iris:matter`, `iris:loot` and `iris:spawn`. They are written against IrisApi and
`art.arcane.iris.builtin` alone: the chunk's `BlockState` hunk, the block registry's traits and `canPlaceOn`, the terrain
sampler (heights around the chunk, slope, fluid height, where the upper dimension begins) and the mantle's planned blocks;
the loot and spawn services, which have no chunk to ask, ask `LiveWorld` (below). Without the jar a pack's world has no
loot, block drops, entity spawns or ambient effects, and its biomes' `loot`, `blockDrops`, `entitySpawners` and `effects` are
not read. Iris no longer compiles them in (`IrisModuleHost.generationModules()`), so a pack gets them by putting
The jar holds `iris:post`, `iris:perfection`, `iris:matter`, `iris:loot` and `iris:spawn`, and the object placement stages
`iris:prepare`, `iris:anchor`, `iris:validate`, `iris:bore`, `iris:blocks`, `iris:stilt`, `iris:vacuum` and `iris:snow`. They are
written against IrisApi and `art.arcane.iris.builtin` alone: the chunk's `BlockState` hunk, the block registry's traits and
`canPlaceOn`, the terrain sampler (heights around the chunk, slope, fluid height, where the upper dimension begins) and the
mantle's planned blocks; the placement stages read the placement being run through the `ObjectPlacement` facade, and the loot and
spawn services, which have no chunk to ask, ask `LiveWorld` (both below). Without the jar a pack's world has no loot, block drops,
entity spawns or ambient effects, and its biomes' `loot`, `blockDrops`, `entitySpawners` and `effects` are not read.
Iris no longer compiles them in (`IrisModuleHost.generationModules()`), so a pack gets them by putting
`iris-builtins.jar` into its `modules` folder; the built-ins that order after their stages (`iris:floating`,
`iris:decorant`, `iris:custom`) only order, so a pack without the jar still loads. Iris warns once per pack folder
when a pack loads none of the jar's modules (`IrisModuleHost.JAR_MODULE_IDS`, which a test keeps equal to
@@ -156,5 +160,11 @@ running world, outside any chunk stage: the layout and settings at a block, the
objects' loot and the spawner cooldowns Iris saves with the world; values only, implemented by Iris's worlds like `IrisSeed`),
`loot.LootResolver` (the random streams loot is drawn from, shared with the hosts that fill containers) and the loot and
marker lists of an object placement (`loot.ObjectLoot`, `loot.ObjectVanillaLoot`, `spawn.PlacementMarker`, which the modules
register as held types, because Iris's `IrisObjectPlacement` holds them). `iris:post` reads its switches
register as held types, because Iris's `IrisObjectPlacement` holds them). The placement stages need more of the object being
placed than IrisApi describes, so `placement.ObjectPlacement` is the facade Iris implements for each placement and binds to the placing
thread (`ObjectPlacement.current()`): the object's size (`ObjectShape`), the placement's settings (`PlacementSettings`, read from
Iris's `IrisObjectPlacement`), the terrain questions of its placer and the world around it (`PlacementTerrain`), the surface warp,
and the block operations only the platform can do (turning a state with the object, merging two states, matching, traits of the
placement's own states). Its types answer with IrisApi, VolmLib and built-in values only. `prepare.PreparedPlacement`, the output of
`iris:prepare/transforms`, lives in the exposed package too, because `IrisStages` names it. `iris:post` reads its switches
(`postProcessingWalls`, `postProcessingSlabs`) and the biome's `wall` and `slab` as module settings through its context.
+16 -1
View File
@@ -12,7 +12,7 @@
# (art.arcane.iris.builtin), the JDK and the other classes of the jar. `./gradlew builtinModulesJar` checks
# that with IrisApi's pack class checks and fails naming the class and what it uses.
#
# Moving a module here means removing it from IrisModuleHost.generationModules() or PlacementModules.all() in Iris.
# Moving a module here means removing it from IrisModuleHost.generationModules() in Iris.
module art.arcane.iris.engine.modifier.PostModule
include art/arcane/iris/engine/modifier/SurfaceSmoothing*.class
@@ -22,3 +22,18 @@ module art.arcane.iris.engine.loot.LootModule
include art/arcane/iris/engine/loot/**
module art.arcane.iris.engine.spawn.SpawnModule
include art/arcane/iris/engine/spawn/**
module art.arcane.iris.engine.object.placement.PrepareModule
module art.arcane.iris.engine.object.placement.AnchorModule
module art.arcane.iris.engine.object.placement.ValidateModule
module art.arcane.iris.engine.object.placement.BoreModule
module art.arcane.iris.engine.object.placement.BlocksModule
module art.arcane.iris.engine.object.placement.StiltModule
module art.arcane.iris.engine.object.placement.VacuumModule
module art.arcane.iris.engine.object.placement.SnowModule
include art/arcane/iris/engine/object/placement/PlacementModules.class
include art/arcane/iris/engine/object/placement/PlacementWorld.class
include art/arcane/iris/engine/object/placement/WorldVolume.class
include art/arcane/iris/engine/object/placement/ObjectEdits*.class
include art/arcane/iris/engine/object/placement/ResolvedReplace*.class
include art/arcane/iris/engine/object/placement/IrisSurfaceSupport*.class
include art/arcane/iris/engine/object/placement/IrisObjectVacuum.class
@@ -20,9 +20,9 @@ package art.arcane.iris.builtin;
import art.arcane.iris.builtin.anchor.AnchorHeight;
import art.arcane.iris.builtin.blocks.WrittenBlocks;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.stilt.StiltLayers;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.placement.PreparedPlacement;
import com.volmit.stage.BlockStage;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.MantleStage;
@@ -40,8 +40,8 @@ public final class IrisStages {
/** Module {@code iris:prepare}: what a placement decides before it looks for its height. */
public static final class Prepare {
/** The settings the placement uses: the requested ones, turned downhill when they ask to face the slope. Rejects {@code slope}. */
public static final PlacementStage<IrisObjectPlacement> SLOPE = Stage.placement("iris:prepare/slope", IrisObjectPlacement.class);
/** The rotation the placement uses: the requested one, turned downhill when the settings ask to face the slope. Rejects {@code slope}. */
public static final PlacementStage<ObjectRotation> SLOPE = Stage.placement("iris:prepare/slope", ObjectRotation.class);
/** The random rotation, translation and height offset, chosen once per placement. */
public static final PlacementStage<PreparedPlacement> TRANSFORMS = Stage.placement("iris:prepare/transforms", PreparedPlacement.class);
@@ -32,8 +32,9 @@
* ({@link art.arcane.iris.builtin.IrisSeed}, {@link art.arcane.iris.builtin.LiveWorld}), and per-world state several of them use
* ({@link art.arcane.iris.builtin.terrain.LayerBlocks}). Keep them few: each is a promise.
* <p>
* 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.
* The placement stages ({@code iris:prepare} to {@code iris:snow}) reach the object being placed through
* {@link art.arcane.iris.builtin.placement.ObjectPlacement}, a facade Iris implements for each placement. Its types
* answer with IrisApi, VolmLib and built-in values only, and the stages' outputs ({@link art.arcane.iris.builtin.prepare.PreparedPlacement})
* are built-in types too, so a pack module can require a placement stage and read what it chose.
*/
package art.arcane.iris.builtin;
@@ -0,0 +1,59 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import java.util.IdentityHashMap;
import java.util.Map;
/**
* The traits of the block states one placement handles, asked of the placement once per state instance. A placement
* reads the same few states over and over and the platform looks every state up by its value, so the answers are kept by
* identity. For one placement on one thread.
*/
public final class BlockTraits {
private final ObjectPlacement placement;
private final Map<BlockState, TraitAnswers> answers = new IdentityHashMap<>();
public BlockTraits(ObjectPlacement placement) {
this.placement = placement;
}
public boolean has(BlockState state, BlockTrait trait) {
return answers.computeIfAbsent(state, ignored -> new TraitAnswers()).has(placement, state, trait);
}
private static final class TraitAnswers {
private int asked;
private int held;
boolean has(ObjectPlacement placement, BlockState state, BlockTrait trait) {
int flag = 1 << trait.ordinal();
if ((asked & flag) == 0) {
if (placement.hasTrait(state, trait)) {
held |= flag;
}
asked |= flag;
}
return (held & flag) != 0;
}
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
/** The cave an object is placed in: the height of its floor and how many blocks it is high. */
public record CaveSpace(int surface, int height) {
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import com.volmit.block.BlockState;
import java.util.List;
/** One marker of a placement, an entry of its {@code markers}: the blocks it marks and how many. */
public interface MarkerRule {
/** The pack's marker to add. */
String marker();
/** The blocks to mark. */
List<BlockState> targets();
/** Whether a block must match a target exactly; otherwise its material is enough. */
boolean exact();
int maximum();
}
@@ -0,0 +1,105 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.spawn.SpawnMarker;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.world.BlockPosition;
import java.util.Optional;
import java.util.function.Supplier;
/**
* The object placement being run, as Iris's built-in placement stages see it: what is placed and with which settings, the
* terrain it is placed on, and the few block operations that only the platform can do. Iris implements it for each
* placement and binds it to the placing thread while the placement graph runs; the stages read it through {@link #current()}.
* Heights are in the coordinates of the placement stages: above the dimension's bottom.
* <p>
* It never hands out an engine, pack data or a platform type; everything it answers is an IrisApi, VolmLib or
* {@code art.arcane.iris.builtin} value.
*/
public interface ObjectPlacement {
/** The placement running on this thread. */
static ObjectPlacement current() {
return PlacementBinding.current();
}
/** Runs {@code placement} with {@code inputs} as {@link #current()} on this thread. */
static <T> T runBound(ObjectPlacement inputs, Supplier<T> placement) {
return PlacementBinding.run(inputs, placement);
}
ObjectShape object();
/** The settings as the caller passed them; the stages derive what they change (the rotation) themselves. */
PlacementSettings settings();
int x();
/** The height the caller asked for, negative when the placement samples it. */
int requestedY();
int z();
/** The cave the object is placed in; empty outside caves. */
Optional<CaveSpace> cave();
/** Answers the questions of the terrain the placement was asked to place on. */
PlacementTerrain terrain();
/**
* The terrain the placement anchors against: {@link #terrain()}, or, when the settings place on a heightmap, the same
* terrain with its heights from the heightmap's noise, seeded from {@code rng}.
*/
PlacementTerrain terrainFor(RNG rng);
/** The noise that warps the placement's columns; empty when the settings do not warp. */
Optional<SurfaceWarp> surfaceWarp(RNG rng);
/** Iris's simplex noise of {@code seed}, whose signed reads fill -1 to 1. */
PlaneNoise simplex(long seed);
/** {@code state} turned with the object by {@code rotation}, as the platform turns stairs, logs and other facing blocks. */
BlockState rotate(BlockState state, ObjectRotation rotation, int spinX, int spinY, int spinZ);
/** {@code update} laid over {@code base}: the platform's merge of two states of one block, else {@code update}. */
BlockState merge(BlockState base, BlockState update);
/** Whether {@code state}, as the platform's own state, matches {@code other}: {@code state.matches(other)} of the platform. */
boolean matches(BlockState state, BlockState other);
/**
* Whether {@code state} has {@code trait}, as the platform's own state answers it. Unlike the block registry it keeps
* the identity of the states this placement handed out, so a content plugin's block, which shares its key with the
* block it is drawn as, answers as itself ({@link BlockTrait#CUSTOM}).
*/
boolean hasTrait(BlockState state, BlockTrait trait);
/** The marker of the pack named {@code key}, if the pack has one. */
Optional<SpawnMarker> marker(String key);
/** Reports a buffered write as one of the object's own blocks, which Iris's placement listener hears after the commit. */
void objectBlockWritten(BlockPosition position);
/** Reports the height the object was anchored at, which the placement returns to its caller. */
void anchoredAt(int y);
}
@@ -0,0 +1,45 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import art.arcane.volmlib.util.math.IrisBlockVector;
import java.util.List;
/** The object being placed: its declared size, the block its offsets count from, and where it must stand on solid ground. */
public interface ObjectShape {
int width();
int height();
int depth();
/** The block the object's offsets count from, relative to its corner. */
int centerX();
int centerY();
int centerZ();
/** The pack's key of the object, or null for an object without one. */
String key();
/** The columns of the object's lowest solid layer, as offsets from its anchor before any transform; empty for the origin only. */
List<IrisBlockVector> surfaceSupportOffsets();
}
@@ -0,0 +1,40 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import java.util.function.Supplier;
/** The placement bound to the placing thread. */
final class PlacementBinding {
private static final ScopedValue<ObjectPlacement> CURRENT = ScopedValue.newInstance();
private PlacementBinding() {
}
static ObjectPlacement current() {
if (!CURRENT.isBound()) {
throw new IllegalStateException("No Iris object placement is running on this thread");
}
return CURRENT.get();
}
static <T> T run(ObjectPlacement placement, Supplier<T> body) {
return ScopedValue.where(CURRENT, placement).call(body::get);
}
}
@@ -0,0 +1,92 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.blocks.ObjectReplace;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.prepare.ObjectTranslate;
import art.arcane.iris.builtin.prepare.SlopeClip;
import art.arcane.iris.builtin.stilt.StiltSettings;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import art.arcane.iris.builtin.validate.ObjectLimit;
import java.util.List;
import java.util.Optional;
/** The settings of one object placement, as the placement stages read them. */
public interface PlacementSettings {
boolean forcePlace();
SlopeClip slopeCondition();
boolean rotateTowardsSlope();
ObjectRotation rotation();
ObjectTranslate translate();
ObjectPlaceMode mode();
boolean fromBottom();
/** Whether the object places from the ground up instead of by height checks. */
boolean bottom();
CarvingMode carvingSupport();
boolean underwater();
boolean onwater();
boolean requireSurfaceSupport();
int surfaceSupportBuffer();
int surfaceSupportDepth();
ObjectLimit clamp();
/** Whether air is placed before the object. */
boolean bore();
int boreExtendMinY();
int boreExtendMaxY();
List<ObjectReplace> edit();
boolean waterloggable();
boolean meld();
List<MarkerRule> markers();
Optional<StiltSettings> stilt();
Optional<VacuumSettings> vacuum();
/** The snow filter's depth, 0 for none. */
double snow();
List<String> allowedCollisions();
List<String> forbiddenCollisions();
}
@@ -0,0 +1,72 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
import com.volmit.block.BlockState;
/**
* What a placement asks of the terrain and the world around it: heights, carving and water at a column, and the
* world's own facts. A placement made without a world ({@link #hasWorld()} is false) answers its terrain questions from
* the placer alone and the world's facts with nothing.
*/
public interface PlacementTerrain {
/** The surface height of the column, counting fluid unless {@code ignoreFluid}. */
int highest(int x, int z, boolean ignoreFluid);
boolean isCarved(int x, int y, int z);
/** Whether the block is real, solid ground; the height field alone cannot say at mantle time. */
boolean isSurfaceSolid(int x, int y, int z);
boolean isUnderwater(int x, int z);
/** The height up to which the dimension is filled with fluid. */
int fluidHeight();
/** Whether leaves the placement writes never decay. */
boolean preventsDecay();
/** Whether bored air is written as a visible block, to see where smart boring bored. */
boolean debugsSmartBore();
boolean hasWorld();
/** The terrain's slope at the column, as the dimension's slope field gives it. */
double slopeAt(int x, int z);
/** The terrain height at a position between columns, as the dimension's height field gives it. */
double heightAt(double x, double z);
/** Whether the dimension has a bedrock floor. */
boolean hasBedrock();
/** The real Y of the dimension's bottom. */
int minHeight();
/** The dimension's height in blocks. */
int worldHeight();
/** The rock the dimension has at the column; air when it has none to say. */
BlockState rockAt(int x, int z);
StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ);
/** The pack's key of the object placed at the block, or null when none was. */
String objectKeyAt(int x, int y, int z);
}
@@ -0,0 +1,24 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
/** Noise over a plane that swings between -1 and 1, such as the rolling wave of a terrain bend. */
public interface PlaneNoise {
double signed(double x, double z);
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
/** The world-space bounds of the native structure pieces around a placement, in the world's real Y. */
public interface StructureVolumes {
boolean isEmpty();
/** Whether any piece meets the box, bounds inclusive. */
boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ);
/** Whether any piece contains the block or comes within {@code margin} blocks of it. */
boolean containsWithin(int x, int y, int z, int margin);
}
@@ -0,0 +1,28 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.placement;
/** Noise that moves the columns of a placement sideways, so a square object warps like a flag. */
public interface SurfaceWarp {
/** How far, in blocks, the warp may move a column in total. */
double multiplier();
/** The noise at the position, fitted to the range from {@code min} to {@code max}. */
double fit(double min, double max, double x, double y, double z);
}
@@ -42,6 +42,16 @@ public final class ObjectRotation {
public ObjectRotation() {
}
/** A rotation with the given axes, as Iris's own rotation model hands them to the placement stages. */
public static ObjectRotation of(boolean enabled, AxisRotationClamp xAxis, AxisRotationClamp yAxis, AxisRotationClamp zAxis) {
ObjectRotation rotation = new ObjectRotation();
rotation.enabled = enabled;
rotation.xAxis = xAxis;
rotation.yAxis = yAxis;
rotation.zAxis = zAxis;
return rotation;
}
public boolean enabled() {
return enabled;
}
@@ -57,4 +67,28 @@ public final class ObjectRotation {
public AxisRotationClamp zAxis() {
return zAxis;
}
public boolean canRotateX() {
return enabled && xAxis.enabled();
}
public boolean canRotateY() {
return enabled && yAxis.enabled();
}
public boolean canRotateZ() {
return enabled && zAxis.enabled();
}
public boolean canRotate() {
return canRotateX() || canRotateY() || canRotateZ();
}
/** The angle, in radians, the object turns around {@code axis} for the random {@code spin}; 0 when the rotation or the axis is off. */
public double radians(AxisRotationClamp axis, int spin) {
if (!enabled || !axis.enabled()) {
return 0;
}
return axis.getRadians(spin);
}
}
@@ -1,31 +1,24 @@
package art.arcane.iris.engine.object.placement;
package art.arcane.iris.builtin.prepare;
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.volmlib.util.math.IrisBlockVector;
/**
* Precomputed vector rotation for a single placement.
* <p>
* This mirrors {@link IrisObjectRotation#rotate(IrisBlockVector, int, int, int)} branch for branch, with two
* differences: it mutates the vector handed to it instead of cloning, and the per-axis angle plus its cosine
* and sine are resolved once instead of once per block. The angle is a pure function of the axis clamp and the
* spin, both fixed for the placement, and Math.cos/Math.sin are pure, so every produced double is identical to
* the value the per-call form would have produced.
* Turns vectors branch for branch as Iris's object rotation does, with two differences: it mutates the vector
* handed to it instead of cloning, and the per-axis angle plus its cosine and sine are resolved once instead of once
* per block. The angle is a pure function of the axis clamp and the spin, both fixed for the placement, and
* Math.cos/Math.sin are pure, so every produced double is identical to the value the per-call form would have produced.
*/
final class ObjectSpinKernel {
public final class ObjectSpinKernel {
private static final int MODE_NONE = 0;
private static final int MODE_FLIP = 1;
private static final int MODE_QUARTER = 2;
private static final int MODE_THREE_QUARTER = 3;
private static final int MODE_ANGLE = 4;
IrisObjectRotation rotation;
private final ObjectRotation rotation;
private final int spinX ;
private final int spinY;
private final int spinZ;
private final int xMode;
private final int yMode;
private final int zMode;
@@ -36,17 +29,14 @@ import art.arcane.volmlib.util.math.IrisBlockVector;
private final double zCos;
private final double zSin;
ObjectSpinKernel(IrisObjectRotation rotation, int spinX, int spinY, int spinZ) {
public ObjectSpinKernel(ObjectRotation rotation, int spinX, int spinY, int spinZ) {
this.rotation = rotation;
xMode = rotation.canRotateX() ? modeOf(rotation.getXAxis()) : MODE_NONE;
zMode = rotation.canRotateZ() ? modeOf(rotation.getZAxis()) : MODE_NONE;
yMode = rotation.canRotateY() ? modeOf(rotation.getYAxis()) : MODE_NONE;
this.spinX = spinX;
this.spinY = spinY;
this.spinZ = spinZ;
double xAngle = xMode == MODE_ANGLE ? rotation.getXRotation(spinX) : 0;
double zAngle = zMode == MODE_ANGLE ? rotation.getZRotation(spinZ) : 0;
double yAngle = yMode == MODE_ANGLE ? rotation.getYRotation(spinY) : 0;
xMode = rotation.canRotateX() ? modeOf(rotation.xAxis()) : MODE_NONE;
zMode = rotation.canRotateZ() ? modeOf(rotation.zAxis()) : MODE_NONE;
yMode = rotation.canRotateY() ? modeOf(rotation.yAxis()) : MODE_NONE;
double xAngle = xMode == MODE_ANGLE ? rotation.radians(rotation.xAxis(), spinX) : 0;
double zAngle = zMode == MODE_ANGLE ? rotation.radians(rotation.zAxis(), spinZ) : 0;
double yAngle = yMode == MODE_ANGLE ? rotation.radians(rotation.yAxis(), spinY) : 0;
xCos = Math.cos(xAngle);
xSin = Math.sin(xAngle);
zCos = Math.cos(zAngle);
@@ -75,14 +65,10 @@ import art.arcane.volmlib.util.math.IrisBlockVector;
return MODE_ANGLE;
}
PlatformBlockState rotate(PlatformBlockState state) {
return rotation.rotate(state, spinX, spinY, spinZ);
}
/**
* Rotates in place. Axis order (X, then Z, then Y) is load bearing.
*/
void rotate(IrisBlockVector v) {
public void rotate(IrisBlockVector v) {
if (!rotation.canRotate()) {
return;
}
@@ -52,6 +52,20 @@ public final class ObjectTranslate {
public ObjectTranslate() {
}
/** A shift of the given size, as Iris's own translate model hands it to the placement stages. */
public static ObjectTranslate of(int x, int y, int yRandom, int z) {
ObjectTranslate translate = new ObjectTranslate();
translate.x = x;
translate.y = y;
translate.yRandom = yRandom;
translate.z = z;
return translate;
}
public boolean canTranslate() {
return x != 0 || y != 0 || z != 0;
}
public int x() {
return x;
}
@@ -16,24 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.placement;
package art.arcane.iris.builtin.prepare;
import art.arcane.iris.builtin.anchor.PlaceMode;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.builtin.placement.BlockTraits;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.placement.SurfaceWarp;
import art.arcane.volmlib.util.math.IrisBlockVector;
import art.arcane.iris.util.project.noise.CNG;
import com.volmit.block.BlockState;
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.
* What one placement chose before it is anchored: the settings it uses, the rotation it ended up with, the terrain
* that answers its height, water and carving questions, its random spin 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 ObjectPlacement placement;
private final PlacementSettings settings;
private final PlaceMode mode;
private final ObjectRotation rotation;
private final BlockTraits traits;
private final PlacementTerrain terrain;
private final ObjectSpinKernel spin;
private final int spinX;
private final int spinY;
@@ -44,12 +52,17 @@ public final class PreparedPlacement {
private final int randomY;
private final int warpMargin;
private final TransformedBounds bounds;
private final CNG surfaceWarp;
private final SurfaceWarp 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;
/** Everything the preparation worked out; {@code translation} and {@code surfaceWarp} are null when the placement has none. */
public PreparedPlacement(ObjectPlacement placement, ObjectRotation rotation, BlockTraits traits, PlacementTerrain terrain,
ObjectSpinKernel spin, int spinX, int spinY, int spinZ, IrisBlockVector translation, int rotatedCenterY,
int translatedCenterY, int randomY, int warpMargin, TransformedBounds bounds, SurfaceWarp surfaceWarp) {
this.placement = placement;
this.settings = placement.settings();
this.mode = settings.mode().placeMode();
this.rotation = rotation;
this.traits = traits;
this.terrain = terrain;
this.spin = spin;
this.spinX = spinX;
@@ -64,72 +77,82 @@ public final class PreparedPlacement {
this.surfaceWarp = surfaceWarp;
}
/** The settings this placement uses, which may differ from the requested ones. */
public IrisObjectPlacement config() {
return config;
/** The settings the placement was asked for; the rotation may differ, see {@link #rotation()}. */
public PlacementSettings settings() {
return settings;
}
/** The rotation the placement uses, which may differ from the requested one. */
public ObjectRotation rotation() {
return rotation;
}
/** The traits of the block states this placement handles. */
public BlockTraits traits() {
return traits;
}
/** Answers height, water and carving questions; a heightmap placement answers heights from its noise. */
IObjectPlacer terrain() {
public PlacementTerrain terrain() {
return terrain;
}
PlaceMode mode() {
return config.getMode().placeMode();
public PlaceMode mode() {
return mode;
}
int spinX() {
public int spinX() {
return spinX;
}
int spinY() {
public int spinY() {
return spinY;
}
int spinZ() {
public int spinZ() {
return spinZ;
}
/** The rotated translation, or null when the placement does not translate. */
IrisBlockVector translation() {
public IrisBlockVector translation() {
return translation;
}
/** The height of the object's center after rotation. */
int rotatedCenterY() {
public int rotatedCenterY() {
return rotatedCenterY;
}
/** The height of the object's center after translation. */
int translatedCenterY() {
public int translatedCenterY() {
return translatedCenterY;
}
/** The random height offset added once the anchor is final. */
int randomY() {
public int randomY() {
return randomY;
}
int warpMargin() {
public int warpMargin() {
return warpMargin;
}
TransformedBounds bounds() {
public TransformedBounds bounds() {
return bounds;
}
boolean isWarped() {
public 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);
public int warpOffset(double along, double y, double across) {
double half = surfaceWarp.multiplier() / 2D;
return (int) surfaceWarp.fit(-half, half, along, y, across);
}
/** An object block's offset from the anchor after this placement's transforms. */
BlockPosition transform(BlockPosition local) {
public BlockPosition transform(BlockPosition local) {
IrisBlockVector offset = new IrisBlockVector(local.x(), local.y(), local.z());
spin.rotate(offset);
if (mode().has(PlaceTrait.UPSIDE_DOWN)) {
@@ -142,7 +165,7 @@ public final class PreparedPlacement {
}
/** 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);
public BlockState rotate(BlockState state) {
return placement.rotate(state, rotation, spinX, spinY, spinZ);
}
}
@@ -16,8 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.placement;
package art.arcane.iris.builtin.prepare;
/** 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) {
public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
}
@@ -18,17 +18,24 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.anchor.AnchorHeight;
import art.arcane.iris.core.modules.IrisPlacement;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.placement.CaveSpace;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.ObjectShape;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.prepare.TransformedBounds;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.StageGraph;
import java.util.Optional;
/**
* 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
@@ -54,24 +61,24 @@ public final class AnchorModule implements IrisModule {
}
private static AnchorHeight height(PlacementStageContext context) {
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
PlacementSettings settings = prepared.settings();
boolean structurePiece = prepared.mode().has(PlaceTrait.RAW_STAMP);
if (!config.isFromBottom() && placement.requestedY() < 0) {
if (!settings.fromBottom() && 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())) {
ObjectShape object = placement.object();
int y = settings.fromBottom() ? object.height() + 1 + prepared.rotatedCenterY() : placement.requestedY();
if (!settings.forcePlace() && !structurePiece && rejectsCarvingAnchor(prepared, placement.x(), y, placement.z())) {
context.reject(CARVING_ANCHOR);
return new AnchorHeight(y);
}
if (placement.requestedY() < 0 || !config.isBottom() || structurePiece) {
if (placement.requestedY() < 0 || !settings.bottom() || structurePiece) {
return new AnchorHeight(y);
}
y += Math.floorDiv(object.h, 2);
if (!config.isForcePlace() && config.getCarvingSupport() != CarvingMode.CARVING_ONLY
y += Math.floorDiv(object.height(), 2);
if (!settings.forcePlace() && settings.carvingSupport() != CarvingMode.CARVING_ONLY
&& rejectsCarvingAnchor(prepared, placement.x(), y, placement.z())) {
context.reject(CARVING_ANCHOR);
}
@@ -80,14 +87,14 @@ public final class AnchorModule implements IrisModule {
private static AnchorHeight finalHeight(PlacementStageContext context) {
int y = context.output(IrisStages.Anchor.HEIGHT).y() + context.output(IrisStages.Prepare.TRANSFORMS).randomY();
IrisPlacement.current().anchoredAt(y);
ObjectPlacement.current().anchoredAt(y);
return new AnchorHeight(y);
}
private static int sampled(PlacementStageContext context, IrisPlacement placement, PreparedPlacement prepared) {
private static int sampled(PlacementStageContext context, ObjectPlacement 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 SURFACE -> checked(context, prepared, placement.x(), surface(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);
@@ -98,27 +105,27 @@ public final class AnchorModule implements IrisModule {
}
/** 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();
private static int centerSurface(ObjectPlacement placement, PreparedPlacement prepared) {
Optional<CaveSpace> cave = placement.cave();
if (cave.isPresent()) {
return cave.get().surface() + prepared.rotatedCenterY();
}
return surface(placement, prepared, placement.x(), placement.z());
return surface(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 surface(PreparedPlacement prepared, int x, int z) {
return prepared.terrain().highest(x, z, prepared.settings().underwater()) + 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)) {
if (!prepared.settings().forcePlace() && 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,
private static int extremeSurface(PlacementStageContext context, ObjectPlacement placement, PreparedPlacement prepared,
boolean highest, boolean cornersOnly) {
TransformedBounds bounds = prepared.bounds();
int minX = placement.x() + bounds.minX();
@@ -130,8 +137,8 @@ public final class AnchorModule implements IrisModule {
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)) {
int column = surface(prepared, x, z);
if (!prepared.settings().forcePlace() && rejectsCarvingAnchor(prepared, x, column, z)) {
context.reject(CARVING_ANCHOR);
return y;
}
@@ -143,15 +150,15 @@ public final class AnchorModule implements IrisModule {
/** 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()) {
PlacementTerrain terrain = prepared.terrain();
return switch (prepared.settings().carvingSupport()) {
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) {
private static boolean carvedWithin(PlacementTerrain 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;
@@ -18,30 +18,24 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.blocks.ObjectReplace;
import com.volmit.FeatureRegistry;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.blocks.ObjectMarkers;
import art.arcane.iris.builtin.blocks.WrittenBlocks;
import art.arcane.iris.core.modules.BlockEntities;
import art.arcane.iris.core.modules.IrisPlacement;
import art.arcane.iris.builtin.spawn.PlacementMarker;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.placement.MarkerRule;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.spawn.SpawnMarker;
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.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.block.BlockSpec;
import com.volmit.block.BlockState;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.object.BlockEntityData;
import com.volmit.object.ObjectBlock;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStageContext;
@@ -49,6 +43,8 @@ import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.StageGraph;
import com.volmit.world.BlockPosition;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
@@ -59,23 +55,24 @@ import java.util.Set;
*/
public final class BlocksModule implements IrisModule {
private static final Set<String> AIR_MATERIALS = Set.of("minecraft:air", "minecraft:cave_air");
private static final BlockState VOID_AIR = new BlockState("minecraft:void_air");
private static final BlockState VOID_AIR_DEBUG = new BlockState("minecraft:cobweb");
private static final String DISTANCE = "distance";
private static final String PERSISTENT = "persistent";
private static final String WATERLOGGED = "waterlogged";
private static final String TRUE = "true";
static final String WATERLOGGED = "waterlogged";
static final String TRUE = "true";
private static final String FALSE = "false";
private static final int MARKER_HEADROOM_BLOCKS = 2;
private static final Map<String, int[]> FACE_OFFSETS = Map.of(
"north", new int[]{0, 0, -1}, "east", new int[]{1, 0, 0}, "south", new int[]{0, 0, 1},
"west", new int[]{-1, 0, 0}, "up", new int[]{0, 1, 0}, "down", new int[]{0, -1, 0});
private static final String[] FACE_PROPERTIES = {"north", "east", "south", "west", "up", "down"};
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:blocks", "Object blocks", PlacementModules.VERSION);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerHeldType(ObjectReplace.class);
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Blocks.WRITE)
@@ -91,20 +88,21 @@ public final class BlocksModule implements IrisModule {
}
private static void write(BlockStageContext context, WrittenBlocks written) {
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
PlacementWorld world = new PlacementWorld(context.access(), placement.states());
PlacementSettings settings = prepared.settings();
PlacementWorld world = new PlacementWorld(context.access(), prepared.traits());
ObjectBlock block = context.block();
BlockPosition offset = prepared.transform(block.position());
int anchorY = context.output(IrisStages.Anchor.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());
BlockState data = sourceState(block, placement, prepared);
Optional<BlockEntityData> blockEntity = block.blockEntity();
if (!settings.edit().isEmpty()) {
ObjectEdits.Edited edited = ObjectEdits.apply(settings.edit(), data, blockEntity, new RNG(context.random().nextLong()),
offset.x() + placement.x(), offset.y() + anchorY, offset.z() + placement.z(),
ResolvedReplaces.of(context, prepared.terrain()), placement);
data = edited.data();
tile = edited.tile();
blockEntity = edited.blockEntity();
}
data = prepared.rotate(data);
int x = placement.x() + offset.x();
@@ -114,48 +112,48 @@ public final class BlocksModule implements IrisModule {
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());
if (WorldVolume.isPainted(placement, prepared) && !world.has(data, BlockTrait.VINE)) {
y = offset.y() + Math.floorDiv(placement.object().height(), 2)
+ prepared.terrain().highest(x, z, settings.underwater());
}
boolean structurePiece = prepared.mode().has(PlaceTrait.RAW_STAMP);
if (config.isMeld() && !structurePiece && !world.isSolid(x, y, z)) {
if (settings.meld() && !structurePiece && !world.isSolid(x, y, z)) {
return;
}
if (IrisProceduralBlocks.hasProperty(data, WATERLOGGED) && shouldWaterlog(world, config, placement.requestedY(), x, y, z)) {
if (data.properties().containsKey(WATERLOGGED) && shouldWaterlog(world, settings, placement.requestedY(), x, y, z)) {
data = data.withProperty(WATERLOGGED, TRUE);
}
if (B.isVineBlock(data)) {
if (world.has(data, BlockTrait.VINE)) {
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);
PlacedBlock placed = world.set(x, y, z, data, blockEntity);
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;
private static BlockState sourceState(ObjectBlock block, ObjectPlacement placement, PreparedPlacement prepared) {
BlockState data = block.state();
PlacementTerrain terrain = prepared.terrain();
if (terrain.debugsSmartBore() && placement.matches(data, VOID_AIR)) {
data = VOID_AIR_DEBUG;
}
if (terrain.isPreventingDecay() && IrisProceduralBlocks.hasProperty(data, DISTANCE)
&& FALSE.equals(IrisProceduralBlocks.propertyValue(data, PERSISTENT))) {
if (terrain.preventsDecay() && data.properties().containsKey(DISTANCE)
&& FALSE.equals(data.properties().get(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()) {
private static boolean shouldWrite(PlacementWorld world, BlockState data, int x, int y, int z, boolean structurePiece) {
if (world.has(data, BlockTrait.CUSTOM)) {
return true;
}
boolean vineIntoSolid = B.isVineBlock(data) && world.isSolid(x, y, z);
return shouldPlaceObjectBlock(structurePiece, AIR_MATERIALS.contains(IrisObjectShaping.materialKey(data)), vineIntoSolid);
boolean vineIntoSolid = world.has(data, BlockTrait.VINE) && world.isSolid(x, y, z);
return shouldPlaceObjectBlock(structurePiece, AIR_MATERIALS.contains(data.material().toString()), vineIntoSolid);
}
/** Air is written only by structure pieces, and a vine never replaces a solid block. */
@@ -164,27 +162,27 @@ public final class BlocksModule implements IrisModule {
}
/** 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())) {
static boolean shouldWaterlog(PlacementWorld world, PlacementSettings settings, int requestedY, int x, int y, int z) {
if (!(settings.waterloggable() || settings.underwater())) {
return false;
}
if (requestedY >= 0 && config.getCarvingSupport() == CarvingMode.CARVING_ONLY) {
if (requestedY >= 0 && settings.carvingSupport() == CarvingMode.CARVING_ONLY) {
return false;
}
PlatformBlockState existing = world.get(x, y, z);
return B.isWater(existing) || B.isWaterLogged(existing);
BlockState existing = world.get(x, y, z);
return world.has(existing, BlockTrait.WATER) || TRUE.equals(existing.properties().get(WATERLOGGED));
}
/** {@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)) {
static BlockState attachVineFaces(PlacementWorld world, BlockState vine, int x, int y, int z) {
BlockState attached = vine;
for (String face : FACE_PROPERTIES) {
if (!vine.properties().containsKey(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)) {
int[] offset = FACE_OFFSETS.get(face);
BlockState facing = world.get(x + offset[0], y + offset[1], z + offset[2]);
if (world.has(facing, BlockTrait.SOLID) && !world.has(facing, BlockTrait.VINE)) {
attached = attached.withProperty(face, TRUE);
}
}
@@ -196,66 +194,55 @@ public final class BlocksModule implements IrisModule {
* where the marker either allows anything above or finds two blocks of air.
*/
private static void placeMarkers(PlacementStageContext context) {
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
if (config.getMarkers().isEmpty() || prepared.terrain().getEngine() == null) {
PlacementSettings settings = prepared.settings();
if (settings.markers().isEmpty() || !prepared.terrain().hasWorld()) {
return;
}
WrittenBlocks written = context.output(IrisStages.Blocks.WRITE);
PlacementWorld world = new PlacementWorld(context.access(), placement.states());
PlacementWorld world = new PlacementWorld(context.access(), prepared.traits());
RNG markerRandom = new RNG(context.random().nextLong());
int salt = 0;
for (PlacementMarker markerConfig : config.getMarkers()) {
SpawnMarker marker = SpawnResources.marker(placement.data().getPackResources(), markerConfig.marker());
for (MarkerRule rule : settings.markers()) {
Optional<SpawnMarker> marker = placement.marker(rule.marker());
int markerSalt = salt++;
if (marker == null) {
if (marker.isEmpty()) {
continue;
}
KList<BlockPosition> candidates = candidates(written, markerConfig, markTargets(markerConfig, placement), placement);
int remaining = markerConfig.maximumMarkers();
KList<BlockPosition> candidates = candidates(written, rule, placement);
int remaining = rule.maximum();
for (BlockPosition position : candidates.shuffleCopy(markerRandom.nextParallelRNG(markerSalt))) {
if (remaining <= 0) {
break;
}
if (!marker.emptyAbove() || hasAirAbove(world, position)) {
context.access().marker(ObjectMarkers.of(position, markerConfig.marker()));
if (!marker.get().emptyAbove() || hasAirAbove(world, position)) {
context.access().marker(ObjectMarkers.of(position, rule.marker()));
remaining--;
}
}
}
}
private static KList<PlatformBlockState> markTargets(PlacementMarker markerConfig, IrisPlacement placement) {
KList<PlatformBlockState> targets = new KList<>();
for (BlockSpec spec : markerConfig.mark()) {
BlockState state = placement.data().getPackResources().blocks().resolve(spec);
targets.add(placement.states().toPlatform(state));
}
return targets;
}
private static KList<BlockPosition> candidates(WrittenBlocks written, PlacementMarker markerConfig,
KList<PlatformBlockState> targets, IrisPlacement placement) {
private static KList<BlockPosition> candidates(WrittenBlocks written, MarkerRule rule, ObjectPlacement placement) {
KList<BlockPosition> candidates = new KList<>();
for (PlacedBlock block : written.blocks()) {
PlatformBlockState state = placement.states().toPlatform(block.state());
if (targets.stream().anyMatch(target -> marks(markerConfig, target, state))) {
if (rule.targets().stream().anyMatch(target -> marks(placement, rule, target, block.state()))) {
candidates.add(block.position());
}
}
return candidates;
}
private static boolean marks(PlacementMarker markerConfig, PlatformBlockState target, PlatformBlockState state) {
return markerConfig.exact()
? target.matches(state)
: IrisObjectShaping.materialKey(target).equals(IrisObjectShaping.materialKey(state));
private static boolean marks(ObjectPlacement placement, MarkerRule rule, BlockState target, BlockState state) {
return rule.exact()
? placement.matches(target, state)
: target.material().equals(state.material());
}
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()))) {
if (!world.has(world.get(position.x(), position.y() + above, position.z()), BlockTrait.AIR)) {
return false;
}
}
@@ -19,15 +19,19 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.core.modules.IrisPlacement;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
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 {
private static final BlockState AIR = new BlockState("minecraft:cave_air");
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:bore", "Bore", PlacementModules.VERSION);
@@ -42,17 +46,17 @@ public final class BoreModule implements IrisModule {
private static void clear(PlacementStageContext context) {
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
if (!config.isBore()) {
PlacementSettings settings = prepared.settings();
if (!settings.bore()) {
return;
}
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
WorldVolume volume = WorldVolume.of(placement, prepared, context.output(IrisStages.Anchor.FINAL).y());
PlacementWorld world = new PlacementWorld(context.access(), placement.states());
PlacementWorld world = new PlacementWorld(context.access(), prepared.traits());
for (int x = volume.minX(); x <= volume.maxX(); x++) {
for (int y = volume.minY() - config.getBoreExtendMinY(); y <= volume.maxY() + config.getBoreExtendMaxY(); y++) {
for (int y = volume.minY() - settings.boreExtendMinY(); y <= volume.maxY() + settings.boreExtendMaxY(); y++) {
for (int z = volume.minZ(); z <= volume.maxZ(); z++) {
world.set(x, y, z, IrisObject.States.AIR);
world.set(x, y, z, AIR);
}
}
}
@@ -1,8 +1,9 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.prepare.ObjectSpinKernel;
import art.arcane.iris.builtin.prepare.ObjectTranslate;
import art.arcane.volmlib.util.math.IrisBlockVector;
import java.util.Arrays;
@@ -20,29 +21,41 @@ public final class IrisSurfaceSupport {
private IrisSurfaceSupport() {
}
public static boolean isUnsupported(IObjectPlacer placer, IrisData data, int x, int z,
IrisObjectTranslate translate, IrisObjectRotation rotation,
public static boolean isUnsupported(PlacementTerrain terrain, int x, int z,
ObjectTranslate translate, ObjectRotation rotation,
int spinX, int spinY, int spinZ,
List<IrisBlockVector> supportOffsets, int buffer, int minSolidDepth) {
Stencil stencil = STENCIL.get();
if (!stencil.build(supportOffsets, translate, rotation, spinX, spinY, spinZ, Math.max(0, buffer))) {
Transform transform = new Transform(translate, new ObjectSpinKernel(rotation, spinX, spinY, spinZ));
if (!stencil.build(supportOffsets, transform, Math.max(0, buffer))) {
return true;
}
return stencil.anyColumnUnsupported(placer, data, x, z, Math.max(1, minSolidDepth));
return stencil.anyColumnUnsupported(terrain, x, z, Math.max(1, minSolidDepth));
}
private static IrisBlockVector transform(IrisBlockVector offset, IrisObjectTranslate translate,
IrisObjectRotation rotation, int spinX, int spinY, int spinZ) {
IrisBlockVector transformed = offset.clone();
if (rotation != null) {
transformed = rotation.rotate(transformed, spinX, spinY, spinZ);
/** The placement's rotation and translation, as they move a support offset. */
private static final class Transform {
private final ObjectSpinKernel spin;
private final IrisBlockVector translation;
private Transform(ObjectTranslate translate, ObjectSpinKernel spin) {
this.spin = spin;
if (translate.canTranslate()) {
translation = new IrisBlockVector(translate.x(), translate.y(), translate.z());
spin.rotate(translation);
} else {
translation = null;
}
}
if (translate == null) {
private IrisBlockVector apply(IrisBlockVector offset) {
IrisBlockVector transformed = offset.clone();
spin.rotate(transformed);
if (translation != null) {
transformed.add(translation);
}
return transformed;
}
return rotation == null
? translate.translate(transformed)
: translate.translate(transformed, rotation, spinX, spinY, spinZ);
}
/**
@@ -61,8 +74,7 @@ public final class IrisSurfaceSupport {
private int centerX;
private int centerZ;
private boolean build(List<IrisBlockVector> supportOffsets, IrisObjectTranslate translate,
IrisObjectRotation rotation, int spinX, int spinY, int spinZ, int buffer) {
private boolean build(List<IrisBlockVector> supportOffsets, Transform transform, int buffer) {
boolean originOnly = supportOffsets == null || supportOffsets.isEmpty();
int count = originOnly ? 1 : supportOffsets.size();
if (offsetX.length < count) {
@@ -76,7 +88,7 @@ public final class IrisSurfaceSupport {
int highZ = Integer.MIN_VALUE;
for (int i = 0; i < count; i++) {
IrisBlockVector source = originOnly ? new IrisBlockVector(0, 0, 0) : supportOffsets.get(i);
IrisBlockVector transformed = transform(source, translate, rotation, spinX, spinY, spinZ);
IrisBlockVector transformed = transform.apply(source);
int transformedX = transformed.getBlockX();
int transformedZ = transformed.getBlockZ();
offsetX[i] = transformedX;
@@ -150,13 +162,13 @@ public final class IrisSurfaceSupport {
}
/** Centre-outward so the common failure, a hole right under the anchor, costs one column. */
private boolean anyColumnUnsupported(IObjectPlacer placer, IrisData data, int x, int z, int minSolidDepth) {
private boolean anyColumnUnsupported(PlacementTerrain terrain, int x, int z, int minSolidDepth) {
int maxRing = Math.max(
Math.max(centerX, width - 1 - centerX),
Math.max(centerZ, depth - 1 - centerZ));
for (int ring = 0; ring <= maxRing; ring++) {
if (ring == 0) {
if (isColumnUnsupported(placer, data, x, z, centerX, centerZ, minSolidDepth)) {
if (isColumnUnsupported(terrain, x, z, centerX, centerZ, minSolidDepth)) {
return true;
}
continue;
@@ -167,14 +179,14 @@ public final class IrisSurfaceSupport {
int lowZ = centerZ - ring;
int highZ = centerZ + ring;
for (int sx = lowX; sx <= highX; sx++) {
if (isColumnUnsupported(placer, data, x, z, sx, lowZ, minSolidDepth)
|| isColumnUnsupported(placer, data, x, z, sx, highZ, minSolidDepth)) {
if (isColumnUnsupported(terrain, x, z, sx, lowZ, minSolidDepth)
|| isColumnUnsupported(terrain, x, z, sx, highZ, minSolidDepth)) {
return true;
}
}
for (int sz = lowZ + 1; sz < highZ; sz++) {
if (isColumnUnsupported(placer, data, x, z, lowX, sz, minSolidDepth)
|| isColumnUnsupported(placer, data, x, z, highX, sz, minSolidDepth)) {
if (isColumnUnsupported(terrain, x, z, lowX, sz, minSolidDepth)
|| isColumnUnsupported(terrain, x, z, highX, sz, minSolidDepth)) {
return true;
}
}
@@ -182,7 +194,7 @@ public final class IrisSurfaceSupport {
return false;
}
private boolean isColumnUnsupported(IObjectPlacer placer, IrisData data, int x, int z,
private boolean isColumnUnsupported(PlacementTerrain terrain, int x, int z,
int stencilX, int stencilZ, int minSolidDepth) {
if (stencilX < 0 || stencilX >= width || stencilZ < 0 || stencilZ >= depth
|| !cells[(stencilX * depth) + stencilZ]) {
@@ -191,13 +203,13 @@ public final class IrisSurfaceSupport {
int columnX = x + minX + stencilX;
int columnZ = z + minZ + stencilZ;
int surfaceY = placer.getHighest(columnX, columnZ, data, true);
int surfaceY = terrain.highest(columnX, columnZ, true);
for (int below = 0; below < minSolidDepth; below++) {
if (placer.isCarved(columnX, surfaceY - below, columnZ)) {
if (terrain.isCarved(columnX, surfaceY - below, columnZ)) {
return true;
}
}
return !placer.isSurfaceSolid(columnX, surfaceY, columnZ);
return !terrain.isSurfaceSolid(columnX, surfaceY, columnZ);
}
}
}
@@ -19,12 +19,14 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.blocks.ObjectReplace;
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.iris.builtin.placement.ObjectPlacement;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.object.BlockEntityData;
import java.util.List;
import java.util.Optional;
/**
* A placement's block replacements ({@code edit}): each replacement, by its chance, swaps the blocks it
@@ -35,42 +37,44 @@ 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) {
ResolvedReplaces replaces = ResolvedReplaces.of(rdata);
PlatformBlockState edited = data;
TileData editedTile = tile;
for (ObjectReplace settings : config.getEdit()) {
/** The result's block entity is the last replacement's, if it has one. */
static Edited apply(List<ObjectReplace> edits, BlockState data, Optional<BlockEntityData> blockEntity, RNG rng,
double x, double y, double z, ResolvedReplaces replaces, ObjectPlacement placement) {
BlockState edited = data;
Optional<BlockEntityData> editedEntity = blockEntity;
for (ObjectReplace settings : edits) {
ResolvedReplace replace = replaces.of(settings);
if (!rng.chance(replace.chance())) {
continue;
}
for (PlatformBlockState find : replace.find()) {
if (!finds(replace, find, edited)) {
for (BlockState find : replace.find()) {
if (!finds(placement, replace, find, edited)) {
continue;
}
edited = replaced(edited, replace.replacement(rng, x, y, z));
editedTile = replace.tile(rng).orElse(editedTile);
edited = replaced(placement, edited, replace.replacement(rng, x, y, z));
Optional<BlockEntityData> picked = replace.tile(rng);
if (picked.isPresent()) {
editedEntity = picked;
}
}
}
return new Edited(edited, editedTile);
return new Edited(edited, editedEntity);
}
private static boolean finds(ResolvedReplace replace, PlatformBlockState find, PlatformBlockState data) {
private static boolean finds(ObjectPlacement placement, ResolvedReplace replace, BlockState find, BlockState data) {
return replace.exact()
? find.matches(data)
: IrisObjectShaping.materialKey(find).equals(IrisObjectShaping.materialKey(data));
? placement.matches(find, data)
: find.material().equals(data.material());
}
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);
private static BlockState replaced(ObjectPlacement placement, BlockState data, BlockState replacement) {
boolean sameMaterial = replacement.material().equals(data.material());
if (sameMaterial && !placement.hasTrait(replacement, BlockTrait.CUSTOM) && !placement.hasTrait(data, BlockTrait.CUSTOM)) {
return placement.merge(data, replacement);
}
return replacement;
}
record Edited(PlatformBlockState data, TileData tile) {
record Edited(BlockState data, Optional<BlockEntityData> blockEntity) {
}
}
@@ -18,19 +18,10 @@
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 {
/** What Iris's built-in object placement modules share: the version they report. The modules ship in the built-ins jar. */
final class PlacementModules {
static final String VERSION = "built-in";
private PlacementModules() {
}
public static List<IrisModule> all() {
return List.of(new PrepareModule(), new AnchorModule(), new ValidateModule(), new BoreModule(),
new BlocksModule(), new StiltModule(), new VacuumModule(), new SnowModule());
}
}
@@ -18,46 +18,44 @@
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 art.arcane.iris.builtin.placement.BlockTraits;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.object.BlockEntityData;
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.
*/
/** A placement stage's buffered world: 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;
private final BlockTraits traits;
PlacementWorld(PlacementAccess access, PlatformBlockStates states) {
PlacementWorld(PlacementAccess access, BlockTraits traits) {
this.access = access;
this.states = states;
this.traits = traits;
}
PlatformBlockState get(int x, int y, int z) {
return states.toPlatform(access.get(x, y, z));
BlockState get(int x, int y, int z) {
return access.get(x, y, z);
}
boolean has(BlockState state, BlockTrait trait) {
return traits.has(state, trait);
}
boolean isSolid(int x, int y, int z) {
return B.isSolid(get(x, y, z));
return has(get(x, y, z), BlockTrait.SOLID);
}
PlacedBlock set(int x, int y, int z, PlatformBlockState state) {
return set(x, y, z, state, null);
PlacedBlock set(int x, int y, int z, BlockState state) {
return set(x, y, z, state, Optional.empty());
}
/** {@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));
PlacedBlock set(int x, int y, int z, BlockState state, Optional<BlockEntityData> blockEntity) {
PlacedBlock block = new PlacedBlock(new BlockPosition(x, y, z), state, blockEntity);
access.set(block);
return block;
}
@@ -18,26 +18,29 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.prepare.SlopeClip;
import com.volmit.FeatureRegistry;
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
import art.arcane.iris.builtin.IrisStages;
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.IrisObject;
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.placement.BlockTraits;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.ObjectShape;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.placement.SurfaceWarp;
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.prepare.ObjectSpinKernel;
import art.arcane.iris.builtin.prepare.ObjectTranslate;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.prepare.TransformedBounds;
import art.arcane.volmlib.util.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;
import java.util.Optional;
/**
* Module {@code iris:prepare}: checks the slope, turns the object downhill when asked, and chooses the
* placement's rotation, translation and random height offset.
@@ -55,12 +58,6 @@ public final class PrepareModule implements IrisModule {
return ModuleInfo.of("iris:prepare", "Placement preparation", PlacementModules.VERSION);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerHeldType(SlopeClip.class);
registry.registerHeldType(AxisRotationClamp.class);
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Prepare.SLOPE).produce(PrepareModule::slope);
@@ -69,76 +66,78 @@ public final class PrepareModule implements IrisModule {
.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;
private static ObjectRotation slope(PlacementStageContext context) {
ObjectPlacement placement = ObjectPlacement.current();
PlacementSettings settings = placement.settings();
ObjectRotation requested = settings.rotation();
boolean checksSlope = !settings.forcePlace() && !settings.slopeCondition().isDefault();
if (!checksSlope && !settings.rotateTowardsSlope()) {
return requested;
}
Engine engine = placement.placer().getEngine();
if (engine == null) {
if (!placement.terrain().hasWorld()) {
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()))) {
if (checksSlope && !settings.slopeCondition().isValid(placement.terrain().slopeAt(placement.x(), placement.z()))) {
context.reject("slope");
return config;
return requested;
}
return config.isRotateTowardsSlope() ? turnedDownhill(placement.object(), config, engine, placement.x(), placement.z()) : config;
return settings.rotateTowardsSlope() ? turnedDownhill(placement, requested) : requested;
}
/** 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<Double> 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);
/** A copy of {@code requested} whose Y rotation faces the lowest side of the rectangle around the object. */
private static ObjectRotation turnedDownhill(ObjectPlacement placement, ObjectRotation requested) {
PlacementTerrain terrain = placement.terrain();
ObjectShape object = placement.object();
int x = placement.x();
int z = placement.z();
double north = terrain.heightAt(x, z + ((float) object.depth()) / 2);
double east = terrain.heightAt(x + ((float) object.width()) / 2, z);
double south = terrain.heightAt(x, z - ((float) object.depth()) / 2);
double west = terrain.heightAt(x - ((float) object.width()) / 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().min() + downhill;
IrisObjectRotation rotation = new IrisObjectRotation();
rotation.setXAxis(requested.getXAxis());
rotation.setZAxis(requested.getZAxis());
double turn = requested.yAxis().min() + downhill;
if (turn == 0) {
rotation.setYAxis(AxisRotationClamp.of(false, false, 0, 0, QUARTER_TURN));
rotation.setEnabled(requested.canRotateX() || requested.canRotateZ());
} else {
rotation.setYAxis(AxisRotationClamp.of(true, false, turn, turn, QUARTER_TURN));
rotation.setEnabled(true);
return ObjectRotation.of(requested.canRotateX() || requested.canRotateZ(), requested.xAxis(),
AxisRotationClamp.of(false, false, 0, 0, QUARTER_TURN), requested.zAxis());
}
IrisObjectPlacement turned = config.toPlacement(config.getPlace().toArray(new String[0]));
turned.setRotation(rotation);
return turned;
return ObjectRotation.of(true, requested.xAxis(), AxisRotationClamp.of(true, false, turn, turn, QUARTER_TURN),
requested.zAxis());
}
private static PreparedPlacement transforms(PlacementStageContext context) {
IrisPlacement placement = IrisPlacement.current();
IrisObjectPlacement config = context.output(IrisStages.Prepare.SLOPE);
IrisObject object = placement.object();
ObjectPlacement placement = ObjectPlacement.current();
PlacementSettings settings = placement.settings();
ObjectRotation rotation = context.output(IrisStages.Prepare.SLOPE);
ObjectShape 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());
PlacementTerrain terrain = placement.terrainFor(rng);
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();
ObjectTranslate translate = settings.translate();
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().placeMode().has(PlaceTrait.UPSIDE_DOWN), 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);
IrisBlockVector rotatedCenter = new IrisBlockVector(0, object.centerY(), 0);
spin.rotate(rotatedCenter);
IrisBlockVector translation = translate.canTranslate() ? rotated(spin, translate) : null;
IrisBlockVector translatedCenter = new IrisBlockVector(0, object.centerY(), 0);
if (translation != null) {
translatedCenter = (IrisBlockVector) translatedCenter.clone().add(translation);
}
int randomY = randomHeightOffset(translate.yRandom(), rng);
Optional<SurfaceWarp> surfaceWarp = placement.surfaceWarp(rng);
int warpMargin = surfaceWarp.map(warp -> (int) Math.ceil(Math.abs(warp.multiplier()) / 2D)).orElse(0);
TransformedBounds bounds = transformedBounds(object, spin, translation, settings.mode().placeMode().has(PlaceTrait.UPSIDE_DOWN), warpMargin);
return new PreparedPlacement(placement, rotation, new BlockTraits(placement), terrain, spin,
spinX, spinY, spinZ, translation, rotatedCenter.getBlockY(), translatedCenter.getBlockY(), randomY,
warpMargin, bounds, surfaceWarp.orElse(null));
}
private static IrisBlockVector rotated(ObjectSpinKernel spin, ObjectTranslate translate) {
IrisBlockVector shift = new IrisBlockVector(translate.x(), translate.y(), translate.z());
spin.rotate(shift);
return shift;
}
/** Within {@code range} of zero, on the side its sign gives. */
@@ -149,11 +148,11 @@ public final class PrepareModule implements IrisModule {
return range < 0 ? rng.i(range, 0) : 0;
}
private static TransformedBounds transformedBounds(IrisObject object, ObjectSpinKernel spin, IrisBlockVector translation,
private static TransformedBounds transformedBounds(ObjectShape 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[] sourceX = {-object.centerX(), object.width() - object.centerX() - 1};
int[] sourceY = {-object.centerY(), object.height() - object.centerY() - 1};
int[] sourceZ = {-object.centerZ(), object.depth() - object.centerZ() - 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;
@@ -19,13 +19,9 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.blocks.ObjectReplace;
import art.arcane.iris.core.modules.BlockEntities;
import art.arcane.iris.engine.object.prefab.TileData;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockSpec;
import com.volmit.block.BlockState;
import com.volmit.block.PaletteSpec;
import com.volmit.object.BlockEntityData;
@@ -33,12 +29,12 @@ import java.util.List;
import java.util.Optional;
/**
* One {@link ObjectReplace} made ready for a pack: the blocks it finds resolved to the platform's, its palette
* picked through the pack's block registry with the seed of the {@link RNG} the placement hands in, and the tile
* data of the palette's entries resolved once. The old settings class cached the same things on itself.
* One {@link ObjectReplace} made ready for a pack: the blocks it finds resolved through the pack's block registry, its
* palette picked through the registry with the seed of the {@link RNG} the placement hands in, and the tile data of the
* palette's entries resolved once. The old settings class cached the same things on itself.
*/
final class ResolvedReplace {
private final List<PlatformBlockState> find;
private final List<BlockState> find;
private final boolean exact;
private final float chance;
private final PaletteSpec replace;
@@ -46,7 +42,7 @@ final class ResolvedReplace {
private final List<Optional<BlockEntityData>> entryTiles;
private final int weightedSize;
ResolvedReplace(List<PlatformBlockState> find, boolean exact, float chance, PaletteSpec replace, BlockRegistry blocks) {
ResolvedReplace(List<BlockState> find, boolean exact, float chance, PaletteSpec replace, BlockRegistry blocks) {
this.find = List.copyOf(find);
this.exact = exact;
this.chance = chance;
@@ -57,9 +53,7 @@ final class ResolvedReplace {
}
static ResolvedReplace of(ObjectReplace settings, BlockRegistry blocks) {
List<PlatformBlockState> find = settings.find().stream()
.map(spec -> B.getState(blocks.resolve(spec).key()))
.toList();
List<BlockState> find = settings.find().stream().map(blocks::resolve).toList();
return new ResolvedReplace(find, settings.exact(), settings.chance(), settings.replace(), blocks);
}
@@ -71,21 +65,20 @@ final class ResolvedReplace {
return exact;
}
List<PlatformBlockState> find() {
List<BlockState> find() {
return find;
}
PlatformBlockState replacement(RNG rng, double x, double y, double z) {
return B.getState(blocks.palette(replace, rng.getSeed()).at(x, y, z).key());
BlockState replacement(RNG rng, double x, double y, double z) {
return blocks.palette(replace, rng.getSeed()).at(x, y, z);
}
/** The tile data of the entry picked for {@code rng}: the first entry when the palette's weights add up to one, else a uniform pick. */
Optional<TileData> tile(RNG rng) {
Optional<BlockEntityData> tile(RNG rng) {
if (weightedSize == 0) {
return Optional.empty();
}
Optional<BlockEntityData> entity = entryTiles.get(weightedSize == 1 ? 0 : pickedEntry(rng));
return entity.map(BlockEntities::tileOf);
return entryTiles.get(weightedSize == 1 ? 0 : pickedEntry(rng));
}
private int pickedEntry(RNG rng) {
@@ -19,33 +19,28 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.blocks.ObjectReplace;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import com.volmit.block.BlockRegistry;
import com.volmit.stage.PlacementStageContext;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** The {@link ResolvedReplace}s of one engine runtime, one per decoded {@link ObjectReplace}, built when a placement first uses it. */
/** The {@link ResolvedReplace}s of one pack's block registry, one per decoded {@link ObjectReplace}, built when a placement first uses it. */
final class ResolvedReplaces {
private final BlockRegistry blocks;
private final Map<ObjectReplace, ResolvedReplace> resolved = new ConcurrentHashMap<>();
ResolvedReplaces(Engine engine) {
this(engine.getData().getPackResources().blocks());
}
ResolvedReplaces(BlockRegistry blocks) {
this.blocks = blocks;
}
/** The replacements of the engine {@code data} serves, or of {@code data} alone when no engine runs it. */
static ResolvedReplaces of(IrisData data) {
Engine engine = data.getEngine();
if (engine == null) {
return new ResolvedReplaces(data.getPackResources().blocks());
/** The replacements of the world {@code context} places in, or of the pack alone when the placement has no world. */
static ResolvedReplaces of(PlacementStageContext context, PlacementTerrain terrain) {
if (!terrain.hasWorld()) {
return new ResolvedReplaces(context.resources().blocks());
}
return engine.getGeneration().state(ResolvedReplaces.class, ResolvedReplaces::new);
return context.world().state(ResolvedReplaces.class, world -> new ResolvedReplaces(world.resources().blocks()));
}
ResolvedReplace of(ObjectReplace settings) {
@@ -20,11 +20,11 @@ package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.blocks.WrittenBlocks;
import art.arcane.iris.core.modules.IrisPlacement;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.StageGraph;
@@ -32,6 +32,7 @@ import com.volmit.world.BlockPosition;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.IntStream;
/**
* Module {@code iris:snow}: a random depth of snow on top of each column of the object, deeper the more
@@ -39,6 +40,9 @@ import java.util.Map;
*/
public final class SnowModule implements IrisModule {
private static final int LAYERS_PER_UNIT_OF_SNOW = 7;
private static final BlockState[] SNOW_LAYERS = IntStream.rangeClosed(1, 8)
.mapToObj(layers -> new BlockState("minecraft:snow").withProperty("layers", Integer.toString(layers)))
.toArray(BlockState[]::new);
@Override
public ModuleInfo info() {
@@ -54,17 +58,18 @@ public final class SnowModule implements IrisModule {
}
private static void cover(PlacementStageContext context) {
double snow = context.output(IrisStages.Prepare.TRANSFORMS).config().getSnow();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
double snow = prepared.settings().snow();
WrittenBlocks written = context.output(IrisStages.Blocks.WRITE);
if (!(snow > 0) || written.isEmpty()) {
return;
}
PlacementWorld world = new PlacementWorld(context.access(), IrisPlacement.current().states());
PlacementWorld world = new PlacementWorld(context.access(), prepared.traits());
RNG rng = new RNG(context.random().nextLong());
int maxLayer = IrisObject.States.SNOW_LAYERS.length - 1;
int maxLayer = 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)]);
world.set(top.x(), top.y() + 1, top.z(), SNOW_LAYERS[Math.max(Math.min(layer, maxLayer), 0)]);
}
}
@@ -18,19 +18,18 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.anchor.StiltShape;
import com.volmit.FeatureRegistry;
import art.arcane.iris.builtin.stilt.StiltSettings;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.anchor.StiltShape;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.stilt.StiltLayers;
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.iris.builtin.stilt.StiltSettings;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.object.ObjectBlock;
import com.volmit.stage.BlockStageContext;
import com.volmit.stage.PlacementStageContext;
@@ -38,6 +37,7 @@ import com.volmit.stage.StageGraph;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
@@ -48,8 +48,9 @@ import java.util.Set;
public final class StiltModule implements IrisModule {
private static final Set<String> 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 BlockState SOIL_REPLACEMENT = new BlockState("minecraft:dirt");
private static final Set<String> NO_STILT_SUFFIXES = Set.of("_stairs", "_slab");
private static final String PATH_MATERIAL = "minecraft:dirt_path";
private static final long HASH_X = 341873128712L;
private static final long HASH_Y = 132897987541L;
private static final long HASH_Z = 735791245321L;
@@ -67,11 +68,6 @@ public final class StiltModule implements IrisModule {
return ModuleInfo.of("iris:stilt", "Stilts", PlacementModules.VERSION);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerHeldType(StiltSettings.class);
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Stilt.LAYERS)
@@ -90,12 +86,21 @@ public final class StiltModule implements IrisModule {
return;
}
ObjectBlock block = context.block();
if (!IrisObjectShaping.shouldStilt(IrisPlacement.current().states().toPlatform(block.state()))) {
if (!shouldStilt(prepared, block.state())) {
return;
}
layers.include(new ObjectBlock(prepared.transform(block.position()), block.state(), block.blockEntity()));
}
/** Whether the block is solid ground a stilt can repeat: not a stair, a slab or a path. */
private static boolean shouldStilt(PreparedPlacement prepared, BlockState state) {
if (!prepared.traits().has(state, BlockTrait.OCCLUDING)) {
return false;
}
String material = state.material().toString();
return NO_STILT_SUFFIXES.stream().noneMatch(material::endsWith) && !material.equals(PATH_MATERIAL);
}
private static void fill(PlacementStageContext context) {
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
StiltShape shape = prepared.mode().stilt();
@@ -112,25 +117,27 @@ public final class StiltModule implements IrisModule {
/** 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 ObjectPlacement placement;
private final PreparedPlacement prepared;
private final IrisObjectPlacement config;
private final PlacementSettings config;
private final StiltSettings settings;
private final PlatformBlockState palette;
private final BlockState palette;
private final StiltShape shape;
private final PlacementWorld world;
private final PlacementStageContext context;
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.placement = ObjectPlacement.current();
this.prepared = prepared;
this.config = prepared.config();
this.settings = config.getStiltSettings();
this.context = context;
this.config = prepared.settings();
this.settings = config.stilt().orElse(null);
this.shape = prepared.mode().stilt();
this.world = new PlacementWorld(context.access(), placement.states());
this.world = new PlacementWorld(context.access(), prepared.traits());
this.rng = new RNG(context.random().nextLong());
this.anchorY = context.output(IrisStages.Anchor.FINAL).y();
this.palette = settings == null ? null : paletteBlock(settings);
@@ -139,17 +146,17 @@ public final class StiltModule implements IrisModule {
}
/** The block the settings' palette picks for this placement, the same for every column; null without a palette. */
private PlatformBlockState paletteBlock(StiltSettings stilt) {
private BlockState paletteBlock(StiltSettings stilt) {
return stilt.palette()
.map(spec -> placement.data().getPackResources().blocks().palette(spec, rng.getSeed()))
.map(picker -> B.getState(picker.at(placement.x(), anchorY, placement.z()).key()))
.map(spec -> context.resources().blocks().palette(spec, rng.getSeed()))
.map(picker -> picker.at(placement.x(), anchorY, placement.z()))
.orElse(null);
}
private void grow(ObjectBlock block) {
BlockPosition offset = block.position();
PlatformBlockState state = stiltState(block, offset);
if (state == null || !state.isOccluding()) {
BlockState state = stiltState(block, offset);
if (!world.has(state, BlockTrait.OCCLUDING)) {
return;
}
int x = placement.x() + offset.x();
@@ -168,27 +175,27 @@ public final class StiltModule implements IrisModule {
}
/** 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());
private BlockState stiltState(ObjectBlock block, BlockPosition offset) {
BlockState state = block.state();
if (palette != null) {
state = palette;
} else if (SOIL_MATERIALS.contains(IrisObjectShaping.materialKey(state))) {
state = B.getState(SOIL_REPLACEMENT);
} else if (SOIL_MATERIALS.contains(state.material().toString())) {
state = SOIL_REPLACEMENT;
}
state = prepared.rotate(state);
if (config.getEdit().isEmpty() || state == null) {
if (config.edit().isEmpty()) {
return state;
}
return ObjectEdits.apply(config, state, null, rng, offset.x() + placement.x(), offset.y() + anchorY,
offset.z() + placement.z(), placement.data()).data();
return ObjectEdits.apply(config.edit(), state, Optional.empty(), rng, offset.x() + placement.x(), offset.y() + anchorY,
offset.z() + placement.z(), ResolvedReplaces.of(context, prepared.terrain()), placement).data();
}
private void growToSurface(PlatformBlockState state, BlockPosition offset, int x, int z) {
private void growToSurface(BlockState 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)
int highest = prepared.terrain().highest(x, z, true);
if (state.properties().containsKey(BlocksModule.WATERLOGGED)
&& BlocksModule.shouldWaterlog(world, config, placement.requestedY(), x, highest, z)) {
state = state.withProperty(WATERLOGGED, "true");
state = state.withProperty(BlocksModule.WATERLOGGED, BlocksModule.TRUE);
}
int lowerBound = highest - 1;
if (settings != null) {
@@ -201,13 +208,13 @@ public final class StiltModule implements IrisModule {
lowerBound = top - erode.depth(offset, top - lowerBound);
}
for (int y = top; y > lowerBound; y--) {
if (B.isFluid(world.get(x, y, z))) {
if (world.has(world.get(x, y, z), BlockTrait.FLUID)) {
return;
}
if (erode != null && erode.breaksAt(x, y, z, top - y, top - lowerBound)) {
continue;
}
if (B.isVineBlock(state)) {
if (world.has(state, BlockTrait.VINE)) {
state = BlocksModule.attachVineFaces(world, state, x, y, z);
}
world.set(x, y, z, state);
@@ -215,7 +222,7 @@ public final class StiltModule implements IrisModule {
}
/** 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) {
private void growOrganic(BlockState state, int x, int z, int direction) {
int maxScan = settings != null ? Math.max(1, settings.organicMaxScan()) : DEFAULT_ORGANIC_MAX_SCAN;
int jitterMax = settings != null ? Math.max(0, settings.organicJitter()) : DEFAULT_ORGANIC_JITTER;
double scratch = settings != null ? Math.max(0, Math.min(1, settings.organicScratch())) : DEFAULT_ORGANIC_SCRATCH;
@@ -18,20 +18,19 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.anchor.VacuumProfile;
import com.volmit.FeatureRegistry;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.anchor.VacuumProfile;
import art.arcane.iris.builtin.blocks.WrittenBlocks;
import art.arcane.iris.core.modules.IrisPlacement;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.terrain.TerrainPalettes;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import art.arcane.iris.util.project.noise.SimplexNoise;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.placement.PlaneNoise;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.prepare.TransformedBounds;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.StageGraph;
@@ -46,17 +45,14 @@ public final class VacuumModule implements IrisModule {
private static final long HASH_Z = 132897987541L;
private static final int HASH_BUCKETS = 1000;
private static final double HALF = 0.5;
private static final BlockState STONE = new BlockState("minecraft:stone");
private static final BlockState AIR = new BlockState("minecraft:cave_air");
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:vacuum", "Vacuum", PlacementModules.VERSION);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerHeldType(VacuumSettings.class);
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Vacuum.TERRAIN)
@@ -68,47 +64,46 @@ public final class VacuumModule implements IrisModule {
private static void bendTerrain(PlacementStageContext context) {
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
WrittenBlocks written = context.output(IrisStages.Blocks.WRITE);
Engine engine = prepared.terrain().getEngine();
if (!prepared.mode().bendsTerrain() || written.isEmpty() || engine == null) {
if (!prepared.mode().bendsTerrain() || written.isEmpty() || !prepared.terrain().hasWorld()) {
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);
new Bend(context, prepared).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 ObjectPlacement placement;
private final PreparedPlacement prepared;
private final PlacementTerrain terrain;
private final PlacementWorld world;
private final TerrainPalettes palettes;
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 PlaneNoise waves;
private final int lowestY;
private final int highestY;
private Bend(PlacementStageContext context, PreparedPlacement prepared, Engine engine) {
private Bend(PlacementStageContext context, PreparedPlacement prepared) {
VacuumProfile vacuum = prepared.mode().vacuum();
this.placement = IrisPlacement.current();
this.placement = ObjectPlacement.current();
this.prepared = prepared;
this.world = new PlacementWorld(context.access(), placement.states());
this.palettes = engine.getComplex() == null ? null : TerrainPalettes.of(engine);
VacuumSettings settings = prepared.config().getVacuumSettings();
this.terrain = prepared.terrain();
this.world = new PlacementWorld(context.access(), prepared.traits());
VacuumSettings settings = prepared.settings().vacuum().orElse(null);
this.radius = IrisObjectVacuum.resolveRadius(vacuum, settings);
this.step = vacuum.columnStepBlocks();
this.falloff = IrisObjectVacuum.resolveFalloff(settings);
this.jitter = settings != null ? Math.max(0, settings.organicJitter()) : DEFAULT_ORGANIC_JITTER;
this.waveAmplitude = IrisObjectVacuum.resolveWaveAmplitude(settings);
this.waveScale = IrisObjectVacuum.resolveWaveScale(settings);
this.waves = vacuum.edge() == VacuumProfile.Edge.WAVY && waveAmplitude > 0 ? new SimplexNoise(WAVE_SEED) : null;
this.waves = vacuum.edge() == VacuumProfile.Edge.WAVY && waveAmplitude > 0 ? placement.simplex(WAVE_SEED) : null;
this.lowestY = IrisObjectVacuum.LOWEST_TARGET_Y;
this.highestY = engine.getHeight() - 1;
this.highestY = terrain.worldHeight() - 1;
}
private void apply(int baseY, int topY) {
@@ -124,7 +119,7 @@ public final class VacuumModule implements IrisModule {
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 originalY = terrain.highest(x, z, 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) {
@@ -157,13 +152,13 @@ public final class VacuumModule implements IrisModule {
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);
return IrisObjectVacuum.waveOffset(distance, effectiveRadius, waves.signed(x * waveScale, z * waveScale), waveAmplitude);
}
private void raise(int x, int z, int fromY, int toY) {
PlatformBlockState fill = palettes != null ? palettes.rockAt(x, z) : null;
if (B.isAir(fill)) {
fill = IrisObject.States.STONE;
BlockState fill = terrain.rockAt(x, z);
if (world.has(fill, BlockTrait.AIR)) {
fill = STONE;
}
for (int y = fromY + 1; y <= toY; y++) {
world.set(x, y, z, fill);
@@ -172,7 +167,7 @@ public final class VacuumModule implements IrisModule {
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);
world.set(x, y, z, AIR);
}
}
}
@@ -18,17 +18,16 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.validate.ObjectLimit;
import com.volmit.FeatureRegistry;
import art.arcane.iris.builtin.IrisStages;
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.volmlib.util.collection.KList;
import art.arcane.iris.builtin.placement.CaveSpace;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.placement.ObjectShape;
import art.arcane.iris.builtin.placement.PlacementSettings;
import art.arcane.iris.builtin.placement.PlacementTerrain;
import art.arcane.iris.builtin.placement.StructureVolumes;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleLog;
@@ -38,6 +37,7 @@ import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.StageGraph;
import com.volmit.world.BlockPosition;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -56,11 +56,6 @@ public final class ValidateModule implements IrisModule {
return ModuleInfo.of("iris:validate", "Placement checks", PlacementModules.VERSION);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerHeldType(ObjectLimit.class);
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Validate.SURFACE)
@@ -78,59 +73,59 @@ public final class ValidateModule implements IrisModule {
}
private static void checkSurface(PlacementStageContext context) {
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
if (config.isForcePlace() || config.isFromBottom() || prepared.mode().has(PlaceTrait.FREE_HEIGHT)) {
PlacementSettings settings = prepared.settings();
if (settings.forcePlace() || settings.fromBottom() || prepared.mode().has(PlaceTrait.FREE_HEIGHT)) {
return;
}
int y = context.output(IrisStages.Anchor.HEIGHT).y();
boolean sampled = placement.requestedY() < 0;
if (sampled && config.getCarvingSupport().supportsSurface() && isOnBedrock(prepared, y)) {
warnImplausibleBedrockPlacement(placement, config, y, context.log());
if (sampled && settings.carvingSupport().supportsSurface() && isOnBedrock(prepared, y)) {
warnImplausibleBedrockPlacement(placement, settings, y, context.log());
context.reject("bedrock-anchor");
return;
}
boolean surfaceAnchored = sampled ? config.getCarvingSupport().supportsSurface()
: config.getCarvingSupport() == CarvingMode.SURFACE_ONLY;
if (surfaceAnchored && !config.isUnderwater() && !config.isOnwater() && config.isRequireSurfaceSupport()
boolean surfaceAnchored = sampled ? settings.carvingSupport().supportsSurface()
: settings.carvingSupport() == CarvingMode.SURFACE_ONLY;
if (surfaceAnchored && !settings.underwater() && !settings.onwater() && settings.requireSurfaceSupport()
&& 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;
PlacementTerrain terrain = prepared.terrain();
return terrain.hasWorld() && terrain.hasBedrock() && 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 boolean lacksSurfaceSupport(ObjectPlacement placement, PreparedPlacement prepared) {
PlacementSettings settings = prepared.settings();
return IrisSurfaceSupport.isUnsupported(prepared.terrain(), placement.x(), placement.z(), settings.translate(),
prepared.rotation(), prepared.spinX(), prepared.spinY(), prepared.spinZ(),
placement.object().surfaceSupportOffsets(), settings.surfaceSupportBuffer(), settings.surfaceSupportDepth());
}
private static void checkLimits(PlacementStageContext context) {
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
if (config.isForcePlace() || prepared.mode().has(PlaceTrait.RAW_STAMP)) {
PlacementSettings settings = prepared.settings();
if (settings.forcePlace() || prepared.mode().has(PlaceTrait.RAW_STAMP)) {
return;
}
int y = context.output(IrisStages.Anchor.HEIGHT).y();
int rotated = prepared.rotatedCenterY();
int translated = prepared.translatedCenterY();
if (placement.requestedY() < 0 && !prepared.mode().has(PlaceTrait.FREE_HEIGHT) && !config.isUnderwater()
&& !config.isOnwater() && prepared.terrain().isUnderwater(placement.x(), placement.z())) {
Optional<CaveSpace> cave = placement.cave();
if (placement.requestedY() < 0 && !prepared.mode().has(PlaceTrait.FREE_HEIGHT) && !settings.underwater()
&& !settings.onwater() && 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()) {
} else if (cave.isPresent()
&& Math.max(0, placement.object().height() + prepared.randomY() + translated) + 1 >= cave.get().height()) {
context.reject("cave-clearance");
} else if (config.isUnderwater() && y + rotated + translated >= prepared.terrain().getFluidHeight()) {
} else if (settings.underwater() && y + rotated + translated >= prepared.terrain().fluidHeight()) {
context.reject("fluid-height");
} else if (!config.getClamp().canPlace(y + rotated + translated, y - rotated + translated)) {
} else if (!settings.clamp().canPlace(y + rotated + translated, y - rotated + translated)) {
context.reject("height-clamp");
}
}
@@ -141,31 +136,29 @@ public final class ValidateModule implements IrisModule {
return;
}
int y = context.output(IrisStages.Anchor.HEIGHT).y() + prepared.randomY();
if (meetsNativeStructure(context, IrisPlacement.current(), prepared, y)) {
if (meetsNativeStructure(context, ObjectPlacement.current(), prepared, y)) {
context.reject("native-structure");
}
}
private static boolean meetsNativeStructure(PlacementStageContext context, IrisPlacement placement,
private static boolean meetsNativeStructure(PlacementStageContext context, ObjectPlacement placement,
PreparedPlacement prepared, int y) {
Engine engine = prepared.terrain().getEngine();
if (engine == null) {
PlacementTerrain terrain = prepared.terrain();
if (!terrain.hasWorld()) {
return false;
}
int x = placement.x();
int z = placement.z();
int margin = nativeStructureMargin(placement.object(), prepared);
KList<NativeStructureVolume> volumes = engine.getNativeStructureVolumes(x - margin, z - margin, x + margin, z + margin);
if (volumes == null || volumes.isEmpty()) {
StructureVolumes volumes = terrain.structureVolumes(x - margin, z - margin, x + margin, z + margin);
if (volumes.isEmpty()) {
return false;
}
boolean painted = WorldVolume.isPainted(placement, prepared);
int worldY = y + engine.getMinHeight();
int worldY = y + terrain.minHeight();
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) {
if (!volumes.intersects(x - margin, envelopeMinY, z - margin, x + margin, envelopeMaxY, z + margin)) {
return false;
}
for (ObjectBlock block : context.request().object().blocks()) {
@@ -176,22 +169,20 @@ public final class ValidateModule implements IrisModule {
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())
? offset.y() + Math.floorDiv(placement.object().height(), 2)
+ terrain.highest(blockX, blockZ, prepared.settings().underwater())
: y + offset.y();
int worldBlockY = blockY + engine.getMinHeight();
for (NativeStructureVolume volume : volumes) {
if (volume.containsWithin(blockX, worldBlockY, blockZ, prepared.warpMargin())) {
return true;
}
int worldBlockY = blockY + terrain.minHeight();
if (volumes.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();
private static int nativeStructureMargin(ObjectShape object, PreparedPlacement prepared) {
int margin = (Math.max(object.width(), Math.max(object.height(), object.depth())) / 2) + 1 + prepared.warpMargin();
if (prepared.translation() == null) {
return margin;
}
@@ -204,33 +195,25 @@ public final class ValidateModule implements IrisModule {
}
private static void checkCollisions(PlacementStageContext context) {
IrisPlacement placement = IrisPlacement.current();
ObjectPlacement placement = ObjectPlacement.current();
PreparedPlacement prepared = context.output(IrisStages.Prepare.TRANSFORMS);
IrisObjectPlacement config = prepared.config();
if (config.isForcePlace() || prepared.mode().has(PlaceTrait.RAW_STAMP)
|| (config.getAllowedCollisions().isEmpty() && config.getForbiddenCollisions().isEmpty())) {
PlacementSettings settings = prepared.settings();
if (settings.forcePlace() || prepared.mode().has(PlaceTrait.RAW_STAMP)
|| (settings.allowedCollisions().isEmpty() && settings.forbiddenCollisions().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(IrisStages.Anchor.HEIGHT).y() + prepared.randomY());
if (collidesWithForbiddenObject(engine, config, volume)) {
if (collidesWithForbiddenObject(prepared.terrain(), settings, volume)) {
context.reject("object-collision");
}
}
private static boolean collidesWithForbiddenObject(Engine engine, IrisObjectPlacement config, WorldVolume volume) {
private static boolean collidesWithForbiddenObject(PlacementTerrain terrain, PlacementSettings settings, 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)) {
String key = terrain.objectKeyAt(x, y, z);
if (key != null && settings.forbiddenCollisions().contains(key) && !settings.allowedCollisions().contains(key)) {
return true;
}
}
@@ -239,9 +222,9 @@ public final class ValidateModule implements IrisModule {
return false;
}
private static void warnImplausibleBedrockPlacement(IrisPlacement placement, IrisObjectPlacement config, int y, ModuleLog log) {
String key = placement.object().getLoadKey();
String fingerprint = (key == null ? "<null>" : key) + "|" + config.getMode();
private static void warnImplausibleBedrockPlacement(ObjectPlacement placement, PlacementSettings settings, int y, ModuleLog log) {
String key = placement.object().key();
String fingerprint = (key == null ? "<null>" : key) + "|" + settings.mode();
long now = System.currentTimeMillis();
Long last = IMPLAUSIBLE_BEDROCK_WARNS.get(fingerprint);
if (last != null && now - last < IMPLAUSIBLE_BEDROCK_WARN_THROTTLE_MS) {
@@ -250,8 +233,8 @@ public final class ValidateModule implements IrisModule {
IMPLAUSIBLE_BEDROCK_WARNS.put(fingerprint, now);
log.warn("Implausible object placement rejected: "
+ (key == null ? "<no loadKey>" : key)
+ " resolved anchorY=" + y + " at (" + placement.x() + "," + placement.z() + ") mode=" + config.getMode()
+ " carving=" + config.getCarvingSupport()
+ " resolved anchorY=" + y + " at (" + placement.x() + "," + placement.z() + ") mode=" + settings.mode()
+ " carving=" + settings.carvingSupport()
+ ". 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.");
@@ -19,14 +19,16 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.anchor.AnchorSampling;
import art.arcane.iris.core.modules.IrisPlacement;
import art.arcane.iris.builtin.placement.ObjectPlacement;
import art.arcane.iris.builtin.prepare.PreparedPlacement;
import art.arcane.iris.builtin.prepare.TransformedBounds;
/**
* 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) {
static WorldVolume of(ObjectPlacement placement, PreparedPlacement prepared, int anchorY) {
TransformedBounds bounds = prepared.bounds();
int minX = placement.x() + bounds.minX();
int maxX = placement.x() + bounds.maxX();
@@ -39,18 +41,18 @@ record WorldVolume(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
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());
int surface = prepared.terrain().highest(x, z, prepared.settings().underwater());
lowestSurface = Math.min(lowestSurface, surface);
highestSurface = Math.max(highestSurface, surface);
}
}
int paintOffset = Math.floorDiv(placement.object().h, 2);
int paintOffset = Math.floorDiv(placement.object().height(), 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) {
static boolean isPainted(ObjectPlacement placement, PreparedPlacement prepared) {
return placement.requestedY() < 0 && prepared.mode().anchor() == AnchorSampling.SURFACE;
}
}