mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Structure fit moves into iris:structure behind the VanillaStructures service
The module now owns every way a platform start meets the terrain: the surface fit (SOURCE beard, VACUUM and its foundation repair), terrain integration (SOURCE bury and encapsulate, ENCASE, BORE, FORCE_CARVE with the organic carve), rigid piece support, legacy template air and stilts, all written against StructureFit and BlockAccess in the new structure/fit package. Where a start sits (shift, band, burial) and how far it reaches are module answers too. The fit settings become the module's own: StructureTerrain, StructureTerrainMode, StructureCarveShape, StructureStilts and StructureYBand replace the Iris classes and the API values, with the same JSON. A start carries its fit as a memo (terrain JSON, stilts JSON) so every chunk it reaches fits it the same way. The jigsaw overrides of a placement are the API's JigsawOverrides.
This commit is contained in:
1 parent
13aa3ccc68
commit
3d7b82c2cb
34 files changed
+3113
-371
No files matched your search
@@ -24,9 +24,6 @@ import com.volmit.config.MinItems;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.vanilla.StructureStilts;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.YBand;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -45,7 +42,7 @@ public final class StructureAdjustment {
|
||||
private int yShift = 0;
|
||||
|
||||
@Desc("Optional absolute world Y band. The structure is relocated so its vertical midpoint lands inside the band, deterministically from its start chunk and clamped to the world's build bounds. Precedence: preserveSourceY wins over yBand, and yBand wins over both yShift and Iris burial repositioning. Structures with a fixed vanilla alignment (ocean monument sea level, desert and jungle pyramid surface fit) ignore it.")
|
||||
private YBand yBand = null;
|
||||
private StructureYBand yBand = null;
|
||||
|
||||
@Desc("When true, skip Iris burial repositioning so the structure keeps the Y its own vanilla placement chose. Underground structures are otherwise pushed below the lowest solid column across their whole footprint, which hides terrain-aware structures such as mineshafts that intentionally breach cliffs and surfaces. Vertical shifts still apply on top of the preserved Y: this dimension's undergroundYShift plus every matching adjustment's yShift.")
|
||||
private boolean preserveSourceY = false;
|
||||
@@ -59,7 +56,7 @@ public final class StructureAdjustment {
|
||||
public StructureAdjustment() {
|
||||
}
|
||||
|
||||
public StructureAdjustment(List<String> match, int yShift, YBand yBand, boolean preserveSourceY, StructureStilts stilt,
|
||||
public StructureAdjustment(List<String> match, int yShift, StructureYBand yBand, boolean preserveSourceY, StructureStilts stilt,
|
||||
StructureTerrain terrain) {
|
||||
this.match = List.copyOf(match);
|
||||
this.yShift = yShift;
|
||||
@@ -78,7 +75,7 @@ public final class StructureAdjustment {
|
||||
return yShift;
|
||||
}
|
||||
|
||||
public Optional<YBand> yBand() {
|
||||
public Optional<StructureYBand> yBand() {
|
||||
return Optional.ofNullable(yBand);
|
||||
}
|
||||
|
||||
|
||||
+24
-4
@@ -1,9 +1,26 @@
|
||||
package art.arcane.iris.engine.object.structure;
|
||||
/*
|
||||
* 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 art.arcane.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("Controls the shape of the expanded terrain carve around an overbored structure.")
|
||||
public enum IrisStructureCarveShape {
|
||||
public enum StructureCarveShape {
|
||||
@Desc("Carves the full expanded rectangular volume with straight walls, ceiling, and floor.")
|
||||
BOX,
|
||||
|
||||
@@ -13,16 +30,19 @@ public enum IrisStructureCarveShape {
|
||||
@Desc("Carves a rounded volume whose outer boundary is eroded by deterministic noise.")
|
||||
ERODED;
|
||||
|
||||
private static final double ERODED_CEILING_GROWTH = 0.8D;
|
||||
|
||||
public double maximumCeilingScale() {
|
||||
return maximumCeilingScale(1D);
|
||||
}
|
||||
|
||||
/** How far above its configured head room a carve of this shape may reach, as a multiple of it. */
|
||||
public double maximumCeilingScale(double erosionStrength) {
|
||||
double strength = Double.isFinite(erosionStrength)
|
||||
? Math.max(0D, Math.min(1D, erosionStrength)) : 1D;
|
||||
return switch (this) {
|
||||
case BOX, ROUNDED -> 1D;
|
||||
case ERODED -> 1D + 0.8D * strength;
|
||||
case ERODED -> 1D + ERODED_CEILING_GROWTH * strength;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.builtin.structure;
|
||||
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Foundation columns built beneath a structure's pieces after they are placed, as packs write it:
|
||||
* {"maxDepth": 32, "palette": {"palette": [{"block": "stone_bricks"}]}, "spacing": 2}. Held by structure placements and
|
||||
* by the {@code importedStructures} adjustments; ownership records keep its JSON for the starts they track.
|
||||
*/
|
||||
@Desc("Defines foundation columns placed beneath a structure.")
|
||||
public final class StructureStilts {
|
||||
private static final String DEFAULT_BLOCK = "minecraft:cobblestone";
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Maximum number of blocks each foundation column may descend while searching for solid ground.")
|
||||
private int maxDepth = 64;
|
||||
|
||||
@Desc("Block palette used for foundation columns.")
|
||||
private PaletteSpec palette = PaletteSpec.of(List.of(BlockSpec.of(DEFAULT_BLOCK)));
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Desc("Horizontal spacing between support columns. One fills every eligible foundation column; larger values create sparse stilts.")
|
||||
private int spacing = 1;
|
||||
|
||||
@Desc("For Iris-authored structures, whether solid partial blocks such as slabs, stairs, and walls may seed foundation columns instead of requiring a fully occluding base block.")
|
||||
private boolean supportNonOccluding = false;
|
||||
|
||||
public StructureStilts() {
|
||||
}
|
||||
|
||||
public int maxDepth() {
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
/** The blocks of the columns; empty when the pack wrote {@code "palette": null}. */
|
||||
public Optional<PaletteSpec> palette() {
|
||||
return Optional.ofNullable(palette);
|
||||
}
|
||||
|
||||
public int spacing() {
|
||||
return spacing;
|
||||
}
|
||||
|
||||
public boolean supportNonOccluding() {
|
||||
return supportNonOccluding;
|
||||
}
|
||||
}
|
||||
+60
-21
@@ -1,20 +1,37 @@
|
||||
package art.arcane.iris.engine.object.structure;
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
package art.arcane.iris.builtin.structure;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* How a structure meets the terrain, as packs write it: {"mode": "FORCE_CARVE", "horizontalPadding": 4, "shape": "ERODED"}.
|
||||
* Held by structure placements and by the {@code importedStructures} adjustments; ownership records keep its JSON for
|
||||
* the starts they track, so its field names and defaults are the persisted format.
|
||||
*/
|
||||
@Desc("Terrain integration applied after a structure graph is assembled and before its pieces are placed.")
|
||||
public class IrisStructureTerrain {
|
||||
public final class StructureTerrain {
|
||||
private static final double AUTO_LOBE_FREQUENCY_RATIO = 0.3D;
|
||||
private static final double DEFAULT_EROSION_STRENGTH = 0.8D;
|
||||
private static final double DEFAULT_EROSION_FREQUENCY = 0.07D;
|
||||
@@ -24,7 +41,7 @@ public class IrisStructureTerrain {
|
||||
private static final double MAX_LOBE_FREQUENCY = 1D;
|
||||
|
||||
@Desc("Terrain operation. SOURCE applies the registered native structure's authored terrain adaptation and is a no-op for editable Iris structures. PRESERVE disables terrain integration. VACUUM raises terrain from processed rigid-template foundations at or below each authored ground plane with a 12-block falloff without lowering existing ground. BORE and FORCE_CARVE clear the requested envelope, while ENCASE fills it before placement so native shells are not lost to pre-carved air.")
|
||||
private IrisStructureTerrainMode mode = IrisStructureTerrainMode.SOURCE;
|
||||
private StructureTerrainMode mode = StructureTerrainMode.SOURCE;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(128)
|
||||
@@ -42,10 +59,10 @@ public class IrisStructureTerrain {
|
||||
private int floorPadding = 0;
|
||||
|
||||
@Desc("Shape used by FORCE_CARVE.")
|
||||
private IrisStructureCarveShape shape = IrisStructureCarveShape.BOX;
|
||||
private StructureCarveShape shape = StructureCarveShape.BOX;
|
||||
|
||||
@Desc("Block palette used by ENCASE. When unset, the Overworld uses stone or deepslate, the Nether uses netherrack, and the End uses end stone.")
|
||||
private IrisMaterialPalette encasePalette = null;
|
||||
private PaletteSpec encasePalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@@ -67,12 +84,34 @@ public class IrisStructureTerrain {
|
||||
@Desc("Fraction of the horizontal padding the lobes may remove for ERODED force carving. Zero keeps a uniform boundary.")
|
||||
private double lobeStrength = DEFAULT_LOBE_STRENGTH;
|
||||
|
||||
public IrisStructureTerrainMode resolvedMode() {
|
||||
return mode == null ? IrisStructureTerrainMode.SOURCE : mode;
|
||||
public StructureTerrain() {
|
||||
}
|
||||
|
||||
public IrisStructureCarveShape resolvedShape() {
|
||||
return shape == null ? IrisStructureCarveShape.BOX : shape;
|
||||
/** The terrain operation; SOURCE where the pack wrote none or one Iris does not know. */
|
||||
public StructureTerrainMode resolvedMode() {
|
||||
return mode == null ? StructureTerrainMode.SOURCE : mode;
|
||||
}
|
||||
|
||||
public int horizontalPadding() {
|
||||
return horizontalPadding;
|
||||
}
|
||||
|
||||
public int ceilingPadding() {
|
||||
return ceilingPadding;
|
||||
}
|
||||
|
||||
public int floorPadding() {
|
||||
return floorPadding;
|
||||
}
|
||||
|
||||
/** The carve shape; BOX where the pack wrote none or one Iris does not know. */
|
||||
public StructureCarveShape resolvedShape() {
|
||||
return shape == null ? StructureCarveShape.BOX : shape;
|
||||
}
|
||||
|
||||
/** The blocks ENCASE fills with; empty for the dimension's own stone. */
|
||||
public Optional<PaletteSpec> encasePalette() {
|
||||
return Optional.ofNullable(encasePalette);
|
||||
}
|
||||
|
||||
public double resolvedErosionStrength() {
|
||||
+21
-3
@@ -1,9 +1,27 @@
|
||||
package art.arcane.iris.engine.object.structure;
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
package art.arcane.iris.builtin.structure;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("Controls how terrain is integrated with a structure.")
|
||||
public enum IrisStructureTerrainMode {
|
||||
public enum StructureTerrainMode {
|
||||
@Desc("Replays the registered native structure's own authored terrain adaptation (beard surface fitting, BURY/ENCAPSULATE fill, legacy template-air clearing). Does nothing for editable Iris structures, which have no source adaptation to replay.")
|
||||
SOURCE,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
/**
|
||||
* A band of absolute world heights a platform structure is moved into, as packs write it: {"min": -120, "max": -20}.
|
||||
* Unlike the API's heights these are world Y, as the platform's own structure definitions use them. Reversed bounds
|
||||
* mean the same band.
|
||||
*/
|
||||
@Desc("An absolute world Y band a native structure is relocated into. Reversed bounds are normalized.")
|
||||
public final class StructureYBand {
|
||||
@MinNumber(-4064)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Lowest absolute world Y of the band.")
|
||||
private int min = 0;
|
||||
|
||||
@MinNumber(-4064)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Highest absolute world Y of the band.")
|
||||
private int max = 0;
|
||||
|
||||
public StructureYBand() {
|
||||
}
|
||||
|
||||
public int resolvedMin() {
|
||||
return Math.min(min, max);
|
||||
}
|
||||
|
||||
public int resolvedMax() {
|
||||
return Math.max(min, max);
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,10 @@ 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.engine.object.structure.IrisStructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
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.volmlib.util.collection.KList;
|
||||
@@ -698,17 +698,17 @@ public final class IrisStructureLocator {
|
||||
return null;
|
||||
}
|
||||
|
||||
IrisStructureTerrain terrain = placement.resolvedTerrain();
|
||||
IrisStructureTerrainMode terrainMode = terrain.resolvedMode();
|
||||
boolean forceCarve = terrainMode == IrisStructureTerrainMode.FORCE_CARVE;
|
||||
boolean bore = terrainMode == IrisStructureTerrainMode.BORE;
|
||||
int sideExtension = forceCarve || bore ? Math.max(0, terrain.getHorizontalPadding()) : 0;
|
||||
IrisStructureCarveShape carveShape = terrain.resolvedShape();
|
||||
StructureTerrain terrain = placement.resolvedTerrain();
|
||||
StructureTerrainMode terrainMode = terrain.resolvedMode();
|
||||
boolean forceCarve = terrainMode == StructureTerrainMode.FORCE_CARVE;
|
||||
boolean bore = terrainMode == StructureTerrainMode.BORE;
|
||||
int sideExtension = forceCarve || bore ? Math.max(0, terrain.horizontalPadding()) : 0;
|
||||
StructureCarveShape carveShape = terrain.resolvedShape();
|
||||
int topExtension = forceCarve
|
||||
? carveShape.maximumCeilingExtension(
|
||||
terrain.getCeilingPadding(), terrain.resolvedErosionStrength())
|
||||
: bore ? Math.max(0, terrain.getCeilingPadding()) : 0;
|
||||
int bottomExtension = forceCarve || bore ? Math.max(0, terrain.getFloorPadding()) : 0;
|
||||
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 minimumShift = Math.max(worldMin - (bounds[1] - bottomExtension), bandMin - baseY);
|
||||
@@ -719,7 +719,7 @@ public final class IrisStructureLocator {
|
||||
|
||||
Long2IntOpenHashMap surfaceHeights = new Long2IntOpenHashMap();
|
||||
surfaceHeights.defaultReturnValue(Integer.MIN_VALUE);
|
||||
if (bore || forceCarve && carveShape == IrisStructureCarveShape.BOX) {
|
||||
if (bore || forceCarve && carveShape == StructureCarveShape.BOX) {
|
||||
maximumShift = resolveBurialEnvelopeShift(
|
||||
engine,
|
||||
bounds[0] - sideExtension,
|
||||
|
||||
@@ -24,8 +24,6 @@ import art.arcane.iris.builtin.structure.StructureSettings;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.vanilla.VanillaStructureFit;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
|
||||
import java.util.List;
|
||||
@@ -66,8 +64,8 @@ public final class ImportedStructures {
|
||||
* How the platform's own starts of {@code key} are adjusted: the underground shift for underground steps, then every
|
||||
* matching adjustment in the order the pack lists them.
|
||||
*/
|
||||
public VanillaStructureAdjustment adjustment(String key, boolean underground) {
|
||||
VanillaStructureAdjustment adjustment = VanillaStructureAdjustment.NONE.shifted(underground ? settings.undergroundYShift() : 0);
|
||||
public NativeStructureFit adjustment(String key, boolean underground) {
|
||||
NativeStructureFit adjustment = NativeStructureFit.NONE.shifted(underground ? settings.undergroundYShift() : 0);
|
||||
for (StructureAdjustment entry : settings.adjustments()) {
|
||||
if (entry != null && matchesAny(entry.match(), key)) {
|
||||
adjustment = adjustment.then(asAdjustment(entry));
|
||||
@@ -130,13 +128,9 @@ public final class ImportedStructures {
|
||||
return patterns.stream().anyMatch(pattern -> matchesKey(pattern, key));
|
||||
}
|
||||
|
||||
private static VanillaStructureAdjustment asAdjustment(StructureAdjustment entry) {
|
||||
VanillaStructureFit fit = VanillaStructureFit.SOURCE;
|
||||
fit = entry.stilt().map(fit::withStilts).orElse(fit);
|
||||
fit = entry.terrain().map(fit::withTerrain).orElse(fit);
|
||||
VanillaStructureAdjustment adjustment = VanillaStructureAdjustment.NONE.shifted(entry.yShift()).withFit(fit);
|
||||
adjustment = entry.yBand().map(adjustment::withYBand).orElse(adjustment);
|
||||
return entry.preserveSourceY() ? adjustment.keepingSourceY() : adjustment;
|
||||
private static NativeStructureFit asAdjustment(StructureAdjustment entry) {
|
||||
return new NativeStructureFit(entry.yShift(), entry.yBand().orElse(null), entry.preserveSourceY(),
|
||||
entry.stilt().orElse(null), entry.terrain().orElse(null));
|
||||
}
|
||||
|
||||
private static String normalize(String key) {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.framework.structure;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureStilts;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureYBand;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.vanilla.StartMemo;
|
||||
|
||||
/**
|
||||
* How {@code iris:structure} places and fits one platform structure, or one start: how far it moves the platform's own
|
||||
* starts and into which band of world heights, whether they keep the platform's height, the foundation columns built
|
||||
* under their pieces and how they meet the terrain. A start the module places itself carries its fit as a memo, the
|
||||
* JSON of its terrain and stilts, which ownership records keep, so its later chunks use the fit it began with.
|
||||
*
|
||||
* @param yBand null for no band
|
||||
* @param stilts null for no foundation columns
|
||||
* @param terrain null for the structure's own terrain adaptation (SOURCE)
|
||||
*/
|
||||
public record NativeStructureFit(int yShift, StructureYBand yBand, boolean keepsSourceY, StructureStilts stilts,
|
||||
StructureTerrain terrain) {
|
||||
/** The platform's starts as the platform makes them. */
|
||||
public static final NativeStructureFit NONE = new NativeStructureFit(0, null, false, null, null);
|
||||
|
||||
private static final Gson MEMO_JSON = new Gson();
|
||||
private static final String NO_STILTS = "null";
|
||||
|
||||
/** The fit a start's memo records: its terrain and stilts, with no vertical adjustment. */
|
||||
public static NativeStructureFit of(StartMemo memo) {
|
||||
StructureStilts stilts = NO_STILTS.equals(memo.foundation())
|
||||
? null : MEMO_JSON.fromJson(memo.foundation(), StructureStilts.class);
|
||||
StructureTerrain terrain = MEMO_JSON.fromJson(memo.terrain(), StructureTerrain.class);
|
||||
if (terrain == null) {
|
||||
throw new IllegalStateException("A start's memo has no terrain fit: " + memo);
|
||||
}
|
||||
return new NativeStructureFit(0, null, false, stilts, terrain);
|
||||
}
|
||||
|
||||
/** The memo of a start placed with this fit's terrain and stilts. */
|
||||
public StartMemo memo() {
|
||||
return new StartMemo(MEMO_JSON.toJson(resolvedTerrain()), MEMO_JSON.toJson(stilts));
|
||||
}
|
||||
|
||||
/** The terrain fitting; the structure's own adaptation (SOURCE) when none is set. */
|
||||
public StructureTerrain resolvedTerrain() {
|
||||
return terrain == null ? new StructureTerrain() : terrain;
|
||||
}
|
||||
|
||||
public NativeStructureFit shifted(int blocks) {
|
||||
return new NativeStructureFit(Math.addExact(yShift, blocks), yBand, keepsSourceY, stilts, terrain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Both fits, {@code later} after this one: shifts add up, keeping the platform's height sticks, and a band, stilts
|
||||
* or terrain {@code later} states replaces this one's.
|
||||
*/
|
||||
public NativeStructureFit then(NativeStructureFit later) {
|
||||
return new NativeStructureFit(Math.addExact(yShift, later.yShift),
|
||||
later.yBand == null ? yBand : later.yBand,
|
||||
keepsSourceY || later.keepsSourceY,
|
||||
later.stilts == null ? stilts : later.stilts,
|
||||
later.terrain == null ? terrain : later.terrain);
|
||||
}
|
||||
}
|
||||
+41
-31
@@ -23,33 +23,33 @@ import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
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 com.google.gson.Gson;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.JigsawOverrides;
|
||||
import com.volmit.vanilla.StructureStilts;
|
||||
import com.volmit.vanilla.StructureTerrain;
|
||||
import com.volmit.vanilla.VanillaStructureAdjustment;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.vanilla.PlatformStart;
|
||||
import com.volmit.vanilla.StartMemo;
|
||||
import com.volmit.vanilla.StartReach;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
import com.volmit.vanilla.VanillaStructureContext;
|
||||
import com.volmit.vanilla.VanillaStructureFit;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import com.volmit.vanilla.VanillaStructureSetup;
|
||||
import com.volmit.vanilla.VanillaStructureStart;
|
||||
import com.volmit.vanilla.VanillaStructureStartContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What {@code iris:structure} says about the platform's own structures. The dimension's {@code importedStructures}
|
||||
* settings ({@link ImportedStructures}) disable, adjust and set them up; the pack's structure placements replace
|
||||
* them ({@code vanillaSource} with native suppression), place them alongside ({@link IrisStructureLocator#isPlaced})
|
||||
* and start them where their {@code nativeStructures} grids say ({@link NativeStartPlanner}).
|
||||
* settings ({@link ImportedStructures}) disable, move, fit and set them up; the pack's structure placements replace
|
||||
* them ({@code vanillaSource} with native suppression), place them alongside ({@link IrisStructureLocator#isPlaced}),
|
||||
* start them where their {@code nativeStructures} grids say ({@link NativeStartPlanner}) and fit those starts the way
|
||||
* the placement says, which their memo carries to every chunk they reach ({@link StructureFitting}).
|
||||
*/
|
||||
public final class StructureVanillaHook implements VanillaStructureHook {
|
||||
private static final Gson SAME_JSON = new Gson();
|
||||
|
||||
public final class StructureVanillaStructures implements VanillaStructures {
|
||||
/**
|
||||
* {@link VanillaStructureRule#REPLACE} for a structure an Iris structure replaces or the dimension disables while a
|
||||
* placement places it, {@link VanillaStructureRule#BLOCK} for one the dimension disables, and
|
||||
@@ -66,11 +66,6 @@ public final class StructureVanillaHook implements VanillaStructureHook {
|
||||
return placed ? rule.and(VanillaStructureRule.ALSO_PLACE) : rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaStructureAdjustment adjustment(ResourceId structure, boolean underground, VanillaStructureContext context) {
|
||||
return ImportedStructures.of(context.settings()).adjustment(structure.toString(), underground);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VanillaStructureStart> starts(int chunkX, int chunkZ, VanillaStructureStartContext context) {
|
||||
Engine engine = IrisPackWorld.of(context.world()).engine();
|
||||
@@ -79,18 +74,43 @@ public final class StructureVanillaHook implements VanillaStructureHook {
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int shift(PlatformStart start, VanillaStructureContext context) {
|
||||
return StartLayouts.shift(start, ImportedStructures.of(context.settings())
|
||||
.adjustment(start.structure().toString(), start.underground()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartReach reach(ResourceId structure, boolean underground, Optional<StartMemo> memo,
|
||||
VanillaStructureContext context) {
|
||||
NativeStructureFit fit = memo.map(NativeStructureFit::of)
|
||||
.orElseGet(() -> ImportedStructures.of(context.settings()).adjustment(structure.toString(), underground));
|
||||
return StartLayouts.reach(fit.resolvedTerrain());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforePieces(StructureFit fit) {
|
||||
StructureFitting.beforePieces(fit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPieces(StructureFit fit, StructureFit.Start placed) {
|
||||
StructureFitting.afterPieces(fit, placed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaStructureSetup setup(VanillaStructureContext context) {
|
||||
return ImportedStructures.of(context.settings()).setup();
|
||||
}
|
||||
|
||||
/** {@code plan} as the start the platform generates: heights above the bottom, the placement's fit and identity. */
|
||||
/** {@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()),
|
||||
plan.chunkX(), plan.chunkZ(), plan.baseY() - minHeight)
|
||||
.withIdentity(StructurePlacementGrid.placementIdentity(placement))
|
||||
.withFit(fit(placement));
|
||||
.withMemo(fit.memo());
|
||||
if (placement.isUnderground()) {
|
||||
start = start.underground();
|
||||
}
|
||||
@@ -98,18 +118,8 @@ public final class StructureVanillaHook implements VanillaStructureHook {
|
||||
start = start.replacingPlatformStart();
|
||||
}
|
||||
if (plan.source().getJigsaw() != null) {
|
||||
start = start.withJigsaw(sameJson(plan.source().getJigsaw(), JigsawOverrides.class));
|
||||
start = start.withJigsaw(plan.source().getJigsaw());
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
private static VanillaStructureFit fit(IrisStructurePlacement placement) {
|
||||
VanillaStructureFit fit = VanillaStructureFit.SOURCE.withTerrain(sameJson(placement.resolvedTerrain(), StructureTerrain.class));
|
||||
return placement.getStilt() == null ? fit : fit.withStilts(sameJson(placement.getStilt(), StructureStilts.class));
|
||||
}
|
||||
|
||||
/** The placement classes are Iris's; the API values read the same JSON. */
|
||||
private static <T> T sameJson(Object irisValue, Class<T> apiType) {
|
||||
return SAME_JSON.fromJson(SAME_JSON.toJsonTree(irisValue), apiType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import com.volmit.mantle.BlockBox;
|
||||
|
||||
/** A box of world blocks, every bound inclusive and Y in world heights, the way the platform's structures measure. */
|
||||
record Box(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
/** {@code box}, an API box above the dimension's bottom with exclusive maxima, in world heights. */
|
||||
static Box of(BlockBox box, int bottomY) {
|
||||
return new Box(box.minX(), box.minY() + bottomY, box.minZ(),
|
||||
box.maxX() - 1, box.maxY() - 1 + bottomY, box.maxZ() - 1);
|
||||
}
|
||||
|
||||
/** This box as an API box above the dimension's bottom. */
|
||||
BlockBox toApi(int bottomY) {
|
||||
return new BlockBox(minX, minY - bottomY, minZ, maxX + 1, maxY + 1 - bottomY, maxZ + 1);
|
||||
}
|
||||
|
||||
int xSpan() {
|
||||
return maxX - minX + 1;
|
||||
}
|
||||
|
||||
int ySpan() {
|
||||
return maxY - minY + 1;
|
||||
}
|
||||
|
||||
int zSpan() {
|
||||
return maxZ - minZ + 1;
|
||||
}
|
||||
|
||||
boolean contains(int x, int y, int z) {
|
||||
return x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ;
|
||||
}
|
||||
|
||||
boolean intersects(Box other) {
|
||||
return maxX >= other.minX && minX <= other.maxX && maxY >= other.minY && minY <= other.maxY
|
||||
&& maxZ >= other.minZ && minZ <= other.maxZ;
|
||||
}
|
||||
|
||||
boolean intersectsHorizontally(Box other) {
|
||||
return maxX >= other.minX && minX <= other.maxX && maxZ >= other.minZ && minZ <= other.maxZ;
|
||||
}
|
||||
|
||||
/** This box grown by {@code blocks} sideways, keeping its heights. */
|
||||
Box widened(int blocks) {
|
||||
return new Box(minX - blocks, minY, minZ - blocks, maxX + blocks, maxY, maxZ + blocks);
|
||||
}
|
||||
|
||||
Box encapsulating(Box other) {
|
||||
return new Box(Math.min(minX, other.minX), Math.min(minY, other.minY), Math.min(minZ, other.minZ),
|
||||
Math.max(maxX, other.maxX), Math.max(maxY, other.maxY), Math.max(maxZ, other.maxZ));
|
||||
}
|
||||
|
||||
/** The column index of a block of this box's columns, rows along X. */
|
||||
int columnIndex(int x, int z) {
|
||||
return (z - minZ) * xSpan() + x - minX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.engine.mantle.components.StructureCarvingFootprint;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Per-column occupancy of whole starts for organic carving, kept because a structure spans many chunks and every one of
|
||||
* them carves against the same shrinkwrapped footprint. Keyed weakly on the platform's own key of the start, so retired
|
||||
* starts (world unload, generation done) are collectable; values hold only primitives, so no value pins its key. The
|
||||
* cached cells stay inside a budget, the oldest starts giving way first.
|
||||
*/
|
||||
final class CarveFootprints {
|
||||
private static final int MAX_CACHED_CARVE_CELLS = 2_000_000;
|
||||
private static final int MAX_CARVE_COLUMNS = 2_000_000;
|
||||
private static final Map<Object, Map<Integer, CachedCarveFootprint>> CARVE_FOOTPRINTS = new WeakHashMap<>(16);
|
||||
private static final ConcurrentHashMap<CarveFootprintKey, CompletableFuture<StructureCarvingFootprint>> BUILDS =
|
||||
new ConcurrentHashMap<>();
|
||||
private static int cachedCarveCells;
|
||||
|
||||
private CarveFootprints() {
|
||||
}
|
||||
|
||||
static StructureCarvingFootprint of(FitStart start, int horizontalPadding) {
|
||||
CarveFootprintKey key = new CarveFootprintKey(start.key(), horizontalPadding);
|
||||
StructureCarvingFootprint cached = cached(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
CompletableFuture<StructureCarvingFootprint> build = new CompletableFuture<>();
|
||||
CompletableFuture<StructureCarvingFootprint> active = BUILDS.putIfAbsent(key, build);
|
||||
if (active != null) {
|
||||
return await(active);
|
||||
}
|
||||
// Close the check-then-claim window: a racer whose cache check missed before the previous builder cached can
|
||||
// claim the build slot after that builder retired it, and would rebuild a second instance without this re-check.
|
||||
StructureCarvingFootprint published = cached(key);
|
||||
if (published != null) {
|
||||
build.complete(published);
|
||||
BUILDS.remove(key, build);
|
||||
return published;
|
||||
}
|
||||
try {
|
||||
StructureCarvingFootprint footprint = StructureCarvingFootprint.fromColumns(sink -> {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
piece.columns(sink::column);
|
||||
}
|
||||
return true;
|
||||
}, horizontalPadding, MAX_CARVE_COLUMNS);
|
||||
if (footprint == null) {
|
||||
throw new IllegalStateException("Native structure carve footprint is empty or exceeds "
|
||||
+ MAX_CARVE_COLUMNS + " columns");
|
||||
}
|
||||
cache(key, footprint);
|
||||
build.complete(footprint);
|
||||
return footprint;
|
||||
} catch (RuntimeException | Error error) {
|
||||
build.completeExceptionally(error);
|
||||
throw error;
|
||||
} finally {
|
||||
BUILDS.remove(key, build);
|
||||
}
|
||||
}
|
||||
|
||||
static int cachedCells() {
|
||||
synchronized (CARVE_FOOTPRINTS) {
|
||||
cachedCarveCells = liveCells();
|
||||
return cachedCarveCells;
|
||||
}
|
||||
}
|
||||
|
||||
static int maximumCachedCells() {
|
||||
return MAX_CACHED_CARVE_CELLS;
|
||||
}
|
||||
|
||||
private static int liveCells() {
|
||||
int total = 0;
|
||||
for (Map<Integer, CachedCarveFootprint> perStart : CARVE_FOOTPRINTS.values()) {
|
||||
for (CachedCarveFootprint cached : perStart.values()) {
|
||||
total += cached.cells();
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private static StructureCarvingFootprint cached(CarveFootprintKey key) {
|
||||
synchronized (CARVE_FOOTPRINTS) {
|
||||
Map<Integer, CachedCarveFootprint> perStart = CARVE_FOOTPRINTS.get(key.start());
|
||||
CachedCarveFootprint cached = perStart == null ? null : perStart.get(key.padding());
|
||||
return cached == null ? null : cached.footprint();
|
||||
}
|
||||
}
|
||||
|
||||
/** The loser of a build race surfaces the builder's own exception, not a CompletionException wrapper. */
|
||||
private static StructureCarvingFootprint await(CompletableFuture<StructureCarvingFootprint> future) {
|
||||
try {
|
||||
return future.join();
|
||||
} catch (CompletionException error) {
|
||||
Throwable cause = error.getCause();
|
||||
if (cause instanceof RuntimeException runtime) {
|
||||
throw runtime;
|
||||
}
|
||||
if (cause instanceof Error fatal) {
|
||||
throw fatal;
|
||||
}
|
||||
if (cause == null) {
|
||||
throw error;
|
||||
}
|
||||
throw new IllegalStateException("Native structure carve footprint build failed", cause);
|
||||
}
|
||||
}
|
||||
|
||||
private static void cache(CarveFootprintKey key, StructureCarvingFootprint footprint) {
|
||||
int cells = Math.multiplyExact(footprint.width(), footprint.depth());
|
||||
synchronized (CARVE_FOOTPRINTS) {
|
||||
// Weak keys expunge silently as the GC drops retired starts; re-derive the live total so the cell budget
|
||||
// tracks reality instead of drifting.
|
||||
cachedCarveCells = liveCells();
|
||||
Map<Integer, CachedCarveFootprint> perStart =
|
||||
CARVE_FOOTPRINTS.computeIfAbsent(key.start(), ignored -> new LinkedHashMap<>(4));
|
||||
CachedCarveFootprint previous = perStart.remove(key.padding());
|
||||
if (previous != null) {
|
||||
cachedCarveCells -= previous.cells();
|
||||
}
|
||||
Iterator<Map.Entry<Object, Map<Integer, CachedCarveFootprint>>> eviction =
|
||||
CARVE_FOOTPRINTS.entrySet().iterator();
|
||||
while (cachedCarveCells + cells > MAX_CACHED_CARVE_CELLS && eviction.hasNext()) {
|
||||
Map.Entry<Object, Map<Integer, CachedCarveFootprint>> victim = eviction.next();
|
||||
if (victim.getKey() == key.start()) {
|
||||
continue;
|
||||
}
|
||||
for (CachedCarveFootprint evicted : victim.getValue().values()) {
|
||||
cachedCarveCells -= evicted.cells();
|
||||
}
|
||||
eviction.remove();
|
||||
}
|
||||
perStart.put(key.padding(), new CachedCarveFootprint(footprint, cells));
|
||||
cachedCarveCells += cells;
|
||||
}
|
||||
}
|
||||
|
||||
/** The platform's start has no value equality, so the key pins the exact start a chunk carves against. */
|
||||
private record CarveFootprintKey(Object start, int padding) {
|
||||
}
|
||||
|
||||
private record CachedCarveFootprint(StructureCarvingFootprint footprint, int cells) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import com.volmit.block.BlockFace;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BlockAccess;
|
||||
|
||||
/**
|
||||
* The chunk's live blocks in world heights, and the block questions the structure fit asks. The fit's rules were
|
||||
* written in world heights (deepslate below 0, bands of world Y, noise sampled at world heights), so it keeps them and
|
||||
* converts here.
|
||||
*/
|
||||
final class FitBlocks {
|
||||
static final BlockState AIR = new BlockState("minecraft:air");
|
||||
static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
static final BlockState COBBLESTONE = new BlockState("minecraft:cobblestone");
|
||||
private static final ResourceId STRUCTURE_VOID = ResourceId.parse("minecraft:structure_void");
|
||||
private static final ResourceId JIGSAW = ResourceId.parse("minecraft:jigsaw");
|
||||
private static final ResourceId LOGS_TAG = ResourceId.parse("minecraft:logs");
|
||||
private static final ResourceId LEAVES_TAG = ResourceId.parse("minecraft:leaves");
|
||||
|
||||
private final BlockAccess access;
|
||||
private final int bottomY;
|
||||
|
||||
FitBlocks(BlockAccess access, int bottomY) {
|
||||
this.access = access;
|
||||
this.bottomY = bottomY;
|
||||
}
|
||||
|
||||
int bottomY() {
|
||||
return bottomY;
|
||||
}
|
||||
|
||||
BlockState get(int x, int y, int z) {
|
||||
return access.get(x, y - bottomY, z);
|
||||
}
|
||||
|
||||
void set(int x, int y, int z, BlockState state) {
|
||||
access.set(x, y - bottomY, z, state);
|
||||
}
|
||||
|
||||
boolean isAir(BlockState state) {
|
||||
return access.is(state, BlockTrait.AIR);
|
||||
}
|
||||
|
||||
boolean isSolid(BlockState state) {
|
||||
return access.is(state, BlockTrait.SOLID);
|
||||
}
|
||||
|
||||
boolean holdsFluid(BlockState state) {
|
||||
return access.is(state, BlockTrait.FLUID);
|
||||
}
|
||||
|
||||
/** Logs, wood, stems, hyphae and leaves: the blocks of trees the fit never treats as terrain. */
|
||||
boolean isTree(BlockState state) {
|
||||
return access.is(state, BlockTrait.LOG) || access.is(state, BlockTrait.LEAVES);
|
||||
}
|
||||
|
||||
/** Logs or leaves by the platform's tags alone, as stilts tell vegetation from ground. */
|
||||
boolean isTaggedVegetation(BlockState state) {
|
||||
return access.inTag(state, LOGS_TAG) || access.inTag(state, LEAVES_TAG);
|
||||
}
|
||||
|
||||
boolean inTag(BlockState state, ResourceId tag) {
|
||||
return access.inTag(state, tag);
|
||||
}
|
||||
|
||||
/** Solid ground that is not part of a tree. */
|
||||
boolean isTerrain(BlockState state) {
|
||||
return isSolid(state) && !isTree(state);
|
||||
}
|
||||
|
||||
/** Air or anything holding a fluid: the cells a fill may claim. */
|
||||
boolean isEncaseable(BlockState state) {
|
||||
return isAir(state) || holdsFluid(state);
|
||||
}
|
||||
|
||||
/** A block a structure can stand on: solid, dry, and neither structure void nor a jigsaw. */
|
||||
boolean isSolidBase(BlockState state) {
|
||||
return state != null && isSolid(state)
|
||||
&& !state.material().equals(STRUCTURE_VOID)
|
||||
&& !state.material().equals(JIGSAW)
|
||||
&& !holdsFluid(state);
|
||||
}
|
||||
|
||||
boolean sturdyTop(int x, int y, int z) {
|
||||
return access.sturdy(x, y - bottomY, z, BlockFace.UP);
|
||||
}
|
||||
|
||||
BlockState fluidOf(BlockState state) {
|
||||
return access.fluid(state);
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -16,11 +16,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.structure.vanilla;
|
||||
package art.arcane.iris.engine.framework.structure.fit;
|
||||
|
||||
public enum NativeStructureGenerationStatus {
|
||||
GENERATE_NATIVE,
|
||||
DISABLED_BY_PACK,
|
||||
REPLACED_BY_IRIS,
|
||||
INVALID_REGISTRY_KEY
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
|
||||
/** Picks a block of a pack palette for the structure fit, seeded the way the fit's own randomness is. */
|
||||
@FunctionalInterface
|
||||
interface FitPalettes {
|
||||
/** The block {@code palette}, seeded with {@code seed}, gives at the world position. */
|
||||
BlockState at(PaletteSpec palette, long seed, int x, int y, int z);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import com.volmit.vanilla.PieceKind;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A piece of a start in world heights with inclusive bounds. */
|
||||
final class FitPiece {
|
||||
private final StructureFit.Piece piece;
|
||||
private final Box box;
|
||||
private final int bottomY;
|
||||
|
||||
FitPiece(StructureFit.Piece piece, int bottomY) {
|
||||
this.piece = piece;
|
||||
this.box = Box.of(piece.box(), bottomY);
|
||||
this.bottomY = bottomY;
|
||||
}
|
||||
|
||||
Box box() {
|
||||
return box;
|
||||
}
|
||||
|
||||
PieceKind kind() {
|
||||
return piece.kind();
|
||||
}
|
||||
|
||||
boolean isJigsaw() {
|
||||
return piece.kind() != PieceKind.FIXED;
|
||||
}
|
||||
|
||||
boolean isRigid() {
|
||||
return piece.kind() == PieceKind.RIGID;
|
||||
}
|
||||
|
||||
/** Whether the piece keeps its shape over the terrain: every piece built in code, and rigid jigsaw pieces. */
|
||||
boolean isRigidOrFixed() {
|
||||
return piece.kind() != PieceKind.TERRAIN_MATCHING;
|
||||
}
|
||||
|
||||
int groundLevelDelta() {
|
||||
return piece.groundLevelDelta();
|
||||
}
|
||||
|
||||
/** The world height of the piece's ground level. */
|
||||
int groundY() {
|
||||
return box.minY() + piece.groundLevelDelta();
|
||||
}
|
||||
|
||||
/** The junctions, their Y the world height of the ground at their source. */
|
||||
List<BlockPosition> junctions() {
|
||||
List<BlockPosition> junctions = new ArrayList<>(piece.junctions().size());
|
||||
for (BlockPosition junction : piece.junctions()) {
|
||||
junctions.add(new BlockPosition(junction.x(), junction.y() + bottomY, junction.z()));
|
||||
}
|
||||
return junctions;
|
||||
}
|
||||
|
||||
TemplateCells cells(Box region) {
|
||||
return piece.cells(region.toApi(bottomY));
|
||||
}
|
||||
|
||||
/** The cell's world height. */
|
||||
int cellY(TemplateCells cells, int cell) {
|
||||
return cells.y(cell) + bottomY;
|
||||
}
|
||||
|
||||
void columns(StructureFit.ColumnVisitor visitor) {
|
||||
piece.columns((x, z, minY, maxY) -> visitor.column(x, z, minY + bottomY, maxY + bottomY));
|
||||
}
|
||||
|
||||
/** Legacy template air inside {@code clip}, in world heights. */
|
||||
List<BlockPosition> legacyAir(Box clip) {
|
||||
List<BlockPosition> air = piece.legacyAir(clip.toApi(bottomY));
|
||||
List<BlockPosition> world = new ArrayList<>(air.size());
|
||||
for (BlockPosition position : air) {
|
||||
world.add(new BlockPosition(position.x(), position.y() + bottomY, position.z()));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.engine.framework.structure.NativeStructureFit;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
import com.volmit.vanilla.StructureStep;
|
||||
import com.volmit.vanilla.TerrainAdaptation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A start the platform places in the chunk, with the fit {@code iris:structure} gives it, its pieces in world heights. */
|
||||
final class FitStart {
|
||||
private final StructureFit.Start start;
|
||||
private final NativeStructureFit fit;
|
||||
private final List<FitPiece> pieces;
|
||||
|
||||
FitStart(StructureFit.Start start, NativeStructureFit fit, int bottomY) {
|
||||
this.start = start;
|
||||
this.fit = fit;
|
||||
List<FitPiece> converted = new ArrayList<>(start.pieces().size());
|
||||
for (StructureFit.Piece piece : start.pieces()) {
|
||||
converted.add(new FitPiece(piece, bottomY));
|
||||
}
|
||||
this.pieces = List.copyOf(converted);
|
||||
}
|
||||
|
||||
StructureFit.Start start() {
|
||||
return start;
|
||||
}
|
||||
|
||||
String structureId() {
|
||||
return start.structure().toString();
|
||||
}
|
||||
|
||||
NativeStructureFit fit() {
|
||||
return fit;
|
||||
}
|
||||
|
||||
StructureTerrain terrain() {
|
||||
return fit.resolvedTerrain();
|
||||
}
|
||||
|
||||
TerrainAdaptation adaptation() {
|
||||
return start.adaptation();
|
||||
}
|
||||
|
||||
StructureStep step() {
|
||||
return start.step();
|
||||
}
|
||||
|
||||
int chunkX() {
|
||||
return start.chunkX();
|
||||
}
|
||||
|
||||
int chunkZ() {
|
||||
return start.chunkZ();
|
||||
}
|
||||
|
||||
List<FitPiece> pieces() {
|
||||
return pieces;
|
||||
}
|
||||
|
||||
/** The box around every piece of the start. */
|
||||
Box contentBounds() {
|
||||
Box bounds = pieces.getFirst().box();
|
||||
for (FitPiece piece : pieces) {
|
||||
bounds = bounds.encapsulating(piece.box());
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Object key() {
|
||||
return start.key();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureStilts;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
/**
|
||||
* Foundation columns under a placed start: in every column of the start's foundation envelope (the pieces' lowest
|
||||
* layers up to one above their ground), from the lowest solid block placed there down to the first block that can
|
||||
* carry it, the terrain's surface for a surface structure, at most {@code maxDepth} blocks deep. Sparse stilts keep
|
||||
* only the columns on their spacing grid.
|
||||
*
|
||||
* <p>These are the vanilla structures' stilts. Objects grow theirs from their own bottom layer instead
|
||||
* ({@code iris:stilt}): repeated object blocks, eroded or organic tips and a ceiling hang have no counterpart here, and
|
||||
* these columns have no counterpart there, so the two stay separate.
|
||||
*/
|
||||
final class FoundationStilts {
|
||||
private static final int FOUNDATION_VERTICAL_TOLERANCE = 1;
|
||||
|
||||
private FoundationStilts() {
|
||||
}
|
||||
|
||||
static void placeStilts(FitBlocks blocks, Box area, FitStart start, StructureStilts settings, long seed,
|
||||
FitPalettes palettes, IntBinaryOperator surfaceHeight, boolean surfaceStructure) {
|
||||
Objects.requireNonNull(surfaceHeight, "Structure stilts require an Iris terrain height resolver");
|
||||
Optional<PaletteSpec> palette = settings.palette();
|
||||
long paletteSeed = seed ^ start.structureId().hashCode();
|
||||
for (FoundationColumn column : foundationEnvelope(area, start)) {
|
||||
if (!isStiltColumn(column.x(), column.z(), settings.spacing())) {
|
||||
continue;
|
||||
}
|
||||
int foundationY = findFoundationY(blocks, column);
|
||||
if (foundationY == Integer.MIN_VALUE) {
|
||||
continue;
|
||||
}
|
||||
int terrainY = surfaceStructure
|
||||
? Math.max(area.minY(), Math.min(area.maxY(), surfaceHeight.applyAsInt(column.x(), column.z())))
|
||||
: area.minY() - 1;
|
||||
int anchorY = findStiltAnchorY(blocks, column.x(), column.z(), foundationY,
|
||||
Math.max(1, settings.maxDepth()), terrainY, area.minY());
|
||||
if (anchorY == Integer.MIN_VALUE) {
|
||||
continue;
|
||||
}
|
||||
for (int y = foundationY - 1; y > anchorY; y--) {
|
||||
BlockState stilt = palette.isEmpty()
|
||||
? FitBlocks.COBBLESTONE
|
||||
: Objects.requireNonNull(palettes.at(palette.get(), paletteSeed, column.x(), y, column.z()),
|
||||
"Stilt palette returned no block for " + start.structureId() + " at "
|
||||
+ column.x() + "," + y + "," + column.z());
|
||||
blocks.set(column.x(), y, column.z(), stilt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isStiltColumn(int x, int z, int spacing) {
|
||||
int resolvedSpacing = Math.max(1, spacing);
|
||||
return resolvedSpacing == 1 || Math.floorMod(x, resolvedSpacing) == 0 && Math.floorMod(z, resolvedSpacing) == 0;
|
||||
}
|
||||
|
||||
static int findStiltAnchorY(FitBlocks blocks, int x, int z, int foundationY, int maxDepth, int terrainY,
|
||||
int areaMinY) {
|
||||
int minimumAnchorY = Math.max(areaMinY, Math.max(terrainY, foundationY - maxDepth - 1));
|
||||
for (int y = foundationY - 1; y >= minimumAnchorY; y--) {
|
||||
BlockState state = blocks.get(x, y, z);
|
||||
if (!blocks.isTaggedVegetation(state) && blocks.sturdyTop(x, y, z)) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static List<FoundationColumn> foundationEnvelope(Box area, FitStart start) {
|
||||
Box structure = start.contentBounds();
|
||||
int minX = Math.max(area.minX(), structure.minX());
|
||||
int minZ = Math.max(area.minZ(), structure.minZ());
|
||||
int maxX = Math.min(area.maxX(), structure.maxX());
|
||||
int maxZ = Math.min(area.maxZ(), structure.maxZ());
|
||||
if (minX > maxX || minZ > maxZ) {
|
||||
return List.of();
|
||||
}
|
||||
List<FoundationColumn> columns = new ArrayList<>((maxX - minX + 1) * (maxZ - minZ + 1));
|
||||
BitSet envelope = new BitSet(area.ySpan());
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
envelope.clear();
|
||||
markFoundationEnvelope(envelope, start, area, x, z);
|
||||
int cellCount = envelope.cardinality();
|
||||
if (cellCount == 0) {
|
||||
continue;
|
||||
}
|
||||
int[] ys = new int[cellCount];
|
||||
int cell = 0;
|
||||
for (int bit = envelope.nextSetBit(0); bit >= 0; bit = envelope.nextSetBit(bit + 1)) {
|
||||
ys[cell++] = area.minY() + bit;
|
||||
}
|
||||
columns.add(new FoundationColumn(x, z, ys));
|
||||
}
|
||||
}
|
||||
return List.copyOf(columns);
|
||||
}
|
||||
|
||||
private static void markFoundationEnvelope(BitSet envelope, FitStart start, Box area, int x, int z) {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
Box bounds = piece.box();
|
||||
if (x < bounds.minX() || x > bounds.maxX() || z < bounds.minZ() || z > bounds.maxZ()) {
|
||||
continue;
|
||||
}
|
||||
int groundY = piece.groundY();
|
||||
if (piece.isJigsaw() && groundY < bounds.minY()) {
|
||||
continue;
|
||||
}
|
||||
int minY = Math.max(area.minY(), bounds.minY());
|
||||
int maxY = Math.min(area.maxY(), Math.min(bounds.maxY(), groundY + FOUNDATION_VERTICAL_TOLERANCE));
|
||||
if (minY <= maxY) {
|
||||
envelope.set(minY - area.minY(), maxY - area.minY() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int findFoundationY(FitBlocks blocks, FoundationColumn column) {
|
||||
for (int y : column.ys()) {
|
||||
if (blocks.isSolid(blocks.get(column.x(), y, column.z()))) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private record FoundationColumn(int x, int z, int[] ys) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Closes the short gaps between two rigid pieces of one surface start whose ground planes are one or two blocks apart:
|
||||
* where the upper piece's lowest solid base sits two blocks over the lower piece's ground, the gap is filled with the
|
||||
* terrain under the lower piece, so steps and terraces stand on ground instead of air. Only the chunk's own blocks are
|
||||
* filled, never across starts, and nothing at all when the work would exceed its budget.
|
||||
*/
|
||||
final class RigidSupport {
|
||||
private static final int MAX_BATCH_CELLS = 524_288;
|
||||
private static final int MAX_BRIDGE_SPAN = 2;
|
||||
|
||||
private RigidSupport() {
|
||||
}
|
||||
|
||||
static Set<Long> bridgeRigidPieceSupport(FitBlocks blocks, Box area, List<FitStart> starts) {
|
||||
if (starts.isEmpty()) {
|
||||
return Set.of();
|
||||
}
|
||||
Map<Long, BlockState> planned;
|
||||
try {
|
||||
BatchCellBudget budget = new BatchCellBudget();
|
||||
List<SupportRequest> requests = new ArrayList<>();
|
||||
Set<Object> seenStarts = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
for (FitStart start : starts) {
|
||||
if (!SurfaceFitting.requiresSurfaceTerrain(start) || !seenStarts.add(start.key())) {
|
||||
continue;
|
||||
}
|
||||
collectStartRequests(blocks, area, start, budget, requests);
|
||||
}
|
||||
planned = planWrites(blocks, area, requests, budget);
|
||||
} catch (BatchBudgetExceeded ignored) {
|
||||
return Set.of();
|
||||
}
|
||||
if (planned.isEmpty()) {
|
||||
return Set.of();
|
||||
}
|
||||
List<Map.Entry<Long, BlockState>> ordered = new ArrayList<>(planned.entrySet());
|
||||
ordered.sort(Map.Entry.comparingByKey());
|
||||
Set<Long> written = new HashSet<>();
|
||||
for (Map.Entry<Long, BlockState> entry : ordered) {
|
||||
int x = TemplateFootprint.packedX(entry.getKey());
|
||||
int y = TemplateFootprint.packedY(entry.getKey());
|
||||
int z = TemplateFootprint.packedZ(entry.getKey());
|
||||
BlockState existing = blocks.get(x, y, z);
|
||||
if (!blocks.isSolid(existing) && !blocks.isTree(existing) && !blocks.holdsFluid(existing)) {
|
||||
blocks.set(x, y, z, entry.getValue());
|
||||
written.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
return Set.copyOf(written);
|
||||
}
|
||||
|
||||
private static void collectStartRequests(FitBlocks blocks, Box area, FitStart start, BatchCellBudget budget,
|
||||
List<SupportRequest> requests) {
|
||||
List<RigidAnchor> anchors = rigidAnchors(start);
|
||||
if (anchors.size() < 2) {
|
||||
return;
|
||||
}
|
||||
for (RigidAnchor upper : anchors) {
|
||||
Map<Long, Integer> lowerMeets = candidateLowerMeets(area, upper, anchors, budget);
|
||||
if (lowerMeets.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
TemplateCells cells = upper.piece().cells(area);
|
||||
budget.consume(cells.readBlocks());
|
||||
if (!cells.resolved()) {
|
||||
continue;
|
||||
}
|
||||
for (Map.Entry<Long, TemplateFootprint.Cell> entry
|
||||
: lowestBridgeableCells(cells, upper.piece(), area, lowerMeets).entrySet()) {
|
||||
TemplateFootprint.Cell cell = entry.getValue();
|
||||
Integer lowerMeet = lowerMeets.get(entry.getKey());
|
||||
if (lowerMeet == null || cell.blocker() || !blocks.isSolidBase(cell.state())
|
||||
|| cell.y() - lowerMeet < 2 || cell.y() - lowerMeet > MAX_BRIDGE_SPAN) {
|
||||
continue;
|
||||
}
|
||||
budget.consume(1);
|
||||
requests.add(new SupportRequest(cell.x(), cell.z(), lowerMeet, cell.y()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The lowest cell of each column over a lower piece's ground, among the cells no higher than the widest bridge
|
||||
* above that ground: the cells the support could stand under.
|
||||
*/
|
||||
private static Map<Long, TemplateFootprint.Cell> lowestBridgeableCells(TemplateCells cells, FitPiece piece, Box area,
|
||||
Map<Long, Integer> lowerMeets) {
|
||||
Map<Long, TemplateFootprint.Cell> lowest = new HashMap<>();
|
||||
for (int cell = 0; cell < cells.size(); cell++) {
|
||||
int x = cells.x(cell);
|
||||
int y = piece.cellY(cells, cell);
|
||||
int z = cells.z(cell);
|
||||
long column = TemplateFootprint.columnKey(x, z);
|
||||
Integer lowerMeet = lowerMeets.get(column);
|
||||
if (!area.contains(x, y, z) || lowerMeet == null || y > lowerMeet + MAX_BRIDGE_SPAN) {
|
||||
continue;
|
||||
}
|
||||
TemplateFootprint.Cell current = lowest.get(column);
|
||||
if (current == null || y < current.y()) {
|
||||
lowest.put(column, new TemplateFootprint.Cell(x, y, z, cells.state(cell)));
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
private static List<RigidAnchor> rigidAnchors(FitStart start) {
|
||||
List<RigidAnchor> anchors = new ArrayList<>();
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (!piece.isRigid()) {
|
||||
continue;
|
||||
}
|
||||
anchors.add(new RigidAnchor(piece, piece.box(), piece.groundY() - 1));
|
||||
}
|
||||
return List.copyOf(anchors);
|
||||
}
|
||||
|
||||
private static Map<Long, Integer> candidateLowerMeets(Box area, RigidAnchor upper, List<RigidAnchor> anchors,
|
||||
BatchCellBudget budget) {
|
||||
Map<Long, Integer> lowerMeets = new HashMap<>();
|
||||
for (RigidAnchor lower : anchors) {
|
||||
budget.consume(1);
|
||||
int span = upper.meetY() - lower.meetY();
|
||||
if (lower.piece() == upper.piece() || span < 1 || span > MAX_BRIDGE_SPAN
|
||||
|| lower.meetY() < area.minY() || lower.meetY() > area.maxY()) {
|
||||
continue;
|
||||
}
|
||||
int minimumX = Math.max(area.minX(), Math.max(upper.bounds().minX(), lower.bounds().minX()));
|
||||
int maximumX = Math.min(area.maxX(), Math.min(upper.bounds().maxX(), lower.bounds().maxX()));
|
||||
int minimumZ = Math.max(area.minZ(), Math.max(upper.bounds().minZ(), lower.bounds().minZ()));
|
||||
int maximumZ = Math.min(area.maxZ(), Math.min(upper.bounds().maxZ(), lower.bounds().maxZ()));
|
||||
if (minimumX > maximumX || minimumZ > maximumZ) {
|
||||
continue;
|
||||
}
|
||||
for (int x = minimumX; x <= maximumX; x++) {
|
||||
for (int z = minimumZ; z <= maximumZ; z++) {
|
||||
budget.consume(1);
|
||||
lowerMeets.merge(TemplateFootprint.columnKey(x, z), lower.meetY(), Math::max);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lowerMeets;
|
||||
}
|
||||
|
||||
private static Map<Long, BlockState> planWrites(FitBlocks blocks, Box area, List<SupportRequest> requests,
|
||||
BatchCellBudget budget) {
|
||||
List<SupportRequest> eligible = new ArrayList<>();
|
||||
Set<MaterialKey> materialKeys = new HashSet<>();
|
||||
for (SupportRequest request : requests) {
|
||||
BlockState lowerTerrain = blocks.get(request.x(), request.lowerMeetY(), request.z());
|
||||
if (!isTerrainSupport(blocks, lowerTerrain) || !gapIsClear(blocks, area, request, budget)) {
|
||||
continue;
|
||||
}
|
||||
eligible.add(request);
|
||||
materialKeys.add(new MaterialKey(request.x(), request.z(), request.lowerMeetY()));
|
||||
}
|
||||
Map<MaterialKey, BlockState> materials = new HashMap<>();
|
||||
for (MaterialKey key : materialKeys) {
|
||||
materials.put(key, resolveSupportState(blocks, key.x(), key.z(), key.lowerMeetY(), budget));
|
||||
}
|
||||
Map<Long, BlockState> planned = new HashMap<>();
|
||||
Set<Long> conflicts = new HashSet<>();
|
||||
eligible.sort(Comparator.comparingInt(SupportRequest::x)
|
||||
.thenComparingInt(SupportRequest::z)
|
||||
.thenComparingInt(SupportRequest::lowerMeetY)
|
||||
.thenComparingInt(SupportRequest::baseY));
|
||||
for (SupportRequest request : eligible) {
|
||||
BlockState material = materials.get(new MaterialKey(request.x(), request.z(), request.lowerMeetY()));
|
||||
for (int y = request.lowerMeetY() + 1; y < request.baseY(); y++) {
|
||||
budget.consume(1);
|
||||
long positionKey = TemplateFootprint.packedPosition(request.x(), y, request.z());
|
||||
if (conflicts.contains(positionKey)) {
|
||||
continue;
|
||||
}
|
||||
BlockState existing = planned.putIfAbsent(positionKey, material);
|
||||
if (existing != null && !existing.equals(material)) {
|
||||
planned.remove(positionKey);
|
||||
conflicts.add(positionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
return planned;
|
||||
}
|
||||
|
||||
private static boolean gapIsClear(FitBlocks blocks, Box area, SupportRequest request, BatchCellBudget budget) {
|
||||
for (int y = request.lowerMeetY() + 1; y < request.baseY(); y++) {
|
||||
budget.consume(1);
|
||||
if (!area.contains(request.x(), y, request.z())) {
|
||||
return false;
|
||||
}
|
||||
BlockState state = blocks.get(request.x(), y, request.z());
|
||||
if (blocks.isSolid(state) || blocks.isTree(state) || blocks.holdsFluid(state)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static BlockState resolveSupportState(FitBlocks blocks, int x, int z, int lowerMeetY, BatchCellBudget budget) {
|
||||
budget.consume(1);
|
||||
BlockState below = blocks.get(x, lowerMeetY - 1, z);
|
||||
if (isTerrainSupport(blocks, below)) {
|
||||
return below;
|
||||
}
|
||||
return blocks.get(x, lowerMeetY, z);
|
||||
}
|
||||
|
||||
private static boolean isTerrainSupport(FitBlocks blocks, BlockState state) {
|
||||
return blocks.isSolid(state) && !blocks.isTree(state) && !blocks.holdsFluid(state);
|
||||
}
|
||||
|
||||
private record RigidAnchor(FitPiece piece, Box bounds, int meetY) {
|
||||
}
|
||||
|
||||
private record SupportRequest(int x, int z, int lowerMeetY, int baseY) {
|
||||
}
|
||||
|
||||
private record MaterialKey(int x, int z, int lowerMeetY) {
|
||||
}
|
||||
|
||||
private static final class BatchCellBudget {
|
||||
private int consumed;
|
||||
|
||||
private void consume(int amount) {
|
||||
if (amount < 0 || consumed > MAX_BATCH_CELLS - amount) {
|
||||
throw BatchBudgetExceeded.INSTANCE;
|
||||
}
|
||||
consumed += amount;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BatchBudgetExceeded extends RuntimeException {
|
||||
private static final BatchBudgetExceeded INSTANCE = new BatchBudgetExceeded();
|
||||
|
||||
private BatchBudgetExceeded() {
|
||||
super(null, null, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureYBand;
|
||||
import art.arcane.iris.engine.framework.structure.NativeStructureFit;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.vanilla.PlatformStart;
|
||||
import com.volmit.vanilla.StartReach;
|
||||
|
||||
/**
|
||||
* Where the platform's own starts sit and how far {@code iris:structure} changes the terrain around a start. A start
|
||||
* that keeps the platform's height only takes its shift; a band moves the start's middle into it, chosen per start
|
||||
* chunk; an underground start is buried under the lowest terrain column above it; anything else takes its shift. A
|
||||
* structure the host aligns itself only takes its shift on top of that alignment.
|
||||
*/
|
||||
public final class StartLayouts {
|
||||
private static final int MAX_BURIAL_COLUMNS = 2_000_000;
|
||||
private static final int UNDERGROUND_SURFACE_CLEARANCE = 1;
|
||||
private static final long BAND_IDENTITY_X = 341873128712L;
|
||||
private static final long BAND_IDENTITY_Z = 132897987541L;
|
||||
|
||||
private StartLayouts() {
|
||||
}
|
||||
|
||||
/** How far {@code start} moves up (negative: down) under {@code fit}, before the host keeps it inside the world. */
|
||||
public static int shift(PlatformStart start, NativeStructureFit fit) {
|
||||
if (start.aligned() || fit.keepsSourceY()) {
|
||||
return fit.yShift();
|
||||
}
|
||||
if (fit.yBand() != null) {
|
||||
return bandShift(start, fit.yBand());
|
||||
}
|
||||
if (start.underground()) {
|
||||
return burialShift(start, fit.yShift());
|
||||
}
|
||||
return fit.yShift();
|
||||
}
|
||||
|
||||
/** How far around its pieces a start with {@code terrain} changes the terrain. */
|
||||
public static StartReach reach(StructureTerrain terrain) {
|
||||
return switch (terrain.resolvedMode()) {
|
||||
case SOURCE -> StartReach.PLATFORM;
|
||||
case PRESERVE -> StartReach.blocks(0);
|
||||
case VACUUM -> StartReach.blocks(SurfaceFitting.surfaceTerrainRadius());
|
||||
case BORE, FORCE_CARVE, ENCASE -> StartReach.blocks(Math.max(0, terrain.horizontalPadding()));
|
||||
};
|
||||
}
|
||||
|
||||
private static int bandShift(PlatformStart start, StructureYBand band) {
|
||||
BlockBox bounds = start.bounds();
|
||||
int minY = bounds.minY() + start.bottomY();
|
||||
int maxY = bounds.maxY() - 1 + start.bottomY();
|
||||
int target = bandTargetMidpointY(minY, maxY, band.resolvedMin(), band.resolvedMax(), start.chunkX(), start.chunkZ());
|
||||
return Math.subtractExact(target, minY + (maxY - minY) / 2);
|
||||
}
|
||||
|
||||
/** The world height the middle of a start from {@code maxY - minY} high moves to, inside the band, per start chunk. */
|
||||
static int bandTargetMidpointY(int minY, int maxY, int bandMin, int bandMax, int chunkX, int chunkZ) {
|
||||
int height = Math.subtractExact(maxY, minY);
|
||||
int lowest = Math.addExact(bandMin, height / 2);
|
||||
int highest = Math.subtractExact(bandMax, height - height / 2);
|
||||
if (lowest > highest) {
|
||||
// The band is shorter than the structure, so only its midpoint can be honoured.
|
||||
return Math.floorDiv(Math.addExact(bandMin, bandMax), 2);
|
||||
}
|
||||
int span = highest - lowest + 1;
|
||||
if (span == 1) {
|
||||
return lowest;
|
||||
}
|
||||
long identity = (long) chunkX * BAND_IDENTITY_X ^ (long) chunkZ * BAND_IDENTITY_Z;
|
||||
return lowest + new RNG(identity).nextInt(span);
|
||||
}
|
||||
|
||||
/** At most {@code requestedShift}, and low enough that the start's top stays a block under every terrain column. */
|
||||
private static int burialShift(PlatformStart start, int requestedShift) {
|
||||
BlockBox bounds = start.bounds();
|
||||
long width = (long) bounds.maxX() - bounds.minX();
|
||||
long depth = (long) bounds.maxZ() - bounds.minZ();
|
||||
if (width <= 0L || depth <= 0L || width > MAX_BURIAL_COLUMNS / depth) {
|
||||
throw new IllegalStateException("Underground native structure burial footprint is invalid or exceeds "
|
||||
+ MAX_BURIAL_COLUMNS + " columns");
|
||||
}
|
||||
int topY = bounds.maxY() - 1;
|
||||
int maximumShift = requestedShift;
|
||||
for (int x = bounds.minX(); x < bounds.maxX(); x++) {
|
||||
for (int z = bounds.minZ(); z < bounds.maxZ(); z++) {
|
||||
int allowedTopY = start.surfaceY(x, z) - UNDERGROUND_SURFACE_CLEARANCE;
|
||||
maximumShift = Math.min(maximumShift, allowedTopY - topY);
|
||||
}
|
||||
}
|
||||
return maximumShift;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureStilts;
|
||||
import art.arcane.iris.engine.framework.structure.ImportedStructures;
|
||||
import art.arcane.iris.engine.framework.structure.NativeStructureFit;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
/**
|
||||
* How {@code iris:structure} fits the platform's starts into one chunk. Before any piece is placed it fits the
|
||||
* surface around SOURCE beard and VACUUM starts, integrates the terrain of every start and bridges short gaps between
|
||||
* rigid pieces; after each start's pieces it builds that start's stilts, and after the last one it repairs the gaps
|
||||
* left under VACUUM foundations. A start the module placed itself is fitted the way its memo records; one of the
|
||||
* platform's own starts the way the dimension's {@code importedStructures} adjust it today.
|
||||
*/
|
||||
public final class StructureFitting {
|
||||
private StructureFitting() {
|
||||
}
|
||||
|
||||
public static void beforePieces(StructureFit fit) {
|
||||
chunkOf(fit).prepare();
|
||||
}
|
||||
|
||||
public static void afterPieces(StructureFit fit, StructureFit.Start placed) {
|
||||
ChunkFit chunk = chunkOf(fit);
|
||||
chunk.buildStilts(placed);
|
||||
if (placed == fit.starts().getLast()) {
|
||||
chunk.repairFoundations();
|
||||
}
|
||||
}
|
||||
|
||||
private static ChunkFit chunkOf(StructureFit fit) {
|
||||
return fit.state(ChunkFit.class, () -> new ChunkFit(fit));
|
||||
}
|
||||
|
||||
/** One chunk's fit: its starts with their resolved fits, and the foundations VACUUM raised the terrain to. */
|
||||
private static final class ChunkFit {
|
||||
private final StructureFit fit;
|
||||
private final FitBlocks blocks;
|
||||
private final Box area;
|
||||
private final List<FitStart> starts;
|
||||
private final IntBinaryOperator surfaceHeight;
|
||||
private SurfaceFitting.VacuumFoundationPlan vacuumFoundations = SurfaceFitting.VacuumFoundationPlan.EMPTY;
|
||||
|
||||
private ChunkFit(StructureFit fit) {
|
||||
this.fit = fit;
|
||||
this.blocks = new FitBlocks(fit.blocks(), fit.bottomY());
|
||||
this.area = Box.of(fit.area(), fit.bottomY());
|
||||
this.starts = resolvedStarts(fit);
|
||||
this.surfaceHeight = (x, z) -> fit.surfaceY(x, z) + fit.bottomY();
|
||||
}
|
||||
|
||||
private static List<FitStart> resolvedStarts(StructureFit fit) {
|
||||
List<FitStart> starts = new ArrayList<>(fit.starts().size());
|
||||
for (StructureFit.Start start : fit.starts()) {
|
||||
starts.add(new FitStart(start, fitOf(fit, start), fit.bottomY()));
|
||||
}
|
||||
return List.copyOf(starts);
|
||||
}
|
||||
|
||||
private static NativeStructureFit fitOf(StructureFit fit, StructureFit.Start start) {
|
||||
return start.memo()
|
||||
.map(NativeStructureFit::of)
|
||||
.orElseGet(() -> ImportedStructures.of(fit.world().settings())
|
||||
.adjustment(start.structure().toString(), start.step().isUnderground()));
|
||||
}
|
||||
|
||||
private void prepare() {
|
||||
vacuumFoundations = SurfaceFitting.prepareSurfaceStructures(blocks, area, starts, surfaceHeight,
|
||||
SurfaceFitting.MAX_SURFACE_TEMPLATE_CELLS);
|
||||
TerrainIntegration.prepareTerrain(blocks, area, starts, fit.seed(), this::naturalBlock, this::paletteBlock);
|
||||
RigidSupport.bridgeRigidPieceSupport(blocks, area, starts);
|
||||
}
|
||||
|
||||
private void buildStilts(StructureFit.Start placed) {
|
||||
FitStart start = fitStartOf(placed);
|
||||
StructureStilts stilts = start.fit().stilts();
|
||||
if (stilts == null) {
|
||||
return;
|
||||
}
|
||||
FoundationStilts.placeStilts(blocks, area, start, stilts, fit.seed(), this::paletteBlock, surfaceHeight,
|
||||
!start.step().isUnderground());
|
||||
}
|
||||
|
||||
private void repairFoundations() {
|
||||
SurfaceFitting.repairVacuumFoundations(blocks, area, vacuumFoundations);
|
||||
}
|
||||
|
||||
private FitStart fitStartOf(StructureFit.Start placed) {
|
||||
for (FitStart start : starts) {
|
||||
if (start.start() == placed) {
|
||||
return start;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Start " + placed.structure() + " is not one of the chunk's starts");
|
||||
}
|
||||
|
||||
private BlockState naturalBlock(int worldY) {
|
||||
return fit.naturalBlock(worldY - fit.bottomY());
|
||||
}
|
||||
|
||||
private BlockState paletteBlock(PaletteSpec palette, long seed, int x, int y, int z) {
|
||||
return fit.world().resources().blocks().palette(palette, seed).at(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,713 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectVacuum;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.vanilla.StructureStep;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
import com.volmit.vanilla.TerrainAdaptation;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
/**
|
||||
* Fits the surface around the platform's surface structures before their pieces are placed. SOURCE replays the
|
||||
* platform's beard adaptation: the terrain within 12 blocks of the structure's ground planes bends toward them, never
|
||||
* more than 6 blocks. VACUUM raises the terrain to meet the processed solid foundations of rigid pieces, again over 12
|
||||
* blocks, without ever lowering it, and after the pieces are placed fills the gaps left under their bases
|
||||
* ({@link #repairVacuumFoundations}).
|
||||
*/
|
||||
final class SurfaceFitting {
|
||||
private static final double SURFACE_TERRAIN_FALLOFF = 2.0;
|
||||
private static final long SURFACE_TERRAIN_INFLUENCE_SCALE = 1_000_000L;
|
||||
private static final int SURFACE_TERRAIN_RADIUS = 12;
|
||||
private static final int MAX_SOURCE_SURFACE_DELTA = 6;
|
||||
static final int MAX_SURFACE_TEMPLATE_CELLS = 4_194_304;
|
||||
private static final int FOUNDATION_ANCHOR_STRENGTH = 2;
|
||||
private static final int JUNCTION_ANCHOR_STRENGTH = 1;
|
||||
private static final Set<String> WARNED_SOURCE_BUDGET = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<String> WARNED_VACUUM_BUDGET = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private SurfaceFitting() {
|
||||
}
|
||||
|
||||
/** The radius of the surface falloff, which a VACUUM start reaches beyond its pieces. */
|
||||
static int surfaceTerrainRadius() {
|
||||
return SURFACE_TERRAIN_RADIUS;
|
||||
}
|
||||
|
||||
static VacuumFoundationPlan prepareSurfaceStructures(FitBlocks blocks, Box area, List<FitStart> starts,
|
||||
IntBinaryOperator surfaceHeight, int maximumTemplateCells) {
|
||||
if (starts.isEmpty()) {
|
||||
return VacuumFoundationPlan.EMPTY;
|
||||
}
|
||||
Objects.requireNonNull(surfaceHeight, "Surface structure terrain fitting requires an Iris height resolver");
|
||||
List<SurfaceAnchor> anchors = collectSourceSurfaceAnchors(blocks, area, starts, maximumTemplateCells);
|
||||
if (!anchors.isEmpty()) {
|
||||
fitSurfaceTerrain(blocks, area, anchors, surfaceHeight);
|
||||
}
|
||||
VacuumFootprint vacuum = collectVacuumFootprint(blocks, area, starts, maximumTemplateCells);
|
||||
if (!vacuum.anchors().isEmpty()) {
|
||||
fitVacuumTerrain(blocks, area, vacuum, surfaceHeight);
|
||||
}
|
||||
return VacuumFoundationPlan.create(vacuum.foundationBases(), vacuum.occupiedCells(), area);
|
||||
}
|
||||
|
||||
static void repairVacuumFoundations(FitBlocks blocks, Box area, VacuumFoundationPlan plan) {
|
||||
if (plan == null || plan.foundationBases.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (long packedBase : plan.foundationBases) {
|
||||
int baseX = TemplateFootprint.packedX(packedBase);
|
||||
int baseY = TemplateFootprint.packedY(packedBase);
|
||||
int baseZ = TemplateFootprint.packedZ(packedBase);
|
||||
if (!area.contains(baseX, baseY, baseZ)) {
|
||||
continue;
|
||||
}
|
||||
if (!blocks.isSolidBase(blocks.get(baseX, baseY, baseZ))) {
|
||||
continue;
|
||||
}
|
||||
int supportY = findVacuumFoundationSupport(blocks, area, baseX, baseY - 1, baseZ);
|
||||
if (supportY == Integer.MIN_VALUE || supportY == baseY - 1) {
|
||||
continue;
|
||||
}
|
||||
if (intersectsVacuumOccupancy(plan.occupiedCells, baseX, baseZ, supportY + 1, baseY - 1)) {
|
||||
continue;
|
||||
}
|
||||
BlockState fill = resolveSurfaceMaterials(blocks, baseX, baseZ, supportY, area.minY()).subsurface();
|
||||
for (int y = supportY + 1; y < baseY; y++) {
|
||||
BlockState existing = blocks.get(baseX, y, baseZ);
|
||||
if (blocks.isAir(existing) || blocks.holdsFluid(existing)) {
|
||||
blocks.set(baseX, y, baseZ, fill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean shouldPrepareSurfaceTerrain(TerrainAdaptation adaptation, StructureStep step) {
|
||||
return step == StructureStep.SURFACE_STRUCTURES
|
||||
&& (adaptation == TerrainAdaptation.BEARD_THIN || adaptation == TerrainAdaptation.BEARD_BOX);
|
||||
}
|
||||
|
||||
static int resolveSurfaceTarget(List<SurfaceAnchor> anchors, int worldX, int worldZ, int originalY) {
|
||||
return resolveSurface(anchors, worldX, worldZ, originalY).targetY();
|
||||
}
|
||||
|
||||
private static SurfaceResolution resolveSurface(List<SurfaceAnchor> anchors, int worldX, int worldZ, int originalY) {
|
||||
int localTargetY = originalY;
|
||||
SurfaceAnchor selectedLocal = null;
|
||||
long totalInfluence = 0L;
|
||||
long weightedTargetY = 0L;
|
||||
long maximumInfluence = 0L;
|
||||
for (SurfaceAnchor anchor : anchors) {
|
||||
int outX = IrisObjectVacuum.outset(worldX, anchor.minX(), anchor.maxX());
|
||||
int outZ = IrisObjectVacuum.outset(worldZ, anchor.minZ(), anchor.maxZ());
|
||||
boolean containsColumn = outX == 0 && outZ == 0;
|
||||
long distanceSquared = (long) outX * outX + (long) outZ * outZ;
|
||||
long radiusSquared = (long) SURFACE_TERRAIN_RADIUS * SURFACE_TERRAIN_RADIUS;
|
||||
if (distanceSquared > radiusSquared) {
|
||||
continue;
|
||||
}
|
||||
double distance = Math.sqrt(distanceSquared);
|
||||
double factor = Math.pow(1D - distance / SURFACE_TERRAIN_RADIUS, SURFACE_TERRAIN_FALLOFF);
|
||||
if (factor <= 0D) {
|
||||
continue;
|
||||
}
|
||||
int boundedTargetY = boundedSurfaceTarget(originalY, anchor.meetY());
|
||||
if (containsColumn) {
|
||||
if (precedes(anchor, selectedLocal)) {
|
||||
localTargetY = boundedTargetY;
|
||||
selectedLocal = anchor;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
long influence = Math.round(factor * SURFACE_TERRAIN_INFLUENCE_SCALE);
|
||||
if (influence <= 0L) {
|
||||
continue;
|
||||
}
|
||||
long weightedInfluence = influence * Math.max(1, anchor.strength());
|
||||
totalInfluence += weightedInfluence;
|
||||
weightedTargetY += weightedInfluence * boundedTargetY;
|
||||
maximumInfluence = Math.max(maximumInfluence, influence);
|
||||
}
|
||||
if (selectedLocal != null) {
|
||||
return new SurfaceResolution(localTargetY,
|
||||
selectedLocal.strength() > 1 && localTargetY == selectedLocal.meetY());
|
||||
}
|
||||
if (totalInfluence == 0L) {
|
||||
return new SurfaceResolution(originalY, false);
|
||||
}
|
||||
double blendedTargetY = weightedTargetY / (double) totalInfluence;
|
||||
double factor = maximumInfluence / (double) SURFACE_TERRAIN_INFLUENCE_SCALE;
|
||||
return new SurfaceResolution(blendSurfaceTarget(originalY, blendedTargetY, factor), false);
|
||||
}
|
||||
|
||||
private static int boundedSurfaceTarget(int originalY, int meetY) {
|
||||
int delta = Math.max(-MAX_SOURCE_SURFACE_DELTA, Math.min(MAX_SOURCE_SURFACE_DELTA, meetY - originalY));
|
||||
return originalY + delta;
|
||||
}
|
||||
|
||||
private static int blendSurfaceTarget(int originalY, double targetY, double factor) {
|
||||
double delta = (targetY - originalY) * factor;
|
||||
int magnitude = (int) Math.round(Math.abs(delta));
|
||||
return originalY + (delta < 0D ? -magnitude : magnitude);
|
||||
}
|
||||
|
||||
private static boolean precedes(SurfaceAnchor candidate, SurfaceAnchor selected) {
|
||||
if (selected == null) {
|
||||
return true;
|
||||
}
|
||||
if (candidate.strength() != selected.strength()) {
|
||||
return candidate.strength() > selected.strength();
|
||||
}
|
||||
if (candidate.meetY() != selected.meetY()) {
|
||||
return candidate.meetY() < selected.meetY();
|
||||
}
|
||||
if (candidate.minX() != selected.minX()) {
|
||||
return candidate.minX() < selected.minX();
|
||||
}
|
||||
if (candidate.minZ() != selected.minZ()) {
|
||||
return candidate.minZ() < selected.minZ();
|
||||
}
|
||||
if (candidate.maxX() != selected.maxX()) {
|
||||
return candidate.maxX() < selected.maxX();
|
||||
}
|
||||
if (candidate.maxZ() != selected.maxZ()) {
|
||||
return candidate.maxZ() < selected.maxZ();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<SurfaceAnchor> collectSourceSurfaceAnchors(FitBlocks blocks, Box area, List<FitStart> starts,
|
||||
int maximumTemplateCells) {
|
||||
Box influenceArea = area.widened(SURFACE_TERRAIN_RADIUS);
|
||||
List<SurfaceAnchor> anchors = new ArrayList<>();
|
||||
Set<Object> seenStarts = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
for (FitStart start : starts) {
|
||||
if (!requiresSourceSurfaceTerrain(start) || !seenStarts.add(start.key())) {
|
||||
continue;
|
||||
}
|
||||
TemplateCellBudget budget = new TemplateCellBudget(maximumTemplateCells);
|
||||
boolean budgetExceeded = false;
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (piece.isJigsaw()) {
|
||||
if (!budgetExceeded && piece.box().intersectsHorizontally(influenceArea)) {
|
||||
try {
|
||||
List<SurfaceAnchor> pieceAnchors = new ArrayList<>();
|
||||
addProcessedSurfaceAnchors(blocks, influenceArea, piece, budget, pieceAnchors);
|
||||
anchors.addAll(pieceAnchors);
|
||||
} catch (TemplateBudgetExceeded ignored) {
|
||||
budgetExceeded = true;
|
||||
warnBudget(WARNED_SOURCE_BUDGET, start, "SOURCE",
|
||||
"skipping remaining processed footprints for this start");
|
||||
}
|
||||
}
|
||||
for (BlockPosition junction : piece.junctions()) {
|
||||
anchors.add(new SurfaceAnchor(junction.x(), junction.x(), junction.z(), junction.z(),
|
||||
junction.y() - 1, JUNCTION_ANCHOR_STRENGTH));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Box bounds = piece.box();
|
||||
anchors.add(surfaceAnchor(bounds, bounds.minY(), FOUNDATION_ANCHOR_STRENGTH));
|
||||
}
|
||||
}
|
||||
return List.copyOf(anchors);
|
||||
}
|
||||
|
||||
private static void addProcessedSurfaceAnchors(FitBlocks blocks, Box influenceArea, FitPiece piece,
|
||||
TemplateCellBudget budget, List<SurfaceAnchor> anchors) {
|
||||
TemplateCells cells = piece.cells(influenceArea);
|
||||
budget.consume(cells.readBlocks());
|
||||
if (!cells.resolved()) {
|
||||
return;
|
||||
}
|
||||
int maximumFoundationY = piece.groundY();
|
||||
for (TemplateFootprint.Cell cell : TemplateFootprint.lowestSolidCells(cells, piece, blocks).values()) {
|
||||
budget.consume(1);
|
||||
if (piece.isRigid() && cell.y() > maximumFoundationY) {
|
||||
continue;
|
||||
}
|
||||
int groundY = piece.isRigid() ? maximumFoundationY : cell.y();
|
||||
Box column = new Box(cell.x(), groundY, cell.z(), cell.x(), groundY, cell.z());
|
||||
anchors.add(surfaceAnchor(column, groundY, FOUNDATION_ANCHOR_STRENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
private static void warnBudget(Set<String> warned, FitStart start, String mode, String consequence) {
|
||||
if (warned.add(start.structureId())) {
|
||||
IrisLogging.warn("Native structure " + mode + " fitting for '" + start.structureId()
|
||||
+ "' exceeded its bounded template budget; " + consequence);
|
||||
}
|
||||
}
|
||||
|
||||
private static VacuumFootprint collectVacuumFootprint(FitBlocks blocks, Box area, List<FitStart> starts,
|
||||
int maximumTemplateCells) {
|
||||
Box influenceArea = area.widened(SURFACE_TERRAIN_RADIUS);
|
||||
Map<Long, VacuumAnchor> anchors = new HashMap<>();
|
||||
Map<Long, Integer> columnCaps = new HashMap<>();
|
||||
Set<Long> foundationBases = new HashSet<>();
|
||||
Set<Long> occupiedCells = new HashSet<>();
|
||||
Set<Object> seenStarts = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
for (FitStart start : starts) {
|
||||
if (start.terrain().resolvedMode() != StructureTerrainMode.VACUUM || !seenStarts.add(start.key())) {
|
||||
continue;
|
||||
}
|
||||
Map<Long, VacuumAnchor> targetAnchors = new HashMap<>();
|
||||
Map<Long, Integer> targetCaps = new HashMap<>();
|
||||
Set<Long> targetFoundationBases = new HashSet<>();
|
||||
Set<Long> targetOccupiedCells = new HashSet<>();
|
||||
TemplateCellBudget budget = new TemplateCellBudget(maximumTemplateCells);
|
||||
try {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (!piece.box().intersectsHorizontally(influenceArea) || !piece.isRigid()) {
|
||||
continue;
|
||||
}
|
||||
addVacuumJunctionAnchors(anchors, influenceArea, piece);
|
||||
TemplateCells cells = piece.cells(influenceArea);
|
||||
budget.consume(cells.readBlocks());
|
||||
if (!cells.resolved()) {
|
||||
continue;
|
||||
}
|
||||
for (int cell = 0; cell < cells.size(); cell++) {
|
||||
targetOccupiedCells.add(TemplateFootprint.packedPosition(
|
||||
cells.x(cell), piece.cellY(cells, cell), cells.z(cell)));
|
||||
}
|
||||
int groundY = piece.groundY() - 1;
|
||||
for (TemplateFootprint.Cell cell : TemplateFootprint.lowestCells(cells, piece).values()) {
|
||||
budget.consume(1);
|
||||
long column = TemplateFootprint.columnKey(cell.x(), cell.z());
|
||||
targetCaps.merge(column, Math.min(cell.y(), groundY), Math::min);
|
||||
if (cell.blocker() || cell.y() > groundY + 1 || !blocks.isSolidBase(cell.state())) {
|
||||
continue;
|
||||
}
|
||||
addVacuumAnchor(targetAnchors, cell.x(), cell.z(),
|
||||
new VacuumAnchor(cell.y() - 1, FOUNDATION_ANCHOR_STRENGTH));
|
||||
targetFoundationBases.add(TemplateFootprint.packedPosition(cell.x(), cell.y(), cell.z()));
|
||||
}
|
||||
}
|
||||
} catch (TemplateBudgetExceeded ignored) {
|
||||
warnBudget(WARNED_VACUUM_BUDGET, start, "VACUUM", "using jigsaw junction smoothing for oversized starts");
|
||||
continue;
|
||||
}
|
||||
targetAnchors.forEach((column, anchor) -> anchors.merge(column, anchor, SurfaceFitting::preferredVacuumAnchor));
|
||||
targetCaps.forEach((column, cap) -> columnCaps.merge(column, cap, Math::min));
|
||||
foundationBases.addAll(targetFoundationBases);
|
||||
occupiedCells.addAll(targetOccupiedCells);
|
||||
}
|
||||
return new VacuumFootprint(Map.copyOf(anchors), Map.copyOf(columnCaps),
|
||||
Set.copyOf(foundationBases), Set.copyOf(occupiedCells));
|
||||
}
|
||||
|
||||
private static void addVacuumJunctionAnchors(Map<Long, VacuumAnchor> anchors, Box influenceArea, FitPiece piece) {
|
||||
for (BlockPosition junction : piece.junctions()) {
|
||||
if (junction.x() < influenceArea.minX() || junction.x() > influenceArea.maxX()
|
||||
|| junction.z() < influenceArea.minZ() || junction.z() > influenceArea.maxZ()) {
|
||||
continue;
|
||||
}
|
||||
addVacuumAnchor(anchors, junction.x(), junction.z(),
|
||||
new VacuumAnchor(junction.y() - 1, JUNCTION_ANCHOR_STRENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
private static void addVacuumAnchor(Map<Long, VacuumAnchor> anchors, int x, int z, VacuumAnchor candidate) {
|
||||
anchors.merge(TemplateFootprint.columnKey(x, z), candidate, SurfaceFitting::preferredVacuumAnchor);
|
||||
}
|
||||
|
||||
private static VacuumAnchor preferredVacuumAnchor(VacuumAnchor first, VacuumAnchor second) {
|
||||
if (first.strength() != second.strength()) {
|
||||
return first.strength() > second.strength() ? first : second;
|
||||
}
|
||||
return first.surfaceY() <= second.surfaceY() ? first : second;
|
||||
}
|
||||
|
||||
static SurfaceAnchor surfaceAnchor(Box bounds, int groundY, int strength) {
|
||||
return new SurfaceAnchor(bounds.minX(), bounds.maxX(), bounds.minZ(), bounds.maxZ(), groundY - 1, strength);
|
||||
}
|
||||
|
||||
/** Whether the start's pieces need the surface fitted around them: VACUUM, or SOURCE with a beard adaptation. */
|
||||
static boolean requiresSurfaceTerrain(FitStart start) {
|
||||
return start.terrain().resolvedMode() == StructureTerrainMode.VACUUM || requiresSourceSurfaceTerrain(start);
|
||||
}
|
||||
|
||||
private static boolean requiresSourceSurfaceTerrain(FitStart start) {
|
||||
return start.terrain().resolvedMode() == StructureTerrainMode.SOURCE
|
||||
&& shouldPrepareSurfaceTerrain(start.adaptation(), start.step());
|
||||
}
|
||||
|
||||
private static void fitSurfaceTerrain(FitBlocks blocks, Box area, List<SurfaceAnchor> anchors,
|
||||
IntBinaryOperator surfaceHeight) {
|
||||
int width = area.xSpan();
|
||||
int depth = area.zSpan();
|
||||
int[] originalHeights = new int[width * depth];
|
||||
int[] targetHeights = new int[width * depth];
|
||||
boolean[] rigidBaseSupport = new boolean[width * depth];
|
||||
for (int z = area.minZ(); z <= area.maxZ(); z++) {
|
||||
for (int x = area.minX(); x <= area.maxX(); x++) {
|
||||
int column = area.columnIndex(x, z);
|
||||
int originalY = Math.max(area.minY(), Math.min(area.maxY(), surfaceHeight.applyAsInt(x, z)));
|
||||
SurfaceResolution resolution = resolveSurface(anchors, x, z, originalY);
|
||||
originalHeights[column] = originalY;
|
||||
targetHeights[column] = Math.max(area.minY(), Math.min(area.maxY(), resolution.targetY()));
|
||||
rigidBaseSupport[column] = resolution.rigidBaseSupport();
|
||||
}
|
||||
}
|
||||
for (int z = area.minZ(); z <= area.maxZ(); z++) {
|
||||
for (int x = area.minX(); x <= area.maxX(); x++) {
|
||||
int column = area.columnIndex(x, z);
|
||||
applySurfaceColumn(blocks, x, z, originalHeights[column], targetHeights[column], area.minY(), area.maxY(),
|
||||
rigidBaseSupport[column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void fitVacuumTerrain(FitBlocks blocks, Box area, VacuumFootprint footprint,
|
||||
IntBinaryOperator surfaceHeight) {
|
||||
int width = area.xSpan();
|
||||
int depth = area.zSpan();
|
||||
int[] originalHeights = new int[width * depth];
|
||||
int[] targetHeights = new int[width * depth];
|
||||
boolean[] rigidBaseSupport = new boolean[width * depth];
|
||||
for (int z = area.minZ(); z <= area.maxZ(); z++) {
|
||||
for (int x = area.minX(); x <= area.maxX(); x++) {
|
||||
int column = area.columnIndex(x, z);
|
||||
int nominalY = Math.max(area.minY(), Math.min(area.maxY(), surfaceHeight.applyAsInt(x, z)));
|
||||
long columnKey = TemplateFootprint.columnKey(x, z);
|
||||
VacuumAnchor local = footprint.anchors().get(columnKey);
|
||||
Integer cap = footprint.columnCaps().get(columnKey);
|
||||
boolean suppressed = local != null && local.strength() > 1 && cap != null && cap < local.surfaceY();
|
||||
int scanStartY = local != null && local.strength() > 1 && !suppressed
|
||||
? Math.max(area.minY(), Math.min(area.maxY(), local.surfaceY()))
|
||||
: nominalY;
|
||||
int originalY = resolveVacuumSurfaceHeight(blocks, x, z, scanStartY, area.minY());
|
||||
SurfaceResolution resolution = resolveVacuumSurface(footprint, x, z, originalY);
|
||||
originalHeights[column] = originalY;
|
||||
targetHeights[column] = Math.max(originalY, Math.min(area.maxY(), resolution.targetY()));
|
||||
rigidBaseSupport[column] = resolution.rigidBaseSupport() && targetHeights[column] > originalY;
|
||||
}
|
||||
}
|
||||
for (int z = area.minZ(); z <= area.maxZ(); z++) {
|
||||
for (int x = area.minX(); x <= area.maxX(); x++) {
|
||||
int column = area.columnIndex(x, z);
|
||||
applySurfaceColumn(blocks, x, z, originalHeights[column], targetHeights[column], area.minY(), area.maxY(),
|
||||
rigidBaseSupport[column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int resolveVacuumSurfaceHeight(FitBlocks blocks, int x, int z, int nominalY, int worldMinY) {
|
||||
for (int y = nominalY; y >= worldMinY; y--) {
|
||||
if (blocks.isTerrain(blocks.get(x, y, z))) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return nominalY;
|
||||
}
|
||||
|
||||
private static int findVacuumFoundationSupport(FitBlocks blocks, Box area, int x, int startY, int z) {
|
||||
if (startY < area.minY()) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
int maximumY = Math.min(area.maxY(), startY);
|
||||
for (int y = maximumY; y >= area.minY(); y--) {
|
||||
BlockState state = blocks.get(x, y, z);
|
||||
if (blocks.isTerrain(state)) {
|
||||
return y;
|
||||
}
|
||||
if (!blocks.isAir(state) && !blocks.holdsFluid(state)) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private static boolean intersectsVacuumOccupancy(Set<Long> occupiedCells, int x, int z, int minimumY, int maximumY) {
|
||||
for (int y = minimumY; y <= maximumY; y++) {
|
||||
if (occupiedCells.contains(TemplateFootprint.packedPosition(x, y, z))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static SurfaceResolution resolveVacuumSurface(VacuumFootprint footprint, int worldX, int worldZ, int originalY) {
|
||||
long column = TemplateFootprint.columnKey(worldX, worldZ);
|
||||
Integer cap = footprint.columnCaps().get(column);
|
||||
VacuumAnchor local = footprint.anchors().get(column);
|
||||
if (local != null && local.strength() > 1) {
|
||||
int localTargetY = cap == null ? local.surfaceY() : Math.min(local.surfaceY(), cap);
|
||||
if (localTargetY <= originalY) {
|
||||
return new SurfaceResolution(originalY, false);
|
||||
}
|
||||
return new SurfaceResolution(localTargetY, localTargetY == local.surfaceY());
|
||||
}
|
||||
long totalInfluence = 0L;
|
||||
long weightedSurfaceY = 0L;
|
||||
long maximumInfluence = 0L;
|
||||
int radiusSquared = SURFACE_TERRAIN_RADIUS * SURFACE_TERRAIN_RADIUS;
|
||||
for (int offsetX = -SURFACE_TERRAIN_RADIUS; offsetX <= SURFACE_TERRAIN_RADIUS; offsetX++) {
|
||||
for (int offsetZ = -SURFACE_TERRAIN_RADIUS; offsetZ <= SURFACE_TERRAIN_RADIUS; offsetZ++) {
|
||||
int horizontalDistanceSquared = offsetX * offsetX + offsetZ * offsetZ;
|
||||
if (horizontalDistanceSquared > radiusSquared) {
|
||||
continue;
|
||||
}
|
||||
VacuumAnchor anchor = footprint.anchors().get(
|
||||
TemplateFootprint.columnKey(worldX + offsetX, worldZ + offsetZ));
|
||||
if (anchor == null || anchor.surfaceY() <= originalY) {
|
||||
continue;
|
||||
}
|
||||
int verticalDistance = Math.abs(anchor.surfaceY() + 1 - originalY);
|
||||
long distanceSquared = horizontalDistanceSquared + (long) verticalDistance * verticalDistance;
|
||||
double factor = 0D;
|
||||
if (distanceSquared <= radiusSquared) {
|
||||
factor = surfaceFactor(Math.sqrt(distanceSquared));
|
||||
}
|
||||
if (anchor.strength() > 1 && verticalDistance > SURFACE_TERRAIN_RADIUS) {
|
||||
double rescueProgress = Math.min(1D,
|
||||
(verticalDistance - SURFACE_TERRAIN_RADIUS) / (double) SURFACE_TERRAIN_RADIUS);
|
||||
double rescueWeight = rescueProgress * rescueProgress * (3D - 2D * rescueProgress);
|
||||
factor = Math.max(factor, surfaceFactor(Math.sqrt(horizontalDistanceSquared)) * rescueWeight);
|
||||
}
|
||||
long influence = Math.round(factor * SURFACE_TERRAIN_INFLUENCE_SCALE);
|
||||
if (influence <= 0L) {
|
||||
continue;
|
||||
}
|
||||
long weightedInfluence = influence * Math.max(1, anchor.strength());
|
||||
totalInfluence += weightedInfluence;
|
||||
weightedSurfaceY += weightedInfluence * anchor.surfaceY();
|
||||
maximumInfluence = Math.max(maximumInfluence, influence);
|
||||
}
|
||||
}
|
||||
if (totalInfluence == 0L) {
|
||||
return new SurfaceResolution(originalY, false);
|
||||
}
|
||||
double blendedSurfaceY = weightedSurfaceY / (double) totalInfluence;
|
||||
double factor = maximumInfluence / (double) SURFACE_TERRAIN_INFLUENCE_SCALE;
|
||||
int targetY = (int) Math.round(originalY + ((blendedSurfaceY - originalY) * factor));
|
||||
if (cap != null) {
|
||||
targetY = Math.min(targetY, cap);
|
||||
}
|
||||
return new SurfaceResolution(Math.max(originalY, targetY), false);
|
||||
}
|
||||
|
||||
private static double surfaceFactor(double distance) {
|
||||
return Math.pow(1D - distance / SURFACE_TERRAIN_RADIUS, SURFACE_TERRAIN_FALLOFF);
|
||||
}
|
||||
|
||||
static void applySurfaceColumn(FitBlocks blocks, int x, int z, int originalY, int targetY, int worldMinY,
|
||||
int worldMaxY, boolean requireRigidBaseSupport) {
|
||||
if (targetY == originalY) {
|
||||
if (requireRigidBaseSupport) {
|
||||
ensureRigidBaseTerrain(blocks, x, z, targetY, worldMinY);
|
||||
}
|
||||
return;
|
||||
}
|
||||
SurfaceMaterials materials = resolveSurfaceMaterials(blocks, x, z, originalY, worldMinY);
|
||||
if (targetY < originalY) {
|
||||
BlockState clearedState = clearSurfaceDecorationAndResolveFill(blocks, x, z, originalY, worldMaxY);
|
||||
for (int y = originalY; y > targetY; y--) {
|
||||
blocks.set(x, y, z, clearedState);
|
||||
}
|
||||
blocks.set(x, targetY, z, materials.surface());
|
||||
if (requireRigidBaseSupport) {
|
||||
ensureRigidBaseTerrain(blocks, x, z, targetY, worldMinY, materials);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int y = originalY + 1; y < targetY; y++) {
|
||||
if (!blocks.isTree(blocks.get(x, y, z))) {
|
||||
blocks.set(x, y, z, materials.subsurface());
|
||||
}
|
||||
}
|
||||
if (!blocks.isTree(blocks.get(x, targetY, z))) {
|
||||
blocks.set(x, targetY, z, materials.surface());
|
||||
}
|
||||
if (requireRigidBaseSupport) {
|
||||
ensureRigidBaseTerrain(blocks, x, z, targetY, worldMinY, materials);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureRigidBaseTerrain(FitBlocks blocks, int x, int z, int targetY, int worldMinY) {
|
||||
int supportY = targetY - 1;
|
||||
boolean targetIsTerrain = blocks.isTerrain(blocks.get(x, targetY, z));
|
||||
boolean supportIsTerrain = supportY < worldMinY || blocks.isTerrain(blocks.get(x, supportY, z));
|
||||
if (targetIsTerrain && supportIsTerrain) {
|
||||
return;
|
||||
}
|
||||
SurfaceMaterials materials = resolveSurfaceMaterials(blocks, x, z, targetY, worldMinY);
|
||||
ensureRigidBaseTerrain(blocks, x, z, targetY, worldMinY, materials);
|
||||
}
|
||||
|
||||
private static void ensureRigidBaseTerrain(FitBlocks blocks, int x, int z, int targetY, int worldMinY,
|
||||
SurfaceMaterials materials) {
|
||||
int supportY = targetY - 1;
|
||||
if (!blocks.isTerrain(blocks.get(x, targetY, z))) {
|
||||
blocks.set(x, targetY, z, materials.surface());
|
||||
}
|
||||
if (supportY < worldMinY) {
|
||||
return;
|
||||
}
|
||||
if (!blocks.isTerrain(blocks.get(x, supportY, z))) {
|
||||
blocks.set(x, supportY, z, materials.subsurface());
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockState clearSurfaceDecorationAndResolveFill(FitBlocks blocks, int x, int z, int originalY,
|
||||
int worldMaxY) {
|
||||
for (int y = originalY + 1; y <= worldMaxY; y++) {
|
||||
BlockState state = blocks.get(x, y, z);
|
||||
if (blocks.isAir(state)) {
|
||||
return FitBlocks.AIR;
|
||||
}
|
||||
if (blocks.holdsFluid(state)) {
|
||||
BlockState fluid = blocks.fluidOf(state);
|
||||
if (!state.equals(fluid)) {
|
||||
blocks.set(x, y, z, fluid);
|
||||
}
|
||||
return fluid;
|
||||
}
|
||||
if (blocks.isSolid(state) || blocks.isTree(state)) {
|
||||
return FitBlocks.AIR;
|
||||
}
|
||||
blocks.set(x, y, z, FitBlocks.AIR);
|
||||
}
|
||||
return FitBlocks.AIR;
|
||||
}
|
||||
|
||||
private static SurfaceMaterials resolveSurfaceMaterials(FitBlocks blocks, int x, int z, int originalY, int worldMinY) {
|
||||
BlockState surface = blocks.get(x, originalY, z);
|
||||
BlockState subsurface = null;
|
||||
for (int y = originalY - 1; y >= worldMinY; y--) {
|
||||
BlockState candidate = blocks.get(x, y, z);
|
||||
if (blocks.isTerrain(candidate)) {
|
||||
subsurface = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (subsurface == null) {
|
||||
subsurface = blocks.isTerrain(surface) ? surface : FitBlocks.STONE;
|
||||
}
|
||||
if (!blocks.isTerrain(surface)) {
|
||||
surface = subsurface;
|
||||
}
|
||||
return new SurfaceMaterials(surface, subsurface);
|
||||
}
|
||||
|
||||
record SurfaceAnchor(int minX, int maxX, int minZ, int maxZ, int meetY, int strength) {
|
||||
}
|
||||
|
||||
private record SurfaceMaterials(BlockState surface, BlockState subsurface) {
|
||||
}
|
||||
|
||||
private record SurfaceResolution(int targetY, boolean rigidBaseSupport) {
|
||||
}
|
||||
|
||||
private record VacuumFootprint(Map<Long, VacuumAnchor> anchors, Map<Long, Integer> columnCaps,
|
||||
Set<Long> foundationBases, Set<Long> occupiedCells) {
|
||||
}
|
||||
|
||||
private record VacuumAnchor(int surfaceY, int strength) {
|
||||
}
|
||||
|
||||
/** The foundation bases VACUUM raised the terrain to, kept until the pieces are placed for the repair. */
|
||||
static final class VacuumFoundationPlan {
|
||||
static final VacuumFoundationPlan EMPTY = new VacuumFoundationPlan(List.of(), Set.of());
|
||||
|
||||
private final List<Long> foundationBases;
|
||||
private final Set<Long> occupiedCells;
|
||||
|
||||
private VacuumFoundationPlan(List<Long> foundationBases, Set<Long> occupiedCells) {
|
||||
this.foundationBases = foundationBases;
|
||||
this.occupiedCells = occupiedCells;
|
||||
}
|
||||
|
||||
private static VacuumFoundationPlan create(Set<Long> packedBases, Set<Long> packedOccupancy, Box area) {
|
||||
if (packedBases.isEmpty()) {
|
||||
return EMPTY;
|
||||
}
|
||||
List<Long> bases = new ArrayList<>(packedBases.size());
|
||||
Set<Long> columns = new HashSet<>();
|
||||
for (long packedBase : packedBases) {
|
||||
int x = TemplateFootprint.packedX(packedBase);
|
||||
int z = TemplateFootprint.packedZ(packedBase);
|
||||
if (!area.contains(x, TemplateFootprint.packedY(packedBase), z)) {
|
||||
continue;
|
||||
}
|
||||
bases.add(packedBase);
|
||||
columns.add(TemplateFootprint.columnKey(x, z));
|
||||
}
|
||||
if (bases.isEmpty()) {
|
||||
return EMPTY;
|
||||
}
|
||||
bases.sort((first, second) -> {
|
||||
int yOrder = Integer.compare(TemplateFootprint.packedY(first), TemplateFootprint.packedY(second));
|
||||
return yOrder == 0 ? Long.compare(first, second) : yOrder;
|
||||
});
|
||||
Set<Long> occupancy = new HashSet<>();
|
||||
for (long packedCell : packedOccupancy) {
|
||||
if (columns.contains(TemplateFootprint.columnKey(
|
||||
TemplateFootprint.packedX(packedCell), TemplateFootprint.packedZ(packedCell)))) {
|
||||
occupancy.add(packedCell);
|
||||
}
|
||||
}
|
||||
return new VacuumFoundationPlan(List.copyOf(bases), Set.copyOf(occupancy));
|
||||
}
|
||||
}
|
||||
|
||||
/** Bounds the template blocks one start may read for one fitting. */
|
||||
static final class TemplateCellBudget {
|
||||
private final int maximum;
|
||||
private int consumed;
|
||||
|
||||
TemplateCellBudget(int maximum) {
|
||||
if (maximum < 0) {
|
||||
throw new IllegalArgumentException("Native structure surface template budget cannot be negative");
|
||||
}
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
void consume(int amount) {
|
||||
if (amount < 0 || consumed > maximum - amount) {
|
||||
throw TemplateBudgetExceeded.INSTANCE;
|
||||
}
|
||||
consumed += amount;
|
||||
}
|
||||
}
|
||||
|
||||
static final class TemplateBudgetExceeded extends RuntimeException {
|
||||
static final TemplateBudgetExceeded INSTANCE = new TemplateBudgetExceeded();
|
||||
|
||||
private TemplateBudgetExceeded() {
|
||||
super(null, null, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** The lowest template cell of each column of a piece, the cells a structure stands on. */
|
||||
final class TemplateFootprint {
|
||||
private static final int PACKED_HORIZONTAL_BITS = 26;
|
||||
private static final int PACKED_VERTICAL_BITS = 12;
|
||||
private static final long PACKED_HORIZONTAL_MASK = (1L << PACKED_HORIZONTAL_BITS) - 1L;
|
||||
private static final long PACKED_VERTICAL_MASK = (1L << PACKED_VERTICAL_BITS) - 1L;
|
||||
private static final int PACKED_X_OFFSET = PACKED_VERTICAL_BITS + PACKED_HORIZONTAL_BITS;
|
||||
private static final int PACKED_Z_OFFSET = PACKED_VERTICAL_BITS;
|
||||
|
||||
private TemplateFootprint() {
|
||||
}
|
||||
|
||||
/** The lowest cell of every column, removed blocks included. */
|
||||
static Map<Long, Cell> lowestCells(TemplateCells cells, FitPiece piece) {
|
||||
Map<Long, Cell> lowest = new HashMap<>();
|
||||
for (int cell = 0; cell < cells.size(); cell++) {
|
||||
keepLowest(lowest, cells, piece, cell);
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
/** The lowest cell of every column that a structure can stand on. */
|
||||
static Map<Long, Cell> lowestSolidCells(TemplateCells cells, FitPiece piece, FitBlocks blocks) {
|
||||
Map<Long, Cell> lowest = new HashMap<>();
|
||||
for (int cell = 0; cell < cells.size(); cell++) {
|
||||
if (cells.removed(cell) || !blocks.isSolidBase(cells.state(cell))) {
|
||||
continue;
|
||||
}
|
||||
keepLowest(lowest, cells, piece, cell);
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
private static void keepLowest(Map<Long, Cell> lowest, TemplateCells cells, FitPiece piece, int cell) {
|
||||
int y = piece.cellY(cells, cell);
|
||||
long column = columnKey(cells.x(cell), cells.z(cell));
|
||||
Cell current = lowest.get(column);
|
||||
if (current == null || y < current.y()) {
|
||||
lowest.put(column, new Cell(cells.x(cell), y, cells.z(cell), cells.state(cell)));
|
||||
}
|
||||
}
|
||||
|
||||
static long columnKey(int x, int z) {
|
||||
return (long) x << 32 ^ z & 0xffffffffL;
|
||||
}
|
||||
|
||||
/** A block position packed the way the platform packs positions, so sets of them sort the platform's way. */
|
||||
static long packedPosition(int x, int y, int z) {
|
||||
return ((long) x & PACKED_HORIZONTAL_MASK) << PACKED_X_OFFSET
|
||||
| ((long) y & PACKED_VERTICAL_MASK)
|
||||
| ((long) z & PACKED_HORIZONTAL_MASK) << PACKED_Z_OFFSET;
|
||||
}
|
||||
|
||||
static int packedX(long packed) {
|
||||
return (int) (packed << (64 - PACKED_X_OFFSET - PACKED_HORIZONTAL_BITS) >> (64 - PACKED_HORIZONTAL_BITS));
|
||||
}
|
||||
|
||||
static int packedY(long packed) {
|
||||
return (int) (packed << (64 - PACKED_VERTICAL_BITS) >> (64 - PACKED_VERTICAL_BITS));
|
||||
}
|
||||
|
||||
static int packedZ(long packed) {
|
||||
return (int) (packed << (64 - PACKED_Z_OFFSET - PACKED_HORIZONTAL_BITS) >> (64 - PACKED_HORIZONTAL_BITS));
|
||||
}
|
||||
|
||||
/** A template cell at its world position; no state for a block the processors removed. */
|
||||
record Cell(int x, int y, int z, BlockState state) {
|
||||
boolean blocker() {
|
||||
return state == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,633 @@
|
||||
/*
|
||||
* 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.framework.structure.fit;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.engine.mantle.components.StructureCarveEnvelope;
|
||||
import art.arcane.iris.engine.mantle.components.StructureCarvingFootprint;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.TerrainAdaptation;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
/**
|
||||
* The terrain fitting that runs before a start's pieces are placed, for every mode but VACUUM: SOURCE replays the
|
||||
* platform's BURY and ENCAPSULATE adaptations by filling the envelope around rigid pieces with the nearby natural
|
||||
* material, ENCASE fills the padded piece boxes, BORE clears them, FORCE_CARVE clears a box or a rounded, optionally
|
||||
* eroded shape around the pieces' silhouette. Legacy templates then clear their authored air over the terrain.
|
||||
*/
|
||||
final class TerrainIntegration {
|
||||
private static final long CARVE_CEILING_ROLL_SIGNATURE = 0x2A17L;
|
||||
private static final long CARVE_FLOOR_ROLL_SIGNATURE = 0x5B3DL;
|
||||
private static final long CARVE_LOBE_SIGNATURE = 0x7C41L;
|
||||
private static final long CARVE_IDENTITY_X = 341873128712L;
|
||||
private static final long CARVE_IDENTITY_Z = 132897987541L;
|
||||
private static final int SOURCE_BURY_HORIZONTAL_RADIUS = 6;
|
||||
private static final int SOURCE_BURY_VERTICAL_RADIUS = 12;
|
||||
private static final int SOURCE_ENCAPSULATE_RADIUS = 12;
|
||||
private static final int SOURCE_JUNCTION_RADIUS = 12;
|
||||
private static final int SOURCE_MATERIAL_SAMPLE_RADIUS = 8;
|
||||
private static final Set<String> VANILLA_SOURCE_TERRAIN_BLOCKS = Set.of(
|
||||
"minecraft:stone", "minecraft:granite", "minecraft:diorite", "minecraft:andesite",
|
||||
"minecraft:tuff", "minecraft:deepslate", "minecraft:netherrack", "minecraft:basalt",
|
||||
"minecraft:blackstone", "minecraft:dirt", "minecraft:coarse_dirt", "minecraft:rooted_dirt",
|
||||
"minecraft:grass_block", "minecraft:podzol", "minecraft:mycelium", "minecraft:mud",
|
||||
"minecraft:moss_block", "minecraft:sand", "minecraft:red_sand", "minecraft:terracotta",
|
||||
"minecraft:crimson_nylium", "minecraft:warped_nylium", "minecraft:snow_block",
|
||||
"minecraft:ice", "minecraft:packed_ice", "minecraft:blue_ice", "minecraft:soul_sand",
|
||||
"minecraft:soul_soil", "minecraft:end_stone", "minecraft:gravel", "minecraft:clay",
|
||||
"minecraft:calcite", "minecraft:dripstone_block", "minecraft:sandstone",
|
||||
"minecraft:red_sandstone", "minecraft:sculk");
|
||||
private static final List<ResourceId> SOURCE_TERRAIN_TAGS = List.of(
|
||||
ResourceId.parse("minecraft:base_stone_overworld"), ResourceId.parse("minecraft:base_stone_nether"),
|
||||
ResourceId.parse("minecraft:substrate_overworld"), ResourceId.parse("minecraft:dirt"),
|
||||
ResourceId.parse("minecraft:sand"), ResourceId.parse("minecraft:terracotta"),
|
||||
ResourceId.parse("minecraft:mud"), ResourceId.parse("minecraft:moss_blocks"),
|
||||
ResourceId.parse("minecraft:grass_blocks"), ResourceId.parse("minecraft:nylium"),
|
||||
ResourceId.parse("minecraft:snow"), ResourceId.parse("minecraft:ice"),
|
||||
ResourceId.parse("minecraft:coral_blocks"), ResourceId.parse("minecraft:soul_fire_base_blocks"));
|
||||
|
||||
private TerrainIntegration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrates the terrain of every start, then clears the legacy template air of those that replay their own
|
||||
* adaptation or are encased. The natural material SOURCE fills with is read once for all starts, before any fill.
|
||||
*/
|
||||
static void prepareTerrain(FitBlocks blocks, Box area, List<FitStart> starts, long seed,
|
||||
IntFunction<BlockState> naturalBlock, FitPalettes palettes) {
|
||||
if (starts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SourceTerrainSnapshot sourceTerrain = captureSourceTerrain(blocks, area, starts);
|
||||
for (FitStart start : starts) {
|
||||
integrateTerrain(blocks, area, start, seed, naturalBlock, palettes, sourceTerrain);
|
||||
}
|
||||
for (FitStart start : starts) {
|
||||
if (clearsLegacyTemplateAir(start)) {
|
||||
clearLegacyTemplateAir(blocks, area, start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void integrateTerrain(FitBlocks blocks, Box area, FitStart start, long seed,
|
||||
IntFunction<BlockState> naturalBlock, FitPalettes palettes,
|
||||
SourceTerrainSnapshot sourceTerrain) {
|
||||
StructureTerrain terrain = start.terrain();
|
||||
StructureTerrainMode mode = terrain.resolvedMode();
|
||||
switch (mode) {
|
||||
case SOURCE -> integrateSourceTerrain(blocks, area, start, naturalBlock, sourceTerrain);
|
||||
case PRESERVE, VACUUM -> {
|
||||
}
|
||||
case ENCASE -> encasePieces(blocks, area, start, terrain, seed, naturalBlock, palettes);
|
||||
case BORE, FORCE_CARVE -> carve(blocks, area, start, terrain, seed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void carve(FitBlocks blocks, Box area, FitStart start, StructureTerrain terrain, long seed) {
|
||||
StructureCarveShape shape = terrain.resolvedMode() == StructureTerrainMode.BORE
|
||||
? StructureCarveShape.BOX : terrain.resolvedShape();
|
||||
if (shape == StructureCarveShape.BOX) {
|
||||
carvePieceBoxes(blocks, area, start, terrain);
|
||||
return;
|
||||
}
|
||||
carveOrganicColumns(blocks, area, organicCarve(
|
||||
CarveFootprints.of(start, Math.max(0, terrain.horizontalPadding())),
|
||||
terrain, shape, carveNoiseIdentity(seed, start)));
|
||||
}
|
||||
|
||||
static SourceTerrainSnapshot captureSourceTerrain(FitBlocks blocks, Box area, List<FitStart> starts) {
|
||||
BitSet requiredLayers = new BitSet(area.ySpan());
|
||||
boolean requiresSnapshot = false;
|
||||
for (FitStart start : starts) {
|
||||
if (requiresSourceTerrainFill(start)) {
|
||||
requiresSnapshot = true;
|
||||
markSourceTerrainLayers(area, start, requiredLayers);
|
||||
}
|
||||
}
|
||||
return requiresSnapshot ? SourceTerrainSnapshot.capture(blocks, area, requiredLayers) : null;
|
||||
}
|
||||
|
||||
private static void markSourceTerrainLayers(Box area, FitStart start, BitSet requiredLayers) {
|
||||
TerrainAdaptation adaptation = start.adaptation();
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (!piece.isRigidOrFixed()) {
|
||||
continue;
|
||||
}
|
||||
Box bounds = piece.box();
|
||||
long horizontalDistanceSquared = minimumHorizontalDistanceSquared(area, bounds);
|
||||
if (adaptation == TerrainAdaptation.BURY) {
|
||||
long remainingDistanceSquared = (long) SOURCE_BURY_VERTICAL_RADIUS * SOURCE_BURY_VERTICAL_RADIUS
|
||||
- 1L - horizontalDistanceSquared * 4L;
|
||||
if (remainingDistanceSquared < 0L) {
|
||||
continue;
|
||||
}
|
||||
int verticalRadius = (int) Math.floor(Math.sqrt(remainingDistanceSquared));
|
||||
long groundY = piece.groundY();
|
||||
markLayers(area, requiredLayers, groundY - verticalRadius, groundY + verticalRadius);
|
||||
} else {
|
||||
long remainingDistanceSquared = (long) SOURCE_ENCAPSULATE_RADIUS * SOURCE_ENCAPSULATE_RADIUS
|
||||
- 1L - horizontalDistanceSquared;
|
||||
if (remainingDistanceSquared < 0L) {
|
||||
continue;
|
||||
}
|
||||
int verticalRadius = (int) Math.floor(Math.sqrt(remainingDistanceSquared));
|
||||
markLayers(area, requiredLayers, (long) bounds.minY() - verticalRadius,
|
||||
(long) bounds.maxY() + verticalRadius);
|
||||
}
|
||||
}
|
||||
markSourceJunctionLayers(area, start, requiredLayers);
|
||||
}
|
||||
|
||||
private static void markSourceJunctionLayers(Box area, FitStart start, BitSet requiredLayers) {
|
||||
for (BlockPosition anchor : sourceJunctionAnchors(start)) {
|
||||
long deltaX = intervalDistance(area.minX(), area.maxX(), anchor.x(), anchor.x());
|
||||
long deltaZ = intervalDistance(area.minZ(), area.maxZ(), anchor.z(), anchor.z());
|
||||
long horizontalDistanceSquared = deltaX * deltaX + deltaZ * deltaZ;
|
||||
long remainingDistanceSquared = (long) SOURCE_JUNCTION_RADIUS * SOURCE_JUNCTION_RADIUS
|
||||
- 1L - horizontalDistanceSquared;
|
||||
if (remainingDistanceSquared < 1L) {
|
||||
continue;
|
||||
}
|
||||
int verticalRadius = (int) Math.floor(Math.sqrt(remainingDistanceSquared));
|
||||
markLayers(area, requiredLayers, (long) anchor.y() - verticalRadius, (long) anchor.y() - 1L);
|
||||
}
|
||||
}
|
||||
|
||||
private static long minimumHorizontalDistanceSquared(Box area, Box bounds) {
|
||||
long deltaX = intervalDistance(area.minX(), area.maxX(), bounds.minX(), bounds.maxX());
|
||||
long deltaZ = intervalDistance(area.minZ(), area.maxZ(), bounds.minZ(), bounds.maxZ());
|
||||
return deltaX * deltaX + deltaZ * deltaZ;
|
||||
}
|
||||
|
||||
private static long intervalDistance(int firstMin, int firstMax, int secondMin, int secondMax) {
|
||||
if (firstMax < secondMin) {
|
||||
return (long) secondMin - firstMax;
|
||||
}
|
||||
if (firstMin > secondMax) {
|
||||
return (long) firstMin - secondMax;
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
private static void markLayers(Box area, BitSet requiredLayers, long minimumY, long maximumY) {
|
||||
long clippedMinimumY = Math.max(area.minY(), minimumY);
|
||||
long clippedMaximumY = Math.min(area.maxY(), maximumY);
|
||||
if (clippedMinimumY > clippedMaximumY) {
|
||||
return;
|
||||
}
|
||||
int fromIndex = Math.toIntExact(clippedMinimumY - area.minY());
|
||||
int toIndex = Math.toIntExact(clippedMaximumY - area.minY() + 1L);
|
||||
requiredLayers.set(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
/** Whether SOURCE fills terrain for the start: it buries or encapsulates its rigid pieces. */
|
||||
private static boolean requiresSourceTerrainFill(FitStart start) {
|
||||
return start.terrain().resolvedMode() == StructureTerrainMode.SOURCE
|
||||
&& (start.adaptation() == TerrainAdaptation.BURY || start.adaptation() == TerrainAdaptation.ENCAPSULATE);
|
||||
}
|
||||
|
||||
static boolean clearsLegacyTemplateAir(FitStart start) {
|
||||
StructureTerrainMode mode = start.terrain().resolvedMode();
|
||||
return mode == StructureTerrainMode.ENCASE
|
||||
|| mode == StructureTerrainMode.SOURCE && start.adaptation() != TerrainAdaptation.NONE;
|
||||
}
|
||||
|
||||
private static void integrateSourceTerrain(FitBlocks blocks, Box area, FitStart start,
|
||||
IntFunction<BlockState> naturalBlock, SourceTerrainSnapshot sourceTerrain) {
|
||||
if (start.adaptation() == TerrainAdaptation.BURY) {
|
||||
fillBuriedTerrain(blocks, area, start, naturalBlock, requireSourceTerrain(blocks, area, start, sourceTerrain));
|
||||
} else if (start.adaptation() == TerrainAdaptation.ENCAPSULATE) {
|
||||
fillEncapsulatedTerrain(blocks, area, start, naturalBlock,
|
||||
requireSourceTerrain(blocks, area, start, sourceTerrain));
|
||||
}
|
||||
}
|
||||
|
||||
private static SourceTerrainSnapshot requireSourceTerrain(FitBlocks blocks, Box area, FitStart start,
|
||||
SourceTerrainSnapshot sourceTerrain) {
|
||||
if (sourceTerrain != null) {
|
||||
return sourceTerrain;
|
||||
}
|
||||
BitSet requiredLayers = new BitSet(area.ySpan());
|
||||
markSourceTerrainLayers(area, start, requiredLayers);
|
||||
return SourceTerrainSnapshot.capture(blocks, area, requiredLayers);
|
||||
}
|
||||
|
||||
private static void fillBuriedTerrain(FitBlocks blocks, Box area, FitStart start, IntFunction<BlockState> naturalBlock,
|
||||
SourceTerrainSnapshot sourceTerrain) {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (!piece.isRigidOrFixed()) {
|
||||
continue;
|
||||
}
|
||||
Box bounds = piece.box();
|
||||
int groundY = piece.groundY();
|
||||
int minX = Math.max(area.minX(), bounds.minX() - SOURCE_BURY_HORIZONTAL_RADIUS);
|
||||
int maxX = Math.min(area.maxX(), bounds.maxX() + SOURCE_BURY_HORIZONTAL_RADIUS);
|
||||
int minY = Math.max(area.minY(), groundY - SOURCE_BURY_VERTICAL_RADIUS);
|
||||
int maxY = Math.min(area.maxY(), groundY + SOURCE_BURY_VERTICAL_RADIUS);
|
||||
int minZ = Math.max(area.minZ(), bounds.minZ() - SOURCE_BURY_HORIZONTAL_RADIUS);
|
||||
int maxZ = Math.min(area.maxZ(), bounds.maxZ() + SOURCE_BURY_HORIZONTAL_RADIUS);
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int outX = outset(x, bounds.minX(), bounds.maxX());
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
int outZ = outset(z, bounds.minZ(), bounds.maxZ());
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
if (insideBurialEnvelope(outX, Math.abs(y - groundY), outZ)) {
|
||||
fillEncaseable(blocks, x, y, z, naturalBlock, sourceTerrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fillSourceJunctionTerrain(blocks, area, start, naturalBlock, sourceTerrain);
|
||||
}
|
||||
|
||||
private static void fillEncapsulatedTerrain(FitBlocks blocks, Box area, FitStart start,
|
||||
IntFunction<BlockState> naturalBlock, SourceTerrainSnapshot sourceTerrain) {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (!piece.isRigidOrFixed()) {
|
||||
continue;
|
||||
}
|
||||
Box bounds = piece.box();
|
||||
int minX = Math.max(area.minX(), bounds.minX() - SOURCE_ENCAPSULATE_RADIUS);
|
||||
int maxX = Math.min(area.maxX(), bounds.maxX() + SOURCE_ENCAPSULATE_RADIUS);
|
||||
int minY = Math.max(area.minY(), bounds.minY() - SOURCE_ENCAPSULATE_RADIUS);
|
||||
int maxY = Math.min(area.maxY(), bounds.maxY() + SOURCE_ENCAPSULATE_RADIUS);
|
||||
int minZ = Math.max(area.minZ(), bounds.minZ() - SOURCE_ENCAPSULATE_RADIUS);
|
||||
int maxZ = Math.min(area.maxZ(), bounds.maxZ() + SOURCE_ENCAPSULATE_RADIUS);
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int outX = outset(x, bounds.minX(), bounds.maxX());
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
int outZ = outset(z, bounds.minZ(), bounds.maxZ());
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
if (insideEncapsulationEnvelope(outX, outset(y, bounds.minY(), bounds.maxY()), outZ)) {
|
||||
fillEncaseable(blocks, x, y, z, naturalBlock, sourceTerrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fillSourceJunctionTerrain(blocks, area, start, naturalBlock, sourceTerrain);
|
||||
}
|
||||
|
||||
static boolean insideBurialEnvelope(int outX, int verticalDistance, int outZ) {
|
||||
long horizontalSquared = (long) outX * outX + (long) outZ * outZ;
|
||||
long verticalSquared = (long) verticalDistance * verticalDistance;
|
||||
return horizontalSquared * 4L + verticalSquared < (long) SOURCE_BURY_VERTICAL_RADIUS * SOURCE_BURY_VERTICAL_RADIUS;
|
||||
}
|
||||
|
||||
static boolean insideEncapsulationEnvelope(int outX, int outY, int outZ) {
|
||||
return (long) outX * outX + (long) outY * outY + (long) outZ * outZ
|
||||
< (long) SOURCE_ENCAPSULATE_RADIUS * SOURCE_ENCAPSULATE_RADIUS;
|
||||
}
|
||||
|
||||
static boolean insideSourceJunctionEnvelope(int deltaX, int deltaY, int deltaZ) {
|
||||
if (deltaY >= 0) {
|
||||
return false;
|
||||
}
|
||||
return (long) deltaX * deltaX + (long) deltaY * deltaY + (long) deltaZ * deltaZ
|
||||
< (long) SOURCE_JUNCTION_RADIUS * SOURCE_JUNCTION_RADIUS;
|
||||
}
|
||||
|
||||
private static void fillSourceJunctionTerrain(FitBlocks blocks, Box area, FitStart start,
|
||||
IntFunction<BlockState> naturalBlock, SourceTerrainSnapshot sourceTerrain) {
|
||||
for (BlockPosition anchor : sourceJunctionAnchors(start)) {
|
||||
int minX = Math.max(area.minX(), anchor.x() - SOURCE_JUNCTION_RADIUS + 1);
|
||||
int maxX = Math.min(area.maxX(), anchor.x() + SOURCE_JUNCTION_RADIUS - 1);
|
||||
int minY = Math.max(area.minY(), anchor.y() - SOURCE_JUNCTION_RADIUS + 1);
|
||||
int maxY = Math.min(area.maxY(), anchor.y() - 1);
|
||||
int minZ = Math.max(area.minZ(), anchor.z() - SOURCE_JUNCTION_RADIUS + 1);
|
||||
int maxZ = Math.min(area.maxZ(), anchor.z() + SOURCE_JUNCTION_RADIUS - 1);
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int deltaX = x - anchor.x();
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
int deltaZ = z - anchor.z();
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
if (insideSourceJunctionEnvelope(deltaX, y - anchor.y(), deltaZ)) {
|
||||
fillEncaseable(blocks, x, y, z, naturalBlock, sourceTerrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The jigsaw junctions of every piece, each place once. The order is a set's, as no fill depends on it. */
|
||||
private static Set<BlockPosition> sourceJunctionAnchors(FitStart start) {
|
||||
Set<BlockPosition> anchors = new HashSet<>();
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
anchors.addAll(piece.junctions());
|
||||
}
|
||||
return anchors;
|
||||
}
|
||||
|
||||
private static int outset(int value, int minimum, int maximum) {
|
||||
if (value < minimum) {
|
||||
return minimum - value;
|
||||
}
|
||||
return Math.max(0, value - maximum);
|
||||
}
|
||||
|
||||
private static void fillEncaseable(FitBlocks blocks, int x, int y, int z, IntFunction<BlockState> naturalBlock,
|
||||
SourceTerrainSnapshot sourceTerrain) {
|
||||
if (blocks.isEncaseable(blocks.get(x, y, z))) {
|
||||
blocks.set(x, y, z, sourceEncaseBlock(x, y, z, naturalBlock, sourceTerrain));
|
||||
}
|
||||
}
|
||||
|
||||
/** The nearest natural terrain block of the snapshot along the axes, within 8 blocks; else the dimension's own. */
|
||||
static BlockState sourceEncaseBlock(int x, int y, int z, IntFunction<BlockState> naturalBlock,
|
||||
SourceTerrainSnapshot sourceTerrain) {
|
||||
for (int distance = 1; distance <= SOURCE_MATERIAL_SAMPLE_RADIUS; distance++) {
|
||||
BlockState sampled = sourceTerrain.stateAt(x - distance, y, z);
|
||||
if (sampled != null) {
|
||||
return sampled;
|
||||
}
|
||||
sampled = sourceTerrain.stateAt(x + distance, y, z);
|
||||
if (sampled != null) {
|
||||
return sampled;
|
||||
}
|
||||
sampled = sourceTerrain.stateAt(x, y, z - distance);
|
||||
if (sampled != null) {
|
||||
return sampled;
|
||||
}
|
||||
sampled = sourceTerrain.stateAt(x, y, z + distance);
|
||||
if (sampled != null) {
|
||||
return sampled;
|
||||
}
|
||||
}
|
||||
return naturalBlock.apply(y);
|
||||
}
|
||||
|
||||
private static BlockState sourceTerrainBlock(FitBlocks blocks, BlockState state) {
|
||||
if (!blocks.isSolid(state) || blocks.isTree(state)) {
|
||||
return null;
|
||||
}
|
||||
if (VANILLA_SOURCE_TERRAIN_BLOCKS.contains(state.material().toString())) {
|
||||
return state;
|
||||
}
|
||||
for (ResourceId tag : SOURCE_TERRAIN_TAGS) {
|
||||
if (blocks.inTag(state, tag)) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static OrganicCarve organicCarve(StructureCarvingFootprint footprint, StructureTerrain terrain,
|
||||
StructureCarveShape shape, long identity) {
|
||||
double strength = terrain.resolvedErosionStrength();
|
||||
double lobeStrength = terrain.resolvedLobeStrength();
|
||||
RNG noiseRng = new RNG(identity);
|
||||
CNG blob = null;
|
||||
CNG ceilingRoll = null;
|
||||
CNG floorRoll = null;
|
||||
CNG lobe = null;
|
||||
if (shape == StructureCarveShape.ERODED && strength > 0D) {
|
||||
blob = CNG.signature(noiseRng);
|
||||
ceilingRoll = CNG.signature(noiseRng.nextParallelRNG(CARVE_CEILING_ROLL_SIGNATURE));
|
||||
floorRoll = CNG.signature(noiseRng.nextParallelRNG(CARVE_FLOOR_ROLL_SIGNATURE));
|
||||
}
|
||||
if (shape == StructureCarveShape.ERODED && lobeStrength > 0D) {
|
||||
// A plain single octave channel: the fractured signature noise has no usable low frequency band.
|
||||
lobe = new CNG(noiseRng.nextParallelRNG(CARVE_LOBE_SIGNATURE), 1D, 1);
|
||||
}
|
||||
return new OrganicCarve(footprint, shape,
|
||||
Math.max(0, terrain.horizontalPadding()),
|
||||
Math.max(0, terrain.ceilingPadding()),
|
||||
Math.max(0, terrain.floorPadding()),
|
||||
strength, terrain.resolvedErosionFrequency(), blob, ceilingRoll, floorRoll,
|
||||
lobe, terrain.resolvedLobeFrequency(), lobeStrength);
|
||||
}
|
||||
|
||||
static void carveOrganicColumns(FitBlocks blocks, Box area, OrganicCarve carve) {
|
||||
StructureCarvingFootprint footprint = carve.footprint();
|
||||
int minX = Math.max(area.minX(), footprint.minX());
|
||||
int maxX = Math.min(area.maxX(), footprint.maxX());
|
||||
int minZ = Math.max(area.minZ(), footprint.minZ());
|
||||
int maxZ = Math.min(area.maxZ(), footprint.maxZ());
|
||||
if (minX > maxX || minZ > maxZ) {
|
||||
return;
|
||||
}
|
||||
boolean eroded = carve.blob() != null;
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int index = footprint.indexAt(x, z);
|
||||
long horizontalDistanceSquared = footprint.distanceSquaredAt(index);
|
||||
double sideReach = StructureCarveEnvelope.lobedSideReach(carve.lobe(),
|
||||
carve.lobeFrequency(), carve.lobeStrength(), x, z, carve.horizontalPadding());
|
||||
double sideReachSquared = sideReach * sideReach;
|
||||
if (horizontalDistanceSquared > sideReachSquared) {
|
||||
continue;
|
||||
}
|
||||
double normalizedHorizontal = sideReachSquared == 0D ? 0D : horizontalDistanceSquared / sideReachSquared;
|
||||
int sourceMinY = footprint.sourceMinYAt(index);
|
||||
int sourceMaxY = footprint.sourceMaxYAt(index);
|
||||
double upReach = eroded
|
||||
? StructureCarveEnvelope.lobedUpReach(carve.lobe(), carve.lobeFrequency(),
|
||||
carve.lobeStrength(), x, z,
|
||||
StructureCarveEnvelope.erodedUpReach(carve.ceilingRoll(),
|
||||
carve.frequency(), carve.strength(), x, z, carve.ceilingPadding()))
|
||||
: Math.max(1D, carve.ceilingPadding());
|
||||
double floorReach = eroded
|
||||
? StructureCarveEnvelope.erodedDownReach(carve.floorRoll(), carve.frequency(),
|
||||
carve.strength(), x, z, carve.floorPadding())
|
||||
: carve.floorPadding();
|
||||
int columnMinY = Math.max(area.minY(), sourceMinY - (int) Math.floor(floorReach));
|
||||
int columnMaxY = Math.min(area.maxY(),
|
||||
sourceMaxY + (eroded ? (int) Math.ceil(upReach) : carve.ceilingPadding()));
|
||||
double downReach = Math.max(1D, floorReach);
|
||||
for (int y = columnMinY; y <= columnMaxY; y++) {
|
||||
double normalizedVertical = StructureCarveEnvelope.normalizedVerticalDistance(
|
||||
y, sourceMinY, sourceMaxY, upReach, downReach);
|
||||
double distanceSquared = normalizedHorizontal + normalizedVertical * normalizedVertical;
|
||||
if (distanceSquared > 1D) {
|
||||
continue;
|
||||
}
|
||||
if (distanceSquared > 0D && eroded) {
|
||||
double noise = carve.blob().fitDouble(0D, 1D,
|
||||
x * carve.frequency(), y * carve.frequency(), z * carve.frequency());
|
||||
if (!StructureCarveEnvelope.shouldCarveOverboreCell(
|
||||
carve.shape(), distanceSquared, noise, carve.strength())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
blocks.set(x, y, z, FitBlocks.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long carveNoiseIdentity(long seed, FitStart start) {
|
||||
return seed
|
||||
^ ((long) start.chunkX() * CARVE_IDENTITY_X)
|
||||
^ ((long) start.chunkZ() * CARVE_IDENTITY_Z)
|
||||
^ start.structureId().hashCode();
|
||||
}
|
||||
|
||||
private static void encasePieces(FitBlocks blocks, Box area, FitStart start, StructureTerrain terrain, long seed,
|
||||
IntFunction<BlockState> naturalBlock, FitPalettes palettes) {
|
||||
Optional<PaletteSpec> palette = terrain.encasePalette();
|
||||
long paletteSeed = seed ^ start.structureId().hashCode();
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
Box shell = paddedPieceArea(area, piece.box(), terrain);
|
||||
if (shell == null) {
|
||||
continue;
|
||||
}
|
||||
for (int x = shell.minX(); x <= shell.maxX(); x++) {
|
||||
for (int z = shell.minZ(); z <= shell.maxZ(); z++) {
|
||||
for (int y = shell.minY(); y <= shell.maxY(); y++) {
|
||||
if (!blocks.isEncaseable(blocks.get(x, y, z))) {
|
||||
continue;
|
||||
}
|
||||
BlockState fill = palette.isEmpty()
|
||||
? naturalBlock.apply(y)
|
||||
: Objects.requireNonNull(palettes.at(palette.get(), paletteSeed, x, y, z),
|
||||
"Encase palette returned no block for " + start.structureId() + " at "
|
||||
+ x + "," + y + "," + z);
|
||||
blocks.set(x, y, z, fill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void carvePieceBoxes(FitBlocks blocks, Box area, FitStart start, StructureTerrain terrain) {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
Box carve = paddedPieceArea(area, piece.box(), terrain);
|
||||
if (carve == null) {
|
||||
continue;
|
||||
}
|
||||
for (int x = carve.minX(); x <= carve.maxX(); x++) {
|
||||
for (int z = carve.minZ(); z <= carve.maxZ(); z++) {
|
||||
for (int y = carve.minY(); y <= carve.maxY(); y++) {
|
||||
blocks.set(x, y, z, FitBlocks.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Box paddedPieceArea(Box area, Box bounds, StructureTerrain terrain) {
|
||||
int horizontalPadding = Math.max(0, terrain.horizontalPadding());
|
||||
int minX = Math.max(area.minX(), bounds.minX() - horizontalPadding);
|
||||
int minY = Math.max(area.minY(), bounds.minY() - Math.max(0, terrain.floorPadding()));
|
||||
int minZ = Math.max(area.minZ(), bounds.minZ() - horizontalPadding);
|
||||
int maxX = Math.min(area.maxX(), bounds.maxX() + horizontalPadding);
|
||||
int maxY = Math.min(area.maxY(), bounds.maxY() + Math.max(0, terrain.ceilingPadding()));
|
||||
int maxZ = Math.min(area.maxZ(), bounds.maxZ() + horizontalPadding);
|
||||
if (minX > maxX || minY > maxY || minZ > maxZ) {
|
||||
return null;
|
||||
}
|
||||
return new Box(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
/** Clears the air of rigid legacy templates over the terrain, from their ground level up, sparing trees. */
|
||||
static void clearLegacyTemplateAir(FitBlocks blocks, Box area, FitStart start) {
|
||||
for (FitPiece piece : start.pieces()) {
|
||||
if (!piece.isRigid() || !piece.box().intersects(area)) {
|
||||
continue;
|
||||
}
|
||||
int groundY = piece.groundY();
|
||||
for (BlockPosition air : piece.legacyAir(area)) {
|
||||
BlockState existing = blocks.get(air.x(), air.y(), air.z());
|
||||
if (shouldClearLegacyAir(air.y(), groundY, blocks.isAir(existing)) && !blocks.isTree(existing)) {
|
||||
blocks.set(air.x(), air.y(), air.z(), FitBlocks.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean shouldClearLegacyAir(int airY, int groundY, boolean existingAir) {
|
||||
return airY >= groundY && !existingAir;
|
||||
}
|
||||
|
||||
/** The natural terrain blocks of some layers of the area, read before any fill, so fills never feed on fills. */
|
||||
static final class SourceTerrainSnapshot {
|
||||
private final Box area;
|
||||
private final int width;
|
||||
private final BlockState[][] statesByLayer;
|
||||
private final int sampledCells;
|
||||
|
||||
private SourceTerrainSnapshot(Box area, int width, BlockState[][] statesByLayer, int sampledCells) {
|
||||
this.area = area;
|
||||
this.width = width;
|
||||
this.statesByLayer = statesByLayer;
|
||||
this.sampledCells = sampledCells;
|
||||
}
|
||||
|
||||
static SourceTerrainSnapshot capture(FitBlocks blocks, Box area, BitSet requiredLayers) {
|
||||
Objects.requireNonNull(requiredLayers, "Source terrain snapshot requires sampled layers");
|
||||
int width = area.xSpan();
|
||||
int horizontalCells = Math.multiplyExact(width, area.zSpan());
|
||||
int height = area.ySpan();
|
||||
BlockState[][] statesByLayer = new BlockState[height][];
|
||||
int sampledCells = 0;
|
||||
for (int layer = requiredLayers.nextSetBit(0); layer >= 0; layer = requiredLayers.nextSetBit(layer + 1)) {
|
||||
if (layer >= height) {
|
||||
throw new IllegalArgumentException("Source terrain snapshot layer exceeds writable bounds: " + layer);
|
||||
}
|
||||
BlockState[] states = new BlockState[horizontalCells];
|
||||
statesByLayer[layer] = states;
|
||||
sampledCells = Math.addExact(sampledCells, horizontalCells);
|
||||
int y = Math.addExact(area.minY(), layer);
|
||||
for (int z = area.minZ(); z <= area.maxZ(); z++) {
|
||||
for (int x = area.minX(); x <= area.maxX(); x++) {
|
||||
states[area.columnIndex(x, z)] = sourceTerrainBlock(blocks, blocks.get(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SourceTerrainSnapshot(area, width, statesByLayer, sampledCells);
|
||||
}
|
||||
|
||||
BlockState stateAt(int x, int y, int z) {
|
||||
if (!area.contains(x, y, z)) {
|
||||
return null;
|
||||
}
|
||||
BlockState[] states = statesByLayer[y - area.minY()];
|
||||
if (states == null) {
|
||||
return null;
|
||||
}
|
||||
return states[(z - area.minZ()) * width + x - area.minX()];
|
||||
}
|
||||
|
||||
int sampledCells() {
|
||||
return sampledCells;
|
||||
}
|
||||
}
|
||||
|
||||
record OrganicCarve(StructureCarvingFootprint footprint, StructureCarveShape shape,
|
||||
int horizontalPadding, int ceilingPadding, int floorPadding,
|
||||
double strength, double frequency, CNG blob, CNG ceilingRoll, CNG floorRoll,
|
||||
CNG lobe, double lobeFrequency, double lobeStrength) {
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
|
||||
/**
|
||||
@@ -129,12 +129,12 @@ public final class StructureCarveEnvelope {
|
||||
return 1D - clampedStrength * (1D - clampedNoise);
|
||||
}
|
||||
|
||||
public static boolean shouldCarveOverboreCell(IrisStructureCarveShape shape, double distanceSquared,
|
||||
public static boolean shouldCarveOverboreCell(StructureCarveShape shape, double distanceSquared,
|
||||
double noise, double strength) {
|
||||
if (distanceSquared <= 0.0) {
|
||||
return true;
|
||||
}
|
||||
IrisStructureCarveShape resolvedShape = shape == null ? IrisStructureCarveShape.ERODED : shape;
|
||||
StructureCarveShape resolvedShape = shape == null ? StructureCarveShape.ERODED : shape;
|
||||
return switch (resolvedShape) {
|
||||
case BOX -> true;
|
||||
case ROUNDED -> distanceSquared <= 1D;
|
||||
|
||||
@@ -20,6 +20,8 @@ package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
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.core.modules.IrisPackWorld;
|
||||
@@ -28,15 +30,17 @@ import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.structure.StructureLocating;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.engine.framework.structure.StructureValidator;
|
||||
import art.arcane.iris.engine.framework.structure.StructureVanillaHook;
|
||||
import art.arcane.iris.engine.framework.structure.StructureVanillaStructures;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleLifecycle;
|
||||
import com.volmit.config.PackSettings;
|
||||
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;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
/**
|
||||
@@ -50,9 +54,11 @@ import com.volmit.world.PackWorld;
|
||||
* {@link StructureLocating}, and forgets a world's structure index when the world stops, which includes every reload of
|
||||
* the pack's structure files.
|
||||
* <p>
|
||||
* It decides over the platform's own structures through its vanilla structure hook ({@link StructureVanillaHook}): the
|
||||
* dimension's {@code importedStructures} settings disable, adjust and set them up, and the pack's structure placements
|
||||
* replace them, place them alongside, and start them where their {@code nativeStructures} grids say.
|
||||
* 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.
|
||||
*/
|
||||
public final class StructureModule implements IrisModule, ModuleLifecycle {
|
||||
private static final String VERSION = "built-in";
|
||||
@@ -75,7 +81,10 @@ public final class StructureModule implements IrisModule, ModuleLifecycle {
|
||||
registry.registerValidator(new StructureValidator());
|
||||
registry.registerService(StructureLocator.class, new StructureLocating());
|
||||
registry.registerLifecycle(this);
|
||||
registry.registerVanillaStructureHook(new StructureVanillaHook());
|
||||
registry.registerService(VanillaStructures.class, new StructureVanillaStructures());
|
||||
registry.registerHeldType(StructureTerrain.class);
|
||||
registry.registerHeldType(StructureStilts.class);
|
||||
registry.registerHeldType(JigsawOverrides.class);
|
||||
}
|
||||
|
||||
/** The structure index is still kept per engine rather than in the world's state, so a stopping world drops it. */
|
||||
|
||||
@@ -22,7 +22,6 @@ import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.data.cache.Cache;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.PlacedStructurePiece;
|
||||
@@ -33,15 +32,16 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
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.engine.object.structure.IrisStructureCarveShape;
|
||||
import art.arcane.iris.builtin.structure.StructureCarveShape;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrainMode;
|
||||
import art.arcane.iris.builtin.structure.StructureStilts;
|
||||
import com.volmit.block.PaletteSampler;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrain;
|
||||
import art.arcane.iris.builtin.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
@@ -61,7 +61,6 @@ import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Places the Iris structures of the dimension, its regions and biomes into the mantle for
|
||||
@@ -119,24 +118,24 @@ public class StructurePlacing {
|
||||
clearIntersectingObjectTrees(writer, resolved);
|
||||
}
|
||||
|
||||
IrisStructureTerrain terrain = placement.resolvedTerrain();
|
||||
IrisStructureTerrainMode terrainMode = terrain.resolvedMode();
|
||||
if (terrainMode == IrisStructureTerrainMode.FORCE_CARVE) {
|
||||
StructureTerrain terrain = placement.resolvedTerrain();
|
||||
StructureTerrainMode terrainMode = terrain.resolvedMode();
|
||||
if (terrainMode == StructureTerrainMode.FORCE_CARVE) {
|
||||
forceCarveStructure(writer, pieces, terrain);
|
||||
} else if (terrainMode == IrisStructureTerrainMode.BORE) {
|
||||
} else if (terrainMode == StructureTerrainMode.BORE) {
|
||||
boreStructure(writer, pieces, terrain);
|
||||
} else if (terrainMode != IrisStructureTerrainMode.PRESERVE
|
||||
&& terrainMode != IrisStructureTerrainMode.SOURCE) {
|
||||
} else if (terrainMode != StructureTerrainMode.PRESERVE
|
||||
&& terrainMode != StructureTerrainMode.SOURCE) {
|
||||
throw new IllegalStateException("Iris assembly terrain mode " + terrainMode
|
||||
+ " is not implemented for structure '" + key + "'");
|
||||
}
|
||||
|
||||
ObjectPlaceMode mode = structure.getPlaceMode();
|
||||
int failedPieces = 0;
|
||||
IrisStructureStiltSettings stilt = placement.getStilt();
|
||||
StructureStilts stilt = placement.getStilt();
|
||||
Long2IntOpenHashMap foundationColumns = stilt == null
|
||||
? null : new Long2IntOpenHashMap();
|
||||
boolean supportNonOccluding = stilt != null && stilt.isSupportNonOccluding();
|
||||
boolean supportNonOccluding = stilt != null && stilt.supportNonOccluding();
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
@@ -173,12 +172,13 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
private void placeFoundation(MantleWriter writer, Long2IntOpenHashMap columns,
|
||||
IrisStructureStiltSettings settings, RNG rng,
|
||||
StructureStilts settings, RNG rng,
|
||||
boolean surfaceStructure) {
|
||||
IrisMaterialPalette palette = Objects.requireNonNull(
|
||||
settings.getPalette(), "Structure stilt palette must not be null");
|
||||
PaletteSpec palette = settings.palette().orElseThrow(
|
||||
() -> new NullPointerException("Structure stilt palette must not be null"));
|
||||
PaletteSampler picker = engine.getData().getPackResources().blocks().palette(palette, rng.getSeed());
|
||||
int mantleOffset = engine.getMinHeight();
|
||||
int maxDepth = Math.max(1, settings.getMaxDepth());
|
||||
int maxDepth = Math.max(1, settings.maxDepth());
|
||||
for (Long2IntMap.Entry column : columns.long2IntEntrySet()) {
|
||||
int worldX = StructureFoundationPlanner.unpackX(column.getLongKey());
|
||||
int worldZ = StructureFoundationPlanner.unpackZ(column.getLongKey());
|
||||
@@ -206,17 +206,16 @@ public class StructurePlacing {
|
||||
continue;
|
||||
}
|
||||
StructureFoundationPlanner.fillSupportColumn(foundationY, groundY, y -> {
|
||||
writeFoundationSupport(
|
||||
writer, palette, rng, engine.getData(), worldX, y, worldZ, mantleOffset);
|
||||
writeFoundationSupport(writer, picker, worldX, y, worldZ, mantleOffset);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void writeFoundationSupport(MantleWriter writer, IrisMaterialPalette palette, RNG rng,
|
||||
IrisData data, int worldX, int mantleY, int worldZ,
|
||||
/** Writes the stilt palette's block at the column's mantle height, clearing any carve there. */
|
||||
static void writeFoundationSupport(MantleWriter writer, PaletteSampler picker, int worldX, int mantleY, int worldZ,
|
||||
int mantleOffset) {
|
||||
int worldY = mantleY + mantleOffset;
|
||||
PlatformBlockState support = palette.get(rng, worldX, worldY, worldZ, data);
|
||||
PlatformBlockState support = B.getState(picker.at(worldX, worldY, worldZ).key());
|
||||
if (support == null) {
|
||||
throw new IllegalStateException("Structure stilt palette resolved no block at "
|
||||
+ worldX + "," + worldY + "," + worldZ);
|
||||
@@ -251,17 +250,17 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
private void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
StructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
return;
|
||||
}
|
||||
int pad = Math.max(0, terrain.getHorizontalPadding());
|
||||
int pad = Math.max(0, terrain.horizontalPadding());
|
||||
int minX = bounds[0] - pad;
|
||||
int minY = bounds[1] - Math.max(0, terrain.getFloorPadding());
|
||||
int minY = bounds[1] - Math.max(0, terrain.floorPadding());
|
||||
int minZ = bounds[2] - pad;
|
||||
int maxX = bounds[3] + pad;
|
||||
int maxY = bounds[4] + Math.max(0, terrain.getCeilingPadding());
|
||||
int maxY = bounds[4] + Math.max(0, terrain.ceilingPadding());
|
||||
int maxZ = bounds[5] + pad;
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
@@ -281,22 +280,22 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
private void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
StructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
return;
|
||||
}
|
||||
IrisStructureCarveShape shape = terrain.resolvedShape();
|
||||
int margin = Math.max(0, terrain.getHorizontalPadding());
|
||||
int head = Math.max(0, terrain.getCeilingPadding());
|
||||
int floorCut = Math.max(0, terrain.getFloorPadding());
|
||||
StructureCarveShape shape = terrain.resolvedShape();
|
||||
int margin = Math.max(0, terrain.horizontalPadding());
|
||||
int head = Math.max(0, terrain.ceilingPadding());
|
||||
int floorCut = Math.max(0, terrain.floorPadding());
|
||||
double strength = terrain.resolvedErosionStrength();
|
||||
int mantleOffset = engine.getMinHeight();
|
||||
int worldMin = engine.getMinHeight() + 1;
|
||||
int worldMax = engine.getMinHeight() + engine.getHeight() - 1;
|
||||
int upExtension = shape.maximumCeilingExtension(head, strength);
|
||||
|
||||
if (shape == IrisStructureCarveShape.BOX) {
|
||||
if (shape == StructureCarveShape.BOX) {
|
||||
carveOverboreBox(writer, bounds, margin, head, floorCut, mantleOffset, worldMin, worldMax);
|
||||
return;
|
||||
}
|
||||
@@ -309,7 +308,7 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
double frequency = terrain.resolvedErosionFrequency();
|
||||
boolean eroded = shape == IrisStructureCarveShape.ERODED && strength > 0D;
|
||||
boolean eroded = shape == StructureCarveShape.ERODED && strength > 0D;
|
||||
CNG blob = null;
|
||||
CNG roll = null;
|
||||
if (eroded) {
|
||||
@@ -604,10 +603,10 @@ public class StructurePlacing {
|
||||
if (!placement.hasIrisStructures()) {
|
||||
continue;
|
||||
}
|
||||
IrisStructureTerrain terrain = placement.resolvedTerrain();
|
||||
int carvePadding = terrain.resolvedMode() == IrisStructureTerrainMode.FORCE_CARVE
|
||||
|| terrain.resolvedMode() == IrisStructureTerrainMode.BORE
|
||||
? Math.max(0, terrain.getHorizontalPadding()) : 0;
|
||||
StructureTerrain terrain = placement.resolvedTerrain();
|
||||
int carvePadding = terrain.resolvedMode() == StructureTerrainMode.FORCE_CARVE
|
||||
|| terrain.resolvedMode() == StructureTerrainMode.BORE
|
||||
? Math.max(0, terrain.horizontalPadding()) : 0;
|
||||
for (String key : placement.getStructures()) {
|
||||
IrisStructure structure = StructureResources.structure(engine.getData(), key);
|
||||
if (structure != null) {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.engine.object.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;
|
||||
@@ -119,16 +121,16 @@ public class IrisStructurePlacement {
|
||||
private int caveMinimumClearance = 3;
|
||||
|
||||
@Desc("Terrain integration for this placement. The editable structures backend supports SOURCE, PRESERVE, BORE, and FORCE_CARVE. The nativeStructures backend supports every terrain mode.")
|
||||
private IrisStructureTerrain terrain = new IrisStructureTerrain();
|
||||
private StructureTerrain terrain = new StructureTerrain();
|
||||
|
||||
@Desc("Optional foundation columns placed beneath the assembled structure's occupied bottom cells. Columns pass through air and fluids until they reach solid ground, up to maxDepth.")
|
||||
private IrisStructureStiltSettings stilt = null;
|
||||
private StructureStilts stilt = null;
|
||||
|
||||
@Desc("If false, the placement is skipped when its selected surface or cave column is submerged.")
|
||||
private boolean underwater = false;
|
||||
|
||||
public IrisStructureTerrain resolvedTerrain() {
|
||||
return terrain == null ? new IrisStructureTerrain() : terrain;
|
||||
public StructureTerrain resolvedTerrain() {
|
||||
return terrain == null ? new StructureTerrain() : terrain;
|
||||
}
|
||||
|
||||
public boolean hasIrisStructures() {
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package art.arcane.iris.engine.object.structure;
|
||||
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Defines foundation columns placed beneath a structure.")
|
||||
@Data
|
||||
public class IrisStructureStiltSettings {
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Maximum number of blocks each foundation column may descend while searching for solid ground.")
|
||||
private int maxDepth = 64;
|
||||
|
||||
@Desc("Block palette used for foundation columns.")
|
||||
private IrisMaterialPalette palette = new IrisMaterialPalette().qclear().qadd("minecraft:cobblestone");
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Desc("Horizontal spacing between support columns. One fills every eligible foundation column; larger values create sparse stilts.")
|
||||
private int spacing = 1;
|
||||
|
||||
@Desc("For Iris-authored structures, whether solid partial blocks such as slabs, stairs, and walls may seed foundation columns instead of requiring a fully occluding base block.")
|
||||
private boolean supportNonOccluding = false;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package art.arcane.iris.engine.object.structure;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@Desc("An absolute world Y band a native structure is relocated into. Reversed bounds are normalized.")
|
||||
public class IrisStructureYBand {
|
||||
@MinNumber(-4064)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Lowest absolute world Y of the band.")
|
||||
private int min = 0;
|
||||
|
||||
@MinNumber(-4064)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Highest absolute world Y of the band.")
|
||||
private int max = 0;
|
||||
|
||||
public int resolvedMin() {
|
||||
return Math.min(min, max);
|
||||
}
|
||||
|
||||
public int resolvedMax() {
|
||||
return Math.max(min, max);
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
package art.arcane.iris.engine.object.structure.jigsaw;
|
||||
|
||||
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.RegistryListNativeJigsawPool;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@Desc("Optional overrides applied to a live vanilla, datapack, or modded jigsaw definition before Minecraft assembles it. Omitted values preserve the registered source definition.")
|
||||
public class IrisJigsawConfiguration {
|
||||
@Desc("Optional registered template-pool key used instead of the source jigsaw's start pool. Empty preserves the source pool.")
|
||||
@RegistryListNativeJigsawPool
|
||||
private String startPool = "";
|
||||
|
||||
@Desc("Optional start connector name. Empty preserves the source value; the literal NONE removes the source constraint.")
|
||||
private String startJigsawName = "";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(20)
|
||||
@Desc("Maximum jigsaw recursion depth. Null preserves the source value.")
|
||||
private Integer maxDepth = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(128)
|
||||
@Desc("Exact horizontal block distance allowed from the start. Null preserves the source value.")
|
||||
private Integer maxDistanceHorizontal = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4064)
|
||||
@Desc("Exact vertical block distance allowed from the start. Null preserves the source value.")
|
||||
private Integer maxDistanceVertical = null;
|
||||
|
||||
@Desc("Expansion-hack override. Null preserves the source value.")
|
||||
private Boolean useExpansionHack = null;
|
||||
|
||||
@Desc("Heightmap projection override. SOURCE preserves the registered value and NONE removes projection.")
|
||||
private IrisJigsawHeightmap projectStartToHeightmap = IrisJigsawHeightmap.SOURCE;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(Integer.MAX_VALUE)
|
||||
@Desc("Minimum distance retained above the dimension floor. Null preserves the source value.")
|
||||
private Integer dimensionPaddingBottom = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(Integer.MAX_VALUE)
|
||||
@Desc("Minimum distance retained below the dimension ceiling. Null preserves the source value.")
|
||||
private Integer dimensionPaddingTop = null;
|
||||
|
||||
@Desc("Waterlogging override. SOURCE preserves the registered value.")
|
||||
private IrisJigsawLiquidSettings liquidSettings = IrisJigsawLiquidSettings.SOURCE;
|
||||
|
||||
public boolean hasOverrides() {
|
||||
return (startPool != null && !startPool.isBlank())
|
||||
|| (startJigsawName != null && !startJigsawName.isBlank())
|
||||
|| maxDepth != null
|
||||
|| maxDistanceHorizontal != null
|
||||
|| maxDistanceVertical != null
|
||||
|| useExpansionHack != null
|
||||
|| (projectStartToHeightmap != null && projectStartToHeightmap != IrisJigsawHeightmap.SOURCE)
|
||||
|| dimensionPaddingBottom != null
|
||||
|| dimensionPaddingTop != null
|
||||
|| (liquidSettings != null && liquidSettings != IrisJigsawLiquidSettings.SOURCE);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package art.arcane.iris.engine.object.structure.jigsaw;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
|
||||
@Desc("Controls whether a configured native jigsaw projects its start onto a Minecraft heightmap.")
|
||||
public enum IrisJigsawHeightmap {
|
||||
@Desc("Keeps the registered structure's own heightmap projection exactly as the vanilla, datapack, or mod definition declares it.")
|
||||
SOURCE,
|
||||
|
||||
@Desc("Removes heightmap projection entirely, so the start piece lands at the structure's literal start height instead of following terrain.")
|
||||
NONE,
|
||||
|
||||
@Desc("Drops the start piece onto the terrain top counting water as solid, so ocean starts sit on the water surface.")
|
||||
WORLD_SURFACE_WG,
|
||||
|
||||
@Desc("Identical to WORLD_SURFACE_WG in Iris worlds: the start piece rides the terrain top including water.")
|
||||
WORLD_SURFACE,
|
||||
|
||||
@Desc("Drops the start piece onto solid terrain, ignoring water, so ocean starts sit on the seabed.")
|
||||
OCEAN_FLOOR_WG,
|
||||
|
||||
@Desc("Identical to OCEAN_FLOOR_WG in Iris worlds: the start piece sits on solid ground beneath any water.")
|
||||
OCEAN_FLOOR,
|
||||
|
||||
@Desc("Behaves like WORLD_SURFACE in Iris worlds; the start piece sits on the terrain top including water.")
|
||||
MOTION_BLOCKING,
|
||||
|
||||
@Desc("Behaves like WORLD_SURFACE in Iris worlds; Iris height queries have no leaf layer to skip.")
|
||||
MOTION_BLOCKING_NO_LEAVES
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package art.arcane.iris.engine.object.structure.jigsaw;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
|
||||
@Desc("Controls waterlogging behavior for a configured native jigsaw.")
|
||||
public enum IrisJigsawLiquidSettings {
|
||||
@Desc("Keeps the registered structure's own liquid setting; vanilla defaults to applying waterlogging when the definition omits it.")
|
||||
SOURCE,
|
||||
|
||||
@Desc("Places pieces dry: existing water is displaced and waterloggable blocks stay unwaterlogged, leaving air-filled interiors underwater.")
|
||||
IGNORE_WATERLOGGING,
|
||||
|
||||
@Desc("Re-applies pre-existing water into placed waterloggable blocks and floods from neighboring sources, so underwater pieces come out waterlogged.")
|
||||
APPLY_WATERLOGGING
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.engine.object.structure.vanilla;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure;
|
||||
@@ -9,6 +8,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.volmit.vanilla.JigsawOverrides;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@@ -26,5 +26,5 @@ public class IrisNativeStructure {
|
||||
private int weight = 1;
|
||||
|
||||
@Desc("Optional jigsaw-only assembly overrides. Null preserves the complete registered structure definition.")
|
||||
private IrisJigsawConfiguration jigsaw = null;
|
||||
private JigsawOverrides jigsaw = null;
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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.structure.vanilla;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructureYBand;
|
||||
public record IrisNativeStructureDecision(
|
||||
NativeStructureGenerationStatus status,
|
||||
int yShift,
|
||||
IrisStructureYBand yBand,
|
||||
boolean preserveSourceY,
|
||||
IrisStructureStiltSettings stilt,
|
||||
IrisStructureTerrain terrain
|
||||
) {
|
||||
public boolean generate() {
|
||||
return status == NativeStructureGenerationStatus.GENERATE_NATIVE;
|
||||
}
|
||||
|
||||
public IrisNativeStructureDecision withStatus(NativeStructureGenerationStatus replacement) {
|
||||
return new IrisNativeStructureDecision(
|
||||
replacement, yShift, yBand, preserveSourceY, stilt, terrain);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user