Merge branch 'wave3b/2'

# Conflicts:
#	builtin-modules.txt
#	src/main/java/art/arcane/iris/builtin/package-info.java
#	src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java
#	src/main/java/art/arcane/iris/engine/object/terrain/floating/ResolvedFloatingChild.java
#	src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java
#	src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiomeColorRenderer.java
#	src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java
#	src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java
This commit is contained in:
piexel committed 2026-10-15 07:29:06 +02:00
commit c3ed24364f
68 files changed
+4024 -2488

No files matched your search

+10
View File
@@ -50,6 +50,16 @@ Object place modes are data (`PlaceMode`: height sampling,
stilt, `VacuumProfile`, `PlaceTrait`s) that the placement stages ask; the pack JSON keeps the mode names.
`iris:objects` also provides `SaplingGrowth` (`TreeGrowing`: the tree a sapling grows into, as placed blocks, and which
objects are trees) and says which biomes and regions place an object (`ObjectLocating`, for the object search).
`iris:objects` ships in the built-ins jar. It declares the settings `objects` (region, biome: the list of `ObjectPlacement`s),
`proceduralObjects` (region, biome), `treeSettings` (dimension), `requireObjectSurfaceSupport`, `objectSurfaceSupportBuffer`,
`upperDimensionObjects` and `upperObjectsForcePlace` (dimension), all written as they always were. `ObjectPlacement` describes
the same JSON as Iris's `IrisObjectPlacement` and keeps the JSON it was read from, because Iris's placement stages still read
a placement as their own class (`ObjectPlacements.host`). What a jar cannot do, Iris does through the facades `ObjectHost` and
`ObjectChunk` in `art.arcane.iris.builtin.objects`: loading and scaling the pack's objects, placing one with the placement
stages into the chunk's mantle (on the surface, in a cave inside the cave's bounds, or hung from the terrain above), reading the
carved space the cave carver planned, and the layout around a position. `ObjectPlacing` and its helpers (`ChunkObjectPlacing`,
`CaveAnchors`, `PlacementReach`) decide what to place and where. The procedural generators (`engine/object/procedural`) stay
compiled in, behind `ProceduralPlacement`, until they build `GeneratedObject`s instead of Iris objects.
`iris:loot` owns the loot table resource kind (`LootResources`, folder `loot`), checks the tables and the references to
them (`LootValidator`), and provides `Loot` (`LootGiving`: which tables a container draws from and the `ItemDrop`s a
table gives) and `BlockDrops` (`BlockDropping`). `iris:spawn` owns spawners, entities and markers (`SpawnResources`,
+11
View File
@@ -72,3 +72,14 @@ module art.arcane.iris.engine.actuator.TerrainModule
include art/arcane/iris/engine/actuator/Terrain*.class
include art/arcane/iris/engine/actuator/ResolvedOre*.class
include art/arcane/iris/engine/actuator/OreWarmUp*.class
module art.arcane.iris.engine.mantle.components.ObjectModule
include art/arcane/iris/engine/mantle/components/ObjectPlacing*.class
include art/arcane/iris/engine/mantle/components/ChunkObjectPlacing*.class
include art/arcane/iris/engine/mantle/components/CaveAnchors*.class
include art/arcane/iris/engine/mantle/components/CaveSettings*.class
include art/arcane/iris/engine/mantle/components/CaveRejects*.class
include art/arcane/iris/engine/mantle/components/EffectivePlacements*.class
include art/arcane/iris/engine/mantle/components/PlacementReach*.class
include art/arcane/iris/engine/mantle/components/ObjectWarmUp*.class
include art/arcane/iris/engine/mantle/components/ObjectLocating*.class
include art/arcane/iris/engine/mantle/components/TreeGrowing*.class
@@ -0,0 +1,33 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import java.util.Optional;
/** The voids the cave carver planned in the mantle around the chunk being placed, which cave objects anchor in. */
public interface CarvedSpace {
/** Whether the position is carved. */
boolean isCarved(int x, int y, int z);
/** Whether each height from 0 up to {@code height} is carved at the column, 1 for carved and 0 for not. */
byte[] column(int x, int z, int height);
/** The void at the position; empty where nothing was carved. */
Optional<Cavern> cavernAt(int x, int y, int z);
}
@@ -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.objects;
/**
* The outcome of placing an object in a cave.
*
* @param resultY the height the object was placed at, negative when the placement rejected it
* @param commit what became of the blocks the object wrote
*/
public record CavePlacement(int resultY, Commit commit) {
public enum Commit {
/** The blocks were written. */
COMMITTED,
/** The object wrote no blocks, or the placement was rejected. */
EMPTY,
/** Some block lay outside the cave, so nothing was written. */
REJECTED_BOUNDS
}
public boolean wroteBlocks() {
return commit == Commit.COMMITTED;
}
}
@@ -0,0 +1,29 @@
/*
* 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.objects;
/**
* A carved void of the mantle, as the cave carver left it.
*
* @param air whether the void holds air
* @param liquid the carver's liquid code for the void; {@link #FORCED_AIR_LIQUID} means air that stays air
*/
public record Cavern(boolean air, byte liquid) {
public static final byte FORCED_AIR_LIQUID = 3;
}
@@ -0,0 +1,136 @@
/*
* 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.objects;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinItems;
import com.volmit.config.MinNumber;
import com.volmit.config.Required;
import com.volmit.config.Snippet;
import com.volmit.noise.NoiseStyle;
import java.util.Collections;
import java.util.List;
/** The virtual heightmap an object placement may sit on instead of the terrain, written as the placement's {@code heightmap}. */
@Snippet("generator")
@Desc("A noise generator")
public final class HeightmapNoise {
@MinNumber(0.0001)
@Desc("The coordinate input zoom")
private double zoom = 1;
@Desc("Reverse the output. So that noise = -noise + opacity")
private boolean negative = false;
@MinNumber(0)
@MaxNumber(1)
@Desc("The output multiplier")
private double opacity = 1;
@Desc("Coordinate offset x")
private double offsetX = 0;
@Desc("Height output offset y. Avoid using with terrain generation.")
private double offsetY = 0;
@Desc("Coordinate offset z")
private double offsetZ = 0;
@Required
@Desc("The seed")
private long seed = 0;
@Desc("Apply a parametric curve on the output")
private boolean parametric = false;
@Desc("Apply a bezier curve on the output")
private boolean bezier = false;
@Desc("Apply a sin-center curve on the output (0, and 1 = 0 and 0.5 = 1.0 using a sinoid shape.)")
private boolean sinCentered = false;
@Desc("The exponent noise^EXPONENT")
private double exponent = 1;
@Desc("Enable / disable. Outputs offsetY if disabled")
private boolean enabled = true;
@Required
@Desc("The Noise Style")
private NoiseStyle style = NoiseStyle.of("IRIS");
@MinNumber(1)
@Desc("Multiple octaves for multple generators of changing zooms added together")
private int octaves = 1;
@MinItems(1)
@Desc("Apply a child noise generator to fracture the input coordinates of this generator")
private List<HeightmapNoise> fracture = List.of();
public HeightmapNoise() {
}
public double zoom() {
return zoom;
}
public boolean negative() {
return negative;
}
public double opacity() {
return opacity;
}
public double offsetX() {
return offsetX;
}
public double offsetY() {
return offsetY;
}
public double offsetZ() {
return offsetZ;
}
public long seed() {
return seed;
}
public boolean parametric() {
return parametric;
}
public boolean bezier() {
return bezier;
}
public boolean sinCentered() {
return sinCentered;
}
public double exponent() {
return exponent;
}
public boolean enabled() {
return enabled;
}
public NoiseStyle style() {
return style;
}
public int octaves() {
return octaves;
}
public List<HeightmapNoise> fracture() {
return fracture == null ? List.of() : Collections.unmodifiableList(fracture);
}
}
@@ -0,0 +1,56 @@
/*
* 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.objects;
import art.arcane.volmlib.util.math.RNG;
/**
* The chunk whose mantle {@code iris:objects} is placing into: the one place objects are written. Every placement here
* runs Iris's placement stages, so it is what a pack's {@code objects} get when they are placed anywhere. Reached through
* {@link ObjectHost#chunk()} from a mantle stage.
*/
public interface ObjectChunk {
/** The voids the cave carver planned around the chunk. */
CarvedSpace carved();
/** Whether the golden-debug switch is on for the chunk, which logs every decision of its placements. */
boolean goldenDebug(int chunkX, int chunkZ);
/**
* Places an object on the terrain, where it sits at the height its place mode finds.
*
* @param goldenTag logs the placer's questions under this tag, or null to leave them
* @return the height the object was placed at, negative when the placement rejected it
*/
int placeOnSurface(PlaceableObject object, int x, int z, PlacementSource placement, PlacementChanges changes,
PlacementTags tags, RNG rng, String goldenTag);
/**
* Places an object in a cave, anchored at {@code anchorY}, and writes it only when all of it lies inside the cave and
* no deeper than {@code minDepthBelowSurface} under the surface.
*
* @param goldenTag logs the placer's questions under this tag, or null to leave them
*/
CavePlacement placeInCave(PlaceableObject object, int x, int anchorY, int z, PlacementSource placement, PlacementChanges changes,
int minDepthBelowSurface, PlacementTags tags, RNG rng, String goldenTag);
/** Places an object at a given height, which the terrain stacked above uses for the objects hung from it. */
int placeUpper(PlaceableObject object, int x, int anchorY, int z, ObjectPlacement placement, PlacementChanges changes,
PlacementTags tags, RNG rng);
}
@@ -0,0 +1,125 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings;
import com.volmit.config.PackSettings;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import java.util.List;
import java.util.Optional;
/**
* What {@code iris:objects} asks of Iris: the objects of the pack, how Iris scales and places them, and the layout around
* a world position. Iris's worlds implement it; a module reaches it with {@link #of}. Nothing here hands out the engine.
*/
public interface ObjectHost {
/** The host of the world {@code settings} are the pack's of, which must be a world Iris generates. */
static ObjectHost of(PackSettings settings) {
if (settings instanceof Source source) {
return source.objects();
}
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + settings);
}
/** The host of {@code world}, which must be a world Iris generates. */
static ObjectHost of(PackWorld world) {
if (world instanceof Source source) {
return source.objects();
}
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
}
/** Whether Iris's debug setting is on. */
boolean debugging();
/** The height, above the dimension's bottom, up to which caves are filled with lava. */
int caveLavaHeight();
/** The height of the dimension's fluid. */
int fluidHeight();
/** The settings that apply at a world column, for work outside a chunk's generation. */
FeatureSettings columnSettings();
/** The random a chunk's objects are placed with: the same for the same chunk of the same world. */
RNG chunkRandom(int chunkX, int chunkZ);
/** The chunk whose objects are being placed on this thread. */
ObjectChunk chunk();
/** The object of the pack that {@code key} names. */
Optional<PlaceableObject> object(String key);
/** An object of the placement, picked with {@code rng} and scaled the way the placement scales it; empty when it has none. */
Optional<PlaceableObject> pickScaled(ObjectPlacement placement, RNG rng);
/** How many objects the placement places at the column, when its chance check passes. */
int density(ObjectPlacement placement, RNG rng, double x, double z);
/** The size of the pack's object, read without loading its blocks; empty when the pack has no such object. */
Optional<ObjectSize> sizeOf(String objectKey);
/** Builds what placing the placement would build on first use, so the first chunk to place it does not wait. */
void warm(ObjectPlacement placement, RNG rng);
/** The procedural objects {@code settings} declare, made placeable once. */
List<ProceduralPlacement> procedural(ProceduralObjectSettings settings);
/** The object settings of the biome and the region of the dimension stacked above, at the column; none where nothing sits above. */
Optional<UpperObjects> upperObjects(int worldX, int worldZ);
/** Places the object into {@code sink}, which is outside any chunk's generation, such as a growing sapling's tree. */
int placeInto(PlaceableObject object, int x, int y, int z, ObjectPlacement placement, ObjectSink sink, RNG rng);
/** The region at the column. */
ResourceId regionAt(int worldX, int worldZ);
/** The surface biome at the column. */
ResourceId surfaceBiomeAt(int worldX, int worldZ);
/** The biome at the position, which is the cave biome underground. */
ResourceId biomeAt(int worldX, int y, int worldZ);
/** The settings the biome declares itself, whichever column it is found at; empty when it declares none. */
<F extends IrisFeature> Optional<F> biomeDeclaration(ResourceId biome, Class<F> type);
/** The settings the region declares itself; empty when it declares none. */
<F extends IrisFeature> Optional<F> regionDeclaration(ResourceId region, Class<F> type);
/** Every region and every reachable biome that declares the settings, by the key the pack knows it by, regions first. */
<F extends IrisFeature> List<Declaration<F>> declarations(Class<F> type);
/** What the dimension stacked above declares to place at a column, where each is null when its level declares none. */
record UpperObjects(ObjectSettings biome, ObjectSettings region, String biomeKey, String regionKey) {
}
/** Iris's worlds answer for their objects. */
interface Source {
ObjectHost objects();
}
/** One region's or biome's declaration of settings. */
record Declaration<F extends IrisFeature>(Target level, String key, F settings) {
}
}
@@ -0,0 +1,323 @@
/*
* 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.objects;
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.carve.CaveAnchorMode;
import art.arcane.iris.builtin.loot.ObjectLoot;
import art.arcane.iris.builtin.loot.ObjectVanillaLoot;
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.spawn.PlacementMarker;
import art.arcane.iris.builtin.stilt.StiltSettings;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import art.arcane.iris.builtin.validate.ObjectLimit;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinItems;
import com.volmit.config.MinNumber;
import com.volmit.config.Ref;
import com.volmit.config.Reference;
import com.volmit.config.Required;
import com.volmit.config.Snippet;
import com.volmit.noise.NoiseStyle;
import com.volmit.noise.StyledRange;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* One object placement of a biome or region, an entry of its {@code objects}: which objects, how often, and how they sit
* in the world. {@code iris:objects} decides from the options it owns (what to place, chance, density, carving and
* surface support); Iris's placement stages read the rest from the placement itself, so this keeps the JSON the placement
* was written as ({@link #json()}) for Iris to read it again the way it reads placements everywhere else.
*/
@Snippet("object-placer")
@Desc("Represents an iris object placer. It places objects.")
@JsonAdapter(ObjectPlacement.KeepingItsJson.class)
public final class ObjectPlacement implements PlacementSource {
private static final int DEFAULT_SURFACE_SUPPORT_BUFFER = 2;
private static final int DEFAULT_SURFACE_SUPPORT_DEPTH = 2;
@Required
@MinItems(1)
@Ref(Reference.PACK_OBJECT)
@Desc("List of objects to place")
private List<String> place = List.of();
@Desc("Rotate this objects placement")
private ObjectRotation rotation = new ObjectRotation();
@Desc("Limit the max height or min height of placement.")
private ObjectLimit clamp = new ObjectLimit();
@MinNumber(0)
@MaxNumber(1)
@Desc("The maximum layer level of a snow filter overtop of this placement. Set to 0 to disable. Max of 1.")
private double snow = 0;
@Desc("Whether or not this object can be targeted by a dolphin.")
private boolean isDolphinTarget = false;
@Desc("The slope at which this object can be placed. Range from 0 to 10 by default. Calculated from a 3-block radius from the center of the object placement.")
private SlopeClip slopeCondition = new SlopeClip();
@Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object." +
"Rounded to 90 degrees. Adds the *min* rotation of the y axis as well (to still allow you to rotate objects nicely). Discards *max* and *interval* on *yaxis*")
private boolean rotateTowardsSlope = false;
@MinNumber(0)
@MaxNumber(1)
@Desc("The chance for this to place in a chunk. If you need multiple per chunk, set this to 1 and use density.")
private double chance = 1;
@MinNumber(1)
@Desc("If the chance check passes, place this many in a single chunk")
private int density = 1;
@Desc("If the chance check passes, and you specify this, it picks a number in the range based on noise, and 'density' is ignored.")
private StyledRange densityStyle = null;
@Desc("When stilting is enabled, this object will define various properties related to it.")
private StiltSettings stiltSettings;
@Desc("When a VACUUM place mode is used, this defines the deformation radius and falloff.")
private VacuumSettings vacuumSettings;
@MaxNumber(64)
@MinNumber(0)
@Desc("When bore is enabled, expand max-y of the cuboid it removes")
private int boreExtendMaxY = 0;
@MinItems(1)
@Desc("Add markers to blocks in this object")
private List<PlacementMarker> markers = List.of();
@MaxNumber(64)
@MinNumber(-1)
@Desc("When bore is enabled, lower min-y of the cuboid it removes")
private int boreExtendMinY = 0;
@Desc("If set to true, objects will place on the terrain height, ignoring the water surface.")
private boolean underwater = false;
@Desc("If set to true, objects will place in carvings (such as underground) or under an overhang.")
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
@MinNumber(0)
@MaxNumber(16)
@Desc("Extra buffer, in blocks, around this object's base footprint that must also be solid, un-carved ground. 0 checks only the footprint itself.")
private int surfaceSupportBuffer = DEFAULT_SURFACE_SUPPORT_BUFFER;
@MinNumber(1)
@MaxNumber(16)
@Desc("Minimum thickness, in blocks, of un-carved ground required under every column of this object's base footprint.")
private int surfaceSupportDepth = DEFAULT_SURFACE_SUPPORT_DEPTH;
@Desc("Set to false to let this placement sit over carved surface openings such as cave entrances.")
private boolean requireSurfaceSupport = true;
@Desc("When carving placement is enabled, select which carved-space anchor this placement targets.")
private CaveAnchorMode caveAnchorMode = CaveAnchorMode.PROFILE_DEFAULT;
@Desc("If this is defined, this object wont place on the terrain heightmap, but instead on this virtual heightmap")
private HeightmapNoise heightmap;
@Desc("If set to true, Iris will try to fill the insides of 'rooms' and 'pockets' where air should fit based off of raytrace checks. This prevents a village house placing in an area where a tree already exists, and instead replaces the parts of the tree where the interior of the structure is. \n\nThis operation does not affect warmed-up generation speed however it does slow down loading objects.")
private boolean smartBore = false;
@Desc("If set to true, Blocks placed underwater that could be waterlogged are waterlogged.")
private boolean waterloggable = false;
@Desc("If set to true, objects will place on the fluid height level Such as boats.")
private boolean onwater = false;
@Desc("If set to true, this object will only place parts of itself where blocks already exist. Warning: Melding is very performance intensive!")
private boolean meld = false;
@Desc("If set to true, this object will get placed from the bottom of the world up")
private boolean fromBottom;
@Desc("If set to true, this object will place from the ground up instead of height checks when not y locked to the surface. This is not compatable with X and Z axis rotations (it may look off)")
private boolean bottom = false;
@Desc("If set to true, air will be placed before the schematic places.")
private boolean bore = false;
@Desc("Use a generator to warp the field of coordinates. Using simplex for example would make a square placement warp like a flag")
private NoiseStyle warp = NoiseStyle.of(NoiseStyle.FLAT);
@Desc("The placement mode")
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
@MinItems(1)
@Desc("Find and replace blocks")
private List<ObjectReplace> edit = List.of();
@Desc("Translate this object's placement")
private ObjectTranslate translate = new ObjectTranslate();
@Desc("Scale Objects")
private ObjectScale scale = new ObjectScale();
@MinItems(1)
@Desc("The loot tables to apply to these objects")
private List<ObjectLoot> loot = List.of();
@MinItems(1)
@Desc("The vanilla loot tables to apply to these objects")
private List<ObjectVanillaLoot> vanillaLoot = List.of();
@Desc("Whether the given loot tables override any and all other loot tables available in the dimension, region or biome.")
private boolean overrideGlobalLoot = false;
@MinItems(1)
@Desc("This object / these objects override the following trees when they grow...")
private List<TreeOverride> trees = List.of();
@MinItems(1)
@Ref(Reference.PACK_OBJECT)
@Desc("List of objects to this object is allowed to collied with")
private List<String> allowedCollisions = List.of();
@MinItems(1)
@Ref(Reference.PACK_OBJECT)
@Desc("List of objects to this object is forbidden to collied with")
private List<String> forbiddenCollisions = List.of();
@Desc("Ignore any placement restrictions for this object")
@SerializedName(value = "forcePlace", alternate = {"force"})
private boolean forcePlace = false;
private transient volatile String json;
private transient volatile Object hostForm;
public ObjectPlacement() {
}
/** The objects to pick from, by the keys of the pack's objects. */
public List<String> place() {
return place == null ? List.of() : Collections.unmodifiableList(place);
}
@Override
public double chance() {
return chance;
}
/** The count of placements when the chance check passes, unless {@link #densityStyle()} picks it. */
public int density() {
return density;
}
public Optional<StyledRange> densityStyle() {
return Optional.ofNullable(densityStyle);
}
/** The fixed density, or, when a style picks the count, the middle of its range. */
public int middleDensity() {
if (densityStyle == null) {
return density;
}
return (int) ((densityStyle.max() + densityStyle.min()) / 2);
}
public ObjectRotation rotation() {
return rotation;
}
public ObjectTranslate translate() {
return translate;
}
public ObjectScale scale() {
return scale;
}
public NoiseStyle warp() {
return warp;
}
@Override
public ObjectPlaceMode mode() {
return mode;
}
public Optional<VacuumSettings> vacuumSettings() {
return Optional.ofNullable(vacuumSettings);
}
@Override
public CarvingMode carvingSupport() {
return carvingSupport;
}
@Override
public CaveAnchorMode caveAnchorMode() {
return caveAnchorMode;
}
@Override
public boolean underwater() {
return underwater;
}
@Override
public boolean isDolphinTarget() {
return isDolphinTarget;
}
public boolean forcePlace() {
return forcePlace;
}
@Override
public boolean requireSurfaceSupport() {
return requireSurfaceSupport;
}
@Override
public int surfaceSupportBuffer() {
return surfaceSupportBuffer;
}
public List<TreeOverride> trees() {
return trees == null ? List.of() : Collections.unmodifiableList(trees);
}
/** The JSON this placement was read from, which Iris reads again as its own placement; null for one made in code. */
public String json() {
return json;
}
/**
* What Iris made of {@link #json()} the last time it asked, kept here so it asks once. Only Iris sets or reads it,
* and it is its own type.
*/
public Object hostForm() {
return hostForm;
}
public void hostForm(Object form) {
this.hostForm = form;
}
/** Reads a placement like any settings and keeps the JSON it was read from. */
public static final class KeepingItsJson implements TypeAdapterFactory {
@Override
@SuppressWarnings("unchecked") // The type is checked to be ObjectPlacement.
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (type.getRawType() != ObjectPlacement.class) {
return null;
}
TypeAdapter<ObjectPlacement> placements = gson.getDelegateAdapter(this, TypeToken.get(ObjectPlacement.class));
TypeAdapter<JsonElement> elements = gson.getAdapter(JsonElement.class);
return (TypeAdapter<T>) new TypeAdapter<ObjectPlacement>() {
@Override
public void write(JsonWriter out, ObjectPlacement placement) throws IOException {
placements.write(out, placement);
}
@Override
public ObjectPlacement read(JsonReader in) throws IOException {
JsonElement written = elements.read(in);
ObjectPlacement placement = placements.fromJsonTree(written);
if (placement != null) {
placement.json = written.toString();
}
return placement;
}
}.nullSafe();
}
}
}
@@ -0,0 +1,85 @@
/*
* 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.objects;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.Snippet;
/** How an object placement scales its objects, written as the placement's {@code scale}. */
@Snippet("object-scale")
@Desc("Scale Objects")
public final class ObjectScale {
private static final double NO_SCALE = 1;
@MinNumber(0.01)
@MaxNumber(50)
@Desc("Fixed scale multiplier for this object. 0.5 shrinks to half size, 2.0 doubles the size. When set to anything other than 1, this overrides minimumScale and maximumScale. Leave at 1 to use the minimumScale/maximumScale range.")
private double size = NO_SCALE;
@MinNumber(1)
@MaxNumber(32)
@Desc("Iris Objects are scaled and cached to speed up placements. Because of this extra memory is used, so we evenly distribute variations across the defined scale range, then pick one randomly. If the differences is small, use a lower number. For more possibilities on the scale spectrum, increase this at the cost of memory.")
private int variations = 7;
@MinNumber(0.01)
@MaxNumber(50)
@Desc("The minimum scale. Used when size is 1 to pick a random scale per placement.")
private double minimumScale = NO_SCALE;
@MinNumber(0.01)
@MaxNumber(50)
@Desc("The maximum scale. Used when size is 1 to pick a random scale per placement.")
private double maximumScale = NO_SCALE;
@Desc("If this object is scaled up beyond its origin size, specify a 3D interpolator. NONE keeps blocky scaled output, TRILINEAR (LERP) smooths with linear interpolation, TRICUBIC and TRIHERMITE produce smoother but slower output.")
private ScaleInterpolation interpolation = ScaleInterpolation.NONE;
public ObjectScale() {
}
public double size() {
return size;
}
public int variations() {
return variations;
}
public double minimumScale() {
return minimumScale;
}
public double maximumScale() {
return maximumScale;
}
public ScaleInterpolation interpolation() {
return interpolation == null ? ScaleInterpolation.NONE : interpolation;
}
/** The largest factor this scale makes an object, which a placement's reach has to cover. */
public double maxScale() {
if (size != NO_SCALE) {
return size;
}
return Math.max(minimumScale, maximumScale);
}
}
@@ -0,0 +1,47 @@
/*
* 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.objects;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
import com.volmit.config.MinItems;
import java.util.Collections;
import java.util.List;
/**
* The object placements a region or biome declares, written as {@code "objects": [...]}, the list of placements. A chunk
* places those of its centre column's region and of that column's biome, and of the cave biome where it places in caves.
*/
@Desc("Objects define what schematics (iob files) iris will place here")
@Feature(id = "iris:objects", name = "Objects", key = "objects", root = "objects", targets = {Target.REGION, Target.BIOME})
public final class ObjectSettings implements IrisFeature {
@MinItems(1)
@Desc("Objects define what schematics (iob files) iris will place here")
private List<ObjectPlacement> objects = List.of();
public ObjectSettings() {
}
public List<ObjectPlacement> objects() {
return objects == null ? List.of() : Collections.unmodifiableList(objects);
}
}
@@ -0,0 +1,34 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import com.volmit.block.BlockState;
/** Where an object placed through {@link ObjectHost#placeInto} reads the world around it and writes its blocks. */
public interface ObjectSink {
/** The height of the highest block at the column; {@code ignoreFluid} leaves out the fluid above the ground. */
int highest(int x, int z, boolean ignoreFluid);
BlockState get(int x, int y, int z);
void set(int x, int y, int z, BlockState state);
/** The height of the dimension's fluid. */
int fluidHeight();
}
@@ -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.objects;
/** The size of an object, in blocks. */
public record ObjectSize(int width, int height, int depth) {
}
@@ -0,0 +1,34 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
/** An object of the pack, or one made for a placement, that {@link ObjectHost} can place; Iris's own object class is one. */
public interface PlaceableObject {
/** The key the pack loads the object by, or the key a procedural object is given; null for an object made in code. */
String key();
/** How wide the object is, in blocks. */
int width();
/** How tall the object is, in blocks. */
int height();
/** How deep the object is, in blocks. */
int depth();
}
@@ -0,0 +1,69 @@
/*
* 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.objects;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.carve.CarvingMode;
import java.util.List;
/**
* How a placement differs from the settings it was read from, when {@code iris:objects} places it: a field that is
* null is left as the settings have it.
*
* @param place the objects the placement names, replacing the settings'
* @param mode the place mode
* @param upsideDown whether the object is turned over, for the objects hung from the terrain stacked above
* @param carvingSupport where the placement may place
* @param requireSurfaceSupport whether a surface placement needs solid ground under it
* @param surfaceSupportBuffer the buffer of solid ground around the object's base
* @param forcePlace whether the placement ignores the placement restrictions
*/
public record PlacementChanges(List<String> place, ObjectPlaceMode mode, Boolean upsideDown, CarvingMode carvingSupport,
Boolean requireSurfaceSupport, Integer surfaceSupportBuffer, Boolean forcePlace) {
public static final PlacementChanges NONE = new PlacementChanges(null, null, null, null, null, null, null);
public boolean isNone() {
return this.equals(NONE);
}
public PlacementChanges withPlace(List<String> place) {
return new PlacementChanges(place, mode, upsideDown, carvingSupport, requireSurfaceSupport, surfaceSupportBuffer, forcePlace);
}
public PlacementChanges withMode(ObjectPlaceMode mode) {
return new PlacementChanges(place, mode, upsideDown, carvingSupport, requireSurfaceSupport, surfaceSupportBuffer, forcePlace);
}
public PlacementChanges withUpsideDown(boolean upsideDown) {
return new PlacementChanges(place, mode, upsideDown, carvingSupport, requireSurfaceSupport, surfaceSupportBuffer, forcePlace);
}
public PlacementChanges withCarvingSupport(CarvingMode carvingSupport) {
return new PlacementChanges(place, mode, upsideDown, carvingSupport, requireSurfaceSupport, surfaceSupportBuffer, forcePlace);
}
public PlacementChanges withSurfaceSupport(boolean required, int buffer) {
return new PlacementChanges(place, mode, upsideDown, carvingSupport, required, buffer, forcePlace);
}
public PlacementChanges withForcePlace(boolean forcePlace) {
return new PlacementChanges(place, mode, upsideDown, carvingSupport, requireSurfaceSupport, surfaceSupportBuffer, forcePlace);
}
}
@@ -0,0 +1,42 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
/** What a placement is read from: an object placement of a biome or region, or a procedural object. */
public interface PlacementSource {
double chance();
ObjectPlaceMode mode();
CarvingMode carvingSupport();
CaveAnchorMode caveAnchorMode();
boolean underwater();
boolean requireSurfaceSupport();
int surfaceSupportBuffer();
boolean isDolphinTarget();
}
@@ -0,0 +1,29 @@
/*
* 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.objects;
/**
* What a placement writes into the mantle besides the blocks, beside each block of the object.
*
* @param marker the placement marker to write beside every block the object places, or null for none
* @param treeMaterial whether the block is also written as the tree material the mantle keeps for felling and growth
* @param buriedTreasure whether storage chests among the blocks are marked as buried treasure
*/
public record PlacementTags(String marker, boolean treeMaterial, boolean buriedTreasure) {
}
@@ -0,0 +1,99 @@
/*
* 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.objects;
import art.arcane.iris.builtin.objects.coral.Coral;
import art.arcane.iris.builtin.objects.crystal.Crystal;
import art.arcane.iris.builtin.objects.formation.Formation;
import art.arcane.iris.builtin.objects.fungi.Fungus;
import art.arcane.iris.builtin.objects.ruin.Ruin;
import art.arcane.iris.builtin.objects.tree.Tree;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
import com.volmit.config.MinItems;
import com.volmit.config.Snippet;
import java.util.Collections;
import java.util.List;
/**
* The procedural objects a region or biome declares, written as {@code "proceduralObjects": {"trees": [...], ...}}: things
* Iris generates from scratch at world-gen time and places like object placements.
*/
@Snippet("procedural-objects")
@Desc("Procedurally generated objects placed in a biome or region. Unlike the objects block (which loads iob files), these are generated from scratch at world-gen time.")
@Feature(id = "iris:objects/procedural", name = "Procedural objects", key = "proceduralObjects", targets = {Target.REGION, Target.BIOME})
public final class ProceduralObjectSettings implements IrisFeature {
@MinItems(1)
@Desc("Procedurally generated trees.")
private List<Tree> trees = List.of();
@MinItems(1)
@Desc("Procedurally generated ruins (crumbling pillars, walls, arches, rubble).")
private List<Ruin> ruins = List.of();
@MinItems(1)
@Desc("Procedurally generated natural rock formations (spires, hoodoos, arches, sea stacks, boulders, basalt columns).")
private List<Formation> formations = List.of();
@MinItems(1)
@Desc("Procedurally generated underwater coral structures.")
private List<Coral> coral = List.of();
@MinItems(1)
@Desc("Procedurally generated mushrooms and shelf fungi.")
private List<Fungus> fungi = List.of();
@MinItems(1)
@Desc("Procedurally generated crystal clusters (usually placed in caves).")
private List<Crystal> crystals = List.of();
public ProceduralObjectSettings() {
}
public List<Tree> trees() {
return view(trees);
}
public List<Ruin> ruins() {
return view(ruins);
}
public List<Formation> formations() {
return view(formations);
}
public List<Coral> coral() {
return view(coral);
}
public List<Fungus> fungi() {
return view(fungi);
}
public List<Crystal> crystals() {
return view(crystals);
}
private static <T> List<T> view(List<T> list) {
return list == null ? List.of() : Collections.unmodifiableList(list);
}
}
@@ -0,0 +1,88 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.prepare.ObjectTranslate;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import art.arcane.volmlib.util.math.RNG;
import java.util.List;
import java.util.Optional;
/**
* A procedural object of a region or biome made placeable: a pool of variants Iris bakes once from its settings, and
* the options it is scattered with, like an object placement.
*/
public interface ProceduralPlacement extends PlacementSource {
String name();
@Override
double chance();
int density();
/** Whether the variants are meant to look like the real thing, so leaves decay. */
boolean plausible();
/** Whether the variants are trees. */
boolean tree();
@Override
ObjectPlaceMode mode();
@Override
CarvingMode carvingSupport();
@Override
CaveAnchorMode caveAnchorMode();
@Override
boolean underwater();
@Override
default boolean requireSurfaceSupport() {
return true;
}
@Override
default int surfaceSupportBuffer() {
return 2;
}
@Override
default boolean isDolphinTarget() {
return false;
}
ObjectRotation rotation();
ObjectTranslate translate();
Optional<VacuumSettings> vacuumSettings();
/** One of the variants, picked with {@code rng}; empty when none baked. */
Optional<PlaceableObject> variant(RNG rng);
/** Every variant, baked on first use. */
List<PlaceableObject> variants();
}
@@ -0,0 +1,41 @@
/*
* 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.objects;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
/** Whether a dimension refuses surface objects over carved openings, written as {@code "requireObjectSurfaceSupport": true}. */
@Desc("Refuse to place surface objects and trees over carved surface openings.")
@Feature(id = "iris:objects/surface-support", name = "Require surface support", key = "requireObjectSurfaceSupport", root = "require", targets = Target.DIMENSION)
public final class RequireSurfaceSupportSettings implements IrisFeature {
private static final boolean DEFAULT_REQUIRED = true;
@Desc("Refuse to place surface objects and trees over carved surface openings.")
private boolean require = DEFAULT_REQUIRED;
public RequireSurfaceSupportSettings() {
}
public boolean require() {
return require;
}
}
@@ -0,0 +1,33 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import com.volmit.config.Desc;
@Desc("Use 3D Interpolation on scaled objects if they are larger than the origin.")
public enum ScaleInterpolation {
@Desc("Don't interpolate, big cubes")
NONE,
@Desc("Uses linear interpolation in 3 dimensions, generally pretty good, but slow")
TRILINEAR,
@Desc("Uses cubic spline interpolation in 3 dimensions, even better, but extreme slowdowns")
TRICUBIC,
@Desc("Uses hermite spline interpolation in 3 dimensions, even better, but extreme slowdowns")
TRIHERMITE
}
@@ -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.objects;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
/** The least surface-support buffer a dimension gives its surface objects, written as {@code "objectSurfaceSupportBuffer": 2}. */
@Desc("Minimum surface-support buffer, in blocks, applied to every surface object placement in this dimension. A placement may ask for more but never less.")
@Feature(id = "iris:objects/surface-support-buffer", name = "Surface support buffer", key = "objectSurfaceSupportBuffer", root = "buffer", targets = Target.DIMENSION)
public final class SurfaceSupportBufferSettings implements IrisFeature {
private static final int DEFAULT_BUFFER_BLOCKS = 2;
@MinNumber(0)
@MaxNumber(16)
@Desc("Minimum surface-support buffer, in blocks, applied to every surface object placement in this dimension. A placement may ask for more but never less.")
private int buffer = DEFAULT_BUFFER_BLOCKS;
public SurfaceSupportBufferSettings() {
}
public int buffer() {
return buffer;
}
}
@@ -0,0 +1,50 @@
/*
* 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.objects;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
import com.volmit.config.Required;
import com.volmit.config.Snippet;
/** Whether a dimension's saplings grow the trees of its object placements, written as {@code "treeSettings": {...}}. */
@Snippet("tree-settings")
@Desc("Tree growth override settings")
@Feature(id = "iris:objects/trees", name = "Tree growth", key = "treeSettings", targets = Target.DIMENSION)
public final class TreeGrowthSettings implements IrisFeature {
@Required
@Desc("Turn replacing on and off")
private boolean enabled = false;
@Desc("Object picking modes")
private TreeMode mode = TreeMode.FIRST;
public TreeGrowthSettings() {
}
public boolean enabled() {
return enabled;
}
public TreeMode mode() {
return mode == null ? TreeMode.FIRST : mode;
}
}
@@ -1,6 +1,6 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
* 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
@@ -16,15 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.procedural.tree;
package art.arcane.iris.builtin.objects;
import art.arcane.iris.engine.object.annotations.Desc;
import com.volmit.config.Desc;
@Desc("Sapling override object picking options")
public enum IrisTreeModes {
public enum TreeMode {
@Desc("Check biome, then region, pick the first one that has options. Dimension placements are not consulted.")
FIRST,
@Desc("Check biome, regions, and dimensions, and pick any option from the total list")
ALL
}
}
@@ -0,0 +1,76 @@
/*
* 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.objects;
import com.volmit.config.Desc;
import com.volmit.config.MinItems;
import com.volmit.config.Required;
import com.volmit.config.Snippet;
import java.util.Collections;
import java.util.List;
/** The trees an object placement overrides when their saplings grow, an entry of the placement's {@code trees}. */
@Snippet("tree")
@Desc("Tree replace options for this object placer")
public final class TreeOverride {
@Required
@MinItems(1)
@Desc("The types of trees overwritten by this object")
private List<String> treeTypes = List.of();
@Required
@MinItems(1)
@Desc("The size of the square of saplings this applies to (2 means a 2 * 2 sapling area)")
private List<TreeSize> sizes = List.of();
public TreeOverride() {
}
public List<String> treeTypes() {
return treeTypes == null ? List.of() : Collections.unmodifiableList(treeTypes);
}
public List<TreeSize> sizes() {
return sizes == null ? List.of() : Collections.unmodifiableList(sizes);
}
/** Whether this override is for a sapling area of {@code width} by {@code depth} growing the species {@code species}. */
public boolean matches(int width, int depth, String species) {
return matchesSize(width, depth) && matchesSpecies(species);
}
private boolean matchesSize(int width, int depth) {
for (TreeSize size : sizes()) {
if (size.matches(width, depth)) {
return true;
}
}
return false;
}
private boolean matchesSpecies(String species) {
for (String type : treeTypes()) {
if (type != null && type.equalsIgnoreCase(species)) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,57 @@
/*
* 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.objects;
import com.volmit.config.Desc;
import com.volmit.config.Required;
import com.volmit.config.Snippet;
/** The size of a sapling area, in saplings, that a tree override applies to. */
@Snippet("tree-size")
@Desc("Sapling override object picking options")
public final class TreeSize {
@Required
@Desc("The width of the sapling area")
private int width = 1;
@Required
@Desc("The depth of the sapling area")
private int depth = 1;
public TreeSize() {
}
public TreeSize(int width, int depth) {
this.width = width;
this.depth = depth;
}
public int width() {
return width;
}
public int depth() {
return depth;
}
/** Whether an area of {@code otherWidth} by {@code otherDepth} saplings is this size, turned either way. */
public boolean matches(int otherWidth, int otherDepth) {
return (width == otherWidth && depth == otherDepth) || (depth == otherWidth && width == otherDepth);
}
}
@@ -0,0 +1,39 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
/** Whether the objects placed in the terrain stacked above ignore placement restrictions, written as {@code "upperObjectsForcePlace": true}. */
@Desc("When true, upper-dimension objects force-place regardless of placement restrictions (slope, underwater, clamp, collisions, carving). Normal dimension objects always place first; upper objects place second and may clip or occlude lower-dimension placements when this is enabled.")
@Feature(id = "iris:objects/upper-force", name = "Force upper dimension objects", key = "upperObjectsForcePlace", root = "force", targets = Target.DIMENSION)
public final class UpperObjectsForceSettings implements IrisFeature {
@Desc("When true, upper-dimension objects force-place regardless of placement restrictions (slope, underwater, clamp, collisions, carving). Normal dimension objects always place first; upper objects place second and may clip or occlude lower-dimension placements when this is enabled.")
private boolean force = false;
public UpperObjectsForceSettings() {
}
public boolean force() {
return force;
}
}
@@ -0,0 +1,39 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.objects;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
/** Whether the objects of a dimension are also placed in the terrain stacked above it, written as {@code "upperDimensionObjects": true}. */
@Desc("When true, objects from the mantle (structures, trees, etc.) can be placed in the upper dimension terrain zone. When false, the upper terrain is protected from object placement.")
@Feature(id = "iris:objects/upper", name = "Upper dimension objects", key = "upperDimensionObjects", root = "enabled", targets = Target.DIMENSION)
public final class UpperObjectsSettings implements IrisFeature {
@Desc("When true, objects from the mantle (structures, trees, etc.) can be placed in the upper dimension terrain zone. When false, the upper terrain is protected from object placement.")
private boolean enabled = false;
public UpperObjectsSettings() {
}
public boolean enabled() {
return enabled;
}
}
@@ -1,6 +1,6 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
* 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
@@ -16,53 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.procedural.tree;
package art.arcane.iris.builtin.objects.tree;
import art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf;
import art.arcane.iris.builtin.objects.tree.TreeDecorator;
import art.arcane.iris.builtin.objects.tree.TreeCanopy;
import art.arcane.iris.builtin.objects.tree.TreeRootStyle;
import art.arcane.iris.builtin.objects.tree.TreeProfile;
import art.arcane.iris.builtin.objects.tree.TreeFunction;
import art.arcane.iris.builtin.objects.tree.TreeAzimuthMode;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
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.stilt.StiltSettings;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import art.arcane.iris.builtin.validate.ObjectLimit;
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
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.engine.object.procedural.IrisProceduralPlacement;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.volmlib.util.cache.AtomicCache;
import art.arcane.iris.engine.object.annotations.ArrayType;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.MaxNumber;
import art.arcane.iris.engine.object.annotations.MinNumber;
import art.arcane.iris.engine.object.annotations.RegistryListBlockType;
import art.arcane.iris.engine.object.annotations.Required;
import art.arcane.iris.engine.object.annotations.Snippet;
import art.arcane.iris.engine.object.procedural.tree.ProceduralTreeGenerator;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import com.volmit.block.PaletteSpec;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinItems;
import com.volmit.config.MinNumber;
import com.volmit.config.Ref;
import com.volmit.config.Reference;
import com.volmit.config.Required;
import com.volmit.config.Snippet;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Snippet("procedural-tree")
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Desc("A single procedurally generated tree. Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file.")
@Data
public class IrisProceduralTree implements IrisProceduralPlacement {
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
public final class Tree {
@Desc("A human readable name used in logs and as the variant load key.")
private String name = "procedural-tree";
@@ -90,7 +69,7 @@ public class IrisProceduralTree implements IrisProceduralPlacement {
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
@Desc("Rotate this tree's placement.")
private IrisObjectRotation rotation = new IrisObjectRotation();
private ObjectRotation rotation = new ObjectRotation();
@Desc("Limit the max or min height of placement.")
private ObjectLimit clamp = new ObjectLimit();
@@ -102,7 +81,7 @@ public class IrisProceduralTree implements IrisProceduralPlacement {
private boolean underwater = false;
@Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.")
private IrisObjectTranslate translate = new IrisObjectTranslate();
private ObjectTranslate translate = new ObjectTranslate();
@Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
private StiltSettings stiltSettings;
@@ -112,19 +91,19 @@ public class IrisProceduralTree implements IrisProceduralPlacement {
@Required
@Desc("The trunk (log) block, e.g. minecraft:oak_log. Ignored when trunkPalette is set.")
@RegistryListBlockType
@Ref(Reference.BLOCK)
private String trunk = "minecraft:oak_log";
@Desc("A noise-driven palette for the trunk. When set this overrides the single trunk block, letting the trunk mix blocks by noise.")
private IrisMaterialPalette trunkPalette = null;
private PaletteSpec trunkPalette;
@Required
@Desc("The leaf block, e.g. minecraft:oak_leaves. Ignored when leavesPalette is set.")
@RegistryListBlockType
@Ref(Reference.BLOCK)
private String leaves = "minecraft:oak_leaves";
@Desc("A noise-driven palette for the leaves. When set this overrides the single leaf block, letting the canopy mix leaf (or other) blocks by noise. Only blocks that are actually leaves get vanilla decay distances.")
private IrisMaterialPalette leavesPalette = null;
private PaletteSpec leavesPalette;
@Desc("The named canopy profile that drives default crown radii and shape.")
private TreeProfile profile = TreeProfile.OAK;
@@ -209,27 +188,27 @@ public class IrisProceduralTree implements IrisProceduralPlacement {
private int azimuthWhorlCount = 5;
@Desc("Optional accent leaf block scattered through the canopy (blossoms, shroomlight).")
@RegistryListBlockType
private String secondaryLeaves = null;
@Ref(Reference.BLOCK)
private String secondaryLeaves;
@MinNumber(0)
@MaxNumber(1)
@Desc("The fraction of leaves replaced by the secondary leaf block(s).")
private double secondaryLeafFraction = 0.35;
@ArrayType(min = 1, type = TreeSecondaryLeaf.class)
@MinItems(1)
@Desc("Optional weighted set of accent leaf blocks. When set this overrides the single secondaryLeaves block.")
private KList<TreeSecondaryLeaf> weightedSecondaryLeaves = new KList<>();
private List<TreeSecondaryLeaf> weightedSecondaryLeaves = List.of();
@Desc("A noise-driven palette for the secondary (accent) leaves. When set this overrides both secondaryLeaves and weightedSecondaryLeaves.")
private IrisMaterialPalette secondaryLeavesPalette = null;
private PaletteSpec secondaryLeavesPalette;
@Desc("Optional secondary trunk block used over a height band (for color-banded trunks). Ignored when secondaryTrunkPalette is set.")
@RegistryListBlockType
private String secondaryTrunk = null;
@Ref(Reference.BLOCK)
private String secondaryTrunk;
@Desc("A noise-driven palette for the secondary trunk band. When set this overrides the single secondaryTrunk block.")
private IrisMaterialPalette secondaryTrunkPalette = null;
private PaletteSpec secondaryTrunkPalette;
@MinNumber(0)
@MaxNumber(1)
@@ -271,80 +250,262 @@ public class IrisProceduralTree implements IrisProceduralPlacement {
@Desc("The leaf crown configuration.")
private TreeCanopy canopy = new TreeCanopy();
@ArrayType(min = 1, type = TreeDecorator.class)
@MinItems(1)
@Desc("Accent decorators applied after the tree is built (fruit, vines, snow, glow).")
private KList<TreeDecorator> decorators = new KList<>();
private List<TreeDecorator> decorators = List.of();
public KList<IrisObject> getVariantObjects(IrisData data) {
return variantCache.aquire(() -> {
KList<IrisObject> baked = new KList<>();
int count = Math.max(1, variants);
int lo = Math.min(heightMin, heightMax);
int hi = Math.max(heightMin, heightMax);
RNG heightRng = new RNG(seed);
for (int i = 0; i < count; i++) {
int height;
if (count == 1 || lo == hi) {
height = heightRng.i(lo, hi + 1);
} else {
double step = (hi - lo) / (double) (count - 1);
double base = lo + step * i;
double jitter = heightRng.d(-step * 0.3, step * 0.3);
height = (int) Math.round(Math.max(lo, Math.min(hi, base + jitter)));
}
IrisObject object = ProceduralTreeGenerator.generate(this, Math.max(2, height), new RNG(seed + (i * 7919L)), data);
if (object == null || object.getBlocks().isEmpty()) {
continue;
}
object.setLoadKey(getVariantLoadKey(i));
object.setLoader(data);
baked.add(object);
}
if (new java.io.File("plugins/Iris/goldendebug.txt").isFile()) {
for (IrisObject object : baked) {
long[] digest = new long[]{0L};
object.getBlocks().forEach((vector, state) -> {
long position = ((long) vector.getBlockX() << 40) ^ ((long) vector.getBlockY() << 20) ^ vector.getBlockZ();
digest[0] ^= Long.rotateLeft(position * 0x9E3779B97F4A7C15L ^ state.key().hashCode(), (int) (position & 63));
});
IrisLogging.debug("Goldendebug bake: " + object.getLoadKey() + " blocks=" + object.getBlocks().size() + " digest=" + Long.toHexString(digest[0]));
}
}
return baked;
});
public Tree() {
}
public IrisObject getVariantObject(IrisData data, RNG rng) {
KList<IrisObject> baked = getVariantObjects(data);
if (baked == null || baked.isEmpty()) {
return null;
}
return baked.get(rng.i(baked.size()));
}
public String getVariantLoadKey(int index) {
/** The key the variant {@code index} of the tree named {@code name} is loaded under, which placement markers and the sapling tree list name. */
public static String variantLoadKey(String name, int index) {
if (index < 0) {
throw new IllegalArgumentException("index must not be negative");
}
return "procedural/tree/" + name + "#" + index;
}
public IrisObjectPlacement asPlacement() {
IrisObjectPlacement placement = new IrisObjectPlacement();
placement.setMode(mode);
placement.setRotation(rotation);
placement.setClamp(clamp);
placement.setCarvingSupport(carvingSupport);
placement.setUnderwater(underwater);
placement.setTranslate(translate);
placement.setStiltSettings(stiltSettings);
placement.setVacuumSettings(vacuumSettings);
placement.setChance(chance);
placement.setDensity(density);
return placement;
public String name() {
return name;
}
public double chance() {
return chance;
}
public int density() {
return density;
}
public int variants() {
return variants;
}
public long seed() {
return seed;
}
public boolean plausible() {
return plausible;
}
public ObjectPlaceMode mode() {
return mode;
}
public ObjectRotation rotation() {
return rotation;
}
public ObjectLimit clamp() {
return clamp;
}
public CarvingMode carvingSupport() {
return carvingSupport;
}
public boolean underwater() {
return underwater;
}
public ObjectTranslate translate() {
return translate;
}
public Optional<StiltSettings> stiltSettings() {
return Optional.ofNullable(stiltSettings);
}
public Optional<VacuumSettings> vacuumSettings() {
return Optional.ofNullable(vacuumSettings);
}
public String trunk() {
return trunk;
}
public Optional<PaletteSpec> trunkPalette() {
return Optional.ofNullable(trunkPalette);
}
public String leaves() {
return leaves;
}
public Optional<PaletteSpec> leavesPalette() {
return Optional.ofNullable(leavesPalette);
}
public TreeProfile profile() {
return profile;
}
public int heightMin() {
return heightMin;
}
public int heightMax() {
return heightMax;
}
public int trunkWidth() {
return trunkWidth;
}
public TreeFunction trunkShape() {
return trunkShape;
}
public double shapeStart() {
return shapeStart;
}
public double shapeEnd() {
return shapeEnd;
}
public double shapeSteepness() {
return shapeSteepness;
}
public double shapeBase() {
return shapeBase;
}
public double shapePeriod() {
return shapePeriod;
}
public double shapeAmplitude() {
return shapeAmplitude;
}
public double shapePeakOffset() {
return shapePeakOffset;
}
public double shapeFloor() {
return shapeFloor;
}
public double leanAzimuth() {
return leanAzimuth;
}
public double leanAngle() {
return leanAngle;
}
public TreeFunction trunkCurve() {
return trunkCurve;
}
public double curveSteepness() {
return curveSteepness;
}
public TreeAzimuthMode leanAzimuthMode() {
return leanAzimuthMode;
}
public double azimuthStart() {
return azimuthStart;
}
public double azimuthEnd() {
return azimuthEnd;
}
public double azimuthTurns() {
return azimuthTurns;
}
public double azimuthAmplitude() {
return azimuthAmplitude;
}
public double azimuthPeriod() {
return azimuthPeriod;
}
public double azimuthOffset() {
return azimuthOffset;
}
public double azimuthScale() {
return azimuthScale;
}
public int azimuthWhorlCount() {
return azimuthWhorlCount;
}
public Optional<String> secondaryLeaves() {
return Optional.ofNullable(secondaryLeaves);
}
public double secondaryLeafFraction() {
return secondaryLeafFraction;
}
public List<TreeSecondaryLeaf> weightedSecondaryLeaves() {
return weightedSecondaryLeaves == null ? List.of() : Collections.unmodifiableList(weightedSecondaryLeaves);
}
public Optional<PaletteSpec> secondaryLeavesPalette() {
return Optional.ofNullable(secondaryLeavesPalette);
}
public Optional<String> secondaryTrunk() {
return Optional.ofNullable(secondaryTrunk);
}
public Optional<PaletteSpec> secondaryTrunkPalette() {
return Optional.ofNullable(secondaryTrunkPalette);
}
public double secondaryTrunkStart() {
return secondaryTrunkStart;
}
public double secondaryTrunkEnd() {
return secondaryTrunkEnd;
}
public boolean roots() {
return roots;
}
public TreeRootStyle rootStyle() {
return rootStyle;
}
public int rootDepth() {
return rootDepth;
}
public double rootFlare() {
return rootFlare;
}
public int trunkForks() {
return trunkForks;
}
public double forkHeight() {
return forkHeight;
}
public double forkAngle() {
return forkAngle;
}
public TreeCanopy canopy() {
return canopy;
}
public List<TreeDecorator> decorators() {
return decorators == null ? List.of() : Collections.unmodifiableList(decorators);
}
}
@@ -29,9 +29,10 @@
* <p>
* Besides those, it holds what the compiled-in built-ins and the built-ins jar must share, since each sees its own copy
* of every other class: narrow facades only Iris's own built-ins use, interfaces Iris's worlds implement
* ({@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}, {@link art.arcane.iris.builtin.terrain.BiomeLayers},
* {@link art.arcane.iris.builtin.terrain.TerrainPalettes}). Keep them few: each is a promise.
* ({@link art.arcane.iris.builtin.IrisSeed}, {@link art.arcane.iris.builtin.LiveWorld}, {@link art.arcane.iris.builtin.objects.ObjectHost}),
* and per-world state several of them use ({@link art.arcane.iris.builtin.terrain.LayerBlocks},
* {@link art.arcane.iris.builtin.terrain.BiomeLayers}, {@link art.arcane.iris.builtin.terrain.TerrainPalettes}). Keep them few: each is
* a promise.
* <p>
* 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
@@ -0,0 +1,228 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
import art.arcane.iris.builtin.objects.CarvedSpace;
import art.arcane.iris.builtin.objects.Cavern;
import art.arcane.volmlib.util.cache.CacheKey;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.resource.ResourceId;
import com.volmit.world.BiomeSample;
import com.volmit.world.TerrainSampler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/** Finds the places in the carved caves of a chunk where a cave object may be anchored, remembering what it scanned. */
final class CaveAnchors {
private static final int BEDROCK_CLEARANCE = 6;
private static final int SOLID_NEIGHBOR_REACH_BLOCKS = 3;
private static final int MAX_PACKED_SETTING = 65535;
private final CarvedSpace carved;
private final TerrainSampler terrain;
private final int worldHeight;
private final int caveLavaHeight;
private final Map<Long, Map<Long, List<Integer>>> anchorsBySetting = new HashMap<>();
private final Map<Long, byte[]> carvedColumns = new HashMap<>();
private final Map<Long, Integer> surfaceHeights = new HashMap<>();
CaveAnchors(CarvedSpace carved, TerrainSampler terrain, int worldHeight, int caveLavaHeight) {
this.carved = carved;
this.terrain = terrain;
this.worldHeight = worldHeight;
this.caveLavaHeight = caveLavaHeight;
}
/** A position to anchor a cave object at. */
record Anchor(int x, int y, int z) {
}
/** How a cave placement looks for its anchor. */
record Search(CaveAnchorMode mode, int scanStep, int minDepthBelowSurface, int attempts) {
}
/**
* Looks for an anchor in the chunk whose first block is {@code minX}, {@code minZ}: a column picked at random, a height in
* it picked among those the mode accepts, tried up to the search's attempts.
*
* @param expectedCaveBiome the cave biome the anchor has to be in, or null for any
* @return the anchor, or null when no attempt found one
*/
Anchor find(RNG rng, int minX, int minZ, Search search, ResourceId expectedCaveBiome, boolean underwater) {
for (int attempt = 0; attempt < search.attempts(); attempt++) {
int candidateX = rng.i(minX, minX + 16);
int candidateZ = rng.i(minZ, minZ + 16);
int candidateY = anchorY(rng, candidateX, candidateZ, search);
if (candidateY < 0
|| biomeConflicts(candidateX, candidateY, candidateZ, expectedCaveBiome)
|| !acceptsFluid(underwater, carved.cavernAt(candidateX, candidateY, candidateZ), candidateY, caveLavaHeight)) {
continue;
}
return new Anchor(candidateX, candidateY, candidateZ);
}
return null;
}
static boolean acceptsFluid(boolean underwater, Optional<Cavern> cavern, int y, int lavaHeight) {
if (cavern.isEmpty()) {
return false;
}
if (underwater || cavern.get().liquid() == Cavern.FORCED_AIR_LIQUID) {
return true;
}
return cavern.get().air() && y > lavaHeight;
}
/** One above the highest height an anchor may sit at, or 0 when none may. */
static int scanUpperBound(int worldHeight, int surfaceY, int minDepthBelowSurface) {
int maxAnchorY = maxBuriedY(worldHeight, surfaceY, minDepthBelowSurface);
if (maxAnchorY <= 1) {
return 0;
}
return maxAnchorY + 1;
}
/** The highest height a cave object may reach: no deeper than {@code minDepthBelowSurface} under the surface. */
static int maxBuriedY(int worldHeight, int surfaceY, int minDepthBelowSurface) {
return Math.min(worldHeight - 1, surfaceY - Math.max(0, minDepthBelowSurface));
}
/** Whether the cave biome at the position is not the one expected, nor the surface biome the cave sits under. */
private boolean biomeConflicts(int x, int y, int z, ResourceId expectedCaveBiome) {
if (expectedCaveBiome == null) {
return false;
}
BiomeSample sample = terrain.biome(x, y, z);
return biomeConflicts(sample.caveBiome().orElse(null), sample.surfaceBiome(), expectedCaveBiome);
}
static boolean biomeConflicts(ResourceId at, ResourceId surface, ResourceId expectedCaveBiome) {
if (expectedCaveBiome == null || at == null) {
return false;
}
if (at.equals(expectedCaveBiome)) {
return false;
}
return surface == null || !at.equals(surface);
}
private int anchorY(RNG rng, int x, int z, Search search) {
List<Integer> anchors = anchorsAt(x, z, search);
if (anchors.isEmpty()) {
return -1;
}
if (anchors.size() == 1) {
return anchors.get(0);
}
return anchors.get(rng.i(anchors.size()));
}
private List<Integer> anchorsAt(int x, int z, Search search) {
if (search.scanStep() > MAX_PACKED_SETTING || search.minDepthBelowSurface() > MAX_PACKED_SETTING) {
return scanColumn(x, z, search);
}
long settingKey = ((long) search.mode().ordinal() << 32) | ((long) search.scanStep() << 16) | search.minDepthBelowSurface();
Map<Long, List<Integer>> columns = anchorsBySetting.computeIfAbsent(settingKey, key -> new HashMap<>());
long columnKey = CacheKey.key(x, z);
List<Integer> anchors = columns.get(columnKey);
if (anchors != null) {
return anchors;
}
anchors = scanColumn(x, z, search);
columns.put(columnKey, anchors);
return anchors;
}
private List<Integer> scanColumn(int x, int z, Search search) {
int step = Math.max(1, search.scanStep());
int surfaceY = surfaceHeight(x, z);
int maxAnchorExclusive = scanUpperBound(worldHeight, surfaceY, search.minDepthBelowSurface());
if (maxAnchorExclusive == 0) {
return new ArrayList<>();
}
int carvedHeight = Math.min(worldHeight, maxAnchorExclusive + 3);
byte[] carvedColumn = carvedColumn(x, z, carvedHeight);
return scanRange(search.mode(), step, carvedHeight, maxAnchorExclusive, carvedColumn);
}
private List<Integer> scanRange(CaveAnchorMode mode, int step, int height, int maxAnchorY, byte[] carvedColumn) {
List<Integer> anchors = new ArrayList<>();
for (int y = BEDROCK_CLEARANCE; y < maxAnchorY; y += step) {
if (!isCarved(carvedColumn, y)) {
continue;
}
boolean solidBelow = hasSolidNeighbor(carvedColumn, y, height, -1);
boolean solidAbove = hasSolidNeighbor(carvedColumn, y, height, 1);
if (matches(mode, solidBelow, solidAbove)) {
anchors.add(y);
}
}
return anchors;
}
private static boolean isCarved(byte[] carvedColumn, int y) {
return y >= 0 && y < carvedColumn.length && carvedColumn[y] == 1;
}
private static boolean hasSolidNeighbor(byte[] carvedColumn, int y, int height, int direction) {
for (int distance = 1; distance <= SOLID_NEIGHBOR_REACH_BLOCKS; distance++) {
int neighbor = y + (direction * distance);
if (neighbor < 0 || neighbor >= height || !isCarved(carvedColumn, neighbor)) {
return true;
}
}
return false;
}
private static boolean matches(CaveAnchorMode mode, boolean solidBelow, boolean solidAbove) {
return switch (mode) {
case PROFILE_DEFAULT, FLOOR -> solidBelow;
case CEILING -> solidAbove;
case CENTER -> !solidBelow && !solidAbove;
case ANY -> true;
};
}
private byte[] carvedColumn(int x, int z, int height) {
long columnKey = CacheKey.key(x, z);
byte[] column = carvedColumns.get(columnKey);
if (column != null && column.length == height) {
return column;
}
column = carved.column(x, z, height);
carvedColumns.put(columnKey, column);
return column;
}
private int surfaceHeight(int x, int z) {
long columnKey = CacheKey.key(x, z);
Integer known = surfaceHeights.get(columnKey);
if (known != null) {
return known;
}
int surfaceY = (int) Math.round(terrain.surfaceY(x, z));
surfaceHeights.put(columnKey, surfaceY);
return surfaceY;
}
}
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
final class CaveObjectPlacementTransaction implements IObjectPlacer {
public final class CaveObjectPlacementTransaction implements IObjectPlacer {
private static final int CACHE_MISS = Integer.MIN_VALUE;
private final IObjectPlacer delegate;
@@ -46,7 +46,7 @@ final class CaveObjectPlacementTransaction implements IObjectPlacer {
private final Long2IntOpenHashMap caveCeilings;
private int blockWrites;
CaveObjectPlacementTransaction(IObjectPlacer delegate, int anchorY, int minDepthBelowSurface) {
public CaveObjectPlacementTransaction(IObjectPlacer delegate, int anchorY, int minDepthBelowSurface) {
this.delegate = delegate;
this.engine = delegate.getEngine();
this.anchorY = anchorY;
@@ -60,7 +60,7 @@ final class CaveObjectPlacementTransaction implements IObjectPlacer {
this.caveCeilings.defaultReturnValue(CACHE_MISS);
}
CommitResult commit() {
public CommitResult commit() {
if (blockWrites == 0) {
discard();
return CommitResult.EMPTY;
@@ -80,13 +80,13 @@ final class CaveObjectPlacementTransaction implements IObjectPlacer {
return CommitResult.COMMITTED;
}
void discard() {
public void discard() {
mutations.clear();
bufferedBlocks.clear();
blockWrites = 0;
}
int getCaveCeiling(int x, int z) {
public int getCaveCeiling(int x, int z) {
long key = CacheKey.key(x, z);
int cached = caveCeilings.get(key);
if (cached != CACHE_MISS) {
@@ -242,7 +242,7 @@ final class CaveObjectPlacementTransaction implements IObjectPlacer {
return Math.min(worldHeight, scanLimit + 1);
}
enum CommitResult {
public enum CommitResult {
COMMITTED,
EMPTY,
REJECTED_BOUNDS
@@ -0,0 +1,69 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.PlaceableObject;
import com.volmit.ModuleLog;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/** Debug lines for cave objects that were not placed, at most one per kind of rejection every few seconds. */
final class CaveRejects {
private static final long THROTTLE_MILLIS = 5000L;
private static final Map<String, State> STATES = new ConcurrentHashMap<>();
private CaveRejects() {
}
static void log(ObjectHost host, ModuleLog log, String scope, String reason, int chunkX, int chunkZ, ObjectPlacement placement,
PlaceableObject object, int densityIndex, int density, CaveAnchors.Search search, Integer anchorY, Throwable error) {
if (!host.debugging()) {
return;
}
String placementKeys = placement == null ? "none" : String.join(",", placement.place());
String objectKey = object == null ? "null" : object.key();
String throttleKey = scope + "|" + reason + "|" + placementKeys + "|" + objectKey;
State state = STATES.computeIfAbsent(throttleKey, key -> new State());
long now = System.currentTimeMillis();
long last = state.lastLogMillis.get();
if ((now - last) < THROTTLE_MILLIS || !state.lastLogMillis.compareAndSet(last, now)) {
state.suppressed.incrementAndGet();
return;
}
int suppressed = state.suppressed.getAndSet(0);
String errorText = error == null ? "none" : error.getClass().getSimpleName() + ":" + error.getMessage();
log.debug("Cave object reject: scope=" + scope + " reason=" + reason + " chunk=" + chunkX + "," + chunkZ + " object=" + objectKey
+ " placements=" + placementKeys + " densityIndex=" + densityIndex + " density=" + density
+ " anchorMode=" + search.mode() + " anchorSearchAttempts=" + search.attempts() + " anchorScanStep=" + search.scanStep()
+ " minDepthBelowSurface=" + search.minDepthBelowSurface() + " anchorY=" + (anchorY == null ? "none" : anchorY)
+ " forcePlace=" + (placement != null && placement.forcePlace())
+ " carvingSupport=" + (placement == null ? "none" : placement.carvingSupport())
+ " suppressed=" + suppressed + " error=" + errorText);
}
private static final class State {
private final AtomicLong lastLogMillis = new AtomicLong(0L);
private final AtomicInteger suppressed = new AtomicInteger(0);
}
}
@@ -0,0 +1,88 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
import art.arcane.iris.builtin.carve.CaveProfile;
import art.arcane.iris.builtin.objects.PlacementSource;
/** What a cave object placement takes from the cave profile that applies to it. */
final class CaveSettings {
private static final CaveProfile DEFAULT_PROFILE = new CaveProfile();
private static final int DEFAULT_SCAN_STEP = 1;
private static final int DEFAULT_MIN_DEPTH_BELOW_SURFACE = 6;
private static final int DEFAULT_SEARCH_ATTEMPTS = 6;
private final CaveProfile dimensionProfile;
CaveSettings(CaveProfile dimensionProfile) {
this.dimensionProfile = dimensionProfile;
}
/** The profile of the first of {@code preferred} and {@code secondary} that is enabled, else the dimension's, else the default one. */
CaveProfile resolve(CaveProfile preferred, CaveProfile secondary) {
if (preferred != null && preferred.enabled()) {
return preferred;
}
if (secondary != null && secondary.enabled()) {
return secondary;
}
if (dimensionProfile != null) {
return dimensionProfile;
}
return DEFAULT_PROFILE;
}
/** How the placement looks for its anchor in caves: its own mode, else the profile's, else the floor; turned upside down, the ceiling. */
CaveAnchors.Search searchFor(PlacementSource placement, CaveProfile profile) {
CaveAnchorMode mode = anchorMode(placement, profile);
if (placement.mode().placeMode().has(PlaceTrait.UPSIDE_DOWN)) {
mode = CaveAnchorMode.CEILING;
}
return new CaveAnchors.Search(mode, scanStep(profile), minDepthBelowSurface(profile), searchAttempts(profile));
}
private static CaveAnchorMode anchorMode(PlacementSource placement, CaveProfile profile) {
CaveAnchorMode placementMode = placement.caveAnchorMode();
if (placementMode != null && !placementMode.equals(CaveAnchorMode.PROFILE_DEFAULT)) {
return placementMode;
}
if (profile == null) {
return CaveAnchorMode.FLOOR;
}
CaveAnchorMode profileMode = profile.defaultObjectAnchor();
if (profileMode == null || profileMode.equals(CaveAnchorMode.PROFILE_DEFAULT)) {
return CaveAnchorMode.FLOOR;
}
return profileMode;
}
private static int scanStep(CaveProfile profile) {
return profile == null ? DEFAULT_SCAN_STEP : Math.max(1, profile.anchorScanStep());
}
private static int minDepthBelowSurface(CaveProfile profile) {
return profile == null ? DEFAULT_MIN_DEPTH_BELOW_SURFACE : Math.max(0, profile.objectMinDepthBelowSurface());
}
private static int searchAttempts(CaveProfile profile) {
return profile == null ? DEFAULT_SEARCH_ATTEMPTS : Math.max(1, profile.anchorSearchAttempts());
}
}
@@ -0,0 +1,675 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.carve.CaveProfile;
import art.arcane.iris.builtin.objects.CavePlacement;
import art.arcane.iris.builtin.objects.ObjectChunk;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.builtin.objects.PlacementChanges;
import art.arcane.iris.builtin.objects.PlacementSource;
import art.arcane.iris.builtin.objects.PlacementTags;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralPlacement;
import art.arcane.iris.builtin.objects.RequireSurfaceSupportSettings;
import art.arcane.iris.builtin.objects.SurfaceSupportBufferSettings;
import art.arcane.iris.builtin.objects.UpperObjectsForceSettings;
import art.arcane.iris.builtin.objects.UpperObjectsSettings;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.ModuleLog;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.resource.ResourceId;
import com.volmit.stage.MantleStageContext;
import com.volmit.world.TerrainSampler;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
/**
* Places what the objects of one chunk's region and biomes say: the objects of its surface, caves and the terrain stacked above,
* and its procedural objects, in that order, all drawing from the one random of the chunk.
*/
final class ChunkObjectPlacing {
private static final int CENTER_OFFSET_BLOCKS = 8;
private static final int CHUNK_SHIFT = 4;
private static final int CHUNK_WIDTH_BLOCKS = 16;
private static final double CHANCE_JITTER = 0.005;
private static final int[] CAVE_BIOME_SAMPLE_DEPTHS = {48, 80, 112};
private static final int LEGACY_CAVE_SAMPLE_DEPTH = 48;
private static final int UPPER_SURFACE_MARGIN_BLOCKS = 2;
private static final int MINIMUM_UPPER_ANCHOR_Y = 1;
private static final int DIAGNOSTIC_CHUNK_MASK = 31;
private static final int DIAGNOSTIC_SURFACE_MARGIN = 14;
private static final String TREE_FOLDER = "trees/";
private static final String REGEN_THREAD_PREFIX = "Iris-Regen-";
private final ObjectHost host;
private final ModuleLog log;
private final MantleStageContext context;
private final ObjectChunk chunk;
private final TerrainSampler terrain;
private final int chunkX;
private final int chunkZ;
private final int centerX;
private final int centerZ;
private final RNG rng;
private final boolean traceRegen;
private final boolean golden;
private final EffectivePlacements effective;
private final CaveSettings caves;
private final int worldHeight;
private final int caveLavaHeight;
ChunkObjectPlacing(ObjectHost host, ModuleLog log, MantleStageContext context) {
this.host = host;
this.log = log;
this.context = context;
this.chunk = host.chunk();
this.terrain = context.terrain();
this.chunkX = context.originX() >> CHUNK_SHIFT;
this.chunkZ = context.originZ() >> CHUNK_SHIFT;
this.centerX = CENTER_OFFSET_BLOCKS + (chunkX << CHUNK_SHIFT);
this.centerZ = CENTER_OFFSET_BLOCKS + (chunkZ << CHUNK_SHIFT);
this.rng = host.chunkRandom(chunkX, chunkZ);
this.traceRegen = Thread.currentThread().getName().startsWith(REGEN_THREAD_PREFIX) && host.debugging();
this.golden = chunk.goldenDebug(chunkX, chunkZ);
this.worldHeight = context.mantle().bounds().maxY();
this.caveLavaHeight = host.caveLavaHeight();
this.effective = new EffectivePlacements(dimensionRequiresSurfaceSupport(), dimensionSurfaceSupportBuffer());
this.caves = new CaveSettings(dimensionLevel(CaveProfile.class));
}
/** Places what originates in this chunk. */
void place() {
Column column = readColumn();
if (host.debugging() && (chunkX & DIAGNOSTIC_CHUNK_MASK) == 0 && (chunkZ & DIAGNOSTIC_CHUNK_MASK) == 0) {
logCaveDiagnostics(column);
}
if (traceRegen) {
logLayerStart(column);
}
Tally tally = placeObjects(column);
placeProceduralObjects(column);
if (upperObjectsEnabled()) {
placeUpperObjects(column);
}
if (traceRegen) {
logLayerDone(tally);
}
}
/** The region and biomes at the chunk's centre and what each declares. */
private Column readColumn() {
ResourceId region = host.regionAt(centerX, centerZ);
ResourceId surface = host.surfaceBiomeAt(centerX, centerZ);
int surfaceY = surfaceY(centerX, centerZ);
ResourceId cave = resolveCaveObjectBiome(surfaceY, surface);
return new Column(region, surface, cave, surfaceY, objectsOf(cave, region, surface), proceduralOf(cave, region, surface),
profilesOf(cave, region, surface));
}
private int surfaceY(int x, int z) {
return (int) Math.round(terrain.surfaceY(x, z));
}
private ResourceId resolveCaveObjectBiome(int surfaceY, ResourceId surfaceBiome) {
ResourceId legacy = caveBiomeAt(Math.max(1, surfaceY - LEGACY_CAVE_SAMPLE_DEPTH)).orElse(surfaceBiome);
ResourceId ladderChoice = null;
for (int depth : CAVE_BIOME_SAMPLE_DEPTHS) {
Optional<ResourceId> sampled = caveBiomeAt(Math.max(1, surfaceY - depth));
if (sampled.isEmpty() || sampled.get().equals(surfaceBiome)) {
continue;
}
if (hasCarvingObjects(host.biomeDeclaration(sampled.get(), ObjectSettings.class))) {
ladderChoice = sampled.get();
}
}
return ladderChoice != null ? ladderChoice : legacy;
}
private Optional<ResourceId> caveBiomeAt(int y) {
return terrain.biome(centerX, y, centerZ).caveBiome();
}
private static boolean hasCarvingObjects(Optional<ObjectSettings> settings) {
return settings.isPresent() && !carvingObjects(settings.get()).isEmpty();
}
private ColumnObjects objectsOf(ResourceId cave, ResourceId region, ResourceId surface) {
List<Entry<ObjectSettings>> entries = context.settings().at(ObjectSettings.class, centerX, centerZ);
return new ColumnObjects(level(entries, Target.BIOME), caveSettings(cave, surface, entries, ObjectSettings.class), level(entries, Target.REGION));
}
private ColumnProcedural proceduralOf(ResourceId cave, ResourceId region, ResourceId surface) {
List<Entry<ProceduralObjectSettings>> entries = context.settings().at(ProceduralObjectSettings.class, centerX, centerZ);
return new ColumnProcedural(level(entries, Target.BIOME),
caveSettings(cave, surface, entries, ProceduralObjectSettings.class), level(entries, Target.REGION));
}
private ColumnProfiles profilesOf(ResourceId cave, ResourceId region, ResourceId surface) {
List<Entry<CaveProfile>> entries = context.settings().at(CaveProfile.class, centerX, centerZ);
return new ColumnProfiles(level(entries, Target.BIOME), caveSettings(cave, surface, entries, CaveProfile.class), level(entries, Target.REGION));
}
private <F extends IrisFeature> F caveSettings(ResourceId cave, ResourceId surface, List<Entry<F>> entries, Class<F> type) {
if (cave.equals(surface)) {
return level(entries, Target.BIOME);
}
return host.biomeDeclaration(cave, type).orElse(null);
}
private <F extends IrisFeature> F dimensionLevel(Class<F> type) {
return level(context.settings().at(type, centerX, centerZ), Target.DIMENSION);
}
private static <F extends IrisFeature> F level(List<Entry<F>> entries, Target level) {
for (Entry<F> entry : entries) {
if (entry.level() == level) {
return entry.value();
}
}
return null;
}
private boolean dimensionRequiresSurfaceSupport() {
RequireSurfaceSupportSettings settings = dimensionLevel(RequireSurfaceSupportSettings.class);
return settings == null ? new RequireSurfaceSupportSettings().require() : settings.require();
}
private int dimensionSurfaceSupportBuffer() {
SurfaceSupportBufferSettings settings = dimensionLevel(SurfaceSupportBufferSettings.class);
return settings == null ? new SurfaceSupportBufferSettings().buffer() : settings.buffer();
}
private boolean upperObjectsEnabled() {
UpperObjectsSettings settings = dimensionLevel(UpperObjectsSettings.class);
return settings != null && settings.enabled() && terrain.upperDimensionY(centerX, centerZ).isPresent();
}
private boolean upperObjectsForced() {
UpperObjectsForceSettings settings = dimensionLevel(UpperObjectsForceSettings.class);
return settings != null && settings.force();
}
private static List<ObjectPlacement> surfaceObjects(ObjectSettings settings) {
return settings == null ? List.of() : settings.objects().stream().filter(p -> p.carvingSupport().supportsSurface()).toList();
}
private static List<ObjectPlacement> carvingObjects(ObjectSettings settings) {
return settings == null ? List.of() : settings.objects().stream().filter(p -> p.carvingSupport().supportsCarving()).toList();
}
private CaveAnchors newAnchors() {
return new CaveAnchors(chunk.carved(), terrain, worldHeight, caveLavaHeight);
}
private Tally placeObjects(Column column) {
Tally tally = new Tally();
CaveProfile biomeCaveProfile = caves.resolve(column.profiles().cave(), column.profiles().region());
CaveProfile regionCaveProfile = caves.resolve(column.profiles().region(), column.profiles().cave());
CaveAnchors anchors = newAnchors();
placeSurfaceScope(tally, "biome-surface", surfaceObjects(column.objects().surface()), column.surface().toString());
placeCaveScope(tally, "biome-cave", carvingObjects(column.objects().cave()), biomeCaveProfile, column.cave(), column.cave().toString(), anchors);
placeSurfaceScope(tally, "region-surface", surfaceObjects(column.objects().region()), column.region().toString());
placeCaveScope(tally, "region-cave", carvingObjects(column.objects().region()), regionCaveProfile, null, column.region().toString(), anchors);
return tally;
}
private void placeSurfaceScope(Tally tally, String scope, List<ObjectPlacement> placements, String ownerName) {
for (ObjectPlacement placement : placements) {
tally.checked(scope);
boolean passes = rng.chance(placement.chance() + rng.d(-CHANCE_JITTER, CHANCE_JITTER));
traceChance(scope, passes, placement);
if (!passes) {
continue;
}
tally.triggered(scope);
try {
placeObject(tally, placement, scope);
} catch (Throwable failure) {
tally.errors++;
logPlacementFailure("Failed to place objects in the following " + ownerKind(scope) + ": " + ownerName, placement, failure);
}
}
}
private void placeCaveScope(Tally tally, String scope, List<ObjectPlacement> placements, CaveProfile profile,
ResourceId expectedCaveBiome, String ownerName, CaveAnchors anchors) {
for (ObjectPlacement placement : placements) {
tally.checked(scope);
boolean passes = rng.chance(placement.chance());
traceChance(scope, passes, placement);
if (!passes) {
continue;
}
tally.triggered(scope);
try {
placeCaveObject(tally, placement, profile, scope, expectedCaveBiome, anchors);
} catch (Throwable failure) {
tally.errors++;
logPlacementFailure("Failed to place cave objects in the following " + ownerKind(scope) + ": " + ownerName, placement, failure);
}
}
}
private static String ownerKind(String scope) {
return scope.startsWith("biome") ? "biome" : "region";
}
private void logPlacementFailure(String message, ObjectPlacement placement, Throwable failure) {
log.error(message, failure);
log.error("Object(s) " + String.join(", ", placement.place()) + " (" + failure.getClass().getSimpleName() + ").", null);
log.error("Are these objects missing?", null);
}
private void placeObject(Tally tally, ObjectPlacement placement, String scope) {
int blockX = chunkX << CHUNK_SHIFT;
int blockZ = chunkZ << CHUNK_SHIFT;
int density = host.density(placement, rng, blockX, blockZ);
for (int i = 0; i < density; i++) {
tally.attempts++;
Optional<PlaceableObject> picked = host.pickScaled(placement, rng);
if (picked.isEmpty()) {
tally.nullObjects++;
traceNullObject(scope, i, density, placement);
continue;
}
PlaceableObject object = picked.get();
int x = rng.i(blockX, blockX + CHUNK_WIDTH_BLOCKS);
int z = rng.i(blockZ, blockZ + CHUNK_WIDTH_BLOCKS);
PlacementChanges changes = effective.forSurface(placement, object);
boolean treePlacement = isTreePlacement(object, placement);
int id = rng.i(0, Integer.MAX_VALUE);
String goldenTag = golden ? scope + "/" + object.key() : null;
if (golden) {
log.debug("Goldendebug object attempt: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key()
+ " densityIndex=" + i + " xx=" + x + " zz=" + z + " mode=" + placement.mode());
}
try {
PlacementTags tags = tags(object, id, "surface", treePlacement, placement);
int result = chunk.placeOnSurface(object, x, z, placement, changes, tags, rng, goldenTag);
if (result >= 0) {
tally.placed++;
} else {
tally.rejected++;
}
traceObjectResult(scope, object, result, x, z, i, density);
} catch (Throwable failure) {
tally.errors++;
log.error("Regen object placement exception: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key()
+ " densityIndex=" + i + " density=" + density + " error=" + failure.getClass().getSimpleName() + ":" + failure.getMessage(), failure);
}
}
}
private void placeCaveObject(Tally tally, ObjectPlacement placement, CaveProfile profile, String scope,
ResourceId expectedCaveBiome, CaveAnchors anchors) {
int minX = chunkX << CHUNK_SHIFT;
int minZ = chunkZ << CHUNK_SHIFT;
int density = host.density(placement, rng, minX, minZ);
CaveAnchors.Search search = caves.searchFor(placement, profile);
for (int i = 0; i < density; i++) {
tally.attempts++;
Optional<PlaceableObject> picked = host.pickScaled(placement, rng);
if (picked.isEmpty()) {
tally.nullObjects++;
traceNullObject(scope, i, density, placement);
CaveRejects.log(host, log, scope, "NULL_OBJECT", chunkX, chunkZ, placement, null, i, density, search, null, null);
continue;
}
PlaceableObject object = picked.get();
CaveAnchors.Anchor anchor = anchors.find(rng, minX, minZ, search, expectedCaveBiome, placement.underwater());
if (anchor == null) {
tally.rejected++;
CaveRejects.log(host, log, scope, "NO_ANCHOR", chunkX, chunkZ, placement, object, i, density, search, null, null);
continue;
}
int id = rng.i(0, Integer.MAX_VALUE);
PlacementChanges changes = effective.forCave(placement, object, profile);
try {
PlacementTags tags = tags(object, id, "cave", isTreePlacement(object, placement), placement);
CavePlacement contained = chunk.placeInCave(object, anchor.x(), anchor.y(), anchor.z(), placement, changes,
search.minDepthBelowSurface(), tags, rng, null);
tallyCave(tally, contained, scope, object, placement, i, density, search, anchor);
} catch (Throwable failure) {
tally.errors++;
log.error("Regen cave object placement exception: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key()
+ " densityIndex=" + i + " density=" + density + " error=" + failure.getClass().getSimpleName() + ":" + failure.getMessage(), failure);
CaveRejects.log(host, log, scope, "EXCEPTION", chunkX, chunkZ, placement, object, i, density, search, anchor.y(), failure);
}
}
}
private void tallyCave(Tally tally, CavePlacement contained, String scope, PlaceableObject object, ObjectPlacement placement,
int index, int density, CaveAnchors.Search search, CaveAnchors.Anchor anchor) {
if (contained.wroteBlocks()) {
tally.placed++;
} else {
tally.rejected++;
CaveRejects.log(host, log, scope, rejectReason(contained), chunkX, chunkZ, placement, object, index, density, search, anchor.y(), null);
}
if (traceRegen) {
log.debug("Regen cave object placement result: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key()
+ " resultY=" + contained.resultY() + " anchorY=" + anchor.y() + " px=" + anchor.x() + " pz=" + anchor.z()
+ " wroteBlocks=" + contained.wroteBlocks() + " densityIndex=" + index + " density=" + density);
}
}
private static String rejectReason(CavePlacement contained) {
if (contained.resultY() < 0) {
return "PLACE_NEGATIVE";
}
return contained.commit() == CavePlacement.Commit.REJECTED_BOUNDS ? "CONTAINMENT" : "NO_WRITES";
}
private void placeProceduralObjects(Column column) {
List<ProceduralPlacement> surface = proceduralPlacements(column.procedural().surface());
List<ProceduralPlacement> region = proceduralPlacements(column.procedural().region());
CaveProfile surfaceProfile = caves.resolve(column.profiles().surface(), column.profiles().region());
CaveProfile regionProfile = caves.resolve(column.profiles().region(), column.profiles().cave());
placeProceduralFrom(surface, column.surface().toString(), surfaceProfile, column.surface());
placeProceduralFrom(region, column.region().toString(), regionProfile, null);
if (!column.cave().equals(column.surface())) {
CaveProfile caveProfile = caves.resolve(column.profiles().cave(), column.profiles().region());
placeProceduralFrom(proceduralPlacements(column.procedural().cave()), column.cave().toString(), caveProfile, column.cave());
}
}
private List<ProceduralPlacement> proceduralPlacements(ProceduralObjectSettings settings) {
return settings == null ? List.of() : host.procedural(settings);
}
private void placeProceduralFrom(List<ProceduralPlacement> placements, String scope, CaveProfile caveProfile, ResourceId expectedCaveBiome) {
if (placements.isEmpty()) {
return;
}
int blockX = chunkX << CHUNK_SHIFT;
int blockZ = chunkZ << CHUNK_SHIFT;
CaveAnchors anchors = newAnchors();
for (ProceduralPlacement placement : placements) {
boolean chancePassed = passesProceduralChance(rng, placement.chance());
if (golden) {
log.debug("Goldendebug procedural chance: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " placement=" + placement.name() + " passed=" + chancePassed);
}
if (!chancePassed) {
continue;
}
placeProcedural(placement, scope, caveProfile, expectedCaveBiome, anchors, blockX, blockZ);
}
}
private void placeProcedural(ProceduralPlacement placement, String scope, CaveProfile caveProfile, ResourceId expectedCaveBiome,
CaveAnchors anchors, int blockX, int blockZ) {
boolean carving = placement.carvingSupport() == CarvingMode.CARVING_ONLY;
CaveAnchors.Search search = caves.searchFor(placement, caveProfile);
int density = Math.max(1, placement.density());
for (int i = 0; i < density; i++) {
Optional<PlaceableObject> picked = placement.variant(rng);
if (picked.isEmpty()) {
if (golden) {
log.debug("Goldendebug procedural pick: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name() + " densityIndex=" + i + " variant=null");
}
continue;
}
PlaceableObject variant = picked.get();
CaveAnchors.Anchor anchor = carving ? anchors.find(rng, blockX, blockZ, search, expectedCaveBiome, placement.underwater()) : null;
if (carving && anchor == null) {
if (golden) {
log.debug("Goldendebug procedural cave anchor rejected: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name()
+ " minDepthBelowSurface=" + search.minDepthBelowSurface());
}
continue;
}
int x = anchor == null ? rng.i(blockX, blockX + CHUNK_WIDTH_BLOCKS) : anchor.x();
int z = anchor == null ? rng.i(blockZ, blockZ + CHUNK_WIDTH_BLOCKS) : anchor.z();
int id = rng.i(0, Integer.MAX_VALUE);
if (golden) {
logProceduralPick(placement, variant, i, x, z, carving);
}
try {
placeProceduralVariant(placement, variant, scope, caveProfile, search, anchor, x, z, id);
} catch (Throwable failure) {
log.error("Failed to place procedural object '" + placement.name() + "' in " + scope, failure);
}
}
}
private void placeProceduralVariant(ProceduralPlacement placement, PlaceableObject variant, String scope, CaveProfile caveProfile,
CaveAnchors.Search search, CaveAnchors.Anchor anchor, int x, int z, int id) {
String goldenTag = golden ? scope + "/" + placement.name() : null;
PlacementTags tags = tags(variant, id, "procedural", placement.tree(), false);
int resultY;
String commit = "n/a";
if (anchor != null) {
PlacementChanges changes = effective.forCave(placement, variant, caveProfile);
CavePlacement contained = chunk.placeInCave(variant, x, anchor.y(), z, placement, changes, search.minDepthBelowSurface(), tags, rng, goldenTag);
resultY = contained.resultY();
commit = contained.commit().toString();
} else {
resultY = chunk.placeOnSurface(variant, x, z, placement, PlacementChanges.NONE, tags, rng, goldenTag);
}
if (golden) {
log.debug("Goldendebug procedural result: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name()
+ " variant=" + variant.key() + " xx=" + x + " zz=" + z + " resultY=" + resultY + " commit=" + commit);
}
}
private void logProceduralPick(ProceduralPlacement placement, PlaceableObject variant, int index, int x, int z, boolean carving) {
List<PlaceableObject> pool = placement.variants();
log.debug("Goldendebug procedural pick: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name() + " densityIndex=" + index
+ " variant=" + variant.key() + " variantIndex=" + pool.indexOf(variant) + "/" + pool.size() + " xx=" + x + " zz=" + z
+ " mode=" + placement.mode() + " carving=" + carving);
}
static boolean passesProceduralChance(RNG rng, double chance) {
if (chance <= 0.0) {
return false;
}
if (chance >= 1.0) {
return true;
}
return rng.chance(Math.max(0.0, Math.min(1.0, chance + rng.d(-CHANCE_JITTER, CHANCE_JITTER))));
}
private void placeUpperObjects(Column column) {
Optional<ObjectHost.UpperObjects> upper = host.upperObjects(centerX, centerZ);
if (upper.isEmpty() || (upper.get().biome() == null && upper.get().region() == null)) {
return;
}
boolean forcePlace = upperObjectsForced();
placeUpperScope(upper.get().biome(), upper.get().biomeKey(), "upper-biome-surface", "biome", forcePlace);
placeUpperScope(upper.get().region(), upper.get().regionKey(), "upper-region-surface", "region", forcePlace);
}
private void placeUpperScope(ObjectSettings settings, String ownerKey, String scope, String kind, boolean forcePlace) {
for (ObjectPlacement placement : surfaceObjects(settings)) {
if (!rng.chance(placement.chance() + rng.d(-CHANCE_JITTER, CHANCE_JITTER))) {
continue;
}
try {
placeUpperObject(placement, forcePlace, scope);
} catch (Throwable failure) {
log.error("Failed to place upper-dimension objects in " + kind + " " + ownerKey + ": " + String.join(", ", placement.place())
+ " (" + failure.getClass().getSimpleName() + ")", failure);
}
}
}
private void placeUpperObject(ObjectPlacement placement, boolean forcePlace, String scope) {
int minX = chunkX << CHUNK_SHIFT;
int minZ = chunkZ << CHUNK_SHIFT;
int density = host.density(placement, rng, minX, minZ);
for (int i = 0; i < density; i++) {
Optional<PlaceableObject> picked = host.pickScaled(placement, rng);
if (picked.isEmpty()) {
continue;
}
PlaceableObject object = picked.get();
int x = rng.i(minX, minX + CHUNK_WIDTH_BLOCKS);
int z = rng.i(minZ, minZ + CHUNK_WIDTH_BLOCKS);
OptionalInt upperSurface = terrain.upperDimensionY(x, z);
if (upperSurface.isEmpty() || upperSurface.getAsInt() >= worldHeight - UPPER_SURFACE_MARGIN_BLOCKS) {
continue;
}
int anchorY = upperSurface.getAsInt() - 1 - Math.floorDiv(object.height(), 2);
if (anchorY <= MINIMUM_UPPER_ANCHOR_Y) {
continue;
}
int id = rng.i(0, Integer.MAX_VALUE);
PlacementChanges changes = PlacementChanges.NONE.withPlace(List.of(String.valueOf(object.key())))
.withMode(ObjectPlaceMode.CENTER_HEIGHT)
.withUpsideDown(true).withCarvingSupport(CarvingMode.ANYWHERE);
if (forcePlace) {
changes = changes.withForcePlace(true);
}
PlacementTags tags = tags(object, id, "upper", isTreePlacement(object, placement), placement);
int result = chunk.placeUpper(object, x, anchorY, z, placement, changes, tags, rng);
if (traceRegen) {
log.debug("Upper object placement: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key() + " anchorY="
+ anchorY + " upperSurfaceY=" + upperSurface.getAsInt() + " resultY=" + result + " forcePlace=" + forcePlace);
}
}
}
private PlacementTags tags(PlaceableObject object, int id, String context, boolean treePlacement, PlacementSource placement) {
return tags(object, id, context, treePlacement, placement.isDolphinTarget() && placement.underwater());
}
private PlacementTags tags(PlaceableObject object, int id, String context, boolean treePlacement, boolean buriedTreasure) {
return new PlacementTags(placementMarker(object, id, context), treePlacement, buriedTreasure);
}
private String placementMarker(PlaceableObject object, int id, String context) {
String key = object == null ? null : object.key();
if (key == null || key.isEmpty() || key.equals("null")) {
String fingerprint = context + "|" + (object == null ? "<null>" : object.getClass().getSimpleName());
log.warnOnce(fingerprint, "Skipping placement marker write: the object has no loadKey (context=" + context + "). "
+ "This would previously produce 'Couldn't find Object: null' warnings on chunk reload.");
return null;
}
return key + "@" + id;
}
private static boolean isTreePlacement(PlaceableObject object, ObjectPlacement placement) {
String key = object == null ? null : object.key();
return (key != null && key.startsWith(TREE_FOLDER)) || (placement != null && !placement.trees().isEmpty());
}
private void traceChance(String scope, boolean passes, ObjectPlacement placement) {
if (!traceRegen) {
return;
}
log.debug("Regen object placer chance: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " chanceResult=" + passes
+ " chanceBase=" + placement.chance() + " densityMid=" + placement.middleDensity() + " objects=" + placement.place().size());
}
private void traceNullObject(String scope, int index, int density, ObjectPlacement placement) {
if (!traceRegen) {
return;
}
log.debug("Regen object placement null object: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " densityIndex=" + index
+ " density=" + density + " placementKeys=" + String.join(",", placement.place()));
}
private void traceObjectResult(String scope, PlaceableObject object, int result, int x, int z, int index, int density) {
if (golden) {
log.debug("Goldendebug object result: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key()
+ " resultY=" + result + " fallback=surface");
}
if (traceRegen) {
log.debug("Regen object placement result: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.key()
+ " resultY=" + result + " px=" + x + " pz=" + z + " fallback=surface densityIndex=" + index + " density=" + density);
}
}
private void logCaveDiagnostics(Column column) {
int carvedBlocks = 0;
int maxY = Math.min(worldHeight - 1, column.surfaceY() - DIAGNOSTIC_SURFACE_MARGIN);
for (int y = 1; y < maxY; y++) {
if (chunk.carved().isCarved(centerX, y, centerZ)) {
carvedBlocks++;
}
}
log.debug("Cave object diag: chunk=" + chunkX + "," + chunkZ + " surfaceBiome=" + column.surface() + " caveBiome=" + column.cave()
+ " surfaceY=" + column.surfaceY() + " maxAnchorY=" + maxY + " carvedAtCenter=" + carvedBlocks
+ " biomeCarvingObjects=" + carvingObjects(column.objects().cave()).size()
+ " regionCarvingObjects=" + carvingObjects(column.objects().region()).size()
+ " sameBiome=" + column.cave().equals(column.surface()));
}
private void logLayerStart(Column column) {
log.debug("Regen object layer start: chunk=" + chunkX + "," + chunkZ + " surfaceBiome=" + column.surface() + " caveBiome=" + column.cave()
+ " region=" + column.region() + " biomeSurfacePlacers=" + surfaceObjects(column.objects().surface()).size()
+ " biomeCavePlacers=" + carvingObjects(column.objects().cave()).size()
+ " regionSurfacePlacers=" + surfaceObjects(column.objects().region()).size()
+ " regionCavePlacers=" + carvingObjects(column.objects().region()).size());
}
private void logLayerDone(Tally tally) {
log.debug("Regen object layer done: chunk=" + chunkX + "," + chunkZ + " " + tally.describe()
+ " objectAttempts=" + tally.attempts + " objectPlaced=" + tally.placed + " objectRejected=" + tally.rejected
+ " objectNull=" + tally.nullObjects + " objectErrors=" + tally.errors);
}
private record Column(ResourceId region, ResourceId surface, ResourceId cave, int surfaceY, ColumnObjects objects,
ColumnProcedural procedural, ColumnProfiles profiles) {
}
private record ColumnObjects(ObjectSettings surface, ObjectSettings cave, ObjectSettings region) {
}
private record ColumnProcedural(ProceduralObjectSettings surface, ProceduralObjectSettings cave, ProceduralObjectSettings region) {
}
private record ColumnProfiles(CaveProfile surface, CaveProfile cave, CaveProfile region) {
}
/** What placing the objects of a chunk came to. */
private static final class Tally {
private final java.util.Map<String, int[]> scopes = new java.util.LinkedHashMap<>();
private int attempts;
private int placed;
private int rejected;
private int nullObjects;
private int errors;
void checked(String scope) {
scopes.computeIfAbsent(scope, key -> new int[2])[0]++;
}
void triggered(String scope) {
scopes.computeIfAbsent(scope, key -> new int[2])[1]++;
}
String describe() {
StringBuilder text = new StringBuilder();
scopes.forEach((scope, counts) -> text.append(scope).append("PlacersChecked=").append(counts[0])
.append(' ').append(scope).append("PlacersTriggered=").append(counts[1]).append(' '));
return text.toString();
}
}
}
@@ -0,0 +1,90 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.anchor.PlaceTrait;
import art.arcane.iris.builtin.carve.CaveProfile;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.builtin.objects.PlacementChanges;
import art.arcane.iris.builtin.objects.PlacementSource;
import java.util.List;
import java.util.Locale;
/** How a dimension and a cave profile change the placement an object is placed with. */
final class EffectivePlacements {
private static final String IMPORTS_FOLDER = "imports/";
private final boolean dimensionRequiresSurfaceSupport;
private final int dimensionSurfaceSupportBuffer;
EffectivePlacements(boolean dimensionRequiresSurfaceSupport, int dimensionSurfaceSupportBuffer) {
this.dimensionRequiresSurfaceSupport = dimensionRequiresSurfaceSupport;
this.dimensionSurfaceSupportBuffer = dimensionSurfaceSupportBuffer;
}
/** The changes to make to {@code placement} to place {@code object} on the surface. */
PlacementChanges forSurface(PlacementSource placement, PlaceableObject object) {
return withDimensionSurfaceSupport(placement, withImportedMode(placement, object, PlacementChanges.NONE));
}
/** The changes to make to {@code placement} to place {@code object} in a cave with the cave profile {@code caveProfile}. */
PlacementChanges forCave(PlacementSource placement, PlaceableObject object, CaveProfile caveProfile) {
PlacementChanges changes = forSurface(placement, object);
ObjectPlaceMode mode = changes.mode() != null ? changes.mode() : placement.mode();
if (mode != ObjectPlaceMode.CENTER_HEIGHT || caveProfile == null) {
return changes;
}
ObjectPlaceMode profileMode = caveProfile.defaultObjectPlaceMode().orElse(null);
if (profileMode == null) {
return changes;
}
String key = object.key();
List<String> place = key == null || key.isBlank() ? List.of() : List.of(key);
return changes.withPlace(place).withMode(profileMode);
}
/** Imported objects are placed with the fast minimal stilt unless their mode finds its own height. */
private static PlacementChanges withImportedMode(PlacementSource placement, PlaceableObject object, PlacementChanges changes) {
String key = object.key();
if (key == null || key.isBlank() || !isImported(key)) {
return changes;
}
ObjectPlaceMode mode = placement.mode();
if (mode.placeMode().has(PlaceTrait.FREE_HEIGHT) || mode == ObjectPlaceMode.FAST_MIN_STILT) {
return changes;
}
return changes.withPlace(List.of(key)).withMode(ObjectPlaceMode.FAST_MIN_STILT);
}
private static boolean isImported(String key) {
return key.toLowerCase(Locale.ROOT).contains(IMPORTS_FOLDER);
}
/** The dimension widens the buffer of a placement, never narrows it, and its support requirement applies on top of the placement's own: both have to want it. */
private PlacementChanges withDimensionSurfaceSupport(PlacementSource placement, PlacementChanges changes) {
boolean require = placement.requireSurfaceSupport() && dimensionRequiresSurfaceSupport;
int buffer = Math.max(placement.surfaceSupportBuffer(), dimensionSurfaceSupportBuffer);
if (require == placement.requireSurfaceSupport() && buffer == placement.surfaceSupportBuffer()) {
return changes;
}
return changes.withSurfaceSupport(require, buffer);
}
}
@@ -29,6 +29,7 @@ import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.mantle.MantleWriter;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
import art.arcane.iris.engine.object.placement.IrisObjectVacuum;
import art.arcane.iris.engine.object.placement.IObjectPlacer;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.prefab.IrisObject;
@@ -593,7 +594,7 @@ public class FloatingObjectPlacing {
size = IrisObject.sampleSize(file);
sizeCache.put(objectKey, size);
}
int reach = ObjectPlacing.calculatePlacementReach(size, placement);
int reach = calculatePlacementReach(size, placement);
if (reach > 128 && warnedLargeObjects.add(objectKey)) {
log.warn("Floating object " + objectKey + " has a large placement reach (" + reach + " blocks) and may increase memory usage!");
}
@@ -605,4 +606,53 @@ public class FloatingObjectPlacing {
}
return radius;
}
static int calculatePlacementReach(IrisBlockVector size, IrisObjectPlacement placement) {
if (size == null) {
return 0;
}
if (placement == null) {
return Math.max(Math.abs(size.getBlockX()), Math.abs(size.getBlockZ()));
}
double scale = placement.getScale() != null ? Math.max(1D, placement.getScale().getMaxScale()) : 1D;
int width = scaledDimension(size.getBlockX(), scale);
int height = scaledDimension(size.getBlockY(), scale);
int depth = scaledDimension(size.getBlockZ(), scale);
IrisObjectRotation rotation = placement.getRotation();
boolean rotateX = rotation != null && rotation.isEnabled() && rotation.getXAxis() != null && rotation.getXAxis().enabled();
boolean rotateZ = rotation != null && rotation.isEnabled() && rotation.getZAxis() != null && rotation.getZAxis().enabled();
int footprint = rotateX || rotateZ ? Math.max(width, Math.max(height, depth)) : Math.max(width, depth);
int translation = calculateTranslationReach(placement.getTranslate(), rotation, rotateX || rotateZ);
int warp = placement.getWarp() != null && !placement.getWarp().isFlat()
? (int) Math.ceil(Math.abs(placement.getWarp().getMultiplier()) / 2D)
: 0;
int vacuum = placement.getMode().placeMode().bendsTerrain()
? 2 * IrisObjectVacuum.resolveRadius(placement.getMode().placeMode().vacuum(), placement.getVacuumSettings())
: 0;
long reach = (long) footprint + translation + warp + vacuum;
return reach > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) reach;
}
private static int scaledDimension(int dimension, double scale) {
int absoluteDimension = Math.abs(dimension);
if (scale <= 1D) {
return absoluteDimension;
}
return (int) Math.ceil((absoluteDimension * scale) + (scale * 2D));
}
private static int calculateTranslationReach(IrisObjectTranslate translate, IrisObjectRotation rotation, boolean rotateVertically) {
if (translate == null || !translate.canTranslate()) {
return 0;
}
double x = translate.getX();
double y = translate.getY();
double z = translate.getZ();
if (rotateVertically) {
return (int) Math.ceil(Math.sqrt((x * x) + (y * y) + (z * z)));
}
boolean rotateY = rotation != null && rotation.isEnabled() && rotation.getYAxis() != null && rotation.getYAxis().enabled();
return rotateY ? (int) Math.ceil(Math.hypot(x, z)) : (int) Math.max(Math.abs(x), Math.abs(z));
}
}
@@ -25,7 +25,7 @@ import art.arcane.iris.engine.object.prefab.TileData;
import art.arcane.iris.spi.PlatformBlockState;
import com.volmit.ModuleLog;
final class GoldenDebugObjectPlacer implements IObjectPlacer {
public final class GoldenDebugObjectPlacer implements IObjectPlacer {
private static final int[] GOLDEN_DEBUG_TARGET = parseGoldenDebugTarget(resolveGoldenDebugSpec());
private static final boolean GOLDEN_DEBUG = GOLDEN_DEBUG_TARGET != null;
@@ -33,7 +33,7 @@ final class GoldenDebugObjectPlacer implements IObjectPlacer {
private final String tag;
private final ModuleLog log;
GoldenDebugObjectPlacer(IObjectPlacer delegate, String tag, ModuleLog log) {
public GoldenDebugObjectPlacer(IObjectPlacer delegate, String tag, ModuleLog log) {
this.delegate = delegate;
this.tag = tag;
this.log = log;
@@ -70,7 +70,7 @@ final class GoldenDebugObjectPlacer implements IObjectPlacer {
}
}
static boolean isGoldenDebugChunk(int x, int z) {
public static boolean isGoldenDebugChunk(int x, int z) {
return GOLDEN_DEBUG
&& Math.abs(GOLDEN_DEBUG_TARGET[0] - x) <= GOLDEN_DEBUG_TARGET[2]
&& Math.abs(GOLDEN_DEBUG_TARGET[1] - z) <= GOLDEN_DEBUG_TARGET[2];
@@ -18,13 +18,14 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.core.modules.IrisPackWorld;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.service.ObjectsAt;
import com.volmit.world.PackWorld;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -36,38 +37,28 @@ import java.util.Set;
public final class ObjectLocating implements ObjectsAt {
@Override
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
return ObjectModule.placing(engine(world), world.log()).guess(chunkX, chunkZ);
return ObjectPlacing.of(world).guess(chunkX, chunkZ);
}
@Override
public PlacedBy placedBy(PackWorld world, String objectKey) {
Engine engine = engine(world);
Set<String> biomes = new LinkedHashSet<>();
for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) {
if (biome != null && placesObject(biome.getSurfaceObjects(), objectKey)) {
biomes.add(biome.getLoadKey());
}
}
Set<String> regions = new LinkedHashSet<>();
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
if (region != null && placesObject(region.getSurfaceObjects(), objectKey)) {
regions.add(region.getLoadKey());
for (Declaration<ObjectSettings> declaration : ObjectHost.of(world).declarations(ObjectSettings.class)) {
if (!placesObject(declaration.settings().objects(), objectKey)) {
continue;
}
(declaration.level() == Target.BIOME ? biomes : regions).add(declaration.key());
}
return new PlacedBy(biomes, regions);
}
private static boolean placesObject(List<IrisObjectPlacement> placements, String objectKey) {
for (IrisObjectPlacement placement : placements) {
if (placement != null && placement.getPlace().contains(objectKey)) {
private static boolean placesObject(List<ObjectPlacement> placements, String objectKey) {
for (ObjectPlacement placement : placements) {
if (placement != null && placement.carvingSupport().supportsSurface() && placement.place().contains(objectKey)) {
return true;
}
}
return false;
}
private static Engine engine(PackWorld world) {
return IrisPackWorld.of(world).engine();
}
}
@@ -19,18 +19,14 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.objects.coral.Coral;
import art.arcane.iris.builtin.objects.crystal.Crystal;
import art.arcane.iris.builtin.objects.formation.Formation;
import art.arcane.iris.builtin.objects.fungi.Fungus;
import art.arcane.iris.builtin.objects.ruin.Ruin;
import art.arcane.iris.builtin.objects.tree.TreeCanopy;
import art.arcane.iris.builtin.objects.tree.TreeDecorator;
import art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf;
import art.arcane.iris.core.modules.IrisMantleChunk;
import art.arcane.iris.core.modules.IrisPackSettings;
import art.arcane.iris.core.modules.IrisPackWorld;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.RequireSurfaceSupportSettings;
import art.arcane.iris.builtin.objects.SurfaceSupportBufferSettings;
import art.arcane.iris.builtin.objects.TreeGrowthSettings;
import art.arcane.iris.builtin.objects.UpperObjectsForceSettings;
import art.arcane.iris.builtin.objects.UpperObjectsSettings;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
@@ -72,33 +68,26 @@ public final class ObjectModule implements IrisModule, ModuleLifecycle {
log = registry.log();
registry.registerService(ObjectsAt.class, new ObjectLocating());
registry.registerService(SaplingGrowth.class, new TreeGrowing());
registry.registerHeldType(TreeCanopy.class);
registry.registerHeldType(TreeDecorator.class);
registry.registerHeldType(TreeSecondaryLeaf.class);
registry.registerHeldType(Coral.class);
registry.registerHeldType(Crystal.class);
registry.registerHeldType(Formation.class);
registry.registerHeldType(Fungus.class);
registry.registerHeldType(Ruin.class);
registry.registerSettings(ObjectSettings.class);
registry.registerSettings(ProceduralObjectSettings.class);
registry.registerSettings(TreeGrowthSettings.class);
registry.registerSettings(RequireSurfaceSupportSettings.class);
registry.registerSettings(SurfaceSupportBufferSettings.class);
registry.registerSettings(UpperObjectsSettings.class);
registry.registerSettings(UpperObjectsForceSettings.class);
registry.registerLifecycle(this);
}
@Override
public void warmUp(PackWorld world) {
new ObjectWarmUp(IrisPackWorld.of(world).engine()).warm();
new ObjectWarmUp(world).warm();
}
private static void place(MantleStageContext context) {
IrisMantleChunk chunk = IrisMantleChunk.current();
placing(chunk.engine(), context.log()).place(chunk.writer(), chunk.chunkX(), chunk.chunkZ(), chunk.context());
ObjectPlacing.of(context.world()).place(context);
}
private int reach(PackSettings settings) {
return placing(IrisPackSettings.of(settings).engine(), log).reach();
}
/** The engine runtime's object placing, which the module's {@link ObjectsAt} also asks; {@code log} is the module's. */
public static ObjectPlacing placing(Engine engine, ModuleLog log) {
return engine.getGeneration().state(ObjectPlacing.class, generating -> new ObjectPlacing(generating, log));
return new PlacementReach(ObjectHost.of(settings), log).ofPack(settings);
}
}
File diff suppressed because it is too large. Load diff
@@ -18,16 +18,19 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.procedural.IrisProceduralObjects;
import art.arcane.iris.engine.object.procedural.IrisProceduralPlacement;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralPlacement;
import art.arcane.iris.builtin.IrisSeed;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.FeatureAttachment.Target;
import com.volmit.world.PackWorld;
import java.util.Comparator;
import java.util.List;
/**
* Builds what object placing would build on first use, for every object placement and procedural object the world's
@@ -37,55 +40,48 @@ import java.util.Comparator;
*/
final class ObjectWarmUp {
private static final long ROOT_SEED_SALT = 7777L;
private static final int PROBE_COORDINATE = 0;
private final Engine engine;
private final ObjectHost host;
private final RNG root;
private int warmed;
ObjectWarmUp(Engine engine) {
this.engine = engine;
this.root = new RNG(engine.getSeedManager().getComponent() + ROOT_SEED_SALT);
ObjectWarmUp(PackWorld world) {
this.host = ObjectHost.of(world);
this.root = new RNG(IrisSeed.COMPONENT.of(world) + ROOT_SEED_SALT);
}
void warm() {
KList<IrisBiome> biomes = engine.getAllBiomes();
biomes.sort(Comparator.comparing(IrisBiome::getLoadKey));
for (IrisBiome biome : biomes) {
warmPlacements(biome.getObjects());
warmProcedural(biome.getProceduralObjects());
}
KList<IrisRegion> regions = engine.getDimension().getAllRegions(engine);
regions.sort(Comparator.comparing(IrisRegion::getLoadKey));
for (IrisRegion region : regions) {
warmPlacements(region.getObjects());
warmProcedural(region.getProceduralObjects());
}
}
private void warmPlacements(KList<IrisObjectPlacement> placements) {
if (placements == null) {
return;
}
for (IrisObjectPlacement placement : placements) {
if (placement == null) {
continue;
List<Declaration<ObjectSettings>> placements = byKey(host.declarations(ObjectSettings.class));
List<Declaration<ProceduralObjectSettings>> procedural = byKey(host.declarations(ProceduralObjectSettings.class));
for (Target level : new Target[]{Target.BIOME, Target.REGION}) {
for (Declaration<ObjectSettings> declaration : placements) {
if (declaration.level() == level) {
warmPlacements(declaration.settings().objects());
}
}
for (Declaration<ProceduralObjectSettings> declaration : procedural) {
if (declaration.level() == level) {
warmProcedural(declaration.settings());
}
}
RNG rng = root.nextParallelRNG(warmed++);
placement.getSurfaceWarp(rng, engine.getData(), engine);
placement.getDensity(rng, PROBE_COORDINATE, PROBE_COORDINATE, engine.getData());
}
}
private void warmProcedural(IrisProceduralObjects procedural) {
if (procedural == null) {
return;
}
for (IrisProceduralPlacement placement : procedural.getAllPlacements()) {
private static <F extends com.volmit.IrisFeature> List<Declaration<F>> byKey(List<Declaration<F>> declarations) {
return declarations.stream().sorted(Comparator.comparing(Declaration::key)).toList();
}
private void warmPlacements(List<ObjectPlacement> placements) {
for (ObjectPlacement placement : placements) {
if (placement != null) {
placement.getVariantObject(engine.getData(), root.nextParallelRNG(warmed++));
host.warm(placement, root.nextParallelRNG(warmed++));
}
}
}
private void warmProcedural(ProceduralObjectSettings settings) {
for (ProceduralPlacement placement : host.procedural(settings)) {
placement.variant(root.nextParallelRNG(warmed++));
}
}
}
@@ -0,0 +1,170 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.anchor.PlaceMode;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSize;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.builtin.objects.ProceduralPlacement;
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
import art.arcane.iris.builtin.prepare.ObjectRotation;
import art.arcane.iris.builtin.prepare.ObjectTranslate;
import art.arcane.iris.builtin.vacuum.VacuumSettings;
import com.volmit.ModuleLog;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.PackSettings;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/** How far, in blocks along X and Z, the objects a pack places may write beyond their chunk. */
final class PlacementReach {
private static final int LARGE_REACH_WARNING_BLOCKS = 128;
private static final int MAX_VACUUM_RADIUS_BLOCKS = 128;
private static final double SCALE_PADDING_FACTOR = 2D;
private final ObjectHost host;
private final ModuleLog log;
private final Map<String, Optional<ObjectSize>> sizes = new HashMap<>();
private final Set<String> warnedLargeObjects = new HashSet<>();
PlacementReach(ObjectHost host, ModuleLog log) {
this.host = host;
this.log = log;
}
/** The largest reach of any object placement or procedural object the pack's regions and biomes declare. */
int ofPack(PackSettings settings) {
int radius = 0;
for (Entry<ObjectSettings> entry : settings.declared(ObjectSettings.class)) {
radius = Math.max(radius, ofPlacements(entry.value().objects()));
}
for (Entry<ProceduralObjectSettings> entry : settings.declared(ProceduralObjectSettings.class)) {
radius = Math.max(radius, ofProcedural(entry.value()));
}
return radius;
}
private int ofPlacements(List<ObjectPlacement> placements) {
int radius = 0;
for (ObjectPlacement placement : placements) {
if (placement == null) {
continue;
}
for (String objectKey : placement.place()) {
radius = Math.max(radius, ofObject(placement, objectKey));
}
}
return radius;
}
private int ofObject(ObjectPlacement placement, String objectKey) {
try {
Optional<ObjectSize> size = sizes.computeIfAbsent(objectKey, host::sizeOf);
if (size.isEmpty()) {
return 0;
}
int reach = of(size.get(), placement);
if (reach > LARGE_REACH_WARNING_BLOCKS && warnedLargeObjects.add(objectKey)) {
log.warn("Object " + objectKey + " has a large placement reach (" + reach + " blocks) and may increase memory usage!");
}
return reach;
} catch (Throwable failure) {
log.error("Failed to work out the reach of an object placement", failure);
return 0;
}
}
private int ofProcedural(ProceduralObjectSettings settings) {
int radius = 0;
for (ProceduralPlacement placement : host.procedural(settings)) {
for (PlaceableObject variant : placement.variants()) {
radius = Math.max(radius, of(new ObjectSize(variant.width(), variant.height(), variant.depth()), placement));
}
}
return radius;
}
/** The reach of an object of {@code size} placed with the options a procedural object has. */
static int of(ObjectSize size, ProceduralPlacement placement) {
return of(size, placement.mode().placeMode(), null, placement.rotation(), placement.translate(), null,
placement.vacuumSettings().orElse(null));
}
static int of(ObjectSize size, ObjectPlacement placement) {
return of(size, placement.mode().placeMode(), placement.scale().maxScale(), placement.rotation(), placement.translate(),
placement.warp() == null || placement.warp().isFlat() ? 0 : placement.warp().multiplier(),
placement.vacuumSettings().orElse(null));
}
private static int of(ObjectSize size, PlaceMode mode, Double maxScale, ObjectRotation rotation, ObjectTranslate translate,
Double warpMultiplier, VacuumSettings vacuum) {
double scale = maxScale == null ? 1D : Math.max(1D, maxScale);
int width = scaledDimension(size.width(), scale);
int height = scaledDimension(size.height(), scale);
int depth = scaledDimension(size.depth(), scale);
boolean rotateX = rotation != null && rotation.enabled() && rotation.xAxis() != null && rotation.xAxis().enabled();
boolean rotateZ = rotation != null && rotation.enabled() && rotation.zAxis() != null && rotation.zAxis().enabled();
int footprint = rotateX || rotateZ ? Math.max(width, Math.max(height, depth)) : Math.max(width, depth);
int translation = translationReach(translate, rotation, rotateX || rotateZ);
int warp = warpMultiplier == null ? 0 : (int) Math.ceil(Math.abs(warpMultiplier) / 2D);
int vacuumReach = mode.bendsTerrain() ? 2 * vacuumRadius(mode, vacuum) : 0;
long reach = (long) footprint + translation + warp + vacuumReach;
return reach > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) reach;
}
private static int scaledDimension(int dimension, double scale) {
int absoluteDimension = Math.abs(dimension);
if (scale <= 1D) {
return absoluteDimension;
}
return (int) Math.ceil((absoluteDimension * scale) + (scale * SCALE_PADDING_FACTOR));
}
private static int translationReach(ObjectTranslate translate, ObjectRotation rotation, boolean rotateVertically) {
if (translate == null || (translate.x() == 0 && translate.y() == 0 && translate.z() == 0)) {
return 0;
}
double x = translate.x();
double y = translate.y();
double z = translate.z();
if (rotateVertically) {
return (int) Math.ceil(Math.sqrt((x * x) + (y * y) + (z * z)));
}
AxisRotationClamp yAxis = rotation == null ? null : rotation.yAxis();
boolean rotateY = rotation != null && rotation.enabled() && yAxis != null && yAxis.enabled();
return rotateY ? (int) Math.ceil(Math.hypot(x, z)) : (int) Math.max(Math.abs(x), Math.abs(z));
}
private static int vacuumRadius(PlaceMode mode, VacuumSettings settings) {
int radius = mode.vacuum().defaultRadiusBlocks();
if (settings != null && settings.radius() > 0) {
radius = settings.radius();
}
return Math.max(0, Math.min(MAX_VACUUM_RADIUS_BLOCKS, radius));
}
}
@@ -67,7 +67,7 @@ public final class StructureModule implements IrisModule {
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Structure.PLACE).requires(IrisStages.Objects.PLACE).softAfter(IrisStages.Floating.OBJECTS.ref())
graph.define(IrisStages.Structure.PLACE).softAfter(IrisStages.Objects.PLACE.ref(), IrisStages.Floating.OBJECTS.ref())
.reach(this::reach).run(StructureModule::place);
}
@@ -18,26 +18,22 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.IrisPackWorld;
import art.arcane.iris.core.modules.PlatformBlockStates;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.placement.IObjectPlacer;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.placement.IrisTreeSize;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.prefab.TileData;
import art.arcane.iris.engine.object.procedural.IrisProceduralObjects;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.engine.object.procedural.tree.IrisTreeModes;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.ObjectSink;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.TreeGrowthSettings;
import art.arcane.iris.builtin.objects.TreeMode;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.block.BlockState;
import com.volmit.placement.PlacedBlock;
import com.volmit.resource.ResourceId;
import com.volmit.service.SaplingGrowth;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
@@ -54,84 +50,88 @@ import java.util.Set;
* of blocks the host then places. The same placements tell which objects are trees.
*/
public final class TreeGrowing implements SaplingGrowth {
private static final IrisTreeSize SAPLING_SIZE = new IrisTreeSize(1, 1);
private static final int SAPLING_WIDTH = 1;
private static final int SAPLING_DEPTH = 1;
@Override
public Optional<Growth> grow(PackWorld world, Sapling sapling, Surroundings surroundings) {
Engine engine = IrisPackWorld.of(world).engine();
if (!engine.getDimension().getTreeSettings().isEnabled()) {
ObjectHost host = ObjectHost.of(world);
BlockPosition at = sapling.at();
TreeGrowthSettings growth = treeGrowth(host, at);
if (!growth.enabled()) {
return Optional.empty();
}
IrisObjectPlacement placement = pickPlacement(engine, sapling);
if (placement == null) {
Optional<ObjectPlacement> placement = pickPlacement(host, growth, sapling);
if (placement.isEmpty()) {
return Optional.empty();
}
IrisData data = engine.getData();
IrisObject object = data.getObjectLoader().load(placement.getPlace().getRandom(RNG.r));
GrowthPlacer placer = new GrowthPlacer(engine, surroundings);
List<String> keys = placement.get().place();
Optional<PlaceableObject> tree = host.object(keys.get(RNG.r.i(keys.size())));
if (tree.isEmpty()) {
return Optional.empty();
}
PlaceableObject object = tree.get();
GrowthSink sink = new GrowthSink(surroundings, host);
BlockPosition center = sapling.center();
object.place(center.x(), center.y() + object.getH() / 2, center.z(), placer, placement, RNG.r, data);
return Optional.of(new Growth(object.getLoadKey(), placer.placed()));
host.placeInto(object, center.x(), center.y() + object.height() / 2, center.z(), placement.get(), sink, RNG.r);
return Optional.of(new Growth(object.key(), sink.placed()));
}
@Override
public TreeObjects treeObjects(PackWorld world) {
Engine engine = IrisPackWorld.of(world).engine();
ObjectHost host = ObjectHost.of(world);
Set<String> objects = new HashSet<>();
Set<String> procedural = new HashSet<>();
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
if (region != null) {
collectPlacements(region.getObjects(), objects);
collectProceduralTrees(region.getProceduralObjects(), procedural);
}
for (Declaration<ObjectSettings> declaration : host.declarations(ObjectSettings.class)) {
collectPlacements(declaration.settings().objects(), objects);
}
for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) {
if (biome != null) {
collectPlacements(biome.getObjects(), objects);
collectProceduralTrees(biome.getProceduralObjects(), procedural);
}
for (Declaration<ProceduralObjectSettings> declaration : host.declarations(ProceduralObjectSettings.class)) {
collectProceduralTrees(declaration.settings().trees(), procedural);
}
return new TreeObjects(objects, procedural);
}
/** One placement, picked at random, of the tree placements that grow {@code sapling}'s species; null for none. */
private static IrisObjectPlacement pickPlacement(Engine engine, Sapling sapling) {
KList<IrisObjectPlacement> placements = new KList<>();
boolean useAll = engine.getDimension().getTreeSettings().getMode().equals(IrisTreeModes.ALL);
BlockPosition at = sapling.at();
placements.addAll(matching(engine.getBiome(at.x(), at.y(), at.z()).getObjects(), sapling.species()));
if (useAll || placements.isEmpty()) {
placements.addAll(matching(engine.getRegion(at.x(), at.z()).getObjects(), sapling.species()));
private static TreeGrowthSettings treeGrowth(ObjectHost host, BlockPosition at) {
for (Entry<TreeGrowthSettings> entry : host.columnSettings().at(TreeGrowthSettings.class, at.x(), at.z())) {
if (entry.level() == Target.DIMENSION) {
return entry.value();
}
}
return placements.isNotEmpty() ? placements.getRandom() : null;
return new TreeGrowthSettings();
}
private static KList<IrisObjectPlacement> matching(KList<IrisObjectPlacement> objects, String species) {
KList<IrisObjectPlacement> matches = new KList<>();
for (IrisObjectPlacement placement : objects) {
if (placement.matches(SAPLING_SIZE, species)) {
/** One placement, picked at random, of the tree placements that grow {@code sapling}'s species. */
private static Optional<ObjectPlacement> pickPlacement(ObjectHost host, TreeGrowthSettings growth, Sapling sapling) {
List<ObjectPlacement> placements = new ArrayList<>();
BlockPosition at = sapling.at();
ResourceId biome = host.biomeAt(at.x(), at.y(), at.z());
host.biomeDeclaration(biome, ObjectSettings.class).ifPresent(settings -> placements.addAll(matching(settings, sapling.species())));
if (growth.mode() == TreeMode.ALL || placements.isEmpty()) {
ResourceId region = host.regionAt(at.x(), at.z());
host.regionDeclaration(region, ObjectSettings.class).ifPresent(settings -> placements.addAll(matching(settings, sapling.species())));
}
if (placements.isEmpty()) {
return Optional.empty();
}
return Optional.of(placements.get(RNG.r.i(placements.size())));
}
private static List<ObjectPlacement> matching(ObjectSettings settings, String species) {
List<ObjectPlacement> matches = new ArrayList<>();
for (ObjectPlacement placement : settings.objects()) {
if (placement.trees().stream().anyMatch(tree -> tree.matches(SAPLING_WIDTH, SAPLING_DEPTH, species))) {
matches.add(placement);
}
}
return matches;
}
private static void collectPlacements(Iterable<IrisObjectPlacement> placements, Set<String> objectKeys) {
if (placements == null) {
return;
}
for (IrisObjectPlacement placement : placements) {
if (placement == null
|| placement.getTrees() == null
|| placement.getTrees().isEmpty()
|| placement.getPlace() == null) {
private static void collectPlacements(List<ObjectPlacement> placements, Set<String> objectKeys) {
for (ObjectPlacement placement : placements) {
if (placement == null || placement.trees().isEmpty()) {
continue;
}
for (String objectKey : placement.getPlace()) {
for (String objectKey : placement.place()) {
if (objectKey != null && !objectKey.isBlank()) {
objectKeys.add(objectKey);
}
@@ -139,31 +139,27 @@ public final class TreeGrowing implements SaplingGrowth {
}
}
private static void collectProceduralTrees(IrisProceduralObjects proceduralObjects, Set<String> objectKeys) {
if (proceduralObjects == null || proceduralObjects.getTrees() == null) {
return;
}
for (IrisProceduralTree tree : proceduralObjects.getTrees()) {
if (tree == null || tree.getName() == null || tree.getName().isBlank()) {
private static void collectProceduralTrees(List<Tree> trees, Set<String> objectKeys) {
for (Tree tree : trees) {
if (tree == null || tree.name() == null || tree.name().isBlank()) {
continue;
}
int variants = Math.max(1, tree.getVariants());
int variants = Math.max(1, tree.variants());
for (int index = 0; index < variants; index++) {
objectKeys.add(tree.getVariantLoadKey(index));
objectKeys.add(Tree.variantLoadKey(tree.name(), index));
}
}
}
/** Places an object into a list of blocks, reading the world around the sapling through the host. */
private static final class GrowthPlacer implements IObjectPlacer {
private final Engine engine;
private static final class GrowthSink implements ObjectSink {
private final Surroundings surroundings;
private final PlatformBlockStates states = new PlatformBlockStates(key -> IrisPlatforms.get().registries().block(key));
private final ObjectHost host;
private final List<PlacedBlock> placed = new ArrayList<>();
private GrowthPlacer(Engine engine, Surroundings surroundings) {
this.engine = engine;
private GrowthSink(Surroundings surroundings, ObjectHost host) {
this.surroundings = surroundings;
this.host = host;
}
private List<PlacedBlock> placed() {
@@ -171,77 +167,23 @@ public final class TreeGrowing implements SaplingGrowth {
}
@Override
public int getHighest(int x, int z, IrisData data) {
return surroundings.highest(x, z, false);
}
@Override
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
public int highest(int x, int z, boolean ignoreFluid) {
return surroundings.highest(x, z, ignoreFluid);
}
@Override
public void set(int x, int y, int z, PlatformBlockState state) {
placed.add(new PlacedBlock(new BlockPosition(x, y, z), states.toApi(state), Optional.empty()));
public BlockState get(int x, int y, int z) {
return surroundings.blockAt(x, y, z);
}
@Override
public PlatformBlockState get(int x, int y, int z) {
BlockState block = surroundings.blockAt(x, y, z);
return states.toPlatform(block);
public void set(int x, int y, int z, BlockState state) {
placed.add(new PlacedBlock(new BlockPosition(x, y, z), state, Optional.empty()));
}
@Override
public boolean isPreventingDecay() {
return true;
}
@Override
public boolean isCarved(int x, int y, int z) {
return false;
}
@Override
public boolean isSurfaceSolid(int x, int y, int z) {
return isSolid(x, y, z);
}
@Override
public boolean isSolid(int x, int y, int z) {
return get(x, y, z).isSolid();
}
@Override
public boolean isUnderwater(int x, int z) {
return false;
}
@Override
public int getFluidHeight() {
return engine.getDimension().getFluidHeight();
}
@Override
public boolean isDebugSmartBore() {
return false;
}
@Override
public void setTile(int xx, int yy, int zz, TileData tile) {
}
@Override
public <T> void setData(int xx, int yy, int zz, T data) {
}
@Override
public <T> T getData(int xx, int yy, int zz, Class<T> t) {
return null;
}
@Override
public Engine getEngine() {
return engine;
public int fluidHeight() {
return host.fluidHeight();
}
}
}
@@ -19,6 +19,7 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.builtin.objects.TreeOverride;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.blocks.ObjectReplace;
@@ -63,7 +64,6 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.bukkit.Bukkit;
import org.bukkit.TreeType;
import org.jetbrains.annotations.Nullable;
@@ -176,8 +176,8 @@ public class IrisObjectPlacement {
@Desc("Whether the given loot tables override any and all other loot tables available in the dimension, region or biome.")
private boolean overrideGlobalLoot = false;
@Desc("This object / these objects override the following trees when they grow...")
@ArrayType(min = 1, type = IrisTree.class)
private KList<IrisTree> trees = new KList<>();
@ArrayType(min = 1, type = TreeOverride.class)
private KList<TreeOverride> trees = new KList<>();
@RegistryListResource(IrisObject.class)
@ArrayType(type = String.class)
@Desc("List of objects to this object is allowed to collied with")
@@ -267,14 +267,10 @@ public class IrisObjectPlacement {
return g.getData().getObjectLoader().load(place.get(random.nextInt(place.size())));
}
/** Whether a tree placement grows the species the platform calls {@code species} for a sapling area of {@code size}. */
public boolean matches(IrisTreeSize size, String species) {
return matches(size, TreeType.valueOf(species));
}
public boolean matches(IrisTreeSize size, TreeType type) {
for (IrisTree i : getTrees()) {
if (i.matches(size, type)) {
/** Whether a tree placement grows the species the platform calls {@code species} for a sapling area of {@code width} by {@code depth}. */
public boolean matches(int width, int depth, String species) {
for (TreeOverride tree : getTrees()) {
if (tree.matches(width, depth, species)) {
return true;
}
}
@@ -1,83 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.engine.object.annotations.ArrayType;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.Required;
import art.arcane.iris.engine.object.annotations.Snippet;
import art.arcane.volmlib.util.collection.KList;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.bukkit.TreeType;
@Snippet("tree")
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Desc("Tree replace options for this object placer")
@Data
public class IrisTree {
@Required
@Desc("The types of trees overwritten by this object")
@ArrayType(min = 1, type = String.class)
private KList<String> treeTypes = new KList<>();
@Required
@Desc("The size of the square of saplings this applies to (2 means a 2 * 2 sapling area)")
@ArrayType(min = 1, type = IrisTreeSize.class)
private KList<IrisTreeSize> sizes = new KList<>();
public boolean matches(IrisTreeSize size, TreeType type) {
if (!matchesSize(size)) {
return false;
}
return matchesType(type);
}
private boolean matchesSize(IrisTreeSize size) {
for (IrisTreeSize i : getSizes()) {
if ((i.getDepth() == size.getDepth() && i.getWidth() == size.getWidth()) || (i.getDepth() == size.getWidth() && i.getWidth() == size.getDepth())) {
return true;
}
}
return false;
}
private boolean matchesType(TreeType type) {
if (type == null) {
return false;
}
String name = type.name();
for (String i : getTreeTypes()) {
if (i != null && i.equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
}
@@ -1,54 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.Required;
import art.arcane.iris.engine.object.annotations.Snippet;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Snippet("tree-size")
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Desc("Sapling override object picking options")
@Data
public class IrisTreeSize {
@Required
@Desc("The width of the sapling area")
int width = 1;
@Required
@Desc("The depth of the sapling area")
int depth = 1;
/**
* Does the size match
*
* @param size the size to check match
* @return true if it matches (fits within width and depth)
*/
public boolean doesMatch(IrisTreeSize size) {
return (width == size.getWidth() && depth == size.getDepth()) || (depth == size.getWidth() && width == size.getDepth());
}
}
@@ -0,0 +1,144 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.RequireSurfaceSupportSettings;
import art.arcane.iris.builtin.objects.SurfaceSupportBufferSettings;
import art.arcane.iris.builtin.objects.TreeGrowthSettings;
import art.arcane.iris.builtin.objects.UpperObjectsForceSettings;
import art.arcane.iris.builtin.objects.UpperObjectsSettings;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.engine.object.procedural.ResolvedProceduralObjects;
import art.arcane.volmlib.util.collection.KList;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.WeakHashMap;
/**
* The object placements and procedural objects a region or biome declares, as Iris places them: the module settings of
* {@code iris:objects}, made into Iris's own placements once and kept for as long as the settings live.
*/
public final class ObjectPlacements {
private static final Map<ObjectSettings, Placements> PLACEMENTS = Collections.synchronizedMap(new WeakHashMap<>());
private static final Map<ProceduralObjectSettings, ResolvedProceduralObjects> PROCEDURAL = Collections.synchronizedMap(new WeakHashMap<>());
private ObjectPlacements() {
}
/** Every placement {@code owner} declares. */
public static KList<IrisObjectPlacement> all(IrisRegistrant owner) {
return placementsOf(owner).all;
}
/** The placements of {@code owner} that place on the surface. */
public static KList<IrisObjectPlacement> surface(IrisRegistrant owner) {
return placementsOf(owner).surface;
}
/** The placements of {@code owner} that place in carvings. */
public static KList<IrisObjectPlacement> carving(IrisRegistrant owner) {
return placementsOf(owner).carving;
}
/** The procedural objects {@code owner} declares; none when it declares none. */
public static ResolvedProceduralObjects procedural(IrisRegistrant owner) {
Optional<ProceduralObjectSettings> settings = owner.getModuleSettings().find(ProceduralObjectSettings.class);
return procedural(settings.orElse(NO_PROCEDURAL_OBJECTS));
}
/** The procedural objects {@code settings} declare. */
public static ResolvedProceduralObjects procedural(ProceduralObjectSettings settings) {
return PROCEDURAL.computeIfAbsent(settings, ResolvedProceduralObjects::new);
}
/** Whether {@code dimension} places its objects in the terrain stacked above it too. */
public static boolean upperObjects(IrisRegistrant dimension) {
return dimension.getModuleSettings().find(UpperObjectsSettings.class).map(UpperObjectsSettings::enabled).orElse(false);
}
/** Whether the objects placed in the terrain stacked above ignore placement restrictions. */
public static boolean upperObjectsForced(IrisRegistrant dimension) {
return dimension.getModuleSettings().find(UpperObjectsForceSettings.class).map(UpperObjectsForceSettings::force).orElse(false);
}
/** Whether {@code dimension} refuses surface objects over carved openings. */
public static boolean requiresSurfaceSupport(IrisRegistrant dimension) {
return dimension.getModuleSettings().find(RequireSurfaceSupportSettings.class).map(RequireSurfaceSupportSettings::require)
.orElse(NO_SURFACE_SUPPORT_REQUIREMENT.require());
}
/** The least surface-support buffer {@code dimension} gives its surface objects. */
public static int surfaceSupportBuffer(IrisRegistrant dimension) {
return dimension.getModuleSettings().find(SurfaceSupportBufferSettings.class).map(SurfaceSupportBufferSettings::buffer)
.orElse(NO_SURFACE_SUPPORT_BUFFER.buffer());
}
/** The tree growth settings of {@code dimension}. */
public static TreeGrowthSettings treeGrowth(IrisRegistrant dimension) {
return dimension.getModuleSettings().find(TreeGrowthSettings.class).orElse(NO_TREE_GROWTH);
}
/** Iris's placement for the settings {@code placement}, read from the JSON it was written as. */
public static IrisObjectPlacement host(ObjectPlacement placement, IrisData data) {
Object kept = placement.hostForm();
if (kept instanceof IrisObjectPlacement hostPlacement) {
return hostPlacement;
}
IrisObjectPlacement made = data.getGson().fromJson(placement.json(), IrisObjectPlacement.class);
placement.hostForm(made);
return made;
}
private static final ProceduralObjectSettings NO_PROCEDURAL_OBJECTS = new ProceduralObjectSettings();
private static final RequireSurfaceSupportSettings NO_SURFACE_SUPPORT_REQUIREMENT = new RequireSurfaceSupportSettings();
private static final SurfaceSupportBufferSettings NO_SURFACE_SUPPORT_BUFFER = new SurfaceSupportBufferSettings();
private static final TreeGrowthSettings NO_TREE_GROWTH = new TreeGrowthSettings();
private static final ObjectSettings NO_OBJECTS = new ObjectSettings();
private static Placements placementsOf(IrisRegistrant owner) {
ObjectSettings settings = owner.getModuleSettings().find(ObjectSettings.class).orElse(NO_OBJECTS);
Placements found = PLACEMENTS.get(settings);
if (found != null) {
return found;
}
return PLACEMENTS.computeIfAbsent(settings, declared -> new Placements(declared, owner.getLoader()));
}
private record Placements(KList<IrisObjectPlacement> all, KList<IrisObjectPlacement> surface, KList<IrisObjectPlacement> carving) {
Placements(ObjectSettings settings, IrisData data) {
this(new KList<>(), new KList<>(), new KList<>());
for (ObjectPlacement declared : settings.objects()) {
IrisObjectPlacement placement = host(declared, data);
all.add(placement);
if (placement.getCarvingSupport().supportsSurface()) {
surface.add(placement);
}
if (placement.getCarvingSupport().supportsCarving()) {
carving.add(placement);
}
}
}
}
}
@@ -18,6 +18,7 @@
package art.arcane.iris.engine.object.prefab;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
import art.arcane.iris.engine.object.placement.IObjectPlacer;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
@@ -71,7 +72,7 @@ import java.util.function.BiConsumer;
*/
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class IrisObject extends IrisRegistrant {
public class IrisObject extends IrisRegistrant implements PlaceableObject {
protected static final IrisVector HALF = new IrisVector(0.5, 0.5, 0.5);
public static final class States {
public static final PlatformBlockState AIR = B.getState("CAVE_AIR");
@@ -372,6 +373,26 @@ public class IrisObject extends IrisRegistrant {
}
}
@Override
public String key() {
return getLoadKey();
}
@Override
public int width() {
return w;
}
@Override
public int height() {
return h;
}
@Override
public int depth() {
return d;
}
public int volume() {
return blocks.size();
}
@@ -1,112 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.procedural;
import art.arcane.iris.builtin.objects.ruin.Ruin;
import art.arcane.iris.engine.object.procedural.ruin.ResolvedRuin;
import art.arcane.iris.builtin.objects.fungi.Fungus;
import art.arcane.iris.engine.object.procedural.fungi.ResolvedFungus;
import art.arcane.iris.builtin.objects.formation.Formation;
import art.arcane.iris.engine.object.procedural.formation.ResolvedFormation;
import art.arcane.iris.builtin.objects.crystal.Crystal;
import art.arcane.iris.engine.object.procedural.crystal.ResolvedCrystal;
import art.arcane.iris.builtin.objects.coral.Coral;
import art.arcane.iris.engine.object.procedural.coral.ResolvedCoral;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.engine.object.annotations.ArrayType;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.Snippet;
import art.arcane.volmlib.util.collection.KList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import lombok.AllArgsConstructor;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Snippet("procedural-objects")
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Desc("Procedurally generated objects placed in a biome or region. Unlike the objects block (which loads iob files), these are generated from scratch at world-gen time.")
@Data
public class IrisProceduralObjects {
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
@EqualsAndHashCode.Exclude
private final transient Map<Object, ResolvedProceduralPlacement> placeables = new ConcurrentHashMap<>();
@ArrayType(min = 1, type = IrisProceduralTree.class)
@Desc("Procedurally generated trees.")
private KList<IrisProceduralTree> trees = new KList<>();
@ArrayType(min = 1, type = Ruin.class)
@Desc("Procedurally generated ruins (crumbling pillars, walls, arches, rubble).")
private KList<Ruin> ruins = new KList<>();
@ArrayType(min = 1, type = Formation.class)
@Desc("Procedurally generated natural rock formations (spires, hoodoos, arches, sea stacks, boulders, basalt columns).")
private KList<Formation> formations = new KList<>();
@ArrayType(min = 1, type = Coral.class)
@Desc("Procedurally generated underwater coral structures.")
private KList<Coral> coral = new KList<>();
@ArrayType(min = 1, type = Fungus.class)
@Desc("Procedurally generated mushrooms and shelf fungi.")
private KList<Fungus> fungi = new KList<>();
@ArrayType(min = 1, type = Crystal.class)
@Desc("Procedurally generated crystal clusters (usually placed in caves).")
private KList<Crystal> crystals = new KList<>();
public KList<IrisProceduralPlacement> getAllPlacements() {
KList<IrisProceduralPlacement> all = new KList<>();
if (trees != null) {
all.addAll(trees);
}
addPlaceable(all, ruins, ResolvedRuin::new);
addPlaceable(all, formations, ResolvedFormation::new);
addPlaceable(all, coral, ResolvedCoral::new);
addPlaceable(all, fungi, ResolvedFungus::new);
addPlaceable(all, crystals, ResolvedCrystal::new);
return all;
}
/** The settings in {@code settings}, each made placeable once, in order. */
@SuppressWarnings("unchecked")
private <S> void addPlaceable(KList<IrisProceduralPlacement> all, KList<S> settings, Function<S, ResolvedProceduralPlacement> resolve) {
if (settings == null) {
return;
}
for (S entry : settings) {
all.add(placeables.computeIfAbsent(entry, key -> resolve.apply((S) key)));
}
}
public boolean isEmpty() {
return getAllPlacements().isEmpty();
}
}
@@ -0,0 +1,62 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.procedural;
import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.iris.engine.object.procedural.coral.ResolvedCoral;
import art.arcane.iris.engine.object.procedural.crystal.ResolvedCrystal;
import art.arcane.iris.engine.object.procedural.formation.ResolvedFormation;
import art.arcane.iris.engine.object.procedural.fungi.ResolvedFungus;
import art.arcane.iris.engine.object.procedural.ruin.ResolvedRuin;
import art.arcane.iris.engine.object.procedural.tree.ResolvedTree;
import art.arcane.volmlib.util.collection.KList;
import java.util.List;
import java.util.function.Function;
/** The procedural objects a region or biome declares, each made placeable once, in the order the settings list them. */
public final class ResolvedProceduralObjects {
private final KList<IrisProceduralPlacement> all = new KList<>();
public ResolvedProceduralObjects(ProceduralObjectSettings settings) {
for (Tree tree : settings.trees()) {
all.add(new ResolvedTree(tree));
}
addAll(settings.ruins(), ResolvedRuin::new);
addAll(settings.formations(), ResolvedFormation::new);
addAll(settings.coral(), ResolvedCoral::new);
addAll(settings.fungi(), ResolvedFungus::new);
addAll(settings.crystals(), ResolvedCrystal::new);
}
private <S> void addAll(List<S> settings, Function<S, ResolvedProceduralPlacement> resolve) {
for (S entry : settings) {
all.add(resolve.apply(entry));
}
}
public KList<IrisProceduralPlacement> getAllPlacements() {
return all;
}
public boolean isEmpty() {
return all.isEmpty();
}
}
@@ -63,6 +63,11 @@ public abstract class ResolvedProceduralPlacement implements IrisProceduralPlace
return Math.max(1, shape.variants());
}
/** The options this object shares with an object placement. */
public Shape shape() {
return shape;
}
@Override
public String getName() {
return shape.name();
@@ -1,45 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.Required;
import art.arcane.iris.engine.object.annotations.Snippet;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Snippet("tree-settings")
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Desc("Tree growth override settings")
@Data
@EqualsAndHashCode(callSuper = false)
public class IrisTreeSettings {
@Required
@Desc("Turn replacing on and off")
boolean enabled = false;
@Desc("Object picking modes")
IrisTreeModes mode = IrisTreeModes.FIRST;
}
@@ -20,7 +20,7 @@ package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.volmlib.util.math.IrisBlockVector;
import art.arcane.volmlib.util.math.RNG;
@@ -36,13 +36,13 @@ public final class ProceduralTreeGenerator {
private ProceduralTreeGenerator() {
}
public static IrisObject generate(IrisProceduralTree tree, int height, RNG rng, IrisData data) {
public static IrisObject generate(Tree tree, int height, RNG rng, IrisData data) {
TreeBlockCanvas canvas = new TreeBlockCanvas();
long baseSeed = rng.getSeed();
List<TreeTrunkBuilder.Limb> limbs = TreeTrunkBuilder.build(canvas, tree, height);
boolean wantEndpoints = tree.getDecorators() != null && !tree.getDecorators().isEmpty();
boolean wantEndpoints = tree.decorators() != null && !tree.decorators().isEmpty();
List<int[]> branchEndpoints = wantEndpoints ? new ArrayList<>() : null;
int limbIndex = 0;
@@ -55,11 +55,11 @@ public final class ProceduralTreeGenerator {
TreeDecoratorApplier.apply(canvas, tree, baseSeed, branchEndpoints);
}
if (tree.isRoots()) {
if (tree.roots()) {
TreeRootBuilder.build(canvas, tree, height, baseSeed);
}
if (tree.isPlausible()) {
if (tree.plausible()) {
TreeSupport.ensureLeavesSupported(canvas, 24);
}
@@ -0,0 +1,107 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import java.io.File;
/** A procedural tree made placeable: its variants are baked by {@link ProceduralTreeGenerator}, at heights spread between its limits. */
public final class ResolvedTree extends ResolvedProceduralPlacement {
private static final long VARIANT_SEED_STRIDE = 7919L;
private static final double HEIGHT_JITTER_FRACTION = 0.3;
private static final int MINIMUM_HEIGHT = 2;
private final Tree settings;
public ResolvedTree(Tree settings) {
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)));
this.settings = settings;
}
public String getVariantLoadKey(int index) {
return Tree.variantLoadKey(settings.name(), index);
}
@Override
public boolean isPlausible() {
return settings.plausible();
}
@Override
protected IrisObject generate(int index, RNG rng, IrisData data) {
throw new UnsupportedOperationException("Tree variants are baked with heights spread over the limits");
}
@Override
protected KList<IrisObject> bake(IrisData data) {
KList<IrisObject> baked = new KList<>();
int count = Math.max(1, settings.variants());
int lo = Math.min(settings.heightMin(), settings.heightMax());
int hi = Math.max(settings.heightMin(), settings.heightMax());
RNG heightRng = new RNG(settings.seed());
for (int i = 0; i < count; i++) {
int height = variantHeight(heightRng, lo, hi, count, i);
IrisObject object = ProceduralTreeGenerator.generate(settings, Math.max(MINIMUM_HEIGHT, height),
new RNG(settings.seed() + (i * VARIANT_SEED_STRIDE)), data);
if (object == null || object.getBlocks().isEmpty()) {
continue;
}
object.setLoadKey(getVariantLoadKey(i));
object.setLoader(data);
baked.add(object);
}
digestForGoldenDebug(baked);
return baked;
}
private static int variantHeight(RNG heightRng, int lo, int hi, int count, int index) {
if (count == 1 || lo == hi) {
return heightRng.i(lo, hi + 1);
}
double step = (hi - lo) / (double) (count - 1);
double base = lo + step * index;
double jitter = heightRng.d(-step * HEIGHT_JITTER_FRACTION, step * HEIGHT_JITTER_FRACTION);
return (int) Math.round(Math.max(lo, Math.min(hi, base + jitter)));
}
private static void digestForGoldenDebug(KList<IrisObject> baked) {
if (!new File("plugins/Iris/goldendebug.txt").isFile()) {
return;
}
for (IrisObject object : baked) {
long[] digest = new long[]{0L};
object.getBlocks().forEach((vector, state) -> {
long position = ((long) vector.getBlockX() << 40) ^ ((long) vector.getBlockY() << 20) ^ vector.getBlockZ();
digest[0] ^= Long.rotateLeft(position * 0x9E3779B97F4A7C15L ^ state.key().hashCode(), (int) (position & 63));
});
IrisLogging.debug("Goldendebug bake: " + object.getLoadKey() + " blocks=" + object.getBlocks().size() + " digest=" + Long.toHexString(digest[0]));
}
}
}
@@ -21,10 +21,9 @@ package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf;
import art.arcane.iris.builtin.objects.tree.TreeDecorator;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
import com.volmit.block.PaletteSpec;
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import art.arcane.volmlib.util.math.RNG;
@@ -33,38 +32,38 @@ public final class TreeBlockResolver {
private TreeBlockResolver() {
}
public static PlatformBlockState resolve(IrisProceduralTree tree, IrisData data, TreeBlockCanvas.Cell cell, TreeBlockCanvas.Vec pos) {
RNG paletteRng = new RNG(tree.getSeed());
RNG posRng = new RNG(tree.getSeed() ^ positionHash(pos));
public static PlatformBlockState resolve(Tree tree, IrisData data, TreeBlockCanvas.Cell cell, TreeBlockCanvas.Vec pos) {
RNG paletteRng = new RNG(tree.seed());
RNG posRng = new RNG(tree.seed() ^ positionHash(pos));
switch (cell.role()) {
case TRUNK -> {
PlatformBlockState state = resolveBlock(tree.getTrunk(), tree.getTrunkPalette(), data, pos, paletteRng);
PlatformBlockState state = resolveBlock(tree.trunk(), tree.trunkPalette().orElse(null), data, pos, paletteRng);
return finishTrunk(state, cell);
}
case SECONDARY_TRUNK -> {
PlatformBlockState state = resolveBlock(tree.getSecondaryTrunk(), tree.getSecondaryTrunkPalette(), data, pos, paletteRng);
PlatformBlockState state = resolveBlock(tree.secondaryTrunk().orElse(null), tree.secondaryTrunkPalette().orElse(null), data, pos, paletteRng);
if (state == null) {
state = resolveBlock(tree.getTrunk(), tree.getTrunkPalette(), data, pos, paletteRng);
state = resolveBlock(tree.trunk(), tree.trunkPalette().orElse(null), data, pos, paletteRng);
}
return finishTrunk(state, cell);
}
case LEAF -> {
return resolveBlock(tree.getLeaves(), tree.getLeavesPalette(), data, pos, paletteRng);
return resolveBlock(tree.leaves(), tree.leavesPalette().orElse(null), data, pos, paletteRng);
}
case SECONDARY_LEAF -> {
PlatformBlockState state = resolveSecondaryLeaf(tree, data, pos, paletteRng, posRng);
if (state == null) {
state = resolveBlock(tree.getLeaves(), tree.getLeavesPalette(), data, pos, paletteRng);
state = resolveBlock(tree.leaves(), tree.leavesPalette().orElse(null), data, pos, paletteRng);
}
return state;
}
case DECORATOR -> {
int index = cell.decoratorIndex();
if (index < 0 || tree.getDecorators() == null || index >= tree.getDecorators().size()) {
if (index < 0 || tree.decorators() == null || index >= tree.decorators().size()) {
return null;
}
TreeDecorator dec = tree.getDecorators().get(index);
TreeDecorator dec = tree.decorators().get(index);
PlatformBlockState state = resolveBlock(dec.block(), dec.palette().orElse(null), data, pos, paletteRng);
if (state != null && cell.facing() != null && IrisProceduralBlocks.hasProperty(state, "facing")) {
try {
@@ -96,23 +95,24 @@ public final class TreeBlockResolver {
return state;
}
private static PlatformBlockState resolveSecondaryLeaf(IrisProceduralTree tree, IrisData data, TreeBlockCanvas.Vec pos, RNG paletteRng, RNG posRng) {
if (TreeTrunkBuilder.paletteSet(tree.getSecondaryLeavesPalette())) {
return tree.getSecondaryLeavesPalette().get(paletteRng, pos.x(), pos.y(), pos.z(), data);
private static PlatformBlockState resolveSecondaryLeaf(Tree tree, IrisData data, TreeBlockCanvas.Vec pos, RNG paletteRng, RNG posRng) {
PaletteSpec secondaryPalette = tree.secondaryLeavesPalette().orElse(null);
if (IrisProceduralBlocks.paletteSet(secondaryPalette)) {
return IrisProceduralBlocks.pick(secondaryPalette, data, paletteRng.getSeed(), pos.x(), pos.y(), pos.z());
}
if (tree.getWeightedSecondaryLeaves() != null && !tree.getWeightedSecondaryLeaves().isEmpty()) {
if (tree.weightedSecondaryLeaves() != null && !tree.weightedSecondaryLeaves().isEmpty()) {
String picked = pickWeighted(tree, posRng);
return picked == null ? null : B.getStateOrNull(picked, false);
}
if (tree.getSecondaryLeaves() != null && !tree.getSecondaryLeaves().isEmpty()) {
return B.getStateOrNull(tree.getSecondaryLeaves(), false);
if (tree.secondaryLeaves().isPresent() && !tree.secondaryLeaves().get().isEmpty()) {
return B.getStateOrNull(tree.secondaryLeaves().get(), false);
}
return null;
}
private static String pickWeighted(IrisProceduralTree tree, RNG rng) {
private static String pickWeighted(Tree tree, RNG rng) {
int total = 0;
for (art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf s : tree.getWeightedSecondaryLeaves()) {
for (art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf s : tree.weightedSecondaryLeaves()) {
total += Math.max(0, s.weight());
}
if (total <= 0) {
@@ -120,29 +120,19 @@ public final class TreeBlockResolver {
}
double r = rng.nextDouble() * total;
double cumulative = 0;
for (art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf s : tree.getWeightedSecondaryLeaves()) {
for (art.arcane.iris.builtin.objects.tree.TreeSecondaryLeaf s : tree.weightedSecondaryLeaves()) {
cumulative += Math.max(0, s.weight());
if (r < cumulative) {
return s.block();
}
}
return tree.getWeightedSecondaryLeaves().get(tree.getWeightedSecondaryLeaves().size() - 1).block();
return tree.weightedSecondaryLeaves().get(tree.weightedSecondaryLeaves().size() - 1).block();
}
private static PlatformBlockState resolveBlock(String block, PaletteSpec palette, IrisData data, TreeBlockCanvas.Vec pos, RNG paletteRng) {
return IrisProceduralBlocks.resolve(block, palette, data, pos.x(), pos.y(), pos.z(), paletteRng);
}
private static PlatformBlockState resolveBlock(String block, IrisMaterialPalette palette, IrisData data, TreeBlockCanvas.Vec pos, RNG paletteRng) {
if (TreeTrunkBuilder.paletteSet(palette)) {
return palette.get(paletteRng, pos.x(), pos.y(), pos.z(), data);
}
if (block != null && !block.isEmpty()) {
return B.getStateOrNull(block, false);
}
return null;
}
private static PlatformBlockState woodCap(PlatformBlockState state) {
String key = state.key();
int bracket = key.indexOf('[');
@@ -24,7 +24,8 @@ import art.arcane.iris.builtin.objects.tree.TreeCanopy;
import art.arcane.iris.builtin.objects.tree.TreeBranches;
import art.arcane.iris.builtin.objects.tree.TreeProfile;
import art.arcane.iris.builtin.objects.tree.TreeLeafMode;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
@@ -34,15 +35,15 @@ public final class TreeCanopyBuilder {
private TreeCanopyBuilder() {
}
public static void build(TreeBlockCanvas canvas, IrisProceduralTree tree, int height, double[][] offsets,
public static void build(TreeBlockCanvas canvas, Tree tree, int height, double[][] offsets,
int branchStartY, long baseSeed, List<int[]> branchEndpoints) {
TreeCanopy canopy = tree.getCanopy();
TreeCanopy canopy = tree.canopy();
if (canopy == null) {
canopy = new TreeCanopy();
}
TreeBranches branches = canopy.branches().orElse(null);
double[][] layers = resolveLayers(canopy, tree.getProfile(), height, branches != null);
double[][] layers = resolveLayers(canopy, tree.profile(), height, branches != null);
if (branches != null) {
if (layers.length > 0) {
@@ -56,7 +57,7 @@ public final class TreeCanopyBuilder {
}
}
private static void placeApexCap(TreeBlockCanvas canvas, IrisProceduralTree tree, int height, double[][] layers,
private static void placeApexCap(TreeBlockCanvas canvas, Tree tree, int height, double[][] layers,
double[][] offsets, long baseSeed) {
int ocx = 0;
int ocz = 0;
@@ -69,7 +70,7 @@ public final class TreeCanopyBuilder {
maxR = Math.max(maxR, layer[1]);
}
int capRadius = Math.max(2, Math.min(3, (int) Math.round(maxR * 0.35)));
TreeCanopy canopy = tree.getCanopy();
TreeCanopy canopy = tree.canopy();
TreeLeafMode mode = canopy != null ? canopy.mode() : TreeLeafMode.TRIMMED;
double density = canopy != null ? canopy.leafDensity() : 1.0;
placeLeafCluster(canvas, tree, ocx, height - 1, ocz, capRadius, mode, density, baseSeed + 5555L);
@@ -88,7 +89,7 @@ public final class TreeCanopyBuilder {
return TreeProfiles.presetLayers(profile, height, branchDriven);
}
private static void volumeCanopy(TreeBlockCanvas canvas, IrisProceduralTree tree, double[][] layers,
private static void volumeCanopy(TreeBlockCanvas canvas, Tree tree, double[][] layers,
TreeCanopy canopy, long baseSeed, double[][] offsets) {
int ocx = 0;
int ocz = 0;
@@ -136,7 +137,7 @@ public final class TreeCanopyBuilder {
return (int) Math.ceil(radius * squish);
}
private static void placeLeafDisc(TreeBlockCanvas canvas, IrisProceduralTree tree, int cx, int cy, int cz,
private static void placeLeafDisc(TreeBlockCanvas canvas, Tree tree, int cx, int cy, int cz,
double radius, TreeLeafMode mode, double density, long seed) {
double sx = stretchX(tree);
double sz = stretchZ(tree);
@@ -157,7 +158,7 @@ public final class TreeCanopyBuilder {
}
}
private static void placeLeafCluster(TreeBlockCanvas canvas, IrisProceduralTree tree, int cx, int cy, int cz,
private static void placeLeafCluster(TreeBlockCanvas canvas, Tree tree, int cx, int cy, int cz,
int radius, TreeLeafMode mode, double density, long seed) {
double sx = stretchX(tree);
double sz = stretchZ(tree);
@@ -180,13 +181,13 @@ public final class TreeCanopyBuilder {
}
}
private static double stretchX(IrisProceduralTree tree) {
TreeCanopy c = tree.getCanopy();
private static double stretchX(Tree tree) {
TreeCanopy c = tree.canopy();
return c == null ? 1.0 : Math.max(0.1, c.crownStretchX());
}
private static double stretchZ(IrisProceduralTree tree) {
TreeCanopy c = tree.getCanopy();
private static double stretchZ(Tree tree) {
TreeCanopy c = tree.canopy();
return c == null ? 1.0 : Math.max(0.1, c.crownStretchZ());
}
@@ -244,20 +245,20 @@ public final class TreeCanopyBuilder {
}
}
private static TreeBlockCanvas.Role resolveLeaf(IrisProceduralTree tree, RNG rng) {
boolean hasSecondary = TreeTrunkBuilder.paletteSet(tree.getSecondaryLeavesPalette())
|| (tree.getWeightedSecondaryLeaves() != null && !tree.getWeightedSecondaryLeaves().isEmpty())
|| (tree.getSecondaryLeaves() != null && !tree.getSecondaryLeaves().isEmpty());
if (!hasSecondary || tree.getSecondaryLeafFraction() <= 0.0) {
private static TreeBlockCanvas.Role resolveLeaf(Tree tree, RNG rng) {
boolean hasSecondary = IrisProceduralBlocks.paletteSet(tree.secondaryLeavesPalette())
|| (tree.weightedSecondaryLeaves() != null && !tree.weightedSecondaryLeaves().isEmpty())
|| tree.secondaryLeaves().filter(leaves -> !leaves.isEmpty()).isPresent();
if (!hasSecondary || tree.secondaryLeafFraction() <= 0.0) {
return TreeBlockCanvas.Role.LEAF;
}
if (rng.nextDouble() >= tree.getSecondaryLeafFraction()) {
if (rng.nextDouble() >= tree.secondaryLeafFraction()) {
return TreeBlockCanvas.Role.LEAF;
}
return TreeBlockCanvas.Role.SECONDARY_LEAF;
}
private static void branchCanopy(TreeBlockCanvas canvas, IrisProceduralTree tree, int height,
private static void branchCanopy(TreeBlockCanvas canvas, Tree tree, int height,
TreeBranches branches, int branchStartY, long baseSeed, double[][] offsets,
List<int[]> branchEndpoints) {
long branchSeed = baseSeed + 9999;
@@ -297,7 +298,7 @@ public final class TreeCanopyBuilder {
}
}
private static void growSubBranches(TreeBlockCanvas canvas, IrisProceduralTree tree, int ox, int oy, int oz,
private static void growSubBranches(TreeBlockCanvas canvas, Tree tree, int ox, int oy, int oz,
double az, double el, double len, TreeSubBranches sub, int depth, long seed) {
if (sub == null || depth <= 0) {
return;
@@ -19,7 +19,7 @@
package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.builtin.objects.tree.TreeDecorator;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.math.RNG;
@@ -31,8 +31,8 @@ public final class TreeDecoratorApplier {
private TreeDecoratorApplier() {
}
public static void apply(TreeBlockCanvas canvas, IrisProceduralTree tree, long baseSeed, List<int[]> branchEndpoints) {
KList<TreeDecorator> decorators = tree.getDecorators();
public static void apply(TreeBlockCanvas canvas, Tree tree, long baseSeed, List<int[]> branchEndpoints) {
List<TreeDecorator> decorators = tree.decorators();
if (decorators == null || decorators.isEmpty()) {
return;
}
@@ -21,7 +21,7 @@ package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.builtin.objects.tree.TreeBranches;
import art.arcane.iris.builtin.objects.tree.TreeFunction;
import art.arcane.iris.builtin.objects.tree.TreeAzimuthMode;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.volmlib.util.math.RNG;
public final class TreeFunctions {
@@ -30,27 +30,27 @@ public final class TreeFunctions {
private TreeFunctions() {
}
public static double trunkWidthMultiplier(IrisProceduralTree tree, double t) {
double start = tree.getShapeStart();
double end = tree.getShapeEnd();
return switch (tree.getTrunkShape()) {
public static double trunkWidthMultiplier(Tree tree, double t) {
double start = tree.shapeStart();
double end = tree.shapeEnd();
return switch (tree.trunkShape()) {
case CONSTANT -> 1.0;
case LINEAR -> start + (end - start) * t;
case SIGMOID -> 1.0 / (1.0 + Math.exp(tree.getShapeSteepness() * (t - 0.5)));
case SIGMOID -> 1.0 / (1.0 + Math.exp(tree.shapeSteepness() * (t - 0.5)));
case LOG -> {
double base = Math.max(1.0001, tree.getShapeBase());
double base = Math.max(1.0001, tree.shapeBase());
if (t <= 0.0) {
yield 1.0;
}
yield Math.max(0.0, 1.0 - Math.log(1.0 + t * (base - 1.0)) / Math.log(base));
}
case SINE -> {
double period = tree.getShapePeriod() == 0 ? 1.0 : tree.getShapePeriod();
yield 1.0 + tree.getShapeAmplitude() * Math.sin(2.0 * Math.PI * t / period);
double period = tree.shapePeriod() == 0 ? 1.0 : tree.shapePeriod();
yield 1.0 + tree.shapeAmplitude() * Math.sin(2.0 * Math.PI * t / period);
}
case PARABOLIC -> {
double peak = tree.getShapePeakOffset();
double floor = tree.getShapeFloor();
double peak = tree.shapePeakOffset();
double floor = tree.shapeFloor();
double denom = Math.pow(Math.max(peak, 1.0 - peak), 2);
if (denom == 0) {
denom = 1;
@@ -59,7 +59,7 @@ public final class TreeFunctions {
}
case EXPONENTIAL -> geometric(start, end, t);
case SQRT -> start + (end - start) * Math.sqrt(t);
case STEP -> t < tree.getShapePeakOffset() ? start : end;
case STEP -> t < tree.shapePeakOffset() ? start : end;
case BELL -> start + (end - start) * bell(t);
case EASE_IN_OUT -> start + (end - start) * smoothstep(t);
};
@@ -114,24 +114,24 @@ public final class TreeFunctions {
};
}
public static double azimuthDegrees(TreeAzimuthMode mode, double t, int index, IrisProceduralTree tree, double constantBase, RNG rng) {
public static double azimuthDegrees(TreeAzimuthMode mode, double t, int index, Tree tree, double constantBase, RNG rng) {
return switch (mode) {
case CONSTANT -> constantBase;
case LINEAR -> tree.getAzimuthStart() + (tree.getAzimuthEnd() - tree.getAzimuthStart()) * t;
case SPIRAL -> tree.getAzimuthStart() + tree.getAzimuthTurns() * 360.0 * t;
case LINEAR -> tree.azimuthStart() + (tree.azimuthEnd() - tree.azimuthStart()) * t;
case SPIRAL -> tree.azimuthStart() + tree.azimuthTurns() * 360.0 * t;
case SINE -> {
double period = tree.getAzimuthPeriod() == 0 ? 1.0 : tree.getAzimuthPeriod();
yield tree.getAzimuthOffset() + tree.getAzimuthAmplitude() * Math.sin(2.0 * Math.PI * t / period);
double period = tree.azimuthPeriod() == 0 ? 1.0 : tree.azimuthPeriod();
yield tree.azimuthOffset() + tree.azimuthAmplitude() * Math.sin(2.0 * Math.PI * t / period);
}
case NOISE -> noiseAzimuth(t, tree.getAzimuthScale(), tree.getSeed());
case NOISE -> noiseAzimuth(t, tree.azimuthScale(), tree.seed());
case RANDOM -> rng != null ? rng.d(0.0, 360.0) : constantBase;
case GOLDEN_ANGLE -> index >= 0 ? constantBase + index * GOLDEN_ANGLE : constantBase;
case ALTERNATING -> index >= 0 ? constantBase + (index % 2) * 180.0 : constantBase;
case WHORL -> {
int count = Math.max(1, tree.getAzimuthWhorlCount());
int count = Math.max(1, tree.azimuthWhorlCount());
yield index >= 0 ? constantBase + (index % count) * (360.0 / count) : constantBase;
}
case ZIGZAG -> index >= 0 ? constantBase + ((index % 2 == 0) ? -tree.getAzimuthAmplitude() : tree.getAzimuthAmplitude()) : constantBase;
case ZIGZAG -> index >= 0 ? constantBase + ((index % 2 == 0) ? -tree.azimuthAmplitude() : tree.azimuthAmplitude()) : constantBase;
};
}
@@ -19,7 +19,7 @@
package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.iris.spi.PlatformBlockState;
import java.util.ArrayDeque;
@@ -38,7 +38,7 @@ public final class TreePlausibility {
}
public static void apply(Map<TreeBlockCanvas.Vec, PlatformBlockState> resolved, Set<TreeBlockCanvas.Vec> trunkPositions,
Set<TreeBlockCanvas.Vec> leafPositions, IrisProceduralTree tree) {
Set<TreeBlockCanvas.Vec> leafPositions, Tree tree) {
Set<TreeBlockCanvas.Vec> realLeaves = new HashSet<>();
for (TreeBlockCanvas.Vec v : leafPositions) {
PlatformBlockState state = resolved.get(v);
@@ -55,7 +55,7 @@ public final class TreePlausibility {
for (TreeBlockCanvas.Vec v : realLeaves) {
PlatformBlockState leaf = resolved.get(v);
Integer d = distance.get(v);
if (!tree.isPlausible()) {
if (!tree.plausible()) {
leaf = leaf.withProperty("persistent", "true").withProperty("distance", "1");
} else if (d != null && d < MAX_DISTANCE) {
leaf = leaf.withProperty("persistent", "false").withProperty("distance", String.valueOf(Math.max(1, d)));
@@ -19,7 +19,7 @@
package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.builtin.objects.tree.TreeRootStyle;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.builtin.objects.tree.Tree;
import art.arcane.volmlib.util.math.RNG;
import java.util.ArrayList;
@@ -29,7 +29,7 @@ public final class TreeRootBuilder {
private TreeRootBuilder() {
}
public static void build(TreeBlockCanvas canvas, IrisProceduralTree tree, int height, long baseSeed) {
public static void build(TreeBlockCanvas canvas, Tree tree, int height, long baseSeed) {
List<int[]> cells = new ArrayList<>();
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
if (v.y() == 0) {
@@ -40,7 +40,7 @@ public final class TreeRootBuilder {
return;
}
int depth = tree.getRootDepth() > 0 ? tree.getRootDepth() : autoDepth(height);
int depth = tree.rootDepth() > 0 ? tree.rootDepth() : autoDepth(height);
RNG rng = new RNG(baseSeed ^ 0x5009L);
double cx = 0;
@@ -56,9 +56,9 @@ public final class TreeRootBuilder {
for (int[] c : cells) {
baseRadius = Math.max(baseRadius, Math.hypot(c[0] - cx, c[1] - cz) + 0.5);
}
double flare = tree.getRootFlare() > 0 ? tree.getRootFlare() : baseRadius + Math.max(2.0, depth * 0.6);
double flare = tree.rootFlare() > 0 ? tree.rootFlare() : baseRadius + Math.max(2.0, depth * 0.6);
TreeRootStyle style = tree.getRootStyle();
TreeRootStyle style = tree.rootStyle();
switch (style) {
case TAPROOT -> taproot(canvas, cells, cx, cz, baseRadius, depth);
case BUTTRESS -> {
@@ -19,8 +19,8 @@
package art.arcane.iris.engine.object.procedural.tree;
import art.arcane.iris.builtin.objects.tree.TreeAzimuthMode;
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
import art.arcane.iris.engine.object.procedural.tree.IrisProceduralTree;
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
import art.arcane.iris.builtin.objects.tree.Tree;
import java.util.ArrayList;
import java.util.List;
@@ -32,10 +32,10 @@ public final class TreeTrunkBuilder {
private TreeTrunkBuilder() {
}
public static List<Limb> build(TreeBlockCanvas canvas, IrisProceduralTree tree, int height) {
public static List<Limb> build(TreeBlockCanvas canvas, Tree tree, int height) {
boolean hasSecondary = hasSecondaryTrunk(tree);
double[][] mainOffsets = leanPath(tree, height);
int forks = Math.max(1, tree.getTrunkForks());
int forks = Math.max(1, tree.trunkForks());
List<Limb> limbs = new ArrayList<>();
if (forks == 1) {
@@ -45,12 +45,12 @@ public final class TreeTrunkBuilder {
return limbs;
}
int forkY = Math.max(1, Math.min(height - 2, (int) Math.round(tree.getForkHeight() * (height - 1))));
int forkY = Math.max(1, Math.min(height - 2, (int) Math.round(tree.forkHeight() * (height - 1))));
placeColumn(canvas, tree, mainOffsets, height, 0, forkY, hasSecondary);
double baseCx = mainOffsets[forkY][0];
double baseCz = mainOffsets[forkY][1];
double reachMax = (height - forkY) * Math.tan(Math.toRadians(tree.getForkAngle()));
double reachMax = (height - forkY) * Math.tan(Math.toRadians(tree.forkAngle()));
for (int f = 0; f < forks; f++) {
double az = Math.toRadians((360.0 / forks) * f);
@@ -73,7 +73,7 @@ public final class TreeTrunkBuilder {
return limbs;
}
private static double[][] leanPath(IrisProceduralTree tree, int height) {
private static double[][] leanPath(Tree tree, int height) {
double[][] offsets = new double[height][2];
for (int y = 0; y < height; y++) {
double[] lean = leanOffset(tree, y, height);
@@ -83,7 +83,7 @@ public final class TreeTrunkBuilder {
return offsets;
}
private static void placeColumn(TreeBlockCanvas canvas, IrisProceduralTree tree, double[][] offsets, int height,
private static void placeColumn(TreeBlockCanvas canvas, Tree tree, double[][] offsets, int height,
int yStart, int yEnd, boolean hasSecondary) {
double prevCx = yStart > 0 ? offsets[yStart - 1][0] : 0.0;
double prevCz = yStart > 0 ? offsets[yStart - 1][1] : 0.0;
@@ -128,45 +128,41 @@ public final class TreeTrunkBuilder {
}
}
private static int widthAt(IrisProceduralTree tree, int y, int height) {
private static int widthAt(Tree tree, int y, int height) {
double t = y / (double) Math.max(height - 1, 1);
double multiplier = TreeFunctions.trunkWidthMultiplier(tree, t);
return Math.max(1, (int) Math.round(tree.getTrunkWidth() * multiplier));
return Math.max(1, (int) Math.round(tree.trunkWidth() * multiplier));
}
private static TreeBlockCanvas.Role trunkRole(IrisProceduralTree tree, boolean hasSecondary, int y, int height) {
private static TreeBlockCanvas.Role trunkRole(Tree tree, boolean hasSecondary, int y, int height) {
if (!hasSecondary) {
return TreeBlockCanvas.Role.TRUNK;
}
double t = y / (double) Math.max(height - 1, 1);
if (tree.getSecondaryTrunkStart() <= t && t <= tree.getSecondaryTrunkEnd()) {
if (tree.secondaryTrunkStart() <= t && t <= tree.secondaryTrunkEnd()) {
return TreeBlockCanvas.Role.SECONDARY_TRUNK;
}
return TreeBlockCanvas.Role.TRUNK;
}
private static boolean hasSecondaryTrunk(IrisProceduralTree tree) {
if (paletteSet(tree.getSecondaryTrunkPalette())) {
private static boolean hasSecondaryTrunk(Tree tree) {
if (IrisProceduralBlocks.paletteSet(tree.secondaryTrunkPalette())) {
return true;
}
return tree.getSecondaryTrunk() != null && !tree.getSecondaryTrunk().isEmpty();
return tree.secondaryTrunk().filter(trunk -> !trunk.isEmpty()).isPresent();
}
static boolean paletteSet(IrisMaterialPalette palette) {
return palette != null && palette.getPalette() != null && !palette.getPalette().isEmpty();
}
private static double[] leanOffset(IrisProceduralTree tree, int y, int height) {
if (tree.getLeanAngle() == 0.0 || height <= 1) {
private static double[] leanOffset(Tree tree, int y, int height) {
if (tree.leanAngle() == 0.0 || height <= 1) {
return new double[]{0.0, 0.0};
}
double t = y / (double) Math.max(height - 1, 1);
double progress = TreeFunctions.curveProgress(tree.getTrunkCurve(), t, tree.getCurveSteepness());
double maxReach = height * Math.tan(Math.toRadians(tree.getLeanAngle()));
double progress = TreeFunctions.curveProgress(tree.trunkCurve(), t, tree.curveSteepness());
double maxReach = height * Math.tan(Math.toRadians(tree.leanAngle()));
double reach = maxReach * progress;
double azDeg = tree.getLeanAzimuthMode() == TreeAzimuthMode.CONSTANT
? tree.getLeanAzimuth()
: TreeFunctions.azimuthDegrees(tree.getLeanAzimuthMode(), t, -1, tree, tree.getLeanAzimuth(), null);
double azDeg = tree.leanAzimuthMode() == TreeAzimuthMode.CONSTANT
? tree.leanAzimuth()
: TreeFunctions.azimuthDegrees(tree.leanAzimuthMode(), t, -1, tree, tree.leanAzimuth(), null);
double azRad = Math.toRadians(azDeg);
double dx = reach * Math.sin(azRad);
double dz = reach * Math.cos(azRad);
@@ -20,6 +20,7 @@ package art.arcane.iris.engine.object.terrain.floating;
import art.arcane.iris.builtin.carve.CarvingEntry;
import art.arcane.iris.builtin.carve.CarvingSettings;
import art.arcane.iris.engine.object.placement.ObjectPlacements;
import art.arcane.iris.builtin.carve.CaveProfile;
import art.arcane.iris.builtin.floating.FloatingChildBiome;
import art.arcane.iris.core.loader.IrisData;
@@ -184,7 +185,7 @@ public final class ResolvedFloatingChild implements IRare {
}
public KList<IrisObjectPlacement> resolveTopObjects(IrisBiome target) {
KList<IrisObjectPlacement> surfaceObjects = (settings.inheritObjects() && target != null) ? target.getSurfaceObjects() : new KList<>();
KList<IrisObjectPlacement> surfaceObjects = (settings.inheritObjects() && target != null) ? ObjectPlacements.surface(target) : new KList<>();
return resolveTopObjectsFromSurface(surfaceObjects);
}
@@ -20,8 +20,6 @@ package art.arcane.iris.engine.object.world.biome;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.NoiseStyle;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.procedural.IrisProceduralObjects;
import art.arcane.iris.engine.object.value.IRare;
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
@@ -79,8 +77,6 @@ public class IrisBiome extends IrisRegistrant implements IRare {
private final transient AtomicCache<KMap<String, IrisBiomeGeneratorLink>> genCache = new AtomicCache<>();
private final transient AtomicCache<KMap<String, Integer>> genCacheMax = new AtomicCache<>();
private final transient AtomicCache<KMap<String, Integer>> genCacheMin = new AtomicCache<>();
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>();
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>();
private final transient AtomicCache<Color> cacheColor = new AtomicCache<>();
private final transient AtomicCache<Color> cacheColorObjectDensity = new AtomicCache<>();
private final transient AtomicCache<Color> cacheColorDecoratorLoad = new AtomicCache<>();
@@ -140,11 +136,6 @@ public class IrisBiome extends IrisRegistrant implements IRare {
@ArrayType(min = 1, type = String.class)
@Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 4 biomes down the tree.")
private KList<String> children = new KList<>();
@ArrayType(min = 1, type = IrisObjectPlacement.class)
@Desc("Objects define what schematics (iob files) iris will place in this biome")
private KList<IrisObjectPlacement> objects = new KList<>();
@Desc("Procedural objects (such as trees) iris generates from scratch and places in this biome, instead of loading them from iob files")
private IrisProceduralObjects proceduralObjects = new IrisProceduralObjects();
@ArrayType(min = 1, type = IrisBiomeGeneratorLink.class)
@Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.")
private KList<IrisBiomeGeneratorLink> generators = new KList<IrisBiomeGeneratorLink>().qadd(new IrisBiomeGeneratorLink());
@@ -260,36 +251,6 @@ public class IrisBiome extends IrisRegistrant implements IRare {
return IrisBiomeGenLinks.getGenLink(this, loadKey);
}
public KList<IrisObjectPlacement> getSurfaceObjects() {
return getSurfaceObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for (IrisObjectPlacement i : o.copy()) {
if (!i.getCarvingSupport().supportsSurface()) {
o.remove(i);
}
}
return o;
});
}
public KList<IrisObjectPlacement> getCarvingObjects() {
return getCarveObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for (IrisObjectPlacement i : o.copy()) {
if (!i.getCarvingSupport().supportsCarving()) {
o.remove(i);
}
}
return o;
});
}
public double getHeight(Engine xg, double x, double z, long seed) {
double height = 0;
@@ -22,6 +22,7 @@ import art.arcane.iris.builtin.decorant.DecorantSettings;
import art.arcane.iris.builtin.decorant.DecoratorLoad;
import art.arcane.iris.builtin.terrain.LayerLoad;
import art.arcane.iris.builtin.terrain.LayersSettings;
import art.arcane.iris.engine.object.placement.ObjectPlacements;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.render.RenderType;
@@ -70,7 +71,7 @@ final class IrisBiomeColorRenderer {
return biome.getCacheColorObjectDensity().aquire(() -> {
double density = 0;
for (IrisObjectPlacement i : biome.getObjects()) {
for (IrisObjectPlacement i : ObjectPlacements.all(biome)) {
density += i.getDensity() * i.getChance();
}
@@ -24,7 +24,6 @@ import art.arcane.iris.engine.object.image.IrisImageMapBinding;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.IrisShapedGeneratorStyle;
import art.arcane.iris.engine.object.noise.NoiseStyle;
import art.arcane.iris.engine.object.procedural.tree.IrisTreeSettings;
import art.arcane.iris.engine.object.runtime.StudioMode;
import art.arcane.iris.engine.object.value.IrisRange;
import art.arcane.iris.engine.object.world.IrisEnvironment;
@@ -115,8 +114,6 @@ public class IrisDimension extends IrisRegistrant {
@MaxNumber(16)
@Desc("Every X/Z % debugCrossSectionsMod == 0 cuts the chunk")
private int debugCrossSectionsMod = 3;
@Desc("Tree growth override settings")
private IrisTreeSettings treeSettings = new IrisTreeSettings();
@MinNumber(0)
@Desc("The version of this dimension. Changing this will stop users from accidentally upgrading (and breaking their worlds).")
private int version = 1;
@@ -138,12 +135,6 @@ public class IrisDimension extends IrisRegistrant {
private IrisGeneratorStyle caveBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
@Desc("Instead of filling objects with air, fills them with cobweb so you can see them")
private boolean debugSmartBore = false;
@Desc("Refuse to place surface objects and trees over carved surface openings.")
private boolean requireObjectSurfaceSupport = true;
@MinNumber(0)
@MaxNumber(16)
@Desc("Minimum surface-support buffer, in blocks, applied to every surface object placement in this dimension. A placement may ask for more but never less.")
private int objectSurfaceSupportBuffer = 2;
@Desc("The world environment")
private IrisEnvironment environment = IrisEnvironment.NORMAL;
@RegistryListResource(IrisRegion.class)
@@ -174,10 +165,6 @@ public class IrisDimension extends IrisRegistrant {
@MaxNumber(256)
@Desc("Minimum air gap in blocks between the lower terrain surface and the upper terrain surface.")
private int upperDimensionGap = 32;
@Desc("When true, objects from the mantle (structures, trees, etc.) can be placed in the upper dimension terrain zone. When false, the upper terrain is protected from object placement.")
private boolean upperDimensionObjects = false;
@Desc("When true, upper-dimension objects force-place regardless of placement restrictions (slope, underwater, clamp, collisions, carving). Normal dimension objects always place first; upper objects place second and may clip or occlude lower-dimension placements when this is enabled.")
private boolean upperObjectsForcePlace = false;
@RegistryListResource(IrisBiome.class)
@Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.")
private String focus = "";
@@ -18,8 +18,6 @@
package art.arcane.iris.engine.object.world.region;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.procedural.IrisProceduralObjects;
import art.arcane.iris.engine.object.value.IRare;
import art.arcane.iris.engine.object.world.biome.InferredType;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
@@ -57,8 +55,6 @@ import java.util.Random;
@Data
@EqualsAndHashCode(callSuper = false)
public class IrisRegion extends IrisRegistrant implements IRare {
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>();
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>();
private final transient AtomicCache<KList<String>> cacheRidge = new AtomicCache<>();
private final transient AtomicCache<KList<String>> cacheSpot = new AtomicCache<>();
private final transient AtomicCache<CNG> shoreHeightGenerator = new AtomicCache<>();
@@ -75,11 +71,6 @@ public class IrisRegion extends IrisRegistrant implements IRare {
@MaxNumber(128)
@Desc("The rarity of the region")
private int rarity = 1;
@ArrayType(min = 1, type = IrisObjectPlacement.class)
@Desc("Objects define what schematics (iob files) iris will place in this region")
private KList<IrisObjectPlacement> objects = new KList<>();
@Desc("Procedural objects (trees, ruins, formations, coral, fungi, crystals) iris generates from scratch and places across this region")
private IrisProceduralObjects proceduralObjects = new IrisProceduralObjects();
@MinNumber(0)
@Desc("The min shore height")
private double shoreHeightMin = 1.2;
@@ -125,36 +116,6 @@ public class IrisRegion extends IrisRegistrant implements IRare {
return name;
}
public KList<IrisObjectPlacement> getSurfaceObjects() {
return getSurfaceObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for (IrisObjectPlacement i : o.copy()) {
if (!i.getCarvingSupport().supportsSurface()) {
o.remove(i);
}
}
return o;
});
}
public KList<IrisObjectPlacement> getCarvingObjects() {
return getCarveObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for (IrisObjectPlacement i : o.copy()) {
if (!i.getCarvingSupport().supportsCarving()) {
o.remove(i);
}
}
return o;
});
}
public CNG getShoreHeightGenerator() {
return shoreHeightGenerator.aquire(() ->
CNG.signature(new RNG((long) (getName().length() + getLandBiomeZoom() + getLandBiomes().size() + 3458612))));