Structure placements become iris:structure settings under the key packs always wrote

The "structures" lists of dimensions, regions and biomes are StructurePlacementSettings (iris:structure/placements):
StructurePlacement and NativeStructureSource with every option, default and description of IrisStructurePlacement and
IrisNativeStructure, and StructureAnchorMode, StructureDistribution and NativeStructureSuppression with their constants
in the same order (placement identities hash the ordinals). The host fields and classes are deleted, as is the
RegistryListStructure annotation only they used. Every reader asks StructurePlacementScope.placementsOf(owner); the
scope index of which levels declare placements lives in the world's state.
This commit is contained in:
piexel committed 2026-10-12 02:19:49 +02:00
1 parent 75f3504ae7
commit 965adea59e
21 files changed
+586 -466

No files matched your search

+6 -4
View File
@@ -34,11 +34,12 @@ replacement) wherever Iris validates a pack; Iris core has no loader or validato
Built-in modules answer Iris through IrisApi services instead of Iris reading their features: `iris:objects`
provides `ObjectsAt` (the objects a chunk would get, for the object search and studio tools) and `iris:structure`
provides `StructureLocator` (`StructureLocating`: the pack's structure keys for Iris's structure index, the ones a
world places, and their nearest start for the find commands). `iris:structure` also has a lifecycle hook that drops a
world's structure index when the world stops, which includes every reload of the pack's structure files.
world places, and their nearest start for the find commands). A world's structure index lives in the world's state
(`engine.getGeneration().state(...)`), so every reload of the pack's structure files, which starts a new world, builds
it again.
`iris:structure` also provides `VanillaStructures` (`StructureVanillaStructures`) for the platform's own structures:
which ones its placements replace or the dimension's `importedStructures` disables, the starts its `nativeStructures`
placements make, the shift and band of the platform's starts, and the whole terrain fit of every start (SOURCE,
placements make (`startedStructures`, `locatableStarts`, `locateStart`), the shift and band of the platform's starts, and the whole terrain fit of every start (SOURCE,
PRESERVE, VACUUM, ENCASE, BORE, FORCE_CARVE, stilts) in `engine/framework/structure/fit`, written against IrisApi's
`StructureFit` and `BlockAccess` only. A start carries its fit as a memo (its terrain and stilts JSON), so every
chunk it reaches and every restart fits it the same way. `iris:vanilla-features` (`VanillaFeaturesModule`, no stages)
@@ -107,7 +108,8 @@ dimension reaches learn of them without reading the settings classes; and `iris:
(`CaveBiomeBands`), which Iris asks for the dimension's carving band at a position and for a biome's minimum cave depth.
Packs write each settings feature under the short key it declares: `deposits` (dimension, region, biome; a list), `decorators`
(biome; a list) and `importedStructures` (dimension; an object of `disabled`, `adjustments` and the rest). The feature ids
(biome; a list), `importedStructures` (dimension; an object of `disabled`, `adjustments` and the rest) and `structures`
(dimension, region, biome; a list of `StructurePlacement`s, `StructurePlacementSettings`). The feature ids
(`iris:deposit`, `iris:decorant`, `iris:structure`) stay the modules' identity in the stage graph and logs. A key is unique
per target across all modules and Iris's own fields, so a new built-in or pack module picks a key no field of the target uses.
@@ -0,0 +1,64 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.structure;
import com.volmit.config.Desc;
import com.volmit.config.MinNumber;
import com.volmit.config.Ref;
import com.volmit.config.Reference;
import com.volmit.config.Required;
import com.volmit.vanilla.JigsawOverrides;
import java.util.Optional;
/**
* One platform structure a structure placement starts itself, written as
* {@code {"structure": "minecraft:ancient_city", "weight": 2, "jigsaw": {...}}}. IrisApi types only.
*/
@Desc("A live vanilla, datapack, or modded structure generated by Minecraft at an Iris-controlled placement.")
public final class NativeStructureSource {
@Required
@Ref(Reference.STRUCTURE)
@Desc("Registered structure key. The source retains its native generator, pieces, templates, processors, entities, markers, and data.")
private String structure = "";
@MinNumber(1)
@Desc("Relative selection weight when a placement offers multiple native structure sources.")
private int weight = 1;
@Desc("Optional jigsaw-only assembly overrides. Null preserves the complete registered structure definition.")
private JigsawOverrides jigsaw = null;
public NativeStructureSource() {
}
/** The registry key of the platform structure, as the pack wrote it. */
public String structure() {
return structure;
}
public int weight() {
return weight;
}
/** The overrides of the platform's jigsaw assembly; empty to keep its own. */
public Optional<JigsawOverrides> jigsaw() {
return Optional.ofNullable(jigsaw);
}
}
@@ -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,18 +16,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.annotations;
package art.arcane.iris.builtin.structure;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import com.volmit.config.Desc;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
@Target({PARAMETER, TYPE, FIELD})
public @interface RegistryListStructure {
/** Whether a structure placement replaces the platform structure its structures stand in for. */
@Desc("Controls whether an Iris structure placement suppresses its imported native source.")
public enum NativeStructureSuppression {
@Desc("Leaves native generation enabled alongside this Iris structure placement.")
NONE,
@Desc("Suppresses the structure's vanillaSource when used by a validated dimension-level replacement placement.")
REPLACE_SOURCE
}
@@ -0,0 +1,54 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin.structure;
import com.volmit.config.Desc;
/** How a structure placement picks the height it anchors a structure at. The placement identity hashes the order. */
@Desc("Selects the vertical environment used to anchor an Iris structure placement.")
public enum StructureAnchorMode {
@Desc("Preserve the historical underground boolean behavior.")
LEGACY,
@Desc("Anchor to the terrain surface and use minHeight/maxHeight as a surface gate.")
SURFACE,
@Desc("Choose a deterministic Y inside the minHeight/maxHeight band.")
HEIGHT_BAND,
@Desc("Anchor in carved space with solid support below.")
CAVE_FLOOR,
@Desc("Anchor in carved space with solid support above.")
CAVE_CEILING,
@Desc("Anchor in carved space without nearby floor or ceiling support.")
CAVE_CENTER,
@Desc("Anchor at any carved-space position.")
CAVE_ANY;
/** Whether the anchor looks for carved space. */
public boolean isCave() {
return switch (this) {
case CAVE_FLOOR, CAVE_CEILING, CAVE_CENTER, CAVE_ANY -> true;
default -> false;
};
}
}
@@ -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,10 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.structure;
package art.arcane.iris.builtin.structure;
import art.arcane.iris.engine.object.annotations.Desc;
import com.volmit.config.Desc;
/** How a structure placement scatters its starts. The placement identity hashes the order. */
@Desc("Controls how structure start positions are scattered across the world.")
public enum StructureDistribution {
@Desc("Vanilla-style spacing/separation grid. One placement attempt per grid cell, randomly offset within it by the separation. Use spacing, separation and salt.")
@@ -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,39 +16,37 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.object.structure;
package art.arcane.iris.builtin.structure;
import art.arcane.iris.builtin.structure.StructureStilts;
import art.arcane.iris.builtin.structure.StructureTerrain;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
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.RegistryListResource;
import art.arcane.iris.engine.object.annotations.RegistryListStructure;
import art.arcane.volmlib.util.collection.KList;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import art.arcane.iris.engine.object.structure.IrisStructure;
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.ResourceRef;
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* Where and how often the structures of a dimension, region or biome start, written as one entry of its
* {@code "structures": [...]}: the pack's own structures to assemble or the platform's to start natively, the
* distribution of the starts, the height they anchor at, and how they meet the terrain. IrisApi types only, besides
* the structure resource kind the {@code structures} keys name.
*/
@Desc("Attaches structures to a biome, region or dimension and controls where and how often they generate. This is independent of a structure's own native generation, so you can add custom placements in tandem with native generation or instead of it.")
@Data
public class IrisStructurePlacement {
@ArrayType(type = String.class, min = 1)
@RegistryListStructure
public final class StructurePlacement {
@MinItems(1)
@ResourceRef(IrisStructure.class)
@Desc("Editable Iris assembly resources offered by this placement. Leave empty when nativeStructures supplies the source.")
private KList<String> structures = new KList<>();
private List<String> structures = List.of();
@ArrayType(type = IrisNativeStructure.class, min = 1)
@MinItems(1)
@Desc("Live registered vanilla, datapack, and modded structures offered by this placement. Minecraft runs their native generator directly, independent of normal biome or dimension eligibility.")
private KList<IrisNativeStructure> nativeStructures = new KList<>();
private List<NativeStructureSource> nativeStructures = List.of();
@Desc("Stable authored identity for this placement. Set this when multiple placements use the same structure and settings. When empty, Iris derives identity from the placement content so list reordering does not move generated structures.")
private String placementId = "";
@@ -98,12 +96,12 @@ public class IrisStructurePlacement {
private boolean underground = false;
@Desc("Vertical anchor policy. LEGACY preserves the underground boolean. Cave modes search existing carved-space data and implicitly behave as underground placements.")
private IrisStructureAnchorMode anchor = IrisStructureAnchorMode.LEGACY;
private StructureAnchorMode anchor = StructureAnchorMode.LEGACY;
@RegistryListResource(IrisBiome.class)
@ArrayType(type = String.class, min = 1)
@MinItems(1)
@Ref(Reference.PACK_BIOME)
@Desc("Optional cave-biome allowlist for cave anchor modes. Empty accepts the cave biome resolved at the selected anchor. Entries match by load key, including prefix matches.")
private KList<String> caveBiomes = new KList<>();
private List<String> caveBiomes = List.of();
@MinNumber(1)
@MaxNumber(64)
@@ -129,27 +127,129 @@ public class IrisStructurePlacement {
@Desc("If false, the placement is skipped when its selected surface or cave column is submerged.")
private boolean underwater = false;
public StructurePlacement() {
}
/** Keys of the pack's structures the placement assembles, one picked per start. */
public List<String> structures() {
return listOrEmpty(structures);
}
/** The platform structures the placement starts natively, one picked per start by weight. */
public List<NativeStructureSource> nativeStructures() {
return listOrEmpty(nativeStructures);
}
public String placementId() {
return placementId;
}
public NativeStructureSuppression nativeSuppression() {
return nativeSuppression == null ? NativeStructureSuppression.NONE : nativeSuppression;
}
public StructureDistribution distribution() {
return distribution == null ? StructureDistribution.RANDOM_SPREAD : distribution;
}
public int spacing() {
return spacing;
}
public int separation() {
return separation;
}
public int salt() {
return salt;
}
public double density() {
return density;
}
public int ringCount() {
return ringCount;
}
public int ringDistance() {
return ringDistance;
}
public int ringSpread() {
return ringSpread;
}
public int minHeight() {
return minHeight;
}
public int maxHeight() {
return maxHeight;
}
public boolean underground() {
return underground;
}
/** The anchor as written; {@link #resolvedAnchor} says what {@code LEGACY} means for this placement. */
public StructureAnchorMode anchor() {
return anchor == null ? StructureAnchorMode.LEGACY : anchor;
}
/** Cave biome keys or key prefixes a cave anchor accepts; empty for any. */
public List<String> caveBiomes() {
return listOrEmpty(caveBiomes);
}
public int caveAnchorAttempts() {
return caveAnchorAttempts;
}
public int caveAnchorScanStep() {
return caveAnchorScanStep;
}
public int caveMinimumClearance() {
return caveMinimumClearance;
}
/** How the placement's structures meet the terrain; the defaults when the pack wrote none. */
public StructureTerrain resolvedTerrain() {
return terrain == null ? new StructureTerrain() : terrain;
}
/** The foundation columns under the structures; empty for none. */
public Optional<StructureStilts> stilt() {
return Optional.ofNullable(stilt);
}
public boolean underwater() {
return underwater;
}
public boolean hasIrisStructures() {
return structures != null && !structures.isEmpty();
return !structures().isEmpty();
}
public boolean hasNativeStructures() {
return nativeStructures != null && !nativeStructures.isEmpty();
return !nativeStructures().isEmpty();
}
public IrisStructureAnchorMode resolvedAnchor() {
if (anchor == null || anchor == IrisStructureAnchorMode.LEGACY) {
return underground ? IrisStructureAnchorMode.HEIGHT_BAND : IrisStructureAnchorMode.SURFACE;
/** The anchor this placement uses: {@code LEGACY} is the band when {@link #underground}, else the surface. */
public StructureAnchorMode resolvedAnchor() {
if (anchor() == StructureAnchorMode.LEGACY) {
return underground ? StructureAnchorMode.HEIGHT_BAND : StructureAnchorMode.SURFACE;
}
return anchor;
return anchor();
}
public boolean isAnchoredUnderground() {
IrisStructureAnchorMode activeAnchor = resolvedAnchor();
return activeAnchor == IrisStructureAnchorMode.HEIGHT_BAND || activeAnchor.isCave();
StructureAnchorMode activeAnchor = resolvedAnchor();
return activeAnchor == StructureAnchorMode.HEIGHT_BAND || activeAnchor.isCave();
}
private static <T> List<T> listOrEmpty(List<T> list) {
return list == null ? List.of() : Collections.unmodifiableList(list);
}
}
@@ -0,0 +1,48 @@
/*
* 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.structure;
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 structure placements of a dimension, region or biome, written as {@code "structures": [...]}: one
* {@link StructurePlacement} per entry. IrisApi types only.
*/
@Desc("Iris structure placements of this dimension, region or biome: where and how often its structures start.")
@Feature(id = "iris:structure/placements", name = "Structure placements", key = "structures", root = "placements",
targets = {Target.DIMENSION, Target.REGION, Target.BIOME})
public final class StructurePlacementSettings implements IrisFeature {
@MinItems(1)
@Desc("Iris structure placements, each independent of the others.")
private List<StructurePlacement> placements = List.of();
public StructurePlacementSettings() {
}
public List<StructurePlacement> placements() {
return placements == null ? List.of() : Collections.unmodifiableList(placements);
}
}
@@ -26,17 +26,17 @@ import art.arcane.iris.engine.framework.structure.StructureGraphCatalog;
import art.arcane.iris.engine.framework.structure.StructureGraphCompilation;
import art.arcane.iris.engine.framework.structure.StructureAssemblyResult;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
import art.arcane.iris.builtin.structure.NativeStructureSource;
import art.arcane.iris.engine.object.value.IrisPosition;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.structure.IrisStructure;
import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode;
import art.arcane.iris.builtin.structure.StructureAnchorMode;
import art.arcane.iris.builtin.structure.StructureCarveShape;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.iris.builtin.structure.StructureTerrain;
import art.arcane.iris.builtin.structure.StructureTerrainMode;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
import art.arcane.iris.engine.object.structure.StructureDistribution;
import art.arcane.iris.builtin.structure.NativeStructureSuppression;
import art.arcane.iris.builtin.structure.StructureDistribution;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.iris.core.modules.IrisModuleHost;
@@ -170,7 +170,7 @@ public final class IrisStructureLocator {
if (engine == null || key == null || key.isBlank()) {
return false;
}
for (IrisStructurePlacement placement : index(engine).placements) {
for (StructurePlacement placement : index(engine).placements) {
if (placement.hasIrisStructures() && matches(placement, key, engine.getData())) {
return true;
}
@@ -282,8 +282,8 @@ public final class IrisStructureLocator {
CandidateBudget candidateBudget) {
LocatedCandidate best = null;
Set<Long> checkedChunks = new LinkedHashSet<>();
for (IrisStructurePlacement placement : catalog.concentricRings()) {
int count = Math.max(1, placement.getRingCount());
for (StructurePlacement placement : catalog.concentricRings()) {
int count = Math.max(1, placement.ringCount());
for (int placementIndex = 0; placementIndex < count; placementIndex++) {
candidateBudget.claim();
int[] candidate = StructurePlacementGrid.concentricRingChunk(
@@ -421,8 +421,8 @@ public final class IrisStructureLocator {
}
Set<Long> checkedRingChunks = new LinkedHashSet<>();
for (IrisStructurePlacement placement : catalog.concentricRings) {
int count = Math.max(1, placement.getRingCount());
for (StructurePlacement placement : catalog.concentricRings) {
int count = Math.max(1, placement.ringCount());
for (int placementIndex = 0; placementIndex < count; placementIndex++) {
candidateBudget.claim();
int[] candidate = StructurePlacementGrid.concentricRingChunk(placement, placementIndex, seed);
@@ -488,13 +488,13 @@ public final class IrisStructureLocator {
&& Math.abs((long) chunkZ - centerChunkZ) <= radius;
}
public static ResolvedPlacement resolvePlacement(Engine engine, IrisStructurePlacement placement, int cx, int cz) {
public static ResolvedPlacement resolvePlacement(Engine engine, StructurePlacement placement, int cx, int cz) {
if (engine == null || engine.getData() == null || engine.getSeedManager() == null) {
throw new IllegalStateException("Iris structure placement requires a fully bound engine");
}
NativeStartPlanner.validateBackend(placement);
if (!placement.hasIrisStructures() || placement.getDistribution() == null) {
throw new IllegalStateException("Iris structure placement is missing its distribution or structure list");
if (!placement.hasIrisStructures()) {
throw new IllegalStateException("Iris structure placement is missing its structure list");
}
long seed = engine.getSeedManager().getMantle();
if (!StructurePlacementGrid.startsInChunk(placement, cx, cz, seed)) {
@@ -580,18 +580,18 @@ public final class IrisStructureLocator {
return new ResolvedPlacement(placement, selectedKey, structure, pieces, rng, originX, baseY, originZ, exactY);
}
public static boolean requirePlacementOutput(IrisStructurePlacement placement, String structureKey,
public static boolean requirePlacementOutput(StructurePlacement placement, String structureKey,
int chunkX, int chunkZ, boolean outputPresent,
String failureReason) {
if (outputPresent) {
return true;
}
if (placement == null
|| NativeStructureSuppression.REPLACE_SOURCE != placement.getNativeSuppression()) {
|| NativeStructureSuppression.REPLACE_SOURCE != placement.nativeSuppression()) {
return false;
}
String key = structureKey == null || structureKey.isBlank()
? String.valueOf(placement.getStructures()) : structureKey;
? String.valueOf(placement.structures()) : structureKey;
String reason = failureReason == null || failureReason.isBlank()
? "placement produced no output" : failureReason;
throw new IllegalStateException("REPLACE_SOURCE placement for Iris structure '" + key
@@ -614,13 +614,13 @@ public final class IrisStructureLocator {
String normalizedKey = normalize(key);
if (hasNativePlacement(engine, key)) {
for (NativeStartPlanner.Plan plan : NativeStartPlanner.plansAt(engine, cx, cz)) {
if (normalize(plan.source().getStructure()).equals(normalizedKey)) {
if (normalize(plan.source().structure()).equals(normalizedKey)) {
return new ResolvedStart(cx << 4, plan.baseY(), cz << 4);
}
}
}
KList<IrisStructurePlacement> placements = StructurePlacementScope.placementsAt(engine, cx, cz);
for (IrisStructurePlacement placement : placements) {
KList<StructurePlacement> placements = StructurePlacementScope.placementsAt(engine, cx, cz);
for (StructurePlacement placement : placements) {
if (!matches(placement, key, data)) {
continue;
}
@@ -638,7 +638,7 @@ public final class IrisStructureLocator {
private static PlacementAnchor resolveAnchor(
Engine engine,
IrisStructurePlacement placement,
StructurePlacement placement,
int chunkX,
int chunkZ,
int originX,
@@ -654,29 +654,29 @@ public final class IrisStructureLocator {
return baseY == null ? null : new PlacementAnchor(originX, baseY, originZ);
}
private static Integer resolveBaseY(Engine engine, IrisStructurePlacement placement, int originX, int originZ, RNG rng) {
private static Integer resolveBaseY(Engine engine, StructurePlacement placement, int originX, int originZ, RNG rng) {
int worldMin = engine.getMinHeight() + 1;
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
if (worldMin > worldMax) {
return null;
}
if (!placement.isUnderwater()
if (!placement.underwater()
&& NativeStartPlanner.isSubmerged(engine, originX, originZ)) {
return null;
}
if (placement.resolvedAnchor() == IrisStructureAnchorMode.SURFACE) {
if (placement.resolvedAnchor() == StructureAnchorMode.SURFACE) {
int surfaceY = engine.getHeight(originX, originZ, true) + engine.getMinHeight();
return surfaceY < placement.getMinHeight() || surfaceY > placement.getMaxHeight() ? null : surfaceY;
return surfaceY < placement.minHeight() || surfaceY > placement.maxHeight() ? null : surfaceY;
}
int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight()));
int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight()));
if (bandMin > bandMax) {
return null;
}
return randomInclusive(rng, bandMin, bandMax);
}
static Integer resolveVerticalShift(KList<PlacedStructurePiece> pieces, IrisStructurePlacement placement,
static Integer resolveVerticalShift(KList<PlacedStructurePiece> pieces, StructurePlacement placement,
int baseY, int worldMin, int worldMax) {
int[] bounds = computeBounds(pieces);
if (bounds == null) {
@@ -685,8 +685,8 @@ public final class IrisStructureLocator {
if (!placement.isAnchoredUnderground() || placement.resolvedAnchor().isCave()) {
return bounds[1] >= worldMin && bounds[4] <= worldMax ? 0 : null;
}
int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight()));
int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight()));
int minimumShift = Math.max(worldMin - bounds[1], bandMin - baseY);
int maximumShift = Math.min(worldMax - bounds[4], bandMax - baseY);
if (minimumShift > maximumShift) {
@@ -702,7 +702,7 @@ public final class IrisStructureLocator {
}
static Integer resolveUndergroundBurialShift(Engine engine, KList<PlacedStructurePiece> pieces,
IrisStructurePlacement placement, int baseY,
StructurePlacement placement, int baseY,
int worldMin, int worldMax) {
int[] bounds = computeBounds(pieces);
if (engine == null || bounds == null || placement == null || !placement.isAnchoredUnderground()
@@ -721,8 +721,8 @@ public final class IrisStructureLocator {
terrain.ceilingPadding(), terrain.resolvedErosionStrength())
: bore ? Math.max(0, terrain.ceilingPadding()) : 0;
int bottomExtension = forceCarve || bore ? Math.max(0, terrain.floorPadding()) : 0;
int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight()));
int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight()));
int minimumShift = Math.max(worldMin - (bounds[1] - bottomExtension), bandMin - baseY);
int maximumShift = Math.min(0, Math.min(worldMax - (bounds[4] + topExtension), bandMax - baseY));
if (minimumShift > maximumShift) {
@@ -786,19 +786,19 @@ public final class IrisStructureLocator {
return maximumShift;
}
static String selectStructureKey(IrisStructurePlacement placement, RNG rng) {
if (placement == null || placement.getStructures() == null || placement.getStructures().isEmpty()) {
static String selectStructureKey(StructurePlacement placement, RNG rng) {
if (placement == null || placement.structures().isEmpty()) {
return null;
}
return placement.getStructures().get(rng.nextInt(placement.getStructures().size()));
return placement.structures().get(rng.nextInt(placement.structures().size()));
}
static KList<PlacedStructurePiece> alignCavePieces(
KList<PlacedStructurePiece> pieces,
IrisStructurePlacement placement,
StructurePlacement placement,
int anchorY
) {
IrisStructureAnchorMode mode = placement.resolvedAnchor();
StructureAnchorMode mode = placement.resolvedAnchor();
if (!mode.isCave()) {
return pieces;
}
@@ -816,7 +816,7 @@ public final class IrisStructureLocator {
}
private static KList<PlacedStructurePiece> alignSurfacePieces(KList<PlacedStructurePiece> pieces,
IrisStructurePlacement placement,
StructurePlacement placement,
IrisStructure structure, int baseY) {
if (placement.isAnchoredUnderground() || pieces.size() <= 1
|| structure.getPlaceMode().placeMode().has(PlaceTrait.FREE_HEIGHT)) {
@@ -826,7 +826,7 @@ public final class IrisStructureLocator {
return bounds == null ? pieces : shiftPieces(pieces, baseY - bounds[1]);
}
static boolean hasExactY(IrisStructurePlacement placement, IrisStructure structure,
static boolean hasExactY(StructurePlacement placement, IrisStructure structure,
KList<PlacedStructurePiece> pieces) {
return placement.isAnchoredUnderground() || pieces.size() > 1
|| structure.getPlaceMode().placeMode().has(PlaceTrait.FREE_HEIGHT);
@@ -893,39 +893,38 @@ public final class IrisStructureLocator {
private static PlacementCatalog collectPlacementCatalog(Engine engine, String key) {
Set<RandomSpreadParameters> randomSpread = new LinkedHashSet<>();
List<IrisStructurePlacement> concentricRings = new ArrayList<>();
List<StructurePlacement> concentricRings = new ArrayList<>();
boolean hasDensity = false;
for (IrisStructurePlacement placement : index(engine).placements) {
for (StructurePlacement placement : index(engine).placements) {
if (!isSearchablePlacement(engine, placement)
|| !matches(placement, key, engine.getData())) {
continue;
}
if (placement.getDistribution() == StructureDistribution.RANDOM_SPREAD) {
if (placement.distribution() == StructureDistribution.RANDOM_SPREAD) {
randomSpread.add(new RandomSpreadParameters(
Math.max(1, placement.getSpacing()), placement.getSeparation(),
Math.max(1, placement.spacing()), placement.separation(),
StructurePlacementGrid.placementSalt(placement)));
} else if (placement.getDistribution() == StructureDistribution.CONCENTRIC_RINGS) {
} else if (placement.distribution() == StructureDistribution.CONCENTRIC_RINGS) {
concentricRings.add(placement);
} else if (placement.getDistribution() == StructureDistribution.DENSITY) {
} else if (placement.distribution() == StructureDistribution.DENSITY) {
hasDensity = true;
}
}
return new PlacementCatalog(List.copyOf(randomSpread), List.copyOf(concentricRings), hasDensity);
}
static boolean isSearchableDensityPlacement(Engine engine, IrisStructurePlacement placement) {
static boolean isSearchableDensityPlacement(Engine engine, StructurePlacement placement) {
return placement != null
&& placement.getDistribution() == StructureDistribution.DENSITY
&& placement.distribution() == StructureDistribution.DENSITY
&& isSearchablePlacement(engine, placement);
}
static boolean isSearchablePlacement(Engine engine, IrisStructurePlacement placement) {
if (engine == null || placement == null || placement.getDistribution() == null
|| engine.getHeight() <= 0) {
static boolean isSearchablePlacement(Engine engine, StructurePlacement placement) {
if (engine == null || placement == null || engine.getHeight() <= 0) {
return false;
}
if (placement.getDistribution() == StructureDistribution.DENSITY
&& !(placement.getDensity() > 0.0)) {
if (placement.distribution() == StructureDistribution.DENSITY
&& !(placement.density() > 0.0)) {
return false;
}
long worldMin = (long) engine.getMinHeight() + (placement.isAnchoredUnderground() ? 1L : 0L);
@@ -935,11 +934,11 @@ public final class IrisStructureLocator {
return false;
}
long configuredMin = placement.isAnchoredUnderground()
? Math.min(placement.getMinHeight(), placement.getMaxHeight())
: placement.getMinHeight();
? Math.min(placement.minHeight(), placement.maxHeight())
: placement.minHeight();
long configuredMax = placement.isAnchoredUnderground()
? Math.max(placement.getMinHeight(), placement.getMaxHeight())
: placement.getMaxHeight();
? Math.max(placement.minHeight(), placement.maxHeight())
: placement.maxHeight();
return configuredMin <= configuredMax && configuredMin <= worldMax && configuredMax >= worldMin;
}
@@ -1017,22 +1016,17 @@ public final class IrisStructureLocator {
private record PlacementAnchor(int x, int y, int z) {
}
private static boolean matches(IrisStructurePlacement placement, String key, IrisData data) {
private static boolean matches(StructurePlacement placement, String key, IrisData data) {
if (placement == null || key == null || data == null) {
return false;
}
String normalizedKey = normalize(key);
if (placement.getNativeStructures() != null) {
for (IrisNativeStructure source : placement.getNativeStructures()) {
if (source != null && normalize(source.getStructure()).equals(normalizedKey)) {
return true;
}
for (NativeStructureSource source : placement.nativeStructures()) {
if (source != null && normalize(source.structure()).equals(normalizedKey)) {
return true;
}
}
if (placement.getStructures() == null) {
return false;
}
for (String structureKey : placement.getStructures()) {
for (String structureKey : placement.structures()) {
if (structureKey == null || structureKey.isBlank()) {
continue;
}
@@ -1085,18 +1079,18 @@ public final class IrisStructureLocator {
Set<String> normalizedEditableKeys = new LinkedHashSet<>();
Set<String> nativeKeys = new LinkedHashSet<>();
Set<String> normalizedNativeKeys = new LinkedHashSet<>();
for (IrisStructurePlacement placement : index(engine).placements) {
for (StructurePlacement placement : index(engine).placements) {
if (!isSearchablePlacement(engine, placement)) {
continue;
}
if (placement.hasNativeStructures()) {
for (IrisNativeStructure source : placement.getNativeStructures()) {
addLocatableKey(source.getStructure(), keys, normalizedKeys);
addLocatableKey(source.getStructure(), nativeKeys, normalizedNativeKeys);
for (NativeStructureSource source : placement.nativeStructures()) {
addLocatableKey(source.structure(), keys, normalizedKeys);
addLocatableKey(source.structure(), nativeKeys, normalizedNativeKeys);
}
continue;
}
for (String structureKey : placement.getStructures()) {
for (String structureKey : placement.structures()) {
IrisStructure structure = StructureResources.structure(data, structureKey);
if (structure == null) {
throw new IllegalStateException(
@@ -1135,13 +1129,13 @@ public final class IrisStructureLocator {
Set<String> normalizedLoadKeys = new LinkedHashSet<>();
Set<String> vanillaAliases = new LinkedHashSet<>();
Set<String> suppressedVanillaSources = new LinkedHashSet<>();
List<IrisStructurePlacement> placements = new ArrayList<>();
collect(engine.getDimension().getStructures(), data, log, loadKeys, normalizedLoadKeys, vanillaAliases,
List<StructurePlacement> placements = new ArrayList<>();
collect(StructurePlacementScope.placementsOf(engine.getDimension()), data, log, loadKeys, normalizedLoadKeys, vanillaAliases,
suppressedVanillaSources, placements, true);
KList<IrisRegion> regions = engine.getDimension().getAllRegions(engine);
if (regions != null) {
for (IrisRegion region : regions) {
collect(region == null ? null : region.getStructures(), data, log,
collect(StructurePlacementScope.placementsOf(region), data, log,
loadKeys, normalizedLoadKeys, vanillaAliases,
suppressedVanillaSources, placements, false);
}
@@ -1149,7 +1143,7 @@ public final class IrisStructureLocator {
KList<IrisBiome> biomes = engine.getDimension().getReachableBiomes(engine);
if (biomes != null) {
for (IrisBiome biome : biomes) {
collect(biome == null ? null : biome.getStructures(), data, log,
collect(StructurePlacementScope.placementsOf(biome), data, log,
loadKeys, normalizedLoadKeys, vanillaAliases,
suppressedVanillaSources, placements, false);
}
@@ -1163,48 +1157,42 @@ public final class IrisStructureLocator {
List.copyOf(placements));
}
private static Set<String> nativeKeys(List<IrisStructurePlacement> placements) {
private static Set<String> nativeKeys(List<StructurePlacement> placements) {
Set<String> nativeKeys = new LinkedHashSet<>();
for (IrisStructurePlacement placement : placements) {
for (StructurePlacement placement : placements) {
if (!placement.hasNativeStructures()) {
continue;
}
for (IrisNativeStructure source : placement.getNativeStructures()) {
for (NativeStructureSource source : placement.nativeStructures()) {
if (source != null) {
nativeKeys.add(normalize(source.getStructure()));
nativeKeys.add(normalize(source.structure()));
}
}
}
return Collections.unmodifiableSet(nativeKeys);
}
private static void collect(KList<IrisStructurePlacement> source, IrisData data, ModuleLog log, Set<String> loadKeys,
private static void collect(List<StructurePlacement> source, IrisData data, ModuleLog log, Set<String> loadKeys,
Set<String> normalizedLoadKeys, Set<String> vanillaAliases,
Set<String> suppressedVanillaSources,
List<IrisStructurePlacement> placements, boolean allowNativeSuppression) {
if (source == null) {
return;
}
for (IrisStructurePlacement placement : source) {
List<StructurePlacement> placements, boolean allowNativeSuppression) {
for (StructurePlacement placement : source) {
if (placement == null) {
throw new IllegalStateException("Iris structure placement list contains a null placement");
}
if (placement.getDistribution() == null) {
throw new IllegalStateException("Iris structure placement is missing its distribution");
}
NativeStartPlanner.validateBackend(placement);
boolean replacesNative = NativeStructureSuppression.REPLACE_SOURCE == placement.getNativeSuppression();
boolean replacesNative = NativeStructureSuppression.REPLACE_SOURCE == placement.nativeSuppression();
if (replacesNative && !allowNativeSuppression) {
throw new IllegalStateException("REPLACE_SOURCE is only valid on dimension-level structure placements");
}
if (placement.hasNativeStructures()) {
for (IrisNativeStructure nativeStructure : placement.getNativeStructures()) {
for (NativeStructureSource nativeStructure : placement.nativeStructures()) {
if (nativeStructure == null
|| nativeStructure.getStructure() == null
|| !NAMESPACED_RESOURCE_KEY.matcher(nativeStructure.getStructure()).matches()) {
|| nativeStructure.structure() == null
|| !NAMESPACED_RESOURCE_KEY.matcher(nativeStructure.structure()).matches()) {
throw new IllegalStateException("Native structure placement contains an invalid structure key");
}
String sourceKey = nativeStructure.getStructure();
String sourceKey = nativeStructure.structure();
loadKeys.add(sourceKey);
normalizedLoadKeys.add(normalize(sourceKey));
vanillaAliases.add(normalize(sourceKey));
@@ -1215,7 +1203,7 @@ public final class IrisStructureLocator {
placements.add(placement);
continue;
}
for (String structureKey : placement.getStructures()) {
for (String structureKey : placement.structures()) {
if (structureKey == null || structureKey.isBlank()) {
throw new IllegalStateException(replacesNative
? "REPLACE_SOURCE contains a blank Iris structure reference"
@@ -1254,7 +1242,7 @@ public final class IrisStructureLocator {
}
}
public record ResolvedPlacement(IrisStructurePlacement placement, String structureKey, IrisStructure structure,
public record ResolvedPlacement(StructurePlacement placement, String structureKey, IrisStructure structure,
KList<PlacedStructurePiece> pieces, RNG rng,
int originX, int baseY, int originZ, boolean exactY) {
}
@@ -1286,7 +1274,7 @@ public final class IrisStructureLocator {
}
private record PlacementCatalog(List<RandomSpreadParameters> randomSpread,
List<IrisStructurePlacement> concentricRings, boolean hasDensity) {
List<StructurePlacement> concentricRings, boolean hasDensity) {
}
private record LocatableIndex(Set<String> keys, Set<String> normalizedKeys,
@@ -1317,12 +1305,12 @@ public final class IrisStructureLocator {
private final Set<String> vanillaAliases;
private final Set<String> suppressedVanillaSources;
private final Set<String> nativeKeys;
private final List<IrisStructurePlacement> placements;
private final List<StructurePlacement> placements;
private PlacementIndex(Set<String> loadKeys, Set<String> normalizedLoadKeys,
Set<String> vanillaAliases, Set<String> suppressedVanillaSources,
Set<String> nativeKeys,
List<IrisStructurePlacement> placements) {
List<StructurePlacement> placements) {
this.loadKeys = loadKeys;
this.normalizedLoadKeys = normalizedLoadKeys;
this.vanillaAliases = vanillaAliases;
@@ -1,8 +1,8 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.builtin.structure.StructureAnchorMode;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.matter.MatterCavern;
@@ -23,26 +23,26 @@ public final class StructureCaveAnchorResolver {
private StructureCaveAnchorResolver() {
}
public static Anchor resolve(Engine engine, IrisStructurePlacement placement, int chunkX, int chunkZ, RNG rng) {
public static Anchor resolve(Engine engine, StructurePlacement placement, int chunkX, int chunkZ, RNG rng) {
Objects.requireNonNull(engine, "Cave structure anchor requires an engine");
Objects.requireNonNull(placement, "Cave structure anchor requires a placement");
Objects.requireNonNull(rng, "Cave structure anchor requires a random source");
IrisStructureAnchorMode mode = placement.resolvedAnchor();
StructureAnchorMode mode = placement.resolvedAnchor();
if (!mode.isCave() || engine.getMantle() == null || engine.getMantle().getMantle() == null) {
return null;
}
int worldMin = engine.getMinHeight() + 1;
int worldMax = engine.getMinHeight() + engine.getHeight() - 2;
int minimumY = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight()));
int maximumY = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight()));
int minimumY = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
int maximumY = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight()));
if (minimumY > maximumY) {
return null;
}
int attempts = Math.min(MAX_ATTEMPTS, Math.max(1, placement.getCaveAnchorAttempts()));
int scanStep = Math.min(MAX_SCAN_STEP, Math.max(1, placement.getCaveAnchorScanStep()));
int clearance = Math.min(MAX_CLEARANCE, Math.max(1, placement.getCaveMinimumClearance()));
int attempts = Math.min(MAX_ATTEMPTS, Math.max(1, placement.caveAnchorAttempts()));
int scanStep = Math.min(MAX_SCAN_STEP, Math.max(1, placement.caveAnchorScanStep()));
int clearance = Math.min(MAX_CLEARANCE, Math.max(1, placement.caveMinimumClearance()));
int chunkMinX = chunkX << 4;
int chunkMinZ = chunkZ << 4;
int[] candidateColumns = candidateColumnIndices(rng, attempts);
@@ -73,8 +73,8 @@ public final class StructureCaveAnchorResolver {
static List<Integer> anchorsInColumn(
Engine engine,
IrisStructurePlacement placement,
IrisStructureAnchorMode mode,
StructurePlacement placement,
StructureAnchorMode mode,
int blockX,
int blockZ,
int minimumY,
@@ -82,7 +82,7 @@ public final class StructureCaveAnchorResolver {
int scanStep,
int clearance
) {
if (mode == IrisStructureAnchorMode.CAVE_CENTER) {
if (mode == StructureAnchorMode.CAVE_CENTER) {
return centerAnchorsInColumn(
engine, placement, blockX, blockZ,
minimumY, maximumY, scanStep, clearance);
@@ -107,7 +107,7 @@ public final class StructureCaveAnchorResolver {
private static List<Integer> centerAnchorsInColumn(
Engine engine,
IrisStructurePlacement placement,
StructurePlacement placement,
int blockX,
int blockZ,
int minimumY,
@@ -153,7 +153,7 @@ public final class StructureCaveAnchorResolver {
private static void addCenterAnchor(
List<Integer> anchors,
Engine engine,
IrisStructurePlacement placement,
StructurePlacement placement,
int blockX,
int blockZ,
int worldY,
@@ -172,14 +172,14 @@ public final class StructureCaveAnchorResolver {
static boolean matchesGeometry(
Engine engine,
IrisStructureAnchorMode mode,
StructureAnchorMode mode,
int blockX,
int mantleY,
int blockZ,
int clearance
) {
IntPredicate carved = y -> isCarved(engine, blockX, y, blockZ);
if (mode == IrisStructureAnchorMode.CAVE_CENTER) {
if (mode == StructureAnchorMode.CAVE_CENTER) {
return matchesCenterGeometry(
carved, mantleY, Math.max(1, clearance), 0, engine.getHeight() - 1);
}
@@ -188,7 +188,7 @@ public final class StructureCaveAnchorResolver {
static boolean matchesGeometry(
IntPredicate carved,
IrisStructureAnchorMode mode,
StructureAnchorMode mode,
int mantleY,
int clearance
) {
@@ -281,14 +281,14 @@ public final class StructureCaveAnchorResolver {
private static boolean matchesAnchorFluid(
Engine engine,
IrisStructurePlacement placement,
StructurePlacement placement,
int blockX,
int mantleY,
int blockZ
) {
MatterCavern cavern = cavernAt(engine, blockX, mantleY, blockZ);
return acceptsAnchorFluid(
placement.isUnderwater(),
placement.underwater(),
cavern,
mantleY,
engine.getDimension().getCaveLavaHeight());
@@ -322,12 +322,12 @@ public final class StructureCaveAnchorResolver {
private static boolean matchesBiome(
Engine engine,
IrisStructurePlacement placement,
StructurePlacement placement,
int blockX,
int mantleY,
int blockZ
) {
if (placement.getCaveBiomes() == null || placement.getCaveBiomes().isEmpty()) {
if (placement.caveBiomes().isEmpty()) {
return true;
}
IrisBiome biome = engine.getCaveOrMantleBiome(blockX, mantleY, blockZ);
@@ -335,7 +335,7 @@ public final class StructureCaveAnchorResolver {
return false;
}
String actual = biome.getLoadKey().toLowerCase(Locale.ROOT);
for (String allowed : placement.getCaveBiomes()) {
for (String allowed : placement.caveBiomes()) {
if (matchesBiomeKey(actual, allowed)) {
return true;
}
@@ -18,9 +18,9 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.builtin.structure.NativeStructureSource;
import art.arcane.iris.builtin.structure.StructureAnchorMode;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.volmlib.util.math.RNG;
import java.util.Locale;
@@ -33,16 +33,16 @@ public final class StructurePlacementGrid {
private StructurePlacementGrid() {
}
public static boolean startsInChunk(IrisStructurePlacement placement, int cx, int cz, long seed) {
return switch (placement.getDistribution()) {
case RANDOM_SPREAD -> randomSpreadStart(cx, cz, placement.getSpacing(), placement.getSeparation(),
public static boolean startsInChunk(StructurePlacement placement, int cx, int cz, long seed) {
return switch (placement.distribution()) {
case RANDOM_SPREAD -> randomSpreadStart(cx, cz, placement.spacing(), placement.separation(),
placementSalt(placement), seed);
case DENSITY -> densityStart(placement, cx, cz, seed);
case CONCENTRIC_RINGS -> concentricRingsStart(cx, cz, placement, seed);
};
}
public static RNG placementRng(IrisStructurePlacement placement, int cx, int cz, long seed) {
public static RNG placementRng(StructurePlacement placement, int cx, int cz, long seed) {
return new RNG(placementSeed(placement, cx, cz, seed));
}
@@ -69,13 +69,13 @@ public final class StructurePlacementGrid {
return new int[]{startCx, startCz};
}
public static int[] concentricRingChunk(IrisStructurePlacement placement, int placementIndex, long seed) {
int count = Math.max(1, placement.getRingCount());
public static int[] concentricRingChunk(StructurePlacement placement, int placementIndex, long seed) {
int count = Math.max(1, placement.ringCount());
if (placementIndex < 0 || placementIndex >= count) {
return null;
}
int distance = Math.max(1, placement.getRingDistance());
int spread = Math.max(1, placement.getRingSpread());
int distance = Math.max(1, placement.ringDistance());
int spread = Math.max(1, placement.ringSpread());
int ring = Math.floorDiv(placementIndex, spread) + 1;
int firstIndex = (ring - 1) * spread;
int slots = Math.min(spread, count - firstIndex);
@@ -94,13 +94,13 @@ public final class StructurePlacementGrid {
};
}
private static boolean concentricRingsStart(int cx, int cz, IrisStructurePlacement placement, long seed) {
private static boolean concentricRingsStart(int cx, int cz, StructurePlacement placement, long seed) {
if (cx == 0 && cz == 0) {
return false;
}
int distance = Math.max(1, placement.getRingDistance());
int count = Math.max(1, placement.getRingCount());
int spread = Math.max(1, placement.getRingSpread());
int distance = Math.max(1, placement.ringDistance());
int count = Math.max(1, placement.ringCount());
int spread = Math.max(1, placement.ringSpread());
double dist = Math.sqrt((double) cx * cx + (double) cz * cz);
int estimatedRing = (int) Math.round(dist / distance);
int ringCount = Math.ceilDiv(count, spread);
@@ -127,8 +127,8 @@ public final class StructurePlacementGrid {
return false;
}
private static boolean densityStart(IrisStructurePlacement placement, int cx, int cz, long seed) {
double density = placement.getDensity();
private static boolean densityStart(StructurePlacement placement, int cx, int cz, long seed) {
double density = placement.density();
if (density <= 0.0) {
return false;
}
@@ -139,33 +139,33 @@ public final class StructurePlacementGrid {
return rng.chance(density);
}
public static long placementIdentity(IrisStructurePlacement placement) {
public static long placementIdentity(StructurePlacement placement) {
long signature = 1469598103934665603L;
signature = appendLong(signature, placement.getDistribution().ordinal());
signature = appendLong(signature, placement.getSalt());
String placementId = placement.getPlacementId();
signature = appendLong(signature, placement.distribution().ordinal());
signature = appendLong(signature, placement.salt());
String placementId = placement.placementId();
if (placementId != null && !placementId.isBlank()) {
signature = appendLong(signature, 1L);
signature = appendSignature(signature, placementId.trim());
} else {
signature = appendLong(signature, 0L);
signature = appendLong(signature, placement.getSpacing());
signature = appendLong(signature, placement.getSeparation());
signature = appendLong(signature, Double.doubleToLongBits(placement.getDensity()));
signature = appendLong(signature, placement.getRingCount());
signature = appendLong(signature, placement.getRingDistance());
signature = appendLong(signature, placement.getRingSpread());
signature = appendLong(signature, placement.getMinHeight());
signature = appendLong(signature, placement.getMaxHeight());
signature = appendLong(signature, placement.isUnderground() ? 1L : 0L);
signature = appendLong(signature, placement.isUnderwater() ? 1L : 0L);
signature = appendLong(signature, placement.spacing());
signature = appendLong(signature, placement.separation());
signature = appendLong(signature, Double.doubleToLongBits(placement.density()));
signature = appendLong(signature, placement.ringCount());
signature = appendLong(signature, placement.ringDistance());
signature = appendLong(signature, placement.ringSpread());
signature = appendLong(signature, placement.minHeight());
signature = appendLong(signature, placement.maxHeight());
signature = appendLong(signature, placement.underground() ? 1L : 0L);
signature = appendLong(signature, placement.underwater() ? 1L : 0L);
signature = appendSources(signature, placement);
signature = appendAnchor(signature, placement);
}
return signature;
}
private static long placementSeed(IrisStructurePlacement placement, int cx, int cz, long seed) {
private static long placementSeed(StructurePlacement placement, int cx, int cz, long seed) {
long signature = placementIdentity(placement);
int identitySalt = (int) (signature ^ (signature >>> 32));
return mix(seed ^ signature, cx, cz, placementSalt(placement) ^ identitySalt);
@@ -189,37 +189,34 @@ public final class StructurePlacementGrid {
return result;
}
private static long appendSources(long signature, IrisStructurePlacement placement) {
private static long appendSources(long signature, StructurePlacement placement) {
long result = signature;
if (placement.hasIrisStructures()) {
result = appendLong(result, 1L);
result = appendLong(result, placement.getStructures().size());
for (String key : placement.getStructures()) {
result = appendLong(result, placement.structures().size());
for (String key : placement.structures()) {
result = appendSignature(result, key == null ? "" : key);
}
return result;
}
result = appendLong(result, 2L);
if (placement.getNativeStructures() == null) {
return appendLong(result, 0L);
}
result = appendLong(result, placement.getNativeStructures().size());
for (IrisNativeStructure source : placement.getNativeStructures()) {
result = appendLong(result, placement.nativeStructures().size());
for (NativeStructureSource source : placement.nativeStructures()) {
if (source == null) {
result = appendSignature(result, "");
result = appendLong(result, 0L);
continue;
}
result = appendSignature(result,
source.getStructure() == null ? "" : source.getStructure());
result = appendLong(result, source.getWeight());
source.structure() == null ? "" : source.structure());
result = appendLong(result, source.weight());
}
return result;
}
private static long appendAnchor(long signature, IrisStructurePlacement placement) {
IrisStructureAnchorMode anchor = placement.getAnchor();
if (anchor == null || anchor == IrisStructureAnchorMode.LEGACY) {
private static long appendAnchor(long signature, StructurePlacement placement) {
StructureAnchorMode anchor = placement.anchor();
if (anchor == StructureAnchorMode.LEGACY) {
return signature;
}
long result = appendLong(signature, 0x4A49475341574C41L);
@@ -227,14 +224,11 @@ public final class StructurePlacementGrid {
if (!anchor.isCave()) {
return result;
}
result = appendLong(result, placement.getCaveAnchorAttempts());
result = appendLong(result, placement.getCaveAnchorScanStep());
result = appendLong(result, placement.getCaveMinimumClearance());
if (placement.getCaveBiomes() == null) {
return appendLong(result, 0L);
}
result = appendLong(result, placement.caveAnchorAttempts());
result = appendLong(result, placement.caveAnchorScanStep());
result = appendLong(result, placement.caveMinimumClearance());
Set<String> biomes = new TreeSet<>();
for (String biome : placement.getCaveBiomes()) {
for (String biome : placement.caveBiomes()) {
if (biome != null && !biome.isBlank()) {
biomes.add(biome.trim().toLowerCase(Locale.ROOT));
}
@@ -246,28 +240,28 @@ public final class StructurePlacementGrid {
return result;
}
static int placementSalt(IrisStructurePlacement placement) {
String placementId = placement.getPlacementId();
static int placementSalt(StructurePlacement placement) {
String placementId = placement.placementId();
long identity;
if (placementId != null && !placementId.isBlank()) {
identity = appendSignature(1469598103934665603L, placementId.trim());
} else {
identity = 1469598103934665603L;
identity = appendLong(identity, placement.getDistribution().ordinal());
identity = appendLong(identity, placement.getSpacing());
identity = appendLong(identity, placement.getSeparation());
identity = appendLong(identity, Double.doubleToLongBits(placement.getDensity()));
identity = appendLong(identity, placement.getRingCount());
identity = appendLong(identity, placement.getRingDistance());
identity = appendLong(identity, placement.getRingSpread());
identity = appendLong(identity, placement.getMinHeight());
identity = appendLong(identity, placement.getMaxHeight());
identity = appendLong(identity, placement.isUnderground() ? 1L : 0L);
identity = appendLong(identity, placement.isUnderwater() ? 1L : 0L);
identity = appendLong(identity, placement.distribution().ordinal());
identity = appendLong(identity, placement.spacing());
identity = appendLong(identity, placement.separation());
identity = appendLong(identity, Double.doubleToLongBits(placement.density()));
identity = appendLong(identity, placement.ringCount());
identity = appendLong(identity, placement.ringDistance());
identity = appendLong(identity, placement.ringSpread());
identity = appendLong(identity, placement.minHeight());
identity = appendLong(identity, placement.maxHeight());
identity = appendLong(identity, placement.underground() ? 1L : 0L);
identity = appendLong(identity, placement.underwater() ? 1L : 0L);
identity = appendSources(identity, placement);
identity = appendAnchor(identity, placement);
}
return placement.getSalt() ^ (int) (identity ^ (identity >>> 32));
return placement.salt() ^ (int) (identity ^ (identity >>> 32));
}
private static double unitDouble(long value) {
@@ -1,75 +1,68 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.iris.builtin.structure.StructurePlacementSettings;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.volmlib.util.collection.KList;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* The structure placements that apply at a chunk: its biome's, its cave biome's cave-anchored ones, its region's and
* the dimension's. Each world keeps which of those levels declare placements at all, so chunks skip the biome and
* region lookups a pack never needs.
*/
public final class StructurePlacementScope {
private static final List<CachedScopeIndex> SCOPE_INDEXES = new ArrayList<>();
private StructurePlacementScope() {
}
public static KList<IrisStructurePlacement> placementsAt(Engine engine, int chunkX, int chunkZ) {
/** The placements {@code owner} declares in its {@code "structures"} settings; empty for none. */
public static List<StructurePlacement> placementsOf(IrisRegistrant owner) {
if (owner == null) {
return List.of();
}
return owner.getModuleSettings().find(StructurePlacementSettings.class)
.map(StructurePlacementSettings::placements)
.orElse(List.of());
}
public static KList<StructurePlacement> placementsAt(Engine engine, int chunkX, int chunkZ) {
Engine activeEngine = Objects.requireNonNull(engine, "Structure placement scope requires an engine");
IrisComplex complex = activeEngine.getComplex();
int blockX = (chunkX << 4) + 8;
int blockZ = (chunkZ << 4) + 8;
KList<IrisStructurePlacement> placements = new KList<>();
Set<IrisStructurePlacement> seen = Collections.newSetFromMap(new IdentityHashMap<>());
KList<StructurePlacement> placements = new KList<>();
Set<StructurePlacement> seen = Collections.newSetFromMap(new IdentityHashMap<>());
ScopeIndex index = scopeIndex(activeEngine);
if (complex != null) {
if (index.biome()) {
IrisBiome biome = complex.getTrueBiomeStream().get(blockX, blockZ);
addUnique(placements, seen, biome == null ? null : biome.getStructures());
addUnique(placements, seen, placementsOf(biome));
}
if (index.caveBiome()) {
IrisBiome caveBiome = complex.getCaveBiomeStream().get(blockX, blockZ);
addCaveUnique(placements, seen, caveBiome == null ? null : caveBiome.getStructures());
addCaveUnique(placements, seen, placementsOf(caveBiome));
}
if (index.region()) {
IrisRegion region = complex.getRegionStream().get(blockX, blockZ);
addUnique(placements, seen, region == null ? null : region.getStructures());
addUnique(placements, seen, placementsOf(region));
}
}
if (index.dimension()) {
addUnique(placements, seen, activeEngine.getDimension().getStructures());
addUnique(placements, seen, placementsOf(activeEngine.getDimension()));
}
return placements;
}
private static ScopeIndex scopeIndex(Engine engine) {
int revision = engine.getCacheID();
synchronized (SCOPE_INDEXES) {
for (int i = SCOPE_INDEXES.size() - 1; i >= 0; i--) {
CachedScopeIndex cached = SCOPE_INDEXES.get(i);
Engine indexedEngine = cached.engine().get();
if (indexedEngine == null) {
SCOPE_INDEXES.remove(i);
continue;
}
if (indexedEngine == engine) {
if (cached.revision() == revision) {
return cached.index();
}
SCOPE_INDEXES.remove(i);
break;
}
}
ScopeIndex index = buildScopeIndex(engine);
SCOPE_INDEXES.add(new CachedScopeIndex(new WeakReference<>(engine), revision, index));
return index;
}
return engine.getGeneration().state(ScopeIndex.class, StructurePlacementScope::buildScopeIndex);
}
private static ScopeIndex buildScopeIndex(Engine engine) {
@@ -81,68 +74,42 @@ public final class StructurePlacementScope {
caveBiome = true;
} else {
for (IrisBiome candidate : allBiomes) {
KList<IrisStructurePlacement> structures = candidate.getStructures();
if (structures == null || structures.isEmpty()) {
List<StructurePlacement> structures = placementsOf(candidate);
if (structures.isEmpty()) {
continue;
}
biome = true;
for (IrisStructurePlacement placement : structures) {
if (placement != null && placement.resolvedAnchor().isCave()) {
caveBiome = true;
break;
}
}
caveBiome |= structures.stream().anyMatch(placement -> placement.resolvedAnchor().isCave());
}
}
boolean region = false;
if (engine.getDimension() != null) {
KList<IrisRegion> allRegions = engine.getDimension().getAllRegions(engine);
if (allRegions == null) {
region = true;
} else {
for (IrisRegion candidate : allRegions) {
if (candidate.getStructures() != null && !candidate.getStructures().isEmpty()) {
region = true;
break;
}
}
}
region = allRegions == null
|| allRegions.stream().anyMatch(candidate -> !placementsOf(candidate).isEmpty());
}
boolean dimension = engine.getDimension() != null
&& engine.getDimension().getStructures() != null
&& !engine.getDimension().getStructures().isEmpty();
boolean dimension = !placementsOf(engine.getDimension()).isEmpty();
return new ScopeIndex(biome, caveBiome, region, dimension);
}
private static void addUnique(KList<IrisStructurePlacement> destination,
Set<IrisStructurePlacement> seen,
KList<IrisStructurePlacement> source) {
if (source == null) {
return;
}
for (IrisStructurePlacement placement : source) {
private static void addUnique(KList<StructurePlacement> destination, Set<StructurePlacement> seen,
List<StructurePlacement> source) {
for (StructurePlacement placement : source) {
if (placement != null && seen.add(placement)) {
destination.add(placement);
}
}
}
private static void addCaveUnique(KList<IrisStructurePlacement> destination,
Set<IrisStructurePlacement> seen,
KList<IrisStructurePlacement> source) {
if (source == null) {
return;
}
for (IrisStructurePlacement placement : source) {
private static void addCaveUnique(KList<StructurePlacement> destination, Set<StructurePlacement> seen,
List<StructurePlacement> source) {
for (StructurePlacement placement : source) {
if (placement != null && placement.resolvedAnchor().isCave() && seen.add(placement)) {
destination.add(placement);
}
}
}
private record CachedScopeIndex(WeakReference<Engine> engine, int revision, ScopeIndex index) {
}
private record ScopeIndex(boolean biome, boolean caveBiome, boolean region, boolean dimension) {
}
}
@@ -21,10 +21,9 @@ package art.arcane.iris.engine.framework.structure;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.StructurePlacementGrid;
import art.arcane.iris.engine.framework.StructurePlacementScope;
import art.arcane.iris.engine.object.structure.IrisStructureAnchorMode;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.iris.builtin.structure.StructureAnchorMode;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.iris.builtin.structure.NativeStructureSource;
import art.arcane.volmlib.util.math.RNG;
import java.util.LinkedHashMap;
@@ -46,17 +45,17 @@ public final class NativeStartPlanner {
}
/** One start a {@code nativeStructures} placement makes: the placement, its chosen source and world base Y. */
public record Plan(IrisStructurePlacement placement, IrisNativeStructure source, int chunkX, int chunkZ, int baseY) {
public record Plan(StructurePlacement placement, NativeStructureSource source, int chunkX, int chunkZ, int baseY) {
}
public static List<Plan> plansAt(Engine engine, int chunkX, int chunkZ) {
Map<String, Plan> plansByStructure = new LinkedHashMap<>();
for (IrisStructurePlacement placement : StructurePlacementScope.placementsAt(engine, chunkX, chunkZ)) {
for (StructurePlacement placement : StructurePlacementScope.placementsAt(engine, chunkX, chunkZ)) {
Plan plan = planAt(engine, placement, chunkX, chunkZ);
if (plan == null) {
continue;
}
String structureKey = normalize(plan.source().getStructure());
String structureKey = normalize(plan.source().structure());
Plan current = plansByStructure.get(structureKey);
if (current == null || comparePlacementPriority(plan.placement(), current.placement()) < 0) {
plansByStructure.put(structureKey, plan);
@@ -65,7 +64,7 @@ public final class NativeStartPlanner {
return List.copyOf(plansByStructure.values());
}
public static Plan planAt(Engine engine, IrisStructurePlacement placement, int chunkX, int chunkZ) {
public static Plan planAt(Engine engine, StructurePlacement placement, int chunkX, int chunkZ) {
validateBackend(placement);
if (!placement.hasNativeStructures()) {
return null;
@@ -80,7 +79,7 @@ public final class NativeStartPlanner {
}
RNG placementRng = StructurePlacementGrid.placementRng(
placement, chunkX, chunkZ, mantleSeed).nextParallelRNG(NATIVE_SELECTION_DOMAIN);
IrisNativeStructure source = selectSource(placement.getNativeStructures(), placementRng);
NativeStructureSource source = selectSource(placement.nativeStructures(), placementRng);
Integer baseY = resolveBaseY(activeEngine, placement, chunkX, chunkZ, placementRng);
if (baseY == null) {
return null;
@@ -88,7 +87,7 @@ public final class NativeStartPlanner {
return new Plan(placement, source, chunkX, chunkZ, baseY);
}
public static void validateBackend(IrisStructurePlacement placement) {
public static void validateBackend(StructurePlacement placement) {
if (placement == null) {
throw new IllegalStateException("Structure placement must not be null");
}
@@ -98,8 +97,7 @@ public final class NativeStartPlanner {
throw new IllegalStateException("Structure placement must declare exactly one backend: "
+ "structures or nativeStructures");
}
if (nativeStructure && placement.getAnchor() != null
&& placement.getAnchor() != IrisStructureAnchorMode.LEGACY) {
if (nativeStructure && placement.anchor() != StructureAnchorMode.LEGACY) {
throw new IllegalStateException("Native structure placements do not support the Iris anchor field");
}
}
@@ -108,26 +106,26 @@ public final class NativeStartPlanner {
return engine.getHeight(blockX, blockZ, true) < engine.getDimension().getFluidHeight();
}
static IrisNativeStructure selectSource(KList<IrisNativeStructure> sources, RNG rng) {
static NativeStructureSource selectSource(List<NativeStructureSource> sources, RNG rng) {
Objects.requireNonNull(sources, "Native structure sources must not be null");
Objects.requireNonNull(rng, "Native structure selection requires an RNG");
long totalWeight = 0L;
for (IrisNativeStructure source : sources) {
if (source == null || source.getStructure() == null || source.getStructure().isBlank()) {
for (NativeStructureSource source : sources) {
if (source == null || source.structure() == null || source.structure().isBlank()) {
throw new IllegalStateException("Native structure placement contains a blank source");
}
if (source.getWeight() < 1) {
throw new IllegalStateException("Native structure source '" + source.getStructure()
+ "' has invalid weight " + source.getWeight());
if (source.weight() < 1) {
throw new IllegalStateException("Native structure source '" + source.structure()
+ "' has invalid weight " + source.weight());
}
totalWeight = Math.addExact(totalWeight, source.getWeight());
totalWeight = Math.addExact(totalWeight, source.weight());
}
if (totalWeight > Integer.MAX_VALUE) {
throw new IllegalStateException("Native structure source weights exceed " + Integer.MAX_VALUE);
}
int roll = rng.nextInt((int) totalWeight);
for (IrisNativeStructure source : sources) {
roll -= source.getWeight();
for (NativeStructureSource source : sources) {
roll -= source.weight();
if (roll < 0) {
return source;
}
@@ -135,7 +133,7 @@ public final class NativeStartPlanner {
throw new IllegalStateException("Native structure source selection produced no result");
}
private static Integer resolveBaseY(Engine engine, IrisStructurePlacement placement,
private static Integer resolveBaseY(Engine engine, StructurePlacement placement,
int chunkX, int chunkZ, RNG rng) {
int worldMin = engine.getMinHeight() + 1;
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
@@ -144,25 +142,25 @@ public final class NativeStartPlanner {
}
int blockX = (chunkX << 4) + 8;
int blockZ = (chunkZ << 4) + 8;
if (!placement.isUnderwater() && isSubmerged(engine, blockX, blockZ)) {
if (!placement.underwater() && isSubmerged(engine, blockX, blockZ)) {
return null;
}
if (!placement.isUnderground()) {
if (!placement.underground()) {
int surfaceY = engine.getHeight(blockX, blockZ, true) + engine.getMinHeight();
if (surfaceY < placement.getMinHeight() || surfaceY > placement.getMaxHeight()) {
if (surfaceY < placement.minHeight() || surfaceY > placement.maxHeight()) {
return null;
}
return surfaceY;
}
int bandMin = Math.max(worldMin, Math.min(placement.getMinHeight(), placement.getMaxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.getMinHeight(), placement.getMaxHeight()));
int bandMin = Math.max(worldMin, Math.min(placement.minHeight(), placement.maxHeight()));
int bandMax = Math.min(worldMax, Math.max(placement.minHeight(), placement.maxHeight()));
if (bandMin > bandMax) {
return null;
}
return bandMin == bandMax ? bandMin : bandMin + rng.nextInt((bandMax - bandMin) + 1);
}
private static int comparePlacementPriority(IrisStructurePlacement left, IrisStructurePlacement right) {
private static int comparePlacementPriority(StructurePlacement left, StructurePlacement right) {
long leftIdentity = StructurePlacementGrid.placementIdentity(left);
long rightIdentity = StructurePlacementGrid.placementIdentity(right);
return Long.compareUnsigned(leftIdentity, rightIdentity);
@@ -25,8 +25,8 @@ import art.arcane.iris.engine.framework.IrisStructureLocator;
import art.arcane.iris.engine.framework.StructurePlacementGrid;
import art.arcane.iris.engine.framework.structure.fit.StartLayouts;
import art.arcane.iris.engine.framework.structure.fit.StructureFitting;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.iris.builtin.structure.NativeStructureSuppression;
import com.volmit.resource.ResourceId;
import com.volmit.service.LocateResult;
import com.volmit.service.VanillaStructures;
@@ -148,21 +148,18 @@ public final class StructureVanillaStructures implements VanillaStructures {
/** {@code plan} as the start the platform generates: heights above the bottom, the placement's identity and fit. */
static VanillaStructureStart start(NativeStartPlanner.Plan plan, int minHeight) {
IrisStructurePlacement placement = plan.placement();
NativeStructureFit fit = new NativeStructureFit(0, null, false, placement.getStilt(), placement.resolvedTerrain());
VanillaStructureStart start = VanillaStructureStart.at(ResourceId.parse(plan.source().getStructure()),
StructurePlacement placement = plan.placement();
NativeStructureFit fit = new NativeStructureFit(0, null, false, placement.stilt().orElse(null), placement.resolvedTerrain());
VanillaStructureStart start = VanillaStructureStart.at(ResourceId.parse(plan.source().structure()),
plan.chunkX(), plan.chunkZ(), plan.baseY() - minHeight)
.withIdentity(StructurePlacementGrid.placementIdentity(placement))
.withMemo(fit.memo());
if (placement.isUnderground()) {
if (placement.underground()) {
start = start.underground();
}
if (placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE) {
if (placement.nativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE) {
start = start.replacingPlatformStart();
}
if (plan.source().getJigsaw() != null) {
start = start.withJigsaw(plan.source().getJigsaw());
}
return start;
return plan.source().jigsaw().map(start::withJigsaw).orElse(start);
}
}
@@ -19,9 +19,8 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.structure.StructurePlacementSettings;
import art.arcane.iris.builtin.structure.StructureSettings;
import art.arcane.iris.builtin.structure.StructureStilts;
import art.arcane.iris.builtin.structure.StructureTerrain;
import art.arcane.iris.core.modules.IrisMantleChunk;
import art.arcane.iris.core.modules.IrisPackSettings;
import art.arcane.iris.engine.framework.Engine;
@@ -38,7 +37,6 @@ import com.volmit.service.StructureLocator;
import com.volmit.service.VanillaStructures;
import com.volmit.stage.MantleStageContext;
import com.volmit.stage.StageGraph;
import com.volmit.vanilla.JigsawOverrides;
/**
* Module {@code iris:structure}: Iris structures, written into the mantle after objects, whose trees they clear
@@ -54,8 +52,8 @@ import com.volmit.vanilla.JigsawOverrides;
* It decides over the platform's own structures through its {@link VanillaStructures} provider
* ({@link StructureVanillaStructures}): the dimension's {@code importedStructures} settings disable, move, fit and set
* them up, and the pack's structure placements replace them, place them alongside, start them where their
* {@code nativeStructures} grids say and fit them into the terrain. It describes the fit settings Iris's structure
* placements hold.
* {@code nativeStructures} grids say and fit them into the terrain. The pack's structure placements are its
* {@code "structures"} settings ({@link StructurePlacementSettings}) of the dimension, its regions and biomes.
*/
public final class StructureModule implements IrisModule {
private static final String VERSION = "built-in";
@@ -77,13 +75,11 @@ public final class StructureModule implements IrisModule {
public void register(FeatureRegistry registry) {
log = registry.log();
registry.registerSettings(StructureSettings.class);
registry.registerSettings(StructurePlacementSettings.class);
StructureResources.kinds().forEach(registry::registerResourceKind);
registry.registerValidator(new StructureValidator());
registry.registerService(StructureLocator.class, new StructureLocating());
registry.registerService(VanillaStructures.class, new StructureVanillaStructures());
registry.registerHeldType(StructureTerrain.class);
registry.registerHeldType(StructureStilts.class);
registry.registerHeldType(JigsawOverrides.class);
}
private static void place(MantleStageContext context) {
@@ -37,7 +37,7 @@ import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.structure.IrisStructure;
import art.arcane.iris.builtin.structure.StructureCarveShape;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.builtin.structure.StructurePlacement;
import art.arcane.iris.builtin.structure.StructureStilts;
import com.volmit.ModuleLog;
import com.volmit.block.PaletteSampler;
@@ -61,6 +61,7 @@ import it.unimi.dsi.fastutil.longs.Long2IntMap;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -82,7 +83,7 @@ public class StructurePlacing {
/** Places what originates in the chunk at chunk coordinates {@code x}, {@code z} into {@code writer}. */
@ChunkCoordinates
public void place(MantleWriter writer, int x, int z, ChunkContext context) {
for (IrisStructurePlacement placement : StructurePlacementScope.placementsAt(
for (StructurePlacement placement : StructurePlacementScope.placementsAt(
engine, x, z)) {
if (!placement.hasIrisStructures()) {
continue;
@@ -92,7 +93,7 @@ public class StructurePlacing {
}
@ChunkCoordinates
private void placeFromPlacement(MantleWriter writer, IrisStructurePlacement placement, int cx, int cz) {
private void placeFromPlacement(MantleWriter writer, StructurePlacement placement, int cx, int cz) {
IrisStructureLocator.ResolvedPlacement resolved = IrisStructureLocator.resolvePlacement(
engine, placement, cx, cz);
if (resolved == null) {
@@ -101,8 +102,8 @@ public class StructurePlacing {
boolean trace = IrisSettings.get().getGeneral().isDebug();
if (trace) {
log.debug("[StructTrace] ORIGIN chunk=" + cx + "," + cz + " structures=" + placement.getStructures()
+ " anchor=" + placement.resolvedAnchor() + " band=" + placement.getMinHeight() + ".." + placement.getMaxHeight());
log.debug("[StructTrace] ORIGIN chunk=" + cx + "," + cz + " structures=" + placement.structures()
+ " anchor=" + placement.resolvedAnchor() + " band=" + placement.minHeight() + ".." + placement.maxHeight());
}
String key = resolved.structureKey();
@@ -135,7 +136,7 @@ public class StructurePlacing {
ObjectPlaceMode mode = structure.getPlaceMode();
int failedPieces = 0;
StructureStilts stilt = placement.getStilt();
StructureStilts stilt = placement.stilt().orElse(null);
Long2IntOpenHashMap foundationColumns = stilt == null
? null : new Long2IntOpenHashMap();
boolean supportNonOccluding = stilt != null && stilt.supportNonOccluding();
@@ -590,19 +591,19 @@ public class StructurePlacing {
int maxBlocks = 0;
for (IrisRegion region : dimension.getAllRegions(engine)) {
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(region.getStructures()));
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(region)));
}
for (IrisBiome biome : dimension.getReachableBiomes(engine)) {
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(biome.getStructures()));
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(biome)));
}
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(dimension.getStructures()));
maxBlocks = Math.max(maxBlocks, maxBlocksFrom(StructurePlacementScope.placementsOf(dimension)));
return maxBlocks;
}
private int maxBlocksFrom(KList<IrisStructurePlacement> placements) {
private int maxBlocksFrom(List<StructurePlacement> placements) {
int max = 0;
for (IrisStructurePlacement placement : placements) {
for (StructurePlacement placement : placements) {
if (!placement.hasIrisStructures()) {
continue;
}
@@ -610,7 +611,7 @@ public class StructurePlacing {
int carvePadding = terrain.resolvedMode() == StructureTerrainMode.FORCE_CARVE
|| terrain.resolvedMode() == StructureTerrainMode.BORE
? Math.max(0, terrain.horizontalPadding()) : 0;
for (String key : placement.getStructures()) {
for (String key : placement.structures()) {
IrisStructure structure = StructureResources.structure(engine.getData(), key);
if (structure != null) {
max = Math.max(max, Math.max(1, structure.getMaxSizeChunks()) * 16 + carvePadding);
@@ -1,34 +0,0 @@
package art.arcane.iris.engine.object.structure;
import art.arcane.iris.engine.object.annotations.Desc;
@Desc("Selects the vertical environment used to anchor an Iris structure placement.")
public enum IrisStructureAnchorMode {
@Desc("Preserve the historical underground boolean behavior.")
LEGACY,
@Desc("Anchor to the terrain surface and use minHeight/maxHeight as a surface gate.")
SURFACE,
@Desc("Choose a deterministic Y inside the minHeight/maxHeight band.")
HEIGHT_BAND,
@Desc("Anchor in carved space with solid support below.")
CAVE_FLOOR,
@Desc("Anchor in carved space with solid support above.")
CAVE_CEILING,
@Desc("Anchor in carved space without nearby floor or ceiling support.")
CAVE_CENTER,
@Desc("Anchor at any carved-space position.")
CAVE_ANY;
public boolean isCave() {
return switch (this) {
case CAVE_FLOOR, CAVE_CEILING, CAVE_CENTER, CAVE_ANY -> true;
default -> false;
};
}
}
@@ -1,30 +0,0 @@
package art.arcane.iris.engine.object.structure.vanilla;
import art.arcane.iris.engine.object.annotations.Desc;
import art.arcane.iris.engine.object.annotations.MinNumber;
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure;
import art.arcane.iris.engine.object.annotations.Required;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import com.volmit.vanilla.JigsawOverrides;
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Data
@Desc("A live vanilla, datapack, or modded structure generated by Minecraft at an Iris-controlled placement.")
public class IrisNativeStructure {
@Required
@RegistryListVanillaStructure
@Desc("Registered structure key. The source retains its native generator, pieces, templates, processors, entities, markers, and data.")
private String structure = "";
@MinNumber(1)
@Desc("Relative selection weight when a placement offers multiple native structure sources.")
private int weight = 1;
@Desc("Optional jigsaw-only assembly overrides. Null preserves the complete registered structure definition.")
private JigsawOverrides jigsaw = null;
}
@@ -1,12 +0,0 @@
package art.arcane.iris.engine.object.structure.vanilla;
import art.arcane.iris.engine.object.annotations.Desc;
@Desc("Controls whether an Iris structure placement suppresses its imported native source.")
public enum NativeStructureSuppression {
@Desc("Leaves native generation enabled alongside this Iris structure placement.")
NONE,
@Desc("Suppresses the structure's vanillaSource when used by a validated dimension-level replacement placement.")
REPLACE_SOURCE
}
@@ -22,7 +22,6 @@ 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.structure.IrisStructurePlacement;
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;
@@ -146,9 +145,6 @@ public class IrisBiome extends IrisRegistrant implements IRare {
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 = IrisStructurePlacement.class)
@Desc("Structures define jigsaw or vanilla/datapack structures iris will place in this biome")
private KList<IrisStructurePlacement> structures = new KList<>();
@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());
@@ -26,7 +26,6 @@ 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.structure.IrisStructurePlacement;
import art.arcane.iris.engine.object.value.IrisRange;
import art.arcane.iris.engine.object.world.IrisEnvironment;
import art.arcane.iris.engine.object.world.IrisWorldBoundary;
@@ -236,9 +235,6 @@ public class IrisDimension extends IrisRegistrant {
@ArrayType(min = 1, type = IrisShapedGeneratorStyle.class)
@Desc("Overlay additional noise on top of the interoplated terrain.")
private KList<IrisShapedGeneratorStyle> overlayNoise = new KList<>();
@Desc("Dimension-wide Iris structure placements, independent of biome/region placements")
@ArrayType(type = IrisStructurePlacement.class, min = 1)
private KList<IrisStructurePlacement> structures = new KList<>();
@ArrayType(type = String.class, min = 1)
@Desc("External datapack sources owned by this dimension. Bukkit registers their resources server-wide, but Iris excludes their structure sets and definitions from generation and locate state in vanilla worlds and Iris dimensions that do not declare the same source. Editable auto-import is limited to resources supplied by the URLs declared by each Iris pack. Any registered datapack structure can be placed directly through nativeStructures without conversion. Replacing native generation requires a dimension-level structure placement with nativeSuppression set to REPLACE_SOURCE; provenance alone never disables native structures.")
private KList<String> datapackImports = new KList<>();
@@ -20,7 +20,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.structure.IrisStructurePlacement;
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;
@@ -81,9 +80,6 @@ public class IrisRegion extends IrisRegistrant implements IRare {
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();
@ArrayType(min = 1, type = IrisStructurePlacement.class)
@Desc("Structures define jigsaw or vanilla/datapack structures iris will place in this region")
private KList<IrisStructurePlacement> structures = new KList<>();
@MinNumber(0)
@Desc("The min shore height")
private double shoreHeightMin = 1.2;