mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
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:
commit
f7e8b74745
35 files changed
+1190
-570
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package art.arcane.iris.builtin.prepare;
|
||||
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
|
||||
/**
|
||||
* Precomputed vector rotation for a single placement.
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
||||
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;
|
||||
|
||||
private final ObjectRotation rotation;
|
||||
|
||||
private final int xMode;
|
||||
private final int yMode;
|
||||
private final int zMode;
|
||||
private final double xCos;
|
||||
private final double xSin;
|
||||
private final double yCos;
|
||||
private final double ySin;
|
||||
private final double zCos;
|
||||
private final double zSin;
|
||||
|
||||
public ObjectSpinKernel(ObjectRotation rotation, int spinX, int spinY, int spinZ) {
|
||||
this.rotation = rotation;
|
||||
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);
|
||||
zSin = Math.sin(zAngle);
|
||||
yCos = Math.cos(yAngle);
|
||||
ySin = Math.sin(yAngle);
|
||||
}
|
||||
|
||||
private static int modeOf(AxisRotationClamp clamp) {
|
||||
if (!clamp.isLocked()) {
|
||||
return MODE_ANGLE;
|
||||
}
|
||||
|
||||
if (Math.abs(clamp.max()) % 360D == 180D) {
|
||||
return MODE_FLIP;
|
||||
}
|
||||
|
||||
if (clamp.max() % 360D == 90D || clamp.max() % 360D == -270D) {
|
||||
return MODE_QUARTER;
|
||||
}
|
||||
|
||||
if (clamp.max() == -90D || clamp.max() % 360D == 270D) {
|
||||
return MODE_THREE_QUARTER;
|
||||
}
|
||||
|
||||
return MODE_ANGLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates in place. Axis order (X, then Z, then Y) is load bearing.
|
||||
*/
|
||||
public void rotate(IrisBlockVector v) {
|
||||
if (!rotation.canRotate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (xMode) {
|
||||
case MODE_FLIP -> {
|
||||
v.setZ(-v.getZ());
|
||||
v.setY(-v.getY());
|
||||
}
|
||||
case MODE_QUARTER -> {
|
||||
double z = v.getZ();
|
||||
v.setZ(v.getY());
|
||||
v.setY(-z);
|
||||
}
|
||||
case MODE_THREE_QUARTER -> {
|
||||
double z = v.getZ();
|
||||
v.setZ(-v.getY());
|
||||
v.setY(z);
|
||||
}
|
||||
case MODE_ANGLE -> {
|
||||
double y = xCos * v.getY() - xSin * v.getZ();
|
||||
double z = xSin * v.getY() + xCos * v.getZ();
|
||||
v.setY(y);
|
||||
v.setZ(z);
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
|
||||
switch (zMode) {
|
||||
case MODE_FLIP -> {
|
||||
v.setY(-v.getY());
|
||||
v.setX(-v.getX());
|
||||
}
|
||||
case MODE_QUARTER -> {
|
||||
double y = v.getY();
|
||||
v.setY(v.getX());
|
||||
v.setX(-y);
|
||||
}
|
||||
case MODE_THREE_QUARTER -> {
|
||||
double y = v.getY();
|
||||
v.setY(-v.getX());
|
||||
v.setX(y);
|
||||
}
|
||||
case MODE_ANGLE -> {
|
||||
double x = zCos * v.getX() - zSin * v.getY();
|
||||
double y = zSin * v.getX() + zCos * v.getY();
|
||||
v.setX(x);
|
||||
v.setY(y);
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
|
||||
switch (yMode) {
|
||||
case MODE_FLIP -> {
|
||||
v.setX(-v.getX());
|
||||
v.setZ(-v.getZ());
|
||||
}
|
||||
case MODE_QUARTER -> {
|
||||
double x = v.getX();
|
||||
v.setX(v.getZ());
|
||||
v.setZ(-x);
|
||||
}
|
||||
case MODE_THREE_QUARTER -> {
|
||||
double x = v.getX();
|
||||
v.setX(-v.getZ());
|
||||
v.setZ(x);
|
||||
}
|
||||
case MODE_ANGLE -> {
|
||||
double x = yCos * v.getX() + ySin * v.getZ();
|
||||
double z = -ySin * v.getX() + yCos * v.getZ();
|
||||
v.setX(x);
|
||||
v.setZ(z);
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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.prepare;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.PlaceMode;
|
||||
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.PlacementSettings;
|
||||
import art.arcane.iris.builtin.placement.PlacementTerrain;
|
||||
import art.arcane.iris.builtin.placement.SurfaceWarp;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
/**
|
||||
* 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 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;
|
||||
private final int spinZ;
|
||||
private final IrisBlockVector translation;
|
||||
private final int rotatedCenterY;
|
||||
private final int translatedCenterY;
|
||||
private final int randomY;
|
||||
private final int warpMargin;
|
||||
private final TransformedBounds bounds;
|
||||
private final SurfaceWarp surfaceWarp;
|
||||
|
||||
/** 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;
|
||||
this.spinY = spinY;
|
||||
this.spinZ = spinZ;
|
||||
this.translation = translation;
|
||||
this.rotatedCenterY = rotatedCenterY;
|
||||
this.translatedCenterY = translatedCenterY;
|
||||
this.randomY = randomY;
|
||||
this.warpMargin = warpMargin;
|
||||
this.bounds = bounds;
|
||||
this.surfaceWarp = surfaceWarp;
|
||||
}
|
||||
|
||||
/** The settings 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. */
|
||||
public PlacementTerrain terrain() {
|
||||
return terrain;
|
||||
}
|
||||
|
||||
public PlaceMode mode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public int spinX() {
|
||||
return spinX;
|
||||
}
|
||||
|
||||
public int spinY() {
|
||||
return spinY;
|
||||
}
|
||||
|
||||
public int spinZ() {
|
||||
return spinZ;
|
||||
}
|
||||
|
||||
/** The rotated translation, or null when the placement does not translate. */
|
||||
public IrisBlockVector translation() {
|
||||
return translation;
|
||||
}
|
||||
|
||||
/** The height of the object's center after rotation. */
|
||||
public int rotatedCenterY() {
|
||||
return rotatedCenterY;
|
||||
}
|
||||
|
||||
/** The height of the object's center after translation. */
|
||||
public int translatedCenterY() {
|
||||
return translatedCenterY;
|
||||
}
|
||||
|
||||
/** The random height offset added once the anchor is final. */
|
||||
public int randomY() {
|
||||
return randomY;
|
||||
}
|
||||
|
||||
public int warpMargin() {
|
||||
return warpMargin;
|
||||
}
|
||||
|
||||
public TransformedBounds bounds() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
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. */
|
||||
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. */
|
||||
public BlockPosition transform(BlockPosition local) {
|
||||
IrisBlockVector offset = new IrisBlockVector(local.x(), local.y(), local.z());
|
||||
spin.rotate(offset);
|
||||
if (mode().has(PlaceTrait.UPSIDE_DOWN)) {
|
||||
offset.setY(-offset.getBlockY());
|
||||
}
|
||||
if (translation != null) {
|
||||
offset.add(translation);
|
||||
}
|
||||
return new BlockPosition((int) Math.round(offset.getX()), (int) Math.round(offset.getY()), (int) Math.round(offset.getZ()));
|
||||
}
|
||||
|
||||
/** A block state turned with the object, so stairs and logs face the way the object does. */
|
||||
public BlockState rotate(BlockState state) {
|
||||
return placement.rotate(state, rotation, spinX, spinY, spinZ);
|
||||
}
|
||||
}
|
||||
@@ -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.prepare;
|
||||
|
||||
/** The bounds of a transformed object around its anchor, inclusive, widened by the surface warp along X and Z. */
|
||||
public record TransformedBounds(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
|
||||
}
|
||||
Reference in new issue
Block a user