mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Remove the inline procedural objects
- Delete the tree, ruin, formation, coral, fungus and crystal generators and their placement types - Drop the proceduralObjects fields from biomes and regions - Remove their placement from the object mantle component, cache warmer, datapack export and mod biome adoption - Remove the procedural studio view and its icons - Remove the old decay-control placer and the tests for the removed generators
This commit is contained in:
1 parent
bdf6ad7cd0
commit
9c6d32a58b
103 files changed
+42
-10754
No files matched your search
@@ -25,7 +25,6 @@ import art.arcane.iris.generation.decoration.IrisDepositGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositVariant;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
@@ -225,8 +224,6 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
||||
@ArrayType(min = 1, type = IrisObjectPlacement.class)
|
||||
@Description("Objects define what schematics (iob files) iris will place in this biome")
|
||||
private KList<IrisObjectPlacement> objects = new KList<>();
|
||||
@Description("Procedural objects (such as trees) iris generates from scratch and places in this biome, instead of loading them from iob files")
|
||||
private IrisProceduralObjects proceduralObjects = new IrisProceduralObjects();
|
||||
@ArrayType(min = 1, type = IrisStructurePlacement.class)
|
||||
@Description("Structures define jigsaw or vanilla/datapack structures iris will place in this biome")
|
||||
private KList<IrisStructurePlacement> structures = new KList<>();
|
||||
|
||||
@@ -19,22 +19,11 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Shared low-level helpers for building procedural objects in memory: resolving a
|
||||
* single block id or a noise palette into a platform block state, and assembling a
|
||||
* raw block map into a centered IrisObject anchored so its y=0 layer sits one block
|
||||
* above the terrain surface (same convention the tree generator uses).
|
||||
* Block state helpers shared by object placement, decorators, terrain and the procedural objects: reading a state's
|
||||
* properties and material, normalizing waterlogging and spotting blocks that fall.
|
||||
*/
|
||||
public final class IrisProceduralBlocks {
|
||||
public static final String[] FACE_PROPERTIES = {"north", "east", "south", "west", "up", "down"};
|
||||
@@ -57,16 +46,6 @@ public final class IrisProceduralBlocks {
|
||||
return palette != null && palette.getPalette() != null && !palette.getPalette().isEmpty();
|
||||
}
|
||||
|
||||
public static NativeBlockState resolve(String block, IrisMaterialPalette palette, IrisData data, int x, int y, int z, RNG paletteRng) {
|
||||
if (paletteSet(palette)) {
|
||||
return palette.get(paletteRng, x, y, z, data);
|
||||
}
|
||||
if (block != null && !block.isEmpty()) {
|
||||
return B.getStateOrNull(block, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasProperty(NativeBlockState state, String property) {
|
||||
String key = state.key();
|
||||
int start = propertyStart(key, property);
|
||||
@@ -158,43 +137,4 @@ public final class IrisProceduralBlocks {
|
||||
String value = submerged && (enabled || authored) ? "true" : "false";
|
||||
return value.equals(current) ? state : state.withProperty("waterlogged", value);
|
||||
}
|
||||
|
||||
public static IrisObject assemble(Map<Vector3i, NativeBlockState> blocks) {
|
||||
if (blocks == null || blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (Vector3i v : blocks.keySet()) {
|
||||
minX = Math.min(minX, v.getBlockX());
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
minZ = Math.min(minZ, v.getBlockZ());
|
||||
maxX = Math.max(maxX, v.getBlockX());
|
||||
maxY = Math.max(maxY, v.getBlockY());
|
||||
maxZ = Math.max(maxZ, v.getBlockZ());
|
||||
}
|
||||
|
||||
int w = maxX - minX + 1;
|
||||
int h = maxY - minY + 1;
|
||||
int d = maxZ - minZ + 1;
|
||||
int cx = w / 2;
|
||||
int cy = h / 2;
|
||||
int cz = d / 2;
|
||||
|
||||
IrisObject object = new IrisObject(w, h, d);
|
||||
for (Map.Entry<Vector3i, NativeBlockState> entry : blocks.entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
int nx = v.getBlockX() - minX - cx;
|
||||
int ny = v.getBlockY() - cy + 1;
|
||||
int nz = v.getBlockZ() - minZ - cz;
|
||||
object.getBlocks().put(new IrisBlockVector(nx, ny, nz), entry.getValue());
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.decoration.coral.IrisCoral;
|
||||
import art.arcane.iris.generation.decoration.crystal.IrisCrystal;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormation;
|
||||
import art.arcane.iris.generation.decoration.fungus.IrisFungus;
|
||||
import art.arcane.iris.generation.decoration.ruin.IrisRuin;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisProceduralTree;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.ArrayType;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("procedural-objects")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("Procedurally generated objects placed in a biome or region. Unlike the objects block (which loads iob files), these are generated from scratch at world-gen time.")
|
||||
@Data
|
||||
public class IrisProceduralObjects {
|
||||
@ArrayType(min = 1, type = IrisProceduralTree.class)
|
||||
@Description("Procedurally generated trees.")
|
||||
private KList<IrisProceduralTree> trees = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = IrisRuin.class)
|
||||
@Description("Procedurally generated ruins (crumbling pillars, walls, arches, rubble).")
|
||||
private KList<IrisRuin> ruins = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = IrisFormation.class)
|
||||
@Description("Procedurally generated natural rock formations (spires, hoodoos, arches, sea stacks, boulders, basalt columns).")
|
||||
private KList<IrisFormation> formations = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = IrisCoral.class)
|
||||
@Description("Procedurally generated underwater coral structures.")
|
||||
private KList<IrisCoral> coral = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = IrisFungus.class)
|
||||
@Description("Procedurally generated mushrooms and shelf fungi.")
|
||||
private KList<IrisFungus> fungi = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = IrisCrystal.class)
|
||||
@Description("Procedurally generated crystal clusters (usually placed in caves).")
|
||||
private KList<IrisCrystal> crystals = new KList<>();
|
||||
|
||||
public KList<IrisProceduralPlacement> getAllPlacements() {
|
||||
KList<IrisProceduralPlacement> all = new KList<>();
|
||||
if (trees != null) {
|
||||
all.addAll(trees);
|
||||
}
|
||||
if (ruins != null) {
|
||||
all.addAll(ruins);
|
||||
}
|
||||
if (formations != null) {
|
||||
all.addAll(formations);
|
||||
}
|
||||
if (coral != null) {
|
||||
all.addAll(coral);
|
||||
}
|
||||
if (fungi != null) {
|
||||
all.addAll(fungi);
|
||||
}
|
||||
if (crystals != null) {
|
||||
all.addAll(crystals);
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getAllPlacements().isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
/**
|
||||
* A procedurally generated, placeable thing in a biome or region (trees, ruins,
|
||||
* formations, coral, fungi, crystals). Implementations bake a deterministic pool
|
||||
* of in-memory IrisObject variants and expose the placement controls the engine
|
||||
* needs to scatter them, exactly like an object placement but generated from
|
||||
* scratch instead of loaded from an iob file.
|
||||
*/
|
||||
public interface IrisProceduralPlacement {
|
||||
String getName();
|
||||
|
||||
double getChance();
|
||||
|
||||
int getDensity();
|
||||
|
||||
boolean isPlausible();
|
||||
|
||||
IrisObjectPlacement asPlacement();
|
||||
|
||||
IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room);
|
||||
|
||||
KList<IrisObject> getVariantObjects(IrisData data);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.coral;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CoralCanvas {
|
||||
public enum Role {
|
||||
STRUCTURE,
|
||||
TIP
|
||||
}
|
||||
|
||||
private static final long BIAS = 1L << 20;
|
||||
private static final long MASK = (1L << 21) - 1L;
|
||||
|
||||
private final Map<Long, Role> cells = new HashMap<>();
|
||||
|
||||
public void set(int x, int y, int z, Role role) {
|
||||
if (y < 0) {
|
||||
return;
|
||||
}
|
||||
long key = encode(x, y, z);
|
||||
Role existing = cells.get(key);
|
||||
if (existing == Role.TIP && role == Role.STRUCTURE) {
|
||||
return;
|
||||
}
|
||||
cells.put(key, role);
|
||||
}
|
||||
|
||||
public Map<Long, Role> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public static long encode(int x, int y, int z) {
|
||||
long ex = (x + BIAS) & MASK;
|
||||
long ey = (y + BIAS) & MASK;
|
||||
long ez = (z + BIAS) & MASK;
|
||||
return (ex << 42) | (ey << 21) | ez;
|
||||
}
|
||||
|
||||
public static int[] decode(long key) {
|
||||
int ez = (int) ((key & MASK) - BIAS);
|
||||
int ey = (int) (((key >> 21) & MASK) - BIAS);
|
||||
int ex = (int) (((key >> 42) & MASK) - BIAS);
|
||||
return new int[]{ex, ey, ez};
|
||||
}
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.coral;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CoralGenerator {
|
||||
private static final double GOLDEN_ANGLE = 137.50776405003785;
|
||||
|
||||
private CoralGenerator() {
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisCoral coral, int variantIndex, RNG rng, IrisData data) {
|
||||
int lo = Math.min(coral.getHeightMin(), coral.getHeightMax());
|
||||
int hi = Math.max(coral.getHeightMin(), coral.getHeightMax());
|
||||
int height = Math.max(2, rng.i(lo, hi + 1));
|
||||
long shapeSeed = rng.getSeed() + variantIndex * 31L;
|
||||
|
||||
CoralCanvas canvas = new CoralCanvas();
|
||||
switch (coral.getForm()) {
|
||||
case BRANCHING -> buildBranching(canvas, coral, height, shapeSeed, rng);
|
||||
case FAN -> buildFan(canvas, coral, height, shapeSeed);
|
||||
case BRAIN -> buildBrain(canvas, coral, height, shapeSeed);
|
||||
case PILLAR -> buildPillar(canvas, coral, height, shapeSeed);
|
||||
case TENDRIL -> buildTendril(canvas, coral, height, shapeSeed, rng);
|
||||
}
|
||||
|
||||
Map<Vector3i, NativeBlockState> resolved = resolve(canvas, coral, data);
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static void buildBranching(CoralCanvas canvas, IrisCoral coral, int height, long seed, RNG rng) {
|
||||
int stalkTop = Math.max(1, (int) Math.round(height * 0.5));
|
||||
for (int y = 0; y < stalkTop; y++) {
|
||||
placeWavy(canvas, coral, 0, y, 0, y, seed, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
|
||||
int count = Math.max(1, coral.getBranchCount());
|
||||
for (int b = 0; b < count; b++) {
|
||||
double az = branchAzimuth(coral, b, count, rng);
|
||||
int startY = stalkTop - 1 + (int) Math.round((b % 2) * 1.0);
|
||||
double[] tip = rasterizeArm(canvas, coral, 0, startY, 0, az,
|
||||
coral.getBranchElevation(), coral.getBranchLength(), seed + b * 131L);
|
||||
|
||||
placeTipCluster(canvas, coral, (int) Math.round(tip[0]), (int) Math.round(tip[1]), (int) Math.round(tip[2]),
|
||||
coral.getTipClusterRadius(), seed + b * 977L);
|
||||
|
||||
if (coral.isSubBranches()) {
|
||||
int subCount = Math.max(1, coral.getSubBranchCount());
|
||||
for (int s = 0; s < subCount; s++) {
|
||||
double subAz = az + (s - (subCount - 1) / 2.0) * 35.0;
|
||||
double subLen = coral.getBranchLength() * coral.getSubBranchScale();
|
||||
double[] subTip = rasterizeArm(canvas, coral,
|
||||
(int) Math.round(tip[0]), (int) Math.round(tip[1]), (int) Math.round(tip[2]),
|
||||
subAz, coral.getBranchElevation() + 10.0, subLen, seed + b * 131L + s * 17L + 5000L);
|
||||
placeTipCluster(canvas, coral, (int) Math.round(subTip[0]), (int) Math.round(subTip[1]), (int) Math.round(subTip[2]),
|
||||
Math.max(0, coral.getTipClusterRadius() - 1), seed + b * 977L + s * 53L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildFan(CoralCanvas canvas, IrisCoral coral, int height, long seed) {
|
||||
int half = Math.max(1, coral.getFanWidth());
|
||||
int tippedWidth = -1;
|
||||
for (int y = height - 1; y >= 0; y--) {
|
||||
double t = y / (double) Math.max(1, height - 1);
|
||||
double profile = Math.sin(Math.PI * t);
|
||||
int w = (int) Math.round(half * profile);
|
||||
for (int dx = -w; dx <= w; dx++) {
|
||||
canvas.set(dx, y, 0, CoralCanvas.Role.STRUCTURE);
|
||||
if (Math.abs(dx) > tippedWidth) {
|
||||
placeTip(canvas, coral, dx, y, 0, seed + dx);
|
||||
}
|
||||
}
|
||||
tippedWidth = Math.max(tippedWidth, w);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildBrain(CoralCanvas canvas, IrisCoral coral, int height, long seed) {
|
||||
int r = Math.max(1, coral.getBrainRadius());
|
||||
int ry = Math.max(1, Math.min(r, (int) Math.round(height * 0.6)));
|
||||
double rough = coral.getBrainRoughness();
|
||||
for (int dx = -r; dx <= r; dx++) {
|
||||
for (int dz = -r; dz <= r; dz++) {
|
||||
for (int dy = 0; dy <= ry * 2; dy++) {
|
||||
double nx = dx / (double) r;
|
||||
double ny = (dy - ry) / (double) ry;
|
||||
double nz = dz / (double) r;
|
||||
double d = nx * nx + ny * ny + nz * nz;
|
||||
double wobble = (TreeFunctions.valueNoise3D(dx, dy, dz, seed) - 0.5) * 2.0 * rough;
|
||||
if (d <= 1.0 + wobble) {
|
||||
canvas.set(dx, dy, dz, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildPillar(CoralCanvas canvas, IrisCoral coral, int height, long seed) {
|
||||
int r = Math.max(1, coral.getPillarRadius());
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int dx = -r; dx <= r; dx++) {
|
||||
for (int dz = -r; dz <= r; dz++) {
|
||||
if (dx * dx + dz * dz <= r * r) {
|
||||
canvas.set(dx, y, dz, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
placeTipCluster(canvas, coral, 0, height - 1, 0, coral.getTipClusterRadius(), seed);
|
||||
}
|
||||
|
||||
private static void buildTendril(CoralCanvas canvas, IrisCoral coral, int height, long seed, RNG rng) {
|
||||
int count = Math.max(1, coral.getTendrilCount());
|
||||
double radius = Math.max(0.0, coral.getSpread());
|
||||
for (int c = 0; c < count; c++) {
|
||||
double az = Math.toRadians(c * (360.0 / count));
|
||||
double bx = Math.cos(az) * radius * 0.5;
|
||||
double bz = Math.sin(az) * radius * 0.5;
|
||||
int tx = (int) Math.round(bx);
|
||||
int tz = (int) Math.round(bz);
|
||||
int top = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
placeWavy(canvas, coral, tx, y, tz, y * (c + 1), seed + c * 311L, CoralCanvas.Role.STRUCTURE);
|
||||
top = y;
|
||||
}
|
||||
placeTip(canvas, coral, tx, top, tz, seed + c * 311L);
|
||||
}
|
||||
}
|
||||
|
||||
private static double[] rasterizeArm(CoralCanvas canvas, IrisCoral coral, int ox, int oy, int oz,
|
||||
double azimuthDeg, double elevationDeg, double length, long seed) {
|
||||
double azRad = Math.toRadians(azimuthDeg);
|
||||
double elRad = Math.toRadians(elevationDeg);
|
||||
double dx = length * Math.cos(elRad) * Math.sin(azRad);
|
||||
double dy = length * Math.sin(elRad);
|
||||
double dz = length * Math.cos(elRad) * Math.cos(azRad);
|
||||
int steps = Math.max(1, (int) Math.round(Math.max(Math.abs(dy), Math.max(Math.abs(dx), Math.abs(dz)))));
|
||||
|
||||
double[] tip = new double[]{ox, oy, oz};
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
double sway = swayOffset(coral, t * length, seed);
|
||||
int x = (int) Math.round(ox + dx * t + sway);
|
||||
int y = (int) Math.round(oy + dy * t);
|
||||
int z = (int) Math.round(oz + dz * t - sway);
|
||||
canvas.set(x, y, z, CoralCanvas.Role.STRUCTURE);
|
||||
tip[0] = x;
|
||||
tip[1] = y;
|
||||
tip[2] = z;
|
||||
}
|
||||
return tip;
|
||||
}
|
||||
|
||||
private static void placeWavy(CoralCanvas canvas, IrisCoral coral, int x, int y, int z, double phase, long seed, CoralCanvas.Role role) {
|
||||
double sway = swayOffset(coral, phase, seed);
|
||||
int sx = (int) Math.round(sway);
|
||||
int sz = (int) Math.round(swayOffset(coral, phase + 53.0, seed + 7L));
|
||||
canvas.set(x + sx, y, z + sz, role);
|
||||
}
|
||||
|
||||
private static double swayOffset(IrisCoral coral, double phase, long seed) {
|
||||
double amount = Math.max(0.0, Math.min(1.0, coral.getSway()));
|
||||
if (amount <= 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
double n = TreeFunctions.valueNoise1D(phase * 0.35, seed) - 0.5;
|
||||
return n * 2.0 * amount * (1.0 + coral.getSpread() * 0.25);
|
||||
}
|
||||
|
||||
private static void placeTipCluster(CoralCanvas canvas, IrisCoral coral, int cx, int cy, int cz, int radius, long seed) {
|
||||
if (radius <= 0) {
|
||||
placeTip(canvas, coral, cx, cy, cz, seed);
|
||||
return;
|
||||
}
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dy = -radius; dy <= radius; dy++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
if (dx * dx + dy * dy + dz * dz <= radius * radius) {
|
||||
canvas.set(cx + dx, cy + dy, cz + dz, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
placeTip(canvas, coral, cx, cy + radius + 1, cz, seed);
|
||||
}
|
||||
|
||||
private static void placeTip(CoralCanvas canvas, IrisCoral coral, int x, int y, int z, long seed) {
|
||||
if (!hasTip(coral)) {
|
||||
return;
|
||||
}
|
||||
if (TreeFunctions.valueNoise1D(x * 31.0 + y * 17.0 + z * 13.0, seed) <= coral.getTipChance()) {
|
||||
canvas.set(x, y, z, CoralCanvas.Role.TIP);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasTip(IrisCoral coral) {
|
||||
return IrisProceduralBlocks.paletteSet(coral.getTipPalette())
|
||||
|| (coral.getTipBlock() != null && !coral.getTipBlock().isEmpty());
|
||||
}
|
||||
|
||||
private static double branchAzimuth(IrisCoral coral, int index, int count, RNG rng) {
|
||||
return switch (coral.getBranchAzimuth()) {
|
||||
case GOLDEN_ANGLE -> index * GOLDEN_ANGLE;
|
||||
case EVEN -> index * (360.0 / count);
|
||||
case RANDOM -> rng.d(0.0, 360.0);
|
||||
};
|
||||
}
|
||||
|
||||
private static Map<Vector3i, NativeBlockState> resolve(CoralCanvas canvas, IrisCoral coral, IrisData data) {
|
||||
Map<Vector3i, NativeBlockState> out = new HashMap<>();
|
||||
RNG paletteRng = new RNG(coral.getSeed());
|
||||
for (Map.Entry<Long, CoralCanvas.Role> entry : canvas.getCells().entrySet()) {
|
||||
int[] xyz = CoralCanvas.decode(entry.getKey());
|
||||
int x = xyz[0];
|
||||
int y = xyz[1];
|
||||
int z = xyz[2];
|
||||
NativeBlockState state;
|
||||
if (entry.getValue() == CoralCanvas.Role.TIP) {
|
||||
state = IrisProceduralBlocks.resolve(coral.getTipBlock(), coral.getTipPalette(), data, x, y, z, paletteRng);
|
||||
if (state == null) {
|
||||
state = IrisProceduralBlocks.resolve(coral.getBlock(), coral.getBlockPalette(), data, x, y, z, paletteRng);
|
||||
}
|
||||
} else {
|
||||
state = IrisProceduralBlocks.resolve(coral.getBlock(), coral.getBlockPalette(), data, x, y, z, paletteRng);
|
||||
}
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
if (coral.isWaterlogged() && IrisProceduralBlocks.hasProperty(state, "waterlogged")) {
|
||||
try {
|
||||
state = state.withProperty("waterlogged", "true");
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
out.put(new Vector3i(x, y, z), state);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.coral;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectLimit;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("coral")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A single procedurally generated coral reef structure. Iris bakes a pool of deterministic variants from these settings and scatters them across the seafloor at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. Mirrors the procedural tree system but tuned for underwater reefs: structural blocks are waterlogged so the coral stays alive, and placement defaults to anchoring on the terrain beneath the water surface.")
|
||||
@Data
|
||||
public class IrisCoral implements IrisProceduralPlacement {
|
||||
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
@Description("A human readable name used in logs and as the variant load key.")
|
||||
private String name = "coral";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per chunk for this coral to attempt placement. Use density for multiple per chunk.")
|
||||
private double chance = 0.4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, attempt this many placements in the chunk.")
|
||||
private int density = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("How many distinct variants to pre-bake for this coral. Higher means more variety at a small memory cost.")
|
||||
private int variants = 6;
|
||||
|
||||
@Description("The base seed for deterministic generation. The same seed and settings always bake the same variants.")
|
||||
private long seed = 1337;
|
||||
|
||||
@Description("The placement mode used to anchor the coral to the seafloor.")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
|
||||
|
||||
@Description("Rotate this coral's placement.")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
|
||||
@Description("Limit the max or min height of placement.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@Description("Whether this coral may place on the terrain surface, under carvings, or both.")
|
||||
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
|
||||
|
||||
@Description("If true (default for coral), the coral anchors on the terrain height beneath the water, so it grows up from the seafloor rather than floating at the water surface.")
|
||||
private boolean underwater = true;
|
||||
|
||||
@Description("Translate (offset) this placement along each axis; for example set a negative y to sink it into the seafloor.")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
|
||||
@Description("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
|
||||
private IrisStiltSettings stiltSettings;
|
||||
|
||||
@Description("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).")
|
||||
private IrisVacuumSettings vacuumSettings;
|
||||
|
||||
@Description("If true (default), every resolved coral block that is waterloggable is forced waterlogged so the coral does not die in water (coral fans, sea pickles and kelp also waterlog). Set false to place dead/dry coral.")
|
||||
private boolean waterlogged = true;
|
||||
|
||||
@Description("The overall silhouette this coral grows into (branching, fan, brain, pillar, tendril). Each form runs a different generation routine.")
|
||||
private IrisCoralForm form = IrisCoralForm.BRANCHING;
|
||||
|
||||
@Required
|
||||
@Description("The structural coral block (the living wood of the reef), e.g. minecraft:tube_coral_block. Ignored when blockPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String block = "minecraft:tube_coral_block";
|
||||
|
||||
@Description("A noise-driven palette for the structural coral block. When set this overrides the single block, letting the reef mix tube/brain/bubble/fire/horn coral_block tones across its body.")
|
||||
private IrisMaterialPalette blockPalette = null;
|
||||
|
||||
@Description("Optional tip block placed at branch tips and at the very top of the structure, e.g. coral fans or minecraft:sea_pickle. Ignored when tipPalette is set. Null disables tips.")
|
||||
@RegistryListBlockType
|
||||
private String tipBlock = null;
|
||||
|
||||
@Description("A noise-driven palette for the tip block. When set this overrides the single tipBlock, letting tips mix fan / pickle decorations.")
|
||||
private IrisMaterialPalette tipPalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per eligible tip position to place a tip block (coral fan / sea pickle).")
|
||||
private double tipChance = 0.6;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum overall height of the coral in blocks.")
|
||||
private int heightMin = 4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum overall height of the coral in blocks.")
|
||||
private int heightMax = 8;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Horizontal spread of the structure in blocks. For BRANCHING this is how far arms reach out, for BRAIN/PILLAR/FAN it widens the base footprint.")
|
||||
private double spread = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Lateral noise wobble (0-1) applied to branches and tendrils so they are not ruler-straight. 0 is perfectly straight, 1 is heavily wandering.")
|
||||
private double sway = 0.5;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(12)
|
||||
@Description("BRANCHING only: how many arms sprout from the central stalk.")
|
||||
private int branchCount = 4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("BRANCHING only: the length of each arm in blocks before reaching its tip.")
|
||||
private double branchLength = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(90)
|
||||
@Description("BRANCHING only: the upward elevation in degrees of each arm from horizontal. 90 is straight up, 0 is flat out.")
|
||||
private double branchElevation = 55;
|
||||
|
||||
@Description("BRANCHING only: how the arms are distributed around the stalk by azimuth.")
|
||||
private IrisCoralBranchAzimuth branchAzimuth = IrisCoralBranchAzimuth.GOLDEN_ANGLE;
|
||||
|
||||
@Description("BRANCHING only: if true, each arm splits once into a small fan of sub-arms for a bushier reef.")
|
||||
private boolean subBranches = true;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(5)
|
||||
@Description("BRANCHING only: how many sub-arms each arm splits into when subBranches is true.")
|
||||
private int subBranchCount = 2;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("BRANCHING only: the length of each sub-arm as a fraction of its parent arm.")
|
||||
private double subBranchScale = 0.5;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(4)
|
||||
@Description("BRANCHING and PILLAR only: the radius of the small coral tip cluster grown at each tip.")
|
||||
private int tipClusterRadius = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
@Description("BRAIN only: the horizontal radius of the brain-coral blob in blocks.")
|
||||
private int brainRadius = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("BRAIN only: how strongly 3D value noise perturbs the ellipsoid surface, for a wrinkled organic blob. 0 is a smooth dome.")
|
||||
private double brainRoughness = 0.35;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(12)
|
||||
@Description("PILLAR only: the radius of the stout vertical column in blocks.")
|
||||
private int pillarRadius = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
@Description("FAN only: the half-width of the upright fan plane in blocks (the disc widens toward its mid-height).")
|
||||
private int fanWidth = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(12)
|
||||
@Description("TENDRIL only: how many thin wavy stalks rise from the base.")
|
||||
private int tendrilCount = 4;
|
||||
|
||||
public KList<IrisObject> getVariantObjects(IrisData data) {
|
||||
return variantCache.aquire(() -> {
|
||||
KList<IrisObject> baked = new KList<>();
|
||||
int count = Math.max(1, variants);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
IrisObject object = CoralGenerator.generate(this, i, new RNG(seed + (i * 7919L)), data);
|
||||
if (object == null || object.getBlocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
object.setLoadKey("procedural/" + name + "#" + i);
|
||||
object.setLoader(data);
|
||||
baked.add(object);
|
||||
}
|
||||
|
||||
return baked;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room) {
|
||||
KList<IrisObject> baked = getVariantObjects(data);
|
||||
if (baked == null || baked.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return baked.get(rng.i(baked.size()));
|
||||
}
|
||||
|
||||
public IrisObjectPlacement asPlacement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(mode);
|
||||
placement.setRotation(rotation);
|
||||
placement.setClamp(clamp);
|
||||
placement.setCarvingSupport(carvingSupport);
|
||||
placement.setUnderwater(underwater);
|
||||
placement.setTranslate(translate);
|
||||
placement.setStiltSettings(stiltSettings);
|
||||
placement.setVacuumSettings(vacuumSettings);
|
||||
placement.setChance(chance);
|
||||
placement.setDensity(density);
|
||||
return placement;
|
||||
}
|
||||
|
||||
public boolean isPlausible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.coral;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("How the arms of a BRANCHING coral are distributed around the central stalk by compass azimuth.")
|
||||
public enum IrisCoralBranchAzimuth {
|
||||
@Description("Distribute arms by the golden angle (about 137.5 degrees per arm) for a natural phyllotactic spiral where no two arms overlap.")
|
||||
GOLDEN_ANGLE,
|
||||
|
||||
@Description("Distribute arms in evenly spaced spokes, dividing 360 degrees equally between them like a radial whorl.")
|
||||
EVEN,
|
||||
|
||||
@Description("Place each arm at a fully random azimuth using the deterministic per-variant RNG, for an irregular wild reef.")
|
||||
RANDOM
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.coral;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("The overall silhouette a procedural coral grows into. Each form drives a completely different generation routine in the coral generator, from tree-like branching arms to rounded brain blobs and thin wavy tendrils.")
|
||||
public enum IrisCoralForm {
|
||||
@Description("A tree-like coral built from a stout central stalk that sprouts several upward-leaning arms (distributed by golden angle or randomly), each optionally splitting once into sub-arms, with small coral tip clusters (fans / sea pickles) at the ends. The most structurally complex form and the closest analogue to a procedural tree.")
|
||||
BRANCHING,
|
||||
|
||||
@Description("A thin, single-block-thick vertical fan plane that rises and widens with height like a sheet of fire or horn coral. Reads as a flat decorative blade rather than a volume.")
|
||||
FAN,
|
||||
|
||||
@Description("A rounded, noise-perturbed ellipsoid blob of brain coral that bulges out of the seafloor like a boulder, with an irregular wrinkled surface driven by 3D value noise.")
|
||||
BRAIN,
|
||||
|
||||
@Description("A stout, thick vertical column of coral block topped with a dense tip cluster. Wider and blunter than a tendril, reading as a solid coral pillar or stack.")
|
||||
PILLAR,
|
||||
|
||||
@Description("Several very thin (one block wide) wavy stalks that rise upward and wander laterally using value noise, like a clump of swaying coral whips or kelp-thin growths.")
|
||||
TENDRIL
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
|
||||
public final class CrystalBaseBuilder {
|
||||
private CrystalBaseBuilder() {
|
||||
}
|
||||
|
||||
public static void build(CrystalCanvas canvas, IrisCrystal crystal, long seed) {
|
||||
double radius = crystal.getBaseRadius();
|
||||
if (radius <= 0.0) {
|
||||
canvas.set(0, 0, 0, CrystalRole.BASE);
|
||||
return;
|
||||
}
|
||||
|
||||
double noiseStrength = crystal.getBaseNoise();
|
||||
int reach = (int) Math.ceil(radius + 1.0);
|
||||
for (int x = -reach; x <= reach; x++) {
|
||||
for (int y = -reach; y <= reach; y++) {
|
||||
for (int z = -reach; z <= reach; z++) {
|
||||
double distance = Math.sqrt((double) x * x + (double) y * y + (double) z * z);
|
||||
double wobble = (TreeFunctions.valueNoise3D(x, y, z, seed) - 0.5) * 2.0 * noiseStrength * radius;
|
||||
if (distance <= radius + wobble) {
|
||||
canvas.set(x, y, z, CrystalRole.BASE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CrystalCanvas {
|
||||
private final Map<Vector3i, CrystalRole> cells = new HashMap<>();
|
||||
|
||||
public void set(int x, int y, int z, CrystalRole role) {
|
||||
Vector3i key = new Vector3i(x, y, z);
|
||||
CrystalRole existing = cells.get(key);
|
||||
if (existing == null || rank(role) > rank(existing)) {
|
||||
cells.put(key, role);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
public Map<Vector3i, CrystalRole> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static int rank(CrystalRole role) {
|
||||
return switch (role) {
|
||||
case BASE -> 0;
|
||||
case SHARD -> 1;
|
||||
case TIP -> 2;
|
||||
};
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CrystalGenerator {
|
||||
private CrystalGenerator() {
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisCrystal crystal, int variantIndex, RNG rng, IrisData data) {
|
||||
CrystalCanvas canvas = new CrystalCanvas();
|
||||
long structureSeed = rng.getSeed();
|
||||
|
||||
CrystalBaseBuilder.build(canvas, crystal, structureSeed + 977L);
|
||||
CrystalShardBuilder.build(canvas, crystal, rng);
|
||||
|
||||
Map<Vector3i, NativeBlockState> resolved = new HashMap<>();
|
||||
RNG paletteRng = new RNG(crystal.getSeed());
|
||||
RNG tipRng = new RNG(crystal.getSeed() + (variantIndex * 31337L) + 4099L);
|
||||
|
||||
for (Map.Entry<Vector3i, CrystalRole> entry : canvas.getCells().entrySet()) {
|
||||
Vector3i position = entry.getKey();
|
||||
int x = position.getBlockX();
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ();
|
||||
NativeBlockState blockData = resolveRole(crystal, entry.getValue(), data, x, y, z, paletteRng, tipRng);
|
||||
if (blockData == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(position, blockData);
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveRole(IrisCrystal crystal, CrystalRole role, IrisData data, int x, int y, int z, RNG paletteRng, RNG tipRng) {
|
||||
return switch (role) {
|
||||
case BASE -> resolveBase(crystal, data, x, y, z, paletteRng);
|
||||
case SHARD -> resolveShard(crystal, data, x, y, z, paletteRng);
|
||||
case TIP -> resolveTip(crystal, data, x, y, z, paletteRng, tipRng);
|
||||
};
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveBase(IrisCrystal crystal, IrisData data, int x, int y, int z, RNG paletteRng) {
|
||||
boolean hasBase = IrisProceduralBlocks.paletteSet(crystal.getBasePalette())
|
||||
|| (crystal.getBaseBlock() != null && !crystal.getBaseBlock().isEmpty());
|
||||
if (hasBase) {
|
||||
NativeBlockState base = IrisProceduralBlocks.resolve(crystal.getBaseBlock(), crystal.getBasePalette(), data, x, y, z, paletteRng);
|
||||
if (base != null) {
|
||||
return base;
|
||||
}
|
||||
}
|
||||
return resolveShard(crystal, data, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveShard(IrisCrystal crystal, IrisData data, int x, int y, int z, RNG paletteRng) {
|
||||
return IrisProceduralBlocks.resolve(crystal.getBlock(), crystal.getBlockPalette(), data, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveTip(IrisCrystal crystal, IrisData data, int x, int y, int z, RNG paletteRng, RNG tipRng) {
|
||||
boolean hasTip = IrisProceduralBlocks.paletteSet(crystal.getTipPalette())
|
||||
|| (crystal.getTipBlock() != null && !crystal.getTipBlock().isEmpty());
|
||||
|
||||
if (hasTip) {
|
||||
if (tipRng.chance(crystal.getTipChance())) {
|
||||
NativeBlockState tip = IrisProceduralBlocks.resolve(crystal.getTipBlock(), crystal.getTipPalette(), data, x, y, z, paletteRng);
|
||||
if (tip != null) {
|
||||
return tip;
|
||||
}
|
||||
}
|
||||
return resolveShard(crystal, data, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
if (crystal.isGlow() && crystal.getGlowBlock() != null && !crystal.getGlowBlock().isEmpty()) {
|
||||
if (tipRng.chance(crystal.getTipChance())) {
|
||||
NativeBlockState glow = IrisProceduralBlocks.resolve(crystal.getGlowBlock(), null, data, x, y, z, paletteRng);
|
||||
if (glow != null) {
|
||||
return glow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resolveShard(crystal, data, x, y, z, paletteRng);
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
|
||||
public final class CrystalGeometry {
|
||||
private CrystalGeometry() {
|
||||
}
|
||||
|
||||
public static double[] surfaceNormal(IrisCrystalSurface surface) {
|
||||
return switch (surface) {
|
||||
case FLOOR -> new double[]{0.0, 1.0, 0.0};
|
||||
case CEILING -> new double[]{0.0, -1.0, 0.0};
|
||||
case WALL -> {
|
||||
double len = Math.sqrt(1.0 + 0.5 * 0.5);
|
||||
yield new double[]{1.0 / len, 0.5 / len, 0.0};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static double[] orthonormalBasisU(double[] normal) {
|
||||
double[] reference = Math.abs(normal[1]) > 0.99 ? new double[]{1.0, 0.0, 0.0} : new double[]{0.0, 1.0, 0.0};
|
||||
double[] u = cross(reference, normal);
|
||||
normalize(u);
|
||||
return u;
|
||||
}
|
||||
|
||||
public static double[] orthonormalBasisV(double[] normal, double[] u) {
|
||||
double[] v = cross(normal, u);
|
||||
normalize(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static double[] coneDirection(double[] normal, double[] u, double[] v, double coneAngleRadians, double azimuthRadians) {
|
||||
double sin = Math.sin(coneAngleRadians);
|
||||
double cos = Math.cos(coneAngleRadians);
|
||||
double ca = Math.cos(azimuthRadians);
|
||||
double sa = Math.sin(azimuthRadians);
|
||||
double[] dir = new double[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
dir[i] = cos * normal[i] + sin * (ca * u[i] + sa * v[i]);
|
||||
}
|
||||
normalize(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static double[] cross(double[] a, double[] b) {
|
||||
return new double[]{
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0]
|
||||
};
|
||||
}
|
||||
|
||||
public static void normalize(double[] vec) {
|
||||
double len = Math.sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
|
||||
if (len < 1e-9) {
|
||||
vec[0] = 0.0;
|
||||
vec[1] = 1.0;
|
||||
vec[2] = 0.0;
|
||||
return;
|
||||
}
|
||||
vec[0] /= len;
|
||||
vec[1] /= len;
|
||||
vec[2] /= len;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
public enum CrystalRole {
|
||||
BASE,
|
||||
SHARD,
|
||||
TIP
|
||||
}
|
||||
-123
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class CrystalShardBuilder {
|
||||
private static final double GOLDEN_ANGLE = 137.50776405003785;
|
||||
|
||||
private CrystalShardBuilder() {
|
||||
}
|
||||
|
||||
public static void build(CrystalCanvas canvas, IrisCrystal crystal, RNG rng) {
|
||||
double[] normal = CrystalGeometry.surfaceNormal(crystal.getGrowthSurface());
|
||||
double[] u = CrystalGeometry.orthonormalBasisU(normal);
|
||||
double[] v = CrystalGeometry.orthonormalBasisV(normal, u);
|
||||
|
||||
int countLo = Math.min(crystal.getShardCountMin(), crystal.getShardCountMax());
|
||||
int countHi = Math.max(crystal.getShardCountMin(), crystal.getShardCountMax());
|
||||
int shardCount = Math.max(1, rng.i(countLo, countHi + 1));
|
||||
|
||||
int lengthLo = Math.min(crystal.getShardLengthMin(), crystal.getShardLengthMax());
|
||||
int lengthHi = Math.max(crystal.getShardLengthMin(), crystal.getShardLengthMax());
|
||||
|
||||
double spreadRadians = Math.toRadians(Math.max(0.0, Math.min(90.0, crystal.getSpreadAngle())));
|
||||
double jitterAmount = Math.max(0.0, Math.min(1.0, crystal.getJitter()));
|
||||
double emitRadius = Math.max(0.0, crystal.getBaseRadius() * 0.6);
|
||||
|
||||
for (int i = 0; i < shardCount; i++) {
|
||||
double azimuth = azimuth(crystal.getDistribution(), i, rng);
|
||||
azimuth += rng.d(-Math.PI, Math.PI) * jitterAmount * 0.5;
|
||||
|
||||
double cone = spreadRadians * fanFraction(shardCount, i, rng);
|
||||
cone += rng.d(-spreadRadians, spreadRadians) * jitterAmount * 0.5;
|
||||
cone = Math.max(0.0, Math.min(Math.PI / 2.0, cone));
|
||||
|
||||
double[] direction = CrystalGeometry.coneDirection(normal, u, v, cone, azimuth);
|
||||
|
||||
double ox = normal[0] * emitRadius + u[0] * Math.cos(azimuth) * emitRadius + v[0] * Math.sin(azimuth) * emitRadius;
|
||||
double oy = normal[1] * emitRadius + u[1] * Math.cos(azimuth) * emitRadius + v[1] * Math.sin(azimuth) * emitRadius;
|
||||
double oz = normal[2] * emitRadius + u[2] * Math.cos(azimuth) * emitRadius + v[2] * Math.sin(azimuth) * emitRadius;
|
||||
|
||||
int length = Math.max(1, rng.i(lengthLo, lengthHi + 1));
|
||||
rasterizeShard(canvas, crystal, ox, oy, oz, direction, length);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rasterizeShard(CrystalCanvas canvas, IrisCrystal crystal, double ox, double oy, double oz, double[] direction, int length) {
|
||||
double baseRadius = Math.max(0.5, crystal.getShardBaseRadius());
|
||||
double taper = Math.max(0.0, Math.min(1.0, crystal.getShardTaper()));
|
||||
|
||||
int samples = Math.max(1, length * 3);
|
||||
|
||||
for (int s = 0; s <= samples; s++) {
|
||||
double t = s / (double) samples;
|
||||
double cx = ox + direction[0] * length * t;
|
||||
double cy = oy + direction[1] * length * t;
|
||||
double cz = oz + direction[2] * length * t;
|
||||
|
||||
double radius = baseRadius * (1.0 - taper * t);
|
||||
if (t >= 1.0) {
|
||||
radius = 0.0;
|
||||
}
|
||||
radius = Math.max(0.0, radius);
|
||||
|
||||
int reach = (int) Math.floor(radius);
|
||||
int centerX = (int) Math.round(cx);
|
||||
int centerY = (int) Math.round(cy);
|
||||
int centerZ = (int) Math.round(cz);
|
||||
|
||||
if (reach <= 0) {
|
||||
canvas.set(centerX, centerY, centerZ, CrystalRole.SHARD);
|
||||
} else {
|
||||
for (int dx = -reach; dx <= reach; dx++) {
|
||||
for (int dy = -reach; dy <= reach; dy++) {
|
||||
for (int dz = -reach; dz <= reach; dz++) {
|
||||
double dist = Math.sqrt((double) dx * dx + (double) dy * dy + (double) dz * dz);
|
||||
if (dist <= radius) {
|
||||
canvas.set(centerX + dx, centerY + dy, centerZ + dz, CrystalRole.SHARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tipX = (int) Math.round(ox + direction[0] * length);
|
||||
int tipY = (int) Math.round(oy + direction[1] * length);
|
||||
int tipZ = (int) Math.round(oz + direction[2] * length);
|
||||
canvas.set(tipX, tipY, tipZ, CrystalRole.TIP);
|
||||
}
|
||||
|
||||
private static double azimuth(IrisCrystalDistribution distribution, int index, RNG rng) {
|
||||
if (distribution == IrisCrystalDistribution.GOLDEN_ANGLE) {
|
||||
return Math.toRadians(index * GOLDEN_ANGLE);
|
||||
}
|
||||
return rng.d(0.0, Math.PI * 2.0);
|
||||
}
|
||||
|
||||
private static double fanFraction(int count, int index, RNG rng) {
|
||||
if (count <= 1) {
|
||||
return rng.d(0.0, 1.0);
|
||||
}
|
||||
double base = index / (double) (count - 1);
|
||||
return Math.max(0.0, Math.min(1.0, base * 0.7 + rng.d(0.0, 0.3)));
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectLimit;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("crystal")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A single procedurally generated crystal cluster: a budding base blob with faceted, tapered shards radiating from it (geode / amethyst-style). Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. Built for caves.")
|
||||
@Data
|
||||
public class IrisCrystal implements IrisProceduralPlacement {
|
||||
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
@Description("A human readable name used in logs and as the variant load key.")
|
||||
private String name = "crystal";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per chunk for this crystal cluster to attempt placement. Use density for multiple per chunk.")
|
||||
private double chance = 0.2;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, attempt this many placements in the chunk.")
|
||||
private int density = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("How many distinct variants to pre-bake for this crystal cluster. Higher means more variety at a small memory cost.")
|
||||
private int variants = 6;
|
||||
|
||||
@Description("The base seed for deterministic generation. The same seed and settings always bake the same variants.")
|
||||
private long seed = 1337;
|
||||
|
||||
@Description("The placement mode used to anchor the crystal cluster to the terrain.")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
|
||||
|
||||
@Description("Rotate this crystal cluster's placement.")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
|
||||
@Description("Limit the max or min height of placement.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@Description("Whether this crystal cluster may place on the terrain surface, under carvings, or both. Crystals are meant for caves, so this defaults to CARVING_ONLY.")
|
||||
private CarvingMode carvingSupport = CarvingMode.CARVING_ONLY;
|
||||
|
||||
@Description("If true, the crystal cluster anchors on the terrain height ignoring the water surface.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
|
||||
@Description("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
|
||||
private IrisStiltSettings stiltSettings;
|
||||
|
||||
@Description("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).")
|
||||
private IrisVacuumSettings vacuumSettings;
|
||||
|
||||
@Description("The surface this crystal grows from (FLOOR shards up, CEILING shards down, WALL shards outward). This orients the baked geometry only.")
|
||||
private IrisCrystalSurface growthSurface = IrisCrystalSurface.FLOOR;
|
||||
|
||||
@Required
|
||||
@Description("The primary crystal shard block, e.g. minecraft:amethyst_block. Ignored when blockPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String block = "minecraft:amethyst_block";
|
||||
|
||||
@Description("A noise-driven palette for the crystal shards (a prismatic mix, e.g. amethyst_block, calcite, tinted_glass). When set this overrides the single block, letting the shards mix blocks by noise. Palette wins.")
|
||||
private IrisMaterialPalette blockPalette = null;
|
||||
|
||||
@Description("Optional block placed at the very tip of each shard for a different colored or sparkling point (e.g. minecraft:amethyst_cluster or glowstone). Ignored when tipPalette is set. If unset and glow is true, a light-emitting block is sprinkled among the tips instead.")
|
||||
@RegistryListBlockType
|
||||
private String tipBlock = null;
|
||||
|
||||
@Description("A noise-driven palette for the shard tips. When set this overrides the single tipBlock. Palette wins.")
|
||||
private IrisMaterialPalette tipPalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per shard that its very tip is replaced by the tip block (or glow block).")
|
||||
private double tipChance = 0.6;
|
||||
|
||||
@Description("If true and no tipBlock/tipPalette is set, sprinkle a light-emitting block (the glowBlock) among the shard tips for a sparkling geode.")
|
||||
private boolean glow = false;
|
||||
|
||||
@Description("The light-emitting block sprinkled among the tips when glow is true and no tip block is configured.")
|
||||
@RegistryListBlockType
|
||||
private String glowBlock = "minecraft:glowstone";
|
||||
|
||||
@Description("Optional block for the budding base blob the shards grow from, e.g. minecraft:budding_amethyst or calcite. Ignored when basePalette is set. If unset, the base is built from the primary shard block.")
|
||||
@RegistryListBlockType
|
||||
private String baseBlock = "minecraft:budding_amethyst";
|
||||
|
||||
@Description("A noise-driven palette for the budding base blob. When set this overrides the single baseBlock. Palette wins.")
|
||||
private IrisMaterialPalette basePalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Radius in blocks of the budding base blob the shards radiate from. 0 places no base blob (shards spring from a single point).")
|
||||
private double baseRadius = 1.6;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How strongly value noise perturbs the surface of the base blob, for a lumpy organic budding base rather than a clean sphere.")
|
||||
private double baseNoise = 0.35;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum number of shards radiating from the base.")
|
||||
private int shardCountMin = 5;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum number of shards radiating from the base.")
|
||||
private int shardCountMax = 11;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum length in blocks of a shard, measured from the base out to its pointed tip.")
|
||||
private int shardLengthMin = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum length in blocks of a shard, measured from the base out to its pointed tip.")
|
||||
private int shardLengthMax = 8;
|
||||
|
||||
@MinNumber(0.5)
|
||||
@Description("Starting radius in blocks of a shard at its thick base end. The shard tapers from this down to a single block at the tip.")
|
||||
private double shardBaseRadius = 1.4;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How aggressively each shard narrows from base to tip. 0 keeps a near-constant column; 1 tapers fully to a sharp point at the very tip. Each shard always ends in a single pointed block.")
|
||||
private double shardTaper = 0.85;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(90)
|
||||
@Description("The half-angle in degrees of the cone the shards fan within around the surface normal. 0 makes all shards parallel to the normal; larger values splay them outward into a starburst.")
|
||||
private double spreadAngle = 45;
|
||||
|
||||
@Description("How the shard azimuths are distributed around the normal (RANDOM for a chaotic clump, GOLDEN_ANGLE for an evenly spaced rosette).")
|
||||
private IrisCrystalDistribution distribution = IrisCrystalDistribution.GOLDEN_ANGLE;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Per-shard angular randomness (0-1) added on top of the chosen distribution so the cluster never looks mechanically regular. 0 is perfectly distributed; 1 is heavily jittered.")
|
||||
private double jitter = 0.25;
|
||||
|
||||
public KList<IrisObject> getVariantObjects(IrisData data) {
|
||||
return variantCache.aquire(() -> {
|
||||
KList<IrisObject> baked = new KList<>();
|
||||
int count = Math.max(1, variants);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
IrisObject object = CrystalGenerator.generate(this, i, new RNG(seed + (i * 7919L)), data);
|
||||
if (object == null || object.getBlocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
object.setLoadKey("procedural/" + name + "#" + i);
|
||||
object.setLoader(data);
|
||||
baked.add(object);
|
||||
}
|
||||
|
||||
return baked;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room) {
|
||||
KList<IrisObject> baked = getVariantObjects(data);
|
||||
if (baked == null || baked.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return baked.get(rng.i(baked.size()));
|
||||
}
|
||||
|
||||
public IrisObjectPlacement asPlacement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(mode);
|
||||
placement.setRotation(rotation);
|
||||
placement.setClamp(clamp);
|
||||
placement.setCarvingSupport(carvingSupport);
|
||||
placement.setUnderwater(underwater);
|
||||
placement.setTranslate(translate);
|
||||
placement.setStiltSettings(stiltSettings);
|
||||
placement.setVacuumSettings(vacuumSettings);
|
||||
placement.setChance(chance);
|
||||
placement.setDensity(density);
|
||||
return placement;
|
||||
}
|
||||
|
||||
public boolean isPlausible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("How the shards of a crystal cluster are angularly distributed around the surface normal.")
|
||||
public enum IrisCrystalDistribution {
|
||||
@Description("Each shard gets a uniformly random azimuth around the normal. Produces a chaotic, naturally clumped cluster.")
|
||||
RANDOM,
|
||||
|
||||
@Description("Each shard's azimuth advances by the golden angle (~137.5 degrees) from the previous one. Produces an evenly spaced sunflower-like fan with no two shards overlapping, ideal for a geode rosette.")
|
||||
GOLDEN_ANGLE
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.crystal;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("The surface a crystal cluster grows from. This only orients the baked geometry (which way the shards point); placement of the object into a cave is handled by the placement system, not here.")
|
||||
public enum IrisCrystalSurface {
|
||||
@Description("Grows from a cave floor. The budding base sits at the bottom and the shards point upward, fanning within the spread cone around the up axis. Built with positive py so the cluster grows up from the base layer.")
|
||||
FLOOR,
|
||||
|
||||
@Description("Grows from a cave ceiling. The budding base sits at the top and the shards point downward like stalactites, fanning within the spread cone around the down axis. Built with negative py so the cluster grows down from the ceiling.")
|
||||
CEILING,
|
||||
|
||||
@Description("Grows from a cave wall. The budding base hugs the wall and the shards point outward and slightly upward, fanning within the spread cone around a tilted normal so the cluster reads as a wall sconce of shards.")
|
||||
WALL
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public final class FormationBlockResolver {
|
||||
private final IrisFormation formation;
|
||||
private final IrisData data;
|
||||
private final RNG paletteRng;
|
||||
private final Int2ObjectOpenHashMap<RNG> strataRngs = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
public FormationBlockResolver(IrisFormation formation, IrisData data) {
|
||||
this.formation = formation;
|
||||
this.data = data;
|
||||
paletteRng = new RNG(formation.getSeed());
|
||||
}
|
||||
|
||||
public NativeBlockState resolve(FormationCanvas.Role role, Vector3i raw) {
|
||||
int x = raw.getBlockX();
|
||||
int y = raw.getBlockY();
|
||||
int z = raw.getBlockZ();
|
||||
|
||||
if (role == FormationCanvas.Role.CAP && capDefined(formation)) {
|
||||
NativeBlockState cap = IrisProceduralBlocks.resolve(formation.getCapBlock(), formation.getCapPalette(), data, x, y, z, paletteRng);
|
||||
if (cap != null) {
|
||||
return cap;
|
||||
}
|
||||
}
|
||||
|
||||
if (strataDefined(formation)) {
|
||||
IrisMaterialPalette strata = formation.getStrataPalette();
|
||||
int thickness = Math.max(1, formation.getStrataThickness());
|
||||
int band = Math.floorDiv(y, thickness);
|
||||
RNG strataRng = strataRngs.get(band);
|
||||
if (strataRng == null) {
|
||||
strataRng = new RNG(formation.getSeed() + band * 31L);
|
||||
strataRngs.put(band, strataRng);
|
||||
}
|
||||
NativeBlockState strataState = strata.get(strataRng, x, band, z, data);
|
||||
if (strataState != null) {
|
||||
return strataState;
|
||||
}
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.resolve(formation.getBlock(), formation.getBlockPalette(), data, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
private static boolean capDefined(IrisFormation f) {
|
||||
return IrisProceduralBlocks.paletteSet(f.getCapPalette()) || (f.getCapBlock() != null && !f.getCapBlock().isEmpty());
|
||||
}
|
||||
|
||||
private static boolean strataDefined(IrisFormation f) {
|
||||
return IrisProceduralBlocks.paletteSet(f.getStrataPalette());
|
||||
}
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FormationCanvas {
|
||||
public enum Role {
|
||||
BODY,
|
||||
CAP
|
||||
}
|
||||
|
||||
private final Map<Vector3i, Role> cells = new HashMap<>();
|
||||
|
||||
public void setBody(int x, int y, int z) {
|
||||
Vector3i key = new Vector3i(x, y, z);
|
||||
if (cells.get(key) == Role.CAP) {
|
||||
return;
|
||||
}
|
||||
cells.put(key, Role.BODY);
|
||||
}
|
||||
|
||||
public void setCap(int x, int y, int z) {
|
||||
cells.put(new Vector3i(x, y, z), Role.CAP);
|
||||
}
|
||||
|
||||
public void remove(int x, int y, int z) {
|
||||
cells.remove(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
public boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
public Map<Vector3i, Role> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cells.isEmpty();
|
||||
}
|
||||
}
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FormationGenerator {
|
||||
private FormationGenerator() {
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisFormation f, int variantIndex, RNG rng, IrisData data) {
|
||||
int lo = Math.min(f.getHeightMin(), f.getHeightMax());
|
||||
int hi = Math.max(f.getHeightMin(), f.getHeightMax());
|
||||
int height = Math.max(3, rng.i(lo, hi + 1));
|
||||
|
||||
return generate(f, variantIndex, rng, data, height);
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisFormation f, int variantIndex, RNG rng, IrisData data, int height) {
|
||||
int wLo = Math.min(f.getBaseWidthMin(), f.getBaseWidthMax());
|
||||
int wHi = Math.max(f.getBaseWidthMin(), f.getBaseWidthMax());
|
||||
double baseRadius = Math.max(1, rng.i(wLo, wHi + 1));
|
||||
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
|
||||
switch (f.getForm()) {
|
||||
case SPIRE -> FormationShapeBuilder.spire(canvas, f, height, baseRadius, rng);
|
||||
case HOODOO -> FormationShapeBuilder.hoodoo(canvas, f, height, baseRadius, rng);
|
||||
case ARCH -> FormationShapeBuilder.arch(canvas, f, height, baseRadius, rng);
|
||||
case SEA_STACK -> FormationShapeBuilder.seaStack(canvas, f, height, baseRadius, rng);
|
||||
case BOULDER -> FormationShapeBuilder.boulder(canvas, f, height, baseRadius, rng);
|
||||
case BASALT_COLUMN -> FormationShapeBuilder.basaltColumns(canvas, f, height, baseRadius, rng);
|
||||
case ICEBERG -> FormationShapeBuilder.iceberg(canvas, f, height, baseRadius, rng);
|
||||
case FISSURE -> FormationShapeBuilder.fissure(canvas, f, height, baseRadius, rng);
|
||||
case SPIRAL -> FormationShapeBuilder.spiral(canvas, f, height, baseRadius, rng);
|
||||
case OVERHANG -> FormationShapeBuilder.overhang(canvas, f, height, baseRadius, rng);
|
||||
}
|
||||
|
||||
if (canvas.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<Vector3i, NativeBlockState> resolved = new HashMap<>();
|
||||
FormationBlockResolver resolver = new FormationBlockResolver(f, data);
|
||||
for (Map.Entry<Vector3i, FormationCanvas.Role> entry : canvas.getCells().entrySet()) {
|
||||
NativeBlockState bd = resolver.resolve(entry.getValue(), entry.getKey());
|
||||
if (bd == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(entry.getKey(), bd);
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
|
||||
public final class FormationProfiles {
|
||||
private FormationProfiles() {
|
||||
}
|
||||
|
||||
public static double radiusAt(IrisFormation f, double baseRadius, double topRadius, double t) {
|
||||
double clamped = Math.max(0.0, Math.min(1.0, t));
|
||||
return switch (f.getProfile()) {
|
||||
case CONSTANT -> baseRadius;
|
||||
case LINEAR -> baseRadius + (topRadius - baseRadius) * clamped;
|
||||
case TAPER -> baseRadius + (topRadius - baseRadius) * smoothstep(clamped);
|
||||
case PARABOLIC -> parabolic(f, baseRadius, topRadius, clamped);
|
||||
case BULGE -> baseRadius + (Math.max(baseRadius, topRadius) - baseRadius) * bell(clamped) + (topRadius - baseRadius) * clamped * 0.25;
|
||||
};
|
||||
}
|
||||
|
||||
private static double parabolic(IrisFormation f, double baseRadius, double topRadius, double t) {
|
||||
double waist = Math.max(0.0, Math.min(1.0, f.getProfileWaist()));
|
||||
double floor = Math.max(0.0, Math.min(1.0, f.getProfileWaistFloor()));
|
||||
double denom = Math.pow(Math.max(waist, 1.0 - waist), 2);
|
||||
if (denom == 0) {
|
||||
denom = 1;
|
||||
}
|
||||
double envelope = baseRadius + (topRadius - baseRadius) * t;
|
||||
double pinch = floor + (1.0 - floor) * (Math.pow(t - waist, 2) / denom);
|
||||
return Math.max(0.5, envelope * pinch);
|
||||
}
|
||||
|
||||
private static double smoothstep(double t) {
|
||||
return 3.0 * t * t - 2.0 * t * t * t;
|
||||
}
|
||||
|
||||
private static double bell(double t) {
|
||||
return Math.exp(-Math.pow(t - 0.5, 2) / (2.0 * 0.22 * 0.22));
|
||||
}
|
||||
}
|
||||
-428
@@ -1,428 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FormationShapeBuilder {
|
||||
private FormationShapeBuilder() {
|
||||
}
|
||||
|
||||
public static void spire(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
double topRadius = f.getTopWidth();
|
||||
column(canvas, f, height, baseRadius, topRadius, 0, 0, rng, true);
|
||||
double lean = Math.toRadians(f.getLean());
|
||||
double azimuth = Math.toRadians(f.getLeanAzimuth());
|
||||
int previousX = 0;
|
||||
int previousZ = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
double shear = Math.tan(lean) * y;
|
||||
int centerX = (int) Math.round(Math.cos(azimuth) * shear);
|
||||
int centerZ = (int) Math.round(Math.sin(azimuth) * shear);
|
||||
boolean cap = y >= height - 2;
|
||||
for (int x = Math.min(previousX, centerX); x <= Math.max(previousX, centerX); x++) {
|
||||
setSpireCenter(canvas, x, y, previousZ, cap);
|
||||
}
|
||||
for (int z = Math.min(previousZ, centerZ); z <= Math.max(previousZ, centerZ); z++) {
|
||||
setSpireCenter(canvas, centerX, y, z, cap);
|
||||
}
|
||||
previousX = centerX;
|
||||
previousZ = centerZ;
|
||||
}
|
||||
}
|
||||
|
||||
public static void seaStack(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
double topRadius = Math.max(1.0, baseRadius * 0.55);
|
||||
if (f.getTopWidth() > 0) {
|
||||
topRadius = f.getTopWidth();
|
||||
}
|
||||
column(canvas, f, height, baseRadius, topRadius, 0, 0, rng, true);
|
||||
}
|
||||
|
||||
public static void hoodoo(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
double topRadius = f.getTopWidth() > 0 ? f.getTopWidth() : Math.max(1.0, baseRadius * 0.7);
|
||||
column(canvas, f, height, baseRadius, topRadius, 0, 0, rng, false);
|
||||
|
||||
int capRadius = f.getHoodooCapRadius();
|
||||
if (capRadius <= 0) {
|
||||
return;
|
||||
}
|
||||
int capHeight = Math.max(1, f.getHoodooCapHeight());
|
||||
double lean = Math.toRadians(f.getLean());
|
||||
double azimuth = Math.toRadians(f.getLeanAzimuth());
|
||||
double shear = Math.tan(lean) * height;
|
||||
double topOffX = Math.cos(azimuth) * shear;
|
||||
double topOffZ = Math.sin(azimuth) * shear;
|
||||
double wideRadius = topRadius + capRadius;
|
||||
|
||||
for (int cy = 0; cy < capHeight; cy++) {
|
||||
int y = height + cy;
|
||||
double shrink = capHeight <= 1 ? 0 : (cy / (double) (capHeight - 1)) * 0.5;
|
||||
double r = wideRadius * (1.0 - shrink);
|
||||
disc(canvas, f, (int) Math.round(topOffX), y, (int) Math.round(topOffZ), r, true, rng);
|
||||
}
|
||||
}
|
||||
|
||||
public static void boulder(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
double rx = baseRadius;
|
||||
double ry = Math.max(2.0, height * 0.5);
|
||||
double rz = baseRadius * (0.8 + rng.d(0.0, 0.3));
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.getRoughness()));
|
||||
long noiseSeed = f.getSeed() + 4201L;
|
||||
|
||||
int maxR = (int) Math.ceil(Math.max(rx, Math.max(ry, rz))) + 2;
|
||||
for (int x = -maxR; x <= maxR; x++) {
|
||||
for (int y = 0; y <= (int) Math.ceil(ry * 2) + 1; y++) {
|
||||
for (int z = -maxR; z <= maxR; z++) {
|
||||
double nx = x / rx;
|
||||
double ny = (y - ry) / ry;
|
||||
double nz = z / rz;
|
||||
double d = nx * nx + ny * ny + nz * nz;
|
||||
double wobble = (TreeFunctions.valueNoise3D(x, y, z, noiseSeed) - 0.5) * roughness * 0.9;
|
||||
if (d + wobble <= 1.0) {
|
||||
canvas.setBody(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void arch(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
double span = Math.max(2.0, f.getArchSpan());
|
||||
double tubeRadius = Math.max(0.75, f.getArchThickness() * 0.5);
|
||||
double asymmetry = Math.max(0.0, Math.min(1.0, f.getArchAsymmetry()));
|
||||
double leftFootX = -span * 0.5 - tubeRadius - rng.d(0.0, span * 0.16) * asymmetry;
|
||||
double rightFootX = span * 0.5 + tubeRadius + rng.d(0.0, span * 0.16) * asymmetry;
|
||||
double leftFootZ = rng.d(-tubeRadius * 0.45, tubeRadius * 0.45) * asymmetry;
|
||||
double rightFootZ = rng.d(-tubeRadius * 0.45, tubeRadius * 0.45) * asymmetry;
|
||||
double crownZ = rng.d(-span * 0.2, span * 0.2) * asymmetry;
|
||||
double crownShiftX = rng.d(-span * 0.12, span * 0.12) * asymmetry;
|
||||
double depthTwist = rng.d(-span * 0.1, span * 0.1) * asymmetry;
|
||||
double crownPosition = 0.5 + rng.d(-0.12, 0.12) * asymmetry;
|
||||
double leftSteepness = 0.58 + rng.d(-0.16, 0.16) * asymmetry;
|
||||
double rightSteepness = 0.58 + rng.d(-0.16, 0.16) * asymmetry;
|
||||
double radiusWave = rng.d(-0.22, 0.22) * asymmetry;
|
||||
double radiusPhase = rng.d(0.0, Math.PI * 2.0);
|
||||
double crownCenterY = Math.max(tubeRadius + 2.0, height - 1.0 - tubeRadius);
|
||||
double footRadius = tubeRadius + Math.min(tubeRadius * 0.45, baseRadius * 0.18);
|
||||
long noiseSeed = rng.nextLong();
|
||||
int steps = Math.max(24, (int) Math.ceil((rightFootX - leftFootX + height) * 4.0));
|
||||
|
||||
ball(canvas, f, (int) Math.round(leftFootX), (int) Math.round(footRadius),
|
||||
(int) Math.round(leftFootZ), footRadius, false, noiseSeed, rng);
|
||||
ball(canvas, f, (int) Math.round(rightFootX), (int) Math.round(footRadius),
|
||||
(int) Math.round(rightFootZ), footRadius, false, noiseSeed, rng);
|
||||
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = step / (double) steps;
|
||||
double normalizedRise;
|
||||
double steepness;
|
||||
if (t <= crownPosition) {
|
||||
normalizedRise = Math.sin((t / crownPosition) * Math.PI * 0.5);
|
||||
steepness = leftSteepness;
|
||||
} else {
|
||||
normalizedRise = Math.sin(((1.0 - t) / (1.0 - crownPosition)) * Math.PI * 0.5);
|
||||
steepness = rightSteepness;
|
||||
}
|
||||
double rise = Math.pow(Math.max(0.0, normalizedRise), steepness);
|
||||
double x = leftFootX + (rightFootX - leftFootX) * t
|
||||
+ Math.sin(Math.PI * t) * crownShiftX;
|
||||
double inverse = 1.0 - t;
|
||||
double z = inverse * inverse * leftFootZ + 2.0 * inverse * t * crownZ + t * t * rightFootZ
|
||||
+ Math.sin(Math.PI * 2.0 * t) * depthTwist;
|
||||
double y = tubeRadius + (crownCenterY - tubeRadius) * rise;
|
||||
double radius = tubeRadius * (1.0 + radiusWave * Math.sin(Math.PI * t)
|
||||
* Math.sin(Math.PI * 2.0 * t + radiusPhase));
|
||||
radius = Math.max(tubeRadius * 0.68, Math.min(tubeRadius * 1.32, radius));
|
||||
ball(canvas, f, (int) Math.round(x), (int) Math.round(y), (int) Math.round(z),
|
||||
radius, false, noiseSeed, rng);
|
||||
}
|
||||
if (asymmetry == 0.0) {
|
||||
mirrorAcrossX(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
public static void basaltColumns(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
int count = Math.max(2, f.getBasaltColumns());
|
||||
int colRadius = Math.max(1, f.getBasaltColumnRadius());
|
||||
double variance = Math.max(0.0, Math.min(1.0, f.getBasaltHeightVariance()));
|
||||
int spread = (int) Math.ceil(baseRadius);
|
||||
|
||||
for (int c = 0; c < count; c++) {
|
||||
double angle = rng.d(0.0, Math.PI * 2.0);
|
||||
double dist = rng.d(0.0, spread);
|
||||
int ox = (int) Math.round(Math.cos(angle) * dist);
|
||||
int oz = (int) Math.round(Math.sin(angle) * dist);
|
||||
double hVar = 1.0 - variance + rng.d(0.0, variance * 2.0);
|
||||
int colHeight = Math.max(3, (int) Math.round(height * hVar));
|
||||
|
||||
for (int y = 0; y < colHeight; y++) {
|
||||
for (int x = -colRadius; x <= colRadius; x++) {
|
||||
for (int z = -colRadius; z <= colRadius; z++) {
|
||||
if (Math.abs(x) + Math.abs(z) > colRadius) {
|
||||
continue;
|
||||
}
|
||||
canvas.setBody(ox + x, y, oz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (colRadius > 0) {
|
||||
canvas.setCap(ox, colHeight - 1, oz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void iceberg(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
long noiseSeed = rng.nextLong();
|
||||
double bodyHeight = Math.max(2.0, height * 0.42);
|
||||
double radiusX = baseRadius * rng.d(1.15, 1.5);
|
||||
double radiusZ = baseRadius * rng.d(1.0, 1.35);
|
||||
ellipsoid(canvas, radiusX, bodyHeight, radiusZ, bodyHeight * 0.36, noiseSeed, f.getRoughness());
|
||||
|
||||
int peaks = Math.max(1, f.getIcebergPeaks());
|
||||
double phase = rng.d(0.0, Math.PI * 2.0);
|
||||
for (int i = 0; i < peaks; i++) {
|
||||
double angle = phase + (Math.PI * 2.0 * i / peaks) + rng.d(-0.35, 0.35);
|
||||
double distance = rng.d(0.0, baseRadius * 0.62);
|
||||
int offsetX = (int) Math.round(Math.cos(angle) * distance);
|
||||
int offsetZ = (int) Math.round(Math.sin(angle) * distance);
|
||||
int peakHeight = Math.max(3, (int) Math.round(height * rng.d(0.58, 1.0)));
|
||||
double peakRadius = Math.max(1.0, baseRadius * rng.d(0.28, 0.58));
|
||||
double leanDistance = rng.d(0.0, Math.max(1.0, baseRadius * 0.45));
|
||||
taperedPeak(canvas, f, peakHeight, peakRadius, offsetX, offsetZ, angle, leanDistance, rng);
|
||||
}
|
||||
}
|
||||
|
||||
public static void fissure(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
int count = Math.max(2, f.getFractureCount());
|
||||
double separation = Math.max(1.0, f.getFractureSeparation());
|
||||
double shardRadius = Math.max(1.0, baseRadius / Math.max(1.6, count * 0.72));
|
||||
double phase = rng.d(0.0, Math.PI * 2.0);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
double lane = i - ((count - 1) / 2.0);
|
||||
double offset = lane * (shardRadius * 2.0 + separation);
|
||||
int offsetX = (int) Math.round(Math.cos(phase) * offset);
|
||||
int offsetZ = (int) Math.round(Math.sin(phase) * offset);
|
||||
double outwardAngle = lane < 0 ? phase + Math.PI : phase;
|
||||
int shardHeight = Math.max(3, (int) Math.round(height * rng.d(0.62, 1.0)));
|
||||
double leanDistance = rng.d(separation * 0.4, separation + baseRadius * 0.8);
|
||||
taperedPeak(canvas, f, shardHeight, shardRadius, offsetX, offsetZ, outwardAngle, leanDistance, rng);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spiral(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
int steps = Math.max(12, height * 4);
|
||||
double turns = Math.max(0.25, f.getSpiralTurns());
|
||||
double startRadius = Math.max(1.0, f.getSpiralRadius());
|
||||
double startThickness = Math.max(1.0, f.getSpiralThickness());
|
||||
double phase = rng.d(0.0, Math.PI * 2.0);
|
||||
long noiseSeed = rng.nextLong();
|
||||
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = step / (double) steps;
|
||||
double angle = phase + Math.PI * 2.0 * turns * t;
|
||||
double radius = startRadius * (1.0 - 0.72 * t);
|
||||
int x = (int) Math.round(Math.cos(angle) * radius);
|
||||
int y = (int) Math.round(t * (height - 1));
|
||||
int z = (int) Math.round(Math.sin(angle) * radius);
|
||||
double thickness = Math.max(0.75, startThickness * (1.0 - 0.48 * t));
|
||||
ball(canvas, f, x, y, z, thickness, step == steps, noiseSeed, rng);
|
||||
}
|
||||
|
||||
double footRadius = Math.max(1.0, Math.min(baseRadius, startThickness + 1.0));
|
||||
disc(canvas, f, (int) Math.round(Math.cos(phase) * startRadius), 0,
|
||||
(int) Math.round(Math.sin(phase) * startRadius), footRadius, false, rng);
|
||||
}
|
||||
|
||||
public static void overhang(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, RNG rng) {
|
||||
int steps = Math.max(12, height * 4);
|
||||
double reach = Math.max(1.0, f.getOverhangReach());
|
||||
double drop = Math.max(0.0, f.getOverhangDrop());
|
||||
double phase = Math.toRadians(f.getLeanAzimuth()) + rng.d(-0.18, 0.18);
|
||||
double trunkHeight = Math.max(3.0, height * 0.62);
|
||||
long noiseSeed = rng.nextLong();
|
||||
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = step / (double) steps;
|
||||
double extension;
|
||||
double y;
|
||||
if (t <= 0.58) {
|
||||
double rise = t / 0.58;
|
||||
extension = reach * 0.16 * rise * rise;
|
||||
y = trunkHeight * rise;
|
||||
} else {
|
||||
double hook = (t - 0.58) / 0.42;
|
||||
extension = reach * (0.16 + 0.84 * Math.sin(hook * Math.PI * 0.5));
|
||||
y = trunkHeight + Math.sin(hook * Math.PI) * height * 0.18 - drop * hook * hook;
|
||||
}
|
||||
int x = (int) Math.round(Math.cos(phase) * extension);
|
||||
int z = (int) Math.round(Math.sin(phase) * extension);
|
||||
double thickness = Math.max(0.9, baseRadius * (1.0 - 0.64 * t));
|
||||
ball(canvas, f, x, Math.max(0, (int) Math.round(y)), z, thickness, step == steps, noiseSeed, rng);
|
||||
}
|
||||
}
|
||||
|
||||
private static void column(FormationCanvas canvas, IrisFormation f, int height, double baseRadius, double topRadius, int extraBaseX, int extraBaseZ, RNG rng, boolean capTop) {
|
||||
double lean = Math.toRadians(f.getLean());
|
||||
double azimuth = Math.toRadians(f.getLeanAzimuth());
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.getRoughness()));
|
||||
double jitter = Math.max(0.0, Math.min(1.0, f.getJitter()));
|
||||
long noiseSeed = f.getSeed() + 9001L;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
double t = height <= 1 ? 1.0 : (y / (double) (height - 1));
|
||||
double radius = FormationProfiles.radiusAt(f, baseRadius, topRadius, t);
|
||||
double shear = Math.tan(lean) * y;
|
||||
int cx = extraBaseX + (int) Math.round(Math.cos(azimuth) * shear);
|
||||
int cz = extraBaseZ + (int) Math.round(Math.sin(azimuth) * shear);
|
||||
boolean cap = capTop && y >= height - 2;
|
||||
ringDisc(canvas, f, cx, y, cz, radius, roughness, jitter, noiseSeed, cap, rng);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setSpireCenter(FormationCanvas canvas, int x, int y, int z, boolean cap) {
|
||||
if (cap) {
|
||||
canvas.setCap(x, y, z);
|
||||
} else {
|
||||
canvas.setBody(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ringDisc(FormationCanvas canvas, IrisFormation f, int cx, int y, int cz, double radius, double roughness, double jitter, long noiseSeed, boolean cap, RNG rng) {
|
||||
int r = (int) Math.ceil(radius) + 1;
|
||||
for (int x = -r; x <= r; x++) {
|
||||
for (int z = -r; z <= r; z++) {
|
||||
double dist = Math.sqrt(x * x + z * z);
|
||||
double perturb = (TreeFunctions.valueNoise3D(cx + x, y, cz + z, noiseSeed) - 0.5) * roughness * (radius + 1.0);
|
||||
double effective = radius + perturb;
|
||||
if (dist <= effective) {
|
||||
if (jitter > 0 && dist > effective - 1.0 && rng.chance(jitter * 0.5)) {
|
||||
continue;
|
||||
}
|
||||
if (cap) {
|
||||
canvas.setCap(cx + x, y, cz + z);
|
||||
} else {
|
||||
canvas.setBody(cx + x, y, cz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void disc(FormationCanvas canvas, IrisFormation f, int cx, int y, int cz, double radius, boolean cap, RNG rng) {
|
||||
int r = (int) Math.ceil(radius) + 1;
|
||||
for (int x = -r; x <= r; x++) {
|
||||
for (int z = -r; z <= r; z++) {
|
||||
if (Math.sqrt(x * x + z * z) <= radius) {
|
||||
if (cap) {
|
||||
canvas.setCap(cx + x, y, cz + z);
|
||||
} else {
|
||||
canvas.setBody(cx + x, y, cz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void taperedPeak(FormationCanvas canvas, IrisFormation f, int height, double radius,
|
||||
int offsetX, int offsetZ, double leanAngle, double leanDistance, RNG rng) {
|
||||
long noiseSeed = rng.nextLong();
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.getRoughness()));
|
||||
double jitter = Math.max(0.0, Math.min(1.0, f.getJitter()));
|
||||
for (int y = 0; y < height; y++) {
|
||||
double t = height <= 1 ? 1.0 : y / (double) (height - 1);
|
||||
int x = offsetX + (int) Math.round(Math.cos(leanAngle) * leanDistance * t * t);
|
||||
int z = offsetZ + (int) Math.round(Math.sin(leanAngle) * leanDistance * t * t);
|
||||
double layerRadius = Math.max(0.45, radius * Math.pow(1.0 - t, 0.72));
|
||||
ringDisc(canvas, f, x, y, z, layerRadius, roughness, jitter, noiseSeed, y >= height - 2, rng);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ellipsoid(FormationCanvas canvas, double radiusX, double radiusY, double radiusZ,
|
||||
double centerY, long noiseSeed, double configuredRoughness) {
|
||||
double roughness = Math.max(0.0, Math.min(1.0, configuredRoughness));
|
||||
int maxX = (int) Math.ceil(radiusX) + 1;
|
||||
int maxY = (int) Math.ceil(radiusY) + 1;
|
||||
int maxZ = (int) Math.ceil(radiusZ) + 1;
|
||||
for (int x = -maxX; x <= maxX; x++) {
|
||||
for (int y = 0; y <= maxY; y++) {
|
||||
for (int z = -maxZ; z <= maxZ; z++) {
|
||||
double nx = x / radiusX;
|
||||
double ny = (y - centerY) / radiusY;
|
||||
double nz = z / radiusZ;
|
||||
double distance = nx * nx + ny * ny + nz * nz;
|
||||
double wobble = (TreeFunctions.valueNoise3D(x, y, z, noiseSeed) - 0.5) * roughness * 0.55;
|
||||
if (distance + wobble <= 1.0) {
|
||||
canvas.setBody(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ball(FormationCanvas canvas, IrisFormation f, int centerX, int centerY, int centerZ,
|
||||
double radius, boolean cap, long noiseSeed, RNG rng) {
|
||||
int extent = (int) Math.ceil(radius);
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.getRoughness()));
|
||||
double jitter = Math.max(0.0, Math.min(1.0, f.getJitter()));
|
||||
for (int x = -extent; x <= extent; x++) {
|
||||
for (int y = -extent; y <= extent; y++) {
|
||||
for (int z = -extent; z <= extent; z++) {
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
double perturb = (TreeFunctions.valueNoise3D(centerX + x, centerY + y, centerZ + z, noiseSeed) - 0.5)
|
||||
* roughness * Math.max(1.0, radius * 0.6);
|
||||
double effectiveRadius = radius + perturb;
|
||||
if (distance > effectiveRadius + 0.2) {
|
||||
continue;
|
||||
}
|
||||
if (jitter > 0.0 && distance > effectiveRadius - 0.75 && rng.chance(jitter * 0.35)) {
|
||||
continue;
|
||||
}
|
||||
int targetY = centerY + y;
|
||||
if (targetY < 0) {
|
||||
continue;
|
||||
}
|
||||
if (cap) {
|
||||
canvas.setCap(centerX + x, targetY, centerZ + z);
|
||||
} else {
|
||||
canvas.setBody(centerX + x, targetY, centerZ + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void mirrorAcrossX(FormationCanvas canvas) {
|
||||
Map<Vector3i, FormationCanvas.Role> cells = new HashMap<>(canvas.getCells());
|
||||
for (Map.Entry<Vector3i, FormationCanvas.Role> entry : cells.entrySet()) {
|
||||
Vector3i position = entry.getKey();
|
||||
if (entry.getValue() == FormationCanvas.Role.CAP) {
|
||||
canvas.setCap(-position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
} else {
|
||||
canvas.setBody(-position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-317
@@ -1,317 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectLimit;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("formation")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A single procedurally generated natural formation, including rock landmarks and magical glacial silhouettes. Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file.")
|
||||
@Data
|
||||
public class IrisFormation implements IrisProceduralPlacement {
|
||||
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
@Description("A human readable name used in logs and as the variant load key.")
|
||||
private String name = "formation";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per chunk for this formation to attempt placement. Use density for multiple per chunk.")
|
||||
private double chance = 0.02;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, attempt this many placements in the chunk.")
|
||||
private int density = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("How many distinct variants to pre-bake for this formation. Higher means more variety at a small memory cost.")
|
||||
private int variants = 6;
|
||||
|
||||
@Description("The base seed for deterministic generation. The same seed and settings always bake the same variants.")
|
||||
private long seed = 1337;
|
||||
|
||||
@Description("The placement mode used to anchor the formation to the terrain.")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
|
||||
|
||||
@Description("Rotate this formation's placement.")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
|
||||
@Description("Limit the max or min height of placement.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@Description("Whether this formation may place on the terrain surface, under carvings, or both.")
|
||||
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(16)
|
||||
@Description("Horizontal buffer, in blocks, beyond each lowest solid foundation block that must also be solid, un-carved ground.")
|
||||
private int surfaceSupportBuffer = 3;
|
||||
|
||||
@Description("If true, the formation anchors on the terrain height ignoring the water surface.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
|
||||
@Description("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
|
||||
private IrisStiltSettings stiltSettings;
|
||||
|
||||
@Description("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).")
|
||||
private IrisVacuumSettings vacuumSettings;
|
||||
|
||||
@Description("The overall silhouette of the formation. Drives which sculpting routine the generator uses.")
|
||||
private IrisFormationForm form = IrisFormationForm.SPIRE;
|
||||
|
||||
@Required
|
||||
@Description("The main rock block, e.g. minecraft:stone. Ignored when blockPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String block = "minecraft:stone";
|
||||
|
||||
@Description("A noise-driven palette for the main rock body. When set this overrides the single block, letting the body mix blocks by noise.")
|
||||
private IrisMaterialPalette blockPalette = null;
|
||||
|
||||
@Description("Optional caprock block placed on the top crown of the formation (and the wide overhanging cap for HOODOO). Ignored when capPalette is set. When null and capPalette is unset, the formation uses its main rock everywhere.")
|
||||
@RegistryListBlockType
|
||||
private String capBlock = null;
|
||||
|
||||
@Description("A noise-driven palette for the caprock. When set this overrides the single capBlock.")
|
||||
private IrisMaterialPalette capPalette = null;
|
||||
|
||||
@Description("Optional palette of strata (horizontal colored bands) blended into the rock body by y level. When set, every strataThickness blocks of height switches to the next strata block, producing the signature banded look. Falls back to the main block where unset.")
|
||||
private IrisMaterialPalette strataPalette = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(32)
|
||||
@Description("The thickness in blocks of each horizontal strata band when strataPalette is set.")
|
||||
private int strataThickness = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum total height of the formation in blocks.")
|
||||
private int heightMin = 14;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum total height of the formation in blocks.")
|
||||
private int heightMax = 26;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum base radius (half-width) of the formation in blocks.")
|
||||
private int baseWidthMin = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum base radius (half-width) of the formation in blocks.")
|
||||
private int baseWidthMax = 6;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("The target radius (half-width) at the very top of the formation in blocks, before the profile is applied. 0 means taper to a point.")
|
||||
private int topWidth = 0;
|
||||
|
||||
@Description("The function used to shape the formation radius over its height.")
|
||||
private IrisFormationProfile profile = IrisFormationProfile.TAPER;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The normalized height (0 base, 1 top) of the pinched waist for the PARABOLIC profile (used by HOODOO).")
|
||||
private double profileWaist = 0.55;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The minimum radius fraction at the waist for the PARABOLIC profile. Lower values pinch the waist tighter.")
|
||||
private double profileWaistFloor = 0.35;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("How far the formation leans, in degrees from vertical. 0 is perfectly upright. The whole body is sheared by this amount over its height.")
|
||||
private double lean = 0;
|
||||
|
||||
@Description("Compass direction in degrees the formation leans toward when lean is non-zero.")
|
||||
private double leanAzimuth = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Surface roughness from 0 (a clean smooth solid) to 1 (heavily eroded and pitted). Driven by 3D value noise that perturbs the radius so the formation never reads as a clean cylinder.")
|
||||
private double roughness = 0.3;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Per-block surface jitter from 0 (none) to 1 (maximum). Randomly carves and adds isolated edge blocks to break up the silhouette.")
|
||||
private double jitter = 0.15;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Extra wide cap radius in blocks added on top for the HOODOO form, producing the overhanging mushroom caprock. 0 disables the overhang.")
|
||||
private int hoodooCapRadius = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(6)
|
||||
@Description("The height in blocks of the HOODOO overhanging caprock slab.")
|
||||
private int hoodooCapHeight = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("How wide the ARCH opening is in blocks (the gap between the two legs). The arch span is rasterized over this width.")
|
||||
private int archSpan = 10;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("The thickness in blocks of the ARCH legs and spanning curve.")
|
||||
private int archThickness = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How strongly an ARCH varies its leg steepness, crown position, depth bow and tube width between deterministic variants. 0 is symmetric and 1 is highly organic.")
|
||||
private double archAsymmetry = 0.35;
|
||||
|
||||
@MinNumber(2)
|
||||
@MaxNumber(12)
|
||||
@Description("How many separate columns make up a BASALT_COLUMN cluster. Each column gets a randomized height around the formation height range.")
|
||||
private int basaltColumns = 5;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("The radius (half-width) in blocks of each individual column in a BASALT_COLUMN cluster.")
|
||||
private int basaltColumnRadius = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How much the heights of individual BASALT_COLUMN columns vary from each other, from 0 (all equal) to 1 (highly varied).")
|
||||
private double basaltHeightVariance = 0.45;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(12)
|
||||
@Description("How many tapered summits crown an ICEBERG formation.")
|
||||
private int icebergPeaks = 3;
|
||||
|
||||
@MinNumber(2)
|
||||
@MaxNumber(8)
|
||||
@Description("How many separated shards form a FISSURE.")
|
||||
private int fractureCount = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(16)
|
||||
@Description("Open-air separation in blocks between the shards of a FISSURE.")
|
||||
private int fractureSeparation = 2;
|
||||
|
||||
@MinNumber(0.25)
|
||||
@MaxNumber(6)
|
||||
@Description("How many complete turns a SPIRAL makes from base to tip.")
|
||||
private double spiralTurns = 1.5;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(32)
|
||||
@Description("The starting distance in blocks between a SPIRAL and its open center.")
|
||||
private int spiralRadius = 4;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
@Description("The radius in blocks of the tube swept along a SPIRAL.")
|
||||
private int spiralThickness = 2;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(32)
|
||||
@Description("How far the hooked arm of an OVERHANG projects from its base.")
|
||||
private int overhangReach = 8;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(16)
|
||||
@Description("How many blocks the tip of an OVERHANG curls downward.")
|
||||
private int overhangDrop = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("For cave placements in an authored subterrain room, size the formation to this fraction of the room vault. Zero uses heightMin and heightMax.")
|
||||
private double roomHeightFraction = 0;
|
||||
|
||||
@Override
|
||||
public IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room) {
|
||||
if (room == null || roomHeightFraction <= 0) {
|
||||
KList<IrisObject> baked = getVariantObjects(data);
|
||||
return baked == null || baked.isEmpty() ? null : baked.get(rng.i(baked.size()));
|
||||
}
|
||||
IrisObject object = FormationGenerator.generate(this, rng.i(Math.max(1, variants)), rng, data,
|
||||
Math.max(1, (int) Math.floor(room.vaultHeight() * Math.min(1D, roomHeightFraction))));
|
||||
if (object != null) {
|
||||
object.setLoadKey("procedural/" + name + "/" + room.featureId());
|
||||
object.setLoader(data);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
public KList<IrisObject> getVariantObjects(IrisData data) {
|
||||
return variantCache.aquire(() -> {
|
||||
KList<IrisObject> baked = new KList<>();
|
||||
int count = Math.max(1, variants);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
IrisObject object = FormationGenerator.generate(this, i, new RNG(seed + (i * 7919L)), data);
|
||||
if (object == null || object.getBlocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
object.setLoadKey("procedural/" + name + "#" + i);
|
||||
object.setLoader(data);
|
||||
baked.add(object);
|
||||
}
|
||||
|
||||
return baked;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObjectPlacement asPlacement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(mode);
|
||||
placement.setRotation(rotation);
|
||||
placement.setClamp(clamp);
|
||||
placement.setCarvingSupport(carvingSupport);
|
||||
placement.setSurfaceSupportBuffer(surfaceSupportBuffer);
|
||||
placement.setUnderwater(underwater);
|
||||
placement.setTranslate(translate);
|
||||
placement.setStiltSettings(stiltSettings);
|
||||
placement.setVacuumSettings(vacuumSettings);
|
||||
placement.setChance(chance);
|
||||
placement.setDensity(density);
|
||||
return placement;
|
||||
}
|
||||
|
||||
public boolean isPlausible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("The overall silhouette of a procedural natural formation. Each form drives a distinct sculpting routine in the formation generator.")
|
||||
public enum IrisFormationForm {
|
||||
@Description("A tall, slender needle of rock that tapers smoothly to a point at the top (a sharp pinnacle or stone spire).")
|
||||
SPIRE,
|
||||
@Description("A column with a pinched, eroded waist and a wide overhanging caprock balanced on top (the classic desert hoodoo / mushroom rock).")
|
||||
HOODOO,
|
||||
@Description("Two stout legs joined by a spanning curved bridge of rock overhead (a natural stone arch).")
|
||||
ARCH,
|
||||
@Description("A chunky, blocky stack that tapers gently as it rises, like an isolated pillar of rock standing in water (a sea stack).")
|
||||
SEA_STACK,
|
||||
@Description("A rounded, lumpy boulder formed from a noise-perturbed ellipsoid that sits low on the terrain.")
|
||||
BOULDER,
|
||||
@Description("A tightly packed cluster of several vertical, near-hexagonal columns of varying height (a basalt column formation / giant's causeway).")
|
||||
BASALT_COLUMN,
|
||||
@Description("A broad, faceted mound crowned by several irregular tapered peaks, suitable for icebergs and glacial outcrops.")
|
||||
ICEBERG,
|
||||
@Description("Several separated, outward-leaning shards divided by open cracks.")
|
||||
FISSURE,
|
||||
@Description("A tapered tube swept around a tightening helix, leaving open air through its curled center.")
|
||||
SPIRAL,
|
||||
@Description("A grounded pillar that bends into a long hooked cantilever and curls downward at its tip.")
|
||||
OVERHANG
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("A width-shaping function evaluated over normalized height (0 at the base, 1 at the top). Controls how the formation radius scales between baseWidth at the bottom and topWidth at the top.")
|
||||
public enum IrisFormationProfile {
|
||||
@Description("Same radius at every height (a straight cylinder of constant baseWidth).")
|
||||
CONSTANT,
|
||||
@Description("Radius ramps straight from baseWidth at the bottom to topWidth at the top.")
|
||||
LINEAR,
|
||||
@Description("Radius shrinks smoothly toward a point as height increases (an ease that drives the SPIRE needle and gentle SEA_STACK taper).")
|
||||
TAPER,
|
||||
@Description("Radius pinches to a narrow waist near profileWaist then widens again toward the top (the eroded waist used by HOODOO columns).")
|
||||
PARABOLIC,
|
||||
@Description("Radius bulges out to its maximum in the middle of the height range and narrows at both ends (a barrel / bulged column).")
|
||||
BULGE
|
||||
}
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusCapBuilder {
|
||||
private FungusCapBuilder() {
|
||||
}
|
||||
|
||||
public static void build(Map<Vector3i, FungusCellRole> roles, IrisFungus fungus, int baseRadius, double cx, int baseY, double cz, long seed) {
|
||||
int radius = (int) Math.round(baseRadius + Math.max(0.0, fungus.getCapOverhang()));
|
||||
int thickness = Math.max(1, Math.min(3, fungus.getCapThickness()));
|
||||
double squish = Math.max(0.0, Math.min(1.0, fungus.getCapSquish()));
|
||||
double droop = Math.max(0.0, fungus.getCapDroop());
|
||||
IrisFungusCapShape shape = fungus.getCapShape() == null ? IrisFungusCapShape.DOME : fungus.getCapShape();
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
|
||||
boolean hasGill = blockOrPaletteSet(fungus.getGillBlock(), fungus.getGillPalette());
|
||||
boolean hasSpot = blockOrPaletteSet(fungus.getSpotBlock(), fungus.getSpotPalette());
|
||||
|
||||
double apexRise = apexRise(shape, radius) * (1.0 - 0.6 * squish);
|
||||
double droopReach = Math.tan(Math.toRadians(droop)) * radius;
|
||||
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||
if (dist > radius + 0.5) {
|
||||
continue;
|
||||
}
|
||||
double normalized = dist / Math.max(1.0, radius);
|
||||
double surfaceTop = baseY + capSurface(shape, normalized, apexRise);
|
||||
surfaceTop -= droopReach * Math.pow(normalized, 3);
|
||||
|
||||
int topYi = (int) Math.round(surfaceTop);
|
||||
for (int layer = 0; layer < thickness; layer++) {
|
||||
int y = topYi - layer;
|
||||
if (y < baseY - thickness) {
|
||||
continue;
|
||||
}
|
||||
Vector3i pos = new Vector3i(icx + dx, y, icz + dz);
|
||||
FungusCellRole role = FungusCellRole.CAP;
|
||||
|
||||
boolean underside = layer == thickness - 1;
|
||||
boolean topFace = layer == 0;
|
||||
|
||||
if (underside && hasGill && rollNoise(icx + dx, y, icz + dz, seed + 4111L) <= fungus.getGillChance()) {
|
||||
role = FungusCellRole.GILL;
|
||||
} else if (topFace && hasSpot && spotNoise(icx + dx, y, icz + dz, seed + 9311L) <= fungus.getSpotChance()) {
|
||||
role = FungusCellRole.SPOT;
|
||||
}
|
||||
|
||||
roles.putIfAbsent(pos, role);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double apexRise(IrisFungusCapShape shape, int radius) {
|
||||
return switch (shape) {
|
||||
case DOME -> radius * 0.85;
|
||||
case CONICAL -> radius * 1.4;
|
||||
case FUNNEL -> radius * 0.5;
|
||||
case FLAT -> radius * 0.35;
|
||||
case FLAT_WIDE -> radius * 0.2;
|
||||
};
|
||||
}
|
||||
|
||||
private static double capSurface(IrisFungusCapShape shape, double normalized, double apexRise) {
|
||||
double n = Math.max(0.0, Math.min(1.0, normalized));
|
||||
return switch (shape) {
|
||||
case DOME -> apexRise * Math.sqrt(Math.max(0.0, 1.0 - n * n));
|
||||
case CONICAL -> apexRise * (1.0 - n);
|
||||
case FUNNEL -> apexRise * (n * n);
|
||||
case FLAT -> apexRise * Math.max(0.0, 1.0 - Math.pow(n, 4));
|
||||
case FLAT_WIDE -> apexRise * Math.max(0.0, 1.0 - Math.pow(n, 6));
|
||||
};
|
||||
}
|
||||
|
||||
private static double rollNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(x, y, z, seed);
|
||||
}
|
||||
|
||||
private static double spotNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(Math.floorDiv(x, 2), y, Math.floorDiv(z, 2), seed);
|
||||
}
|
||||
|
||||
static boolean blockOrPaletteSet(String block, IrisMaterialPalette palette) {
|
||||
if (IrisProceduralBlocks.paletteSet(palette)) {
|
||||
return true;
|
||||
}
|
||||
return block != null && !block.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
enum FungusCellRole {
|
||||
STEM,
|
||||
CAP,
|
||||
GILL,
|
||||
SPOT
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusGenerator {
|
||||
private FungusGenerator() {
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisFungus fungus, int height, RNG rng, IrisData data) {
|
||||
Map<Vector3i, FungusCellRole> roles = new HashMap<>();
|
||||
long baseSeed = rng.getSeed();
|
||||
|
||||
if (fungus.isShelf()) {
|
||||
FungusShelfBuilder.build(roles, fungus, rng, baseSeed);
|
||||
} else {
|
||||
buildUpright(roles, fungus, height, rng, baseSeed);
|
||||
}
|
||||
|
||||
if (roles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RNG paletteRng = new RNG(fungus.getSeed());
|
||||
Map<Vector3i, NativeBlockState> resolved = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, FungusCellRole> entry : roles.entrySet()) {
|
||||
Vector3i pos = entry.getKey();
|
||||
NativeBlockState bd = resolveRole(fungus, entry.getValue(), data, pos, paletteRng);
|
||||
if (bd == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(pos, bd);
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static void buildUpright(Map<Vector3i, FungusCellRole> roles, IrisFungus fungus, int height, RNG rng, long baseSeed) {
|
||||
int stemHeight = Math.max(1, height);
|
||||
double[] top = FungusStemBuilder.build(roles, fungus, stemHeight, baseSeed);
|
||||
|
||||
int radius = pickRadius(fungus, rng);
|
||||
double cx = top[0];
|
||||
double cz = top[2];
|
||||
int capBaseY = (int) Math.round(top[1]);
|
||||
FungusCapBuilder.build(roles, fungus, radius, cx, capBaseY, cz, baseSeed + 5557L);
|
||||
}
|
||||
|
||||
private static int pickRadius(IrisFungus fungus, RNG rng) {
|
||||
int lo = Math.min(fungus.getCapRadiusMin(), fungus.getCapRadiusMax());
|
||||
int hi = Math.max(fungus.getCapRadiusMin(), fungus.getCapRadiusMax());
|
||||
lo = Math.max(1, lo);
|
||||
hi = Math.max(lo, hi);
|
||||
return rng.i(lo, hi + 1);
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveRole(IrisFungus fungus, FungusCellRole role, IrisData data, Vector3i pos, RNG paletteRng) {
|
||||
int x = pos.getBlockX();
|
||||
int y = pos.getBlockY();
|
||||
int z = pos.getBlockZ();
|
||||
return switch (role) {
|
||||
case STEM -> IrisProceduralBlocks.resolve(fungus.getStem(), fungus.getStemPalette(), data, x, y, z, paletteRng);
|
||||
case CAP -> IrisProceduralBlocks.resolve(fungus.getCap(), fungus.getCapPalette(), data, x, y, z, paletteRng);
|
||||
case GILL -> {
|
||||
NativeBlockState gill = IrisProceduralBlocks.resolve(fungus.getGillBlock(), fungus.getGillPalette(), data, x, y, z, paletteRng);
|
||||
yield gill != null ? gill : IrisProceduralBlocks.resolve(fungus.getCap(), fungus.getCapPalette(), data, x, y, z, paletteRng);
|
||||
}
|
||||
case SPOT -> {
|
||||
NativeBlockState spot = IrisProceduralBlocks.resolve(fungus.getSpotBlock(), fungus.getSpotPalette(), data, x, y, z, paletteRng);
|
||||
yield spot != null ? spot : IrisProceduralBlocks.resolve(fungus.getCap(), fungus.getCapPalette(), data, x, y, z, paletteRng);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusShelfBuilder {
|
||||
private FungusShelfBuilder() {
|
||||
}
|
||||
|
||||
public static void build(Map<Vector3i, FungusCellRole> roles, IrisFungus fungus, RNG rng, long seed) {
|
||||
int radius = Math.max(1, fungus.getShelfRadius());
|
||||
double azimuth = rng.d(0.0, Math.PI * 2.0);
|
||||
double fanX = Math.sin(azimuth);
|
||||
double fanZ = Math.cos(azimuth);
|
||||
int stubHeight = Math.max(0, Math.min(2, fungus.getStemWidth()));
|
||||
|
||||
for (int y = 0; y < stubHeight; y++) {
|
||||
roles.put(new Vector3i(0, y, 0), FungusCellRole.STEM);
|
||||
}
|
||||
|
||||
int fanY = stubHeight;
|
||||
boolean hasGill = FungusCapBuilder.blockOrPaletteSet(fungus.getGillBlock(), fungus.getGillPalette());
|
||||
boolean hasSpot = FungusCapBuilder.blockOrPaletteSet(fungus.getSpotBlock(), fungus.getSpotPalette());
|
||||
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||
if (dist > radius + 0.5) {
|
||||
continue;
|
||||
}
|
||||
double forward = dx * fanX + dz * fanZ;
|
||||
if (forward < -0.5) {
|
||||
continue;
|
||||
}
|
||||
double normalized = dist / Math.max(1.0, radius);
|
||||
int lift = (int) Math.round(radius * 0.25 * (1.0 - normalized));
|
||||
int y = fanY + lift;
|
||||
|
||||
FungusCellRole role = FungusCellRole.CAP;
|
||||
if (hasSpot && spotNoise(dx, y, dz, seed + 9311L) <= fungus.getSpotChance()) {
|
||||
role = FungusCellRole.SPOT;
|
||||
}
|
||||
roles.putIfAbsent(new Vector3i(dx, y, dz), role);
|
||||
|
||||
if (hasGill && rollNoise(dx, y - 1, dz, seed + 4111L) <= fungus.getGillChance()) {
|
||||
roles.putIfAbsent(new Vector3i(dx, y - 1, dz), FungusCellRole.GILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double rollNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(x, y, z, seed);
|
||||
}
|
||||
|
||||
private static double spotNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(Math.floorDiv(x, 2), y, Math.floorDiv(z, 2), seed);
|
||||
}
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusStemBuilder {
|
||||
private FungusStemBuilder() {
|
||||
}
|
||||
|
||||
public static double[] build(Map<Vector3i, FungusCellRole> roles, IrisFungus fungus, int stemHeight, long seed) {
|
||||
int width = Math.max(1, Math.min(3, fungus.getStemWidth()));
|
||||
double maxLean = stemHeight * Math.tan(Math.toRadians(Math.max(0.0, fungus.getStemCurve())));
|
||||
double leanRad = Math.toRadians(fungus.getStemLeanAzimuth());
|
||||
double leanX = Math.sin(leanRad);
|
||||
double leanZ = Math.cos(leanRad);
|
||||
double waveAmp = Math.max(0.0, fungus.getStemWaveAmplitude());
|
||||
double wavePeriods = fungus.getStemWavePeriods() == 0 ? 1.0 : fungus.getStemWavePeriods();
|
||||
double waveAzimuth = Math.toRadians(fungus.getStemLeanAzimuth() + 90.0);
|
||||
double waveX = Math.sin(waveAzimuth);
|
||||
double waveZ = Math.cos(waveAzimuth);
|
||||
double wavePhase = TreeFunctions.valueNoise1D(seed, seed) * Math.PI * 2.0;
|
||||
|
||||
double topCx = 0.0;
|
||||
double topCz = 0.0;
|
||||
int topY = Math.max(0, stemHeight - 1);
|
||||
|
||||
for (int y = 0; y < stemHeight; y++) {
|
||||
double t = stemHeight <= 1 ? 0.0 : y / (double) (stemHeight - 1);
|
||||
double lean = maxLean * (t * t);
|
||||
double wave = waveAmp * Math.sin(2.0 * Math.PI * wavePeriods * t + wavePhase);
|
||||
double cx = lean * leanX + wave * waveX;
|
||||
double cz = lean * leanZ + wave * waveZ;
|
||||
|
||||
int ox = (width % 2 == 1 ? (int) Math.round(cx) : (int) Math.floor(cx) + 1) - width / 2;
|
||||
int oz = (width % 2 == 1 ? (int) Math.round(cz) : (int) Math.floor(cz) + 1) - width / 2;
|
||||
for (int dx = 0; dx < width; dx++) {
|
||||
for (int dz = 0; dz < width; dz++) {
|
||||
roles.put(new Vector3i(ox + dx, y, oz + dz), FungusCellRole.STEM);
|
||||
}
|
||||
}
|
||||
|
||||
topCx = cx;
|
||||
topCz = cz;
|
||||
}
|
||||
|
||||
return new double[]{topCx, topY, topCz};
|
||||
}
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectLimit;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("fungus")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A single procedurally generated fungus (giant mushroom or shelf fungus). Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. The fungus is built as a stem column with a cap dome grown on top, mirroring the trunk-and-canopy model used by procedural trees.")
|
||||
@Data
|
||||
public class IrisFungus implements IrisProceduralPlacement {
|
||||
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
@Description("A human readable name used in logs and as the variant load key.")
|
||||
private String name = "fungus";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per chunk for this fungus to attempt placement. Use density for multiple per chunk.")
|
||||
private double chance = 0.4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, attempt this many placements in the chunk.")
|
||||
private int density = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("How many distinct variants to pre-bake for this fungus. Higher means more variety at a small memory cost.")
|
||||
private int variants = 6;
|
||||
|
||||
@Description("The base seed for deterministic generation. The same seed and settings always bake the same variants.")
|
||||
private long seed = 1337;
|
||||
|
||||
@Description("The placement mode used to anchor the fungus to the terrain.")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
|
||||
|
||||
@Description("Rotate this fungus's placement.")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
|
||||
@Description("Limit the max or min height of placement.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@Description("Whether this fungus may place on the terrain surface, under carvings, or both.")
|
||||
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
|
||||
|
||||
@Description("If true, the fungus anchors on the terrain height ignoring the water surface.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
|
||||
@Description("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
|
||||
private IrisStiltSettings stiltSettings;
|
||||
|
||||
@Description("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).")
|
||||
private IrisVacuumSettings vacuumSettings;
|
||||
|
||||
@Required
|
||||
@Description("The stem block, e.g. minecraft:mushroom_stem. Ignored when stemPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String stem = "minecraft:mushroom_stem";
|
||||
|
||||
@Description("A noise-driven palette for the stem. When set this overrides the single stem block, letting the stem mix blocks by noise.")
|
||||
private IrisMaterialPalette stemPalette = null;
|
||||
|
||||
@Required
|
||||
@Description("The cap block, e.g. minecraft:red_mushroom_block. Ignored when capPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String cap = "minecraft:red_mushroom_block";
|
||||
|
||||
@Description("A noise-driven palette for the cap. When set this overrides the single cap block, letting the cap mix blocks by noise.")
|
||||
private IrisMaterialPalette capPalette = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum total stem height in blocks. Variants spread between this and stemHeightMax.")
|
||||
private int stemHeightMin = 5;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum total stem height in blocks. Variants spread between stemHeightMin and this.")
|
||||
private int stemHeightMax = 9;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(3)
|
||||
@Description("Base stem width in blocks. 1 is a single column, 2 is a 2x2 stem, 3 is a chunky 3x3 trunk.")
|
||||
private int stemWidth = 1;
|
||||
|
||||
@Description("How far the stem leans away from vertical, in degrees. 0 is perfectly upright; small values give an organic tilt.")
|
||||
private double stemCurve = 0;
|
||||
|
||||
@Description("Compass direction in degrees the stem leans toward when stemCurve is non-zero.")
|
||||
private double stemLeanAzimuth = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Amplitude in blocks of a gentle sideways wave applied up the stem so it is not a perfectly straight ruler.")
|
||||
private double stemWaveAmplitude = 0.4;
|
||||
|
||||
@MinNumber(0.0001)
|
||||
@Description("The number of full sine wobbles applied over the stem height for the stem wave.")
|
||||
private double stemWavePeriods = 1;
|
||||
|
||||
@Description("The silhouette of the cap (dome, flat umbrella, funnel, cone, or wide shallow slab).")
|
||||
private IrisFungusCapShape capShape = IrisFungusCapShape.DOME;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum cap radius in blocks (measured from the cap center to its rim).")
|
||||
private int capRadiusMin = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum cap radius in blocks (measured from the cap center to its rim).")
|
||||
private int capRadiusMax = 5;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(3)
|
||||
@Description("How many blocks thick the cap shell is. 1 is a thin skin, 3 is a fleshy slab.")
|
||||
private int capThickness = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Vertical flatten factor for the cap. 0 leaves the cap at full height, 1 squashes it flat into a disc.")
|
||||
private double capSquish = 0.4;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("How far the cap rim droops downward, in degrees, curling the edge of the cap toward the ground.")
|
||||
private double capDroop = 20;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("How far the cap radius extends past the stem before the rim begins, in blocks. Larger values make the cap overhang the stem more.")
|
||||
private double capOverhang = 2;
|
||||
|
||||
@Description("Optional block forming the gill layer on the underside of the cap (gills or a glow layer), e.g. minecraft:brown_mushroom_block or minecraft:shroomlight. Ignored when gillPalette is set or left null.")
|
||||
@RegistryListBlockType
|
||||
private String gillBlock = null;
|
||||
|
||||
@Description("A noise-driven palette for the underside gill layer. When set this overrides the single gillBlock.")
|
||||
private IrisMaterialPalette gillPalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The fraction of underside cap blocks replaced by the gill block when a gill block or palette is set.")
|
||||
private double gillChance = 0.85;
|
||||
|
||||
@Description("Optional block speckled across the top of the cap by noise (white toadstool dots, warts, glowing spots), e.g. minecraft:bone_block or minecraft:white_concrete. Ignored when spotPalette is set or left null.")
|
||||
@RegistryListBlockType
|
||||
private String spotBlock = null;
|
||||
|
||||
@Description("A noise-driven palette for the cap top spots. When set this overrides the single spotBlock.")
|
||||
private IrisMaterialPalette spotPalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The fraction of top cap blocks replaced by the spot block, selected by value noise so spots cluster naturally.")
|
||||
private double spotChance = 0.18;
|
||||
|
||||
@Description("If true, generate a bracket / shelf fungus instead of an upright mushroom: a small flat fan that grows sideways off a very short or absent stem, like a polypore clinging to a trunk.")
|
||||
private boolean shelf = false;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("The radius in blocks of the sideways fan when shelf is true.")
|
||||
private int shelfRadius = 3;
|
||||
|
||||
public KList<IrisObject> getVariantObjects(IrisData data) {
|
||||
return variantCache.aquire(() -> {
|
||||
KList<IrisObject> baked = new KList<>();
|
||||
int count = Math.max(1, variants);
|
||||
int lo = Math.min(stemHeightMin, stemHeightMax);
|
||||
int hi = Math.max(stemHeightMin, stemHeightMax);
|
||||
RNG heightRng = new RNG(seed);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int height;
|
||||
if (count == 1 || lo == hi) {
|
||||
height = heightRng.i(lo, hi + 1);
|
||||
} else {
|
||||
double step = (hi - lo) / (double) (count - 1);
|
||||
double base = lo + step * i;
|
||||
double jitter = heightRng.d(-step * 0.3, step * 0.3);
|
||||
height = (int) Math.round(Math.max(lo, Math.min(hi, base + jitter)));
|
||||
}
|
||||
|
||||
IrisObject object = FungusGenerator.generate(this, Math.max(1, height), new RNG(seed + (i * 7919L)), data);
|
||||
if (object == null || object.getBlocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
object.setLoadKey("procedural/" + name + "#" + i);
|
||||
object.setLoader(data);
|
||||
baked.add(object);
|
||||
}
|
||||
|
||||
return baked;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room) {
|
||||
KList<IrisObject> baked = getVariantObjects(data);
|
||||
if (baked == null || baked.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return baked.get(rng.i(baked.size()));
|
||||
}
|
||||
|
||||
public IrisObjectPlacement asPlacement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(mode);
|
||||
placement.setRotation(rotation);
|
||||
placement.setClamp(clamp);
|
||||
placement.setCarvingSupport(carvingSupport);
|
||||
placement.setUnderwater(underwater);
|
||||
placement.setTranslate(translate);
|
||||
placement.setStiltSettings(stiltSettings);
|
||||
placement.setVacuumSettings(vacuumSettings);
|
||||
placement.setChance(chance);
|
||||
placement.setDensity(density);
|
||||
return placement;
|
||||
}
|
||||
|
||||
public boolean isPlausible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("The silhouette of the mushroom cap. Each shape drives how the cap radius and thickness vary from its apex down to the rim, giving the fungus a distinct profile.")
|
||||
public enum IrisFungusCapShape {
|
||||
@Description("A rounded hemisphere cap that bulges up and curls slightly under at the rim, the classic red toadstool dome.")
|
||||
DOME,
|
||||
@Description("A wide, nearly flat umbrella that holds its full radius almost to the edge before dropping, the brown-mushroom plate look.")
|
||||
FLAT,
|
||||
@Description("An upturned bowl whose rim lifts higher than its center, cupping upward like a chanterelle or funnel mushroom.")
|
||||
FUNNEL,
|
||||
@Description("A tall pointed cone that tapers from a broad base to a sharp apex, the witch-hat parasol silhouette.")
|
||||
CONICAL,
|
||||
@Description("A very wide but shallow slab, a low overhanging shelf-like roof that spreads far past the stem with minimal vertical rise.")
|
||||
FLAT_WIDE
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectLimit;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.iris.pack.schema.annotation.ArrayType;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("ruin")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A single procedurally generated ruin: a crumbling man-made structure (pillar, wall, arch, foundation slab, or rubble pile). Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. Weathering swaps blocks for mossy or cracked variants by noise, erosion deletes blocks so the shape reads as collapsed, and a buried fraction sinks the ruin into the terrain.")
|
||||
@Data
|
||||
public class IrisRuin implements IrisProceduralPlacement {
|
||||
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
@Description("A human readable name used in logs and as the variant load key (procedural/<name>#<index>).")
|
||||
private String name = "ruin";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance (0-1) per chunk for this ruin to attempt placement. Use density to attempt more than one per chunk once the chance check passes.")
|
||||
private double chance = 0.05;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, attempt this many placements in the chunk. Defaults to a single ruin per qualifying chunk.")
|
||||
private int density = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("How many distinct variants to pre-bake for this ruin. Higher means more variety (different heights, gap patterns, erosion seeds) at a small memory cost.")
|
||||
private int variants = 6;
|
||||
|
||||
@Description("The base seed for deterministic generation. The same seed and settings always bake the same variants. Every random choice (size, weathering mask, erosion mask, accents) is derived from this.")
|
||||
private long seed = 1337;
|
||||
|
||||
@Description("The placement mode used to anchor the ruin to the terrain. MIN_HEIGHT plants the lowest footprint corner on the ground (good for slabs and rubble on slopes); CENTER_HEIGHT averages the footprint (good for tall pillars and arches).")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.MIN_HEIGHT;
|
||||
|
||||
@Description("Rotate this ruin's placement so variants do not all face the same way.")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
|
||||
@Description("Limit the max or min terrain height at which this ruin may place.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@Description("Whether this ruin may place on the terrain surface, under carvings (caves), or both. SURFACE_ONLY keeps ruins above ground.")
|
||||
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
|
||||
|
||||
@Description("If true the ruin anchors on the terrain height ignoring the water surface, so it can sit submerged. If false (default) it anchors to the surface and avoids water.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
|
||||
@Description("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
|
||||
private IrisStiltSettings stiltSettings;
|
||||
|
||||
@Description("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).")
|
||||
private IrisVacuumSettings vacuumSettings;
|
||||
|
||||
@Required
|
||||
@Description("The primary structural block, e.g. minecraft:cobblestone or minecraft:stone_bricks. Ignored when blockPalette is set. This is the bulk material of the ruin before weathering swaps some of it out.")
|
||||
@RegistryListBlockType
|
||||
private String block = "minecraft:cobblestone";
|
||||
|
||||
@Description("A noise-driven palette for the primary block. When set this overrides the single block, letting the structure mix materials by noise. Palette wins over the block string via IrisProceduralBlocks.resolve.")
|
||||
private IrisMaterialPalette blockPalette = null;
|
||||
|
||||
@Description("The overall silhouette of the ruin: PILLAR (broken column), WALL (gapped segment), ARCH (two legs plus a curved span), FLOOR_SLAB (foundation patch), or RUBBLE (low scattered pile).")
|
||||
private IrisRuinForm form = IrisRuinForm.PILLAR;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum structure height in blocks (PILLAR/WALL/ARCH height, slab thickness for FLOOR_SLAB, mound height for RUBBLE). Variants interpolate between this and heightMax.")
|
||||
private int heightMin = 4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum structure height in blocks. Variants interpolate between heightMin and this so taller and shorter ruins coexist.")
|
||||
private int heightMax = 9;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum footprint width (X axis) in blocks: column/leg thickness for PILLAR/ARCH, wall thickness for WALL, slab width for FLOOR_SLAB, blob width for RUBBLE.")
|
||||
private int widthMin = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum footprint width (X axis) in blocks. Variants interpolate between widthMin and this.")
|
||||
private int widthMax = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum footprint length (Z axis) in blocks: wall run length, arch leg spacing, slab length, rubble blob length.")
|
||||
private int lengthMin = 3;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum footprint length (Z axis) in blocks. Variants interpolate between lengthMin and this.")
|
||||
private int lengthMax = 7;
|
||||
|
||||
@Description("A palette of weathered variants (mossy/cracked block ids) blended over the structure by noise. When set this drives weathering; otherwise weatheredBlock is used.")
|
||||
private IrisMaterialPalette weatheringPalette = null;
|
||||
|
||||
@Description("A single weathered block id used when weatheringPalette is not set, e.g. minecraft:mossy_cobblestone. Applied to a noise-selected fraction of the structure, biased toward the lower rows.")
|
||||
@RegistryListBlockType
|
||||
private String weatheredBlock = "minecraft:mossy_cobblestone";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How much of the structure is replaced by weathered blocks (0 none, 1 nearly all). The replacement mask is value-noise driven and weighted so lower rows weather more than upper rows, mimicking moss climbing from the ground.")
|
||||
private double mossiness = 0.45;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(8)
|
||||
@Description("The scale of the weathering noise. Higher values produce smaller, busier moss/crack patches; lower values produce broad continuous weathered zones.")
|
||||
private double weatheringScale = 1.0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How crumbled the ruin is (0 intact, 1 mostly gone). Blocks whose value-noise falls below this threshold are deleted, so the shape reads as collapsed. Structural integrity is preserved: the bottom row and core legs are never eroded away.")
|
||||
private double erosion = 0.25;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(8)
|
||||
@Description("The scale of the erosion noise. Higher values knock out small speckled holes; lower values carve larger missing chunks out of the silhouette.")
|
||||
private double erosionScale = 1.5;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How far the structure extends below the surface as a fraction of its height (0 sits fully on top, 1 sinks it a full height into the ground). The buried rows live at negative y so the ruin reads as settled and partly swallowed by the terrain.")
|
||||
private double buriedFraction = 0.2;
|
||||
|
||||
@ArrayType(min = 1, type = IrisRuinDecorator.class)
|
||||
@Description("Accent decorators applied after the ruin is built and eroded (moss carpets and lanterns on broken tops, vines and lichen on the faces, rubble and growth scattered around the base).")
|
||||
private KList<IrisRuinDecorator> accents = new KList<>();
|
||||
|
||||
public KList<IrisObject> getVariantObjects(IrisData data) {
|
||||
return variantCache.aquire(() -> {
|
||||
KList<IrisObject> baked = new KList<>();
|
||||
int count = Math.max(1, variants);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
IrisObject object = RuinGenerator.generate(this, i, new RNG(seed + (i * 7919L)), data);
|
||||
if (object == null || object.getBlocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
object.setLoadKey("procedural/" + name + "#" + i);
|
||||
object.setLoader(data);
|
||||
baked.add(object);
|
||||
}
|
||||
|
||||
return baked;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room) {
|
||||
KList<IrisObject> baked = getVariantObjects(data);
|
||||
if (baked == null || baked.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return baked.get(rng.i(baked.size()));
|
||||
}
|
||||
|
||||
public IrisObjectPlacement asPlacement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(mode);
|
||||
placement.setRotation(rotation);
|
||||
placement.setClamp(clamp);
|
||||
placement.setCarvingSupport(carvingSupport);
|
||||
placement.setUnderwater(underwater);
|
||||
placement.setTranslate(translate);
|
||||
placement.setStiltSettings(stiltSettings);
|
||||
placement.setVacuumSettings(vacuumSettings);
|
||||
placement.setChance(chance);
|
||||
placement.setDensity(density);
|
||||
return placement;
|
||||
}
|
||||
|
||||
public boolean isPlausible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("ruin-decorator")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("An accent block applied to a generated ruin after it is built and eroded, such as moss carpets on broken tops, vines on the faces, or rubble scattered around the base.")
|
||||
@Data
|
||||
public class IrisRuinDecorator {
|
||||
@Description("Where on the ruin this accent is placed. TOP sits on the highest block of each column, SURFACE clings to air-facing vertical faces, BASE_SCATTER rings the ground footprint around the base.")
|
||||
private IrisRuinDecoratorTarget target = IrisRuinDecoratorTarget.TOP;
|
||||
|
||||
@Required
|
||||
@Description("The block id to place, e.g. minecraft:moss_carpet or minecraft:vine. Ignored when palette is set.")
|
||||
@RegistryListBlockType
|
||||
private String block = "";
|
||||
|
||||
@Description("A noise-driven palette for this decorator. When set this overrides the single block, letting the accent mix blocks by noise. Resolved through IrisProceduralBlocks.resolve so the palette wins over the string.")
|
||||
private IrisMaterialPalette palette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance (0-1) per candidate position for this decorator to actually place. 1 covers every candidate, lower values leave sparse, patchy accents.")
|
||||
private double chance = 0.4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("For the BASE_SCATTER target, how many blocks beyond the ruin footprint the scatter ring extends outward in each direction. Higher values fling rubble and growth further from the structure.")
|
||||
private int scatterRadius = 2;
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("Where a ruin accent block is placed after the ruin has been built and eroded.")
|
||||
public enum IrisRuinDecoratorTarget {
|
||||
@Description("On top of the highest surviving block in each column (moss carpets, snow, sculk, lanterns on broken tops).")
|
||||
TOP,
|
||||
@Description("On air-facing vertical sides of any surviving block (vines, glow lichen, climbing growth on the ruin faces).")
|
||||
SURFACE,
|
||||
@Description("Scattered across the ground footprint around the y=0 base ring, wider than the structure itself (loose rubble, mushrooms, grass tufts ringing the ruin).")
|
||||
BASE_SCATTER
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("The overall silhouette of a procedural ruin. Each form rasterizes a different crumbling man-made shape from the same size, weathering, and erosion settings.")
|
||||
public enum IrisRuinForm {
|
||||
@Description("A broken vertical column. A square trunk (widthMin..widthMax footprint) rises to a randomized height then snaps off with a jagged crown, leaving a toppled stub. Use for ancient pillars and obelisk stumps.")
|
||||
PILLAR,
|
||||
@Description("A standing wall segment. A flat slab spanning lengthMin..lengthMax long and heightMin..heightMax tall, thickness widthMin..widthMax, punched through with noise-driven gaps and a ragged top edge. Use for collapsed building sides and fortifications.")
|
||||
WALL,
|
||||
@Description("A freestanding arch. Two legs spaced by lengthMin..lengthMax joined at the top by a rasterized semicircular span (the lintel), so the structure literally arches. Use for gateways, aqueduct bays, and ruined doorways.")
|
||||
ARCH,
|
||||
@Description("A flat foundation patch. A single (or few) block-thick slab covering a widthMin..lengthMax footprint at ground level, heavily eroded into an irregular outline. Use for floor remnants, plazas, and building foundations.")
|
||||
FLOOR_SLAB,
|
||||
@Description("A low scattered debris pile. A noise blob of partial blocks mounded near the ground, tallest at the center and thinning toward the edges. Use for collapsed-structure rubble and scree.")
|
||||
RUBBLE
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class RuinBlockCanvas {
|
||||
enum Role {
|
||||
STRUCTURE,
|
||||
ACCENT
|
||||
}
|
||||
|
||||
static final class Cell {
|
||||
private Role role;
|
||||
private boolean structural;
|
||||
private NativeBlockState accentData;
|
||||
|
||||
Cell(Role role, boolean structural) {
|
||||
this.role = role;
|
||||
this.structural = structural;
|
||||
}
|
||||
|
||||
Role role() {
|
||||
return role;
|
||||
}
|
||||
|
||||
boolean structural() {
|
||||
return structural;
|
||||
}
|
||||
|
||||
NativeBlockState accentData() {
|
||||
return accentData;
|
||||
}
|
||||
|
||||
void promote(Role next, boolean structuralNext) {
|
||||
this.role = next;
|
||||
this.structural = this.structural || structuralNext;
|
||||
}
|
||||
|
||||
void makeAccent(NativeBlockState data) {
|
||||
this.role = Role.ACCENT;
|
||||
this.structural = false;
|
||||
this.accentData = data;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<Vector3i, Cell> cells = new HashMap<>();
|
||||
|
||||
Map<Vector3i, Cell> cells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
void set(int x, int y, int z, Role role, boolean structural) {
|
||||
Vector3i key = new Vector3i(x, y, z);
|
||||
Cell existing = cells.get(key);
|
||||
if (existing == null) {
|
||||
cells.put(key, new Cell(role, structural));
|
||||
} else {
|
||||
existing.promote(role, structural);
|
||||
}
|
||||
}
|
||||
|
||||
void accent(int x, int y, int z, NativeBlockState data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
cells.put(new Vector3i(x, y, z), accentCell(data));
|
||||
}
|
||||
|
||||
private static Cell accentCell(NativeBlockState data) {
|
||||
Cell cell = new Cell(Role.ACCENT, false);
|
||||
cell.makeAccent(data);
|
||||
return cell;
|
||||
}
|
||||
|
||||
boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
Cell get(int x, int y, int z) {
|
||||
return cells.get(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
void remove(int x, int y, int z) {
|
||||
cells.remove(new Vector3i(x, y, z));
|
||||
}
|
||||
}
|
||||
-124
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class RuinDecoratorApplier {
|
||||
private static final int[][] HORIZONTAL = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
private RuinDecoratorApplier() {
|
||||
}
|
||||
|
||||
static void apply(RuinBlockCanvas canvas, IrisRuinDecorator decorator, IrisData data, long seed, RNG rng) {
|
||||
List<Vector3i> candidates = switch (decorator.getTarget()) {
|
||||
case TOP -> topCandidates(canvas);
|
||||
case SURFACE -> surfaceCandidates(canvas);
|
||||
case BASE_SCATTER -> baseScatterCandidates(canvas, Math.max(1, decorator.getScatterRadius()));
|
||||
};
|
||||
|
||||
candidates.sort(Comparator.comparingInt(Vector3i::getX)
|
||||
.thenComparingInt(Vector3i::getY).thenComparingInt(Vector3i::getZ));
|
||||
RNG paletteRng = new RNG(seed);
|
||||
for (Vector3i v : candidates) {
|
||||
if (!rng.chance(decorator.getChance())) {
|
||||
continue;
|
||||
}
|
||||
NativeBlockState bd = IrisProceduralBlocks.resolve(decorator.getBlock(), decorator.getPalette(), data, v.getBlockX(), v.getBlockY(), v.getBlockZ(), paletteRng);
|
||||
if (bd != null) {
|
||||
canvas.accent(v.getBlockX(), v.getBlockY(), v.getBlockZ(), bd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Vector3i> topCandidates(RuinBlockCanvas canvas) {
|
||||
Map<Long, Integer> highest = new HashMap<>();
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
long key = columnKey(v.getBlockX(), v.getBlockZ());
|
||||
Integer current = highest.get(key);
|
||||
if (current == null || v.getBlockY() > current) {
|
||||
highest.put(key, v.getBlockY());
|
||||
}
|
||||
}
|
||||
List<Vector3i> out = new ArrayList<>();
|
||||
for (Map.Entry<Long, Integer> entry : highest.entrySet()) {
|
||||
int x = (int) (entry.getKey() >> 32);
|
||||
int z = (int) (entry.getKey() & 0xFFFFFFFFL);
|
||||
int y = entry.getValue() + 1;
|
||||
if (!canvas.has(x, y, z)) {
|
||||
out.add(new Vector3i(x, y, z));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static List<Vector3i> surfaceCandidates(RuinBlockCanvas canvas) {
|
||||
List<Vector3i> out = new ArrayList<>();
|
||||
for (Vector3i v : new ArrayList<>(canvas.cells().keySet())) {
|
||||
for (int[] dir : HORIZONTAL) {
|
||||
int nx = v.getBlockX() + dir[0];
|
||||
int ny = v.getBlockY();
|
||||
int nz = v.getBlockZ() + dir[2];
|
||||
if (!canvas.has(nx, ny, nz)) {
|
||||
out.add(new Vector3i(nx, ny, nz));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static List<Vector3i> baseScatterCandidates(RuinBlockCanvas canvas, int radius) {
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
minX = Math.min(minX, v.getBlockX());
|
||||
minZ = Math.min(minZ, v.getBlockZ());
|
||||
maxX = Math.max(maxX, v.getBlockX());
|
||||
maxZ = Math.max(maxZ, v.getBlockZ());
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
}
|
||||
|
||||
List<Vector3i> out = new ArrayList<>();
|
||||
for (int x = minX - radius; x <= maxX + radius; x++) {
|
||||
for (int z = minZ - radius; z <= maxZ + radius; z++) {
|
||||
if (!canvas.has(x, minY, z) && !canvas.has(x, minY + 1, z)) {
|
||||
out.add(new Vector3i(x, minY, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) | (z & 0xFFFFFFFFL);
|
||||
}
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class RuinGenerator {
|
||||
private RuinGenerator() {
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisRuin ruin, int variantIndex, RNG rng, IrisData data) {
|
||||
int count = Math.max(1, ruin.getVariants());
|
||||
int height = pick(ruin.getHeightMin(), ruin.getHeightMax(), variantIndex, count, rng);
|
||||
int width = pick(ruin.getWidthMin(), ruin.getWidthMax(), variantIndex, count, rng);
|
||||
int length = pick(ruin.getLengthMin(), ruin.getLengthMax(), variantIndex, count, rng);
|
||||
|
||||
RuinBlockCanvas canvas = new RuinBlockCanvas();
|
||||
switch (ruin.getForm()) {
|
||||
case PILLAR -> RuinShapes.pillar(canvas, Math.max(1, width), Math.max(2, height), rng);
|
||||
case WALL -> RuinShapes.wall(canvas, Math.max(1, width), Math.max(2, length), Math.max(2, height), rng);
|
||||
case ARCH -> RuinShapes.arch(canvas, Math.max(1, width), Math.max(3, length), Math.max(3, height), rng);
|
||||
case FLOOR_SLAB -> RuinShapes.floorSlab(canvas, Math.max(3, width), Math.max(3, length), Math.max(1, Math.min(height, 2)));
|
||||
case RUBBLE -> RuinShapes.rubble(canvas, Math.max(3, width), Math.max(3, length), Math.max(1, Math.min(height, 4)), rng);
|
||||
}
|
||||
|
||||
applyBurial(ruin, canvas, height);
|
||||
applyErosion(ruin, canvas);
|
||||
applyAccents(ruin, canvas, rng, data);
|
||||
|
||||
return resolve(ruin, canvas, data);
|
||||
}
|
||||
|
||||
private static int pick(int lo, int hi, int variantIndex, int count, RNG rng) {
|
||||
int min = Math.min(lo, hi);
|
||||
int max = Math.max(lo, hi);
|
||||
if (min == max || count <= 1) {
|
||||
return rng.i(min, max + 1);
|
||||
}
|
||||
double step = (max - min) / (double) (count - 1);
|
||||
double base = min + step * variantIndex;
|
||||
double jitter = rng.d(-step * 0.3, step * 0.3);
|
||||
return (int) Math.round(Math.max(min, Math.min(max, base + jitter)));
|
||||
}
|
||||
|
||||
private static void applyBurial(IrisRuin ruin, RuinBlockCanvas canvas, int height) {
|
||||
double fraction = clamp01(ruin.getBuriedFraction());
|
||||
if (fraction <= 0.0) {
|
||||
return;
|
||||
}
|
||||
int sink = (int) Math.round(height * fraction);
|
||||
if (sink <= 0) {
|
||||
return;
|
||||
}
|
||||
Map<Vector3i, RuinBlockCanvas.Cell> moved = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, RuinBlockCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
moved.put(new Vector3i(v.getBlockX(), v.getBlockY() - sink, v.getBlockZ()), entry.getValue());
|
||||
}
|
||||
canvas.cells().clear();
|
||||
canvas.cells().putAll(moved);
|
||||
}
|
||||
|
||||
private static void applyErosion(IrisRuin ruin, RuinBlockCanvas canvas) {
|
||||
double erosion = clamp01(ruin.getErosion());
|
||||
if (erosion <= 0.0) {
|
||||
return;
|
||||
}
|
||||
double scale = Math.max(0.0001, ruin.getErosionScale());
|
||||
long erosionSeed = ruin.getSeed() * 0x2545F4914F6CDD1DL + 17L;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
}
|
||||
|
||||
List<Vector3i> doomed = new ArrayList<>();
|
||||
for (Map.Entry<Vector3i, RuinBlockCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
RuinBlockCanvas.Cell cell = entry.getValue();
|
||||
if (cell.structural() || v.getBlockY() <= minY) {
|
||||
continue;
|
||||
}
|
||||
int sx = (int) Math.round(v.getBlockX() * scale);
|
||||
int sy = (int) Math.round(v.getBlockY() * scale);
|
||||
int sz = (int) Math.round(v.getBlockZ() * scale);
|
||||
double n = TreeFunctions.valueNoise3D(sx, sy, sz, erosionSeed);
|
||||
if (n < erosion) {
|
||||
doomed.add(v);
|
||||
}
|
||||
}
|
||||
for (Vector3i v : doomed) {
|
||||
canvas.cells().remove(v);
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyAccents(IrisRuin ruin, RuinBlockCanvas canvas, RNG rng, IrisData data) {
|
||||
if (ruin.getAccents() == null || ruin.getAccents().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int decoratorIndex = 0;
|
||||
for (art.arcane.iris.generation.decoration.ruin.IrisRuinDecorator decorator : ruin.getAccents()) {
|
||||
RuinDecoratorApplier.apply(canvas, decorator, data, ruin.getSeed() + decoratorIndex * 911L, rng.nextParallelRNG(decoratorIndex + 1));
|
||||
decoratorIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
private static IrisObject resolve(IrisRuin ruin, RuinBlockCanvas canvas, IrisData data) {
|
||||
if (canvas.cells().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
double scale = Math.max(0.0001, ruin.getWeatheringScale());
|
||||
double mossiness = clamp01(ruin.getMossiness());
|
||||
long weatherSeed = ruin.getSeed() * 0x9E3779B97F4A7C15L + 101L;
|
||||
RNG paletteRng = new RNG(ruin.getSeed());
|
||||
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
maxY = Math.max(maxY, v.getBlockY());
|
||||
}
|
||||
int span = Math.max(1, maxY - minY);
|
||||
|
||||
Map<Vector3i, NativeBlockState> blocks = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, RuinBlockCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
RuinBlockCanvas.Cell cell = entry.getValue();
|
||||
NativeBlockState bd;
|
||||
if (cell.role() == RuinBlockCanvas.Role.ACCENT) {
|
||||
bd = cell.accentData();
|
||||
} else {
|
||||
bd = structuralBlock(ruin, cell, v, data, paletteRng, scale, mossiness, weatherSeed, minY, span);
|
||||
}
|
||||
if (bd != null) {
|
||||
blocks.put(v, bd);
|
||||
}
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(blocks);
|
||||
}
|
||||
|
||||
private static NativeBlockState structuralBlock(IrisRuin ruin, RuinBlockCanvas.Cell cell, Vector3i v, IrisData data, RNG paletteRng, double scale, double mossiness, long weatherSeed, int minY, int span) {
|
||||
boolean weathered = false;
|
||||
if (mossiness > 0.0) {
|
||||
int sx = (int) Math.round(v.getBlockX() * scale);
|
||||
int sy = (int) Math.round(v.getBlockY() * scale);
|
||||
int sz = (int) Math.round(v.getBlockZ() * scale);
|
||||
double n = TreeFunctions.valueNoise3D(sx, sy, sz, weatherSeed);
|
||||
double normalized = (v.getBlockY() - minY) / (double) span;
|
||||
double gradient = 1.0 - 0.6 * normalized;
|
||||
weathered = n < mossiness * gradient;
|
||||
}
|
||||
|
||||
if (weathered) {
|
||||
NativeBlockState wd = IrisProceduralBlocks.resolve(ruin.getWeatheredBlock(), ruin.getWeatheringPalette(), data, v.getBlockX(), v.getBlockY(), v.getBlockZ(), paletteRng);
|
||||
if (wd != null) {
|
||||
return wd;
|
||||
}
|
||||
}
|
||||
return IrisProceduralBlocks.resolve(ruin.getBlock(), ruin.getBlockPalette(), data, v.getBlockX(), v.getBlockY(), v.getBlockZ(), paletteRng);
|
||||
}
|
||||
|
||||
private static double clamp01(double value) {
|
||||
if (value < 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
if (value > 1.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.ruin;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
final class RuinShapes {
|
||||
private RuinShapes() {
|
||||
}
|
||||
|
||||
static void pillar(RuinBlockCanvas canvas, int width, int height, RNG rng) {
|
||||
int half = (width - 1) / 2;
|
||||
int broken = Math.max(2, height - rng.i(0, Math.max(1, height / 3)));
|
||||
for (int y = 0; y < broken; y++) {
|
||||
boolean bottom = y == 0;
|
||||
int jitter = y >= broken - 1 ? rng.i(0, 2) : 0;
|
||||
for (int x = -half; x <= half; x++) {
|
||||
for (int z = -half; z <= half; z++) {
|
||||
if (y == broken - 1 && jitter > 0 && (Math.abs(x) == half || Math.abs(z) == half) && rng.chance(0.5)) {
|
||||
continue;
|
||||
}
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int stub = rng.i(0, 3);
|
||||
if (stub > 0) {
|
||||
int dir = rng.i(0, 4);
|
||||
int dx = dir == 0 ? 1 : (dir == 1 ? -1 : 0);
|
||||
int dz = dir == 2 ? 1 : (dir == 3 ? -1 : 0);
|
||||
for (int s = 1; s <= stub; s++) {
|
||||
canvas.set((half + s) * dx, 0, (half + s) * dz, RuinBlockCanvas.Role.STRUCTURE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void wall(RuinBlockCanvas canvas, int thickness, int length, int height, RNG rng) {
|
||||
int half = (length - 1) / 2;
|
||||
int tHalf = (thickness - 1) / 2;
|
||||
long edgeSeed = rng.lmax();
|
||||
for (int z = -half; z <= half; z++) {
|
||||
int top = height - jaggedDrop(z, height, edgeSeed);
|
||||
for (int y = 0; y < top; y++) {
|
||||
if (y > 0 && rng.chance(0.10)) {
|
||||
continue;
|
||||
}
|
||||
for (int x = -tHalf; x <= thickness - 1 - tHalf; x++) {
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, y == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void arch(RuinBlockCanvas canvas, int thickness, int span, int height, RNG rng) {
|
||||
int legSpacing = Math.max(2, span);
|
||||
int legGap = (legSpacing - 1) / 2;
|
||||
int tHalf = (thickness - 1) / 2;
|
||||
int legTop = Math.max(2, height - Math.max(2, (legSpacing / 2)));
|
||||
|
||||
for (int side = -1; side <= 1; side += 2) {
|
||||
int legZ = side * legGap;
|
||||
for (int y = 0; y < legTop; y++) {
|
||||
for (int x = -tHalf; x <= thickness - 1 - tHalf; x++) {
|
||||
canvas.set(x, y, legZ, RuinBlockCanvas.Role.STRUCTURE, y <= 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double radius = legGap;
|
||||
int crown = legTop + (int) Math.round(radius);
|
||||
for (int z = -legGap; z <= legGap; z++) {
|
||||
double inside = radius * radius - (z * z);
|
||||
if (inside < 0) {
|
||||
continue;
|
||||
}
|
||||
int y = legTop + (int) Math.round(Math.sqrt(inside));
|
||||
for (int yy = legTop; yy <= y && yy <= crown; yy++) {
|
||||
boolean keystone = Math.abs(z) <= 1;
|
||||
for (int x = -tHalf; x <= thickness - 1 - tHalf; x++) {
|
||||
canvas.set(x, yy, z, RuinBlockCanvas.Role.STRUCTURE, keystone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void floorSlab(RuinBlockCanvas canvas, int width, int length, int thickness) {
|
||||
int xHalf = (width - 1) / 2;
|
||||
int zHalf = (length - 1) / 2;
|
||||
for (int y = 0; y < thickness; y++) {
|
||||
for (int x = -xHalf; x <= width - 1 - xHalf; x++) {
|
||||
for (int z = -zHalf; z <= length - 1 - zHalf; z++) {
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, y == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rubble(RuinBlockCanvas canvas, int width, int length, int peak, RNG rng) {
|
||||
int xHalf = (width - 1) / 2;
|
||||
int zHalf = (length - 1) / 2;
|
||||
long blobSeed = rng.lmax();
|
||||
double rx = Math.max(1.0, width / 2.0);
|
||||
double rz = Math.max(1.0, length / 2.0);
|
||||
|
||||
for (int x = -xHalf; x <= width - 1 - xHalf; x++) {
|
||||
for (int z = -zHalf; z <= length - 1 - zHalf; z++) {
|
||||
double radial = (x * x) / (rx * rx) + (z * z) / (rz * rz);
|
||||
if (radial > 1.2) {
|
||||
continue;
|
||||
}
|
||||
double falloff = Math.max(0.0, 1.0 - radial);
|
||||
double noise = art.arcane.iris.generation.decoration.tree.TreeFunctions.valueNoise3D(x, 0, z, blobSeed);
|
||||
int columnHeight = (int) Math.round(peak * falloff * (0.6 + 0.4 * noise));
|
||||
for (int y = 0; y <= columnHeight; y++) {
|
||||
if (y > 0 && rng.chance(0.25)) {
|
||||
continue;
|
||||
}
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, y == 0 && radial < 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int jaggedDrop(int z, int height, long seed) {
|
||||
double n = art.arcane.iris.generation.decoration.tree.TreeFunctions.valueNoise1D(z * 0.9, seed);
|
||||
return (int) Math.round(n * Math.max(1, height - 1) * 0.6);
|
||||
}
|
||||
}
|
||||
-344
@@ -1,344 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectLimit;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.iris.pack.schema.annotation.ArrayType;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("procedural-tree")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A single procedurally generated tree. Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file.")
|
||||
@Data
|
||||
public class IrisProceduralTree implements IrisProceduralPlacement {
|
||||
private final transient AtomicCache<KList<IrisObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
@Description("A human readable name used in logs and as the variant load key.")
|
||||
private String name = "procedural-tree";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per chunk for this tree to attempt placement. Use density for multiple per chunk.")
|
||||
private double chance = 0.4;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, attempt this many placements in the chunk.")
|
||||
private int density = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("How many distinct variants to pre-bake for this tree. Higher means more variety at a small memory cost.")
|
||||
private int variants = 8;
|
||||
|
||||
@Description("The base seed for deterministic generation. The same seed and settings always bake the same variants.")
|
||||
private long seed = 1337;
|
||||
|
||||
@Description("If true (default) leaves are placed with vanilla distance-from-wood values and persistent=false so leaf decay behaves naturally and the tree reads as plausible. If false, leaves are forced persistent and never decay (a raw object dump).")
|
||||
private boolean plausible = true;
|
||||
|
||||
@Description("The placement mode used to anchor the tree to the terrain.")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
|
||||
|
||||
@Description("Rotate this tree's placement.")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
|
||||
@Description("Limit the max or min height of placement.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@Description("Whether this tree may place on the terrain surface, under carvings, or both.")
|
||||
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
|
||||
|
||||
@Description("If true, the tree anchors on the terrain height ignoring the water surface.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
|
||||
@Description("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).")
|
||||
private IrisStiltSettings stiltSettings;
|
||||
|
||||
@Description("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).")
|
||||
private IrisVacuumSettings vacuumSettings;
|
||||
|
||||
@Required
|
||||
@Description("The trunk (log) block, e.g. minecraft:oak_log. Ignored when trunkPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String trunk = "minecraft:oak_log";
|
||||
|
||||
@Description("A noise-driven palette for the trunk. When set this overrides the single trunk block, letting the trunk mix blocks by noise.")
|
||||
private IrisMaterialPalette trunkPalette = null;
|
||||
|
||||
@Required
|
||||
@Description("The leaf block, e.g. minecraft:oak_leaves. Ignored when leavesPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String leaves = "minecraft:oak_leaves";
|
||||
|
||||
@Description("A noise-driven palette for the leaves. When set this overrides the single leaf block, letting the canopy mix leaf (or other) blocks by noise. Only blocks that are actually leaves get vanilla decay distances.")
|
||||
private IrisMaterialPalette leavesPalette = null;
|
||||
|
||||
@Description("The named canopy profile that drives default crown radii and shape.")
|
||||
private IrisTreeProfile profile = IrisTreeProfile.OAK;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Minimum trunk height in blocks.")
|
||||
private int heightMin = 8;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum trunk height in blocks.")
|
||||
private int heightMax = 12;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Base trunk width in blocks. 1 is a single column, 2 is a 2x2 trunk, etc.")
|
||||
private int trunkWidth = 1;
|
||||
|
||||
@Description("The function used to shape trunk width over height.")
|
||||
private IrisTreeFunction trunkShape = IrisTreeFunction.CONSTANT;
|
||||
|
||||
@Description("Width multiplier at the base for the LINEAR trunk shape.")
|
||||
private double shapeStart = 1;
|
||||
|
||||
@Description("Width multiplier at the top for the LINEAR trunk shape.")
|
||||
private double shapeEnd = 1;
|
||||
|
||||
@Description("Steepness for the SIGMOID trunk shape.")
|
||||
private double shapeSteepness = 5;
|
||||
|
||||
@Description("Base for the LOG trunk shape.")
|
||||
private double shapeBase = 2.718281828;
|
||||
|
||||
@Description("Period for the SINE trunk shape.")
|
||||
private double shapePeriod = 1;
|
||||
|
||||
@Description("Amplitude for the SINE trunk shape.")
|
||||
private double shapeAmplitude = 0.2;
|
||||
|
||||
@Description("Pinch position (0-1) for the PARABOLIC trunk shape.")
|
||||
private double shapePeakOffset = 0.5;
|
||||
|
||||
@Description("Minimum width fraction at the waist for the PARABOLIC trunk shape.")
|
||||
private double shapeFloor = 0.5;
|
||||
|
||||
@Description("Compass direction in degrees the trunk leans toward.")
|
||||
private double leanAzimuth = 0;
|
||||
|
||||
@Description("How far the trunk leans, in degrees from vertical. 0 is perfectly upright.")
|
||||
private double leanAngle = 0;
|
||||
|
||||
@Description("How the lean accumulates over height.")
|
||||
private IrisTreeFunction trunkCurve = IrisTreeFunction.LINEAR;
|
||||
|
||||
@Description("Steepness for the SIGMOID trunk curve.")
|
||||
private double curveSteepness = 8;
|
||||
|
||||
@Description("How the lean azimuth itself changes over height (for spiraling or wandering trunks).")
|
||||
private IrisTreeAzimuthMode leanAzimuthMode = IrisTreeAzimuthMode.CONSTANT;
|
||||
|
||||
@Description("Azimuth at the base for the LINEAR azimuth mode.")
|
||||
private double azimuthStart = 0;
|
||||
|
||||
@Description("Azimuth at the top for the LINEAR azimuth mode.")
|
||||
private double azimuthEnd = 0;
|
||||
|
||||
@Description("Number of full turns for the SPIRAL azimuth mode.")
|
||||
private double azimuthTurns = 1;
|
||||
|
||||
@Description("Amplitude for the SINE azimuth mode.")
|
||||
private double azimuthAmplitude = 90;
|
||||
|
||||
@Description("Period for the SINE azimuth mode.")
|
||||
private double azimuthPeriod = 1;
|
||||
|
||||
@Description("Offset for the SINE azimuth mode.")
|
||||
private double azimuthOffset = 0;
|
||||
|
||||
@Description("Scale for the NOISE azimuth mode.")
|
||||
private double azimuthScale = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Number of branches per whorl ring for the WHORL branch azimuth mode.")
|
||||
private int azimuthWhorlCount = 5;
|
||||
|
||||
@Description("Optional accent leaf block scattered through the canopy (blossoms, shroomlight).")
|
||||
@RegistryListBlockType
|
||||
private String secondaryLeaves = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The fraction of leaves replaced by the secondary leaf block(s).")
|
||||
private double secondaryLeafFraction = 0.35;
|
||||
|
||||
@ArrayType(min = 1, type = IrisTreeSecondaryLeaf.class)
|
||||
@Description("Optional weighted set of accent leaf blocks. When set this overrides the single secondaryLeaves block.")
|
||||
private KList<IrisTreeSecondaryLeaf> weightedSecondaryLeaves = new KList<>();
|
||||
|
||||
@Description("A noise-driven palette for the secondary (accent) leaves. When set this overrides both secondaryLeaves and weightedSecondaryLeaves.")
|
||||
private IrisMaterialPalette secondaryLeavesPalette = null;
|
||||
|
||||
@Description("Optional secondary trunk block used over a height band (for color-banded trunks). Ignored when secondaryTrunkPalette is set.")
|
||||
@RegistryListBlockType
|
||||
private String secondaryTrunk = null;
|
||||
|
||||
@Description("A noise-driven palette for the secondary trunk band. When set this overrides the single secondaryTrunk block.")
|
||||
private IrisMaterialPalette secondaryTrunkPalette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The normalized height where the secondary trunk band starts.")
|
||||
private double secondaryTrunkStart = 0.5;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The normalized height where the secondary trunk band ends.")
|
||||
private double secondaryTrunkEnd = 1;
|
||||
|
||||
@Description("If true, a root system extends below (and around) the base so the tree connects to the ground on uneven terrain.")
|
||||
private boolean roots = true;
|
||||
|
||||
@Description("How the root system is built when roots is true.")
|
||||
private IrisTreeRootStyle rootStyle = IrisTreeRootStyle.BUTTRESS;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Root depth in blocks, also used for ground-contact extension up to 16 blocks. 0 scales with tree height.")
|
||||
private int rootDepth = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Horizontal reach of buttress and stilt roots. 0 uses a compact radius based on trunk width. Taproots ignore this field.")
|
||||
private double rootFlare = 0;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(6)
|
||||
@Description("How many separate trunks the tree splits into above forkHeight. 1 is a single trunk.")
|
||||
private int trunkForks = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The normalized height where the trunk splits into forks.")
|
||||
private double forkHeight = 0.5;
|
||||
|
||||
@Description("The outward lean angle in degrees of each fork.")
|
||||
private double forkAngle = 25;
|
||||
|
||||
@Description("The leaf crown configuration.")
|
||||
private IrisTreeCanopy canopy = new IrisTreeCanopy();
|
||||
|
||||
@ArrayType(min = 1, type = IrisTreeDecorator.class)
|
||||
@Description("Accent decorators applied after the tree is built (fruit, vines, snow, glow).")
|
||||
private KList<IrisTreeDecorator> decorators = new KList<>();
|
||||
|
||||
public KList<IrisObject> getVariantObjects(IrisData data) {
|
||||
return variantCache.aquire(() -> {
|
||||
KList<IrisObject> baked = new KList<>();
|
||||
int count = Math.max(1, variants);
|
||||
int lo = Math.min(heightMin, heightMax);
|
||||
int hi = Math.max(heightMin, heightMax);
|
||||
RNG heightRng = new RNG(seed);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int height;
|
||||
if (count == 1 || lo == hi) {
|
||||
height = heightRng.i(lo, hi + 1);
|
||||
} else {
|
||||
double step = (hi - lo) / (double) (count - 1);
|
||||
double base = lo + step * i;
|
||||
double jitter = heightRng.d(-step * 0.3, step * 0.3);
|
||||
height = (int) Math.round(Math.max(lo, Math.min(hi, base + jitter)));
|
||||
}
|
||||
|
||||
IrisObject object = ProceduralTreeGenerator.generate(this, Math.max(2, height), new RNG(seed + (i * 7919L)), data);
|
||||
if (object == null || object.getBlocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
object.setLoadKey(getVariantLoadKey(i));
|
||||
object.setLoader(data);
|
||||
baked.add(object);
|
||||
}
|
||||
|
||||
if (new java.io.File("plugins/Iris/goldendebug.txt").isFile()) {
|
||||
for (IrisObject object : baked) {
|
||||
long[] digest = new long[]{0L};
|
||||
object.getBlocks().forEach((vector, state) -> {
|
||||
long position = ((long) vector.getBlockX() << 40) ^ ((long) vector.getBlockY() << 20) ^ vector.getBlockZ();
|
||||
digest[0] ^= Long.rotateLeft(position * 0x9E3779B97F4A7C15L ^ state.key().hashCode(), (int) (position & 63));
|
||||
});
|
||||
IrisLogging.debug("Goldendebug bake: " + object.getLoadKey() + " blocks=" + object.getBlocks().size() + " digest=" + Long.toHexString(digest[0]));
|
||||
}
|
||||
}
|
||||
|
||||
return baked;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject getVariantObject(IrisData data, RNG rng, SubterrainRoom room) {
|
||||
KList<IrisObject> baked = getVariantObjects(data);
|
||||
if (baked == null || baked.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return baked.get(rng.i(baked.size()));
|
||||
}
|
||||
|
||||
public String getVariantLoadKey(int index) {
|
||||
if (index < 0) {
|
||||
throw new IllegalArgumentException("index must not be negative");
|
||||
}
|
||||
return "procedural/tree/" + name + "#" + index;
|
||||
}
|
||||
|
||||
public IrisObjectPlacement asPlacement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(mode);
|
||||
placement.setRotation(rotation);
|
||||
placement.setClamp(clamp);
|
||||
placement.setCarvingSupport(carvingSupport);
|
||||
placement.setUnderwater(underwater);
|
||||
placement.setTranslate(translate);
|
||||
placement.setStiltSettings(stiltSettings);
|
||||
placement.setVacuumSettings(vacuumSettings);
|
||||
placement.setChance(chance);
|
||||
placement.setDensity(density);
|
||||
return placement;
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("Controls the compass direction (azimuth) of trunk lean as it rises, or the direction each branch is thrown.")
|
||||
public enum IrisTreeAzimuthMode {
|
||||
@Description("A single fixed azimuth.")
|
||||
CONSTANT,
|
||||
@Description("Azimuth ramps straight from start to end with height.")
|
||||
LINEAR,
|
||||
@Description("Azimuth winds around the trunk a number of turns (corkscrew).")
|
||||
SPIRAL,
|
||||
@Description("Azimuth oscillates with a sine wave.")
|
||||
SINE,
|
||||
@Description("Azimuth wanders using deterministic noise.")
|
||||
NOISE,
|
||||
@Description("Each branch picks a uniformly random azimuth (falls back to constant for trunk lean).")
|
||||
RANDOM,
|
||||
@Description("Phyllotaxis: each successive branch is offset by the 137.5 degree golden angle for the most natural spiral packing (branches).")
|
||||
GOLDEN_ANGLE,
|
||||
@Description("Each successive branch is thrown to the opposite side (180 degrees apart).")
|
||||
ALTERNATING,
|
||||
@Description("Branches are grouped into evenly spaced whorls of azimuthWhorlCount around each ring.")
|
||||
WHORL,
|
||||
@Description("Azimuth zigzags by +/- amplitude on alternating branches.")
|
||||
ZIGZAG
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("Controls how the chance of spawning a branch varies with trunk height (0 at the base, 1 at the top).")
|
||||
public enum IrisTreeBranchProbability {
|
||||
@Description("Same branch chance at every height.")
|
||||
CONSTANT,
|
||||
@Description("Ramps straight from base chance to crown chance.")
|
||||
LINEAR,
|
||||
@Description("S-curve that switches on around a midpoint height.")
|
||||
SIGMOID,
|
||||
@Description("Chance rises with height raised to an exponent, clustering branches near the crown.")
|
||||
TOP_HEAVY,
|
||||
@Description("Bell curve peaking in a height band.")
|
||||
GAUSSIAN,
|
||||
@Description("Irregular organic branching from deterministic noise.")
|
||||
NOISE,
|
||||
@Description("Chance falls with height (1-t)^exponent, clustering branches near the base.")
|
||||
BOTTOM_HEAVY,
|
||||
@Description("Regular whorl rings of branches at evenly spaced heights (periods controls count).")
|
||||
PERIODIC,
|
||||
@Description("Branches only within a height window around mean +/- std.")
|
||||
BAND,
|
||||
@Description("Inverse of GAUSSIAN: branches avoid the mean band and favor base and crown.")
|
||||
INVERSE_GAUSSIAN,
|
||||
@Description("Exponential decay from the base upward (constant * e^-exponent*t).")
|
||||
EXPONENTIAL_DECAY
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("tree-branches")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A branch system that throws limbs out of the trunk and places a leaf ball at each tip. When present, branches drive the canopy and only the topmost crown disc of the profile is still placed.")
|
||||
@Data
|
||||
public class IrisTreeBranches {
|
||||
@Description("How branch spawn chance varies over trunk height.")
|
||||
private IrisTreeBranchProbability probabilityFunction = IrisTreeBranchProbability.TOP_HEAVY;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Branch chance for the CONSTANT probability function.")
|
||||
private double probabilityConstant = 0.5;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Branch chance at the base for the LINEAR probability function.")
|
||||
private double probabilityBase = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Branch chance at the crown for the LINEAR probability function.")
|
||||
private double probabilityCrown = 1;
|
||||
|
||||
@Description("Steepness for the SIGMOID probability function.")
|
||||
private double probabilitySteepness = 10;
|
||||
|
||||
@Description("Midpoint height (0-1) for the SIGMOID probability function.")
|
||||
private double probabilityMidpoint = 0.7;
|
||||
|
||||
@Description("Exponent for the TOP_HEAVY probability function.")
|
||||
private double probabilityExponent = 2;
|
||||
|
||||
@Description("Mean height (0-1) for the GAUSSIAN probability function.")
|
||||
private double probabilityMean = 0.7;
|
||||
|
||||
@Description("Standard deviation for the GAUSSIAN probability function.")
|
||||
private double probabilityStd = 0.15;
|
||||
|
||||
@Description("Noise scale for the NOISE probability function.")
|
||||
private double probabilityScale = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Number of whorl rings over the trunk height for the PERIODIC probability function.")
|
||||
private double probabilityPeriods = 5;
|
||||
|
||||
@Description("How branch length varies over trunk height.")
|
||||
private IrisTreeFunction lengthFunction = IrisTreeFunction.LINEAR;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Branch length at the base for the LINEAR length function.")
|
||||
private double lengthBase = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Branch length at the crown for the LINEAR length function.")
|
||||
private double lengthCrown = 4;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Branch length for the CONSTANT length function.")
|
||||
private double lengthConstant = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Maximum branch length for the SIGMOID, LOG and PARABOLIC length functions.")
|
||||
private double lengthMax = 4;
|
||||
|
||||
@Description("Steepness for the SIGMOID length function.")
|
||||
private double lengthSteepness = 5;
|
||||
|
||||
@Description("How the compass direction of each branch is chosen.")
|
||||
private IrisTreeAzimuthMode azimuthMode = IrisTreeAzimuthMode.RANDOM;
|
||||
|
||||
@Description("Fixed azimuth in degrees when azimuthMode is CONSTANT.")
|
||||
private double azimuth = 0;
|
||||
|
||||
@Description("Elevation angle in degrees from horizontal. 0 is flat, positive points up, negative droops down.")
|
||||
private double elevation = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How much each branch sags/droops along its length (catenary). 0 is a straight branch; higher values arc the branch and its tip downward.")
|
||||
private double sag = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(6)
|
||||
@Description("How many recursive levels of sub-branches to grow. 0 is none, 1 is a single level, 2+ produces fractal branching.")
|
||||
private int branchDepth = 1;
|
||||
|
||||
@Description("If true, branches are clamped to never droop below horizontal (useful for upright species).")
|
||||
private boolean leafStartUp = false;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Leaf ball radius placed at each branch tip.")
|
||||
private int clusterRadius = 2;
|
||||
|
||||
@Description("How the branch tip leaf cluster fills.")
|
||||
private IrisTreeLeafMode clusterMode = IrisTreeLeafMode.TRIMMED;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Fill density for the branch tip leaf cluster when clusterMode is density or noise.")
|
||||
private double clusterDensity = 0.85;
|
||||
|
||||
@Description("Optional one level of recursive sub-branches sprouting from each branch tip.")
|
||||
private IrisTreeSubBranches subBranches = null;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.ArrayType;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("tree-canopy")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("The leaf crown of a procedural tree. Built from stacked dome-shaped discs (driven by the profile or by explicit layers) and optionally a branch system.")
|
||||
@Data
|
||||
public class IrisTreeCanopy {
|
||||
@MinNumber(0)
|
||||
@MaxNumber(180)
|
||||
@Description("Elevation angle in degrees from vertical for each leaf dome. 90 is a flat disc, below 90 domes downward into a sphere, above 90 flares outward into an umbrella.")
|
||||
private double startAngle = 90;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Vertical scale of the canopy volume. Lower values flatten the crown.")
|
||||
private double squish = 1;
|
||||
|
||||
@Description("How leaves fill each canopy disc.")
|
||||
private IrisTreeLeafMode mode = IrisTreeLeafMode.TRIMMED;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Fill probability used by the density and noise leaf modes.")
|
||||
private double leafDensity = 0.85;
|
||||
|
||||
@MinNumber(0.1)
|
||||
@Description("Horizontal X stretch of the crown for elliptical or wind-blown shapes. 1 is circular.")
|
||||
private double crownStretchX = 1;
|
||||
|
||||
@MinNumber(0.1)
|
||||
@Description("Horizontal Z stretch of the crown for elliptical or wind-blown shapes. 1 is circular.")
|
||||
private double crownStretchZ = 1;
|
||||
|
||||
@ArrayType(min = 1, type = IrisTreeLayer.class)
|
||||
@Description("Optional explicit crown discs. When provided these replace the profile-driven layers and let you sculpt the silhouette by hand.")
|
||||
private KList<IrisTreeLayer> layers = new KList<>();
|
||||
|
||||
@Description("Optional branch system. When present, branches build most of the canopy and only the topmost profile disc is still placed as a crown.")
|
||||
private IrisTreeBranches branches = null;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("tree-decorator")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("An accent block applied to a generated tree such as fruit on branch tips, vines on the trunk, snow on the crown, or a glowing underside.")
|
||||
@Data
|
||||
public class IrisTreeDecorator {
|
||||
@Description("Where this decorator is placed on the tree.")
|
||||
private IrisTreeDecoratorTarget target = IrisTreeDecoratorTarget.BRANCH_TIP;
|
||||
|
||||
@Required
|
||||
@Description("The block id to place, e.g. minecraft:magma_block. Ignored when palette is set.")
|
||||
@RegistryListBlockType
|
||||
private String block = "";
|
||||
|
||||
@Description("A noise-driven palette for this decorator. When set this overrides the single block.")
|
||||
private IrisMaterialPalette palette = null;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("The chance per candidate position for this decorator to place.")
|
||||
private double chance = 0.5;
|
||||
|
||||
@MinNumber(1)
|
||||
@Description("Maximum strand length downward for the CANOPY_HANG target (random 1..length per column).")
|
||||
private int length = 1;
|
||||
|
||||
@Description("If true the block's facing is oriented away from the trunk (for trunk-mounted fences/gates/banners).")
|
||||
private boolean axisAware = false;
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("Where a tree decorator block is placed.")
|
||||
public enum IrisTreeDecoratorTarget {
|
||||
@Description("At the tip of each generated branch (vines, fruit, lanterns).")
|
||||
BRANCH_TIP,
|
||||
@Description("On air-facing sides of trunk and branch blocks (vines, moss).")
|
||||
TRUNK_SURFACE,
|
||||
@Description("On top of the highest block in each column (snow, sculk).")
|
||||
CANOPY_TOP,
|
||||
@Description("One block below the lowest leaf in each column (glowing underside).")
|
||||
CANOPY_BOTTOM,
|
||||
@Description("Around the y=0 ring at the base of the trunk (roots, mushrooms).")
|
||||
TRUNK_BASE,
|
||||
@Description("On air-facing sides of leaf blocks (berries, lights nestled in the foliage).")
|
||||
LEAF_SURFACE,
|
||||
@Description("Hanging strands of up to 'length' blocks below the lowest leaf in each column (vines, icicles).")
|
||||
CANOPY_HANG,
|
||||
@Description("On the top face of trunk and branch blocks (moss, snow on limbs).")
|
||||
BRANCH_SURFACE,
|
||||
@Description("One block above the very top of the trunk (nest, beehive, beacon).")
|
||||
TRUNK_TOP,
|
||||
@Description("Scattered across the ground footprint around the base, wider than the trunk-base ring.")
|
||||
GROUND_SCATTER
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("A shaping function evaluated over normalized height (0 at the base, 1 at the top). Used for trunk width, trunk curve and branch length.")
|
||||
public enum IrisTreeFunction {
|
||||
@Description("Same value at every height.")
|
||||
CONSTANT,
|
||||
@Description("Ramps straight from start to end.")
|
||||
LINEAR,
|
||||
@Description("S-curve transition controlled by steepness.")
|
||||
SIGMOID,
|
||||
@Description("Logarithmic falloff controlled by base.")
|
||||
LOG,
|
||||
@Description("Sine ripple controlled by period and amplitude.")
|
||||
SINE,
|
||||
@Description("Parabolic pinch, narrowest at peakOffset.")
|
||||
PARABOLIC,
|
||||
@Description("Geometric (exponential) interpolation from start to end.")
|
||||
EXPONENTIAL,
|
||||
@Description("Square-root ease: fast change low, slow high.")
|
||||
SQRT,
|
||||
@Description("Hard step that jumps from start to end at the threshold (peakOffset).")
|
||||
STEP,
|
||||
@Description("Bell bulge peaking in the middle of the height range.")
|
||||
BELL,
|
||||
@Description("Smoothstep ease-in-out (3t^2 - 2t^3).")
|
||||
EASE_IN_OUT
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("tree-layer")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("An explicit canopy disc at a given vertical offset and radius. Define a list of these to bypass the profile and sculpt the crown by hand.")
|
||||
@Data
|
||||
public class IrisTreeLayer {
|
||||
@Description("The vertical offset of this disc, measured in blocks above the trunk base.")
|
||||
private int yOffset = 0;
|
||||
|
||||
@MinNumber(0.5)
|
||||
@Description("The radius of this leaf disc in blocks.")
|
||||
private double radius = 2;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("How leaves fill a disc or cluster.")
|
||||
public enum IrisTreeLeafMode {
|
||||
@Description("Corner-trimmed disc/sphere for a rounded silhouette.")
|
||||
TRIMMED,
|
||||
@Description("Completely filled disc/sphere.")
|
||||
FILLED,
|
||||
@Description("Seeded probabilistic falloff toward the edge controlled by leafDensity.")
|
||||
DENSITY,
|
||||
@Description("Seeded value-noise mask controlled by leafDensity.")
|
||||
NOISE,
|
||||
@Description("Only the outer shell is placed, leaving the interior hollow.")
|
||||
HOLLOW,
|
||||
@Description("Quadratic radial gradient: dense at the center, thinning sharply toward the edge.")
|
||||
GRADIENT,
|
||||
@Description("Coarse low-frequency noise that forms clumps and gaps of foliage.")
|
||||
CLUMPED,
|
||||
@Description("Trimmed with heavy random erosion of the outer ring for a ragged, weathered look.")
|
||||
TATTERED,
|
||||
@Description("Very thin scattering of leaves across the volume.")
|
||||
SPARSE
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("Named canopy presets that drive default layer radii and shape, scaled to the tree height.")
|
||||
public enum IrisTreeProfile {
|
||||
@Description("Rounded broadleaf crown.")
|
||||
OAK,
|
||||
@Description("Slim upright broadleaf crown.")
|
||||
BIRCH,
|
||||
@Description("Upright broadleaf crown with a rounded upper canopy and a tapered top.")
|
||||
POPLAR,
|
||||
@Description("Narrow conifer cone.")
|
||||
SPRUCE,
|
||||
@Description("Tall thin crown concentrated near the very top.")
|
||||
JUNGLE,
|
||||
@Description("Flat shallow umbrella crown.")
|
||||
ACACIA,
|
||||
@Description("Dense rounded broadleaf crown.")
|
||||
DARK_OAK,
|
||||
@Description("Flat wide umbrella crown compressed into the top quarter (vanilla dark oak look).")
|
||||
DARK_OAK_FLAT,
|
||||
@Description("Extra wide flat umbrella that overlaps into a continuous roofed canopy.")
|
||||
DARK_OAK_FLAT_WIDE,
|
||||
@Description("Broad rounded blossom crown.")
|
||||
CHERRY,
|
||||
@Description("Bare trunk with a small tuft of fronds only at the very top.")
|
||||
PALM,
|
||||
@Description("Broad crown with wide drooping radii, ideal with a low startAngle to make a weeping skirt.")
|
||||
WILLOW,
|
||||
@Description("Very narrow tall crown hugging the trunk (cypress / lombardy poplar).")
|
||||
COLUMNAR,
|
||||
@Description("Squat, wide, low crown for shrubs and saplings.")
|
||||
BUSH,
|
||||
@Description("Giant conifer cone for 2x2 mega spruce trunks.")
|
||||
MEGA_SPRUCE
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
@Description("How a procedural tree's root system is built below (and around) the trunk base.")
|
||||
public enum IrisTreeRootStyle {
|
||||
@Description("A single tapering taproot straight down from the base.")
|
||||
TAPROOT,
|
||||
@Description("A taproot plus a ring of flared buttress legs that splay outward as they descend (default).")
|
||||
BUTTRESS,
|
||||
@Description("Visible above-ground prop roots that arch out and down from the lower trunk to the ground (mangrove style).")
|
||||
STILT
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListBlockType;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("tree-secondary-leaf")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("A weighted accent leaf or foliage block scattered through the canopy (blossoms, shroomlight, berries).")
|
||||
@Data
|
||||
public class IrisTreeSecondaryLeaf {
|
||||
@Required
|
||||
@Description("The block id to scatter, e.g. minecraft:shroomlight")
|
||||
@RegistryListBlockType
|
||||
private String block = "";
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("The relative weight of this block among the secondary leaves.")
|
||||
private int weight = 1;
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("tree-sub-branches")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("One recursive level of sub-branches sprouting from each primary branch tip.")
|
||||
@Data
|
||||
public class IrisTreeSubBranches {
|
||||
@MinNumber(1)
|
||||
@Description("How many sub-branches sprout from each primary branch tip.")
|
||||
private int count = 1;
|
||||
|
||||
@Description("Pitch deflection in degrees applied to each sub-branch relative to its parent. Positive bends up, negative droops down. Cumulative pitch past 90 makes sub-branches point downward.")
|
||||
private double pitchDelta = 0;
|
||||
|
||||
@Description("Yaw (horizontal) spread in degrees fanned between sub-branches.")
|
||||
private double yawDelta = 45;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Sub-branch length as a fraction of its parent branch length.")
|
||||
private double lengthScale = 0.5;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How much each sub-branch sags/droops along its length (catenary).")
|
||||
private double sag = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Leaf ball radius placed at each sub-branch tip.")
|
||||
private int clusterRadius = 1;
|
||||
|
||||
@Description("How the sub-branch tip leaf cluster fills.")
|
||||
private IrisTreeLeafMode clusterMode = IrisTreeLeafMode.TRIMMED;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Fill density for the sub-branch leaf cluster when clusterMode is density or noise.")
|
||||
private double clusterDensity = 0.85;
|
||||
}
|
||||
-147
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class ProceduralTreeGenerator {
|
||||
private ProceduralTreeGenerator() {
|
||||
}
|
||||
|
||||
public static IrisObject generate(IrisProceduralTree tree, int height, RNG rng, IrisData data) {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
long baseSeed = rng.getSeed();
|
||||
|
||||
List<TreeTrunkBuilder.Limb> limbs = TreeTrunkBuilder.build(canvas, tree, height);
|
||||
Set<TreeBlockCanvas.Vec> supportPositions = new HashSet<>();
|
||||
for (TreeBlockCanvas.Vec position : canvas.getTrunk()) {
|
||||
if (position.y() == 0) {
|
||||
supportPositions.add(position);
|
||||
}
|
||||
}
|
||||
|
||||
boolean wantEndpoints = tree.getDecorators() != null && !tree.getDecorators().isEmpty();
|
||||
List<int[]> branchEndpoints = wantEndpoints ? new ArrayList<>() : null;
|
||||
|
||||
int limbIndex = 0;
|
||||
for (TreeTrunkBuilder.Limb limb : limbs) {
|
||||
TreeCanopyBuilder.build(canvas, tree, height, limb.offsets(), limb.branchStartY(), baseSeed + limbIndex * 131L, branchEndpoints);
|
||||
limbIndex++;
|
||||
}
|
||||
|
||||
if (wantEndpoints) {
|
||||
TreeDecoratorApplier.apply(canvas, tree, baseSeed, branchEndpoints);
|
||||
}
|
||||
|
||||
if (tree.isRoots()) {
|
||||
Set<TreeBlockCanvas.Vec> existingWood = new HashSet<>(canvas.getTrunk());
|
||||
TreeRootBuilder.build(canvas, tree, height, baseSeed);
|
||||
for (TreeBlockCanvas.Vec position : canvas.getTrunk()) {
|
||||
if (position.y() <= 0 && !existingWood.contains(position)) {
|
||||
supportPositions.add(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tree.isPlausible()) {
|
||||
TreeSupport.ensureLeavesSupported(canvas, 24);
|
||||
}
|
||||
|
||||
Map<TreeBlockCanvas.Vec, NativeBlockState> resolved = new HashMap<>();
|
||||
Set<TreeBlockCanvas.Vec> trunkPositions = new HashSet<>();
|
||||
Set<TreeBlockCanvas.Vec> leafPositions = new HashSet<>();
|
||||
RNG paletteRng = new RNG(tree.getSeed());
|
||||
for (Map.Entry<TreeBlockCanvas.Vec, TreeBlockCanvas.Cell> entry : canvas.getCells().entrySet()) {
|
||||
TreeBlockCanvas.Cell cell = entry.getValue();
|
||||
NativeBlockState state = TreeBlockResolver.resolve(tree, data, cell, entry.getKey(), paletteRng);
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(entry.getKey(), state);
|
||||
if (cell.role() == TreeBlockCanvas.Role.TRUNK || cell.role() == TreeBlockCanvas.Role.SECONDARY_TRUNK) {
|
||||
trunkPositions.add(entry.getKey());
|
||||
} else if (cell.role() == TreeBlockCanvas.Role.LEAF || cell.role() == TreeBlockCanvas.Role.SECONDARY_LEAF) {
|
||||
leafPositions.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
TreePlausibility.apply(resolved, trunkPositions, leafPositions, tree);
|
||||
|
||||
int rootReach = tree.isRoots() ? tree.getRootDepth() > 0 ? tree.getRootDepth()
|
||||
: Math.max(2, (int) Math.round(height * 0.18)) : 0;
|
||||
return assemble(resolved, supportPositions, leafPositions, rootReach);
|
||||
}
|
||||
|
||||
private static IrisObject assemble(Map<TreeBlockCanvas.Vec, NativeBlockState> resolved,
|
||||
Set<TreeBlockCanvas.Vec> supportPositions,
|
||||
Set<TreeBlockCanvas.Vec> leafPositions, int rootReach) {
|
||||
if (resolved.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (TreeBlockCanvas.Vec v : resolved.keySet()) {
|
||||
minX = Math.min(minX, v.x());
|
||||
minY = Math.min(minY, v.y());
|
||||
minZ = Math.min(minZ, v.z());
|
||||
maxX = Math.max(maxX, v.x());
|
||||
maxY = Math.max(maxY, v.y());
|
||||
maxZ = Math.max(maxZ, v.z());
|
||||
}
|
||||
|
||||
int w = 2 * Math.max(Math.abs(minX), Math.abs(maxX)) + 1;
|
||||
int h = maxY - minY + 1;
|
||||
int d = 2 * Math.max(Math.abs(minZ), Math.abs(maxZ)) + 1;
|
||||
int cy = h / 2;
|
||||
|
||||
IrisObject object = new IrisObject(w, h, d);
|
||||
List<TreeGrounding.Root> roots = new ArrayList<>(supportPositions.size());
|
||||
Set<TreeBlockCanvas.Vec> canopy = new HashSet<>(leafPositions.size());
|
||||
for (Map.Entry<TreeBlockCanvas.Vec, NativeBlockState> entry : resolved.entrySet()) {
|
||||
TreeBlockCanvas.Vec v = entry.getKey();
|
||||
int ny = v.y() - cy + 1;
|
||||
object.getBlocks().put(new IrisBlockVector(v.x(), ny, v.z()), entry.getValue());
|
||||
if (supportPositions.contains(v)) {
|
||||
roots.add(new TreeGrounding.Root(v.x(), ny, v.z(), entry.getValue()));
|
||||
}
|
||||
if (leafPositions.contains(v)) {
|
||||
canopy.add(new TreeBlockCanvas.Vec(v.x(), ny, v.z()));
|
||||
}
|
||||
}
|
||||
object.setTreeGrounding(TreeGrounding.create(roots, rootReach, canopy));
|
||||
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class TreeBlockResolver {
|
||||
private TreeBlockResolver() {
|
||||
}
|
||||
|
||||
public static NativeBlockState resolve(IrisProceduralTree tree, IrisData data, TreeBlockCanvas.Cell cell, TreeBlockCanvas.Vec pos, RNG paletteRng) {
|
||||
return switch (cell.role()) {
|
||||
case TRUNK -> finishTrunk(resolveBlock(tree.getTrunk(), tree.getTrunkPalette(), data, pos, paletteRng), cell);
|
||||
case SECONDARY_TRUNK -> {
|
||||
NativeBlockState state = resolveBlock(tree.getSecondaryTrunk(), tree.getSecondaryTrunkPalette(), data, pos, paletteRng);
|
||||
if (state == null) {
|
||||
state = resolveBlock(tree.getTrunk(), tree.getTrunkPalette(), data, pos, paletteRng);
|
||||
}
|
||||
yield finishTrunk(state, cell);
|
||||
}
|
||||
case LEAF -> resolveBlock(tree.getLeaves(), tree.getLeavesPalette(), data, pos, paletteRng);
|
||||
case SECONDARY_LEAF -> {
|
||||
NativeBlockState state = resolveSecondaryLeaf(tree, data, pos, paletteRng);
|
||||
if (state == null) {
|
||||
state = resolveBlock(tree.getLeaves(), tree.getLeavesPalette(), data, pos, paletteRng);
|
||||
}
|
||||
yield state;
|
||||
}
|
||||
case DECORATOR -> {
|
||||
int index = cell.decoratorIndex();
|
||||
if (index < 0 || tree.getDecorators() == null || index >= tree.getDecorators().size()) {
|
||||
yield null;
|
||||
}
|
||||
IrisTreeDecorator dec = tree.getDecorators().get(index);
|
||||
NativeBlockState state = resolveBlock(dec.getBlock(), dec.getPalette(), data, pos, paletteRng);
|
||||
if (state != null && cell.facing() != null && IrisProceduralBlocks.hasProperty(state, "facing")) {
|
||||
try {
|
||||
state = state.withProperty("facing", cell.facing().toLowerCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
yield state;
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private static NativeBlockState finishTrunk(NativeBlockState state, TreeBlockCanvas.Cell cell) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
if (cell.axis() != TreeBlockCanvas.Axis.NONE && IrisProceduralBlocks.hasProperty(state, "axis")) {
|
||||
try {
|
||||
state = state.withProperty("axis", cell.axis().name().toLowerCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
if (cell.exposed()) {
|
||||
return woodCap(state);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveSecondaryLeaf(IrisProceduralTree tree, IrisData data, TreeBlockCanvas.Vec pos, RNG paletteRng) {
|
||||
if (IrisProceduralBlocks.paletteSet(tree.getSecondaryLeavesPalette())) {
|
||||
return tree.getSecondaryLeavesPalette().get(paletteRng, pos.x(), pos.y(), pos.z(), data);
|
||||
}
|
||||
if (tree.getWeightedSecondaryLeaves() != null && !tree.getWeightedSecondaryLeaves().isEmpty()) {
|
||||
String picked = pickWeighted(tree, new RNG(tree.getSeed() ^ positionHash(pos)));
|
||||
return picked == null ? null : B.getStateOrNull(picked, false);
|
||||
}
|
||||
if (tree.getSecondaryLeaves() != null && !tree.getSecondaryLeaves().isEmpty()) {
|
||||
return B.getStateOrNull(tree.getSecondaryLeaves(), false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String pickWeighted(IrisProceduralTree tree, RNG rng) {
|
||||
long total = 0;
|
||||
for (IrisTreeSecondaryLeaf s : tree.getWeightedSecondaryLeaves()) {
|
||||
total += Math.max(0, s.getWeight());
|
||||
}
|
||||
if (total <= 0) {
|
||||
return null;
|
||||
}
|
||||
double r = rng.nextDouble() * total;
|
||||
long cumulative = 0;
|
||||
for (IrisTreeSecondaryLeaf s : tree.getWeightedSecondaryLeaves()) {
|
||||
cumulative += Math.max(0, s.getWeight());
|
||||
if (r < cumulative) {
|
||||
return s.getBlock();
|
||||
}
|
||||
}
|
||||
return tree.getWeightedSecondaryLeaves().get(tree.getWeightedSecondaryLeaves().size() - 1).getBlock();
|
||||
}
|
||||
|
||||
private static NativeBlockState resolveBlock(String block, IrisMaterialPalette palette, IrisData data, TreeBlockCanvas.Vec pos, RNG paletteRng) {
|
||||
if (IrisProceduralBlocks.paletteSet(palette)) {
|
||||
return palette.get(paletteRng, pos.x(), pos.y(), pos.z(), data);
|
||||
}
|
||||
if (block != null && !block.isEmpty()) {
|
||||
return B.getStateOrNull(block, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static NativeBlockState woodCap(NativeBlockState state) {
|
||||
String key = state.key();
|
||||
int bracket = key.indexOf('[');
|
||||
String base = bracket < 0 ? key : key.substring(0, bracket);
|
||||
String woodKey = null;
|
||||
if (base.endsWith("_log")) {
|
||||
woodKey = base.substring(0, base.length() - 4) + "_wood";
|
||||
} else if (base.endsWith("_stem")) {
|
||||
woodKey = base.substring(0, base.length() - 5) + "_hyphae";
|
||||
}
|
||||
if (woodKey == null) {
|
||||
return state;
|
||||
}
|
||||
NativeBlockState wood = B.getStateOrNull(woodKey, false);
|
||||
if (wood == null) {
|
||||
return state;
|
||||
}
|
||||
String axis = IrisProceduralBlocks.propertyValue(state, "axis");
|
||||
if (axis != null && IrisProceduralBlocks.hasProperty(wood, "axis")) {
|
||||
try {
|
||||
wood = wood.withProperty("axis", axis);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
return wood;
|
||||
}
|
||||
|
||||
private static long positionHash(TreeBlockCanvas.Vec pos) {
|
||||
return pos.x() * 73856093L ^ pos.y() * 19349663L ^ pos.z() * 83492791L;
|
||||
}
|
||||
}
|
||||
@@ -1,347 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class TreeCanopyBuilder {
|
||||
private TreeCanopyBuilder() {
|
||||
}
|
||||
|
||||
public static void build(TreeBlockCanvas canvas, IrisProceduralTree tree, int height, double[][] offsets,
|
||||
int branchStartY, long baseSeed, List<int[]> branchEndpoints) {
|
||||
IrisTreeCanopy canopy = tree.getCanopy();
|
||||
if (canopy == null) {
|
||||
canopy = new IrisTreeCanopy();
|
||||
}
|
||||
IrisTreeBranches branches = canopy.getBranches();
|
||||
|
||||
double[][] layers = resolveLayers(canopy, tree.getProfile(), height, branches != null);
|
||||
|
||||
if (branches != null) {
|
||||
if (layers.length > 0) {
|
||||
double[][] crown = new double[][]{layers[layers.length - 1]};
|
||||
volumeCanopy(canvas, tree, crown, canopy, baseSeed, offsets);
|
||||
}
|
||||
placeApexCap(canvas, tree, height, layers, offsets, baseSeed);
|
||||
branchCanopy(canvas, tree, height, branches, branchStartY, baseSeed, offsets, branchEndpoints);
|
||||
} else {
|
||||
volumeCanopy(canvas, tree, layers, canopy, baseSeed, offsets);
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeApexCap(TreeBlockCanvas canvas, IrisProceduralTree tree, int height, double[][] layers,
|
||||
double[][] offsets, long baseSeed) {
|
||||
int ocx = 0;
|
||||
int ocz = 0;
|
||||
if (offsets != null && offsets.length > 0) {
|
||||
ocx = (int) Math.round(offsets[offsets.length - 1][0]);
|
||||
ocz = (int) Math.round(offsets[offsets.length - 1][1]);
|
||||
}
|
||||
double maxR = 2;
|
||||
for (double[] layer : layers) {
|
||||
maxR = Math.max(maxR, layer[1]);
|
||||
}
|
||||
int capRadius = Math.max(2, Math.min(3, (int) Math.round(maxR * 0.35)));
|
||||
IrisTreeCanopy canopy = tree.getCanopy();
|
||||
IrisTreeLeafMode mode = canopy != null ? canopy.getMode() : IrisTreeLeafMode.TRIMMED;
|
||||
double density = canopy != null ? canopy.getLeafDensity() : 1.0;
|
||||
placeLeafCluster(canvas, tree, ocx, height - 1, ocz, capRadius, mode, density, baseSeed + 5555L);
|
||||
}
|
||||
|
||||
private static double[][] resolveLayers(IrisTreeCanopy canopy, IrisTreeProfile profile, int height, boolean branchDriven) {
|
||||
KList<IrisTreeLayer> explicit = canopy.getLayers();
|
||||
if (explicit != null && !explicit.isEmpty()) {
|
||||
double[][] out = new double[explicit.size()][2];
|
||||
for (int i = 0; i < explicit.size(); i++) {
|
||||
out[i][0] = explicit.get(i).getYOffset();
|
||||
out[i][1] = explicit.get(i).getRadius();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return TreeProfiles.presetLayers(profile, height, branchDriven);
|
||||
}
|
||||
|
||||
private static void volumeCanopy(TreeBlockCanvas canvas, IrisProceduralTree tree, double[][] layers,
|
||||
IrisTreeCanopy canopy, long baseSeed, double[][] offsets) {
|
||||
int ocx = 0;
|
||||
int ocz = 0;
|
||||
if (offsets != null && offsets.length > 0) {
|
||||
ocx = (int) Math.round(offsets[offsets.length - 1][0]);
|
||||
ocz = (int) Math.round(offsets[offsets.length - 1][1]);
|
||||
}
|
||||
|
||||
double startAngle = canopy.getStartAngle();
|
||||
double squish = canopy.getSquish();
|
||||
IrisTreeLeafMode mode = canopy.getMode();
|
||||
double leafDensity = canopy.getLeafDensity();
|
||||
|
||||
for (double[] layer : layers) {
|
||||
int yCenter = (int) Math.round(layer[0]);
|
||||
double radius = layer[1];
|
||||
int halfH = layerHalfHeight(radius, startAngle, squish);
|
||||
int downH = startAngle < 90.0
|
||||
? (int) Math.ceil(radius * Math.cos(Math.toRadians(startAngle)) * squish)
|
||||
: 0;
|
||||
int skirt = downH;
|
||||
|
||||
for (int y = yCenter - skirt; y <= yCenter + halfH; y++) {
|
||||
int dy = y - yCenter;
|
||||
double layerR;
|
||||
if (halfH > 0 && dy >= 0) {
|
||||
layerR = radius * Math.sqrt(Math.max(0.0, 1.0 - Math.pow(dy / (double) halfH, 2)));
|
||||
} else if (skirt > 0 && dy < 0) {
|
||||
layerR = radius * Math.sqrt(Math.max(0.0, 1.0 - Math.pow(dy / (double) skirt, 2)));
|
||||
} else {
|
||||
layerR = radius;
|
||||
}
|
||||
if (layerR < 0.5) {
|
||||
continue;
|
||||
}
|
||||
placeLeafDisc(canvas, tree, ocx, y, ocz, layerR, mode, leafDensity, baseSeed + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int layerHalfHeight(double radius, double startAngle, double squish) {
|
||||
if (startAngle >= 180.0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) Math.ceil(radius * squish);
|
||||
}
|
||||
|
||||
private static void placeLeafDisc(TreeBlockCanvas canvas, IrisProceduralTree tree, int cx, int cy, int cz,
|
||||
double radius, IrisTreeLeafMode mode, double density, long seed) {
|
||||
double sx = stretchX(tree);
|
||||
double sz = stretchZ(tree);
|
||||
RNG rng = new RNG(seed);
|
||||
int irx = (int) Math.ceil(radius * sx);
|
||||
int irz = (int) Math.ceil(radius * sz);
|
||||
for (int dx = -irx; dx <= irx; dx++) {
|
||||
for (int dz = -irz; dz <= irz; dz++) {
|
||||
double ddx = dx / sx;
|
||||
double ddz = dz / sz;
|
||||
double dist = Math.sqrt(ddx * ddx + ddz * ddz);
|
||||
boolean corner = Math.abs(dx) == irx && Math.abs(dz) == irz;
|
||||
if (!passesLeafTest(mode, dist, radius, density, rng, cx + dx, cy, cz + dz, seed, corner)) {
|
||||
continue;
|
||||
}
|
||||
canvas.setLeaf(cx + dx, cy, cz + dz, resolveLeaf(tree, rng));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeLeafCluster(TreeBlockCanvas canvas, IrisProceduralTree tree, int cx, int cy, int cz,
|
||||
int radius, IrisTreeLeafMode mode, double density, long seed) {
|
||||
double sx = stretchX(tree);
|
||||
double sz = stretchZ(tree);
|
||||
RNG rng = new RNG(seed);
|
||||
int irx = (int) Math.ceil(radius * sx);
|
||||
int irz = (int) Math.ceil(radius * sz);
|
||||
for (int dx = -irx; dx <= irx; dx++) {
|
||||
for (int dy = -radius; dy <= radius; dy++) {
|
||||
for (int dz = -irz; dz <= irz; dz++) {
|
||||
double ddx = dx / sx;
|
||||
double ddz = dz / sz;
|
||||
double dist = Math.sqrt(ddx * ddx + dy * dy + ddz * ddz);
|
||||
boolean corner = Math.abs(dx) == irx && Math.abs(dz) == irz;
|
||||
if (!passesLeafTest(mode, dist, radius, density, rng, cx + dx, cy + dy, cz + dz, seed, corner)) {
|
||||
continue;
|
||||
}
|
||||
canvas.setLeaf(cx + dx, cy + dy, cz + dz, resolveLeaf(tree, rng));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double stretchX(IrisProceduralTree tree) {
|
||||
IrisTreeCanopy c = tree.getCanopy();
|
||||
return c == null ? 1.0 : Math.max(0.1, c.getCrownStretchX());
|
||||
}
|
||||
|
||||
private static double stretchZ(IrisProceduralTree tree) {
|
||||
IrisTreeCanopy c = tree.getCanopy();
|
||||
return c == null ? 1.0 : Math.max(0.1, c.getCrownStretchZ());
|
||||
}
|
||||
|
||||
private static boolean passesLeafTest(IrisTreeLeafMode mode, double dist, double radius, double density,
|
||||
RNG rng, int wx, int wy, int wz, long seed, boolean corner) {
|
||||
switch (mode) {
|
||||
case TRIMMED -> {
|
||||
return !(dist > radius || corner);
|
||||
}
|
||||
case FILLED -> {
|
||||
return dist <= radius;
|
||||
}
|
||||
case DENSITY -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return rng.nextDouble() <= density * (1.0 - (dist / (radius + 1.0)));
|
||||
}
|
||||
case NOISE -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return TreeFunctions.valueNoise3D(wx, wy, wz, seed) <= density;
|
||||
}
|
||||
case HOLLOW -> {
|
||||
return dist <= radius && dist > radius - 1.0;
|
||||
}
|
||||
case GRADIENT -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return rng.nextDouble() <= density * Math.pow(1.0 - (dist / (radius + 1.0)), 2);
|
||||
}
|
||||
case CLUMPED -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return TreeFunctions.valueNoise3D(Math.floorDiv(wx, 2), Math.floorDiv(wy, 2), Math.floorDiv(wz, 2), seed) <= density;
|
||||
}
|
||||
case TATTERED -> {
|
||||
if (dist > radius || corner) {
|
||||
return false;
|
||||
}
|
||||
return !(dist > radius - 1.5 && rng.nextDouble() < 0.6);
|
||||
}
|
||||
case SPARSE -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return rng.nextDouble() <= density * 0.4;
|
||||
}
|
||||
default -> {
|
||||
return dist <= radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas.Role resolveLeaf(IrisProceduralTree tree, RNG rng) {
|
||||
boolean hasSecondary = IrisProceduralBlocks.paletteSet(tree.getSecondaryLeavesPalette())
|
||||
|| (tree.getWeightedSecondaryLeaves() != null && !tree.getWeightedSecondaryLeaves().isEmpty())
|
||||
|| (tree.getSecondaryLeaves() != null && !tree.getSecondaryLeaves().isEmpty());
|
||||
if (!hasSecondary || tree.getSecondaryLeafFraction() <= 0.0) {
|
||||
return TreeBlockCanvas.Role.LEAF;
|
||||
}
|
||||
if (rng.nextDouble() >= tree.getSecondaryLeafFraction()) {
|
||||
return TreeBlockCanvas.Role.LEAF;
|
||||
}
|
||||
return TreeBlockCanvas.Role.SECONDARY_LEAF;
|
||||
}
|
||||
|
||||
private static void branchCanopy(TreeBlockCanvas canvas, IrisProceduralTree tree, int height,
|
||||
IrisTreeBranches branches, int branchStartY, long baseSeed, double[][] offsets,
|
||||
List<int[]> branchEndpoints) {
|
||||
long branchSeed = baseSeed + 9999;
|
||||
RNG branchRng = new RNG(branchSeed);
|
||||
IrisTreeSubBranches sub = branches.getSubBranches();
|
||||
int depth = branches.getBranchDepth();
|
||||
int branchIndex = 0;
|
||||
|
||||
for (int y = Math.max(0, branchStartY); y < height; y++) {
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
double p = TreeFunctions.branchProbability(branches, t, branchSeed);
|
||||
if (branchRng.nextDouble() > p) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int ox = 0;
|
||||
int oz = 0;
|
||||
if (offsets != null && y < offsets.length) {
|
||||
ox = (int) Math.round(offsets[y][0]);
|
||||
oz = (int) Math.round(offsets[y][1]);
|
||||
}
|
||||
|
||||
double az = TreeFunctions.azimuthDegrees(branches.getAzimuthMode(), t, branchIndex, tree, branches.getAzimuth(), branchRng);
|
||||
branchIndex++;
|
||||
double branchLen = TreeFunctions.branchLength(branches, t);
|
||||
double effElevation = branches.isLeafStartUp() ? Math.max(0.0, branches.getElevation()) : branches.getElevation();
|
||||
int[] end = branchEndpoint(ox, y, oz, az, effElevation, branchLen);
|
||||
int[] tip = rasterizeBranch(canvas, ox, y, oz, end[0], end[1], end[2], branches.getSag());
|
||||
|
||||
if (branchEndpoints != null) {
|
||||
branchEndpoints.add(new int[]{tip[0], tip[1], tip[2], ox, oz});
|
||||
}
|
||||
placeLeafCluster(canvas, tree, tip[0], tip[1], tip[2], branches.getClusterRadius(),
|
||||
branches.getClusterMode(), branches.getClusterDensity(), branchSeed + y);
|
||||
|
||||
growSubBranches(canvas, tree, tip[0], tip[1], tip[2], az, effElevation, branchLen, sub, depth, branchSeed + y + 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
private static void growSubBranches(TreeBlockCanvas canvas, IrisProceduralTree tree, int ox, int oy, int oz,
|
||||
double az, double el, double len, IrisTreeSubBranches sub, int depth, long seed) {
|
||||
if (sub == null || depth <= 0) {
|
||||
return;
|
||||
}
|
||||
int count = Math.max(1, sub.getCount());
|
||||
for (int si = 0; si < count; si++) {
|
||||
double yawOffset = sub.getYawDelta() * (si - (count - 1) / 2.0);
|
||||
double subAz = az + yawOffset;
|
||||
double subEl = el + sub.getPitchDelta();
|
||||
double subLen = len * sub.getLengthScale();
|
||||
int[] end = branchEndpoint(ox, oy, oz, subAz, subEl, subLen);
|
||||
int[] tip = rasterizeBranch(canvas, ox, oy, oz, end[0], end[1], end[2], sub.getSag());
|
||||
placeLeafCluster(canvas, tree, tip[0], tip[1], tip[2], sub.getClusterRadius(),
|
||||
sub.getClusterMode(), sub.getClusterDensity(), seed + si * 131L);
|
||||
growSubBranches(canvas, tree, tip[0], tip[1], tip[2], subAz, subEl, subLen, sub, depth - 1, seed + si * 131L + 17L);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] branchEndpoint(int ox, int oy, int oz, double azimuthDeg, double elevationDeg, double length) {
|
||||
double azRad = Math.toRadians(azimuthDeg);
|
||||
double elRad = Math.toRadians(elevationDeg);
|
||||
double dx = length * Math.cos(elRad) * Math.sin(azRad);
|
||||
double dy = length * Math.sin(elRad);
|
||||
double dz = length * Math.cos(elRad) * Math.cos(azRad);
|
||||
return new int[]{ox + (int) Math.round(dx), oy + (int) Math.round(dy), oz + (int) Math.round(dz)};
|
||||
}
|
||||
|
||||
private static int[] rasterizeBranch(TreeBlockCanvas canvas, int ox, int oy, int oz, int ex, int ey, int ez, double sag) {
|
||||
int dx = ex - ox;
|
||||
int dy = ey - oy;
|
||||
int dz = ez - oz;
|
||||
double horizontal = Math.sqrt(dx * dx + dz * dz);
|
||||
double sagBlocks = sag * horizontal;
|
||||
int steps = Math.max(Math.max(Math.abs(dx), Math.abs(dz)),
|
||||
Math.max((int) (Math.abs(dy) + Math.ceil(sagBlocks)), 1));
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(dx, dy, dz);
|
||||
|
||||
int[] tip = new int[]{ox, oy, oz};
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
int x = (int) Math.round(ox + dx * t);
|
||||
int y = (int) Math.round(oy + dy * t - sagBlocks * t * t);
|
||||
int z = (int) Math.round(oz + dz * t);
|
||||
TreeBlockCanvas.Cell existing = canvas.get(x, y, z);
|
||||
if (existing == null || existing.role() == TreeBlockCanvas.Role.LEAF
|
||||
|| existing.role() == TreeBlockCanvas.Role.SECONDARY_LEAF) {
|
||||
canvas.setTrunk(x, y, z, TreeBlockCanvas.Role.TRUNK, axis);
|
||||
}
|
||||
tip = new int[]{x, y, z};
|
||||
}
|
||||
return tip;
|
||||
}
|
||||
}
|
||||
-307
@@ -1,307 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class TreeDecoratorApplier {
|
||||
private TreeDecoratorApplier() {
|
||||
}
|
||||
|
||||
public static void apply(TreeBlockCanvas canvas, IrisProceduralTree tree, long baseSeed, List<int[]> branchEndpoints) {
|
||||
KList<IrisTreeDecorator> decorators = tree.getDecorators();
|
||||
if (decorators == null || decorators.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RNG rng = new RNG(baseSeed + 77777L);
|
||||
|
||||
for (int idx = 0; idx < decorators.size(); idx++) {
|
||||
IrisTreeDecorator dec = decorators.get(idx);
|
||||
boolean hasBlock = (dec.getBlock() != null && !dec.getBlock().isEmpty()) || IrisProceduralBlocks.paletteSet(dec.getPalette());
|
||||
if (!hasBlock) {
|
||||
continue;
|
||||
}
|
||||
switch (dec.getTarget()) {
|
||||
case BRANCH_TIP -> branchTip(canvas, dec, idx, branchEndpoints, rng);
|
||||
case TRUNK_SURFACE -> trunkSurface(canvas, dec, idx, rng);
|
||||
case CANOPY_TOP -> canopyTop(canvas, dec, idx, rng);
|
||||
case CANOPY_BOTTOM -> canopyBottom(canvas, dec, idx, rng);
|
||||
case TRUNK_BASE -> trunkBase(canvas, dec, idx, rng);
|
||||
case LEAF_SURFACE -> leafSurface(canvas, dec, idx, rng);
|
||||
case CANOPY_HANG -> canopyHang(canvas, dec, idx, rng);
|
||||
case BRANCH_SURFACE -> branchSurface(canvas, dec, idx, rng);
|
||||
case TRUNK_TOP -> trunkTop(canvas, dec, idx, rng);
|
||||
case GROUND_SCATTER -> groundScatter(canvas, dec, idx, rng);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void branchTip(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, List<int[]> branchEndpoints, RNG rng) {
|
||||
if (branchEndpoints == null) {
|
||||
return;
|
||||
}
|
||||
for (int[] e : branchEndpoints) {
|
||||
if (rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
int dx = e[0] - e[3];
|
||||
int dz = e[2] - e[4];
|
||||
boolean alongX = Math.abs(dx) >= Math.abs(dz);
|
||||
int stepX = alongX ? (dx >= 0 ? 1 : -1) : 0;
|
||||
int stepZ = alongX ? 0 : (dz >= 0 ? 1 : -1);
|
||||
int x = e[0] + stepX;
|
||||
int z = e[2] + stepZ;
|
||||
TreeBlockCanvas.Cell cell = canvas.get(x, e[1], z);
|
||||
while (cell != null && cell.role() != TreeBlockCanvas.Role.DECORATOR) {
|
||||
x += stepX;
|
||||
z += stepZ;
|
||||
cell = canvas.get(x, e[1], z);
|
||||
}
|
||||
if (cell != null) {
|
||||
continue;
|
||||
}
|
||||
String facing = dec.isAxisAware() ? facingAway(e[3], e[4], e[0], e[2]) : null;
|
||||
canvas.setDecor(x, e[1], z, idx, facing);
|
||||
}
|
||||
}
|
||||
|
||||
private static void trunkSurface(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
int[][] sides = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
String[] facings = {"east", "west", "south", "north"};
|
||||
for (TreeBlockCanvas.Vec v : sortedPositions(canvas.getTrunk())) {
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
int nx = v.x() + sides[i][0];
|
||||
int nz = v.z() + sides[i][1];
|
||||
if (canvas.has(nx, v.y(), nz) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(nx, v.y(), nz, idx, dec.isAxisAware() ? facings[i] : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void leafSurface(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
int[][] sides = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
String[] facings = {"east", "west", "south", "north"};
|
||||
for (TreeBlockCanvas.Vec v : sortedPositions(canvas.getLeaf())) {
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
int nx = v.x() + sides[i][0];
|
||||
int nz = v.z() + sides[i][1];
|
||||
if (canvas.has(nx, v.y(), nz) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(nx, v.y(), nz, idx, dec.isAxisAware() ? facings[i] : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void branchSurface(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
for (TreeBlockCanvas.Vec v : sortedPositions(canvas.getTrunk())) {
|
||||
int ay = v.y() + 1;
|
||||
if (canvas.has(v.x(), ay, v.z()) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(v.x(), ay, v.z(), idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void canopyTop(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
KMap<Long, Integer> colTop = new KMap<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getCells().keySet()) {
|
||||
long key = pack(v.x(), v.z());
|
||||
Integer cur = colTop.get(key);
|
||||
if (cur == null || v.y() > cur) {
|
||||
colTop.put(key, v.y());
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Long, Integer> e : sortedColumns(colTop)) {
|
||||
int x = unpackX(e.getKey());
|
||||
int z = unpackZ(e.getKey());
|
||||
int aboveY = e.getValue() + 1;
|
||||
if (canvas.has(x, aboveY, z) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(x, aboveY, z, idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void canopyBottom(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
KMap<Long, Integer> colBottom = columnLeafBottoms(canvas);
|
||||
for (Map.Entry<Long, Integer> e : sortedColumns(colBottom)) {
|
||||
int x = unpackX(e.getKey());
|
||||
int z = unpackZ(e.getKey());
|
||||
int belowY = e.getValue() - 1;
|
||||
if (canvas.has(x, belowY, z) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(x, belowY, z, idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void canopyHang(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
int maxLen = Math.max(1, dec.getLength());
|
||||
KMap<Long, Integer> colBottom = columnLeafBottoms(canvas);
|
||||
for (Map.Entry<Long, Integer> e : sortedColumns(colBottom)) {
|
||||
if (rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
int x = unpackX(e.getKey());
|
||||
int z = unpackZ(e.getKey());
|
||||
int strand = rng.i(1, maxLen + 1);
|
||||
for (int k = 1; k <= strand; k++) {
|
||||
int yy = e.getValue() - k;
|
||||
if (canvas.has(x, yy, z)) {
|
||||
break;
|
||||
}
|
||||
canvas.setDecor(x, yy, z, idx, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void trunkBase(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
int[][] sides = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
|
||||
for (TreeBlockCanvas.Vec v : sortedPositions(canvas.getTrunk())) {
|
||||
if (v.y() != 0) {
|
||||
continue;
|
||||
}
|
||||
for (int[] side : sides) {
|
||||
int nx = v.x() + side[0];
|
||||
int nz = v.z() + side[1];
|
||||
if (canvas.has(nx, 0, nz) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(nx, 0, nz, idx, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void trunkTop(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
maxY = Math.max(maxY, v.y());
|
||||
}
|
||||
if (maxY == Integer.MIN_VALUE) {
|
||||
return;
|
||||
}
|
||||
for (TreeBlockCanvas.Vec v : sortedPositions(canvas.getTrunk())) {
|
||||
if (v.y() != maxY) {
|
||||
continue;
|
||||
}
|
||||
int aboveY = v.y() + 1;
|
||||
if (canvas.has(v.x(), aboveY, v.z()) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(v.x(), aboveY, v.z(), idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void groundScatter(TreeBlockCanvas canvas, IrisTreeDecorator dec, int idx, RNG rng) {
|
||||
double cx = 0;
|
||||
double cz = 0;
|
||||
int count = 0;
|
||||
double footprint = 1.0;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == 0) {
|
||||
cx += v.x();
|
||||
cz += v.z();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
cx /= count;
|
||||
cz /= count;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == 0) {
|
||||
footprint = Math.max(footprint, Math.hypot(v.x() - cx, v.z() - cz));
|
||||
}
|
||||
}
|
||||
int radius = (int) Math.ceil(footprint + 3.0);
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
if (Math.hypot(dx, dz) > radius) {
|
||||
continue;
|
||||
}
|
||||
int x = icx + dx;
|
||||
int z = icz + dz;
|
||||
if (canvas.has(x, 0, z) || rng.nextDouble() > dec.getChance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(x, 0, z, idx, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static KMap<Long, Integer> columnLeafBottoms(TreeBlockCanvas canvas) {
|
||||
KMap<Long, Integer> colBottom = new KMap<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getLeaf()) {
|
||||
long key = pack(v.x(), v.z());
|
||||
Integer cur = colBottom.get(key);
|
||||
if (cur == null || v.y() < cur) {
|
||||
colBottom.put(key, v.y());
|
||||
}
|
||||
}
|
||||
return colBottom;
|
||||
}
|
||||
|
||||
private static List<TreeBlockCanvas.Vec> sortedPositions(Collection<TreeBlockCanvas.Vec> positions) {
|
||||
List<TreeBlockCanvas.Vec> sorted = new ArrayList<>(positions);
|
||||
sorted.sort(null);
|
||||
return sorted;
|
||||
}
|
||||
|
||||
private static List<Map.Entry<Long, Integer>> sortedColumns(Map<Long, Integer> columns) {
|
||||
List<Map.Entry<Long, Integer>> sorted = new ArrayList<>(columns.entrySet());
|
||||
sorted.sort(Comparator.comparingLong(Map.Entry::getKey));
|
||||
return sorted;
|
||||
}
|
||||
|
||||
private static String facingAway(int cx, int cz, int x, int z) {
|
||||
int dx = x - cx;
|
||||
int dz = z - cz;
|
||||
if (Math.abs(dx) >= Math.abs(dz)) {
|
||||
return dx >= 0 ? "east" : "west";
|
||||
}
|
||||
return dz >= 0 ? "south" : "north";
|
||||
}
|
||||
|
||||
private static long pack(int x, int z) {
|
||||
return (((long) x) << 32) ^ (z & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
private static int unpackX(long key) {
|
||||
return (int) (key >> 32);
|
||||
}
|
||||
|
||||
private static int unpackZ(long key) {
|
||||
return (int) (key & 0xFFFFFFFFL);
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class TreeFunctions {
|
||||
private static final double GOLDEN_ANGLE = 137.50776405003785;
|
||||
|
||||
private TreeFunctions() {
|
||||
}
|
||||
|
||||
public static double trunkWidthMultiplier(IrisProceduralTree tree, double t) {
|
||||
double start = tree.getShapeStart();
|
||||
double end = tree.getShapeEnd();
|
||||
return switch (tree.getTrunkShape()) {
|
||||
case CONSTANT -> 1.0;
|
||||
case LINEAR -> start + (end - start) * t;
|
||||
case SIGMOID -> 1.0 / (1.0 + Math.exp(tree.getShapeSteepness() * (t - 0.5)));
|
||||
case LOG -> {
|
||||
double base = Math.max(1.0001, tree.getShapeBase());
|
||||
if (t <= 0.0) {
|
||||
yield 1.0;
|
||||
}
|
||||
yield Math.max(0.0, 1.0 - Math.log(1.0 + t * (base - 1.0)) / Math.log(base));
|
||||
}
|
||||
case SINE -> {
|
||||
double period = tree.getShapePeriod() == 0 ? 1.0 : tree.getShapePeriod();
|
||||
yield 1.0 + tree.getShapeAmplitude() * Math.sin(2.0 * Math.PI * t / period);
|
||||
}
|
||||
case PARABOLIC -> {
|
||||
double peak = tree.getShapePeakOffset();
|
||||
double floor = tree.getShapeFloor();
|
||||
double denom = Math.pow(Math.max(peak, 1.0 - peak), 2);
|
||||
if (denom == 0) {
|
||||
denom = 1;
|
||||
}
|
||||
yield floor + (1.0 - floor) * (Math.pow(t - peak, 2) / denom);
|
||||
}
|
||||
case EXPONENTIAL -> geometric(start, end, t);
|
||||
case SQRT -> start + (end - start) * Math.sqrt(t);
|
||||
case STEP -> t < tree.getShapePeakOffset() ? start : end;
|
||||
case BELL -> start + (end - start) * bell(t);
|
||||
case EASE_IN_OUT -> start + (end - start) * smoothstep(t);
|
||||
};
|
||||
}
|
||||
|
||||
public static double curveProgress(IrisTreeFunction fn, double t, double steepness) {
|
||||
return switch (fn) {
|
||||
case LINEAR, CONSTANT, SINE -> t;
|
||||
case LOG -> Math.log(1.0 + t * (Math.E - 1.0));
|
||||
case SIGMOID -> 1.0 / (1.0 + Math.exp(-steepness * (t - 0.5)));
|
||||
case PARABOLIC, EASE_IN_OUT -> smoothstep(t);
|
||||
case EXPONENTIAL -> Math.pow(t, Math.max(1.0, steepness));
|
||||
case SQRT -> Math.sqrt(t);
|
||||
case STEP -> t < 0.5 ? 0.0 : 1.0;
|
||||
case BELL -> bell(t);
|
||||
};
|
||||
}
|
||||
|
||||
public static double branchLength(IrisTreeBranches b, double t) {
|
||||
double base = b.getLengthBase();
|
||||
double crown = b.getLengthCrown();
|
||||
double max = b.getLengthMax();
|
||||
double v = switch (b.getLengthFunction()) {
|
||||
case CONSTANT -> b.getLengthConstant();
|
||||
case LINEAR, SINE -> base + (crown - base) * t;
|
||||
case SIGMOID -> max / (1.0 + Math.exp(-b.getLengthSteepness() * (t - 0.5)));
|
||||
case LOG -> max * Math.log(1.0 + t * (Math.E - 1.0));
|
||||
case PARABOLIC -> max * (1.0 - Math.pow(2.0 * t - 1.0, 2));
|
||||
case EXPONENTIAL -> geometric(base, crown, t);
|
||||
case SQRT -> base + (crown - base) * Math.sqrt(t);
|
||||
case STEP -> t < 0.5 ? base : crown;
|
||||
case BELL -> base + (max - base) * bell(t);
|
||||
case EASE_IN_OUT -> base + (crown - base) * smoothstep(t);
|
||||
};
|
||||
return Math.max(1.0, v);
|
||||
}
|
||||
|
||||
public static double branchProbability(IrisTreeBranches b, double t, long seed) {
|
||||
double std = Math.max(b.getProbabilityStd(), 1e-6);
|
||||
return switch (b.getProbabilityFunction()) {
|
||||
case CONSTANT -> b.getProbabilityConstant();
|
||||
case LINEAR -> b.getProbabilityBase() + (b.getProbabilityCrown() - b.getProbabilityBase()) * t;
|
||||
case SIGMOID -> 1.0 / (1.0 + Math.exp(-b.getProbabilitySteepness() * (t - b.getProbabilityMidpoint())));
|
||||
case TOP_HEAVY -> Math.pow(t, b.getProbabilityExponent());
|
||||
case GAUSSIAN -> Math.exp(-0.5 * Math.pow((t - b.getProbabilityMean()) / std, 2));
|
||||
case NOISE -> valueNoise1D(t * b.getProbabilityScale(), seed);
|
||||
case BOTTOM_HEAVY -> Math.pow(1.0 - t, b.getProbabilityExponent());
|
||||
case PERIODIC -> b.getProbabilityConstant() * Math.pow(Math.max(0.0, Math.sin(2.0 * Math.PI * t * b.getProbabilityPeriods())), 8);
|
||||
case BAND -> Math.abs(t - b.getProbabilityMean()) <= b.getProbabilityStd() ? b.getProbabilityConstant() : 0.0;
|
||||
case INVERSE_GAUSSIAN -> b.getProbabilityConstant() * (1.0 - Math.exp(-0.5 * Math.pow((t - b.getProbabilityMean()) / std, 2)));
|
||||
case EXPONENTIAL_DECAY -> b.getProbabilityConstant() * Math.exp(-b.getProbabilityExponent() * t);
|
||||
};
|
||||
}
|
||||
|
||||
public static double azimuthDegrees(IrisTreeAzimuthMode mode, double t, int index, IrisProceduralTree tree, double constantBase, RNG rng) {
|
||||
return switch (mode) {
|
||||
case CONSTANT -> constantBase;
|
||||
case LINEAR -> tree.getAzimuthStart() + (tree.getAzimuthEnd() - tree.getAzimuthStart()) * t;
|
||||
case SPIRAL -> tree.getAzimuthStart() + tree.getAzimuthTurns() * 360.0 * t;
|
||||
case SINE -> {
|
||||
double period = tree.getAzimuthPeriod() == 0 ? 1.0 : tree.getAzimuthPeriod();
|
||||
yield tree.getAzimuthOffset() + tree.getAzimuthAmplitude() * Math.sin(2.0 * Math.PI * t / period);
|
||||
}
|
||||
case NOISE -> noiseAzimuth(t, tree.getAzimuthScale(), tree.getSeed());
|
||||
case RANDOM -> rng != null ? rng.d(0.0, 360.0) : constantBase;
|
||||
case GOLDEN_ANGLE -> index >= 0 ? constantBase + index * GOLDEN_ANGLE : constantBase;
|
||||
case ALTERNATING -> index >= 0 ? constantBase + (index % 2) * 180.0 : constantBase;
|
||||
case WHORL -> {
|
||||
int count = Math.max(1, tree.getAzimuthWhorlCount());
|
||||
yield index >= 0 ? constantBase + (index % count) * (360.0 / count) : constantBase;
|
||||
}
|
||||
case ZIGZAG -> index >= 0 ? constantBase + ((index % 2 == 0) ? -tree.getAzimuthAmplitude() : tree.getAzimuthAmplitude()) : constantBase;
|
||||
};
|
||||
}
|
||||
|
||||
public static TreeBlockCanvas.Axis logAxis(double dx, double dy, double dz) {
|
||||
double ax = Math.abs(dx);
|
||||
double ay = Math.abs(dy) * 1.8;
|
||||
double az = Math.abs(dz);
|
||||
if (ay >= ax && ay >= az) {
|
||||
return TreeBlockCanvas.Axis.Y;
|
||||
}
|
||||
if (ax >= az) {
|
||||
return TreeBlockCanvas.Axis.X;
|
||||
}
|
||||
return TreeBlockCanvas.Axis.Z;
|
||||
}
|
||||
|
||||
private static double geometric(double a, double b, double t) {
|
||||
if (a <= 0.0 || b <= 0.0) {
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
return a * Math.pow(b / a, t);
|
||||
}
|
||||
|
||||
private static double bell(double t) {
|
||||
return Math.exp(-Math.pow(t - 0.5, 2) / (2.0 * 0.15 * 0.15));
|
||||
}
|
||||
|
||||
private static double smoothstep(double t) {
|
||||
return 3.0 * t * t - 2.0 * t * t * t;
|
||||
}
|
||||
|
||||
public static double noiseAzimuth(double t, double scale, long seed) {
|
||||
double a = valueNoise1D(t * scale, seed);
|
||||
double b = valueNoise1D(t * scale * 0.5, seed + 1);
|
||||
return ((a + b) / 2.0) * 360.0;
|
||||
}
|
||||
|
||||
public static double valueNoise1D(double x, long seed) {
|
||||
long h = mix(seed * 0x9E3779B97F4A7C15L + Math.round(x * 1000.0));
|
||||
return unit(h);
|
||||
}
|
||||
|
||||
public static double valueNoise3D(int x, int y, int z, long seed) {
|
||||
long h = mix(seed);
|
||||
h = mix(h + x * 0x9E3779B97F4A7C15L);
|
||||
h = mix(h + y * 0xC2B2AE3D27D4EB4FL);
|
||||
h = mix(h + z * 0x165667B19E3779F9L);
|
||||
return unit(h);
|
||||
}
|
||||
|
||||
private static long mix(long a) {
|
||||
a ^= (a >>> 33);
|
||||
a *= 0xff51afd7ed558ccdL;
|
||||
a ^= (a >>> 33);
|
||||
a *= 0xc4ceb9fe1a85ec53L;
|
||||
a ^= (a >>> 33);
|
||||
return a;
|
||||
}
|
||||
|
||||
private static double unit(long h) {
|
||||
return (h >>> 11) * 0x1.0p-53;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class TreePlausibility {
|
||||
private static final int MAX_DISTANCE = 7;
|
||||
private static final int[][] NEIGHBORS = {
|
||||
{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}
|
||||
};
|
||||
|
||||
private TreePlausibility() {
|
||||
}
|
||||
|
||||
public static void apply(Map<TreeBlockCanvas.Vec, NativeBlockState> resolved, Set<TreeBlockCanvas.Vec> trunkPositions,
|
||||
Set<TreeBlockCanvas.Vec> leafPositions, IrisProceduralTree tree) {
|
||||
Set<TreeBlockCanvas.Vec> realLeaves = new HashSet<>();
|
||||
for (TreeBlockCanvas.Vec v : leafPositions) {
|
||||
NativeBlockState state = resolved.get(v);
|
||||
if (state != null && IrisProceduralBlocks.hasProperty(state, "persistent") && IrisProceduralBlocks.hasProperty(state, "distance")) {
|
||||
realLeaves.add(v);
|
||||
}
|
||||
}
|
||||
if (realLeaves.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> distance = tree.isPlausible()
|
||||
? computeDistances(trunkPositions, realLeaves)
|
||||
: Map.of();
|
||||
|
||||
for (TreeBlockCanvas.Vec v : realLeaves) {
|
||||
NativeBlockState leaf = resolved.get(v);
|
||||
Integer d = distance.get(v);
|
||||
if (!tree.isPlausible()) {
|
||||
leaf = leaf.withProperty("persistent", "true").withProperty("distance", "1");
|
||||
} else if (d != null && d < MAX_DISTANCE) {
|
||||
leaf = leaf.withProperty("persistent", "false").withProperty("distance", String.valueOf(Math.max(1, d)));
|
||||
} else {
|
||||
leaf = leaf.withProperty("persistent", "true").withProperty("distance", String.valueOf(MAX_DISTANCE));
|
||||
}
|
||||
resolved.put(v, leaf);
|
||||
}
|
||||
}
|
||||
|
||||
static Map<TreeBlockCanvas.Vec, Integer> computeDistances(Set<TreeBlockCanvas.Vec> trunkPositions, Set<TreeBlockCanvas.Vec> realLeaves) {
|
||||
Map<TreeBlockCanvas.Vec, Integer> distance = new HashMap<>();
|
||||
ArrayDeque<TreeBlockCanvas.Vec> queue = new ArrayDeque<>();
|
||||
|
||||
for (TreeBlockCanvas.Vec v : realLeaves) {
|
||||
for (int[] n : NEIGHBORS) {
|
||||
if (trunkPositions.contains(new TreeBlockCanvas.Vec(v.x() + n[0], v.y() + n[1], v.z() + n[2]))) {
|
||||
distance.put(v, 1);
|
||||
queue.add(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
TreeBlockCanvas.Vec v = queue.poll();
|
||||
int d = distance.get(v);
|
||||
if (d >= MAX_DISTANCE) {
|
||||
continue;
|
||||
}
|
||||
for (int[] n : NEIGHBORS) {
|
||||
TreeBlockCanvas.Vec nv = new TreeBlockCanvas.Vec(v.x() + n[0], v.y() + n[1], v.z() + n[2]);
|
||||
if (!realLeaves.contains(nv)) {
|
||||
continue;
|
||||
}
|
||||
Integer existing = distance.get(nv);
|
||||
if (existing == null || existing > d + 1) {
|
||||
distance.put(nv, d + 1);
|
||||
queue.add(nv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distance;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
|
||||
public final class TreeProfiles {
|
||||
private TreeProfiles() {
|
||||
}
|
||||
|
||||
static double radiusScale(IrisTreeProfile profile) {
|
||||
return switch (profile) {
|
||||
case OAK, DARK_OAK, CHERRY -> 1.0;
|
||||
case BIRCH -> 0.7;
|
||||
case POPLAR -> 0.8;
|
||||
case SPRUCE -> 0.55;
|
||||
case JUNGLE -> 0.45;
|
||||
case ACACIA -> 0.6;
|
||||
case DARK_OAK_FLAT -> 1.25;
|
||||
case DARK_OAK_FLAT_WIDE -> 1.8;
|
||||
case PALM -> 0.5;
|
||||
case WILLOW -> 1.1;
|
||||
case COLUMNAR -> 0.35;
|
||||
case BUSH -> 1.3;
|
||||
case MEGA_SPRUCE -> 0.7;
|
||||
};
|
||||
}
|
||||
|
||||
static double[][] fractions(IrisTreeProfile profile) {
|
||||
return switch (profile) {
|
||||
case OAK -> new double[][]{{0.55, 0.6}, {0.65, 0.9}, {0.75, 1.0}, {0.85, 0.9}, {0.92, 0.65}, {0.98, 0.35}};
|
||||
case BIRCH -> new double[][]{{0.6, 0.45}, {0.7, 0.75}, {0.8, 0.85}, {0.88, 0.75}, {0.94, 0.45}, {0.99, 0.2}};
|
||||
case POPLAR -> new double[][]{{0.5, 0.35}, {0.62, 0.7}, {0.74, 1.0}, {0.84, 0.95}, {0.93, 0.65}, {1.0, 0.3}};
|
||||
case SPRUCE, MEGA_SPRUCE -> new double[][]{{0.3, 1.0}, {0.42, 0.85}, {0.54, 0.7}, {0.65, 0.55}, {0.75, 0.4}, {0.84, 0.25}, {0.91, 0.15}, {0.97, 0.05}};
|
||||
case JUNGLE -> new double[][]{{0.82, 0.4}, {0.88, 0.8}, {0.93, 1.0}, {0.97, 0.7}, {1.0, 0.3}};
|
||||
case ACACIA -> new double[][]{{0.9, 0.5}, {0.95, 0.8}, {0.99, 0.4}};
|
||||
case DARK_OAK -> new double[][]{{0.5, 0.7}, {0.62, 1.0}, {0.72, 1.0}, {0.82, 0.9}, {0.91, 0.6}, {0.97, 0.3}};
|
||||
case DARK_OAK_FLAT -> new double[][]{{0.74, 0.62}, {0.83, 1.0}, {0.92, 1.0}, {1.0, 0.6}};
|
||||
case DARK_OAK_FLAT_WIDE -> new double[][]{{0.74, 0.62}, {0.83, 1.0}, {0.92, 1.0}, {1.0, 0.62}};
|
||||
case CHERRY -> new double[][]{{0.5, 0.5}, {0.62, 0.9}, {0.74, 1.0}, {0.84, 1.0}, {0.92, 0.7}, {0.98, 0.4}};
|
||||
case PALM -> new double[][]{{0.92, 0.45}, {0.97, 0.9}, {1.0, 1.0}, {1.03, 0.6}};
|
||||
case WILLOW -> new double[][]{{0.55, 0.7}, {0.68, 1.0}, {0.8, 1.0}, {0.9, 0.85}, {0.97, 0.6}};
|
||||
case COLUMNAR -> new double[][]{{0.4, 0.6}, {0.55, 0.9}, {0.7, 1.0}, {0.82, 0.9}, {0.92, 0.7}, {0.98, 0.4}};
|
||||
case BUSH -> new double[][]{{0.25, 0.7}, {0.45, 1.0}, {0.65, 1.0}, {0.82, 0.8}, {0.95, 0.5}};
|
||||
};
|
||||
}
|
||||
|
||||
static double[][] presetLayers(IrisTreeProfile profile, int height, boolean branchDriven) {
|
||||
double scale = radiusScale(profile);
|
||||
int baseRadius = Math.max(3, (int) Math.round(height / 2.0 * scale));
|
||||
double[][] fractions = fractions(profile);
|
||||
|
||||
int crownExtra = branchDriven ? 0 : Math.max(2, height / 4);
|
||||
int yTop = (height - 1) + crownExtra;
|
||||
|
||||
double[][] layers = new double[fractions.length][2];
|
||||
for (int i = 0; i < fractions.length; i++) {
|
||||
int yOff = (int) Math.round(fractions[i][0] * yTop);
|
||||
double radius = Math.max(1.5, baseRadius * fractions[i][1]);
|
||||
layers[i][0] = yOff;
|
||||
layers[i][1] = radius;
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TreeRootBuilder {
|
||||
private TreeRootBuilder() {
|
||||
}
|
||||
|
||||
public static void build(TreeBlockCanvas canvas, IrisProceduralTree tree, int height, long baseSeed) {
|
||||
List<TreeBlockCanvas.Vec> cells = new ArrayList<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == 0) {
|
||||
cells.add(v);
|
||||
}
|
||||
}
|
||||
if (cells.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
cells.sort(TreeBlockCanvas.Vec::compareTo);
|
||||
|
||||
int depth = tree.getRootDepth() > 0 ? tree.getRootDepth() : autoDepth(height);
|
||||
RNG rng = new RNG(baseSeed ^ 0x5009L);
|
||||
|
||||
double cx = 0;
|
||||
double cz = 0;
|
||||
for (TreeBlockCanvas.Vec cell : cells) {
|
||||
cx += cell.x();
|
||||
cz += cell.z();
|
||||
}
|
||||
cx /= cells.size();
|
||||
cz /= cells.size();
|
||||
|
||||
double baseRadius = 1.0;
|
||||
for (TreeBlockCanvas.Vec cell : cells) {
|
||||
baseRadius = Math.max(baseRadius, Math.hypot(cell.x() - cx, cell.z() - cz) + 0.5);
|
||||
}
|
||||
double flare = tree.getRootFlare() > 0 ? tree.getRootFlare() : baseRadius + Math.max(0.75, baseRadius * 0.35);
|
||||
RootShape shape = new RootShape(cells, cx, cz, baseRadius, depth, flare);
|
||||
|
||||
IrisTreeRootStyle style = tree.getRootStyle();
|
||||
switch (style) {
|
||||
case TAPROOT -> taproot(canvas, shape);
|
||||
case BUTTRESS -> {
|
||||
taproot(canvas, shape);
|
||||
buttress(canvas, shape, rng);
|
||||
}
|
||||
case STILT -> {
|
||||
stilts(canvas, shape, height, rng);
|
||||
taproot(canvas, new RootShape(cells, cx, cz, baseRadius, Math.min(depth, 3), flare));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void taproot(TreeBlockCanvas canvas, RootShape shape) {
|
||||
TreeBlockCanvas.Vec center = nearestCell(shape.cells(), shape.centerX(), shape.centerZ());
|
||||
for (int k = 1; k <= shape.depth(); k++) {
|
||||
double fraction = k / (double) shape.depth();
|
||||
double keepRadius = shape.radius() * (1.0 - fraction);
|
||||
for (TreeBlockCanvas.Vec cell : shape.cells()) {
|
||||
if (Math.hypot(cell.x() - shape.centerX(), cell.z() - shape.centerZ()) <= keepRadius) {
|
||||
placeRoot(canvas, cell.x(), -k, cell.z(), TreeBlockCanvas.Axis.Y);
|
||||
}
|
||||
}
|
||||
placeRoot(canvas, center.x(), -k, center.z(), TreeBlockCanvas.Axis.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buttress(TreeBlockCanvas canvas, RootShape shape, RNG rng) {
|
||||
int legs = Math.max(3, Math.min(8, shape.cells().size() + 2));
|
||||
for (int leg = 0; leg < legs; leg++) {
|
||||
double angle = 2.0 * Math.PI * leg / legs + rng.d(-0.25, 0.25);
|
||||
double reach = shape.flare() * rng.d(0.8, 1.0);
|
||||
int x = (int) Math.round(shape.centerX() + reach * Math.cos(angle));
|
||||
int z = (int) Math.round(shape.centerZ() + reach * Math.sin(angle));
|
||||
int depth = legDepth(shape.depth(), leg, legs);
|
||||
TreeBlockCanvas.Vec start = nearestCell(shape.cells(), x, z);
|
||||
rasterizeRoot(canvas, start, new TreeBlockCanvas.Vec(x, -depth, z));
|
||||
}
|
||||
}
|
||||
|
||||
private static void stilts(TreeBlockCanvas canvas, RootShape shape, int height, RNG rng) {
|
||||
int stiltTop = Math.min(height - 1, Math.max(2, Math.min(7, (int) Math.round(0.25 * height))));
|
||||
List<TreeBlockCanvas.Vec> attachments = new ArrayList<>();
|
||||
for (TreeBlockCanvas.Vec cell : canvas.getTrunk()) {
|
||||
if (cell.y() == stiltTop) {
|
||||
attachments.add(cell);
|
||||
}
|
||||
}
|
||||
if (attachments.isEmpty()) {
|
||||
attachments.addAll(shape.cells());
|
||||
}
|
||||
attachments.sort(TreeBlockCanvas.Vec::compareTo);
|
||||
int props = Math.max(3, Math.min(8, shape.cells().size() + 2));
|
||||
for (int prop = 0; prop < props; prop++) {
|
||||
double angle = 2.0 * Math.PI * prop / props + rng.d(-0.25, 0.25);
|
||||
double reach = shape.flare() * rng.d(0.8, 1.0);
|
||||
int x = (int) Math.round(shape.centerX() + reach * Math.cos(angle));
|
||||
int z = (int) Math.round(shape.centerZ() + reach * Math.sin(angle));
|
||||
int depth = legDepth(Math.min(shape.depth(), 3), prop, props);
|
||||
TreeBlockCanvas.Vec start = nearestCell(attachments, x, z);
|
||||
rasterizeRoot(canvas, start, new TreeBlockCanvas.Vec(x, -depth, z));
|
||||
}
|
||||
}
|
||||
|
||||
private static int legDepth(int depth, int leg, int count) {
|
||||
return Math.max(1, (int) Math.round(depth * (0.55 + 0.45 * leg / Math.max(1, count - 1))));
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas.Vec nearestCell(List<TreeBlockCanvas.Vec> cells, double x, double z) {
|
||||
TreeBlockCanvas.Vec nearest = cells.getFirst();
|
||||
double distance = Double.POSITIVE_INFINITY;
|
||||
for (TreeBlockCanvas.Vec cell : cells) {
|
||||
double dx = cell.x() - x;
|
||||
double dz = cell.z() - z;
|
||||
double candidateDistance = dx * dx + dz * dz;
|
||||
if (candidateDistance < distance) {
|
||||
nearest = cell;
|
||||
distance = candidateDistance;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
private static void rasterizeRoot(TreeBlockCanvas canvas, TreeBlockCanvas.Vec start, TreeBlockCanvas.Vec end) {
|
||||
int dx = end.x() - start.x();
|
||||
int dy = end.y() - start.y();
|
||||
int dz = end.z() - start.z();
|
||||
int steps = Math.max(Math.max(Math.abs(dx), Math.abs(dy)), Math.max(Math.abs(dz), 1));
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(dx, dy, dz);
|
||||
int x = start.x();
|
||||
int y = start.y();
|
||||
int z = start.z();
|
||||
for (int i = 1; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
int nextX = (int) Math.round(start.x() + dx * t);
|
||||
int nextY = (int) Math.round(start.y() + dy * t);
|
||||
int nextZ = (int) Math.round(start.z() + dz * t);
|
||||
while (y != nextY) {
|
||||
y += Integer.signum(nextY - y);
|
||||
placeRoot(canvas, x, y, z, axis);
|
||||
}
|
||||
while (x != nextX) {
|
||||
x += Integer.signum(nextX - x);
|
||||
placeRoot(canvas, x, y, z, axis);
|
||||
}
|
||||
while (z != nextZ) {
|
||||
z += Integer.signum(nextZ - z);
|
||||
placeRoot(canvas, x, y, z, axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeRoot(TreeBlockCanvas canvas, int x, int y, int z, TreeBlockCanvas.Axis axis) {
|
||||
TreeBlockCanvas.Cell cell = canvas.get(x, y, z);
|
||||
if (cell == null || cell.role() != TreeBlockCanvas.Role.TRUNK && cell.role() != TreeBlockCanvas.Role.SECONDARY_TRUNK) {
|
||||
canvas.setTrunk(x, y, z, TreeBlockCanvas.Role.TRUNK, axis);
|
||||
}
|
||||
}
|
||||
|
||||
private static int autoDepth(int height) {
|
||||
return Math.max(2, Math.min(16, (int) Math.round(0.18 * height)));
|
||||
}
|
||||
|
||||
private record RootShape(List<TreeBlockCanvas.Vec> cells, double centerX, double centerZ,
|
||||
double radius, int depth, double flare) {
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class TreeSupport {
|
||||
private static final int LEGAL_DISTANCE = 6;
|
||||
private static final int REACH_GAP = 4;
|
||||
|
||||
private TreeSupport() {
|
||||
}
|
||||
|
||||
public static void ensureLeavesSupported(TreeBlockCanvas canvas, int maxTendrils) {
|
||||
for (int iter = 0; iter < maxTendrils; iter++) {
|
||||
Map<TreeBlockCanvas.Vec, Integer> dist = TreePlausibility.computeDistances(canvas.getTrunk(), canvas.getLeaf());
|
||||
|
||||
TreeBlockCanvas.Vec worstLeaf = null;
|
||||
TreeBlockCanvas.Vec worstWood = null;
|
||||
int worstGap = -1;
|
||||
|
||||
for (TreeBlockCanvas.Vec leaf : canvas.getLeaf()) {
|
||||
Integer d = dist.get(leaf);
|
||||
if (d != null && d <= LEGAL_DISTANCE) {
|
||||
continue;
|
||||
}
|
||||
TreeBlockCanvas.Vec nearest = null;
|
||||
int best = Integer.MAX_VALUE;
|
||||
for (TreeBlockCanvas.Vec wood : canvas.getTrunk()) {
|
||||
int cd = chebyshev(leaf, wood);
|
||||
if (cd < best || cd == best && nearest != null && wood.compareTo(nearest) < 0) {
|
||||
best = cd;
|
||||
nearest = wood;
|
||||
}
|
||||
}
|
||||
if (nearest != null && (best > worstGap
|
||||
|| best == worstGap && worstLeaf != null && leaf.compareTo(worstLeaf) < 0)) {
|
||||
worstGap = best;
|
||||
worstLeaf = leaf;
|
||||
worstWood = nearest;
|
||||
}
|
||||
}
|
||||
|
||||
if (worstLeaf == null) {
|
||||
return;
|
||||
}
|
||||
growTendril(canvas, worstWood, worstLeaf);
|
||||
}
|
||||
}
|
||||
|
||||
private static void growTendril(TreeBlockCanvas canvas, TreeBlockCanvas.Vec from, TreeBlockCanvas.Vec to) {
|
||||
int dx = to.x() - from.x();
|
||||
int dy = to.y() - from.y();
|
||||
int dz = to.z() - from.z();
|
||||
int length = Math.max(Math.max(Math.abs(dx), Math.abs(dy)), Math.max(Math.abs(dz), 1));
|
||||
int steps = Math.max(1, length - REACH_GAP);
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(dx, dy, dz);
|
||||
|
||||
for (int i = 1; i <= steps; i++) {
|
||||
double t = i / (double) length;
|
||||
int x = from.x() + (int) Math.round(dx * t);
|
||||
int y = from.y() + (int) Math.round(dy * t);
|
||||
int z = from.z() + (int) Math.round(dz * t);
|
||||
canvas.setTrunk(x, y, z, TreeBlockCanvas.Role.TRUNK, axis);
|
||||
}
|
||||
}
|
||||
|
||||
private static int chebyshev(TreeBlockCanvas.Vec a, TreeBlockCanvas.Vec b) {
|
||||
return Math.max(Math.max(Math.abs(a.x() - b.x()), Math.abs(a.y() - b.y())), Math.abs(a.z() - b.z()));
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralBlocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TreeTrunkBuilder {
|
||||
public record Limb(double[][] offsets, int branchStartY) {
|
||||
}
|
||||
|
||||
private TreeTrunkBuilder() {
|
||||
}
|
||||
|
||||
public static List<Limb> build(TreeBlockCanvas canvas, IrisProceduralTree tree, int height) {
|
||||
boolean hasSecondary = hasSecondaryTrunk(tree);
|
||||
double[][] mainOffsets = leanPath(tree, height);
|
||||
int forks = Math.max(1, tree.getTrunkForks());
|
||||
|
||||
List<Limb> limbs = new ArrayList<>();
|
||||
if (forks == 1) {
|
||||
placeColumn(canvas, tree, mainOffsets, height, 0, height - 1, hasSecondary);
|
||||
limbs.add(new Limb(mainOffsets, 0));
|
||||
markExposedEnds(canvas);
|
||||
return limbs;
|
||||
}
|
||||
|
||||
int forkY = Math.max(1, Math.min(height - 2, (int) Math.round(tree.getForkHeight() * (height - 1))));
|
||||
placeColumn(canvas, tree, mainOffsets, height, 0, forkY, hasSecondary);
|
||||
|
||||
double baseCx = mainOffsets[forkY][0];
|
||||
double baseCz = mainOffsets[forkY][1];
|
||||
double reachMax = (height - forkY) * Math.tan(Math.toRadians(tree.getForkAngle()));
|
||||
|
||||
for (int f = 0; f < forks; f++) {
|
||||
double az = Math.toRadians((360.0 / forks) * f);
|
||||
double[][] forkOffsets = new double[height][2];
|
||||
for (int y = 0; y <= forkY; y++) {
|
||||
forkOffsets[y][0] = mainOffsets[y][0];
|
||||
forkOffsets[y][1] = mainOffsets[y][1];
|
||||
}
|
||||
for (int y = forkY + 1; y < height; y++) {
|
||||
double p = (y - forkY) / (double) Math.max(1, height - 1 - forkY);
|
||||
double reach = reachMax * p;
|
||||
forkOffsets[y][0] = baseCx + reach * Math.sin(az);
|
||||
forkOffsets[y][1] = baseCz + reach * Math.cos(az);
|
||||
}
|
||||
placeColumn(canvas, tree, forkOffsets, height, forkY + 1, height - 1, hasSecondary);
|
||||
limbs.add(new Limb(forkOffsets, forkY));
|
||||
}
|
||||
|
||||
markExposedEnds(canvas);
|
||||
return limbs;
|
||||
}
|
||||
|
||||
private static double[][] leanPath(IrisProceduralTree tree, int height) {
|
||||
double[][] offsets = new double[height][2];
|
||||
for (int y = 0; y < height; y++) {
|
||||
double[] lean = leanOffset(tree, y, height);
|
||||
offsets[y][0] = lean[0];
|
||||
offsets[y][1] = lean[1];
|
||||
}
|
||||
return offsets;
|
||||
}
|
||||
|
||||
private static void placeColumn(TreeBlockCanvas canvas, IrisProceduralTree tree, double[][] offsets, int height,
|
||||
int yStart, int yEnd, boolean hasSecondary) {
|
||||
double prevCx = yStart > 0 ? offsets[yStart - 1][0] : 0.0;
|
||||
double prevCz = yStart > 0 ? offsets[yStart - 1][1] : 0.0;
|
||||
|
||||
for (int y = yStart; y <= yEnd; y++) {
|
||||
double cx = offsets[y][0];
|
||||
double cz = offsets[y][1];
|
||||
int w = widthAt(tree, y, height);
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(cx - prevCx, 1.0, cz - prevCz);
|
||||
TreeBlockCanvas.Role role = trunkRole(tree, hasSecondary, y, height);
|
||||
|
||||
for (int[] xz : squarePositions(cx, cz, w)) {
|
||||
canvas.setTrunk(xz[0], y, xz[1], role, axis);
|
||||
}
|
||||
|
||||
double shift = Math.hypot(cx - prevCx, cz - prevCz);
|
||||
if (shift > 1.0) {
|
||||
int steps = (int) Math.ceil(shift);
|
||||
for (int s = 1; s < steps; s++) {
|
||||
double tFill = s / (double) steps;
|
||||
double icx = prevCx + (cx - prevCx) * tFill;
|
||||
double icz = prevCz + (cz - prevCz) * tFill;
|
||||
int fillY = (int) Math.round(y - 1 + tFill);
|
||||
for (int[] xz : squarePositions(icx, icz, w)) {
|
||||
if (!canvas.has(xz[0], fillY, xz[1])) {
|
||||
canvas.setTrunk(xz[0], fillY, xz[1], role, axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prevCx = cx;
|
||||
prevCz = cz;
|
||||
}
|
||||
}
|
||||
|
||||
private static void markExposedEnds(TreeBlockCanvas canvas) {
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (!canvas.has(v.x(), v.y() + 1, v.z()) || !canvas.has(v.x(), v.y() - 1, v.z())) {
|
||||
canvas.markExposed(v.x(), v.y(), v.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int widthAt(IrisProceduralTree tree, int y, int height) {
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
double multiplier = TreeFunctions.trunkWidthMultiplier(tree, t);
|
||||
return Math.max(1, (int) Math.round(tree.getTrunkWidth() * multiplier));
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas.Role trunkRole(IrisProceduralTree tree, boolean hasSecondary, int y, int height) {
|
||||
if (!hasSecondary) {
|
||||
return TreeBlockCanvas.Role.TRUNK;
|
||||
}
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
if (tree.getSecondaryTrunkStart() <= t && t <= tree.getSecondaryTrunkEnd()) {
|
||||
return TreeBlockCanvas.Role.SECONDARY_TRUNK;
|
||||
}
|
||||
return TreeBlockCanvas.Role.TRUNK;
|
||||
}
|
||||
|
||||
private static boolean hasSecondaryTrunk(IrisProceduralTree tree) {
|
||||
if (IrisProceduralBlocks.paletteSet(tree.getSecondaryTrunkPalette())) {
|
||||
return true;
|
||||
}
|
||||
return tree.getSecondaryTrunk() != null && !tree.getSecondaryTrunk().isEmpty();
|
||||
}
|
||||
|
||||
private static double[] leanOffset(IrisProceduralTree tree, int y, int height) {
|
||||
if (tree.getLeanAngle() == 0.0 || height <= 1) {
|
||||
return new double[]{0.0, 0.0};
|
||||
}
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
double progress = TreeFunctions.curveProgress(tree.getTrunkCurve(), t, tree.getCurveSteepness());
|
||||
double maxReach = height * Math.tan(Math.toRadians(tree.getLeanAngle()));
|
||||
double reach = maxReach * progress;
|
||||
double azDeg = tree.getLeanAzimuthMode() == IrisTreeAzimuthMode.CONSTANT
|
||||
? tree.getLeanAzimuth()
|
||||
: TreeFunctions.azimuthDegrees(tree.getLeanAzimuthMode(), t, -1, tree, tree.getLeanAzimuth(), null);
|
||||
double azRad = Math.toRadians(azDeg);
|
||||
double dx = reach * Math.sin(azRad);
|
||||
double dz = reach * Math.cos(azRad);
|
||||
return new double[]{dx, dz};
|
||||
}
|
||||
|
||||
private static List<int[]> squarePositions(double cx, double cz, int width) {
|
||||
List<int[]> out = new ArrayList<>();
|
||||
if (width % 2 == 1) {
|
||||
int half = width / 2;
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
for (int dx = -half; dx <= half; dx++) {
|
||||
for (int dz = -half; dz <= half; dz++) {
|
||||
out.add(new int[]{icx + dx, icz + dz});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int ox = (int) Math.floor(cx) - width / 2 + 1;
|
||||
int oz = (int) Math.floor(cz) - width / 2 + 1;
|
||||
for (int dx = 0; dx < width; dx++) {
|
||||
for (int dz = 0; dz < width; dz++) {
|
||||
out.add(new int[]{ox + dx, oz + dz});
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static String stripState(String block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
int idx = block.indexOf('[');
|
||||
return idx < 0 ? block : block.substring(0, idx);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import art.arcane.iris.generation.runtime.UpperDimensionContext;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.structure.object.DecayControlPlacer;
|
||||
import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisAxisRotationClamp;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
@@ -42,16 +41,11 @@ import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.structure.object.IrisObjectVacuum;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisProceduralTree;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlan;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KSet;
|
||||
@@ -74,7 +68,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
@@ -272,7 +265,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
+ " regionCavePlacers=" + region.getCarvingObjects().size());
|
||||
}
|
||||
ObjectPlacementSummary summary = placeObjects(writer, rng, x, z, surfaceBiome, caveBiome, region, complex, traceRegen);
|
||||
placeProceduralObjects(writer, rng, x, z, surfaceBiome, caveBiome, region, complex);
|
||||
UpperDimensionContext upperCtx = getEngineMantle().getEngine().getUpperContext();
|
||||
IrisDimension dimension = getDimension();
|
||||
if (upperCtx != null && dimension.isUpperDimensionObjects()) {
|
||||
@@ -375,14 +367,12 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
private static boolean scanCollisionRules(IrisDimension dimension, DataProvider dataProvider) {
|
||||
for (IrisRegion region : dimension.getAllRegions(dataProvider)) {
|
||||
if (region != null && (hasCollisionRules(region.getObjects())
|
||||
|| hasCollisionRules(region.getProceduralObjects()))) {
|
||||
if (region != null && hasCollisionRules(region.getObjects())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(dataProvider)) {
|
||||
if (biome != null && (hasCollisionRules(biome.getObjects())
|
||||
|| hasCollisionRules(biome.getProceduralObjects()))) {
|
||||
if (biome != null && hasCollisionRules(biome.getObjects())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -406,18 +396,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|| !placement.getForbiddenCollisions().isEmpty());
|
||||
}
|
||||
|
||||
private static boolean hasCollisionRules(IrisProceduralObjects proceduralObjects) {
|
||||
if (proceduralObjects == null || proceduralObjects.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (IrisProceduralPlacement placement : proceduralObjects.getAllPlacements()) {
|
||||
if (placement != null && hasCollisionRules(placement.asPlacement())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private RNG applyNoise(int x, int z, long seed) {
|
||||
CNG noise = CNG.signatureFast(new RNG(seed), NoiseType.WHITE, NoiseType.GLOB);
|
||||
return new RNG((long) (seed * noise.noise(x, z)));
|
||||
@@ -608,214 +586,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
);
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void placeProceduralObjects(ObjectPassPlacer writer, RNG rng, int x, int z, IrisBiome surfaceBiome, IrisBiome caveBiome, IrisRegion region, IrisComplex complex) {
|
||||
IrisCaveProfile surfaceCaveProfile = resolveCaveProfile(surfaceBiome.getCaveProfile(), region.getCaveProfile());
|
||||
IrisCaveProfile regionCaveProfile = resolveCaveProfile(region.getCaveProfile(), caveBiome == null ? null : caveBiome.getCaveProfile());
|
||||
placeProceduralFrom(writer, rng, x, z, surfaceBiome.getProceduralObjects(), surfaceBiome.getName(), surfaceCaveProfile, surfaceBiome.getLoadKey());
|
||||
placeProceduralFrom(writer, rng, x, z, region.getProceduralObjects(), region.getName(), regionCaveProfile, null);
|
||||
if (caveBiome != null && caveBiome != surfaceBiome) {
|
||||
IrisCaveProfile caveProfile = resolveCaveProfile(caveBiome.getCaveProfile(), region.getCaveProfile());
|
||||
placeProceduralFrom(writer, rng, x, z, caveBiome.getProceduralObjects(), caveBiome.getName(), caveProfile, caveBiome.getLoadKey());
|
||||
}
|
||||
if (complex.getSubterrainPlanner() != null && !complex.getSubterrainPlanner().isEmpty()) {
|
||||
Set<String> placed = new HashSet<>();
|
||||
placed.add(surfaceBiome.getLoadKey());
|
||||
if (caveBiome != null) {
|
||||
placed.add(caveBiome.getLoadKey());
|
||||
}
|
||||
for (SubterrainPlan plan : complex.getSubterrainPlanner().plansForBounds(x << 4, z << 4, (x << 4) + 15, (z << 4) + 15)) {
|
||||
if (plan.biome().isEmpty() || !placed.add(plan.biome())) {
|
||||
continue;
|
||||
}
|
||||
IrisBiome featureBiome = getData().getBiomeLoader().load(plan.biome());
|
||||
if (featureBiome != null) {
|
||||
placeProceduralFrom(writer, rng, x, z, featureBiome.getProceduralObjects(), featureBiome.getName(),
|
||||
resolveCaveProfile(featureBiome.getCaveProfile(), region.getCaveProfile()), featureBiome.getLoadKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void placeProceduralFrom(
|
||||
ObjectPassPlacer writer,
|
||||
RNG rng,
|
||||
int x,
|
||||
int z,
|
||||
IrisProceduralObjects proceduralObjects,
|
||||
String scope,
|
||||
IrisCaveProfile caveProfile,
|
||||
String expectedCaveBiomeKey
|
||||
) {
|
||||
if (proceduralObjects == null || proceduralObjects.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
IrisComplex complex = getComplex();
|
||||
int blockX = x << 4;
|
||||
int blockZ = z << 4;
|
||||
boolean golden = GoldenDebugObjectPlacer.isGoldenDebugChunk(x, z);
|
||||
CaveAnchorCache caveAnchorCache = new CaveAnchorCache();
|
||||
for (IrisProceduralPlacement p : proceduralObjects.getAllPlacements()) {
|
||||
boolean treePlacement = p instanceof IrisProceduralTree;
|
||||
boolean chancePassed = passesProceduralChance(rng, p.getChance());
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug procedural chance: chunk=" + x + "," + z
|
||||
+ " scope=" + scope
|
||||
+ " placement=" + p.getName()
|
||||
+ " passed=" + chancePassed);
|
||||
}
|
||||
if (!chancePassed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IrisObjectPlacement placement = p.asPlacement();
|
||||
boolean carving = placement.getCarvingSupport() == CarvingMode.CARVING_ONLY;
|
||||
IrisCaveAnchorMode anchorMode = resolveAnchorMode(placement, caveProfile);
|
||||
if (placement.getMode() == ObjectPlaceMode.CEILING_HANG) {
|
||||
anchorMode = IrisCaveAnchorMode.CEILING;
|
||||
}
|
||||
int anchorScanStep = resolveAnchorScanStep(caveProfile);
|
||||
int minDepthBelowSurface = resolveObjectMinDepthBelowSurface(caveProfile);
|
||||
int anchorSearchAttempts = resolveAnchorSearchAttempts(caveProfile);
|
||||
IObjectPlacer basePlacer = p.isPlausible() ? new DecayControlPlacer(writer) : writer;
|
||||
IObjectPlacer placer = golden ? new GoldenDebugObjectPlacer(basePlacer, scope + "/" + p.getName()) : basePlacer;
|
||||
int density = Math.max(1, p.getDensity());
|
||||
for (int i = 0; i < density; i++) {
|
||||
CavePlacementAnchor caveAnchor = null;
|
||||
if (carving) {
|
||||
caveAnchor = findCavePlacementAnchor(
|
||||
writer,
|
||||
rng,
|
||||
blockX,
|
||||
blockZ,
|
||||
anchorMode,
|
||||
anchorScanStep,
|
||||
minDepthBelowSurface,
|
||||
anchorSearchAttempts,
|
||||
expectedCaveBiomeKey,
|
||||
placement.isUnderwater(),
|
||||
caveAnchorCache
|
||||
);
|
||||
}
|
||||
if (carving && caveAnchor == null) {
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug procedural cave anchor rejected: chunk=" + x + "," + z
|
||||
+ " placement=" + p.getName()
|
||||
+ " minDepthBelowSurface=" + minDepthBelowSurface);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
IrisObject variant = placement.scaleObject(rng, p.getVariantObject(getData(), rng, proceduralRoom(caveAnchor)), getDimension());
|
||||
if (variant == null) {
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug procedural pick: chunk=" + x + "," + z
|
||||
+ " placement=" + p.getName()
|
||||
+ " densityIndex=" + i
|
||||
+ " variant=null");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int xx = caveAnchor == null ? rng.i(blockX, blockX + 16) : caveAnchor.x();
|
||||
int zz = caveAnchor == null ? rng.i(blockZ, blockZ + 16) : caveAnchor.z();
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
if (golden) {
|
||||
KList<IrisObject> pool = p.getVariantObjects(getData());
|
||||
IrisLogging.debug("Goldendebug procedural pick: chunk=" + x + "," + z
|
||||
+ " placement=" + p.getName()
|
||||
+ " densityIndex=" + i
|
||||
+ " variant=" + variant.getLoadKey()
|
||||
+ " variantIndex=" + pool.indexOf(variant) + "/" + pool.size()
|
||||
+ " xx=" + xx
|
||||
+ " zz=" + zz
|
||||
+ " mode=" + placement.getMode()
|
||||
+ " carving=" + carving);
|
||||
}
|
||||
try {
|
||||
int placeResult = -1;
|
||||
CaveObjectPlacementTransaction.CommitResult commitResult = CaveObjectPlacementTransaction.CommitResult.EMPTY;
|
||||
int continuation = writer.beginObjectPlacement(placement.waterRule());
|
||||
if (carving) {
|
||||
int caveFloorY = caveAnchor.y();
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug procedural caveFloor: chunk=" + x + "," + z
|
||||
+ " placement=" + p.getName()
|
||||
+ " xx=" + xx
|
||||
+ " zz=" + zz
|
||||
+ " caveFloorY=" + caveFloorY);
|
||||
}
|
||||
IrisObjectPlacement effectivePlacement = resolveCavePlacement(placement, variant, caveProfile);
|
||||
ContainedPlacementResult contained = placeContainedCaveObject(
|
||||
placer,
|
||||
variant,
|
||||
xx,
|
||||
caveFloorY,
|
||||
zz,
|
||||
effectivePlacement,
|
||||
anchorMode == IrisCaveAnchorMode.FLOOR && effectivePlacement.getMode() != ObjectPlaceMode.CEILING_HANG
|
||||
? IrisObjectPlacementAlignment.FLOOR : IrisObjectPlacementAlignment.CENTER,
|
||||
minDepthBelowSurface,
|
||||
id,
|
||||
"procedural",
|
||||
treePlacement,
|
||||
rng
|
||||
);
|
||||
placeResult = contained.resultY();
|
||||
commitResult = contained.commitResult();
|
||||
} else {
|
||||
if (!allowsObjectPlacement(complex, variant, placement, xx, zz)) {
|
||||
continue;
|
||||
}
|
||||
String marker = placementMarker(variant, id, "procedural");
|
||||
placeResult = variant.place(xx, zz, placer, placement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
placer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
if (treePlacement && marker != null) {
|
||||
writeTreeMaterial(placer, b.getX(), b.getY(), b.getZ(), data);
|
||||
}
|
||||
}, null, getData());
|
||||
}
|
||||
if (placeResult >= 0 && (!carving || commitResult == CaveObjectPlacementTransaction.CommitResult.COMMITTED)) {
|
||||
writer.recordObjectPlacement(continuation);
|
||||
}
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug procedural result: chunk=" + x + "," + z
|
||||
+ " placement=" + p.getName()
|
||||
+ " variant=" + variant.getLoadKey()
|
||||
+ " xx=" + xx
|
||||
+ " zz=" + zz
|
||||
+ " resultY=" + placeResult
|
||||
+ " commit=" + commitResult);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.skipPlacement(e, "procedural object", p.getName(), x << 4, -1, z << 4, scope);
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SubterrainRoom proceduralRoom(CavePlacementAnchor anchor) {
|
||||
if (anchor == null) {
|
||||
return null;
|
||||
}
|
||||
SubterrainCell cell = getEngineMantle().getEngine().getSubterrainCell(anchor.x(), anchor.y(), anchor.z());
|
||||
return cell == null ? null : cell.room();
|
||||
}
|
||||
|
||||
static boolean passesProceduralChance(RNG rng, double chance) {
|
||||
if (chance <= 0.0) {
|
||||
return false;
|
||||
}
|
||||
if (chance >= 1.0) {
|
||||
return true;
|
||||
}
|
||||
return rng.chance(Math.max(0.0, Math.min(1.0, chance + rng.d(-0.005, 0.005))));
|
||||
}
|
||||
|
||||
private CavePlacementAnchor findCavePlacementAnchor(
|
||||
ObjectPassPlacer writer,
|
||||
RNG rng,
|
||||
@@ -1926,12 +1696,12 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
PlacementReach reach = PlacementReach.NONE;
|
||||
for (IrisRegion region : dimension.getAllRegions(dataProvider)) {
|
||||
if (region != null) {
|
||||
reach = reach.union(placements(region.getObjects())).union(procedural(region.getProceduralObjects()));
|
||||
reach = reach.union(placements(region.getObjects()));
|
||||
}
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(dataProvider)) {
|
||||
if (biome != null) {
|
||||
reach = reach.union(placements(biome.getObjects())).union(procedural(biome.getProceduralObjects()));
|
||||
reach = reach.union(placements(biome.getObjects()));
|
||||
}
|
||||
}
|
||||
return reach.withReadMargin(PlacementReach.supportReadMargin(dimension.getObjectSurfaceSupportBuffer()));
|
||||
@@ -2008,35 +1778,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
return reach;
|
||||
}
|
||||
|
||||
private PlacementReach procedural(IrisProceduralObjects procedural) {
|
||||
PlacementReach reach = PlacementReach.NONE;
|
||||
if (procedural == null || procedural.isEmpty()) {
|
||||
return reach;
|
||||
}
|
||||
for (IrisProceduralPlacement placement : procedural.getAllPlacements()) {
|
||||
if (placement == null) {
|
||||
continue;
|
||||
}
|
||||
KList<IrisObject> variants = placement.getVariantObjects(dataProvider.getData());
|
||||
if (variants == null) {
|
||||
continue;
|
||||
}
|
||||
IrisObjectPlacement objectPlacement = placement.asPlacement();
|
||||
KList<PlacementReach.Profile> profiles = profiles(objectPlacement);
|
||||
double scale = objectPlacement.getMaximumScale(dimension);
|
||||
for (IrisObject variant : variants) {
|
||||
if (variant == null) {
|
||||
continue;
|
||||
}
|
||||
PlacementReach.Extent extent = PlacementReach.Extent.of(variant).scaled(scale);
|
||||
for (PlacementReach.Profile profile : profiles) {
|
||||
reach = reach.union(profile.of(extent));
|
||||
}
|
||||
}
|
||||
}
|
||||
return reach;
|
||||
}
|
||||
|
||||
private KList<PlacementReach.Profile> profiles(IrisObjectPlacement placement) {
|
||||
KList<PlacementReach.Profile> profiles = new KList<>(PlacementReach.profile(placement));
|
||||
if (placement.getMode() != ObjectPlaceMode.CENTER_HEIGHT
|
||||
|
||||
@@ -24,22 +24,13 @@ import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.decoration.IrisEngineDecorator;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.M;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public final class GenerationCacheWarmer {
|
||||
private GenerationCacheWarmer() {
|
||||
@@ -50,7 +41,6 @@ public final class GenerationCacheWarmer {
|
||||
IrisData data = engine.getData();
|
||||
RNG root = new RNG(engine.getSeedManager().getComponent() + 7777L);
|
||||
int[] counter = {0};
|
||||
List<ProceduralWarmTask> proceduralTasks = new ArrayList<>();
|
||||
|
||||
KList<IrisBiome> biomes = engine.getAllBiomes();
|
||||
biomes.sort(Comparator.comparing(IrisBiome::getLoadKey));
|
||||
@@ -58,7 +48,6 @@ public final class GenerationCacheWarmer {
|
||||
warmPlacements(biome.getObjects(), root, counter, data, engine);
|
||||
warmDecorators(biome.getDecorators(), engine.getSeedManager().getComponent(), counter, data);
|
||||
warmOres(biome.getOres(), engine.getSeedManager().getTerrain(), counter, data);
|
||||
collectProcedural(biome.getProceduralObjects(), root, counter, proceduralTasks);
|
||||
}
|
||||
|
||||
KList<IrisRegion> regions = engine.getDimension().getAllRegions(engine);
|
||||
@@ -66,11 +55,9 @@ public final class GenerationCacheWarmer {
|
||||
for (IrisRegion region : regions) {
|
||||
warmPlacements(region.getObjects(), root, counter, data, engine);
|
||||
warmOres(region.getOres(), engine.getSeedManager().getTerrain(), counter, data);
|
||||
collectProcedural(region.getProceduralObjects(), root, counter, proceduralTasks);
|
||||
}
|
||||
|
||||
warmOres(engine.getDimension().getOres(), engine.getSeedManager().getTerrain(), counter, data);
|
||||
warmProcedural(proceduralTasks, data);
|
||||
|
||||
IrisLogging.debug("[IrisEngine timing] cache warm " + counter[0] + " configs=" + (M.ms() - start) + "ms");
|
||||
}
|
||||
@@ -118,94 +105,4 @@ public final class GenerationCacheWarmer {
|
||||
ore.warm(new RNG(terrainSeed), data);
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectProcedural(IrisProceduralObjects procedural, RNG root, int[] counter,
|
||||
List<ProceduralWarmTask> tasks) {
|
||||
if (procedural == null) {
|
||||
return;
|
||||
}
|
||||
for (IrisProceduralPlacement placement : procedural.getAllPlacements()) {
|
||||
if (placement != null) {
|
||||
tasks.add(new ProceduralWarmTask(placement, root.nextParallelRNG(counter[0]++)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void warmProcedural(List<ProceduralWarmTask> tasks, IrisData data) {
|
||||
if (tasks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
IdentityHashMap<IrisProceduralPlacement, List<ProceduralWarmTask>> identities = new IdentityHashMap<>();
|
||||
List<List<ProceduralWarmTask>> groups = new ArrayList<>();
|
||||
for (ProceduralWarmTask task : tasks) {
|
||||
List<ProceduralWarmTask> group = identities.get(task.placement());
|
||||
if (group == null) {
|
||||
group = new ArrayList<>();
|
||||
identities.put(task.placement(), group);
|
||||
groups.add(group);
|
||||
}
|
||||
group.add(task);
|
||||
}
|
||||
int workers = Math.min(groups.size(), Math.min(4, Runtime.getRuntime().availableProcessors()));
|
||||
if (workers == 1) {
|
||||
for (ProceduralWarmTask task : tasks) {
|
||||
task.placement().getVariantObject(data, task.rng(), null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Throwable failure = null;
|
||||
boolean interrupted = false;
|
||||
try (ExecutorService executor = Executors.newFixedThreadPool(workers, runnable -> {
|
||||
Thread thread = new Thread(runnable, "Iris-Procedural-Warm");
|
||||
thread.setDaemon(true);
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
return thread;
|
||||
})) {
|
||||
List<Future<?>> pending = new ArrayList<>(groups.size());
|
||||
for (List<ProceduralWarmTask> group : groups) {
|
||||
pending.add(executor.submit(() -> warmGroup(group, data)));
|
||||
}
|
||||
for (Future<?> future : pending) {
|
||||
boolean complete = false;
|
||||
while (!complete) {
|
||||
try {
|
||||
future.get();
|
||||
complete = true;
|
||||
} catch (InterruptedException exception) {
|
||||
interrupted = true;
|
||||
} catch (ExecutionException exception) {
|
||||
Throwable cause = exception.getCause();
|
||||
if (failure == null) {
|
||||
failure = cause;
|
||||
} else if (failure != cause) {
|
||||
failure.addSuppressed(cause);
|
||||
}
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if (failure instanceof Error error) {
|
||||
throw error;
|
||||
}
|
||||
if (failure instanceof RuntimeException exception) {
|
||||
throw exception;
|
||||
}
|
||||
if (failure != null) {
|
||||
throw new IllegalStateException("Procedural generation cache warming failed.", failure);
|
||||
}
|
||||
}
|
||||
|
||||
private static void warmGroup(List<ProceduralWarmTask> group, IrisData data) {
|
||||
for (ProceduralWarmTask task : group) {
|
||||
task.placement().getVariantObject(data, task.rng(), null);
|
||||
}
|
||||
}
|
||||
|
||||
record ProceduralWarmTask(IrisProceduralPlacement placement, RNG rng) {
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import art.arcane.iris.generation.decoration.IrisDepositGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositVariant;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.pack.validation.CompatPools;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
@@ -111,8 +110,6 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
@ArrayType(min = 1, type = IrisObjectPlacement.class)
|
||||
@Description("Objects define what schematics (iob files) iris will place in this region")
|
||||
private KList<IrisObjectPlacement> objects = new KList<>();
|
||||
@Description("Procedural objects (trees, ruins, formations, coral, fungi, crystals) iris generates from scratch and places across this region")
|
||||
private IrisProceduralObjects proceduralObjects = new IrisProceduralObjects();
|
||||
@ArrayType(min = 1, type = IrisStructurePlacement.class)
|
||||
@Description("Structures define jigsaw or vanilla/datapack structures iris will place in this region")
|
||||
private KList<IrisStructurePlacement> structures = new KList<>();
|
||||
|
||||
-34
@@ -2,9 +2,6 @@ package art.arcane.iris.pack.datapack.export.compile.object;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisProceduralTree;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
@@ -23,7 +20,6 @@ import art.arcane.iris.pack.datapack.export.ir.JsonResource;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
@@ -59,7 +55,6 @@ public final class ObjectStage implements CompileStage {
|
||||
private static final class Run {
|
||||
private static final int MAX_STILT_BASES = 16;
|
||||
private static final String TREE_FOLDER = "trees/";
|
||||
private static final String PROCEDURAL_FOLDER = "procedural/";
|
||||
private static final String CAVE_SUFFIX = "_cave";
|
||||
|
||||
private final PackCompileContext context;
|
||||
@@ -75,7 +70,6 @@ public final class ObjectStage implements CompileStage {
|
||||
private final WideObjectStructures wide;
|
||||
private final StructureTemplateEncoder encoder = new StructureTemplateEncoder();
|
||||
private final Map<String, ObjectSource> sources = new HashMap<>();
|
||||
private final Map<IrisProceduralPlacement, IrisObjectPlacement> proceduralPlacements = new IdentityHashMap<>();
|
||||
private final Map<String, BakedVariant> baked = new HashMap<>();
|
||||
private final Map<IrisObjectPlacement, VariantPlanner.Plan> plans = new IdentityHashMap<>();
|
||||
private final Map<IrisObjectPlacement, List<ObjectTemplates>> templates = new IdentityHashMap<>();
|
||||
@@ -119,10 +113,8 @@ public final class ObjectStage implements CompileStage {
|
||||
IrisRegion region = regions.get(entry.getValue());
|
||||
LootCompiler.LootScope scope = new LootCompiler.LootScope(dimension, region, biome);
|
||||
List<IrisObjectPlacement> placements = new ArrayList<>(biome.getObjects());
|
||||
placements.addAll(procedural(biome.getProceduralObjects()));
|
||||
if (region != null) {
|
||||
placements.addAll(region.getObjects());
|
||||
placements.addAll(procedural(region.getProceduralObjects()));
|
||||
}
|
||||
for (IrisObjectPlacement placement : placements) {
|
||||
if (placement == null || placement.getPlace().isEmpty()) {
|
||||
@@ -143,32 +135,6 @@ public final class ObjectStage implements CompileStage {
|
||||
emit();
|
||||
}
|
||||
|
||||
private List<IrisObjectPlacement> procedural(IrisProceduralObjects objects) {
|
||||
if (objects == null || objects.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<IrisObjectPlacement> placements = new ArrayList<>();
|
||||
for (IrisProceduralPlacement placement : objects.getAllPlacements()) {
|
||||
placements.add(proceduralPlacements.computeIfAbsent(placement, this::procedural));
|
||||
}
|
||||
return placements;
|
||||
}
|
||||
|
||||
private IrisObjectPlacement procedural(IrisProceduralPlacement source) {
|
||||
IrisObjectPlacement placement = source.asPlacement();
|
||||
String folder = (source instanceof IrisProceduralTree ? TREE_FOLDER : "") + PROCEDURAL_FOLDER + source.getName() + "-";
|
||||
KList<String> keys = new KList<>();
|
||||
for (IrisObject variant : source.getVariantObjects(data)) {
|
||||
ObjectSource object = ObjectSource.of(variant, variant.getLoadKey(), diagnostics);
|
||||
String key = folder + ContentIds.hash(object.volume() + ";base=" + object.baseY()
|
||||
+ (object.roots().present() ? ";roots=" + object.roots() : ""));
|
||||
sources.putIfAbsent(key, object);
|
||||
keys.add(key);
|
||||
}
|
||||
placement.setPlace(keys);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private void place(String biomeId, IrisObjectPlacement placement, PlacementInput.Anchor anchor, LootCompiler.LootScope scope) {
|
||||
String name = name(placement, anchor);
|
||||
VariantPlanner.Plan plan = plans.computeIfAbsent(placement, ignored -> planner.plan(placement, name, diagnostics));
|
||||
|
||||
@@ -198,17 +198,9 @@ final class ModBiomeAdopter {
|
||||
for (String field : OVERRIDE_FIELDS) {
|
||||
json.remove(field);
|
||||
}
|
||||
if (!ownsVegetation) {
|
||||
return;
|
||||
if (ownsVegetation) {
|
||||
json.remove("objects");
|
||||
}
|
||||
json.remove("objects");
|
||||
JsonObject procedural = model.pack().snippet(json.get("proceduralObjects"), "procedural-objects");
|
||||
if (procedural == null) {
|
||||
return;
|
||||
}
|
||||
JsonObject withoutTrees = procedural.deepCopy();
|
||||
withoutTrees.remove("trees");
|
||||
json.add("proceduralObjects", withoutTrees);
|
||||
}
|
||||
|
||||
private boolean ownsVegetation(CatalogBiome biome, String namespace) {
|
||||
|
||||
@@ -234,7 +234,7 @@ final class CompatWalker {
|
||||
return isIrisObject(value.getClass()) && walkObject(value, path);
|
||||
}
|
||||
|
||||
/** An annotated block key that generates (procedural trees, formations, ...): the chain without a backup. */
|
||||
/** An annotated block key that generates (procedural objects, ...): the chain without a backup. */
|
||||
private void resolveBlockKey(String raw, String path) {
|
||||
ContentGate.BlockResolution resolution = gate.resolveBlock(raw);
|
||||
String key = normalizedKey(raw);
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DecayControlPlacer implements IObjectPlacer {
|
||||
private final IObjectPlacer delegate;
|
||||
|
||||
public DecayControlPlacer(IObjectPlacer delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return delegate.getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return delegate.getHighest(x, z, data, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState d) {
|
||||
delegate.set(x, y, z, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beginTreeCanopy(BlockPosition position) {
|
||||
return delegate.beginTreeCanopy(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endTreeCanopy() {
|
||||
delegate.endTreeCanopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBlockState get(int x, int y, int z) {
|
||||
return delegate.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return delegate.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return delegate.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return delegate.isSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return delegate.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return delegate.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return delegate.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData tile) {
|
||||
delegate.setTile(xx, yy, zz, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int xx, int yy, int zz, T data) {
|
||||
delegate.setData(xx, yy, zz, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int xx, int yy, int zz, Class<T> t) {
|
||||
return delegate.getData(xx, yy, zz, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return delegate.getEngine();
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,6 @@ enum MapView {
|
||||
Group.BLOCKS, null, KeyEvent.VK_P),
|
||||
OBJECTS("Objects", "Every object in the pack in 3D, with the blocks it is made of",
|
||||
Group.BLOCKS, null, KeyEvent.VK_O),
|
||||
PROCEDURAL("Procedural", "Trees, rock formations and more that Iris generates from settings, every variant in 3D",
|
||||
Group.BLOCKS, null, KeyEvent.VK_T),
|
||||
NOISE("Noise", "The pack's noise generators and Iris' built-in noise styles",
|
||||
Group.GENERATORS, null, KeyEvent.VK_N),
|
||||
IMAGE_MAPS("Image maps", "Terrain height, biomes or masks painted from a PNG, previewed and exported into the pack",
|
||||
@@ -82,7 +80,7 @@ enum MapView {
|
||||
}
|
||||
|
||||
/**
|
||||
* The tile renderer's mode for this view, or null for the 3D world, palette, object, procedural, noise and image map
|
||||
* The tile renderer's mode for this view, or null for the 3D world, palette, object, noise and image map
|
||||
* views, which draw themselves.
|
||||
*/
|
||||
TileType renderType() {
|
||||
|
||||
@@ -47,9 +47,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
/**
|
||||
@@ -59,6 +57,7 @@ import java.util.function.IntConsumer;
|
||||
public final class MapWindow implements MapCanvas.Listener {
|
||||
private static final String MAP_CARD = "map";
|
||||
private static final String PALETTES_CARD = "palettes";
|
||||
private static final String OBJECTS_CARD = "objects";
|
||||
private static final String NOISE_CARD = "noise";
|
||||
private static final String WORLD_CARD = "world";
|
||||
private static final String IMAGE_MAPS_CARD = "image maps";
|
||||
@@ -104,7 +103,7 @@ public final class MapWindow implements MapCanvas.Listener {
|
||||
private final BiomeExplorer biomeExplorer;
|
||||
|
||||
private NoiseExplorerGUI paletteExplorer;
|
||||
private final Map<MapView, ObjectExplorer> objectExplorers = new EnumMap<>(MapView.class);
|
||||
private ObjectExplorer objectExplorer;
|
||||
private NoiseExplorerGUI noiseExplorer;
|
||||
private JComponent noiseSidebar;
|
||||
private WorldExplorer worldExplorer;
|
||||
@@ -301,8 +300,8 @@ public final class MapWindow implements MapCanvas.Listener {
|
||||
showWorld();
|
||||
} else if (view == MapView.PALETTES) {
|
||||
showPalettes(previousView);
|
||||
} else if (view == MapView.OBJECTS || view == MapView.PROCEDURAL) {
|
||||
showObjectExplorer(view);
|
||||
} else if (view == MapView.OBJECTS) {
|
||||
showObjectExplorer();
|
||||
} else if (view == MapView.IMAGE_MAPS) {
|
||||
showImageMaps();
|
||||
} else {
|
||||
@@ -384,17 +383,19 @@ public final class MapWindow implements MapCanvas.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void showObjectExplorer(MapView view) {
|
||||
boolean firstOpen = !objectExplorers.containsKey(view);
|
||||
ObjectExplorer explorer = objectExplorers.computeIfAbsent(view, this::createObjectExplorer);
|
||||
private void showObjectExplorer() {
|
||||
boolean firstOpen = objectExplorer == null;
|
||||
if (firstOpen) {
|
||||
createObjectExplorer();
|
||||
}
|
||||
canvas.setActive(false);
|
||||
showControls(explorerControls);
|
||||
useSidebar(viewListAbove(explorer.browser()));
|
||||
useInspector(explorer.overview());
|
||||
showCard(view.name());
|
||||
useSidebar(viewListAbove(objectExplorer.browser()));
|
||||
useInspector(objectExplorer.overview());
|
||||
showCard(OBJECTS_CARD);
|
||||
EventQueue.invokeLater(() -> viewList.select(currentView));
|
||||
if (firstOpen) {
|
||||
explorer.open();
|
||||
objectExplorer.open();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,13 +435,11 @@ public final class MapWindow implements MapCanvas.Listener {
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectExplorer createObjectExplorer(MapView view) {
|
||||
ObjectSource source = view == MapView.PROCEDURAL ? new ProceduralObjectSource() : new PackObjectSource();
|
||||
ObjectExplorer explorer = new ObjectExplorer(start.engine(), start.worldId(), source);
|
||||
keepClearOfIsland(explorer::setCoveredLeftWidth);
|
||||
content.add(explorer.view(), view.name());
|
||||
statusBars.add(explorer.statusBar(), view.name());
|
||||
return explorer;
|
||||
private void createObjectExplorer() {
|
||||
objectExplorer = new ObjectExplorer(start.engine(), start.worldId(), new PackObjectSource());
|
||||
keepClearOfIsland(objectExplorer::setCoveredLeftWidth);
|
||||
content.add(objectExplorer.view(), OBJECTS_CARD);
|
||||
statusBars.add(objectExplorer.statusBar(), OBJECTS_CARD);
|
||||
}
|
||||
|
||||
private void showNoise() {
|
||||
@@ -599,7 +598,7 @@ public final class MapWindow implements MapCanvas.Listener {
|
||||
private void resetExplorerView() {
|
||||
switch (currentView) {
|
||||
case WORLD_3D -> worldExplorer.resetCamera();
|
||||
case OBJECTS, PROCEDURAL -> objectExplorers.get(currentView).resetCamera();
|
||||
case OBJECTS -> objectExplorer.resetCamera();
|
||||
case NOISE -> noiseExplorer.resetViewport();
|
||||
case PALETTES -> paletteExplorer.resetViewport();
|
||||
default -> {
|
||||
@@ -702,7 +701,9 @@ public final class MapWindow implements MapCanvas.Listener {
|
||||
if (paletteExplorer != null) {
|
||||
paletteExplorer.close();
|
||||
}
|
||||
objectExplorers.values().forEach(ObjectExplorer::close);
|
||||
if (objectExplorer != null) {
|
||||
objectExplorer.close();
|
||||
}
|
||||
if (noiseExplorer != null) {
|
||||
noiseExplorer.close();
|
||||
}
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.map;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.decoration.coral.IrisCoral;
|
||||
import art.arcane.iris.generation.decoration.crystal.IrisCrystal;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormation;
|
||||
import art.arcane.iris.generation.decoration.fungus.IrisFungus;
|
||||
import art.arcane.iris.generation.decoration.ruin.IrisRuin;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisProceduralTree;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
/**
|
||||
* The procedural objects the pack's biomes and regions bake, one entry per placement, filed under the biome or region
|
||||
* that declares it.
|
||||
*/
|
||||
final class ProceduralObjectSource implements ObjectSource {
|
||||
private static final int EMPTY_ICON_SIZE = 40;
|
||||
private static final String BIOME_FOLDER = "biomes";
|
||||
private static final String REGION_FOLDER = "regions";
|
||||
|
||||
private volatile Map<String, IrisProceduralPlacement> placementsByKey = Map.of();
|
||||
|
||||
@Override
|
||||
public String noun() {
|
||||
return "procedural object";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyState emptyState() {
|
||||
return new EmptyState(MapViewIcon.large(MapView.PROCEDURAL, EMPTY_ICON_SIZE), "No procedural objects yet",
|
||||
"Add trees, ruins, formations, coral, fungi or crystals to",
|
||||
"a biome's or region's proceduralObjects", "They appear here once the pack reloads.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> keys(IrisData data) {
|
||||
Map<String, IrisProceduralPlacement> byKey = new LinkedHashMap<>();
|
||||
for (String biomeKey : data.getBiomeLoader().getPossibleKeys()) {
|
||||
IrisBiome biome = data.getBiomeLoader().load(biomeKey, false);
|
||||
if (biome != null) {
|
||||
addPlacements(byKey, BIOME_FOLDER + "/" + biomeKey, biome.getProceduralObjects());
|
||||
}
|
||||
}
|
||||
for (String regionKey : data.getRegionLoader().getPossibleKeys()) {
|
||||
IrisRegion region = data.getRegionLoader().load(regionKey, false);
|
||||
if (region != null) {
|
||||
addPlacements(byKey, REGION_FOLDER + "/" + regionKey, region.getProceduralObjects());
|
||||
}
|
||||
}
|
||||
placementsByKey = byKey;
|
||||
return List.copyOf(byKey.keySet());
|
||||
}
|
||||
|
||||
// Placements keep their default name unless the pack renames them, so repeated names are numbered.
|
||||
private static void addPlacements(Map<String, IrisProceduralPlacement> byKey, String ownerFolder, IrisProceduralObjects objects) {
|
||||
if (objects == null) {
|
||||
return;
|
||||
}
|
||||
for (IrisProceduralPlacement placement : objects.getAllPlacements()) {
|
||||
if (placement == null) {
|
||||
continue;
|
||||
}
|
||||
String key = ownerFolder + "/" + placement.getName();
|
||||
for (int repeat = 2; byKey.containsKey(key); repeat++) {
|
||||
key = ownerFolder + "/" + placement.getName() + " " + repeat;
|
||||
}
|
||||
byKey.put(key, placement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IrisObject> variants(IrisData data, String key) {
|
||||
IrisProceduralPlacement placement = placementsByKey.get(key);
|
||||
return placement == null ? List.of() : List.copyOf(placement.getVariantObjects(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalLong seed(String key) {
|
||||
IrisProceduralPlacement placement = placementsByKey.get(key);
|
||||
return placement == null ? OptionalLong.empty() : OptionalLong.of(seedOf(placement));
|
||||
}
|
||||
|
||||
// Procedural objects are baked with their ground at height 0, which placement puts one block above the surface.
|
||||
@Override
|
||||
public OptionalInt groundY(IrisObject object) {
|
||||
return OptionalInt.of(1 - object.getH() / 2);
|
||||
}
|
||||
|
||||
// The pack's own seed reuses the variants world generation bakes.
|
||||
@Override
|
||||
public List<IrisObject> variants(IrisData data, String key, long seed) {
|
||||
IrisProceduralPlacement placement = placementsByKey.get(key);
|
||||
if (placement == null) {
|
||||
return List.of();
|
||||
}
|
||||
IrisProceduralPlacement baked = seedOf(placement) == seed ? placement : reseeded(data, placement, seed);
|
||||
return List.copyOf(baked.getVariantObjects(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBaked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// A fresh copy every run, since a placement keeps the variants it baked.
|
||||
@Override
|
||||
public BakeRun timeBake(IrisData data, String key, long seed) {
|
||||
IrisProceduralPlacement placement = placementsByKey.get(key);
|
||||
if (placement == null) {
|
||||
return null;
|
||||
}
|
||||
IrisProceduralPlacement copy = reseeded(data, placement, seed);
|
||||
long start = System.nanoTime();
|
||||
int variantCount = copy.getVariantObjects(data).size();
|
||||
return new BakeRun(System.nanoTime() - start, variantCount);
|
||||
}
|
||||
|
||||
private static IrisProceduralPlacement reseeded(IrisData data, IrisProceduralPlacement placement, long seed) {
|
||||
IrisProceduralPlacement copy = data.getGson().fromJson(data.getGson().toJson(placement), placement.getClass());
|
||||
switch (copy) {
|
||||
case IrisProceduralTree tree -> tree.setSeed(seed);
|
||||
case IrisRuin ruin -> ruin.setSeed(seed);
|
||||
case IrisFormation formation -> formation.setSeed(seed);
|
||||
case IrisCoral coral -> coral.setSeed(seed);
|
||||
case IrisFungus fungus -> fungus.setSeed(seed);
|
||||
case IrisCrystal crystal -> crystal.setSeed(seed);
|
||||
default -> throw new IllegalArgumentException("Unknown procedural object " + placement.getClass().getName());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static long seedOf(IrisProceduralPlacement placement) {
|
||||
return switch (placement) {
|
||||
case IrisProceduralTree tree -> tree.getSeed();
|
||||
case IrisRuin ruin -> ruin.getSeed();
|
||||
case IrisFormation formation -> formation.getSeed();
|
||||
case IrisCoral coral -> coral.getSeed();
|
||||
case IrisFungus fungus -> fungus.getSeed();
|
||||
case IrisCrystal crystal -> crystal.getSeed();
|
||||
default -> throw new IllegalArgumentException("Unknown procedural object " + placement.getClass().getName());
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,26 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementMarker;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisProceduralTree;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class TreeDefinitionIndex {
|
||||
private static final String PROCEDURAL_TREE_PREFIX = "procedural/tree/";
|
||||
|
||||
private final Set<String> explicitObjectKeys;
|
||||
private final Set<String> proceduralTreeKeys;
|
||||
|
||||
private TreeDefinitionIndex(Set<String> explicitObjectKeys, Set<String> proceduralTreeKeys) {
|
||||
private TreeDefinitionIndex(Set<String> explicitObjectKeys) {
|
||||
this.explicitObjectKeys = Set.copyOf(explicitObjectKeys);
|
||||
this.proceduralTreeKeys = Set.copyOf(proceduralTreeKeys);
|
||||
}
|
||||
|
||||
public static TreeDefinitionIndex build(Engine engine) {
|
||||
Set<String> explicitObjectKeys = new HashSet<>();
|
||||
Set<String> proceduralTreeKeys = new HashSet<>();
|
||||
|
||||
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
collectPlacements(region.getObjects(), explicitObjectKeys);
|
||||
collectProceduralTrees(region.getProceduralObjects(), proceduralTreeKeys);
|
||||
}
|
||||
|
||||
for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
@@ -39,10 +31,9 @@ public final class TreeDefinitionIndex {
|
||||
continue;
|
||||
}
|
||||
collectPlacements(biome.getObjects(), explicitObjectKeys);
|
||||
collectProceduralTrees(biome.getProceduralObjects(), proceduralTreeKeys);
|
||||
}
|
||||
|
||||
return new TreeDefinitionIndex(explicitObjectKeys, proceduralTreeKeys);
|
||||
return new TreeDefinitionIndex(explicitObjectKeys);
|
||||
}
|
||||
|
||||
public boolean isTreeMarker(String marker) {
|
||||
@@ -52,9 +43,6 @@ public final class TreeDefinitionIndex {
|
||||
}
|
||||
|
||||
String objectKey = decoded.objectKey();
|
||||
if (objectKey.startsWith(PROCEDURAL_TREE_PREFIX)) {
|
||||
return proceduralTreeKeys.contains(objectKey);
|
||||
}
|
||||
if (objectKey.startsWith("procedural/")) {
|
||||
return false;
|
||||
}
|
||||
@@ -79,19 +67,4 @@ public final class TreeDefinitionIndex {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectProceduralTrees(IrisProceduralObjects proceduralObjects, Set<String> objectKeys) {
|
||||
if (proceduralObjects == null || proceduralObjects.getTrees() == null) {
|
||||
return;
|
||||
}
|
||||
for (IrisProceduralTree tree : proceduralObjects.getTrees()) {
|
||||
if (tree == null || tree.getName() == null || tree.getName().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
int variants = Math.max(1, tree.getVariants());
|
||||
for (int index = 0; index < variants; index++) {
|
||||
objectKeys.add(tree.getVariantLoadKey(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<!-- Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M2.79289 13.7929L2.20711 13.2071C1.81658 12.8166 1.81658 12.1834 2.20711 11.7929L8.79289 5.20711C9.18342 4.81658 9.81658 4.81658 10.2071 5.20711L10.7929 5.79289C11.1834 6.18342 11.1834 6.81658 10.7929 7.20711L4.20711 13.7929C3.81658 14.1834 3.18342 14.1834 2.79289 13.7929Z" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M9.5 8.5L7.5 6.5" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M10.5 2.5V1.5" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M13.5 5.5H14.5M11.5 9.5L12.5 10.5M6.5 4.5L5.5 3.5" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 889 B |
@@ -1,7 +0,0 @@
|
||||
<!-- Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M2.79289 13.7929L2.20711 13.2071C1.81658 12.8166 1.81658 12.1834 2.20711 11.7929L8.79289 5.20711C9.18342 4.81658 9.81658 4.81658 10.2071 5.20711L10.7929 5.79289C11.1834 6.18342 11.1834 6.81658 10.7929 7.20711L4.20711 13.7929C3.81658 14.1834 3.18342 14.1834 2.79289 13.7929Z" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M9.5 8.5L7.5 6.5" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M10.5 2.5V1.5" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M13.5 5.5H14.5M11.5 9.5L12.5 10.5M6.5 4.5L5.5 3.5" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 889 B |
-1
@@ -121,7 +121,6 @@ public class IrisDecoratorSeedCohesionTest {
|
||||
when(biome.getLoadKey()).thenReturn("fixture");
|
||||
when(biome.getObjects()).thenReturn(new KList<>());
|
||||
when(biome.getOres()).thenReturn(new KList<>());
|
||||
when(biome.getProceduralObjects()).thenReturn(null);
|
||||
when(biome.getDecorators()).thenReturn(new KList<>(decorator));
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.SEA_FLOOR)).thenReturn(new IrisDecorator[]{decorator});
|
||||
placement = new IrisSeaFloorDecorator(engine);
|
||||
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.coral;
|
||||
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CoralGeneratorTest {
|
||||
@Test
|
||||
public void fanTipsFollowTheTopOfEachOccupiedColumn() {
|
||||
NativeBlockState structure = mock(NativeBlockState.class);
|
||||
NativeBlockState tip = mock(NativeBlockState.class);
|
||||
for (int height : new int[]{2, 7, 14}) {
|
||||
for (int width : new int[]{1, 3, 11}) {
|
||||
IrisCoral coral = new IrisCoral().setForm(IrisCoralForm.FAN)
|
||||
.setHeightMin(height).setHeightMax(height).setFanWidth(width)
|
||||
.setWaterlogged(false).setBlockPalette(palette(structure));
|
||||
IrisObject bare = CoralGenerator.generate(coral, 0, new RNG(0L), null);
|
||||
Map<Integer, Integer> tops = new HashMap<>();
|
||||
Set<IrisBlockVector> barePositions = new HashSet<>();
|
||||
for (IrisBlockVector position : bare.getBlocks().keys()) {
|
||||
barePositions.add(position);
|
||||
tops.merge(position.getBlockX(), position.getBlockY(), Math::max);
|
||||
}
|
||||
coral.setTipPalette(palette(tip));
|
||||
for (double chance : new double[]{0.0, 0.35, 1.0}) {
|
||||
coral.setTipChance(chance);
|
||||
for (long seed = 0; seed < 16; seed++) {
|
||||
IrisObject decorated = CoralGenerator.generate(coral, 0, new RNG(seed), null);
|
||||
Set<IrisBlockVector> positions = new HashSet<>();
|
||||
int tipCount = 0;
|
||||
for (IrisBlockVector position : decorated.getBlocks().keys()) {
|
||||
positions.add(position);
|
||||
if (decorated.getBlocks().get(position) == tip) {
|
||||
assertTrue("Fan tip must occupy an existing column", tops.containsKey(position.getBlockX()));
|
||||
assertEquals(tops.get(position.getBlockX()).intValue(), position.getBlockY());
|
||||
tipCount++;
|
||||
}
|
||||
}
|
||||
assertEquals(barePositions, positions);
|
||||
if (chance == 1.0) {
|
||||
assertEquals(tops.size(), tipCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IrisMaterialPalette palette(NativeBlockState state) {
|
||||
IrisBlockData block = mock(IrisBlockData.class);
|
||||
when(block.getWeight()).thenReturn(1);
|
||||
when(block.getBlockData(null)).thenReturn(state);
|
||||
return new IrisMaterialPalette().setPalette(new KList<>(block));
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.generation.subterrain.IrisSubterrainFamily;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ContextualFormationTest {
|
||||
@Test
|
||||
public void roomVaultSizesFormationAfterAnchorWithoutUsingOrdinaryHeightRange() {
|
||||
IrisFormation formation = new IrisFormation().setName("vault-spire").setRoomHeightFraction(0.5)
|
||||
.setHeightMin(80).setHeightMax(80).setBaseWidthMin(2).setBaseWidthMax(2)
|
||||
.setRoughness(0).setLean(0);
|
||||
NativeBlockState rock = mock(NativeBlockState.class);
|
||||
when(rock.key()).thenReturn("minecraft:stone");
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getStateOrNull("minecraft:stone", false)).thenReturn(rock);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisObject shortRoom = formation.getVariantObject(data, new RNG(143L), room(12));
|
||||
IrisObject tallRoom = formation.getVariantObject(data, new RNG(143L), room(40));
|
||||
IrisObject repeat = formation.getVariantObject(data, new RNG(143L), room(40));
|
||||
assertNotNull(shortRoom);
|
||||
assertNotNull(tallRoom);
|
||||
assertTrue(shortRoom.getH() <= 12);
|
||||
assertTrue(tallRoom.getH() <= 40);
|
||||
assertTrue(tallRoom.getH() > shortRoom.getH());
|
||||
assertNotNull(repeat);
|
||||
assertEquals(tallRoom.getW(), repeat.getW());
|
||||
assertEquals(tallRoom.getH(), repeat.getH());
|
||||
assertEquals(tallRoom.getD(), repeat.getD());
|
||||
assertEquals(tallRoom.getBlocks().size(), repeat.getBlocks().size());
|
||||
for (Map.Entry<IrisBlockVector, NativeBlockState> entry : tallRoom.getBlocks()) {
|
||||
NativeBlockState repeated = repeat.getBlocks().get(entry.getKey());
|
||||
assertNotNull(repeated);
|
||||
assertEquals(entry.getValue().key(), repeated.key());
|
||||
}
|
||||
assertEquals("procedural/vault-spire/cenote-room", tallRoom.getLoadKey());
|
||||
}
|
||||
}
|
||||
|
||||
private SubterrainRoom room(int vaultHeight) {
|
||||
return new SubterrainRoom("cenote-room", "cave-biome", IrisSubterrainFamily.CENOTE,
|
||||
0, 20, 0, 0, 12, 0, 10, 11 + vaultHeight, 20, 10,
|
||||
false, false, SubterrainCell.Kind.AIR);
|
||||
}
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class FormationBlockResolverTest {
|
||||
@Test
|
||||
public void sharedResolverMatchesFreshPaletteSeedsAcrossBands() {
|
||||
IrisFormation formation = new IrisFormation().setSeed(43191L).setStrataThickness(3);
|
||||
IrisMaterialPalette body = palette("stone", "andesite");
|
||||
IrisMaterialPalette cap = palette("granite", "diorite");
|
||||
IrisMaterialPalette strata = palette("terracotta", "red_terracotta");
|
||||
formation.setBlockPalette(body);
|
||||
List<Vector3i> positions = new ArrayList<>();
|
||||
for (int x = -8; x <= 8; x++) {
|
||||
for (int y = -12; y <= 24; y++) {
|
||||
positions.add(new Vector3i(x, y, x - y));
|
||||
}
|
||||
}
|
||||
Set<String> materials = new HashSet<>();
|
||||
for (boolean withStrata : new boolean[]{false, true}) {
|
||||
formation.setStrataPalette(withStrata ? strata : null);
|
||||
for (boolean withCap : new boolean[]{false, true}) {
|
||||
formation.setCapPalette(withCap ? cap : null);
|
||||
FormationBlockResolver resolver = new FormationBlockResolver(formation, null);
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
for (Vector3i position : positions) {
|
||||
FormationCanvas.Role role = position.getBlockX() % 2 == 0
|
||||
? FormationCanvas.Role.CAP : FormationCanvas.Role.BODY;
|
||||
IrisMaterialPalette expectedPalette = withCap && role == FormationCanvas.Role.CAP
|
||||
? cap : withStrata ? strata : body;
|
||||
int sampleY = expectedPalette == strata
|
||||
? Math.floorDiv(position.getBlockY(), formation.getStrataThickness()) : position.getBlockY();
|
||||
long sampleSeed = formation.getSeed() + (expectedPalette == strata ? sampleY * 31L : 0L);
|
||||
RNG fresh = new RNG(sampleSeed);
|
||||
NativeBlockState expected = expectedPalette.get(fresh,
|
||||
position.getBlockX(), sampleY, position.getBlockZ(), null);
|
||||
assertSame(expected, resolver.resolve(role, position));
|
||||
assertEquals(new RNG(sampleSeed).nextLong(), fresh.nextLong());
|
||||
materials.add(expected.key());
|
||||
}
|
||||
Collections.reverse(positions);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(materials.size() == 6);
|
||||
}
|
||||
|
||||
private static IrisMaterialPalette palette(String first, String second) {
|
||||
return new IrisMaterialPalette().setPalette(new KList<>(block(first), block(second)));
|
||||
}
|
||||
|
||||
private static IrisBlockData block(String material) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn("minecraft:" + material);
|
||||
IrisBlockData block = mock(IrisBlockData.class);
|
||||
when(block.getWeight()).thenReturn(1);
|
||||
when(block.getBlockData(null)).thenReturn(state);
|
||||
return block;
|
||||
}
|
||||
}
|
||||
-351
@@ -1,351 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FormationShapeBuilderTest {
|
||||
@Test
|
||||
public void magicalFormsAreDeterministicAndGrounded() {
|
||||
assertDeterministicAndGrounded(this::iceberg);
|
||||
assertDeterministicAndGrounded(this::fissure);
|
||||
assertDeterministicAndGrounded(this::spiral);
|
||||
assertDeterministicAndGrounded(this::overhang);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void icebergBuildsWideBodyWithMultipleSummits() {
|
||||
FormationCanvas canvas = iceberg(41L);
|
||||
|
||||
assertTrue(maxY(canvas) >= 12);
|
||||
assertTrue(horizontalDiameter(canvas) >= 12);
|
||||
assertTrue(localSummits(canvas) >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fissureKeepsShardsSeparatedByOpenCracks() {
|
||||
FormationCanvas canvas = fissure(73L);
|
||||
|
||||
assertTrue(connectedComponents(canvas) >= 3);
|
||||
assertTrue(maxY(canvas) >= 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spiralLeavesAnOpenCenterAndCirclesMultipleQuadrants() {
|
||||
FormationCanvas canvas = spiral(101L);
|
||||
int middleY = 9;
|
||||
|
||||
assertFalse(canvas.has(0, middleY, 0));
|
||||
assertTrue(hasQuadrant(canvas, true, true));
|
||||
assertTrue(hasQuadrant(canvas, true, false));
|
||||
assertTrue(hasQuadrant(canvas, false, true));
|
||||
assertTrue(hasQuadrant(canvas, false, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overhangCantileversBeyondItsGroundedFoot() {
|
||||
FormationCanvas canvas = overhang(131L);
|
||||
double footReach = maxHorizontalReach(canvas, 0, 2);
|
||||
double upperReach = maxHorizontalReach(canvas, 9, Integer.MAX_VALUE);
|
||||
|
||||
assertTrue(upperReach >= footReach + 5.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thinLeaningSpireRetainsAConnectedPointedTip() {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setRoughness(0.12);
|
||||
formation.setJitter(0.02);
|
||||
formation.setTopWidth(0);
|
||||
formation.setLean(10);
|
||||
formation.setLeanAzimuth(18);
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
int height = 48;
|
||||
FormationShapeBuilder.spire(canvas, formation, height, 1.0, new RNG(137L));
|
||||
double shear = Math.tan(Math.toRadians(formation.getLean())) * (height - 1);
|
||||
int tipX = (int) Math.round(Math.cos(Math.toRadians(formation.getLeanAzimuth())) * shear);
|
||||
int tipZ = (int) Math.round(Math.sin(Math.toRadians(formation.getLeanAzimuth())) * shear);
|
||||
|
||||
assertEquals(FormationCanvas.Role.CAP, canvas.getCells().get(new Vector3i(tipX, height - 1, tipZ)));
|
||||
assertEquals(height - 1, maxY(canvas));
|
||||
assertEquals(1, connectedComponents(canvas));
|
||||
assertTrue(maxLayerDiameter(canvas) <= 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archRetainsGroundedLegsAndAnOpenCenter() {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setArchSpan(10);
|
||||
formation.setArchThickness(2);
|
||||
formation.setArchAsymmetry(0.8);
|
||||
FormationCanvas canvas = arch(formation, 149L);
|
||||
FormationCanvas repeated = arch(formation, 149L);
|
||||
FormationCanvas different = arch(formation, 151L);
|
||||
|
||||
assertEquals(canvas.getCells(), repeated.getCells());
|
||||
assertFalse(canvas.getCells().equals(different.getCells()));
|
||||
assertEquals(1, connectedComponents(canvas));
|
||||
assertTrue(layerComponents(canvas, 0) >= 2);
|
||||
assertTrue(openCenterColumn(canvas, 3, 6));
|
||||
assertTrue(axisDiameter(canvas, false) >= 4);
|
||||
assertTrue(maxY(canvas) >= 16);
|
||||
assertTrue(maxY(canvas) <= 18);
|
||||
assertTrue(unmirroredCells(canvas) >= 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroAsymmetryKeepsArchMirroredAndThicknessScales() {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setRoughness(0.0);
|
||||
formation.setJitter(0.0);
|
||||
formation.setArchSpan(10);
|
||||
formation.setArchAsymmetry(0.0);
|
||||
|
||||
formation.setArchThickness(1);
|
||||
FormationCanvas thin = arch(formation, 173L);
|
||||
formation.setArchThickness(2);
|
||||
FormationCanvas medium = arch(formation, 173L);
|
||||
formation.setArchThickness(3);
|
||||
FormationCanvas thick = arch(formation, 173L);
|
||||
|
||||
assertEquals(0, unmirroredCells(medium));
|
||||
assertTrue(thin.getCells().size() < medium.getCells().size());
|
||||
assertTrue(medium.getCells().size() < thick.getCells().size());
|
||||
}
|
||||
|
||||
private void assertDeterministicAndGrounded(CanvasFactory factory) {
|
||||
FormationCanvas first = factory.create(31L);
|
||||
FormationCanvas second = factory.create(31L);
|
||||
|
||||
assertFalse(first.isEmpty());
|
||||
assertEquals(first.getCells(), second.getCells());
|
||||
assertTrue(hasLayer(first, 0));
|
||||
}
|
||||
|
||||
private FormationCanvas iceberg(long seed) {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setIcebergPeaks(4);
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
FormationShapeBuilder.iceberg(canvas, formation, 20, 5.0, new RNG(seed));
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private FormationCanvas fissure(long seed) {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setFractureCount(3);
|
||||
formation.setFractureSeparation(4);
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
FormationShapeBuilder.fissure(canvas, formation, 18, 4.0, new RNG(seed));
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private FormationCanvas spiral(long seed) {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setSpiralTurns(1.75);
|
||||
formation.setSpiralRadius(6);
|
||||
formation.setSpiralThickness(1);
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
FormationShapeBuilder.spiral(canvas, formation, 20, 4.0, new RNG(seed));
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private FormationCanvas overhang(long seed) {
|
||||
IrisFormation formation = baseFormation();
|
||||
formation.setOverhangReach(14);
|
||||
formation.setOverhangDrop(4);
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
FormationShapeBuilder.overhang(canvas, formation, 20, 3.0, new RNG(seed));
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private FormationCanvas arch(IrisFormation formation, long seed) {
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
FormationShapeBuilder.arch(canvas, formation, 18, 4.0, new RNG(seed));
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private IrisFormation baseFormation() {
|
||||
IrisFormation formation = new IrisFormation();
|
||||
formation.setRoughness(0.2);
|
||||
formation.setJitter(0.05);
|
||||
return formation;
|
||||
}
|
||||
|
||||
private boolean hasLayer(FormationCanvas canvas, int y) {
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
if (position.getBlockY() == y) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int maxY(FormationCanvas canvas) {
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
max = Math.max(max, position.getBlockY());
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private int horizontalDiameter(FormationCanvas canvas) {
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
minX = Math.min(minX, position.getBlockX());
|
||||
maxX = Math.max(maxX, position.getBlockX());
|
||||
minZ = Math.min(minZ, position.getBlockZ());
|
||||
maxZ = Math.max(maxZ, position.getBlockZ());
|
||||
}
|
||||
return Math.max(maxX - minX + 1, maxZ - minZ + 1);
|
||||
}
|
||||
|
||||
private int axisDiameter(FormationCanvas canvas, boolean xAxis) {
|
||||
int min = Integer.MAX_VALUE;
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
int coordinate = xAxis ? position.getBlockX() : position.getBlockZ();
|
||||
min = Math.min(min, coordinate);
|
||||
max = Math.max(max, coordinate);
|
||||
}
|
||||
return max - min + 1;
|
||||
}
|
||||
|
||||
private int maxLayerDiameter(FormationCanvas canvas) {
|
||||
int maximum = 0;
|
||||
for (int y = 0; y <= maxY(canvas); y++) {
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
if (position.getBlockY() != y) {
|
||||
continue;
|
||||
}
|
||||
minX = Math.min(minX, position.getBlockX());
|
||||
maxX = Math.max(maxX, position.getBlockX());
|
||||
minZ = Math.min(minZ, position.getBlockZ());
|
||||
maxZ = Math.max(maxZ, position.getBlockZ());
|
||||
}
|
||||
if (minX != Integer.MAX_VALUE) {
|
||||
maximum = Math.max(maximum, Math.max(maxX - minX + 1, maxZ - minZ + 1));
|
||||
}
|
||||
}
|
||||
return maximum;
|
||||
}
|
||||
|
||||
private boolean openCenterColumn(FormationCanvas canvas, int halfWidth, int maxY) {
|
||||
for (int x = -halfWidth; x <= halfWidth; x++) {
|
||||
for (int y = 0; y <= maxY; y++) {
|
||||
if (canvas.has(x, y, 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int unmirroredCells(FormationCanvas canvas) {
|
||||
int unmatched = 0;
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
if (!canvas.has(-position.getBlockX(), position.getBlockY(), position.getBlockZ())) {
|
||||
unmatched++;
|
||||
}
|
||||
}
|
||||
return unmatched;
|
||||
}
|
||||
|
||||
private int localSummits(FormationCanvas canvas) {
|
||||
Set<String> summits = new HashSet<>();
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
if (!canvas.has(position.getBlockX(), position.getBlockY() + 1, position.getBlockZ())) {
|
||||
int bucketX = Math.floorDiv(position.getBlockX(), 3);
|
||||
int bucketZ = Math.floorDiv(position.getBlockZ(), 3);
|
||||
if (position.getBlockY() >= 8) {
|
||||
summits.add(bucketX + ":" + bucketZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
return summits.size();
|
||||
}
|
||||
|
||||
private int connectedComponents(FormationCanvas canvas) {
|
||||
Set<Vector3i> remaining = new HashSet<>(canvas.getCells().keySet());
|
||||
int components = 0;
|
||||
while (!remaining.isEmpty()) {
|
||||
Vector3i start = remaining.iterator().next();
|
||||
remaining.remove(start);
|
||||
ArrayDeque<Vector3i> queue = new ArrayDeque<>();
|
||||
queue.add(start);
|
||||
while (!queue.isEmpty()) {
|
||||
Vector3i current = queue.removeFirst();
|
||||
for (Vector3i neighbor : neighbors(current)) {
|
||||
if (remaining.remove(neighbor)) {
|
||||
queue.addLast(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
components++;
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
private int layerComponents(FormationCanvas canvas, int y) {
|
||||
FormationCanvas layer = new FormationCanvas();
|
||||
for (Map.Entry<Vector3i, FormationCanvas.Role> entry : canvas.getCells().entrySet()) {
|
||||
Vector3i position = entry.getKey();
|
||||
if (position.getBlockY() == y) {
|
||||
layer.setBody(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
}
|
||||
return connectedComponents(layer);
|
||||
}
|
||||
|
||||
private Set<Vector3i> neighbors(Vector3i position) {
|
||||
Set<Vector3i> neighbors = new HashSet<>();
|
||||
neighbors.add(new Vector3i(position.getBlockX() + 1, position.getBlockY(), position.getBlockZ()));
|
||||
neighbors.add(new Vector3i(position.getBlockX() - 1, position.getBlockY(), position.getBlockZ()));
|
||||
neighbors.add(new Vector3i(position.getBlockX(), position.getBlockY() + 1, position.getBlockZ()));
|
||||
neighbors.add(new Vector3i(position.getBlockX(), position.getBlockY() - 1, position.getBlockZ()));
|
||||
neighbors.add(new Vector3i(position.getBlockX(), position.getBlockY(), position.getBlockZ() + 1));
|
||||
neighbors.add(new Vector3i(position.getBlockX(), position.getBlockY(), position.getBlockZ() - 1));
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
private boolean hasQuadrant(FormationCanvas canvas, boolean positiveX, boolean positiveZ) {
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
boolean matchesX = positiveX ? position.getBlockX() >= 3 : position.getBlockX() <= -3;
|
||||
boolean matchesZ = positiveZ ? position.getBlockZ() >= 3 : position.getBlockZ() <= -3;
|
||||
if (matchesX && matchesZ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private double maxHorizontalReach(FormationCanvas canvas, int minY, int maxY) {
|
||||
double max = 0.0;
|
||||
for (Vector3i position : canvas.getCells().keySet()) {
|
||||
if (position.getBlockY() < minY || position.getBlockY() > maxY) {
|
||||
continue;
|
||||
}
|
||||
max = Math.max(max, Math.hypot(position.getBlockX(), position.getBlockZ()));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private interface CanvasFactory {
|
||||
FormationCanvas create(long seed);
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.fungus;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FungusStemBuilderTest {
|
||||
@Test
|
||||
public void straightStemsKeepOddAndEvenWidthAnchors() {
|
||||
for (int width = 1; width <= 3; width++) {
|
||||
IrisFungus fungus = new IrisFungus();
|
||||
fungus.setStemWidth(width);
|
||||
fungus.setStemCurve(0D);
|
||||
fungus.setStemWaveAmplitude(0D);
|
||||
Map<Vector3i, FungusCellRole> roles = new HashMap<>();
|
||||
|
||||
double[] top = FungusStemBuilder.build(roles, fungus, 7, 421L);
|
||||
|
||||
assertArrayEquals(new double[]{0D, 6D, 0D}, top, 0D);
|
||||
assertEquals(width * width * 7, roles.size());
|
||||
int origin = width == 3 ? -1 : 0;
|
||||
for (int y = 0; y < 7; y++) {
|
||||
for (int x = origin; x < origin + width; x++) {
|
||||
for (int z = origin; z < origin + width; z++) {
|
||||
assertEquals(FungusCellRole.STEM, roles.get(new Vector3i(x, y, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curvedStemsKeepEveryLayerAndReturnTheirCapAnchor() {
|
||||
IrisFungus fungus = new IrisFungus();
|
||||
fungus.setStemWidth(3);
|
||||
fungus.setStemCurve(22D);
|
||||
fungus.setStemLeanAzimuth(225D);
|
||||
fungus.setStemWaveAmplitude(2D);
|
||||
fungus.setStemWavePeriods(1.5D);
|
||||
Map<Vector3i, FungusCellRole> roles = new HashMap<>();
|
||||
|
||||
double[] top = FungusStemBuilder.build(roles, fungus, 24, -733L);
|
||||
|
||||
assertEquals(24 * 9, roles.size());
|
||||
assertTrue(top[0] < 0D);
|
||||
assertTrue(top[2] < 0D);
|
||||
assertEquals(23D, top[1], 0D);
|
||||
assertEquals(FungusCellRole.STEM, roles.get(new Vector3i(
|
||||
(int) Math.round(top[0]), 23, (int) Math.round(top[2]))));
|
||||
for (int y = 0; y < 24; y++) {
|
||||
int count = 0;
|
||||
for (Vector3i position : roles.keySet()) {
|
||||
if (position.getY() == y) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
assertEquals(9, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
-354
@@ -1,354 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ProceduralTreeGeneratorTest {
|
||||
|
||||
@Test
|
||||
public void variantsUseTreeSpecificProceduralOwnershipKeys() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setName("towering-oak");
|
||||
|
||||
assertEquals("procedural/tree/towering-oak#3", tree.getVariantLoadKey(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trunkBuildsConnectedColumnOfRequestedHeight() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
tree.setTrunkWidth(1);
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 12;
|
||||
TreeTrunkBuilder.build(canvas, tree, height);
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
assertTrue("trunk column missing at y=" + y, canvas.has(0, y, 0));
|
||||
}
|
||||
assertEquals(height, canvas.getTrunk().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leaningTrunkStaysConnected() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
tree.setLeanAngle(35);
|
||||
tree.setLeanAzimuth(45);
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 16;
|
||||
TreeTrunkBuilder.build(canvas, tree, height);
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
boolean layerHasBlock = false;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == y) {
|
||||
layerHasBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue("leaning trunk has a gap at y=" + y, layerHasBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void volumeCanopyProducesLeavesAboveTrunk() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
tree.setLeaves("minecraft:oak_leaves");
|
||||
tree.setProfile(IrisTreeProfile.OAK);
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 9;
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, height).get(0).offsets();
|
||||
TreeCanopyBuilder.build(canvas, tree, height, offsets, 0, 1234L, null);
|
||||
|
||||
assertFalse("canopy produced no leaves", canvas.getLeaf().isEmpty());
|
||||
|
||||
int maxLeafY = Integer.MIN_VALUE;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getLeaf()) {
|
||||
maxLeafY = Math.max(maxLeafY, v.y());
|
||||
}
|
||||
assertTrue("leaves should rise above the trunk top", maxLeafY >= height - 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poplarCrownIsBroaderAndHigherThanColumnarCrown() {
|
||||
TreeBlockCanvas poplar = profileCanopy(IrisTreeProfile.POPLAR);
|
||||
TreeBlockCanvas columnar = profileCanopy(IrisTreeProfile.COLUMNAR);
|
||||
int poplarWidth = 0;
|
||||
int columnarWidth = 0;
|
||||
int poplarBottom = Integer.MAX_VALUE;
|
||||
int columnarBottom = Integer.MAX_VALUE;
|
||||
for (TreeBlockCanvas.Vec leaf : poplar.getLeaf()) {
|
||||
poplarWidth = Math.max(poplarWidth, Math.abs(leaf.x()));
|
||||
poplarBottom = Math.min(poplarBottom, leaf.y());
|
||||
}
|
||||
for (TreeBlockCanvas.Vec leaf : columnar.getLeaf()) {
|
||||
columnarWidth = Math.max(columnarWidth, Math.abs(leaf.x()));
|
||||
columnarBottom = Math.min(columnarBottom, leaf.y());
|
||||
}
|
||||
|
||||
assertTrue(poplarWidth > columnarWidth);
|
||||
assertTrue(poplarBottom > columnarBottom);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void branchingPoplarVariantsRetainSupportedLeavesAndOrientedWood() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree()
|
||||
.setProfile(IrisTreeProfile.POPLAR)
|
||||
.setTrunk("minecraft:poplar_log")
|
||||
.setLeaves("minecraft:orange_poplar_leaves")
|
||||
.setLeanAngle(7);
|
||||
IrisTreeBranches branches = new IrisTreeBranches()
|
||||
.setProbabilityFunction(IrisTreeBranchProbability.TOP_HEAVY)
|
||||
.setProbabilityExponent(2)
|
||||
.setLengthFunction(IrisTreeFunction.CONSTANT)
|
||||
.setLengthConstant(3)
|
||||
.setElevation(35)
|
||||
.setClusterRadius(2);
|
||||
tree.getCanopy().setBranches(branches);
|
||||
for (int height = 7; height <= 11; height++) {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
List<int[]> endpoints = new ArrayList<>();
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, height).getFirst().offsets();
|
||||
TreeCanopyBuilder.build(canvas, tree, height, offsets, 0, height * 7919L, endpoints);
|
||||
TreeSupport.ensureLeavesSupported(canvas, 24);
|
||||
|
||||
assertFalse(endpoints.isEmpty());
|
||||
assertFalse(canvas.getLeaf().isEmpty());
|
||||
Map<TreeBlockCanvas.Vec, Integer> distances = TreePlausibility.computeDistances(canvas.getTrunk(), canvas.getLeaf());
|
||||
for (TreeBlockCanvas.Vec leaf : canvas.getLeaf()) {
|
||||
assertNotNull(distances.get(leaf));
|
||||
assertTrue(distances.get(leaf) <= 6);
|
||||
}
|
||||
for (TreeBlockCanvas.Vec wood : canvas.getTrunk()) {
|
||||
assertTrue(canvas.get(wood.x(), wood.y(), wood.z()).axis() != TreeBlockCanvas.Axis.NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas profileCanopy(IrisTreeProfile profile) {
|
||||
IrisProceduralTree tree = new IrisProceduralTree().setProfile(profile);
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, 14).getFirst().offsets();
|
||||
TreeCanopyBuilder.build(canvas, tree, 14, offsets, 0, 1234L, null);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hollowCanopyHasFewerLeavesThanFilled() {
|
||||
TreeBlockCanvas filled = canopyOnly(IrisTreeLeafMode.FILLED);
|
||||
TreeBlockCanvas hollow = canopyOnly(IrisTreeLeafMode.HOLLOW);
|
||||
assertTrue("hollow canopy should place fewer leaves than filled",
|
||||
hollow.getLeaf().size() < filled.getLeaf().size());
|
||||
assertFalse("hollow canopy still places a leaf shell", hollow.getLeaf().isEmpty());
|
||||
}
|
||||
|
||||
private TreeBlockCanvas canopyOnly(IrisTreeLeafMode mode) {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
tree.setLeaves("minecraft:oak_leaves");
|
||||
tree.setProfile(IrisTreeProfile.OAK);
|
||||
tree.getCanopy().setMode(mode);
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 10;
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, height).get(0).offsets();
|
||||
TreeCanopyBuilder.build(canvas, tree, height, offsets, 0, 99L, null);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void branchCanopyRecordsEndpoints() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:jungle_log");
|
||||
tree.setLeaves("minecraft:jungle_leaves");
|
||||
tree.setProfile(IrisTreeProfile.JUNGLE);
|
||||
IrisTreeBranches branches = new IrisTreeBranches();
|
||||
branches.setProbabilityFunction(IrisTreeBranchProbability.CONSTANT);
|
||||
branches.setProbabilityConstant(1.0);
|
||||
branches.setLengthFunction(IrisTreeFunction.CONSTANT);
|
||||
branches.setLengthConstant(4);
|
||||
branches.setAzimuthMode(art.arcane.iris.generation.decoration.tree.IrisTreeAzimuthMode.GOLDEN_ANGLE);
|
||||
tree.getCanopy().setBranches(branches);
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 14;
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, height).get(0).offsets();
|
||||
List<int[]> endpoints = new java.util.ArrayList<>();
|
||||
TreeCanopyBuilder.build(canvas, tree, height, offsets, 0, 777L, endpoints);
|
||||
|
||||
assertFalse("branch system recorded no endpoints", endpoints.isEmpty());
|
||||
assertFalse("branch system placed no leaves", canvas.getLeaf().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trunkForksProduceMultipleLimbs() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
tree.setTrunkForks(3);
|
||||
tree.setForkHeight(0.4);
|
||||
tree.setForkAngle(30);
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 18;
|
||||
List<TreeTrunkBuilder.Limb> limbs = TreeTrunkBuilder.build(canvas, tree, height);
|
||||
|
||||
assertEquals("a 3-fork tree should yield 3 crown limbs", 3, limbs.size());
|
||||
Set<Integer> topXs = new HashSet<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == height - 1) {
|
||||
topXs.add(v.x());
|
||||
}
|
||||
}
|
||||
assertTrue("forks should spread the trunk into separate tops", topXs.size() >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recursiveBranchesAddMoreWood() {
|
||||
int shallow = branchWoodCount(1);
|
||||
int deep = branchWoodCount(3);
|
||||
assertTrue("deeper recursion should add more branch wood", deep > shallow);
|
||||
}
|
||||
|
||||
private int branchWoodCount(int depth) {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
tree.setLeaves("minecraft:oak_leaves");
|
||||
IrisTreeBranches branches = new IrisTreeBranches();
|
||||
branches.setProbabilityFunction(IrisTreeBranchProbability.CONSTANT);
|
||||
branches.setProbabilityConstant(1.0);
|
||||
branches.setLengthFunction(IrisTreeFunction.CONSTANT);
|
||||
branches.setLengthConstant(4);
|
||||
branches.setBranchDepth(depth);
|
||||
branches.setSubBranches(new art.arcane.iris.generation.decoration.tree.IrisTreeSubBranches());
|
||||
tree.getCanopy().setBranches(branches);
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 14;
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, height).get(0).offsets();
|
||||
TreeCanopyBuilder.build(canvas, tree, height, offsets, 0, 555L, new java.util.ArrayList<>());
|
||||
return canvas.getTrunk().size();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootsExtendBelowTheBase() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunk("minecraft:oak_log");
|
||||
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int height = 14;
|
||||
TreeTrunkBuilder.build(canvas, tree, height);
|
||||
TreeRootBuilder.build(canvas, tree, height, 42L);
|
||||
|
||||
int minY = Integer.MAX_VALUE;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
minY = Math.min(minY, v.y());
|
||||
}
|
||||
assertTrue("roots should descend below the trunk base", minY < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plausibilityDistancesPropagateFromWood() {
|
||||
Set<TreeBlockCanvas.Vec> trunk = new HashSet<>();
|
||||
trunk.add(new TreeBlockCanvas.Vec(0, 0, 0));
|
||||
trunk.add(new TreeBlockCanvas.Vec(0, 1, 0));
|
||||
|
||||
TreeBlockCanvas.Vec a = new TreeBlockCanvas.Vec(1, 1, 0);
|
||||
TreeBlockCanvas.Vec b = new TreeBlockCanvas.Vec(2, 1, 0);
|
||||
TreeBlockCanvas.Vec c = new TreeBlockCanvas.Vec(3, 1, 0);
|
||||
TreeBlockCanvas.Vec far = new TreeBlockCanvas.Vec(40, 1, 0);
|
||||
Set<TreeBlockCanvas.Vec> realLeaves = new HashSet<>();
|
||||
realLeaves.add(a);
|
||||
realLeaves.add(b);
|
||||
realLeaves.add(c);
|
||||
realLeaves.add(far);
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> distances = TreePlausibility.computeDistances(trunk, realLeaves);
|
||||
|
||||
assertEquals(Integer.valueOf(1), distances.get(a));
|
||||
assertEquals(Integer.valueOf(2), distances.get(b));
|
||||
assertEquals(Integer.valueOf(3), distances.get(c));
|
||||
assertNull("disconnected leaf must remain unsupported", distances.get(far));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportTendrilsMakeFarLeavesLegal() {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
canvas.setTrunk(0, 0, 0, TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Axis.Y);
|
||||
for (int x = 1; x <= 14; x++) {
|
||||
canvas.setLeaf(x, 0, 0, TreeBlockCanvas.Role.LEAF);
|
||||
}
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> before = TreePlausibility.computeDistances(canvas.getTrunk(), canvas.getLeaf());
|
||||
assertNull("the far leaf should start unsupported", before.get(new TreeBlockCanvas.Vec(14, 0, 0)));
|
||||
|
||||
TreeSupport.ensureLeavesSupported(canvas, 24);
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> after = TreePlausibility.computeDistances(canvas.getTrunk(), canvas.getLeaf());
|
||||
assertFalse("leaves should remain after support", canvas.getLeaf().isEmpty());
|
||||
for (TreeBlockCanvas.Vec leaf : canvas.getLeaf()) {
|
||||
Integer d = after.get(leaf);
|
||||
assertNotNull("every leaf must be reachable from wood after support", d);
|
||||
assertTrue("every leaf must be within legal decay distance after support", d <= 6);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plausibilityDistanceCapsAtSeven() {
|
||||
Set<TreeBlockCanvas.Vec> trunk = new HashSet<>();
|
||||
trunk.add(new TreeBlockCanvas.Vec(0, 0, 0));
|
||||
|
||||
Set<TreeBlockCanvas.Vec> realLeaves = new HashSet<>();
|
||||
for (int x = 1; x <= 12; x++) {
|
||||
realLeaves.add(new TreeBlockCanvas.Vec(x, 0, 0));
|
||||
}
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> distances = TreePlausibility.computeDistances(trunk, realLeaves);
|
||||
|
||||
for (int x = 1; x <= 7; x++) {
|
||||
assertEquals("leaf at distance " + x + " should be reachable",
|
||||
Integer.valueOf(x), distances.get(new TreeBlockCanvas.Vec(x, 0, 0)));
|
||||
}
|
||||
for (int x = 8; x <= 12; x++) {
|
||||
assertNull("leaves beyond distance 7 must remain unsupported",
|
||||
distances.get(new TreeBlockCanvas.Vec(x, 0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledPlausibilityMakesDisconnectedLeavesPersistent() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setPlausible(false);
|
||||
TreeBlockCanvas.Vec position = new TreeBlockCanvas.Vec(40, 20, -10);
|
||||
NativeBlockState leaf = mock(NativeBlockState.class);
|
||||
NativeBlockState persistent = mock(NativeBlockState.class);
|
||||
NativeBlockState supported = mock(NativeBlockState.class);
|
||||
when(leaf.key()).thenReturn("minecraft:oak_leaves[persistent=false,distance=7]");
|
||||
when(leaf.withProperty("persistent", "true")).thenReturn(persistent);
|
||||
when(persistent.withProperty("distance", "1")).thenReturn(supported);
|
||||
Map<TreeBlockCanvas.Vec, NativeBlockState> resolved = new HashMap<>();
|
||||
resolved.put(position, leaf);
|
||||
|
||||
TreePlausibility.apply(resolved, Set.of(new TreeBlockCanvas.Vec(0, 0, 0)), Set.of(position), tree);
|
||||
|
||||
assertSame(supported, resolved.get(position));
|
||||
}
|
||||
}
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TreeBlockResolverTest {
|
||||
@Test
|
||||
public void largeSecondaryWeightsKeepTheirRelativeDistribution() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setSeed(91874L);
|
||||
tree.setLeavesPalette(palette("oak_leaves", "birch_leaves"));
|
||||
NativeBlockState blossom = mock(NativeBlockState.class);
|
||||
NativeBlockState light = mock(NativeBlockState.class);
|
||||
List<NativeBlockState> normal = new ArrayList<>();
|
||||
List<NativeBlockState> large = new ArrayList<>();
|
||||
TreeBlockCanvas.Cell cell = new TreeBlockCanvas.Cell(
|
||||
TreeBlockCanvas.Role.SECONDARY_LEAF, TreeBlockCanvas.Axis.NONE, false, -1, null);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getStateOrNull("minecraft:cherry_leaves", false)).thenReturn(blossom);
|
||||
blocks.when(() -> B.getStateOrNull("minecraft:shroomlight", false)).thenReturn(light);
|
||||
for (int weight : new int[]{1, Integer.MAX_VALUE}) {
|
||||
tree.setWeightedSecondaryLeaves(new KList<>(
|
||||
new IrisTreeSecondaryLeaf("minecraft:cherry_leaves", weight),
|
||||
new IrisTreeSecondaryLeaf("minecraft:shroomlight", weight)));
|
||||
List<NativeBlockState> resolved = weight == 1 ? normal : large;
|
||||
for (int x = -16; x <= 16; x++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
resolved.add(TreeBlockResolver.resolve(tree, null, cell,
|
||||
new TreeBlockCanvas.Vec(x, y, x + y), new RNG(tree.getSeed())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(normal.contains(blossom));
|
||||
assertTrue(normal.contains(light));
|
||||
assertEquals(normal, large);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sharedPaletteRandomSourceMatchesFreshPerVoxelSources() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setSeed(84261L);
|
||||
tree.setTrunkPalette(palette("oak_log", "spruce_log"));
|
||||
tree.setLeavesPalette(palette("oak_leaves", "birch_leaves"));
|
||||
tree.setSecondaryTrunkPalette(palette("birch_log", "jungle_log"));
|
||||
tree.setSecondaryLeavesPalette(palette("spruce_leaves", "jungle_leaves"));
|
||||
RNG shared = new RNG(tree.getSeed());
|
||||
List<String> freshBlocks = new ArrayList<>();
|
||||
List<String> sharedBlocks = new ArrayList<>();
|
||||
Set<String> materials = new HashSet<>();
|
||||
TreeBlockCanvas.Role[] roles = {
|
||||
TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Role.LEAF,
|
||||
TreeBlockCanvas.Role.SECONDARY_TRUNK, TreeBlockCanvas.Role.SECONDARY_LEAF
|
||||
};
|
||||
for (int x = -8; x <= 8; x++) {
|
||||
for (int y = 0; y < 24; y++) {
|
||||
TreeBlockCanvas.Vec position = new TreeBlockCanvas.Vec(x, y, x - y);
|
||||
TreeBlockCanvas.Cell cell = new TreeBlockCanvas.Cell(
|
||||
roles[Math.floorMod(x + y, roles.length)], TreeBlockCanvas.Axis.NONE, false, -1, null);
|
||||
NativeBlockState expected = TreeBlockResolver.resolve(tree, null, cell, position, new RNG(tree.getSeed()));
|
||||
NativeBlockState actual = TreeBlockResolver.resolve(tree, null, cell, position, shared);
|
||||
freshBlocks.add(position + ":" + expected.key());
|
||||
sharedBlocks.add(position + ":" + actual.key());
|
||||
materials.add(actual.key());
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(freshBlocks, sharedBlocks);
|
||||
assertEquals(new RNG(tree.getSeed()).nextLong(), shared.nextLong());
|
||||
assertTrue(materials.size() > roles.length);
|
||||
}
|
||||
|
||||
private static IrisMaterialPalette palette(String first, String second) {
|
||||
IrisBlockData firstBlock = block(first);
|
||||
IrisBlockData secondBlock = block(second);
|
||||
return new IrisMaterialPalette().setPalette(new KList<>(firstBlock, secondBlock));
|
||||
}
|
||||
|
||||
private static IrisBlockData block(String material) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn("minecraft:" + material);
|
||||
IrisBlockData block = mock(IrisBlockData.class);
|
||||
when(block.getWeight()).thenReturn(1);
|
||||
when(block.getBlockData(null)).thenReturn(state);
|
||||
return block;
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TreeCanopyBuilderTest {
|
||||
@Test
|
||||
public void laterBranchesGrowThroughEarlierLeafClusters() {
|
||||
IrisProceduralTree tree = branchedTree();
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, 6).getFirst().offsets();
|
||||
|
||||
TreeCanopyBuilder.build(canvas, tree, 6, offsets, 0, 42L, null);
|
||||
|
||||
for (int y = 0; y < 6; y++) {
|
||||
for (int z = 0; z <= 4; z++) {
|
||||
assertTrue(canvas.getTrunk().contains(new TreeBlockCanvas.Vec(0, y, z)));
|
||||
assertFalse(canvas.getLeaf().contains(new TreeBlockCanvas.Vec(0, y, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void branchWoodReplacesBothLeafRolesButKeepsWoodAndAccents() {
|
||||
IrisProceduralTree tree = branchedTree();
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
double[][] offsets = TreeTrunkBuilder.build(canvas, tree, 6).getFirst().offsets();
|
||||
canvas.setLeaf(0, 1, 1, TreeBlockCanvas.Role.LEAF);
|
||||
canvas.setLeaf(0, 1, 2, TreeBlockCanvas.Role.SECONDARY_LEAF);
|
||||
canvas.setTrunk(0, 1, 3, TreeBlockCanvas.Role.SECONDARY_TRUNK, TreeBlockCanvas.Axis.X);
|
||||
canvas.setDecor(0, 1, 4, 0, "north");
|
||||
|
||||
TreeCanopyBuilder.build(canvas, tree, 6, offsets, 0, 42L, null);
|
||||
|
||||
assertEquals(TreeBlockCanvas.Role.TRUNK, canvas.get(0, 1, 1).role());
|
||||
assertEquals(TreeBlockCanvas.Role.TRUNK, canvas.get(0, 1, 2).role());
|
||||
assertEquals(TreeBlockCanvas.Role.SECONDARY_TRUNK, canvas.get(0, 1, 3).role());
|
||||
assertEquals(TreeBlockCanvas.Axis.X, canvas.get(0, 1, 3).axis());
|
||||
assertEquals(TreeBlockCanvas.Role.DECORATOR, canvas.get(0, 1, 4).role());
|
||||
assertFalse(canvas.getLeaf().contains(new TreeBlockCanvas.Vec(0, 1, 1)));
|
||||
assertFalse(canvas.getLeaf().contains(new TreeBlockCanvas.Vec(0, 1, 2)));
|
||||
}
|
||||
|
||||
private static IrisProceduralTree branchedTree() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
IrisTreeBranches branches = new IrisTreeBranches();
|
||||
branches.setProbabilityFunction(IrisTreeBranchProbability.CONSTANT);
|
||||
branches.setProbabilityConstant(1);
|
||||
branches.setLengthFunction(IrisTreeFunction.CONSTANT);
|
||||
branches.setLengthConstant(4);
|
||||
branches.setAzimuthMode(IrisTreeAzimuthMode.CONSTANT);
|
||||
branches.setAzimuth(0);
|
||||
branches.setElevation(0);
|
||||
branches.setClusterRadius(2);
|
||||
branches.setClusterMode(IrisTreeLeafMode.FILLED);
|
||||
tree.getCanopy().setBranches(branches);
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
-160
@@ -1,160 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class TreeDecoratorApplierTest {
|
||||
@Test
|
||||
public void allDecoratorTargetsKeepPinnedOutputAcrossHashCollisionInsertionOrders() {
|
||||
long[] seeds = {101L, -73L, 90181L};
|
||||
long[] actual = new long[seeds.length];
|
||||
for (int i = 0; i < seeds.length; i++) {
|
||||
long hash = 0xcbf29ce484222325L;
|
||||
for (IrisTreeDecoratorTarget target : IrisTreeDecoratorTarget.values()) {
|
||||
TreeBlockCanvas forward = collisionCanvas(false);
|
||||
TreeBlockCanvas reverse = collisionCanvas(true);
|
||||
IrisProceduralTree tree = surfaceTree(target, true);
|
||||
tree.getDecorators().getFirst().setChance(0.41D).setLength(4);
|
||||
TreeDecoratorApplier.apply(forward, tree, seeds[i], List.of());
|
||||
TreeDecoratorApplier.apply(reverse, tree, seeds[i], List.of());
|
||||
assertEquals(target + ":" + seeds[i], forward.getCells(), reverse.getCells());
|
||||
List<TreeBlockCanvas.Vec> positions = new ArrayList<>(forward.getCells().keySet());
|
||||
positions.sort(null);
|
||||
for (TreeBlockCanvas.Vec position : positions) {
|
||||
TreeBlockCanvas.Cell cell = forward.getCells().get(position);
|
||||
hash = (hash ^ position.hashCode()) * 0x100000001b3L;
|
||||
hash = (hash ^ cell.role().ordinal()) * 0x100000001b3L;
|
||||
hash = (hash ^ cell.decoratorIndex()) * 0x100000001b3L;
|
||||
hash = (hash ^ (cell.facing() == null ? 0 : cell.facing().hashCode())) * 0x100000001b3L;
|
||||
}
|
||||
}
|
||||
actual[i] = hash;
|
||||
}
|
||||
assertEquals(Arrays.toString(new long[]{4350422081939262412L, 3647024406982151043L, 7110665103288366817L}), Arrays.toString(actual));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportTendrilsChooseTheSameEqualDistanceEndpointsAcrossInsertionOrders() {
|
||||
TreeBlockCanvas forward = supportCanvas(false);
|
||||
TreeBlockCanvas reverse = supportCanvas(true);
|
||||
TreeSupport.ensureLeavesSupported(forward, 4);
|
||||
TreeSupport.ensureLeavesSupported(reverse, 4);
|
||||
assertEquals(forward.getCells(), reverse.getCells());
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas collisionCanvas(boolean reverse) {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
for (int index = 0; index < 24; index++) {
|
||||
int position = reverse ? 23 - index : index;
|
||||
int x = position - 12;
|
||||
int y = -31 * x;
|
||||
canvas.setTrunk(x, y, 0, TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Axis.Y);
|
||||
canvas.setLeaf(x, y, 1, TreeBlockCanvas.Role.LEAF);
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas supportCanvas(boolean reverse) {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
int[] coordinates = reverse ? new int[]{3, -3} : new int[]{-3, 3};
|
||||
for (int x : coordinates) {
|
||||
canvas.setTrunk(x, 0, 0, TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Axis.Y);
|
||||
canvas.setLeaf(x * 4, 0, 2, TreeBlockCanvas.Role.LEAF);
|
||||
canvas.setLeaf(x * 4, 0, -2, TreeBlockCanvas.Role.LEAF);
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trunkAttachmentsFaceAwayFromTheirWoodSupport() {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
canvas.setTrunk(0, 2, 0, TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Axis.Y);
|
||||
IrisProceduralTree tree = surfaceTree(IrisTreeDecoratorTarget.TRUNK_SURFACE, true);
|
||||
|
||||
TreeDecoratorApplier.apply(canvas, tree, 918L, List.of());
|
||||
|
||||
assertOutwardFacings(canvas);
|
||||
assertEquals(1, canvas.getTrunk().size());
|
||||
assertEquals(5, canvas.getCells().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leafAttachmentsFaceAwayFromTheirLeafSupport() {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
canvas.setLeaf(0, 2, 0, TreeBlockCanvas.Role.LEAF);
|
||||
IrisProceduralTree tree = surfaceTree(IrisTreeDecoratorTarget.LEAF_SURFACE, true);
|
||||
|
||||
TreeDecoratorApplier.apply(canvas, tree, 918L, List.of());
|
||||
|
||||
assertOutwardFacings(canvas);
|
||||
assertEquals(1, canvas.getLeaf().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trunkAttachmentsKeepExplicitBlockFacingWhenAxisAwarenessIsDisabled() {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
canvas.setTrunk(0, 2, 0, TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Axis.Y);
|
||||
IrisProceduralTree tree = surfaceTree(IrisTreeDecoratorTarget.TRUNK_SURFACE, false);
|
||||
|
||||
TreeDecoratorApplier.apply(canvas, tree, 918L, List.of());
|
||||
|
||||
assertEquals(TreeBlockCanvas.Role.DECORATOR, canvas.get(1, 2, 0).role());
|
||||
assertNull(canvas.get(1, 2, 0).facing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void branchTipsExtendOutwardThroughLeavesWithoutReplacingWood() {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
for (int x = -3; x <= 3; x++) {
|
||||
canvas.setTrunk(x, 4, 0, TreeBlockCanvas.Role.TRUNK, TreeBlockCanvas.Axis.X);
|
||||
}
|
||||
canvas.setLeaf(-4, 4, 0, TreeBlockCanvas.Role.LEAF);
|
||||
canvas.setLeaf(4, 4, 0, TreeBlockCanvas.Role.LEAF);
|
||||
IrisTreeDecorator decorator = new IrisTreeDecorator()
|
||||
.setTarget(IrisTreeDecoratorTarget.BRANCH_TIP)
|
||||
.setBlock("minecraft:shroomlight")
|
||||
.setChance(1D)
|
||||
.setAxisAware(true);
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setDecorators(new KList<>(decorator));
|
||||
List<int[]> endpoints = List.of(new int[]{-3, 4, 0, 0, 0}, new int[]{3, 4, 0, 0, 0});
|
||||
|
||||
TreeDecoratorApplier.apply(canvas, tree, 4321L, endpoints);
|
||||
|
||||
assertEquals(TreeBlockCanvas.Role.DECORATOR, canvas.get(-5, 4, 0).role());
|
||||
assertEquals("west", canvas.get(-5, 4, 0).facing());
|
||||
assertEquals(TreeBlockCanvas.Role.DECORATOR, canvas.get(5, 4, 0).role());
|
||||
assertEquals("east", canvas.get(5, 4, 0).facing());
|
||||
assertEquals(7, canvas.getTrunk().size());
|
||||
assertEquals(2, canvas.getLeaf().size());
|
||||
assertEquals(11, canvas.getCells().size());
|
||||
|
||||
TreeDecoratorApplier.apply(canvas, tree, 4321L, endpoints);
|
||||
|
||||
assertEquals(11, canvas.getCells().size());
|
||||
}
|
||||
|
||||
private static IrisProceduralTree surfaceTree(IrisTreeDecoratorTarget target, boolean axisAware) {
|
||||
IrisTreeDecorator decorator = new IrisTreeDecorator()
|
||||
.setTarget(target)
|
||||
.setBlock("minecraft:shelf_mushroom")
|
||||
.setChance(1D)
|
||||
.setAxisAware(axisAware);
|
||||
return new IrisProceduralTree().setDecorators(new KList<>(decorator));
|
||||
}
|
||||
|
||||
private static void assertOutwardFacings(TreeBlockCanvas canvas) {
|
||||
assertEquals("east", canvas.get(1, 2, 0).facing());
|
||||
assertEquals("west", canvas.get(-1, 2, 0).facing());
|
||||
assertEquals("south", canvas.get(0, 2, 1).facing());
|
||||
assertEquals("north", canvas.get(0, 2, -1).facing());
|
||||
}
|
||||
}
|
||||
-218
@@ -1,218 +0,0 @@
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TreeRootBuilderTest {
|
||||
@Test
|
||||
public void everyRootHasAFaceConnectedPathToExistingWood() {
|
||||
for (IrisTreeRootStyle style : IrisTreeRootStyle.values()) {
|
||||
for (int width : new int[]{1, 2, 5}) {
|
||||
for (long seed : new long[]{1L, 42L, 5923L}) {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setRootStyle(style);
|
||||
tree.setTrunkWidth(width);
|
||||
tree.setRootDepth(8);
|
||||
tree.setRootFlare(7);
|
||||
tree.setLeanAngle(40);
|
||||
tree.setLeanAzimuth(45);
|
||||
TreeBlockCanvas canvas = trunk(tree, 24);
|
||||
Set<TreeBlockCanvas.Vec> original = new HashSet<>(canvas.getTrunk());
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, 24, seed);
|
||||
|
||||
assertAllRootsConnected(canvas, original);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void automaticFlareRemainsCompactForTallThinTrees() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
for (int height : new int[]{8, 30, 80}) {
|
||||
TreeBlockCanvas canvas = trunk(tree, height);
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, height, 42L);
|
||||
|
||||
for (TreeBlockCanvas.Vec cell : canvas.getTrunk()) {
|
||||
if (cell.y() < 0) {
|
||||
assertTrue(Math.abs(cell.x()) <= 2);
|
||||
assertTrue(Math.abs(cell.z()) <= 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taprootNarrowsToOneCellWithoutExpandingTheBase() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setTrunkWidth(5);
|
||||
tree.setRootDepth(7);
|
||||
tree.setRootStyle(IrisTreeRootStyle.TAPROOT);
|
||||
TreeBlockCanvas canvas = trunk(tree, 20);
|
||||
Set<TreeBlockCanvas.Vec> original = new HashSet<>(canvas.getTrunk());
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, 20, 42L);
|
||||
|
||||
int previousSize = 25;
|
||||
for (int depth = 1; depth <= 7; depth++) {
|
||||
int size = 0;
|
||||
for (TreeBlockCanvas.Vec cell : canvas.getTrunk()) {
|
||||
if (cell.y() == -depth) {
|
||||
size++;
|
||||
assertTrue(original.contains(new TreeBlockCanvas.Vec(cell.x(), 0, cell.z())));
|
||||
}
|
||||
}
|
||||
assertTrue(size > 0);
|
||||
assertTrue(size <= previousSize);
|
||||
previousSize = size;
|
||||
}
|
||||
assertEquals(1, previousSize);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buttressTipsEndAtDifferentDepths() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setRootDepth(8);
|
||||
tree.setRootFlare(7);
|
||||
TreeBlockCanvas canvas = trunk(tree, 20);
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, 20, 42L);
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> outerDepths = new HashMap<>();
|
||||
for (TreeBlockCanvas.Vec cell : canvas.getTrunk()) {
|
||||
if (cell.y() < 0 && Math.hypot(cell.x(), cell.z()) >= 5) {
|
||||
TreeBlockCanvas.Vec column = new TreeBlockCanvas.Vec(cell.x(), 0, cell.z());
|
||||
outerDepths.merge(column, cell.y(), Math::min);
|
||||
}
|
||||
}
|
||||
assertTrue(new HashSet<>(outerDepths.values()).size() > 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitFlareKeepsWideStiltRoots() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setRootStyle(IrisTreeRootStyle.STILT);
|
||||
tree.setRootFlare(8);
|
||||
tree.setRootDepth(5);
|
||||
TreeBlockCanvas canvas = trunk(tree, 24);
|
||||
Set<TreeBlockCanvas.Vec> original = new HashSet<>(canvas.getTrunk());
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, 24, 42L);
|
||||
|
||||
double reach = 0;
|
||||
boolean aboveGround = false;
|
||||
for (TreeBlockCanvas.Vec cell : canvas.getTrunk()) {
|
||||
if (!original.contains(cell)) {
|
||||
reach = Math.max(reach, Math.hypot(cell.x(), cell.z()));
|
||||
aboveGround |= cell.y() > 0;
|
||||
}
|
||||
}
|
||||
assertTrue(reach >= 6);
|
||||
assertTrue(aboveGround);
|
||||
assertAllRootsConnected(canvas, original);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stiltRootsAttachToTheActualLeaningTrunk() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setRootStyle(IrisTreeRootStyle.STILT);
|
||||
tree.setLeanAngle(55);
|
||||
tree.setLeanAzimuth(90);
|
||||
tree.setRootFlare(3);
|
||||
TreeBlockCanvas canvas = trunk(tree, 24);
|
||||
Set<TreeBlockCanvas.Vec> original = new HashSet<>(canvas.getTrunk());
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, 24, 42L);
|
||||
|
||||
boolean attachedAboveGround = false;
|
||||
for (TreeBlockCanvas.Vec cell : canvas.getTrunk()) {
|
||||
if (!original.contains(cell) && cell.y() >= 4) {
|
||||
for (TreeBlockCanvas.Vec neighbor : neighbors(cell)) {
|
||||
attachedAboveGround |= original.contains(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(attachedAboveGround);
|
||||
assertAllRootsConnected(canvas, original);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectingFoliageDoesNotSeverRoots() {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setRootDepth(5);
|
||||
tree.setRootFlare(5);
|
||||
TreeBlockCanvas canvas = trunk(tree, 20);
|
||||
Set<TreeBlockCanvas.Vec> original = new HashSet<>(canvas.getTrunk());
|
||||
for (int x = -5; x <= 5; x++) {
|
||||
for (int z = -5; z <= 5; z++) {
|
||||
canvas.setLeaf(x, -1, z, TreeBlockCanvas.Role.LEAF);
|
||||
}
|
||||
}
|
||||
|
||||
TreeRootBuilder.build(canvas, tree, 20, 42L);
|
||||
|
||||
assertAllRootsConnected(canvas, original);
|
||||
assertEquals(TreeBlockCanvas.Role.TRUNK, canvas.get(0, -1, 0).role());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootGeometryIsDeterministic() {
|
||||
for (IrisTreeRootStyle style : IrisTreeRootStyle.values()) {
|
||||
IrisProceduralTree tree = new IrisProceduralTree();
|
||||
tree.setRootStyle(style);
|
||||
tree.setTrunkWidth(2);
|
||||
TreeBlockCanvas first = trunk(tree, 30);
|
||||
TreeBlockCanvas second = trunk(tree, 30);
|
||||
|
||||
TreeRootBuilder.build(first, tree, 30, 5923L);
|
||||
TreeRootBuilder.build(second, tree, 30, 5923L);
|
||||
|
||||
assertEquals(first.getCells(), second.getCells());
|
||||
}
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas trunk(IrisProceduralTree tree, int height) {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
TreeTrunkBuilder.build(canvas, tree, height);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
private static void assertAllRootsConnected(TreeBlockCanvas canvas, Set<TreeBlockCanvas.Vec> original) {
|
||||
Set<TreeBlockCanvas.Vec> reached = new HashSet<>(original);
|
||||
ArrayDeque<TreeBlockCanvas.Vec> pending = new ArrayDeque<>(original);
|
||||
while (!pending.isEmpty()) {
|
||||
TreeBlockCanvas.Vec cell = pending.removeFirst();
|
||||
for (TreeBlockCanvas.Vec neighbor : neighbors(cell)) {
|
||||
if (canvas.getTrunk().contains(neighbor) && reached.add(neighbor)) {
|
||||
pending.addLast(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
Set<TreeBlockCanvas.Vec> roots = new HashSet<>(canvas.getTrunk());
|
||||
roots.removeAll(original);
|
||||
assertFalse(roots.isEmpty());
|
||||
assertEquals(canvas.getTrunk(), reached);
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas.Vec[] neighbors(TreeBlockCanvas.Vec cell) {
|
||||
return new TreeBlockCanvas.Vec[]{
|
||||
new TreeBlockCanvas.Vec(cell.x() - 1, cell.y(), cell.z()),
|
||||
new TreeBlockCanvas.Vec(cell.x() + 1, cell.y(), cell.z()),
|
||||
new TreeBlockCanvas.Vec(cell.x(), cell.y() - 1, cell.z()),
|
||||
new TreeBlockCanvas.Vec(cell.x(), cell.y() + 1, cell.z()),
|
||||
new TreeBlockCanvas.Vec(cell.x(), cell.y(), cell.z() - 1),
|
||||
new TreeBlockCanvas.Vec(cell.x(), cell.y(), cell.z() + 1)
|
||||
};
|
||||
}
|
||||
}
|
||||
-30
@@ -13,8 +13,6 @@ import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectScale;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
@@ -195,34 +193,6 @@ public class MantleObjectComponentBoundaryRadiusTest {
|
||||
MantleObjectComponent.calculateEagerInputRadius(Integer.MAX_VALUE, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proceduralTreeTransformsContributeToRadius() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement()
|
||||
.setRotation(IrisObjectRotation.of(90, 0, 0))
|
||||
.setTranslate(new IrisObjectTranslate().setX(3).setY(4));
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisProceduralPlacement proceduralPlacement = mock(IrisProceduralPlacement.class);
|
||||
when(proceduralPlacement.getVariantObjects(data)).thenReturn(new KList<>(new IrisObject(5, 48, 7)));
|
||||
when(proceduralPlacement.asPlacement()).thenReturn(placement);
|
||||
IrisProceduralObjects proceduralObjects = mock(IrisProceduralObjects.class);
|
||||
when(proceduralObjects.isEmpty()).thenReturn(false);
|
||||
when(proceduralObjects.getAllPlacements()).thenReturn(new KList<>(proceduralPlacement));
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
when(region.getObjects()).thenReturn(new KList<>());
|
||||
when(region.getProceduralObjects()).thenReturn(proceduralObjects);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getAllObjectScaleFactor()).thenReturn(1D);
|
||||
when(dimension.getAllRegions(any())).thenReturn(new KList<>(region));
|
||||
when(dimension.getReachableBiomes(any())).thenReturn(new KList<>());
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getData()).thenReturn(data);
|
||||
|
||||
assertEquals(27, new MantleObjectComponent(engineMantle).getRadius());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void upperDimensionObjectsDriveRadiusAndCollisionMode() {
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MantleObjectComponentProceduralChanceTest {
|
||||
@Test
|
||||
public void exactChanceBoundariesRemainExact() {
|
||||
for (int seed = 0; seed < 1000; seed++) {
|
||||
RNG rng = new RNG(seed);
|
||||
assertFalse(MantleObjectComponent.passesProceduralChance(rng, 0.0));
|
||||
assertTrue(MantleObjectComponent.passesProceduralChance(rng, 1.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
-47
@@ -4,8 +4,6 @@ import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
@@ -111,37 +109,6 @@ public class MantleObjectComponentWaterPlacementTest {
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void proceduralPlacementOutsideTheTransitionFootprintEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(PLACES);
|
||||
fixture.biome.setProceduralObjects(fixture.proceduralObjects());
|
||||
when(fixture.complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(false);
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedProceduralPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(REJECTS);
|
||||
fixture.biome.setProceduralObjects(fixture.proceduralObjects());
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thrownProceduralPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(THROWS);
|
||||
fixture.biome.setProceduralObjects(fixture.proceduralObjects());
|
||||
|
||||
fixture.generate();
|
||||
|
||||
fixture.assertEndedUnrecorded();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedUpperPlacementEndsWithoutBeingRecorded() {
|
||||
Fixture fixture = new Fixture(REJECTS);
|
||||
@@ -235,20 +202,6 @@ public class MantleObjectComponentWaterPlacementTest {
|
||||
return placement;
|
||||
}
|
||||
|
||||
private IrisProceduralObjects proceduralObjects() {
|
||||
IrisObjectPlacement placement = placement(CarvingMode.SURFACE_ONLY);
|
||||
IrisProceduralPlacement procedural = mock(IrisProceduralPlacement.class);
|
||||
when(procedural.getChance()).thenReturn(2D);
|
||||
when(procedural.getName()).thenReturn("water-procedural");
|
||||
when(procedural.getDensity()).thenReturn(1);
|
||||
when(procedural.asPlacement()).thenReturn(placement);
|
||||
when(procedural.getVariantObject(any(), any(), any())).thenReturn(object);
|
||||
IrisProceduralObjects objects = mock(IrisProceduralObjects.class);
|
||||
when(objects.isEmpty()).thenReturn(false);
|
||||
when(objects.getAllPlacements()).thenReturn(new KList<>(procedural));
|
||||
return objects;
|
||||
}
|
||||
|
||||
private void upperObjects() {
|
||||
IrisObjectPlacement forced = placement(CarvingMode.ANYWHERE);
|
||||
IrisObjectPlacement source = placement(CarvingMode.SURFACE_ONLY);
|
||||
|
||||
-279
@@ -1,279 +0,0 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.cave.CarvingMode;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.decoration.coral.IrisCoral;
|
||||
import art.arcane.iris.generation.decoration.coral.IrisCoralForm;
|
||||
import art.arcane.iris.generation.decoration.crystal.IrisCrystal;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormation;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.subterrain.IrisSubterrainFeature;
|
||||
import art.arcane.iris.generation.subterrain.IrisSubterrainFluid;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlan;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlanner;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPosition;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.nativelib.terrain.BlockStateKey;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NaturalCaveProceduralPlacementTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private final Map<String, NativeBlockState> states = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(registries.block(anyString())).thenAnswer(invocation -> state(invocation.getArgument(0)));
|
||||
when(registries.blockOrNull(anyString())).thenAnswer(invocation -> state(invocation.getArgument(0)));
|
||||
when(registries.blockOrNull(anyString(), eq(false))).thenAnswer(invocation -> state(invocation.getArgument(0)));
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
states.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roomProportionalFormationRestsOnActualFloorWithoutTranslation() {
|
||||
Fixture fixture = fixture(new FixtureOptions(IrisSubterrainFluid.WATER, 0));
|
||||
IrisFormation formation = new IrisFormation().setName("natural-vault").setRoomHeightFraction(0.3)
|
||||
.setHeightMin(90).setHeightMax(90).setBaseWidthMin(1).setBaseWidthMax(1)
|
||||
.setRoughness(0).setLean(0).setJitter(0).setCarvingSupport(CarvingMode.CARVING_ONLY);
|
||||
IrisObject object = variant(formation, fixture);
|
||||
assertTrue(object.getH() <= Math.floor(fixture.room().vaultHeight() * 0.3) + 2);
|
||||
assertTrue(object.getH() > 3);
|
||||
assertTrue(object.getLoadKey().endsWith(fixture.room().featureId()));
|
||||
assertFloorPlacement(object, formation.asPlacement().setRotation(IrisObjectRotation.of(0, 0, 0)), fixture);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crystalBaseAndRotatedShardsRestAboveProtectedCenoteFloor() {
|
||||
for (double angle : List.of(0D, 30D)) {
|
||||
Fixture fixture = fixture(new FixtureOptions(IrisSubterrainFluid.WATER, 0));
|
||||
IrisCrystal crystal = new IrisCrystal().setName("natural-crystal").setVariants(1)
|
||||
.setBaseRadius(1.5).setBaseNoise(0).setShardCountMin(3).setShardCountMax(3)
|
||||
.setShardLengthMin(5).setShardLengthMax(5).setShardBaseRadius(0.5)
|
||||
.setSpreadAngle(10).setJitter(0);
|
||||
IrisObject object = variant(crystal, fixture);
|
||||
assertTrue(object.getH() > 3);
|
||||
IrisObjectPlacement placement = crystal.asPlacement().setRotation(IrisObjectRotation.of(angle, 0, 0));
|
||||
assertFloorPlacement(object, placement, fixture);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submergedCoralUsesOwnedFluidHeadAboveGlobalWaterAndWaterlogsOnlyInWater() {
|
||||
for (IrisSubterrainFluid fluid : IrisSubterrainFluid.values()) {
|
||||
Fixture fixture = fixture(new FixtureOptions(fluid, 12));
|
||||
assertTrue(fixture.room().floorY() > fixture.placer().getFluidHeight(fixture.x(), fixture.z()));
|
||||
IrisCoral coral = coral();
|
||||
IrisObject object = variant(coral, fixture);
|
||||
assertFloorPlacement(object, coral.asPlacement().setRotation(IrisObjectRotation.of(0, 0, 0)), fixture);
|
||||
SubterrainCell.Kind expected = fluid == IrisSubterrainFluid.WATER ? SubterrainCell.Kind.WATER : SubterrainCell.Kind.LAVA;
|
||||
for (Map.Entry<SubterrainPosition, NativeBlockState> entry : fixture.writes().entrySet()) {
|
||||
SubterrainPosition position = entry.getKey();
|
||||
assertEquals(expected, fixture.planner().sample(position.x(), position.y(), position.z()).kind());
|
||||
assertEquals(entry.getValue().key(), fluid == IrisSubterrainFluid.WATER, entry.getValue().isWaterLogged());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authoredDownwardTranslationStillRejectsWholeObjectAtProtectedFloor() {
|
||||
Fixture fixture = fixture(new FixtureOptions(IrisSubterrainFluid.WATER, 0));
|
||||
IrisCrystal crystal = new IrisCrystal().setVariants(1).setBaseRadius(1)
|
||||
.setShardCountMin(1).setShardCountMax(1).setShardLengthMin(4).setShardLengthMax(4)
|
||||
.setSpreadAngle(0).setJitter(0);
|
||||
IrisObject object = variant(crystal, fixture);
|
||||
IrisObjectPlacement placement = crystal.asPlacement().setRotation(IrisObjectRotation.of(0, 0, 0))
|
||||
.setTranslate(new IrisObjectTranslate().setY(-1));
|
||||
CaveObjectPlacementTransaction transaction = transaction(fixture);
|
||||
int firstAirY = MantleObjectComponent.proceduralFloorY(fixture.placer(), fixture.x(), fixture.floorY() + 3, fixture.z());
|
||||
int result = object.placeOnFloor(fixture.x(), firstAirY, fixture.z(), transaction, placement, new RNG(17L),
|
||||
(position, block) -> transaction.setData(position.getX(), position.getY(), position.getZ(), "natural-crystal@1"), fixture.data());
|
||||
assertTrue(result >= 0);
|
||||
assertEquals(CaveObjectPlacementTransaction.CommitResult.REJECTED_SUBTERRAIN, transaction.commit());
|
||||
assertTrue(fixture.writes().isEmpty());
|
||||
assertTrue(fixture.metadata().isEmpty());
|
||||
assertTrue(fixture.placer().get(fixture.x(), fixture.floorY(), fixture.z()).isSolid());
|
||||
}
|
||||
|
||||
private void assertFloorPlacement(IrisObject object, IrisObjectPlacement placement, Fixture fixture) {
|
||||
assertFalse(placement.isBottom());
|
||||
assertEquals(0, placement.getTranslate().getY());
|
||||
CaveObjectPlacementTransaction transaction = transaction(fixture);
|
||||
int firstAirY = MantleObjectComponent.proceduralFloorY(fixture.placer(), fixture.x(), fixture.floorY() + 3, fixture.z());
|
||||
assertEquals(fixture.floorY() + 1, firstAirY);
|
||||
int result = object.placeOnFloor(fixture.x(), firstAirY, fixture.z(), transaction, placement, new RNG(17L),
|
||||
(position, block) -> transaction.setData(position.getX(), position.getY(), position.getZ(), "natural@1"), fixture.data());
|
||||
assertTrue(result >= 0);
|
||||
assertTrue(fixture.writes().isEmpty());
|
||||
assertTrue(fixture.metadata().isEmpty());
|
||||
assertEquals(CaveObjectPlacementTransaction.CommitResult.COMMITTED, transaction.commit());
|
||||
assertFalse(fixture.writes().isEmpty());
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
for (SubterrainPosition position : fixture.writes().keySet()) {
|
||||
lowest = Math.min(lowest, position.y());
|
||||
SubterrainCell cell = fixture.planner().sample(position.x(), position.y(), position.z());
|
||||
assertTrue(cell.occupied());
|
||||
assertFalse(cell.room().reservedPassage());
|
||||
assertTrue(position.y() > cell.room().floorY());
|
||||
assertTrue(position.y() < cell.room().ceilingY());
|
||||
}
|
||||
assertEquals(fixture.floorY() + 1, lowest);
|
||||
boolean supported = false;
|
||||
for (SubterrainPosition position : fixture.writes().keySet()) {
|
||||
if (position.y() == lowest) {
|
||||
assertTrue(fixture.placer().get(position.x(), lowest - 1, position.z()).isSolid());
|
||||
assertFalse(fixture.writes().containsKey(new SubterrainPosition(position.x(), lowest - 1, position.z())));
|
||||
supported = true;
|
||||
}
|
||||
}
|
||||
assertTrue(supported);
|
||||
assertFalse(fixture.metadata().isEmpty());
|
||||
assertFalse(placement.isBottom());
|
||||
}
|
||||
|
||||
private CaveObjectPlacementTransaction transaction(Fixture fixture) {
|
||||
return new CaveObjectPlacementTransaction(fixture.placer(), fixture.floorY() + 3, 6);
|
||||
}
|
||||
|
||||
private IrisObject variant(IrisProceduralPlacement procedural, Fixture fixture) {
|
||||
IrisObject object = procedural.getVariantObject(fixture.data(), new RNG(819L), fixture.room());
|
||||
assertNotNull(object);
|
||||
assertFalse(object.getBlocks().isEmpty());
|
||||
return object;
|
||||
}
|
||||
|
||||
private IrisCoral coral() {
|
||||
return new IrisCoral().setName("natural-coral").setVariants(1).setForm(IrisCoralForm.PILLAR)
|
||||
.setHeightMin(6).setHeightMax(6).setPillarRadius(1).setTipClusterRadius(0)
|
||||
.setBlock("minecraft:tube_coral[waterlogged=true]").setCarvingSupport(CarvingMode.CARVING_ONLY);
|
||||
}
|
||||
|
||||
private Fixture fixture(FixtureOptions options) {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("natural-room").setProbability(1)
|
||||
.setRadius(32).setHeight(40).setFluid(options.fluid()).setFluidDepth(options.fluidDepth())
|
||||
.setPillarSpacing(0).setFormationFraction(0).setWorldYRange(new IrisRange(20, 120));
|
||||
SubterrainPlanner planner = new SubterrainPlanner(new SubterrainPlanner.Options(List.of(feature), 83L, 0, 256, (x, z) -> "test-region"));
|
||||
SubterrainPlan plan = planner.plansForBounds(0, 0, 512, 512).getFirst();
|
||||
int x = plan.centerX() + 8;
|
||||
int z = plan.centerZ() + 8;
|
||||
SubterrainRoom room = plan.sample(x, plan.centerY(), z).room();
|
||||
assertNotNull(room);
|
||||
int floorY = room.floorY();
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getMinHeight()).thenReturn(0);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(220);
|
||||
when(engine.getSubterrainCell(anyInt(), anyInt(), anyInt())).thenAnswer(invocation ->
|
||||
planner.sample(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)));
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
Map<SubterrainPosition, NativeBlockState> writes = new HashMap<>();
|
||||
Map<SubterrainPosition, Object> metadata = new HashMap<>();
|
||||
IObjectPlacer placer = mock(IObjectPlacer.class);
|
||||
when(placer.getEngine()).thenReturn(engine);
|
||||
when(placer.getFluidHeight()).thenReturn(0);
|
||||
when(placer.getFluidHeight(anyInt(), anyInt())).thenReturn(0);
|
||||
when(placer.isUnderwater(anyInt(), anyInt())).thenReturn(options.fluidDepth() > 0);
|
||||
when(placer.get(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
SubterrainPosition position = new SubterrainPosition(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2));
|
||||
NativeBlockState written = writes.get(position);
|
||||
if (written != null) {
|
||||
return written;
|
||||
}
|
||||
SubterrainCell cell = planner.sample(position.x(), position.y(), position.z());
|
||||
return state(cell.owned() ? cell.material() : "minecraft:stone");
|
||||
});
|
||||
when(placer.isCarved(anyInt(), anyInt(), anyInt())).thenAnswer(invocation ->
|
||||
planner.sample(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)).occupied());
|
||||
when(placer.isSolid(anyInt(), anyInt(), anyInt())).thenAnswer(invocation ->
|
||||
placer.get(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)).isSolid());
|
||||
when(placer.isSurfaceSolid(anyInt(), anyInt(), anyInt())).thenAnswer(invocation ->
|
||||
placer.isSolid(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)));
|
||||
doAnswer(invocation -> {
|
||||
writes.put(new SubterrainPosition(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)), invocation.getArgument(3));
|
||||
return null;
|
||||
}).when(placer).set(anyInt(), anyInt(), anyInt(), any());
|
||||
doAnswer(invocation -> {
|
||||
metadata.put(new SubterrainPosition(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)), invocation.getArgument(3));
|
||||
return null;
|
||||
}).when(placer).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
return new Fixture(planner, placer, data, room, x, z, floorY, writes, metadata);
|
||||
}
|
||||
|
||||
private NativeBlockState state(String key) {
|
||||
NativeBlockState cached = states.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
NativeBlockState block = mock(NativeBlockState.class);
|
||||
int properties = key.indexOf('[');
|
||||
String material = properties < 0 ? key : key.substring(0, properties);
|
||||
boolean water = material.equals("minecraft:water");
|
||||
boolean lava = material.equals("minecraft:lava");
|
||||
boolean air = material.endsWith("air");
|
||||
when(block.key()).thenReturn(key);
|
||||
when(block.materialKey()).thenReturn(material);
|
||||
when(block.isSolid()).thenReturn(!air && !water && !lava);
|
||||
when(block.isOccluding()).thenReturn(!air && !water && !lava);
|
||||
when(block.isAir()).thenReturn(air);
|
||||
when(block.isFluid()).thenReturn(water || lava);
|
||||
when(block.isWater()).thenReturn(water);
|
||||
when(block.isAirOrFluid()).thenReturn(air || water || lava);
|
||||
when(block.isWaterLogged()).thenReturn(key.contains("waterlogged=true"));
|
||||
when(block.withProperty(anyString(), anyString())).thenAnswer(invocation ->
|
||||
state(BlockStateKey.withProperty(key, invocation.getArgument(0), invocation.getArgument(1))));
|
||||
states.put(key, block);
|
||||
return block;
|
||||
}
|
||||
|
||||
private record FixtureOptions(IrisSubterrainFluid fluid, int fluidDepth) {
|
||||
}
|
||||
|
||||
private record Fixture(SubterrainPlanner planner, IObjectPlacer placer, IrisData data, SubterrainRoom room,
|
||||
int x, int z, int floorY, Map<SubterrainPosition, NativeBlockState> writes,
|
||||
Map<SubterrainPosition, Object> metadata) {
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -19,7 +19,6 @@ import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.structure.object.ObjectWaterRule;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.iris.structure.object.DecayControlPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
@@ -80,13 +79,12 @@ public class ObjectDestinationTransactionTest {
|
||||
TreeBlockMaterial trunkMaterial = new TreeBlockMaterial("test:trunk");
|
||||
TreeBlockMaterial canopyMaterial = new TreeBlockMaterial("test:canopy");
|
||||
ObjectDestinationTransaction source = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
DecayControlPlacer placer = new DecayControlPlacer(source);
|
||||
for (int x : new int[]{17, 18}) {
|
||||
assertTrue(placer.beginTreeCanopy(new BlockPosition(x, 7, 1)));
|
||||
placer.set(x, 7, 1, canopy);
|
||||
placer.setData(x, 7, 1, "canopy");
|
||||
placer.setData(x, 7, 1, canopyMaterial);
|
||||
placer.endTreeCanopy();
|
||||
assertTrue(source.beginTreeCanopy(new BlockPosition(x, 7, 1)));
|
||||
source.set(x, 7, 1, canopy);
|
||||
source.setData(x, 7, 1, "canopy");
|
||||
source.setData(x, 7, 1, canopyMaterial);
|
||||
source.endTreeCanopy();
|
||||
}
|
||||
ObjectSourcePlan plan = source.sourcePlanSince(0);
|
||||
for (ObjectDestinationTransaction.Mutation mutation : plan.mutationsFor(1, 0)) {
|
||||
|
||||
@@ -2,8 +2,6 @@ package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisFloatingChildBiomes;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.MeteredCache;
|
||||
@@ -145,18 +143,6 @@ public class PlacementReachPackTest {
|
||||
forEachVariant(object, placement, 1D, variant -> verifyCentered(key, variant, placement, reach, statistics));
|
||||
}
|
||||
}
|
||||
for (IrisProceduralPlacement procedural : proceduralPlacements()) {
|
||||
KList<IrisObject> variants = procedural.getVariantObjects(data);
|
||||
if (variants == null) {
|
||||
continue;
|
||||
}
|
||||
IrisObjectPlacement placement = procedural.asPlacement();
|
||||
for (IrisObject variant : variants) {
|
||||
PlacementReach reach = PlacementReach.of(variant, placement, placement.getMaximumScale(dimension));
|
||||
forEachVariant(variant, placement, 1D,
|
||||
scaled -> verifyCentered(variant.getLoadKey(), scaled, placement, reach, statistics));
|
||||
}
|
||||
}
|
||||
assertTrue(statistics.checked > 0);
|
||||
System.out.println("PLACEMENT_REACH_PLACEMENTS placements=" + placements.size() + " " + statistics);
|
||||
}
|
||||
@@ -383,23 +369,6 @@ public class PlacementReachPackTest {
|
||||
return scales;
|
||||
}
|
||||
|
||||
private List<IrisProceduralPlacement> proceduralPlacements() {
|
||||
List<IrisProceduralPlacement> placements = new ArrayList<>();
|
||||
for (IrisRegion region : dimension.getAllRegions(() -> data)) {
|
||||
addProcedural(placements, region.getProceduralObjects());
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(() -> data)) {
|
||||
addProcedural(placements, biome.getProceduralObjects());
|
||||
}
|
||||
return placements;
|
||||
}
|
||||
|
||||
private static void addProcedural(List<IrisProceduralPlacement> placements, IrisProceduralObjects procedural) {
|
||||
if (procedural != null && !procedural.isEmpty()) {
|
||||
placements.addAll(procedural.getAllPlacements());
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] spins(IrisObjectRotation rotation, int axis) {
|
||||
if (rotation == null || !rotation.canRotate()) {
|
||||
return new int[]{0};
|
||||
|
||||
-126
@@ -1,126 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralPlacement;
|
||||
import art.arcane.iris.generation.runtime.GenerationCacheWarmer.ProceduralWarmTask;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class GenerationCacheWarmerParallelTest {
|
||||
@Test
|
||||
public void repeatedIdentitiesKeepTheirSeedOrderWithoutConcurrentCalls() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisProceduralPlacement first = mock(IrisProceduralPlacement.class);
|
||||
IrisProceduralPlacement second = mock(IrisProceduralPlacement.class);
|
||||
List<Long> firstSeeds = new ArrayList<>();
|
||||
List<Long> secondSeeds = new ArrayList<>();
|
||||
AtomicInteger activeFirst = new AtomicInteger();
|
||||
when(first.getVariantObject(same(data), any(RNG.class), isNull())).thenAnswer(invocation -> {
|
||||
assertEquals(1, activeFirst.incrementAndGet());
|
||||
firstSeeds.add(((RNG) invocation.getArgument(1)).getSeed());
|
||||
activeFirst.decrementAndGet();
|
||||
return null;
|
||||
});
|
||||
when(second.getVariantObject(same(data), any(RNG.class), isNull())).thenAnswer(invocation -> {
|
||||
secondSeeds.add(((RNG) invocation.getArgument(1)).getSeed());
|
||||
return null;
|
||||
});
|
||||
GenerationCacheWarmer.warmProcedural(List.of(
|
||||
new ProceduralWarmTask(first, new RNG(11)),
|
||||
new ProceduralWarmTask(second, new RNG(12)),
|
||||
new ProceduralWarmTask(first, new RNG(13)),
|
||||
new ProceduralWarmTask(second, new RNG(14))), data);
|
||||
assertEquals(List.of(11L, 13L), firstSeeds);
|
||||
assertEquals(List.of(12L, 14L), secondSeeds);
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void workerLimitAndReadinessCoverAllBanks() throws Exception {
|
||||
assumeTrue(Runtime.getRuntime().availableProcessors() > 1);
|
||||
int workers = Math.min(4, Runtime.getRuntime().availableProcessors());
|
||||
CountDownLatch started = new CountDownLatch(workers);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
AtomicInteger active = new AtomicInteger();
|
||||
AtomicInteger maximum = new AtomicInteger();
|
||||
AtomicInteger completed = new AtomicInteger();
|
||||
List<ProceduralWarmTask> tasks = new ArrayList<>();
|
||||
for (int index = 0; index < 12; index++) {
|
||||
IrisProceduralPlacement placement = mock(IrisProceduralPlacement.class);
|
||||
when(placement.getVariantObject(isNull(), any(RNG.class), isNull())).thenAnswer(invocation -> {
|
||||
maximum.accumulateAndGet(active.incrementAndGet(), Math::max);
|
||||
started.countDown();
|
||||
try {
|
||||
assertTrue(release.await(5, TimeUnit.SECONDS));
|
||||
completed.incrementAndGet();
|
||||
return null;
|
||||
} finally {
|
||||
active.decrementAndGet();
|
||||
}
|
||||
});
|
||||
tasks.add(new ProceduralWarmTask(placement, new RNG(index)));
|
||||
}
|
||||
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
|
||||
Future<?> warming = executor.submit(() -> GenerationCacheWarmer.warmProcedural(tasks, null));
|
||||
try {
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS));
|
||||
assertThrows(TimeoutException.class, () -> warming.get(50, TimeUnit.MILLISECONDS));
|
||||
} finally {
|
||||
release.countDown();
|
||||
}
|
||||
warming.get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
assertEquals(workers, maximum.get());
|
||||
assertEquals(12, completed.get());
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void failureWaitsForOtherBanksAndKeepsOriginalCause() throws Exception {
|
||||
assumeTrue(Runtime.getRuntime().availableProcessors() > 1);
|
||||
IrisProceduralPlacement failing = mock(IrisProceduralPlacement.class);
|
||||
IrisProceduralPlacement waiting = mock(IrisProceduralPlacement.class);
|
||||
IllegalStateException failure = new IllegalStateException("variant bank failed");
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
when(failing.getVariantObject(isNull(), any(RNG.class), isNull())).thenThrow(failure);
|
||||
when(waiting.getVariantObject(isNull(), any(RNG.class), isNull())).thenAnswer(invocation -> {
|
||||
started.countDown();
|
||||
assertTrue(release.await(5, TimeUnit.SECONDS));
|
||||
return null;
|
||||
});
|
||||
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
|
||||
Future<?> warming = executor.submit(() -> GenerationCacheWarmer.warmProcedural(List.of(
|
||||
new ProceduralWarmTask(failing, new RNG(1)),
|
||||
new ProceduralWarmTask(waiting, new RNG(2))), null));
|
||||
try {
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS));
|
||||
assertThrows(TimeoutException.class, () -> warming.get(50, TimeUnit.MILLISECONDS));
|
||||
} finally {
|
||||
release.countDown();
|
||||
}
|
||||
assertSame(failure, assertThrows(ExecutionException.class,
|
||||
() -> warming.get(5, TimeUnit.SECONDS)).getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,6 @@ final class ModIngestFixture {
|
||||
"biomeScatter": ["minecraft:birch_forest"],
|
||||
"children": ["temperate/plains"],
|
||||
"objects": [{"chance": 0.4, "place": ["trees/oak"]}],
|
||||
"proceduralObjects": {"trees": [{"chance": 0.2}], "ruins": [{"chance": 0.01}]},
|
||||
"decorators": [{"chance": 0.3, "palette": [{"block": "minecraft:short_grass"}]}]
|
||||
}
|
||||
""");
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ModIngesterBiomeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forestModBiomeDropsOverridesChildrenAndTreesWhenItBringsItsOwn() throws Exception {
|
||||
public void forestModBiomeDropsOverridesChildrenAndObjectsWhenItBringsItsOwn() throws Exception {
|
||||
JsonObject biome = ModIngestFixture.readJson(target.resolve("biomes/ingest/examplemod/maple_woods.json"));
|
||||
|
||||
assertEquals("examplemod:maple_woods", biome.get("derivative").getAsString());
|
||||
@@ -81,8 +81,6 @@ public class ModIngesterBiomeTest {
|
||||
assertFalse(biome.has("biomeScatter"));
|
||||
assertFalse(biome.has("children"));
|
||||
assertFalse(biome.has("objects"));
|
||||
assertFalse(biome.getAsJsonObject("proceduralObjects").has("trees"));
|
||||
assertTrue(biome.getAsJsonObject("proceduralObjects").has("ruins"));
|
||||
assertTrue(ModIngestFixture.strings(ModIngestFixture.readJson(target.resolve("regions/temperate.json")).get("landBiomes"))
|
||||
.contains("ingest/examplemod/maple_woods"));
|
||||
}
|
||||
|
||||
-47
@@ -3,10 +3,6 @@ package art.arcane.iris.structure.object;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.formation.FormationGenerator;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormation;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormationForm;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
@@ -575,49 +571,6 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
assertNull(placer.get(1, ANCHOR_Y + 9, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatedGlacialOverhangGrowsPackedIceRootsToTerrain() {
|
||||
NativeBlockState ice = state("minecraft:ice", true);
|
||||
when(ice.isOccluding()).thenReturn(false);
|
||||
NativeBlockState packedIce = state("minecraft:packed_ice", true);
|
||||
IrisMaterialPalette body = mock(IrisMaterialPalette.class);
|
||||
when(body.getPalette()).thenReturn(new KList<>(new IrisBlockData("minecraft:ice")));
|
||||
when(body.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
.thenReturn(ice);
|
||||
IrisMaterialPalette roots = mock(IrisMaterialPalette.class);
|
||||
when(roots.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
.thenReturn(packedIce);
|
||||
IrisFormation formation = new IrisFormation().setForm(IrisFormationForm.OVERHANG)
|
||||
.setHeightMin(16).setHeightMax(25).setBaseWidthMin(5).setBaseWidthMax(8)
|
||||
.setOverhangReach(13).setOverhangDrop(6).setRoughness(0.3).setJitter(0.08)
|
||||
.setBlockPalette(body);
|
||||
IrisObject object = FormationGenerator.generate(formation, 16, new RNG(5055004L + 16L), data);
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
for (int x = -32; x <= 32; x++) {
|
||||
for (int z = -32; z <= 32; z++) {
|
||||
placer.set(x, ANCHOR_Y, z, solid);
|
||||
}
|
||||
}
|
||||
placer.writes().clear();
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.ORGANIC_STILT)
|
||||
.setRotation(IrisObjectRotation.of(0, 0, 0))
|
||||
.setStiltSettings(new IrisStiltSettings().setOrganicMaxScan(96).setOrganicJitter(0)
|
||||
.setOrganicScratch(0).setPalette(roots));
|
||||
|
||||
object.place(0, ANCHOR_Y + object.getCenter().getBlockY() + 12, 0, placer, placement,
|
||||
new RNG(2L), data);
|
||||
|
||||
List<BlockWrite> rootWrites = placer.writesOf(packedIce);
|
||||
assertFalse(rootWrites.isEmpty());
|
||||
assertTrue(rootWrites.stream().anyMatch(write -> write.y() == ANCHOR_Y + 1));
|
||||
for (BlockWrite root : rootWrites) {
|
||||
for (int y = ANCHOR_Y + 1; y < root.y(); y++) {
|
||||
assertSame(packedIce, placer.get(root.x(), y, root.z()));
|
||||
}
|
||||
}
|
||||
assertFalse(placer.writesOf(ice).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludedLowestBlockDoesNotMoveTheFoundationUpIntoTheOriginalObject() {
|
||||
NativeBlockState machine = state("test:machine", true);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormation;
|
||||
import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.IrisObjectTranslate;
|
||||
|
||||
@@ -162,17 +160,6 @@ public class IrisSurfaceSupportTest {
|
||||
assertEquals(-4, updated.getFirst().getBlockY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formationDefaultsToWiderBufferThanObjectDefault() {
|
||||
IrisFormation formation = new IrisFormation();
|
||||
|
||||
assertEquals(2, new IrisObjectPlacement().getSurfaceSupportBuffer());
|
||||
assertEquals(3, formation.asPlacement().getSurfaceSupportBuffer());
|
||||
|
||||
formation.setSurfaceSupportBuffer(0);
|
||||
assertEquals(0, formation.asPlacement().getSurfaceSupportBuffer());
|
||||
}
|
||||
|
||||
private static boolean isUnsupported(IObjectPlacer placer, List<IrisBlockVector> footprint,
|
||||
int buffer, int minSolidDepth) {
|
||||
return IrisSurfaceSupport.isUnsupported(placer, null, 0, 0, null, null, 0, 0, 0,
|
||||
|
||||
Loaded 100 of 103 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user