mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Floating islands generate in the built-ins jar
FloatingModule, FloatingIslands, the island sampling and the floating object placing move to the jar on IrisApi types. Iris answers through a FloatingHost facade: surface biomes, biome lookups and heights, sky biome painting, object footprints, shrinking and the placement of an object against an island face (IslandAnchor). FloatingChildren becomes the per-world FloatingWorld, IslandObjectPlacer the jar's IslandFace, and UndersideTurn turns a footprint the way Iris's flipped rotation does. The island memos key columns by a Column record instead of packed longs, whose Long hash collides along diagonals.
This commit is contained in:
1 parent
d8612fae27
commit
2ae16b9c9e
22 files changed
+1574
-1541
No files matched your search
@@ -84,3 +84,10 @@ include art/arcane/iris/engine/mantle/components/ObjectWarmUp*.class
|
||||
include art/arcane/iris/engine/mantle/components/ObjectLocating*.class
|
||||
include art/arcane/iris/engine/mantle/components/TreeGrowing*.class
|
||||
include art/arcane/iris/engine/object/procedural/**
|
||||
module art.arcane.iris.engine.modifier.FloatingModule
|
||||
include art/arcane/iris/engine/modifier/FloatingIslands*.class
|
||||
include art/arcane/iris/engine/object/terrain/floating/**
|
||||
include art/arcane/iris/engine/mantle/components/FloatingObjectPlacing*.class
|
||||
include art/arcane/iris/engine/mantle/components/FloatingIslandSampleResolver*.class
|
||||
include art/arcane/iris/engine/mantle/components/IslandFace*.class
|
||||
include art/arcane/iris/engine/mantle/components/UndersideTurn*.class
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.builtin.floating;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.terrain.PaletteLayer;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
@@ -37,9 +37,7 @@ import java.util.OptionalInt;
|
||||
/**
|
||||
* A floating island above a biome's terrain, an entry of the biome's {@code floatingChildBiomes}: where its footprint
|
||||
* is, how high it floats, how its top, underside and walls are shaped, and which objects, decorators and water it
|
||||
* gets. Noise and options are IrisApi types; the object placements and palette layers the island hosts are
|
||||
* Iris's own classes, which the host describes itself, so this class leaves the pack module jar only when those
|
||||
* become settings of modules.
|
||||
* gets.
|
||||
*/
|
||||
@Snippet("floating-child-biome")
|
||||
@Desc("Declares a floating biome layer above this biome's terrain. A 2D footprint noise decides which columns are part of the island (threshold + style control blankets, swirls, scattered blobs). The top profile is driven by the target biome's own terrain generators (so a mountains biome produces real peaks, desert produces real dunes). The bottom tail hanging below is a separately configurable noise (pick VASCULAR for drippy roots, FRACTAL_RM_SIMPLEX for crystalline spikes, PERLIN for smooth rounded bowls).")
|
||||
@@ -195,11 +193,11 @@ public final class FloatingChildBiome {
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Additional object placements anchored to the island top.")
|
||||
private List<IrisObjectPlacement> extraObjects = List.of();
|
||||
private List<ObjectPlacement> extraObjects = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Additional object placements that float freely in air, independent of the island. Forced to ObjectPlaceMode.FLOATING.")
|
||||
private List<IrisObjectPlacement> floatingObjects = List.of();
|
||||
private List<ObjectPlacement> floatingObjects = List.of();
|
||||
|
||||
@Desc("Visualization color for this floating child in Iris Studio.")
|
||||
private String color = null;
|
||||
@@ -212,11 +210,11 @@ public final class FloatingChildBiome {
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Object placements that override or supplement the inherited surface objects on the island TOP. Behaviour depends on topObjectMode. INHERIT_ONLY = this list is ignored. MERGE = appended after inherited. REPLACE = used instead of inherited.")
|
||||
private List<IrisObjectPlacement> topObjectOverrides = List.of();
|
||||
private List<ObjectPlacement> topObjectOverrides = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Object placements anchored to the island BOTTOM face. Each entry is auto-inverted 180 degrees around the X axis and placed flush against the lowest solid face of the island, so objects appear to hang upside-down from the underside. WARNING: directional blocks (stairs, doors, slabs) will not render correctly when flipped — use non-directional content (logs, leaves, stone, mycelium, ice, glass) for bottom placements.")
|
||||
private List<IrisObjectPlacement> bottomObjectOverrides = List.of();
|
||||
private List<ObjectPlacement> bottomObjectOverrides = List.of();
|
||||
|
||||
public FloatingChildBiome() {
|
||||
}
|
||||
@@ -366,11 +364,11 @@ public final class FloatingChildBiome {
|
||||
return objectShrinkFactor;
|
||||
}
|
||||
|
||||
public List<IrisObjectPlacement> extraObjects() {
|
||||
public List<ObjectPlacement> extraObjects() {
|
||||
return extraObjects == null ? List.of() : Collections.unmodifiableList(extraObjects);
|
||||
}
|
||||
|
||||
public List<IrisObjectPlacement> floatingObjects() {
|
||||
public List<ObjectPlacement> floatingObjects() {
|
||||
return floatingObjects == null ? List.of() : Collections.unmodifiableList(floatingObjects);
|
||||
}
|
||||
|
||||
@@ -386,11 +384,11 @@ public final class FloatingChildBiome {
|
||||
return bottomObjectMode == null ? OverrideMode.INHERIT_ONLY : bottomObjectMode;
|
||||
}
|
||||
|
||||
public List<IrisObjectPlacement> topObjectOverrides() {
|
||||
public List<ObjectPlacement> topObjectOverrides() {
|
||||
return topObjectOverrides == null ? List.of() : Collections.unmodifiableList(topObjectOverrides);
|
||||
}
|
||||
|
||||
public List<IrisObjectPlacement> bottomObjectOverrides() {
|
||||
public List<ObjectPlacement> bottomObjectOverrides() {
|
||||
return bottomObjectOverrides == null ? List.of() : Collections.unmodifiableList(bottomObjectOverrides);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.builtin.floating;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What {@code iris:floating} asks of Iris beyond the API: the biome of any column, a biome's own terrain height, the sky
|
||||
* biome an island paints, and placing Iris objects against an island. Iris's worlds implement it; a module reaches it
|
||||
* with {@link #of}.
|
||||
*/
|
||||
public interface FloatingHost {
|
||||
/** The host of the world {@code settings} are the pack's of, which must be a world Iris generates. */
|
||||
static FloatingHost of(PackSettings settings) {
|
||||
if (settings instanceof Source source) {
|
||||
return source.floating();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + settings);
|
||||
}
|
||||
|
||||
/** The host of {@code world}, which must be a world Iris generates. */
|
||||
static FloatingHost of(PackWorld world) {
|
||||
if (world instanceof Source source) {
|
||||
return source.floating();
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
|
||||
}
|
||||
|
||||
/** The biome of the column's surface, the biome an island grows from; any column, not only the chunk's. */
|
||||
ResourceId surfaceBiome(int worldX, int worldZ);
|
||||
|
||||
/** The biome {@code key} names in the pack; empty when the pack has none. */
|
||||
Optional<ResourceId> biome(String key);
|
||||
|
||||
/** The height the terrain generators of {@code biome} give the column, as Iris shapes the biome's terrain with {@code seed}. */
|
||||
double biomeHeight(ResourceId biome, int worldX, int worldZ, long seed);
|
||||
|
||||
/**
|
||||
* Paints the sky biome {@code biome} stands for at the column into the blocks {@code ys} of the mantle, where the biome
|
||||
* pass finds it. {@code random} seeds the biome's generator the first time the biome is asked.
|
||||
*/
|
||||
void paintSkyBiome(ResourceId biome, int worldX, int worldZ, int[] ys, RNG random);
|
||||
|
||||
/** Where {@code object} stands: its solid columns, its tallest column and that column's lowest solid block. */
|
||||
IslandFootprint footprint(PlaceableObject object);
|
||||
|
||||
/** {@code object} shrunk by {@code factor} (below 1), the variant picked with {@code random}. */
|
||||
Optional<PlaceableObject> shrink(PlaceableObject object, double factor, RNG random);
|
||||
|
||||
/** Places {@code object} floating free at the column, into the chunk the mantle is generating. */
|
||||
void placeFloating(PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement, RNG random);
|
||||
|
||||
/**
|
||||
* Places {@code object} on an island's top, its lowest block at {@code y}, into the chunk the mantle is generating; nothing
|
||||
* is written unless every block it writes is one {@code anchor} lets it write.
|
||||
*/
|
||||
void placeOnTop(PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IslandAnchor anchor, RNG random);
|
||||
|
||||
/**
|
||||
* Places {@code object} upside down under an island, turned {@code yRotation} degrees about Y, as {@link #placeOnTop} does
|
||||
* on top.
|
||||
*/
|
||||
void placeUnder(PlaceableObject object, int worldX, int y, int worldZ, int yRotation, ObjectPlacement placement,
|
||||
IslandAnchor anchor, RNG random);
|
||||
|
||||
/** A world that hands out its {@link FloatingHost}. */
|
||||
interface Source {
|
||||
FloatingHost floating();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.builtin.floating;
|
||||
|
||||
/**
|
||||
* The face of one island an object is placed against, as {@code iris:floating} samples it: how high the face is, which
|
||||
* blocks of the island are solid, and where the object may write without hanging in the air beside the island.
|
||||
*/
|
||||
public interface IslandAnchor {
|
||||
/** The height of the face at the column; the anchor's own height where the island does not reach. */
|
||||
int faceY(int worldX, int worldZ);
|
||||
|
||||
/** Whether an island lies in the column; where none does, the world's blocks say what is solid. */
|
||||
boolean hasIsland(int worldX, int worldZ);
|
||||
|
||||
/** Whether the island of the column fills the block. */
|
||||
boolean islandSolid(int worldX, int y, int worldZ);
|
||||
|
||||
/** Whether the object may write the block. */
|
||||
boolean writes(int worldX, int y, int worldZ);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.builtin.floating;
|
||||
|
||||
/**
|
||||
* Where an object stands, in its own block positions: the columns holding a solid block ({@link #column} packs each), the
|
||||
* tallest of them (most solid blocks, the lowest bottom on a tie) and the lowest solid block of that column.
|
||||
*/
|
||||
public record IslandFootprint(int tallestX, int tallestZ, int lowestSolidY, long[] columns) {
|
||||
/** The column {@code x}, {@code z} packed as {@link #columns} holds it. */
|
||||
public static long column(int x, int z) {
|
||||
return ((long) x << 32) | (z & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
public static int columnX(long column) {
|
||||
return (int) (column >> 32);
|
||||
}
|
||||
|
||||
public static int columnZ(long column) {
|
||||
return (int) (column & 0xFFFFFFFFL);
|
||||
}
|
||||
}
|
||||
+30
-40
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -18,61 +18,51 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.engine.modifier.FloatingIslands;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingChildren;
|
||||
import art.arcane.iris.engine.object.terrain.floating.Column;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingWorld;
|
||||
import com.volmit.ModuleLog;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
final class FloatingIslandSampleResolver implements IslandObjectPlacer.SampleProvider {
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
private final int chunkHeight;
|
||||
private final long baseSeed;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** The island samples of the columns one chunk's floating objects ask about, each sampled once; null where no island is. */
|
||||
final class FloatingIslandSampleResolver implements IslandFace.SampleProvider {
|
||||
private final FloatingWorld world;
|
||||
private final int worldHeight;
|
||||
private final FloatingIslandBoundarySampler boundarySampler;
|
||||
private final Long2ObjectOpenHashMap<FloatingIslandSample> sampleCache;
|
||||
private final LongOpenHashSet resolvedSamples;
|
||||
private final Map<Column, FloatingIslandSample> samples = new HashMap<>();
|
||||
private final ModuleLog log;
|
||||
|
||||
FloatingIslandSampleResolver(EngineMantle engineMantle, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
this.data = engineMantle.getData();
|
||||
this.engine = engineMantle.getEngine();
|
||||
this.chunkHeight = engine.getHeight();
|
||||
this.baseSeed = engine.getSeedManager().getTerrain() ^ FloatingIslands.FLOATING_BASE_SEED_SALT;
|
||||
FloatingIslandSampleResolver(FloatingWorld world, int worldHeight, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
this.world = world;
|
||||
this.worldHeight = worldHeight;
|
||||
this.boundarySampler = boundarySampler;
|
||||
this.log = log;
|
||||
this.sampleCache = new Long2ObjectOpenHashMap<>();
|
||||
this.resolvedSamples = new LongOpenHashSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FloatingIslandSample sample(int x, int z) {
|
||||
long key = CacheKey.key(x, z);
|
||||
if (resolvedSamples.contains(key)) {
|
||||
return sampleCache.get(key);
|
||||
}
|
||||
IrisBiome parent = parent(x, z);
|
||||
if (parent == null || FloatingChildren.declaredBy(parent).isEmpty()) {
|
||||
resolvedSamples.add(key);
|
||||
return null;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sample(parent, x, z, chunkHeight, baseSeed, data, engine, boundarySampler, log);
|
||||
resolvedSamples.add(key);
|
||||
if (sample != null) {
|
||||
sampleCache.put(key, sample);
|
||||
public FloatingIslandSample sample(int x, int z) {
|
||||
Column key = new Column(x, z);
|
||||
if (samples.containsKey(key)) {
|
||||
return samples.get(key);
|
||||
}
|
||||
FloatingIslandSample sample = resolve(x, z);
|
||||
samples.put(key, sample);
|
||||
return sample;
|
||||
}
|
||||
|
||||
@Nullable IrisBiome parent(int x, int z) {
|
||||
private FloatingIslandSample resolve(int x, int z) {
|
||||
ResourceId parent = parent(x, z);
|
||||
if (parent == null || world.declaredBy(parent).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return FloatingIslandSample.sample(parent, x, z, worldHeight, world, boundarySampler, log);
|
||||
}
|
||||
|
||||
ResourceId parent(int x, int z) {
|
||||
return boundarySampler.parent(x, z);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -30,19 +30,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
private final IslandObjectPlacer delegate;
|
||||
public final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
private final IslandAnchorPlacer delegate;
|
||||
private final KList<BufferedMutation> mutations;
|
||||
private final Map<PositionKey, PlatformBlockState> bufferedBlocks;
|
||||
private int blockWrites;
|
||||
|
||||
FloatingObjectPlacementTransaction(IslandObjectPlacer delegate) {
|
||||
public FloatingObjectPlacementTransaction(IslandAnchorPlacer delegate) {
|
||||
this.delegate = delegate;
|
||||
this.mutations = new KList<>();
|
||||
this.bufferedBlocks = new HashMap<>();
|
||||
}
|
||||
|
||||
CommitResult commit() {
|
||||
public CommitResult commit() {
|
||||
if (blockWrites == 0) {
|
||||
discard();
|
||||
return CommitResult.EMPTY;
|
||||
@@ -60,7 +60,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
return CommitResult.COMMITTED;
|
||||
}
|
||||
|
||||
void discard() {
|
||||
public void discard() {
|
||||
mutations.clear();
|
||||
bufferedBlocks.clear();
|
||||
blockWrites = 0;
|
||||
@@ -167,7 +167,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
return delegate.getEngine();
|
||||
}
|
||||
|
||||
enum CommitResult {
|
||||
public enum CommitResult {
|
||||
COMMITTED,
|
||||
EMPTY,
|
||||
REJECTED_SUPPORT
|
||||
|
||||
+328
-503
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,413 +18,311 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingChildren;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.floating.IslandFootprint;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSize;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectVacuum;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingWorld;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.documentation.ChunkCoordinates;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.ModuleLog;
|
||||
import java.io.File;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.MantleStageContext;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Places the objects of floating child biomes on and under their islands into the mantle for
|
||||
* {@link art.arcane.iris.engine.modifier.FloatingModule}. One per engine runtime. Its reach is the
|
||||
* largest placement reach of any floating object the dimension's biomes can place, at least 16 blocks.
|
||||
* {@link art.arcane.iris.engine.modifier.FloatingModule}. One per world. Its reach is the largest placement reach of any
|
||||
* floating object the dimension's biomes can place, at least 16 blocks.
|
||||
*/
|
||||
public class FloatingObjectPlacing {
|
||||
public final class FloatingObjectPlacing {
|
||||
private static final int INVERTED_PICK_ATTEMPTS = 8;
|
||||
private static final IrisObjectRotation ROTATION_NONE = IrisObjectRotation.of(0, 0, 0);
|
||||
private static final long CHUNK_RANDOM_SALT = 0x0FA710BEL;
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int CHUNK_COLUMNS = 256;
|
||||
private static final int MIN_REACH_BLOCKS = 16;
|
||||
private static final int LARGE_REACH_WARNING_BLOCKS = 128;
|
||||
private static final int FLAT_TOLERANCE_BLOCKS = 2;
|
||||
private static final int LOOSE_FLAT_TOLERANCE_BLOCKS = 4;
|
||||
private static final int QUARTER_TURN_DEGREES = 90;
|
||||
private static final int QUARTER_TURNS = 4;
|
||||
private static final double CHANCE_JITTER = 0.005;
|
||||
private static final String BIOME_PATH_PREFIX = "biome/";
|
||||
|
||||
private final Engine engine;
|
||||
private final FloatingWorld world;
|
||||
private final FloatingHost host;
|
||||
private final ObjectHost objects;
|
||||
private final long mantleSeed;
|
||||
private final ModuleLog log;
|
||||
|
||||
public FloatingObjectPlacing(Engine engine, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
FloatingObjectPlacing(FloatingWorld world, long mantleSeed, ModuleLog log) {
|
||||
this.world = world;
|
||||
this.host = world.host();
|
||||
this.objects = world.objects();
|
||||
this.mantleSeed = mantleSeed;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/** Places what originates in the chunk at chunk coordinates {@code x}, {@code z} into {@code writer}. */
|
||||
public void place(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||
IrisComplex complex = context.getComplex();
|
||||
IrisData data = engine.getData();
|
||||
int minX = x << 4;
|
||||
int minZ = z << 4;
|
||||
RNG chunkRng = new RNG(CacheKey.key(x, z) + engine.getSeedManager().getMantle() + 0x0FA710BEL);
|
||||
FloatingIslandSampleResolver sampleResolver = new FloatingIslandSampleResolver(engine.getMantle(), context.getFloatingIslandBoundarySampler(), log);
|
||||
/** The floating object placing of {@code world}. */
|
||||
public static FloatingObjectPlacing of(PackWorld world, ModuleLog log) {
|
||||
return world.state(FloatingObjectPlacing.class,
|
||||
generating -> new FloatingObjectPlacing(FloatingWorld.of(generating), IrisSeed.MANTLE.of(generating), log));
|
||||
}
|
||||
|
||||
/** Places what originates in the chunk of {@code context} into the mantle. */
|
||||
public void place(MantleStageContext context) {
|
||||
int minX = context.originX();
|
||||
int minZ = context.originZ();
|
||||
BlockBox bounds = context.terrain().bounds();
|
||||
int worldHeight = bounds.maxY() - bounds.minY();
|
||||
RNG chunkRng = new RNG(CacheKey.key(minX >> CHUNK_SHIFT, minZ >> CHUNK_SHIFT) + mantleSeed + CHUNK_RANDOM_SALT);
|
||||
FloatingIslandSampleResolver samples = new FloatingIslandSampleResolver(world, worldHeight,
|
||||
new FloatingIslandBoundarySampler(host::surfaceBiome), log);
|
||||
|
||||
FloatingIslandSample.clearChunkMemo();
|
||||
Chunk chunk = new Chunk(minX, minZ, worldHeight, chunkRng, samples, sampleColumns(samples, minX, minZ));
|
||||
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
for (int xf = 0; xf < 16; xf++) {
|
||||
for (int zf = 0; zf < 16; zf++) {
|
||||
int wx = minX + xf;
|
||||
int wz = minZ + zf;
|
||||
FloatingIslandSample sample = sampleResolver.sample(wx, wz);
|
||||
if (sample != null) {
|
||||
samples[(zf << 4) | xf] = sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The IdentityHashMaps are lookup indices only. Iteration MUST follow the encounter
|
||||
// order of the deterministic 0..255 column scan: identity-hash order changes per JVM
|
||||
// run, and the shared chunkRng makes placement output depend on iteration order.
|
||||
IdentityHashMap<ResolvedFloatingChild, KList<Integer>> entryColumns = new IdentityHashMap<>();
|
||||
IdentityHashMap<ResolvedFloatingChild, KList<Integer>> bottomEntryColumns = new IdentityHashMap<>();
|
||||
// The maps are lookup indices only. Iteration MUST follow the encounter order of the deterministic 0..255 column
|
||||
// scan: identity-hash order changes per JVM run, and the shared chunk random makes placement output depend on order.
|
||||
Map<ResolvedFloatingChild, KList<Integer>> entryColumns = new IdentityHashMap<>();
|
||||
Map<ResolvedFloatingChild, KList<Integer>> bottomEntryColumns = new IdentityHashMap<>();
|
||||
KList<ResolvedFloatingChild> entryOrder = new KList<>();
|
||||
KList<ResolvedFloatingChild> bottomEntryOrder = new KList<>();
|
||||
for (int i = 0; i < 256; i++) {
|
||||
FloatingIslandSample s = samples[i];
|
||||
if (s == null || s.entry == null) {
|
||||
for (int i = 0; i < CHUNK_COLUMNS; i++) {
|
||||
FloatingIslandSample sample = chunk.samples[i];
|
||||
if (sample == null || sample.entry == null) {
|
||||
continue;
|
||||
}
|
||||
entryColumns.computeIfAbsent(s.entry, e -> {
|
||||
entryOrder.add(e);
|
||||
int column = i;
|
||||
entryColumns.computeIfAbsent(sample.entry, entry -> {
|
||||
entryOrder.add(entry);
|
||||
return new KList<>();
|
||||
}).add(i);
|
||||
ResolvedFloatingChild bottomEntry = s.bottomEntry();
|
||||
}).add(column);
|
||||
ResolvedFloatingChild bottomEntry = sample.bottomEntry();
|
||||
if (bottomEntry != null) {
|
||||
bottomEntryColumns.computeIfAbsent(bottomEntry, e -> {
|
||||
bottomEntryOrder.add(e);
|
||||
bottomEntryColumns.computeIfAbsent(bottomEntry, entry -> {
|
||||
bottomEntryOrder.add(entry);
|
||||
return new KList<>();
|
||||
}).add(i);
|
||||
}).add(column);
|
||||
}
|
||||
}
|
||||
|
||||
for (ResolvedFloatingChild entry : entryOrder) {
|
||||
KList<Integer> columns = entryColumns.get(entry);
|
||||
if (columns.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int firstKey = columns.get(0);
|
||||
IrisBiome parent = sampleResolver.parent(minX + (firstKey & 15), minZ + (firstKey >> 4));
|
||||
IrisBiome target = entry.getRealBiome(parent, data);
|
||||
|
||||
KList<IrisObjectPlacement> floating = new KList<>(entry.settings().floatingObjects());
|
||||
if (floating != null && !floating.isEmpty()) {
|
||||
for (IrisObjectPlacement placement : floating) {
|
||||
tryPlaceFloatingChunk(writer, complex, chunkRng, data, placement, columns, minX, minZ, entry);
|
||||
}
|
||||
}
|
||||
|
||||
KList<IrisObjectPlacement> surface = target != null ? entry.resolveTopObjects(target) : null;
|
||||
KList<IrisObjectPlacement> extras = new KList<>(entry.settings().extraObjects());
|
||||
boolean hasSurface = surface != null && !surface.isEmpty();
|
||||
boolean hasExtras = extras != null && !extras.isEmpty();
|
||||
KList<Integer> interior = null;
|
||||
if (hasSurface || hasExtras) {
|
||||
interior = interiorColumns(sampleResolver, columns, minX, minZ, entry, IslandObjectPlacer.AnchorFace.TOP);
|
||||
if (hasSurface) {
|
||||
for (IrisObjectPlacement placement : surface) {
|
||||
tryPlaceAnchoredChunk(writer, complex, chunkRng, data, placement, samples, sampleResolver, columns, interior, minX, minZ, entry);
|
||||
}
|
||||
}
|
||||
if (hasExtras) {
|
||||
for (IrisObjectPlacement placement : extras) {
|
||||
tryPlaceAnchoredChunk(writer, complex, chunkRng, data, placement, samples, sampleResolver, columns, interior, minX, minZ, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOnTop(chunk, entry, entryColumns.get(entry));
|
||||
}
|
||||
|
||||
for (ResolvedFloatingChild entry : bottomEntryOrder) {
|
||||
KList<Integer> columns = bottomEntryColumns.get(entry);
|
||||
if (columns.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int firstKey = columns.get(0);
|
||||
IrisBiome parent = sampleResolver.parent(minX + (firstKey & 15), minZ + (firstKey >> 4));
|
||||
IrisBiome target = entry.getRealBiome(parent, data);
|
||||
KList<IrisObjectPlacement> bottom = target != null ? entry.resolveBottomObjects(target) : null;
|
||||
if (bottom != null && !bottom.isEmpty()) {
|
||||
KList<Integer> interior = interiorColumns(sampleResolver, columns, minX, minZ, entry, IslandObjectPlacer.AnchorFace.BOTTOM);
|
||||
for (IrisObjectPlacement placement : bottom) {
|
||||
tryPlaceInvertedChunk(writer, complex, chunkRng, data, placement, samples, sampleResolver, columns, interior, minX, minZ, entry);
|
||||
}
|
||||
}
|
||||
placeUnder(chunk, entry, bottomEntryColumns.get(entry));
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void tryPlaceFloatingChunk(MantleWriter writer, IrisComplex complex, RNG rng, IrisData data, IrisObjectPlacement placement, KList<Integer> columns, int minX, int minZ, ResolvedFloatingChild entry) {
|
||||
if (placement == null || columns == null || columns.isEmpty()) {
|
||||
private static FloatingIslandSample[] sampleColumns(FloatingIslandSampleResolver samples, int minX, int minZ) {
|
||||
FloatingIslandSample[] sampled = new FloatingIslandSample[CHUNK_COLUMNS];
|
||||
for (int xf = 0; xf < 16; xf++) {
|
||||
for (int zf = 0; zf < 16; zf++) {
|
||||
sampled[(zf << 4) | xf] = samples.sample(minX + xf, minZ + zf);
|
||||
}
|
||||
}
|
||||
return sampled;
|
||||
}
|
||||
|
||||
private void placeOnTop(Chunk chunk, ResolvedFloatingChild entry, KList<Integer> columns) {
|
||||
if (columns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int density = placement.getDensity(rng, minX, minZ, data);
|
||||
double perAttempt = placement.getChance();
|
||||
for (int i = 0; i < density; i++) {
|
||||
if (!rng.chance(perAttempt + rng.d(-0.005, 0.005))) {
|
||||
continue;
|
||||
}
|
||||
IrisObject raw = placement.getObject(complex, rng);
|
||||
if (raw == null) {
|
||||
continue;
|
||||
}
|
||||
IrisObject obj0 = placement.getScale().get(rng, raw, engine);
|
||||
if (obj0 == null) {
|
||||
continue;
|
||||
}
|
||||
if (entry != null && entry.hasObjectShrink()) {
|
||||
obj0 = entry.getShrinkScale().get(rng, obj0, engine);
|
||||
if (obj0 == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
final IrisObject obj = obj0;
|
||||
ResourceId target = targetOf(chunk, entry, columns);
|
||||
|
||||
for (ObjectPlacement placement : entry.settings().floatingObjects()) {
|
||||
placeFloating(chunk, placement, columns, entry);
|
||||
}
|
||||
|
||||
KList<ObjectPlacement> surface = target != null ? entry.resolveTopObjects(target) : null;
|
||||
List<ObjectPlacement> extras = entry.settings().extraObjects();
|
||||
boolean hasSurface = surface != null && !surface.isEmpty();
|
||||
if (!hasSurface && extras.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
KList<Integer> interior = interiorColumns(chunk, columns, entry, IslandFace.Side.TOP);
|
||||
if (hasSurface) {
|
||||
for (ObjectPlacement placement : surface) {
|
||||
placeAnchored(chunk, placement, columns, interior, entry);
|
||||
}
|
||||
}
|
||||
for (ObjectPlacement placement : extras) {
|
||||
placeAnchored(chunk, placement, columns, interior, entry);
|
||||
}
|
||||
}
|
||||
|
||||
private void placeUnder(Chunk chunk, ResolvedFloatingChild entry, KList<Integer> columns) {
|
||||
if (columns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ResourceId target = targetOf(chunk, entry, columns);
|
||||
KList<ObjectPlacement> bottom = target != null ? entry.resolveBottomObjects() : null;
|
||||
if (bottom == null || bottom.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
KList<Integer> interior = interiorColumns(chunk, columns, entry, IslandFace.Side.BOTTOM);
|
||||
for (ObjectPlacement placement : bottom) {
|
||||
placeInverted(chunk, placement, columns, interior, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/** The biome the child's objects come from, its parent taken at the first of its columns. */
|
||||
private ResourceId targetOf(Chunk chunk, ResolvedFloatingChild entry, KList<Integer> columns) {
|
||||
int firstKey = columns.get(0);
|
||||
ResourceId parent = chunk.resolver.parent(chunk.minX + (firstKey & 15), chunk.minZ + (firstKey >> 4));
|
||||
return entry.realBiome(parent);
|
||||
}
|
||||
|
||||
private void placeFloating(Chunk chunk, ObjectPlacement placement, KList<Integer> columns, ResolvedFloatingChild entry) {
|
||||
RNG rng = chunk.rng;
|
||||
int density = objects.density(placement, rng, chunk.minX, chunk.minZ);
|
||||
for (int i = 0; i < density; i++) {
|
||||
Optional<PlaceableObject> picked = pick(placement, entry, rng);
|
||||
if (picked.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
int key = columns.get(rng.i(columns.size()));
|
||||
int xx = minX + (key & 15);
|
||||
int zz = minZ + (key >> 4);
|
||||
IrisObjectPlacement floatingPlacement = placement.toPlacement(obj.getLoadKey());
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
obj.place(xx, -1, zz, writer, floatingPlacement, rng, (b, bd) -> {
|
||||
String marker = placementMarker(obj, id);
|
||||
if (marker != null && shouldWritePlacementMarker(writer, bd, b.getX(), b.getY(), b.getZ())) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
}, null, data);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to place a floating object", e);
|
||||
}
|
||||
host.placeFloating(picked.get(), chunk.minX + (key & 15), chunk.minZ + (key >> 4), placement, rng);
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void tryPlaceAnchoredChunk(MantleWriter writer, IrisComplex complex, RNG rng, IrisData data, IrisObjectPlacement placement, FloatingIslandSample[] samples, IslandObjectPlacer.SampleProvider sampleProvider, KList<Integer> columns, KList<Integer> interior, int minX, int minZ, ResolvedFloatingChild entry) {
|
||||
if (placement == null || columns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int density = placement.getDensity(rng, minX, minZ, data);
|
||||
double perAttempt = placement.getChance();
|
||||
|
||||
private void placeAnchored(Chunk chunk, ObjectPlacement placement, KList<Integer> columns, KList<Integer> interior,
|
||||
ResolvedFloatingChild entry) {
|
||||
RNG rng = chunk.rng;
|
||||
int density = objects.density(placement, rng, chunk.minX, chunk.minZ);
|
||||
for (int i = 0; i < density; i++) {
|
||||
if (!rng.chance(perAttempt + rng.d(-0.005, 0.005))) {
|
||||
Optional<PlaceableObject> picked = pick(placement, entry, rng);
|
||||
if (picked.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IrisObject raw = placement.getObject(complex, rng);
|
||||
if (raw == null) {
|
||||
continue;
|
||||
}
|
||||
IrisObject obj0 = placement.getScale().get(rng, raw, engine);
|
||||
if (obj0 == null) {
|
||||
continue;
|
||||
}
|
||||
if (entry != null && entry.hasObjectShrink()) {
|
||||
obj0 = entry.getShrinkScale().get(rng, obj0, engine);
|
||||
if (obj0 == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
final IrisObject obj = obj0;
|
||||
|
||||
FloatingObjectFootprint fp = FloatingObjectFootprint.compute(obj);
|
||||
PlaceableObject object = picked.get();
|
||||
IslandFootprint footprint = host.footprint(object);
|
||||
|
||||
KList<Integer> pool = interior.isEmpty() ? columns : interior;
|
||||
|
||||
int pickedKey = pool.get(rng.i(pool.size()));
|
||||
int pickedXf = pickedKey & 15;
|
||||
int pickedZf = pickedKey >> 4;
|
||||
FloatingIslandSample pickedSample = samples[(pickedZf << 4) | pickedXf];
|
||||
FloatingIslandSample pickedSample = chunk.samples[(pickedZf << 4) | pickedXf];
|
||||
if (pickedSample == null) {
|
||||
continue;
|
||||
}
|
||||
int pickTopY = pickedSample.topY();
|
||||
|
||||
int pickedX = minX + pickedXf;
|
||||
int pickedZ = minZ + pickedZf;
|
||||
if (!isFootprintFlat(fp, pickedX, pickedZ, pickTopY, sampleProvider, entry, 2)) {
|
||||
if (!isFootprintFlat(fp, pickedX, pickedZ, pickTopY, sampleProvider, entry, 4)) {
|
||||
continue;
|
||||
}
|
||||
int pickedX = chunk.minX + pickedXf;
|
||||
int pickedZ = chunk.minZ + pickedZf;
|
||||
if (!isFootprintFlat(footprint, pickedX, pickedZ, pickTopY, chunk.resolver, entry, FLAT_TOLERANCE_BLOCKS)
|
||||
&& !isFootprintFlat(footprint, pickedX, pickedZ, pickTopY, chunk.resolver, entry, LOOSE_FLAT_TOLERANCE_BLOCKS)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int wx = minX + pickedXf - fp.getTallestKx();
|
||||
int wz = minZ + pickedZf - fp.getTallestKz();
|
||||
|
||||
IrisObjectPlacement anchored = placement.toPlacement(obj.getLoadKey());
|
||||
anchored.setMode(anchored.getMode().onFloatingIsland());
|
||||
anchored.setTranslate(new IrisObjectTranslate());
|
||||
anchored.setRotation(ROTATION_NONE);
|
||||
anchored.setForcePlace(true);
|
||||
anchored.setBottom(false);
|
||||
|
||||
int yv = pickTopY + 1 - fp.getLowestSolidKeyY();
|
||||
|
||||
IslandObjectPlacer islandPlacer = IslandObjectPlacer.top(writer, sampleProvider, entry, pickTopY);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer);
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
int resultY = obj.place(wx, yv, wz, transaction, anchored, rng, (b, bd) -> {
|
||||
String marker = placementMarker(obj, id);
|
||||
if (marker != null && shouldWritePlacementMarker(transaction, bd, b.getX(), b.getY(), b.getZ())) {
|
||||
transaction.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
}, null, data);
|
||||
if (resultY < 0) {
|
||||
transaction.discard();
|
||||
} else {
|
||||
transaction.commit();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
transaction.discard();
|
||||
log.error("Failed to place an anchored floating object", e);
|
||||
}
|
||||
int x = pickedX - footprint.tallestX();
|
||||
int z = pickedZ - footprint.tallestZ();
|
||||
int y = pickTopY + 1 - footprint.lowestSolidY();
|
||||
host.placeOnTop(object, x, y, z, placement, IslandFace.top(chunk.resolver, entry, pickTopY, chunk.worldHeight), rng);
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void tryPlaceInvertedChunk(MantleWriter writer, IrisComplex complex, RNG rng, IrisData data, IrisObjectPlacement placement, FloatingIslandSample[] samples, IslandObjectPlacer.SampleProvider sampleProvider, KList<Integer> columns, KList<Integer> interior, int minX, int minZ, ResolvedFloatingChild entry) {
|
||||
if (placement == null || columns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int density = placement.getDensity(rng, minX, minZ, data);
|
||||
double perAttempt = placement.getChance();
|
||||
|
||||
private void placeInverted(Chunk chunk, ObjectPlacement placement, KList<Integer> columns, KList<Integer> interior,
|
||||
ResolvedFloatingChild entry) {
|
||||
RNG rng = chunk.rng;
|
||||
int density = objects.density(placement, rng, chunk.minX, chunk.minZ);
|
||||
for (int i = 0; i < density; i++) {
|
||||
if (!rng.chance(perAttempt + rng.d(-0.005, 0.005))) {
|
||||
Optional<PlaceableObject> picked = pick(placement, entry, rng);
|
||||
if (picked.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
PlaceableObject object = picked.get();
|
||||
IslandFootprint footprint = host.footprint(object);
|
||||
UndersideTurn turn = new UndersideTurn(rng.i(QUARTER_TURNS) * QUARTER_TURN_DEGREES);
|
||||
|
||||
IrisObject raw = placement.getObject(complex, rng);
|
||||
if (raw == null) {
|
||||
Optional<BottomAnchor> anchor = pickBottomAnchor(chunk, footprint, turn, interior.isEmpty() ? columns : interior, entry);
|
||||
if (anchor.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
IrisObject obj0 = placement.getScale().get(rng, raw, engine);
|
||||
if (obj0 == null) {
|
||||
continue;
|
||||
}
|
||||
if (entry != null && entry.hasObjectShrink()) {
|
||||
obj0 = entry.getShrinkScale().get(rng, obj0, engine);
|
||||
if (obj0 == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
final IrisObject obj = obj0;
|
||||
|
||||
FloatingObjectFootprint fp = FloatingObjectFootprint.compute(obj);
|
||||
int invertedYRotation = rng.i(4) * 90;
|
||||
IrisObjectRotation invertedRotation = IrisObjectRotation.xFlip180WithY(invertedYRotation);
|
||||
|
||||
KList<Integer> pool = interior.isEmpty() ? columns : interior;
|
||||
|
||||
int pickedXf = -1;
|
||||
int pickedZf = -1;
|
||||
int pickBottomY = -1;
|
||||
boolean foundBottomAnchor = false;
|
||||
for (int attempt = 0; attempt < INVERTED_PICK_ATTEMPTS; attempt++) {
|
||||
int pickedKey = pool.get(rng.i(pool.size()));
|
||||
int candidateXf = pickedKey & 15;
|
||||
int candidateZf = pickedKey >> 4;
|
||||
FloatingIslandSample candidateSample = samples[(candidateZf << 4) | candidateXf];
|
||||
if (candidateSample == null) {
|
||||
continue;
|
||||
}
|
||||
int candidateBottomY = candidateSample.bottomY();
|
||||
if (candidateBottomY < 0) {
|
||||
continue;
|
||||
}
|
||||
int candidateX = minX + candidateXf;
|
||||
int candidateZ = minZ + candidateZf;
|
||||
if (!isFootprintFlatBottom(fp, invertedRotation, candidateX, candidateZ, candidateBottomY, sampleProvider, entry, 2)
|
||||
&& !isFootprintFlatBottom(fp, invertedRotation, candidateX, candidateZ, candidateBottomY, sampleProvider, entry, 4)) {
|
||||
continue;
|
||||
}
|
||||
pickedXf = candidateXf;
|
||||
pickedZf = candidateZf;
|
||||
pickBottomY = candidateBottomY;
|
||||
foundBottomAnchor = true;
|
||||
break;
|
||||
}
|
||||
if (!foundBottomAnchor) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int wx = invertedBaseX(minX, pickedXf, fp, invertedRotation);
|
||||
int wz = invertedBaseZ(minZ, pickedZf, fp, invertedRotation);
|
||||
|
||||
IrisObjectPlacement inverted = placement.toPlacement(obj.getLoadKey());
|
||||
inverted.setMode(inverted.getMode().onFloatingIsland());
|
||||
inverted.setTranslate(new IrisObjectTranslate());
|
||||
inverted.setRotation(invertedRotation);
|
||||
inverted.setForcePlace(true);
|
||||
inverted.setBottom(false);
|
||||
|
||||
int yv = invertedBaseY(pickBottomY, fp, invertedRotation);
|
||||
|
||||
IslandObjectPlacer islandPlacer = IslandObjectPlacer.bottom(writer, sampleProvider, entry, pickBottomY);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer);
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
int resultY = obj.place(wx, yv, wz, transaction, inverted, rng, (b, bd) -> {
|
||||
String marker = placementMarker(obj, id);
|
||||
if (marker != null && shouldWritePlacementMarker(transaction, bd, b.getX(), b.getY(), b.getZ())) {
|
||||
transaction.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
}, null, data);
|
||||
if (resultY < 0) {
|
||||
transaction.discard();
|
||||
} else {
|
||||
transaction.commit();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
transaction.discard();
|
||||
log.error("Failed to place an inverted floating object", e);
|
||||
}
|
||||
int pickedXf = anchor.get().xf();
|
||||
int pickedZf = anchor.get().zf();
|
||||
int pickBottomY = anchor.get().bottomY();
|
||||
int x = invertedBaseX(chunk.minX, pickedXf, footprint, turn);
|
||||
int z = invertedBaseZ(chunk.minZ, pickedZf, footprint, turn);
|
||||
int y = invertedBaseY(pickBottomY, footprint, turn);
|
||||
host.placeUnder(object, x, y, z, turn.yRotation(), placement,
|
||||
IslandFace.bottom(chunk.resolver, entry, pickBottomY, chunk.worldHeight), rng);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isFootprintFlatBottom(FloatingObjectFootprint fp, IrisObjectRotation rotation,
|
||||
int pickedX, int pickedZ, int pickBottomY,
|
||||
IslandObjectPlacer.SampleProvider samples,
|
||||
ResolvedFloatingChild entry, int tolerance) {
|
||||
IrisBlockVector anchor = invertedFootprintAnchor(fp, rotation);
|
||||
long[] cells = fp.footprintXZ();
|
||||
private Optional<BottomAnchor> pickBottomAnchor(Chunk chunk, IslandFootprint footprint, UndersideTurn turn, KList<Integer> pool,
|
||||
ResolvedFloatingChild entry) {
|
||||
for (int attempt = 0; attempt < INVERTED_PICK_ATTEMPTS; attempt++) {
|
||||
int pickedKey = pool.get(chunk.rng.i(pool.size()));
|
||||
int candidateXf = pickedKey & 15;
|
||||
int candidateZf = pickedKey >> 4;
|
||||
FloatingIslandSample candidate = chunk.samples[(candidateZf << 4) | candidateXf];
|
||||
if (candidate == null) {
|
||||
continue;
|
||||
}
|
||||
int candidateBottomY = candidate.bottomY();
|
||||
if (candidateBottomY < 0) {
|
||||
continue;
|
||||
}
|
||||
int candidateX = chunk.minX + candidateXf;
|
||||
int candidateZ = chunk.minZ + candidateZf;
|
||||
if (!isFootprintFlatBottom(footprint, turn, candidateX, candidateZ, candidateBottomY, chunk.resolver, entry, FLAT_TOLERANCE_BLOCKS)
|
||||
&& !isFootprintFlatBottom(footprint, turn, candidateX, candidateZ, candidateBottomY, chunk.resolver, entry,
|
||||
LOOSE_FLAT_TOLERANCE_BLOCKS)) {
|
||||
continue;
|
||||
}
|
||||
return Optional.of(new BottomAnchor(candidateXf, candidateZf, candidateBottomY));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** One draw of the chance, then the object the placement picks, scaled, and shrunk as the island shrinks its objects. */
|
||||
private Optional<PlaceableObject> pick(ObjectPlacement placement, ResolvedFloatingChild entry, RNG rng) {
|
||||
if (!rng.chance(placement.chance() + rng.d(-CHANCE_JITTER, CHANCE_JITTER))) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Optional<PlaceableObject> scaled = objects.pickScaled(placement, rng);
|
||||
if (scaled.isEmpty() || !entry.hasObjectShrink()) {
|
||||
return scaled;
|
||||
}
|
||||
return host.shrink(scaled.get(), entry.shrinkFactor(), rng);
|
||||
}
|
||||
|
||||
static boolean isFootprintFlatBottom(IslandFootprint footprint, UndersideTurn turn, int pickedX, int pickedZ, int pickBottomY,
|
||||
IslandFace.SampleProvider samples, ResolvedFloatingChild entry, int tolerance) {
|
||||
BlockPosition anchor = invertedFootprintAnchor(footprint, turn);
|
||||
long[] cells = footprint.columns();
|
||||
if (cells.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0, n = cells.length; i < n; i++) {
|
||||
long encoded = cells[i];
|
||||
int kx = (int) (encoded >> 32);
|
||||
int kz = (int) (encoded & 0xFFFFFFFFL);
|
||||
IrisBlockVector cell = rotation.rotate(new IrisBlockVector(kx, 0, kz), 0, 0, 0);
|
||||
int columnX = pickedX + cell.getBlockX() - anchor.getBlockX();
|
||||
int columnZ = pickedZ + cell.getBlockZ() - anchor.getBlockZ();
|
||||
for (long encoded : cells) {
|
||||
BlockPosition cell = turn.turn(IslandFootprint.columnX(encoded), 0, IslandFootprint.columnZ(encoded));
|
||||
int columnX = pickedX + cell.x() - anchor.x();
|
||||
int columnZ = pickedZ + cell.z() - anchor.z();
|
||||
FloatingIslandSample sample = samples.sample(columnX, columnZ);
|
||||
if (!IslandObjectPlacer.matchesAnchor(sample, entry, IslandObjectPlacer.AnchorFace.BOTTOM)) {
|
||||
if (!IslandFace.matchesAnchor(sample, entry, IslandFace.Side.BOTTOM)) {
|
||||
return false;
|
||||
}
|
||||
int bottomY = sample.bottomY();
|
||||
@@ -435,135 +333,70 @@ public class FloatingObjectPlacing {
|
||||
return true;
|
||||
}
|
||||
|
||||
static int invertedBaseX(int minX, int pickedXf, FloatingObjectFootprint fp) {
|
||||
return invertedBaseX(minX, pickedXf, fp, IrisObjectRotation.xFlip180());
|
||||
static int invertedBaseX(int minX, int pickedXf, IslandFootprint footprint, UndersideTurn turn) {
|
||||
return minX + pickedXf - invertedFootprintAnchor(footprint, turn).x();
|
||||
}
|
||||
|
||||
static int invertedBaseY(int pickBottomY, FloatingObjectFootprint fp) {
|
||||
return invertedBaseY(pickBottomY, fp, IrisObjectRotation.xFlip180());
|
||||
static int invertedBaseY(int pickBottomY, IslandFootprint footprint, UndersideTurn turn) {
|
||||
return pickBottomY - 1 - invertedSolidAnchor(footprint, turn).y();
|
||||
}
|
||||
|
||||
static int invertedBaseZ(int minZ, int pickedZf, FloatingObjectFootprint fp) {
|
||||
return invertedBaseZ(minZ, pickedZf, fp, IrisObjectRotation.xFlip180());
|
||||
static int invertedBaseZ(int minZ, int pickedZf, IslandFootprint footprint, UndersideTurn turn) {
|
||||
return minZ + pickedZf - invertedFootprintAnchor(footprint, turn).z();
|
||||
}
|
||||
|
||||
static int invertedBaseX(int minX, int pickedXf, FloatingObjectFootprint fp, IrisObjectRotation rotation) {
|
||||
return minX + pickedXf - invertedFootprintAnchor(fp, rotation).getBlockX();
|
||||
private static BlockPosition invertedFootprintAnchor(IslandFootprint footprint, UndersideTurn turn) {
|
||||
return turn.turn(footprint.tallestX(), 0, footprint.tallestZ());
|
||||
}
|
||||
|
||||
static int invertedBaseY(int pickBottomY, FloatingObjectFootprint fp, IrisObjectRotation rotation) {
|
||||
return pickBottomY - 1 - invertedSolidAnchor(fp, rotation).getBlockY();
|
||||
private static BlockPosition invertedSolidAnchor(IslandFootprint footprint, UndersideTurn turn) {
|
||||
return turn.turn(footprint.tallestX(), footprint.lowestSolidY(), footprint.tallestZ());
|
||||
}
|
||||
|
||||
static int invertedBaseZ(int minZ, int pickedZf, FloatingObjectFootprint fp, IrisObjectRotation rotation) {
|
||||
return minZ + pickedZf - invertedFootprintAnchor(fp, rotation).getBlockZ();
|
||||
}
|
||||
|
||||
private static IrisBlockVector invertedFootprintAnchor(FloatingObjectFootprint fp, IrisObjectRotation rotation) {
|
||||
return rotation.rotate(new IrisBlockVector(fp.getTallestKx(), 0, fp.getTallestKz()), 0, 0, 0);
|
||||
}
|
||||
|
||||
private static IrisBlockVector invertedSolidAnchor(FloatingObjectFootprint fp, IrisObjectRotation rotation) {
|
||||
return rotation.rotate(new IrisBlockVector(fp.getTallestKx(), fp.getLowestSolidKeyY(), fp.getTallestKz()), 0, 0, 0);
|
||||
}
|
||||
|
||||
private static boolean shouldWritePlacementMarker(IObjectPlacer placer, PlatformBlockState state, int x, int y, int z) {
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
PlatformBlockState existingState = placer.get(x, y, z);
|
||||
boolean wouldReplace = B.isSolid(existingState) && B.isVineBlock(state);
|
||||
String material = IrisObjectShaping.materialKey(state);
|
||||
boolean placesBlock = !material.equals("minecraft:air") && !material.equals("minecraft:cave_air") && !wouldReplace;
|
||||
return state.isCustom() || placesBlock;
|
||||
}
|
||||
|
||||
static boolean isFootprintFlat(FloatingObjectFootprint fp, int pickedX, int pickedZ, int pickTopY,
|
||||
IslandObjectPlacer.SampleProvider samples,
|
||||
ResolvedFloatingChild entry, int tolerance) {
|
||||
int tallestKx = fp.getTallestKx();
|
||||
int tallestKz = fp.getTallestKz();
|
||||
long[] cells = fp.footprintXZ();
|
||||
static boolean isFootprintFlat(IslandFootprint footprint, int pickedX, int pickedZ, int pickTopY,
|
||||
IslandFace.SampleProvider samples, ResolvedFloatingChild entry, int tolerance) {
|
||||
long[] cells = footprint.columns();
|
||||
if (cells.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0, n = cells.length; i < n; i++) {
|
||||
long encoded = cells[i];
|
||||
int kx = (int) (encoded >> 32);
|
||||
int kz = (int) (encoded & 0xFFFFFFFFL);
|
||||
int columnX = pickedX + (kx - tallestKx);
|
||||
int columnZ = pickedZ + (kz - tallestKz);
|
||||
for (long encoded : cells) {
|
||||
int columnX = pickedX + (IslandFootprint.columnX(encoded) - footprint.tallestX());
|
||||
int columnZ = pickedZ + (IslandFootprint.columnZ(encoded) - footprint.tallestZ());
|
||||
FloatingIslandSample sample = samples.sample(columnX, columnZ);
|
||||
if (!IslandObjectPlacer.matchesAnchor(sample, entry, IslandObjectPlacer.AnchorFace.TOP)
|
||||
|| Math.abs(sample.topY() - pickTopY) > tolerance) {
|
||||
if (!IslandFace.matchesAnchor(sample, entry, IslandFace.Side.TOP) || Math.abs(sample.topY() - pickTopY) > tolerance) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static KList<Integer> interiorColumns(IslandObjectPlacer.SampleProvider samples,
|
||||
KList<Integer> columns, int minX, int minZ,
|
||||
ResolvedFloatingChild entry,
|
||||
IslandObjectPlacer.AnchorFace face) {
|
||||
private static KList<Integer> interiorColumns(Chunk chunk, KList<Integer> columns, ResolvedFloatingChild entry, IslandFace.Side side) {
|
||||
KList<Integer> interior = new KList<>();
|
||||
for (int key : columns) {
|
||||
int x = minX + (key & 15);
|
||||
int z = minZ + (key >> 4);
|
||||
if (!IslandObjectPlacer.matchesAnchor(samples.sample(x + 1, z), entry, face)) {
|
||||
continue;
|
||||
int x = chunk.minX + (key & 15);
|
||||
int z = chunk.minZ + (key >> 4);
|
||||
if (IslandFace.matchesAnchor(chunk.resolver.sample(x + 1, z), entry, side)
|
||||
&& IslandFace.matchesAnchor(chunk.resolver.sample(x - 1, z), entry, side)
|
||||
&& IslandFace.matchesAnchor(chunk.resolver.sample(x, z + 1), entry, side)
|
||||
&& IslandFace.matchesAnchor(chunk.resolver.sample(x, z - 1), entry, side)) {
|
||||
interior.add(key);
|
||||
}
|
||||
if (!IslandObjectPlacer.matchesAnchor(samples.sample(x - 1, z), entry, face)) {
|
||||
continue;
|
||||
}
|
||||
if (!IslandObjectPlacer.matchesAnchor(samples.sample(x, z + 1), entry, face)) {
|
||||
continue;
|
||||
}
|
||||
if (!IslandObjectPlacer.matchesAnchor(samples.sample(x, z - 1), entry, face)) {
|
||||
continue;
|
||||
}
|
||||
interior.add(key);
|
||||
}
|
||||
return interior;
|
||||
}
|
||||
|
||||
private static String placementMarker(IrisObject object, int id) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
String key = object.getLoadKey();
|
||||
if (key == null || key.isEmpty() || key.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
return key + "@" + id;
|
||||
}
|
||||
|
||||
/** How far, in blocks along X and Z, placements may write beyond their chunk. */
|
||||
public int reach() {
|
||||
int maxObjectExtent = 16;
|
||||
Map<String, IrisBlockVector> sizeCache = new HashMap<>();
|
||||
Set<String> warnedLargeObjects = new HashSet<>();
|
||||
/** How far, in blocks along X and Z, the floating objects of the pack {@code settings} describe may write beyond their chunk. */
|
||||
public static int reach(PackSettings settings, ModuleLog log) {
|
||||
Reach reach = new Reach(FloatingHost.of(settings), ObjectHost.of(settings), log);
|
||||
int maxObjectExtent = MIN_REACH_BLOCKS;
|
||||
try {
|
||||
IrisData data = engine.getData();
|
||||
for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
List<FloatingChildBiome> settings = FloatingChildren.declaredBy(biome);
|
||||
if (settings.isEmpty()) {
|
||||
for (Entry<FloatingChildSettings> declared : settings.declared(FloatingChildSettings.class)) {
|
||||
if (declared.level() != Target.BIOME) {
|
||||
continue;
|
||||
}
|
||||
for (ResolvedFloatingChild entry : FloatingChildren.of(engine).of(settings)) {
|
||||
maxObjectExtent = Math.max(maxObjectExtent, computePlacementRadius(new KList<>(entry.settings().floatingObjects()), data, sizeCache, warnedLargeObjects));
|
||||
maxObjectExtent = Math.max(maxObjectExtent, computePlacementRadius(new KList<>(entry.settings().extraObjects()), data, sizeCache, warnedLargeObjects));
|
||||
maxObjectExtent = Math.max(maxObjectExtent, computePlacementRadius(new KList<>(entry.settings().topObjectOverrides()), data, sizeCache, warnedLargeObjects));
|
||||
maxObjectExtent = Math.max(maxObjectExtent, computePlacementRadius(new KList<>(entry.settings().bottomObjectOverrides()), data, sizeCache, warnedLargeObjects));
|
||||
try {
|
||||
IrisBiome target = entry.getRealBiome(biome, data);
|
||||
if (target != null) {
|
||||
maxObjectExtent = Math.max(maxObjectExtent, computePlacementRadius(entry.resolveTopObjects(target), data, sizeCache, warnedLargeObjects));
|
||||
maxObjectExtent = Math.max(maxObjectExtent, computePlacementRadius(entry.resolveBottomObjects(target), data, sizeCache, warnedLargeObjects));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to work out the reach of a floating biome's objects", e);
|
||||
}
|
||||
ResourceId biome = biomeIdOf(declared.source());
|
||||
for (FloatingChildBiome child : declared.value().children()) {
|
||||
maxObjectExtent = Math.max(maxObjectExtent, reach.of(child, biome));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -572,87 +405,79 @@ public class FloatingObjectPlacing {
|
||||
return maxObjectExtent;
|
||||
}
|
||||
|
||||
private int computePlacementRadius(KList<IrisObjectPlacement> placements, IrisData data,
|
||||
Map<String, IrisBlockVector> sizeCache,
|
||||
Set<String> warnedLargeObjects) {
|
||||
int radius = 0;
|
||||
if (placements == null) {
|
||||
return radius;
|
||||
/** A settings entry's source names a biome as {@code biome/<key>}; the pack's resources name it by the key alone. */
|
||||
private static ResourceId biomeIdOf(ResourceId source) {
|
||||
String path = source.path();
|
||||
return path.startsWith(BIOME_PATH_PREFIX) ? new ResourceId(source.namespace(), path.substring(BIOME_PATH_PREFIX.length())) : source;
|
||||
}
|
||||
|
||||
/** The reach of floating children's objects, each object sized once. */
|
||||
private static final class Reach {
|
||||
private final FloatingHost host;
|
||||
private final ObjectHost objects;
|
||||
private final ModuleLog log;
|
||||
private final Map<String, Optional<ObjectSize>> sizes = new HashMap<>();
|
||||
private final Set<String> warnedLargeObjects = new HashSet<>();
|
||||
|
||||
private Reach(FloatingHost host, ObjectHost objects, ModuleLog log) {
|
||||
this.host = host;
|
||||
this.objects = objects;
|
||||
this.log = log;
|
||||
}
|
||||
for (IrisObjectPlacement placement : placements) {
|
||||
if (placement == null || placement.getPlace() == null) {
|
||||
continue;
|
||||
|
||||
int of(FloatingChildBiome child, ResourceId parent) {
|
||||
int reach = 0;
|
||||
reach = Math.max(reach, placementRadius(child.floatingObjects()));
|
||||
reach = Math.max(reach, placementRadius(child.extraObjects()));
|
||||
reach = Math.max(reach, placementRadius(child.topObjectOverrides()));
|
||||
reach = Math.max(reach, placementRadius(child.bottomObjectOverrides()));
|
||||
try {
|
||||
ResourceId target = child.biome().isBlank() ? parent : host.biome(child.biome()).orElse(parent);
|
||||
List<ObjectPlacement> surface = child.inheritObjects() ? FloatingWorld.surfaceObjects(objects, target) : List.of();
|
||||
reach = Math.max(reach, placementRadius(ResolvedFloatingChild.topObjects(child, surface)));
|
||||
reach = Math.max(reach, placementRadius(ResolvedFloatingChild.bottomObjects(child)));
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to work out the reach of a floating biome's objects", e);
|
||||
}
|
||||
for (String objectKey : placement.getPlace()) {
|
||||
try {
|
||||
IrisBlockVector size = sizeCache.get(objectKey);
|
||||
if (size == null) {
|
||||
File file = data.getObjectLoader().findFile(objectKey);
|
||||
if (file == null) {
|
||||
continue;
|
||||
}
|
||||
size = IrisObject.sampleSize(file);
|
||||
sizeCache.put(objectKey, size);
|
||||
}
|
||||
int reach = calculatePlacementReach(size, placement);
|
||||
if (reach > 128 && warnedLargeObjects.add(objectKey)) {
|
||||
log.warn("Floating object " + objectKey + " has a large placement reach (" + reach + " blocks) and may increase memory usage!");
|
||||
}
|
||||
radius = Math.max(radius, reach);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to size a floating object", e);
|
||||
return reach;
|
||||
}
|
||||
|
||||
private int placementRadius(List<ObjectPlacement> placements) {
|
||||
int radius = 0;
|
||||
for (ObjectPlacement placement : placements) {
|
||||
if (placement == null) {
|
||||
continue;
|
||||
}
|
||||
for (String objectKey : placement.place()) {
|
||||
radius = Math.max(radius, objectReach(objectKey, placement));
|
||||
}
|
||||
}
|
||||
return radius;
|
||||
}
|
||||
|
||||
private int objectReach(String objectKey, ObjectPlacement placement) {
|
||||
try {
|
||||
Optional<ObjectSize> size = sizes.computeIfAbsent(objectKey, objects::sizeOf);
|
||||
if (size.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int reach = PlacementReach.of(size.get(), placement);
|
||||
if (reach > LARGE_REACH_WARNING_BLOCKS && warnedLargeObjects.add(objectKey)) {
|
||||
log.warn("Floating object " + objectKey + " has a large placement reach (" + reach + " blocks) and may increase memory usage!");
|
||||
}
|
||||
return reach;
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to size a floating object", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return radius;
|
||||
}
|
||||
|
||||
static int calculatePlacementReach(IrisBlockVector size, IrisObjectPlacement placement) {
|
||||
if (size == null) {
|
||||
return 0;
|
||||
}
|
||||
if (placement == null) {
|
||||
return Math.max(Math.abs(size.getBlockX()), Math.abs(size.getBlockZ()));
|
||||
}
|
||||
|
||||
double scale = placement.getScale() != null ? Math.max(1D, placement.getScale().getMaxScale()) : 1D;
|
||||
int width = scaledDimension(size.getBlockX(), scale);
|
||||
int height = scaledDimension(size.getBlockY(), scale);
|
||||
int depth = scaledDimension(size.getBlockZ(), scale);
|
||||
IrisObjectRotation rotation = placement.getRotation();
|
||||
boolean rotateX = rotation != null && rotation.isEnabled() && rotation.getXAxis() != null && rotation.getXAxis().enabled();
|
||||
boolean rotateZ = rotation != null && rotation.isEnabled() && rotation.getZAxis() != null && rotation.getZAxis().enabled();
|
||||
int footprint = rotateX || rotateZ ? Math.max(width, Math.max(height, depth)) : Math.max(width, depth);
|
||||
int translation = calculateTranslationReach(placement.getTranslate(), rotation, rotateX || rotateZ);
|
||||
int warp = placement.getWarp() != null && !placement.getWarp().isFlat()
|
||||
? (int) Math.ceil(Math.abs(placement.getWarp().getMultiplier()) / 2D)
|
||||
: 0;
|
||||
int vacuum = placement.getMode().placeMode().bendsTerrain()
|
||||
? 2 * IrisObjectVacuum.resolveRadius(placement.getMode().placeMode().vacuum(), placement.getVacuumSettings())
|
||||
: 0;
|
||||
long reach = (long) footprint + translation + warp + vacuum;
|
||||
return reach > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) reach;
|
||||
private record BottomAnchor(int xf, int zf, int bottomY) {
|
||||
}
|
||||
|
||||
private static int scaledDimension(int dimension, double scale) {
|
||||
int absoluteDimension = Math.abs(dimension);
|
||||
if (scale <= 1D) {
|
||||
return absoluteDimension;
|
||||
}
|
||||
return (int) Math.ceil((absoluteDimension * scale) + (scale * 2D));
|
||||
}
|
||||
|
||||
private static int calculateTranslationReach(IrisObjectTranslate translate, IrisObjectRotation rotation, boolean rotateVertically) {
|
||||
if (translate == null || !translate.canTranslate()) {
|
||||
return 0;
|
||||
}
|
||||
double x = translate.getX();
|
||||
double y = translate.getY();
|
||||
double z = translate.getZ();
|
||||
if (rotateVertically) {
|
||||
return (int) Math.ceil(Math.sqrt((x * x) + (y * y) + (z * z)));
|
||||
}
|
||||
boolean rotateY = rotation != null && rotation.isEnabled() && rotation.getYAxis() != null && rotation.getYAxis().enabled();
|
||||
return rotateY ? (int) Math.ceil(Math.hypot(x, z)) : (int) Math.max(Math.abs(x), Math.abs(z));
|
||||
/** What one chunk's placements share: where it is, its random, and its columns' island samples. */
|
||||
private record Chunk(int minX, int minZ, int worldHeight, RNG rng, FloatingIslandSampleResolver resolver,
|
||||
FloatingIslandSample[] samples) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.floating.IslandAnchor;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Iris's placer for an object placed against a floating island: heights and the island's solid blocks come from the
|
||||
* {@link IslandAnchor} the floating module samples, and a block is written only where the anchor lets the object write.
|
||||
* Everything else is the mantle's.
|
||||
*/
|
||||
public final class IslandAnchorPlacer implements IObjectPlacer {
|
||||
private final MantleWriter wrapped;
|
||||
private final IslandAnchor anchor;
|
||||
|
||||
public IslandAnchorPlacer(MantleWriter wrapped, IslandAnchor anchor) {
|
||||
this.wrapped = wrapped;
|
||||
this.anchor = anchor;
|
||||
}
|
||||
|
||||
public boolean canWriteObjectBlock(int x, int y, int z) {
|
||||
return anchor.writes(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return anchor.faceY(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return anchor.hasIsland(x, z) ? anchor.islandSolid(x, y, z) : wrapped.isSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return wrapped.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return wrapped.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState state) {
|
||||
if (anchor.writes(x, y, z)) {
|
||||
wrapped.set(x, y, z, state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
return wrapped.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return wrapped.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return wrapped.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return wrapped.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
if (anchor.writes(x, y, z)) {
|
||||
wrapped.setTile(x, y, z, tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (anchor.writes(x, y, z)) {
|
||||
wrapped.setData(x, y, z, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
return wrapped.getData(x, y, z, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return wrapped == null ? null : wrapped.getEngine();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.floating.IslandAnchor;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
|
||||
/**
|
||||
* The top or bottom face of one floating child's island, at the height an object is anchored: what Iris's placer asks
|
||||
* about the island while it places the object, and which blocks the object may write. An object may overhang its anchor
|
||||
* only where the same child's face lies near the anchor height within {@value #OVERHANG_RADIUS} blocks.
|
||||
*/
|
||||
final class IslandFace implements IslandAnchor {
|
||||
private static final int OVERHANG_RADIUS = 2;
|
||||
private static final int OVERHANG_HEIGHT_TOLERANCE = 4;
|
||||
|
||||
private final SampleProvider samples;
|
||||
private final ResolvedFloatingChild entry;
|
||||
private final int anchorY;
|
||||
private final Side side;
|
||||
private final int worldHeight;
|
||||
|
||||
private IslandFace(SampleProvider samples, ResolvedFloatingChild entry, int anchorY, Side side, int worldHeight) {
|
||||
this.samples = samples;
|
||||
this.entry = entry;
|
||||
this.anchorY = anchorY;
|
||||
this.side = side;
|
||||
this.worldHeight = worldHeight;
|
||||
}
|
||||
|
||||
static IslandFace top(SampleProvider samples, ResolvedFloatingChild entry, int anchorY, int worldHeight) {
|
||||
return new IslandFace(samples, entry, anchorY, Side.TOP, worldHeight);
|
||||
}
|
||||
|
||||
static IslandFace bottom(SampleProvider samples, ResolvedFloatingChild entry, int anchorY, int worldHeight) {
|
||||
return new IslandFace(samples, entry, anchorY, Side.BOTTOM, worldHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int faceY(int x, int z) {
|
||||
FloatingIslandSample sample = samples.sample(x, z);
|
||||
if (sample == null) {
|
||||
return anchorY;
|
||||
}
|
||||
if (side == Side.TOP) {
|
||||
return sample.topY();
|
||||
}
|
||||
int bottomY = sample.bottomY();
|
||||
return bottomY < 0 ? anchorY : bottomY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasIsland(int x, int z) {
|
||||
return samples.sample(x, z) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean islandSolid(int x, int y, int z) {
|
||||
FloatingIslandSample sample = samples.sample(x, z);
|
||||
if (sample == null) {
|
||||
return false;
|
||||
}
|
||||
int index = y - sample.islandBaseY;
|
||||
return index >= 0 && index < sample.solidMask.length && sample.solidMask[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writes(int x, int y, int z) {
|
||||
return !skipsAirColumn(x, y, z);
|
||||
}
|
||||
|
||||
/** Whether {@code sample} is this face's child's island, by the face this anchor is on. */
|
||||
static boolean matchesAnchor(FloatingIslandSample sample, ResolvedFloatingChild entry, Side side) {
|
||||
if (sample == null) {
|
||||
return false;
|
||||
}
|
||||
return side == Side.TOP ? sample.entry == entry : sample.bottomEntry() == entry;
|
||||
}
|
||||
|
||||
private boolean skipsAirColumn(int x, int y, int z) {
|
||||
if (y < 0 || y >= worldHeight) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FloatingIslandSample sample = samples.sample(x, z);
|
||||
if (matchesAnchor(sample, entry, side) && isNearAnchorHeight(sample)) {
|
||||
return side == Side.BOTTOM && y >= anchorY;
|
||||
}
|
||||
if (side == Side.TOP && y <= anchorY) {
|
||||
return true;
|
||||
}
|
||||
if (side == Side.BOTTOM && y >= anchorY) {
|
||||
return true;
|
||||
}
|
||||
return !hasNearbySupport(x, z);
|
||||
}
|
||||
|
||||
private boolean hasNearbySupport(int x, int z) {
|
||||
for (int dz = -OVERHANG_RADIUS; dz <= OVERHANG_RADIUS; dz++) {
|
||||
for (int dx = -OVERHANG_RADIUS; dx <= OVERHANG_RADIUS; dx++) {
|
||||
FloatingIslandSample sample = samples.sample(x + dx, z + dz);
|
||||
if (matchesAnchor(sample, entry, side) && isNearAnchorHeight(sample)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isNearAnchorHeight(FloatingIslandSample sample) {
|
||||
int faceY = side == Side.TOP ? sample.topY() : sample.bottomY();
|
||||
return faceY >= 0 && Math.abs(faceY - anchorY) <= OVERHANG_HEIGHT_TOLERANCE;
|
||||
}
|
||||
|
||||
enum Side {
|
||||
TOP,
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface SampleProvider {
|
||||
FloatingIslandSample sample(int x, int z);
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class IslandObjectPlacer implements IObjectPlacer {
|
||||
private static final int OVERHANG_RADIUS = 2;
|
||||
private static final int OVERHANG_HEIGHT_TOLERANCE = 4;
|
||||
|
||||
private final MantleWriter wrapped;
|
||||
private final SampleProvider samples;
|
||||
private final ResolvedFloatingChild entry;
|
||||
private final int anchorY;
|
||||
private final AnchorFace face;
|
||||
|
||||
private IslandObjectPlacer(MantleWriter wrapped, AnchorSettings settings) {
|
||||
this.wrapped = wrapped;
|
||||
this.samples = settings.samples();
|
||||
this.entry = settings.entry();
|
||||
this.anchorY = settings.anchorY();
|
||||
this.face = settings.face();
|
||||
}
|
||||
|
||||
public static IslandObjectPlacer top(MantleWriter wrapped, SampleProvider samples,
|
||||
ResolvedFloatingChild entry, int anchorY) {
|
||||
return new IslandObjectPlacer(wrapped, new AnchorSettings(samples, entry, anchorY, AnchorFace.TOP));
|
||||
}
|
||||
|
||||
public static IslandObjectPlacer bottom(MantleWriter wrapped, SampleProvider samples,
|
||||
ResolvedFloatingChild entry, int anchorY) {
|
||||
return new IslandObjectPlacer(wrapped, new AnchorSettings(samples, entry, anchorY, AnchorFace.BOTTOM));
|
||||
}
|
||||
|
||||
public boolean canWriteObjectBlock(int x, int y, int z) {
|
||||
return !shouldSkipAirColumn(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
FloatingIslandSample sample = samples.sample(x, z);
|
||||
if (face == AnchorFace.TOP) {
|
||||
return sample == null ? anchorY : sample.topY();
|
||||
}
|
||||
if (sample == null) {
|
||||
return anchorY;
|
||||
}
|
||||
int bottomY = sample.bottomY();
|
||||
return bottomY < 0 ? anchorY : bottomY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
FloatingIslandSample sample = samples.sample(x, z);
|
||||
if (sample != null) {
|
||||
int index = y - sample.islandBaseY;
|
||||
if (index >= 0 && index < sample.solidMask.length) {
|
||||
return sample.solidMask[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return wrapped.isSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return wrapped.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurfaceSolid(int x, int y, int z) {
|
||||
return wrapped.isSurfaceSolid(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, PlatformBlockState state) {
|
||||
if (!shouldSkipAirColumn(x, y, z)) {
|
||||
wrapped.set(x, y, z, state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlockState get(int x, int y, int z) {
|
||||
return wrapped.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return wrapped.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return wrapped.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return wrapped.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int x, int y, int z, TileData tile) {
|
||||
if (!shouldSkipAirColumn(x, y, z)) {
|
||||
wrapped.setTile(x, y, z, tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (!shouldSkipAirColumn(x, y, z)) {
|
||||
wrapped.setData(x, y, z, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
return wrapped.getData(x, y, z, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return wrapped == null ? null : wrapped.getEngine();
|
||||
}
|
||||
|
||||
static boolean matchesAnchor(FloatingIslandSample sample, ResolvedFloatingChild entry, AnchorFace face) {
|
||||
if (sample == null) {
|
||||
return false;
|
||||
}
|
||||
return face == AnchorFace.TOP ? sample.entry == entry : sample.bottomEntry() == entry;
|
||||
}
|
||||
|
||||
private boolean shouldSkipAirColumn(int x, int y, int z) {
|
||||
Engine engine = getEngine();
|
||||
if (engine != null && (y < 0 || y >= engine.getHeight())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FloatingIslandSample sample = samples.sample(x, z);
|
||||
if (matchesAnchor(sample, entry, face) && isNearAnchorHeight(sample)) {
|
||||
return face == AnchorFace.BOTTOM && y >= anchorY;
|
||||
}
|
||||
if (face == AnchorFace.TOP && y <= anchorY) {
|
||||
return true;
|
||||
}
|
||||
if (face == AnchorFace.BOTTOM && y >= anchorY) {
|
||||
return true;
|
||||
}
|
||||
return !hasNearbySupport(x, z);
|
||||
}
|
||||
|
||||
private boolean hasNearbySupport(int x, int z) {
|
||||
for (int dz = -OVERHANG_RADIUS; dz <= OVERHANG_RADIUS; dz++) {
|
||||
for (int dx = -OVERHANG_RADIUS; dx <= OVERHANG_RADIUS; dx++) {
|
||||
FloatingIslandSample sample = samples.sample(x + dx, z + dz);
|
||||
if (matchesAnchor(sample, entry, face) && isNearAnchorHeight(sample)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isNearAnchorHeight(FloatingIslandSample sample) {
|
||||
int faceY = face == AnchorFace.TOP ? sample.topY() : sample.bottomY();
|
||||
return faceY >= 0 && Math.abs(faceY - anchorY) <= OVERHANG_HEIGHT_TOLERANCE;
|
||||
}
|
||||
|
||||
public enum AnchorFace {
|
||||
TOP,
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SampleProvider {
|
||||
@Nullable FloatingIslandSample sample(int x, int z);
|
||||
}
|
||||
|
||||
private record AnchorSettings(
|
||||
SampleProvider samples,
|
||||
ResolvedFloatingChild entry,
|
||||
int anchorY,
|
||||
AnchorFace face
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
/**
|
||||
* How Iris turns an object it hangs under an island: upside down about X, then a quarter turn about Y of {@code yRotation}
|
||||
* degrees (0, 90, 180 or 270), in the object's own block positions.
|
||||
*/
|
||||
record UndersideTurn(int yRotation) {
|
||||
private static final int FULL_TURN_DEGREES = 360;
|
||||
|
||||
BlockPosition turn(int x, int y, int z) {
|
||||
int flippedY = -y;
|
||||
int flippedZ = -z;
|
||||
return switch (Math.floorMod(yRotation, FULL_TURN_DEGREES)) {
|
||||
case 90 -> new BlockPosition(flippedZ, flippedY, -x);
|
||||
case 180 -> new BlockPosition(-x, flippedY, -flippedZ);
|
||||
case 270 -> new BlockPosition(-flippedZ, flippedY, x);
|
||||
default -> new BlockPosition(x, flippedY, flippedZ);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,75 +18,296 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingChildren;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.builtin.floating.FloatingBottomPaletteMode;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.terrain.BiomeLayers;
|
||||
import art.arcane.iris.builtin.terrain.ColumnSlope;
|
||||
import art.arcane.iris.builtin.terrain.LayerNoise;
|
||||
import art.arcane.iris.builtin.terrain.PaletteExplosion;
|
||||
import art.arcane.iris.builtin.terrain.PaletteLayer;
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.builtin.terrain.ExplodeBiomePaletteSizeSettings;
|
||||
import art.arcane.iris.builtin.terrain.ExplodeBiomePalettesSettings;
|
||||
import art.arcane.iris.builtin.terrain.ResolvedLayer;
|
||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||
import art.arcane.iris.engine.decorator.DecoratedBiome;
|
||||
import art.arcane.iris.engine.decorator.DecorationScene;
|
||||
import art.arcane.iris.engine.decorator.FloatingDecorator;
|
||||
import art.arcane.iris.engine.decorator.IrisSeaSurfaceDecorator;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.builtin.terrain.BiomeLayers;
|
||||
import art.arcane.iris.builtin.terrain.LayerNoise;
|
||||
import art.arcane.iris.builtin.terrain.ResolvedLayer;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingWorld;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.ChunkStageContext;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import java.util.IdentityHashMap;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import static art.arcane.iris.engine.mantle.EngineMantle.AIR;
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Fills and decorates the floating islands of the dimension's floating child biomes for {@link FloatingModule}:
|
||||
* the islands' solids (top layers, bottom palette, sea surface) and, later, the decoration on their tops. One
|
||||
* per engine runtime, holding the islands' random.
|
||||
* per world, holding the islands' random.
|
||||
*/
|
||||
public class FloatingIslands {
|
||||
public static final long FLOATING_BASE_SEED_SALT = 0x5EED_F107_00F1B10CL;
|
||||
final class FloatingIslands {
|
||||
private static final long ISLAND_RANDOM_SALT = 0x7EB0A73F1DCE514DL;
|
||||
private static final int BOTTOM_PALETTE_SALT = 0xB0770B;
|
||||
private static final int LAYER_RANDOM_SALT = 0x7A4E;
|
||||
private static final int FIRST_LAYER_GENERATOR_SEED = 7235;
|
||||
private static final int MIN_PALETTE_DEPTH = 4;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
private static final int CHUNK_CENTRE = 7;
|
||||
private static final BlockState BARRIER = new BlockState("minecraft:barrier");
|
||||
private static final BlockState FALLBACK_SOLID = new BlockState("minecraft:stone");
|
||||
private static final String DEFAULT_FLUID = "minecraft:water";
|
||||
private static final Runnable NOOP_DECORATION_MISS = () -> {
|
||||
};
|
||||
private final Engine engine;
|
||||
|
||||
private final FloatingWorld world;
|
||||
private final RNG rng;
|
||||
private final BiomeLayers biomeLayers;
|
||||
private final IrisLayers glue;
|
||||
private final ModuleLog log;
|
||||
|
||||
private KList<PlatformBlockState> generateBottomPaletteLayers(ResolvedFloatingChild entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, IrisData data, IrisComplex complex) {
|
||||
if (entry == null || entry.settings().bottomPaletteMode() != FloatingBottomPaletteMode.CUSTOM || entry.settings().bottomPalette() == null || entry.settings().bottomPalette().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return generatePaletteLayers(dimension, new KList<>(entry.settings().bottomPalette()), wx, wz, random.nextParallelRNG(0xB0770B), paletteDepth, data, complex);
|
||||
FloatingIslands(PackWorld world, ModuleLog log) {
|
||||
this.world = FloatingWorld.of(world);
|
||||
this.rng = new RNG(IrisSeed.TERRAIN.of(world) ^ ISLAND_RANDOM_SALT);
|
||||
this.biomeLayers = BiomeLayers.of(world);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
private KList<PlatformBlockState> generatePaletteLayers(IrisDimension dimension, KList<PaletteLayer> layers, double wx, double wz, RNG random, int maxDepth, IrisData data, IrisComplex complex) {
|
||||
KList<PlatformBlockState> generated = new KList<>();
|
||||
if (layers == null || layers.isEmpty() || maxDepth <= 0) {
|
||||
/** The islands of {@code world}. */
|
||||
static FloatingIslands of(PackWorld world, ModuleLog log) {
|
||||
return world.state(FloatingIslands.class, generating -> new FloatingIslands(generating, log));
|
||||
}
|
||||
|
||||
/** Fills the islands' solids into the chunk of {@code context}. */
|
||||
void fillSolids(ChunkStageContext context) {
|
||||
Chunk chunk = new Chunk(context);
|
||||
FloatingIslandSample.clearChunkMemo();
|
||||
|
||||
for (int xf = 0; xf < CHUNK_WIDTH; xf++) {
|
||||
for (int zf = 0; zf < CHUNK_WIDTH; zf++) {
|
||||
fillColumn(chunk, xf, zf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fillColumn(Chunk chunk, int xf, int zf) {
|
||||
int wx = chunk.originX + xf;
|
||||
int wz = chunk.originZ + zf;
|
||||
ResourceId parent = chunk.boundarySampler.parent(wx, wz);
|
||||
if (parent == null || world.declaredBy(parent).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunk.height, world, chunk.boundarySampler, log);
|
||||
if (sample == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
long colSeed = FloatingIslandSample.columnSeed(world.baseSeed(), wx, wz);
|
||||
int paletteDepth = Math.max(MIN_PALETTE_DEPTH, sample.solidCount + MIN_PALETTE_DEPTH);
|
||||
Map<ResolvedFloatingChild, PaletteContext> paletteContexts = new IdentityHashMap<>();
|
||||
Map<ResolvedFloatingChild, Integer> topDepthByEntry = new IdentityHashMap<>();
|
||||
int[] bottomDepths = bottomDepths(sample, chunk.height);
|
||||
for (int k = sample.topIdx; k >= 0; k--) {
|
||||
if (!sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunk.height) {
|
||||
continue;
|
||||
}
|
||||
ResolvedFloatingChild entry = sample.entryAt(k);
|
||||
PaletteContext paletteContext = paletteContexts.computeIfAbsent(entry,
|
||||
ignored -> createPaletteContext(chunk, parent, entry, wx, wz, colSeed, paletteDepth));
|
||||
int depth = topDepthByEntry.getOrDefault(entry, 0);
|
||||
int bottomDepth = bottomDepths[k] < 0 ? depth : bottomDepths[k];
|
||||
BlockState block = selectPaletteBlock(entry, paletteContext.topBlocks(), paletteContext.bottomBlocks(), depth, bottomDepth);
|
||||
if (block != null) {
|
||||
chunk.output.set(xf, y, zf, block);
|
||||
}
|
||||
topDepthByEntry.put(entry, depth + 1);
|
||||
}
|
||||
|
||||
fillLocalFluid(chunk, sample, xf, zf);
|
||||
paintSkyBiomes(parent, wx, wz, sample, chunk.height);
|
||||
}
|
||||
|
||||
private void fillLocalFluid(Chunk chunk, FloatingIslandSample sample, int xf, int zf) {
|
||||
int localFluidHeight = sample.entry.settings().localFluidHeight().orElse(0);
|
||||
if (localFluidHeight <= 0) {
|
||||
return;
|
||||
}
|
||||
BlockState fluid = fluidOf(chunk.blocks, sample.entry.settings().fluidBlock());
|
||||
int fluidCap = Math.min(sample.thickness - 1, localFluidHeight);
|
||||
for (int k = 1; k <= fluidCap; k++) {
|
||||
if (sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunk.height) {
|
||||
continue;
|
||||
}
|
||||
if (hasSolidBelow(sample, k)) {
|
||||
chunk.output.set(xf, y, zf, fluid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockState fluidOf(BlockRegistry blocks, String key) {
|
||||
try {
|
||||
return blocks.resolve(key);
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
return blocks.resolve(DEFAULT_FLUID);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasSolidBelow(FloatingIslandSample sample, int k) {
|
||||
for (int kb = k - 1; kb >= 0; kb--) {
|
||||
if (sample.solidMask[kb]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Decorates the tops of the islands in the chunk of {@code context}. */
|
||||
void decorateColumns(ChunkStageContext context) {
|
||||
Chunk chunk = new Chunk(context);
|
||||
DecorationScene scene = DecorationScene.of(context);
|
||||
|
||||
for (int xf = 0; xf < CHUNK_WIDTH; xf++) {
|
||||
for (int zf = 0; zf < CHUNK_WIDTH; zf++) {
|
||||
decorateColumn(chunk, scene, xf, zf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void decorateColumn(Chunk chunk, DecorationScene scene, int xf, int zf) {
|
||||
int wx = chunk.originX + xf;
|
||||
int wz = chunk.originZ + zf;
|
||||
ResourceId parent = chunk.boundarySampler.parent(wx, wz);
|
||||
if (parent == null || world.declaredBy(parent).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunk.height, world, chunk.boundarySampler, log);
|
||||
if (sample == null) {
|
||||
return;
|
||||
}
|
||||
ResolvedFloatingChild entry = sample.entry;
|
||||
ResourceId target = entry.realBiome(parent);
|
||||
if (!entry.settings().inheritDecorators() || target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DecoratedBiome decorated = decoratedBiome(chunk.settings, target);
|
||||
decorateTop(chunk, scene, sample, decorated, xf, zf, wx, wz);
|
||||
decorateLocalFluid(chunk, scene, sample, decorated, xf, zf, wx, wz);
|
||||
}
|
||||
|
||||
private void decorateTop(Chunk chunk, DecorationScene scene, FloatingIslandSample sample, DecoratedBiome decorated,
|
||||
int xf, int zf, int wx, int wz) {
|
||||
int topY = sample.topY();
|
||||
if (topY + 1 >= chunk.height) {
|
||||
return;
|
||||
}
|
||||
BlockState above = chunk.output.get(xf, topY + 1, zf);
|
||||
if (above != null && !scene.isAir(above)) {
|
||||
return;
|
||||
}
|
||||
int max = Math.max(1, chunk.height - topY);
|
||||
try {
|
||||
RNG colRng = rng.nextParallelRNG((int) FloatingIslandSample.columnSeed(world.baseSeed(), wx, wz));
|
||||
FloatingDecorator.decorateColumn(scene, decorated, DecorationPart.NONE, xf, zf, wx, wz, topY, max, colRng, NOOP_DECORATION_MISS);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to decorate the top of a floating island", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void decorateLocalFluid(Chunk chunk, DecorationScene scene, FloatingIslandSample sample, DecoratedBiome decorated,
|
||||
int xf, int zf, int wx, int wz) {
|
||||
int localFluidHeight = sample.entry.settings().localFluidHeight().orElse(0);
|
||||
if (localFluidHeight <= 0) {
|
||||
return;
|
||||
}
|
||||
int fluidCap = Math.min(sample.thickness - 1, localFluidHeight);
|
||||
int fluidTopY = -1;
|
||||
for (int k = 1; k <= fluidCap; k++) {
|
||||
if (sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunk.height) {
|
||||
continue;
|
||||
}
|
||||
if (hasSolidBelow(sample, k) && y > fluidTopY) {
|
||||
fluidTopY = y;
|
||||
}
|
||||
}
|
||||
if (fluidTopY <= 0 || fluidTopY + 1 >= chunk.height) {
|
||||
return;
|
||||
}
|
||||
BlockState above = chunk.output.get(xf, fluidTopY + 1, zf);
|
||||
if (above != null && !scene.isAir(above)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
new IrisSeaSurfaceDecorator(scene).decorate(xf, zf, wx, wx + 1, wx - 1, wz, wz + 1, wz - 1, decorated, fluidTopY, chunk.height);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to decorate the sea surface of a floating island", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** The decorators' view of the island's biome, which always decorates as land. */
|
||||
private static DecoratedBiome decoratedBiome(FeatureSettings settings, ResourceId biome) {
|
||||
return new DecoratedBiome(BiomeDecorators.biomeKey(biome), settings.declaredBy(biome, DecorantSettings.class).orElse(null), BiomeKind.LAND);
|
||||
}
|
||||
|
||||
private PaletteContext createPaletteContext(Chunk chunk, ResourceId parent, ResolvedFloatingChild entry, int wx, int wz, long colSeed,
|
||||
int paletteDepth) {
|
||||
ResourceId target = entry == null ? parent : entry.realBiome(parent);
|
||||
int entrySeed = entry == null ? 0 : entry.settings().biome().hashCode();
|
||||
RNG layerRng = rng.nextParallelRNG((int) (colSeed ^ LAYER_RANDOM_SALT ^ entrySeed));
|
||||
KList<BlockState> topBlocks = target == null ? null : surfaceLayers(chunk, target, wx, wz, layerRng, paletteDepth);
|
||||
if (topBlocks == null || topBlocks.isEmpty()) {
|
||||
topBlocks = surfaceLayers(chunk, parent, wx, wz, layerRng, paletteDepth);
|
||||
}
|
||||
List<BlockState> bottomBlocks = generateBottomPaletteLayers(chunk, entry, wx, wz, layerRng, paletteDepth);
|
||||
return new PaletteContext(topBlocks, bottomBlocks);
|
||||
}
|
||||
|
||||
private KList<BlockState> surfaceLayers(Chunk chunk, ResourceId biome, int wx, int wz, RNG layerRng, int paletteDepth) {
|
||||
return biomeLayers.generateLayers(biomeLayers.biome(biome, chunk.settings), chunk.explosion, wx, wz, layerRng, paletteDepth,
|
||||
paletteDepth, chunk.slope);
|
||||
}
|
||||
|
||||
private List<BlockState> generateBottomPaletteLayers(Chunk chunk, ResolvedFloatingChild entry, double wx, double wz, RNG random,
|
||||
int paletteDepth) {
|
||||
if (entry == null || entry.settings().bottomPaletteMode() != FloatingBottomPaletteMode.CUSTOM || entry.settings().bottomPalette().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return generatePaletteLayers(chunk, entry.settings().bottomPalette(), wx, wz, random.nextParallelRNG(BOTTOM_PALETTE_SALT), paletteDepth);
|
||||
}
|
||||
|
||||
private List<BlockState> generatePaletteLayers(Chunk chunk, List<PaletteLayer> layers, double wx, double wz, RNG random, int maxDepth) {
|
||||
List<BlockState> generated = new ArrayList<>();
|
||||
if (layers.isEmpty() || maxDepth <= 0) {
|
||||
return generated;
|
||||
}
|
||||
|
||||
int generatorSeed = 7235;
|
||||
int generatorSeed = FIRST_LAYER_GENERATOR_SEED;
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
ResolvedLayer layer = biomeLayers.resolve(layers.get(i));
|
||||
LayerNoise heightGenerator = layer.heightNoise(random.nextParallelRNG((generatorSeed++) * generatorSeed * generatorSeed * generatorSeed));
|
||||
@@ -96,7 +317,7 @@ public class FloatingIslands {
|
||||
double layerDepth = heightGenerator.fit(layer.minHeight(), layer.maxHeight(), wx / layer.zoom(), wz / layer.zoom());
|
||||
SlopeClip slopeClip = layer.slopeCondition();
|
||||
|
||||
if (slopeClip != null && !slopeClip.isDefault() && complex != null && !slopeClip.isValid(complex.getSlopeStream().get(wx, wz))) {
|
||||
if (slopeClip != null && !slopeClip.isDefault() && !slopeClip.isValid(chunk.slope.at(wx, wz))) {
|
||||
layerDepth = 0;
|
||||
}
|
||||
|
||||
@@ -110,7 +331,7 @@ public class FloatingIslands {
|
||||
}
|
||||
|
||||
try {
|
||||
generated.add(glue.platform(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.zoom(), j, (wz - j) / layer.zoom())));
|
||||
generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.zoom(), j, (wz - j) / layer.zoom()));
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to pick a block of a floating island's palette", e);
|
||||
}
|
||||
@@ -120,12 +341,9 @@ public class FloatingIslands {
|
||||
break;
|
||||
}
|
||||
|
||||
if (dimension != null && dimension.getModuleSettings().find(ExplodeBiomePalettesSettings.class).map(ExplodeBiomePalettesSettings::explode).orElse(false)) {
|
||||
PlatformBlockState barrier = B.getState("minecraft:barrier");
|
||||
int gap = dimension.getModuleSettings().find(ExplodeBiomePaletteSizeSettings.class).map(ExplodeBiomePaletteSizeSettings::size)
|
||||
.orElse(ExplodeBiomePaletteSizeSettings.DEFAULT_SIZE);
|
||||
for (int j = 0; j < gap; j++) {
|
||||
generated.add(barrier);
|
||||
if (chunk.explosion.exploded()) {
|
||||
for (int j = 0; j < chunk.explosion.size(); j++) {
|
||||
generated.add(BARRIER);
|
||||
|
||||
if (generated.size() >= maxDepth) {
|
||||
break;
|
||||
@@ -137,18 +355,11 @@ public class FloatingIslands {
|
||||
return generated;
|
||||
}
|
||||
|
||||
private static boolean usesBottomPalette(ResolvedFloatingChild entry) {
|
||||
FloatingBottomPaletteMode mode = entry == null || entry.settings().bottomPaletteMode() == null ? FloatingBottomPaletteMode.DEPTH : entry.settings().bottomPaletteMode();
|
||||
return mode != FloatingBottomPaletteMode.DEPTH;
|
||||
}
|
||||
|
||||
private static int[] bottomDepths(FloatingIslandSample sample, int chunkHeight) {
|
||||
int[] bottomDepths = new int[sample.solidMask.length];
|
||||
for (int i = 0; i < bottomDepths.length; i++) {
|
||||
bottomDepths[i] = -1;
|
||||
}
|
||||
java.util.Arrays.fill(bottomDepths, -1);
|
||||
|
||||
IdentityHashMap<ResolvedFloatingChild, Integer> depthByEntry = new IdentityHashMap<>();
|
||||
Map<ResolvedFloatingChild, Integer> depthByEntry = new IdentityHashMap<>();
|
||||
int max = Math.min(sample.topIdx, sample.solidMask.length - 1);
|
||||
for (int k = 0; k <= max; k++) {
|
||||
if (!sample.solidMask[k]) {
|
||||
@@ -167,227 +378,33 @@ public class FloatingIslands {
|
||||
return bottomDepths;
|
||||
}
|
||||
|
||||
private static PlatformBlockState selectPaletteBlock(ResolvedFloatingChild entry, KList<PlatformBlockState> topBlocks, KList<PlatformBlockState> bottomBlocks, int topDepth, int bottomDepth, PlatformBlockState fallbackSolid) {
|
||||
FloatingBottomPaletteMode mode = entry == null || entry.settings().bottomPaletteMode() == null ? FloatingBottomPaletteMode.DEPTH : entry.settings().bottomPaletteMode();
|
||||
private static BlockState selectPaletteBlock(ResolvedFloatingChild entry, List<BlockState> topBlocks, List<BlockState> bottomBlocks,
|
||||
int topDepth, int bottomDepth) {
|
||||
FloatingBottomPaletteMode mode = entry == null ? FloatingBottomPaletteMode.DEPTH : entry.settings().bottomPaletteMode();
|
||||
if (mode == FloatingBottomPaletteMode.MIRROR_TOP) {
|
||||
return paletteBlock(topBlocks, Math.min(topDepth, bottomDepth), fallbackSolid);
|
||||
return paletteBlock(topBlocks, Math.min(topDepth, bottomDepth));
|
||||
}
|
||||
if (mode == FloatingBottomPaletteMode.CUSTOM && bottomDepth < topDepth) {
|
||||
if (bottomBlocks != null && !bottomBlocks.isEmpty()) {
|
||||
return paletteBlock(bottomBlocks, bottomDepth, fallbackSolid);
|
||||
return paletteBlock(bottomBlocks, bottomDepth);
|
||||
}
|
||||
return paletteBlock(topBlocks, bottomDepth, fallbackSolid);
|
||||
return paletteBlock(topBlocks, bottomDepth);
|
||||
}
|
||||
return paletteBlock(topBlocks, topDepth, fallbackSolid);
|
||||
return paletteBlock(topBlocks, topDepth);
|
||||
}
|
||||
|
||||
private static PlatformBlockState paletteBlock(KList<PlatformBlockState> blocks, int depth, PlatformBlockState fallbackSolid) {
|
||||
private static BlockState paletteBlock(List<BlockState> blocks, int depth) {
|
||||
if (blocks == null || blocks.isEmpty()) {
|
||||
return fallbackSolid;
|
||||
return FALLBACK_SOLID;
|
||||
}
|
||||
PlatformBlockState block = blocks.hasIndex(depth) ? blocks.get(depth) : blocks.getLast();
|
||||
return block == null ? fallbackSolid : block;
|
||||
BlockState block = depth >= 0 && depth < blocks.size() ? blocks.get(depth) : blocks.getLast();
|
||||
return block == null ? FALLBACK_SOLID : block;
|
||||
}
|
||||
|
||||
private PaletteContext createPaletteContext(IrisBiome parent, ResolvedFloatingChild entry, IrisDimension dimension, int wx, int wz, long colSeed, int paletteDepth, IrisData data, IrisComplex complex) {
|
||||
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data);
|
||||
int entrySeed = entry == null || entry.settings().biome() == null ? 0 : entry.settings().biome().hashCode();
|
||||
RNG layerRng = rng.nextParallelRNG((int) (colSeed ^ 0x7A4E ^ entrySeed));
|
||||
KList<PlatformBlockState> topBlocks = target == null ? null : glue.platform(biomeLayers.generateLayers(glue.biome(target), IrisLayers.explosionOf(dimension), wx, wz, layerRng, paletteDepth, paletteDepth, glue.slope()));
|
||||
if (topBlocks == null || topBlocks.isEmpty()) {
|
||||
topBlocks = glue.platform(biomeLayers.generateLayers(glue.biome(parent), IrisLayers.explosionOf(dimension), wx, wz, layerRng, paletteDepth, paletteDepth, glue.slope()));
|
||||
}
|
||||
KList<PlatformBlockState> bottomBlocks = generateBottomPaletteLayers(entry, dimension, wx, wz, layerRng, paletteDepth, data, complex);
|
||||
return new PaletteContext(topBlocks, bottomBlocks, B.getState("minecraft:stone"));
|
||||
}
|
||||
|
||||
private static final class PaletteContext {
|
||||
private final KList<PlatformBlockState> topBlocks;
|
||||
private final KList<PlatformBlockState> bottomBlocks;
|
||||
private final PlatformBlockState fallbackSolid;
|
||||
|
||||
private PaletteContext(KList<PlatformBlockState> topBlocks, KList<PlatformBlockState> bottomBlocks, PlatformBlockState fallbackSolid) {
|
||||
this.topBlocks = topBlocks;
|
||||
this.bottomBlocks = bottomBlocks;
|
||||
this.fallbackSolid = fallbackSolid;
|
||||
}
|
||||
}
|
||||
|
||||
public FloatingIslands(Engine engine, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
this.log = log;
|
||||
rng = new RNG(engine.getSeedManager().getTerrain() ^ 0x7EB0A73F1DCE514DL);
|
||||
biomeLayers = BiomeLayers.of(engine.getGeneration().world());
|
||||
glue = new IrisLayers(engine);
|
||||
}
|
||||
|
||||
/** Fills the islands' solids into the chunk whose first block is {@code x}, {@code z}. */
|
||||
public void fillSolids(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
int chunkHeight = output.getHeight();
|
||||
IrisData data = engine.getData();
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
IrisComplex complex = engine.getComplex();
|
||||
long baseSeed = engine.getSeedManager().getTerrain() ^ FLOATING_BASE_SEED_SALT;
|
||||
FloatingIslandBoundarySampler boundarySampler = context.getFloatingIslandBoundarySampler();
|
||||
FloatingIslandSample.clearChunkMemo();
|
||||
|
||||
for (int xf = 0; xf < 16; xf++) {
|
||||
for (int zf = 0; zf < 16; zf++) {
|
||||
int wx = x + xf;
|
||||
int wz = z + zf;
|
||||
IrisBiome parent = boundarySampler.parent(wx, wz);
|
||||
if (parent == null || FloatingChildren.declaredBy(parent).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler, log);
|
||||
if (sample == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long colSeed = FloatingIslandSample.columnSeed(baseSeed, wx, wz);
|
||||
int paletteDepth = Math.max(4, sample.solidCount + 4);
|
||||
IdentityHashMap<ResolvedFloatingChild, PaletteContext> paletteContexts = new IdentityHashMap<>();
|
||||
IdentityHashMap<ResolvedFloatingChild, Integer> topDepthByEntry = new IdentityHashMap<>();
|
||||
int[] bottomDepths = bottomDepths(sample, chunkHeight);
|
||||
for (int k = sample.topIdx; k >= 0; k--) {
|
||||
if (!sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
ResolvedFloatingChild entry = sample.entryAt(k);
|
||||
PaletteContext paletteContext = paletteContexts.get(entry);
|
||||
if (paletteContext == null) {
|
||||
paletteContext = createPaletteContext(parent, entry, dimension, wx, wz, colSeed, paletteDepth, data, complex);
|
||||
paletteContexts.put(entry, paletteContext);
|
||||
}
|
||||
int depth = topDepthByEntry.getOrDefault(entry, 0);
|
||||
int bottomDepth = bottomDepths == null || bottomDepths[k] < 0 ? depth : bottomDepths[k];
|
||||
PlatformBlockState block = selectPaletteBlock(entry, paletteContext.topBlocks, paletteContext.bottomBlocks, depth, bottomDepth, paletteContext.fallbackSolid);
|
||||
if (block != null) {
|
||||
output.set(xf, y, zf, block);
|
||||
}
|
||||
topDepthByEntry.put(entry, depth + 1);
|
||||
}
|
||||
|
||||
ResolvedFloatingChild entry = sample.entry;
|
||||
int localFluidHeight = entry.settings().localFluidHeight().orElse(0);
|
||||
if (localFluidHeight > 0) {
|
||||
PlatformBlockState fluid = B.getStateOrNull(entry.settings().fluidBlock());
|
||||
if (fluid == null) {
|
||||
fluid = B.getState("minecraft:water");
|
||||
}
|
||||
int fluidCap = Math.min(sample.thickness - 1, localFluidHeight);
|
||||
for (int k = 1; k <= fluidCap; k++) {
|
||||
if (sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
boolean hasSolidBelow = false;
|
||||
for (int kb = k - 1; kb >= 0; kb--) {
|
||||
if (sample.solidMask[kb]) {
|
||||
hasSolidBelow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasSolidBelow) {
|
||||
output.set(xf, y, zf, fluid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeIslandSkyBiomes(parent, wx, wz, sample, chunkHeight, data);
|
||||
}
|
||||
}
|
||||
|
||||
engine.getMetrics().getTerrain().put(p.getMilliseconds());
|
||||
}
|
||||
|
||||
/** Decorates the tops of the islands in the chunk whose first block is {@code x}, {@code z}. */
|
||||
public void decorateColumns(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context, DecorationScene scene) {
|
||||
int chunkHeight = output.getHeight();
|
||||
IrisData data = engine.getData();
|
||||
IrisComplex complex = engine.getComplex();
|
||||
long baseSeed = engine.getSeedManager().getTerrain() ^ FLOATING_BASE_SEED_SALT;
|
||||
FloatingIslandBoundarySampler boundarySampler = context.getFloatingIslandBoundarySampler();
|
||||
|
||||
for (int xf = 0; xf < 16; xf++) {
|
||||
for (int zf = 0; zf < 16; zf++) {
|
||||
int wx = x + xf;
|
||||
int wz = z + zf;
|
||||
IrisBiome parent = boundarySampler.parent(wx, wz);
|
||||
if (parent == null || FloatingChildren.declaredBy(parent).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler, log);
|
||||
if (sample == null) {
|
||||
continue;
|
||||
}
|
||||
ResolvedFloatingChild entry = sample.entry;
|
||||
IrisBiome target = entry.getRealBiome(parent, data);
|
||||
|
||||
if (!entry.settings().inheritDecorators() || target == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int topY = sample.topY();
|
||||
int max = Math.max(1, chunkHeight - topY);
|
||||
if (topY + 1 < chunkHeight) {
|
||||
PlatformBlockState above = output.get(xf, topY + 1, zf);
|
||||
if (above == null || above.isAir()) {
|
||||
try {
|
||||
RNG colRng = rng.nextParallelRNG((int) FloatingIslandSample.columnSeed(baseSeed, wx, wz));
|
||||
FloatingDecorator.decorateColumn(scene, IrisDecoratedBiomes.of(target, BiomeKind.LAND), DecorationPart.NONE, xf, zf, wx, wz, topY, max, colRng, NOOP_DECORATION_MISS);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to decorate the top of a floating island", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int localFluidHeight = entry.settings().localFluidHeight().orElse(0);
|
||||
if (localFluidHeight > 0) {
|
||||
int fluidCap = Math.min(sample.thickness - 1, localFluidHeight);
|
||||
int fluidTopY = -1;
|
||||
for (int k = 1; k <= fluidCap; k++) {
|
||||
if (sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
boolean hasSolidBelow = false;
|
||||
for (int kb = k - 1; kb >= 0; kb--) {
|
||||
if (sample.solidMask[kb]) {
|
||||
hasSolidBelow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasSolidBelow && y > fluidTopY) {
|
||||
fluidTopY = y;
|
||||
}
|
||||
}
|
||||
if (fluidTopY > 0 && fluidTopY + 1 < chunkHeight && B.isAir(output.get(xf, fluidTopY + 1, zf))) {
|
||||
try {
|
||||
new IrisSeaSurfaceDecorator(scene).decorate(xf, zf, wx, wx + 1, wx - 1, wz, wz + 1, wz - 1, IrisDecoratedBiomes.of(target, BiomeKind.LAND), fluidTopY, chunkHeight);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to decorate the sea surface of a floating island", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeIslandSkyBiomes(IrisBiome parent, int wx, int wz, FloatingIslandSample sample, int chunkHeight, IrisData data) {
|
||||
/** Paints, for each child the column's island is made of, its biome's sky biome into the child's solid blocks. */
|
||||
private void paintSkyBiomes(ResourceId parent, int wx, int wz, FloatingIslandSample sample, int chunkHeight) {
|
||||
try {
|
||||
IdentityHashMap<ResolvedFloatingChild, MatterBiomeInject> matterByEntry = new IdentityHashMap<>();
|
||||
Map<ResolvedFloatingChild, List<Integer>> solidYsByEntry = new IdentityHashMap<>();
|
||||
for (int k = 0; k <= sample.topIdx; k++) {
|
||||
if (!sample.solidMask[k]) {
|
||||
continue;
|
||||
@@ -396,29 +413,48 @@ public class FloatingIslands {
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
ResolvedFloatingChild entry = sample.entryAt(k);
|
||||
MatterBiomeInject matter = matterByEntry.get(entry);
|
||||
if (matter == null) {
|
||||
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data);
|
||||
if (target == null) {
|
||||
continue;
|
||||
}
|
||||
matter = createSkyBiomeMatter(target, wx, wz);
|
||||
matterByEntry.put(entry, matter);
|
||||
solidYsByEntry.computeIfAbsent(sample.entryAt(k), ignored -> new ArrayList<>()).add(y);
|
||||
}
|
||||
for (Map.Entry<ResolvedFloatingChild, List<Integer>> solid : solidYsByEntry.entrySet()) {
|
||||
ResolvedFloatingChild entry = solid.getKey();
|
||||
ResourceId target = entry == null ? parent : entry.realBiome(parent);
|
||||
if (target == null) {
|
||||
continue;
|
||||
}
|
||||
engine.getMantle().getMantle().set(wx, y, wz, matter);
|
||||
int[] ys = solid.getValue().stream().mapToInt(Integer::intValue).toArray();
|
||||
world.host().paintSkyBiome(target, wx, wz, ys, rng);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to write the sky biomes of a floating island", e);
|
||||
}
|
||||
}
|
||||
|
||||
private MatterBiomeInject createSkyBiomeMatter(IrisBiome target, int wx, int wz) {
|
||||
if (target.isCustom()) {
|
||||
IrisBiomeCustom custom = target.getCustomBiome(rng, engine, wx, 0, wz);
|
||||
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(engine.getDimension().getLoadKey() + ":" + custom.getId()));
|
||||
}
|
||||
private record PaletteContext(List<BlockState> topBlocks, List<BlockState> bottomBlocks) {
|
||||
}
|
||||
|
||||
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(target.getSkyBiomeKey(rng, engine, wx, 0, wz)));
|
||||
/** What one chunk's columns share: its views of the blocks, terrain and settings, and its island fields. */
|
||||
private final class Chunk {
|
||||
final int originX;
|
||||
final int originZ;
|
||||
final Hunk<BlockState> output;
|
||||
final int height;
|
||||
final BlockRegistry blocks;
|
||||
final FeatureSettings settings;
|
||||
final PaletteExplosion explosion;
|
||||
final ColumnSlope slope;
|
||||
final FloatingIslandBoundarySampler boundarySampler;
|
||||
|
||||
Chunk(ChunkStageContext context) {
|
||||
this.originX = context.originX();
|
||||
this.originZ = context.originZ();
|
||||
this.output = context.hunk(BlockState.class);
|
||||
this.height = output.getHeight();
|
||||
this.blocks = context.resources().blocks();
|
||||
this.settings = context.settings();
|
||||
this.explosion = PaletteExplosion.of(settings, originX + CHUNK_CENTRE, originZ + CHUNK_CENTRE);
|
||||
TerrainSampler terrain = context.terrain();
|
||||
this.slope = (x, z) -> terrain.column((int) x, (int) z).slope();
|
||||
this.boundarySampler = new FloatingIslandBoundarySampler(world.host()::surfaceBiome);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,11 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.core.modules.IrisChunk;
|
||||
import art.arcane.iris.engine.decorator.DecorationScene;
|
||||
import art.arcane.iris.core.modules.IrisMantleChunk;
|
||||
import art.arcane.iris.core.modules.IrisPackSettings;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.components.FloatingObjectPlacing;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleLog;
|
||||
@@ -39,9 +34,8 @@ import com.volmit.stage.StageGraph;
|
||||
/**
|
||||
* Module {@code iris:floating}: the islands of floating child biomes, their objects in the mantle after the
|
||||
* dimension's other objects, their solids after smoothing and their decoration after the chunk's own. The
|
||||
* mantle stage is a port of what was Iris's floating object mantle component, its work done by
|
||||
* {@link FloatingObjectPlacing}, whose reach is the pack's largest floating object placement. The chunk
|
||||
* stages' work is done by {@link FloatingIslands}.
|
||||
* mantle stage's work is done by {@link FloatingObjectPlacing}, whose reach is the pack's largest floating object
|
||||
* placement. The chunk stages' work is done by {@link FloatingIslands}.
|
||||
*/
|
||||
public final class FloatingModule implements IrisModule {
|
||||
private static final String VERSION = "built-in";
|
||||
@@ -71,30 +65,18 @@ public final class FloatingModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void objects(MantleStageContext context) {
|
||||
IrisMantleChunk chunk = IrisMantleChunk.current();
|
||||
objectPlacing(chunk.engine(), context.log()).place(chunk.writer(), chunk.chunkX(), chunk.chunkZ(), chunk.context());
|
||||
FloatingObjectPlacing.of(context.world(), context.log()).place(context);
|
||||
}
|
||||
|
||||
private int objectReach(PackSettings settings) {
|
||||
return objectPlacing(IrisPackSettings.of(settings).engine(), log).reach();
|
||||
return FloatingObjectPlacing.reach(settings, log);
|
||||
}
|
||||
|
||||
private static void solids(ChunkStageContext context) {
|
||||
IrisChunk chunk = IrisChunk.current();
|
||||
islands(chunk, context.log()).fillSolids(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore(), chunk.context());
|
||||
FloatingIslands.of(context.world(), context.log()).fillSolids(context);
|
||||
}
|
||||
|
||||
private static void decorate(ChunkStageContext context) {
|
||||
IrisChunk chunk = IrisChunk.current();
|
||||
islands(chunk, context.log()).decorateColumns(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore(), chunk.context(),
|
||||
DecorationScene.of(context));
|
||||
}
|
||||
|
||||
private static FloatingObjectPlacing objectPlacing(Engine engine, ModuleLog log) {
|
||||
return engine.getGeneration().state(FloatingObjectPlacing.class, generating -> new FloatingObjectPlacing(generating, log));
|
||||
}
|
||||
|
||||
private static FloatingIslands islands(IrisChunk chunk, ModuleLog log) {
|
||||
return chunk.state(FloatingIslands.class, generating -> new FloatingIslands(generating, log));
|
||||
FloatingIslands.of(context.world(), context.log()).decorateColumns(context);
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.ExplodeBiomePaletteSizeSettings;
|
||||
import art.arcane.iris.builtin.terrain.ExplodeBiomePalettesSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersMaxSettings;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.SeaLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.WallSettings;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.builtin.terrain.ColumnSlope;
|
||||
import art.arcane.iris.builtin.terrain.LayeredBiome;
|
||||
import art.arcane.iris.builtin.terrain.PaletteExplosion;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* What Iris's carving and floating islands, which hold Iris's own types, hand the terrain's layers and palettes, and take back as the
|
||||
* platform's blocks. One per engine: what a biome declares about its layers is read once for each biome.
|
||||
*/
|
||||
final class IrisLayers {
|
||||
private final Engine engine;
|
||||
private final Map<IrisBiome, LayeredBiome> biomes = Collections.synchronizedMap(new IdentityHashMap<>());
|
||||
private final Map<BlockState, PlatformBlockState> platformStates = Collections.synchronizedMap(new IdentityHashMap<>());
|
||||
private final ColumnSlope slope;
|
||||
private volatile PaletteExplosion explosion;
|
||||
|
||||
IrisLayers(Engine engine) {
|
||||
this.engine = engine;
|
||||
this.slope = (x, z) -> engine.getComplex().getSlopeStream().get(x, z);
|
||||
}
|
||||
|
||||
/** What the biome declares about its layers. */
|
||||
LayeredBiome biome(IrisBiome biome) {
|
||||
return biomes.computeIfAbsent(biome, declared -> new LayeredBiome(
|
||||
declared.getModuleSettings().find(LayersSettings.class).orElse(null),
|
||||
declared.getModuleSettings().find(SeaLayersSettings.class).orElse(null),
|
||||
declared.getModuleSettings().find(CaveCeilingLayersSettings.class).orElse(null),
|
||||
declared.getModuleSettings().find(LockLayersSettings.class).orElse(null),
|
||||
declared.getModuleSettings().find(LockLayersMaxSettings.class).orElse(null),
|
||||
declared.getModuleSettings().find(WallSettings.class).orElse(null)));
|
||||
}
|
||||
|
||||
/** The biome with only its wall, for a caller that asks for nothing else. */
|
||||
static LayeredBiome wallOf(IrisBiome biome) {
|
||||
return new LayeredBiome(null, null, null, null, null, biome.getModuleSettings().find(WallSettings.class).orElse(null));
|
||||
}
|
||||
|
||||
/** What the engine's dimension declares about separating layers with barriers. */
|
||||
PaletteExplosion explosion() {
|
||||
PaletteExplosion known = explosion;
|
||||
if (known == null) {
|
||||
known = explosionOf(engine.getDimension());
|
||||
explosion = known;
|
||||
}
|
||||
return known;
|
||||
}
|
||||
|
||||
static PaletteExplosion explosionOf(IrisDimension dimension) {
|
||||
if (dimension == null) {
|
||||
return PaletteExplosion.NONE;
|
||||
}
|
||||
return new PaletteExplosion(
|
||||
dimension.getModuleSettings().find(ExplodeBiomePalettesSettings.class).map(ExplodeBiomePalettesSettings::explode).orElse(false),
|
||||
dimension.getModuleSettings().find(ExplodeBiomePaletteSizeSettings.class).map(ExplodeBiomePaletteSizeSettings::size)
|
||||
.orElse(ExplodeBiomePaletteSizeSettings.DEFAULT_SIZE));
|
||||
}
|
||||
|
||||
ColumnSlope slope() {
|
||||
return slope;
|
||||
}
|
||||
|
||||
/** The platform's block for {@code block}, worked out once for each block instance, since a world's layers hold few. */
|
||||
PlatformBlockState platform(BlockState block) {
|
||||
return block == null ? null : platformStates.computeIfAbsent(block, known -> B.getState(known.key()));
|
||||
}
|
||||
|
||||
KList<PlatformBlockState> platform(KList<BlockState> blocks) {
|
||||
KList<PlatformBlockState> converted = new KList<>(blocks.size());
|
||||
for (BlockState block : blocks) {
|
||||
converted.add(platform(block));
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
}
|
||||
+6
-14
@@ -15,19 +15,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.modifier;
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.engine.decorator.DecoratedBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import com.volmit.world.BiomeKind;
|
||||
|
||||
/** The decorators' view of a biome Iris's carving and floating islands hold as an {@link IrisBiome}. */
|
||||
final class IrisDecoratedBiomes {
|
||||
private IrisDecoratedBiomes() {
|
||||
}
|
||||
|
||||
static DecoratedBiome of(IrisBiome biome, BiomeKind kind) {
|
||||
return new DecoratedBiome(biome.getLoadKey(), biome.getModuleSettings().find(DecorantSettings.class).orElse(null), kind);
|
||||
}
|
||||
/**
|
||||
* A world column as a hash key. A long packing both coordinates would hash to {@code x ^ z} as a {@code Long}, which
|
||||
* puts every diagonal of a chunk into one bucket.
|
||||
*/
|
||||
public record Column(int x, int z) {
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/** The {@link ResolvedFloatingChild} of every {@link FloatingChildBiome} an engine runtime has met, one per decoded entry. */
|
||||
public final class FloatingChildren {
|
||||
private final Map<FloatingChildBiome, ResolvedFloatingChild> resolved = new ConcurrentHashMap<>();
|
||||
|
||||
public FloatingChildren(Engine engine) {
|
||||
}
|
||||
|
||||
FloatingChildren() {
|
||||
}
|
||||
|
||||
/** The children of the engine {@code data} serves, or of {@code data} alone when no engine runs it. */
|
||||
public static FloatingChildren of(IrisData data) {
|
||||
Engine engine = data.getEngine();
|
||||
return engine == null ? new FloatingChildren() : of(engine);
|
||||
}
|
||||
|
||||
public static FloatingChildren of(Engine engine) {
|
||||
return engine.getGeneration().state(FloatingChildren.class, FloatingChildren::new);
|
||||
}
|
||||
|
||||
/** The floating children {@code biome} declares, in the order it lists them; none when it declares none. */
|
||||
public static List<FloatingChildBiome> declaredBy(IrisBiome biome) {
|
||||
return biome.getModuleSettings().find(FloatingChildSettings.class).map(FloatingChildSettings::children).orElse(List.of());
|
||||
}
|
||||
|
||||
/** Whether {@code biome} samples every floating child on its own and unions their islands instead of picking one per column. */
|
||||
public static boolean merges(IrisBiome biome) {
|
||||
return biome.getModuleSettings().find(MergeFloatingChildrenSettings.class).map(MergeFloatingChildrenSettings::merge).orElse(false);
|
||||
}
|
||||
|
||||
public ResolvedFloatingChild of(FloatingChildBiome settings) {
|
||||
return resolved.computeIfAbsent(settings, ResolvedFloatingChild::new);
|
||||
}
|
||||
|
||||
public List<ResolvedFloatingChild> of(List<FloatingChildBiome> settings) {
|
||||
return settings.stream().map(this::of).toList();
|
||||
}
|
||||
}
|
||||
+65
-37
@@ -18,14 +18,13 @@
|
||||
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -47,20 +46,20 @@ public final class FloatingIslandBoundarySampler {
|
||||
this.ownershipFields = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public @Nullable IrisBiome parent(int x, int z) {
|
||||
public ResourceId parent(int x, int z) {
|
||||
return parentField(x, z, EDGE_TAPER_WIDTH).parent(x, z);
|
||||
}
|
||||
|
||||
public double edgeFade(IrisBiome parent, int x, int z) {
|
||||
public double edgeFade(ResourceId parent, int x, int z) {
|
||||
return edgeFade(parent, x, z, EDGE_TAPER_WIDTH);
|
||||
}
|
||||
|
||||
public double edgeFade(IrisBiome parent, int x, int z, int taperWidth) {
|
||||
public double edgeFade(ResourceId parent, int x, int z, int taperWidth) {
|
||||
int boundaryDistance = edgeDistance(parent, x, z, taperWidth);
|
||||
return edgeFadeForDistance(boundaryDistance, taperWidth);
|
||||
}
|
||||
|
||||
public int edgeDistance(IrisBiome parent, int x, int z, int taperWidth) {
|
||||
public int edgeDistance(ResourceId parent, int x, int z, int taperWidth) {
|
||||
if (parent == null) {
|
||||
return 0;
|
||||
}
|
||||
@@ -68,11 +67,11 @@ public final class FloatingIslandBoundarySampler {
|
||||
return parentField(x, z, taperWidth).edgeDistance(parent, x, z);
|
||||
}
|
||||
|
||||
public FootprintSample footprint(CNG footprint, int x, int z, double signedCut) {
|
||||
public FootprintSample footprint(NoiseSampler footprint, int x, int z, double signedCut) {
|
||||
return footprint(footprint, x, z, signedCut, EDGE_TAPER_WIDTH);
|
||||
}
|
||||
|
||||
public FootprintSample footprint(CNG footprint, int x, int z, double signedCut, int taperWidth) {
|
||||
public FootprintSample footprint(NoiseSampler footprint, int x, int z, double signedCut, int taperWidth) {
|
||||
int width = FloatingIslandEdgeProfile.clampWidth(taperWidth);
|
||||
int chunkX = Math.floorDiv(x, CHUNK_SIZE);
|
||||
int chunkZ = Math.floorDiv(z, CHUNK_SIZE);
|
||||
@@ -83,11 +82,11 @@ public final class FloatingIslandBoundarySampler {
|
||||
return field.sample(x, z);
|
||||
}
|
||||
|
||||
public OwnershipSample ownership(KList<ResolvedFloatingChild> entries, CNG picker, int x, int z) {
|
||||
public OwnershipSample ownership(KList<ResolvedFloatingChild> entries, NoiseSampler picker, int x, int z) {
|
||||
return ownership(entries, picker, x, z, EDGE_TAPER_WIDTH);
|
||||
}
|
||||
|
||||
public OwnershipSample ownership(KList<ResolvedFloatingChild> entries, CNG picker, int x, int z,
|
||||
public OwnershipSample ownership(KList<ResolvedFloatingChild> entries, NoiseSampler picker, int x, int z,
|
||||
int taperWidth) {
|
||||
int width = FloatingIslandEdgeProfile.clampWidth(taperWidth);
|
||||
int chunkX = Math.floorDiv(x, CHUNK_SIZE);
|
||||
@@ -117,14 +116,14 @@ public final class FloatingIslandBoundarySampler {
|
||||
ignored -> new ParentBoundaryField(source, chunkX, chunkZ, width));
|
||||
}
|
||||
|
||||
private static boolean sameBiome(@Nullable IrisBiome expected, @Nullable IrisBiome actual) {
|
||||
private static boolean sameBiome(ResourceId expected, ResourceId actual) {
|
||||
if (actual == expected) {
|
||||
return true;
|
||||
}
|
||||
if (expected == null || actual == null || expected.getLoadKey() == null) {
|
||||
if (expected == null || actual == null) {
|
||||
return false;
|
||||
}
|
||||
return expected.getLoadKey().equals(actual.getLoadKey());
|
||||
return expected.equals(actual);
|
||||
}
|
||||
|
||||
public record FootprintSample(double signed, int cardinalSupport, int diagonalSupport, boolean accepted,
|
||||
@@ -138,13 +137,13 @@ public final class FloatingIslandBoundarySampler {
|
||||
}
|
||||
|
||||
private static final class FootprintFieldKey {
|
||||
private final CNG footprint;
|
||||
private final NoiseSampler footprint;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
private final long signedCutBits;
|
||||
private final int taperWidth;
|
||||
|
||||
private FootprintFieldKey(CNG footprint, int chunkX, int chunkZ, long signedCutBits, int taperWidth) {
|
||||
private FootprintFieldKey(NoiseSampler footprint, int chunkX, int chunkZ, long signedCutBits, int taperWidth) {
|
||||
this.footprint = footprint;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
@@ -176,12 +175,12 @@ public final class FloatingIslandBoundarySampler {
|
||||
|
||||
private static final class OwnershipFieldKey {
|
||||
private final KList<ResolvedFloatingChild> entries;
|
||||
private final CNG picker;
|
||||
private final NoiseSampler picker;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
private final int taperWidth;
|
||||
|
||||
private OwnershipFieldKey(KList<ResolvedFloatingChild> entries, CNG picker, int chunkX, int chunkZ,
|
||||
private OwnershipFieldKey(KList<ResolvedFloatingChild> entries, NoiseSampler picker, int chunkX, int chunkZ,
|
||||
int taperWidth) {
|
||||
this.entries = entries;
|
||||
this.picker = picker;
|
||||
@@ -216,7 +215,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
private final FieldGeometry geometry;
|
||||
private final int minX;
|
||||
private final int minZ;
|
||||
private final IrisBiome[] parents;
|
||||
private final ResourceId[] parents;
|
||||
private final byte[] distance;
|
||||
private final boolean[] viable;
|
||||
|
||||
@@ -224,17 +223,17 @@ public final class FloatingIslandBoundarySampler {
|
||||
this.geometry = FieldGeometry.forWidth(taperWidth);
|
||||
this.minX = (chunkX * CHUNK_SIZE) - geometry.fadeRadius();
|
||||
this.minZ = (chunkZ * CHUNK_SIZE) - geometry.fadeRadius();
|
||||
this.parents = new IrisBiome[geometry.area()];
|
||||
this.parents = new ResourceId[geometry.area()];
|
||||
this.distance = new byte[geometry.area()];
|
||||
this.viable = new boolean[geometry.area()];
|
||||
build(source);
|
||||
}
|
||||
|
||||
private @Nullable IrisBiome parent(int x, int z) {
|
||||
private ResourceId parent(int x, int z) {
|
||||
return parents[geometry.index(x - minX, z - minZ)];
|
||||
}
|
||||
|
||||
private int edgeDistance(IrisBiome expected, int x, int z) {
|
||||
private int edgeDistance(ResourceId expected, int x, int z) {
|
||||
int index = geometry.index(x - minX, z - minZ);
|
||||
if (!sameBiome(expected, parents[index]) || !viable[index]) {
|
||||
return 0;
|
||||
@@ -244,7 +243,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
|
||||
private void build(BiomeSampler source) {
|
||||
int rawSize = geometry.fieldSize() + 2;
|
||||
IrisBiome[] raw = new IrisBiome[rawSize * rawSize];
|
||||
ResourceId[] raw = new ResourceId[rawSize * rawSize];
|
||||
int rawMinX = minX - 1;
|
||||
int rawMinZ = minZ - 1;
|
||||
for (int z = 0; z < rawSize; z++) {
|
||||
@@ -255,7 +254,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
for (int z = 0; z < geometry.fieldSize(); z++) {
|
||||
for (int x = 0; x < geometry.fieldSize(); x++) {
|
||||
int index = geometry.index(x, z);
|
||||
IrisBiome parent = raw[rawIndex(x + 1, z + 1, rawSize)];
|
||||
ResourceId parent = raw[rawIndex(x + 1, z + 1, rawSize)];
|
||||
parents[index] = parent;
|
||||
distance[index] = (byte) (touchesDifferentBiome(raw, parent, x, z, rawSize)
|
||||
? 1
|
||||
@@ -266,7 +265,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
markLabelCoreSupported(parents, distance, viable, geometry);
|
||||
}
|
||||
|
||||
private static boolean touchesDifferentBiome(IrisBiome[] raw, @Nullable IrisBiome parent, int x, int z,
|
||||
private static boolean touchesDifferentBiome(ResourceId[] raw, ResourceId parent, int x, int z,
|
||||
int rawSize) {
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
@@ -297,7 +296,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
private final byte[] distance;
|
||||
private final boolean[] viable;
|
||||
|
||||
private FootprintField(CNG footprint, int chunkX, int chunkZ, double signedCut, int taperWidth) {
|
||||
private FootprintField(NoiseSampler footprint, int chunkX, int chunkZ, double signedCut, int taperWidth) {
|
||||
this.geometry = FieldGeometry.forWidth(taperWidth);
|
||||
this.occupancyMinX = (chunkX * CHUNK_SIZE) - geometry.fadeRadius();
|
||||
this.occupancyMinZ = (chunkZ * CHUNK_SIZE) - geometry.fadeRadius();
|
||||
@@ -322,20 +321,20 @@ public final class FloatingIslandBoundarySampler {
|
||||
Byte.toUnsignedInt(diagonalSupport[index]), renderable, boundaryDistance, fade);
|
||||
}
|
||||
|
||||
private void build(CNG footprint, double signedCut) {
|
||||
private void build(NoiseSampler footprint, double signedCut) {
|
||||
double[] rawSigned = sampleRawFootprint(footprint);
|
||||
buildOccupancy(rawSigned, signedCut);
|
||||
buildDistanceField();
|
||||
}
|
||||
|
||||
private double[] sampleRawFootprint(CNG footprint) {
|
||||
private double[] sampleRawFootprint(NoiseSampler footprint) {
|
||||
int rawSize = geometry.fieldSize() + 2;
|
||||
double[] rawSigned = new double[rawSize * rawSize];
|
||||
int rawMinX = occupancyMinX - 1;
|
||||
int rawMinZ = occupancyMinZ - 1;
|
||||
for (int z = 0; z < rawSize; z++) {
|
||||
for (int x = 0; x < rawSize; x++) {
|
||||
rawSigned[rawIndex(x, z, rawSize)] = signedFromUnit(footprint.noise(rawMinX + x, rawMinZ + z));
|
||||
rawSigned[rawIndex(x, z, rawSize)] = signedFromUnit(footprint.sample(rawMinX + x, rawMinZ + z));
|
||||
}
|
||||
}
|
||||
return rawSigned;
|
||||
@@ -397,7 +396,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
private final ResolvedFloatingChild[] owners;
|
||||
private final IdentityHashMap<ResolvedFloatingChild, ComponentDistanceField> distances;
|
||||
|
||||
private OwnershipField(KList<ResolvedFloatingChild> entries, CNG picker, int chunkX, int chunkZ,
|
||||
private OwnershipField(KList<ResolvedFloatingChild> entries, NoiseSampler picker, int chunkX, int chunkZ,
|
||||
int taperWidth) {
|
||||
this.geometry = FieldGeometry.forWidth(taperWidth);
|
||||
this.minX = (chunkX * CHUNK_SIZE) - geometry.fadeRadius();
|
||||
@@ -406,8 +405,8 @@ public final class FloatingIslandBoundarySampler {
|
||||
this.distances = new IdentityHashMap<>();
|
||||
for (int z = 0; z < geometry.fieldSize(); z++) {
|
||||
for (int x = 0; x < geometry.fieldSize(); x++) {
|
||||
double value = Math.max(0.0D, Math.min(1.0D, picker.noise(minX + x, minZ + z)));
|
||||
owners[geometry.index(x, z)] = IRare.pick(entries, value);
|
||||
double value = Math.max(0.0D, Math.min(1.0D, picker.sample(minX + x, minZ + z)));
|
||||
owners[geometry.index(x, z)] = pickByRarity(entries, value);
|
||||
}
|
||||
}
|
||||
for (ResolvedFloatingChild entry : entries) {
|
||||
@@ -451,6 +450,35 @@ public final class FloatingIslandBoundarySampler {
|
||||
private record ComponentDistanceField(byte[] distance, boolean[] viable) {
|
||||
}
|
||||
|
||||
/** The entry {@code noiseValue} (0..1) lands on when each entry takes a share of the range inverse to its rarity. */
|
||||
static ResolvedFloatingChild pickByRarity(List<ResolvedFloatingChild> entries, double noiseValue) {
|
||||
if (entries.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (entries.size() == 1) {
|
||||
return entries.getFirst();
|
||||
}
|
||||
|
||||
double total = 0;
|
||||
for (ResolvedFloatingChild entry : entries) {
|
||||
total += 1d / rarityOf(entry);
|
||||
}
|
||||
|
||||
double threshold = total * noiseValue;
|
||||
double buffer = 0;
|
||||
for (ResolvedFloatingChild entry : entries) {
|
||||
buffer += 1d / rarityOf(entry);
|
||||
if (buffer >= threshold) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return entries.getLast();
|
||||
}
|
||||
|
||||
private static int rarityOf(ResolvedFloatingChild entry) {
|
||||
return Math.max(1, entry.rarity());
|
||||
}
|
||||
|
||||
private record FieldGeometry(int taperWidth, int fadeRadius, int fieldSize, int maxDistance) {
|
||||
private static FieldGeometry forWidth(int taperWidth) {
|
||||
int width = FloatingIslandEdgeProfile.clampWidth(taperWidth);
|
||||
@@ -546,7 +574,7 @@ public final class FloatingIslandBoundarySampler {
|
||||
}
|
||||
}
|
||||
|
||||
private static void markLabelCoreSupported(IrisBiome[] labels, byte[] distance, boolean[] viable,
|
||||
private static void markLabelCoreSupported(ResourceId[] labels, byte[] distance, boolean[] viable,
|
||||
FieldGeometry geometry) {
|
||||
for (int z = 0; z < geometry.fieldSize(); z++) {
|
||||
for (int x = 0; x < geometry.fieldSize(); x++) {
|
||||
@@ -559,8 +587,8 @@ public final class FloatingIslandBoundarySampler {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasCoreNeighbor(@Nullable boolean[] inside, byte[] distance,
|
||||
@Nullable IrisBiome[] labels, int x, int z, FieldGeometry geometry) {
|
||||
private static boolean hasCoreNeighbor(boolean[] inside, byte[] distance,
|
||||
ResourceId[] labels, int x, int z, FieldGeometry geometry) {
|
||||
int index = geometry.index(x, z);
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
@@ -591,6 +619,6 @@ public final class FloatingIslandBoundarySampler {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BiomeSampler {
|
||||
@Nullable IrisBiome sample(int x, int z);
|
||||
ResourceId sample(int x, int z);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
|
||||
public final class FloatingIslandEdgeProfile {
|
||||
public static final int DEFAULT_WIDTH = 10;
|
||||
@@ -34,9 +34,9 @@ public final class FloatingIslandEdgeProfile {
|
||||
private final int width;
|
||||
private final double exponent;
|
||||
private final double variationAmplitude;
|
||||
private final CNG variation;
|
||||
private final NoiseSampler variation;
|
||||
|
||||
public FloatingIslandEdgeProfile(int width, double exponent, double variationAmplitude, CNG variation) {
|
||||
public FloatingIslandEdgeProfile(int width, double exponent, double variationAmplitude, NoiseSampler variation) {
|
||||
this.width = clampWidth(width);
|
||||
this.exponent = clampExponent(exponent);
|
||||
this.variationAmplitude = clampVariationAmplitude(variationAmplitude, this.width);
|
||||
@@ -65,7 +65,7 @@ public final class FloatingIslandEdgeProfile {
|
||||
}
|
||||
double localWidth = width;
|
||||
if (variation != null && variationAmplitude > 0.0D) {
|
||||
double noise = Math.max(0.0D, Math.min(1.0D, variation.noise(x, z)));
|
||||
double noise = Math.max(0.0D, Math.min(1.0D, variation.sample(x, z)));
|
||||
double signedNoise = (noise * 2.0D) - 1.0D;
|
||||
localWidth += signedNoise * variationAmplitude;
|
||||
}
|
||||
|
||||
+65
-80
@@ -20,13 +20,10 @@ package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CaveProfileSampler;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.ModuleLog;
|
||||
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -54,8 +51,9 @@ public final class FloatingIslandSample {
|
||||
private static final double CARVE_MAX_VERTICAL_RUN_FRACTION = 0.18D;
|
||||
private static final ThreadLocal<int[]> LAST_REJECT = ThreadLocal.withInitial(() -> new int[1]);
|
||||
private static final ThreadLocal<double[]> LAST_DENSITY = ThreadLocal.withInitial(() -> new double[2]);
|
||||
private static final ThreadLocal<HashMap<Long, FloatingIslandSample>> CHUNK_MEMO = ThreadLocal.withInitial(HashMap::new);
|
||||
private static final ThreadLocal<IdentityHashMap<CNG, Long2DoubleOpenHashMap>> FOOTPRINT_MEMO = ThreadLocal.withInitial(IdentityHashMap::new);
|
||||
private static final ThreadLocal<HashMap<Column, FloatingIslandSample>> CHUNK_MEMO = ThreadLocal.withInitial(HashMap::new);
|
||||
private static final ThreadLocal<IdentityHashMap<NoiseSampler, HashMap<Column, Double>>> FOOTPRINT_MEMO = ThreadLocal.withInitial(IdentityHashMap::new);
|
||||
private static final int FOOTPRINT_MEMO_CAPACITY = 512;
|
||||
private static final AtomicBoolean NULL_CNG_WARNED = new AtomicBoolean(false);
|
||||
|
||||
public static int getLastReject() {
|
||||
@@ -78,13 +76,13 @@ public final class FloatingIslandSample {
|
||||
FOOTPRINT_MEMO.get().clear();
|
||||
}
|
||||
|
||||
public static FloatingIslandSample sampleMemoized(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, IrisData data, Engine engine, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
long key = (((long) wx) << 32) ^ (wz & 0xFFFFFFFFL);
|
||||
HashMap<Long, FloatingIslandSample> memo = CHUNK_MEMO.get();
|
||||
public static FloatingIslandSample sampleMemoized(ResourceId parent, int wx, int wz, int chunkHeight, FloatingWorld world, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
Column key = new Column(wx, wz);
|
||||
HashMap<Column, FloatingIslandSample> memo = CHUNK_MEMO.get();
|
||||
if (memo.containsKey(key)) {
|
||||
return memo.get(key);
|
||||
}
|
||||
FloatingIslandSample result = sample(parent, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler, log);
|
||||
FloatingIslandSample result = sample(parent, wx, wz, chunkHeight, world, boundarySampler, log);
|
||||
memo.put(key, result);
|
||||
return result;
|
||||
}
|
||||
@@ -94,11 +92,11 @@ public final class FloatingIslandSample {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void warnNullCng(String styleField, IrisBiome parent, ModuleLog log) {
|
||||
private static void warnNullCng(String styleField, ResourceId parent, ModuleLog log) {
|
||||
if (NULL_CNG_WARNED.compareAndSet(false, true)) {
|
||||
String biomeKey = parent == null ? "<unknown>" : parent.getLoadKey();
|
||||
log.warn("Floating child biome on " + biomeKey + " has a null CNG for " + styleField
|
||||
+ " (style factory returned null or AtomicCache swallowed an exception); skipping floating sampling until pack is fixed");
|
||||
String biomeKey = parent == null ? "<unknown>" : parent.toString();
|
||||
log.warn("Floating child biome on " + biomeKey + " has no noise for " + styleField
|
||||
+ " (the noise factory failed or AtomicCache swallowed an exception); skipping floating sampling until pack is fixed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,19 +173,17 @@ public final class FloatingIslandSample {
|
||||
return baseSeed ^ ((long) wx * 341873128712L) ^ ((long) wz * 132897987541L);
|
||||
}
|
||||
|
||||
private static int maximumEdgeFieldWidth(KList<ResolvedFloatingChild> entries, long baseSeed,
|
||||
IrisData data, IrisBiome parent, ModuleLog log) {
|
||||
private static int maximumEdgeFieldWidth(KList<ResolvedFloatingChild> entries, ResourceId parent, ModuleLog log) {
|
||||
int maximumWidth = FloatingIslandEdgeProfile.MIN_WIDTH;
|
||||
for (ResolvedFloatingChild entry : entries) {
|
||||
FloatingIslandEdgeProfile profile = resolveEdgeProfile(entry, baseSeed, data, parent, log);
|
||||
FloatingIslandEdgeProfile profile = resolveEdgeProfile(entry, parent, log);
|
||||
maximumWidth = Math.max(maximumWidth, profile.fieldWidth());
|
||||
}
|
||||
return maximumWidth;
|
||||
}
|
||||
|
||||
private static FloatingIslandEdgeProfile resolveEdgeProfile(ResolvedFloatingChild entry, long baseSeed,
|
||||
IrisData data, IrisBiome parent, ModuleLog log) {
|
||||
FloatingIslandEdgeProfile profile = entry.getEdgeTaperProfile(baseSeed, data);
|
||||
private static FloatingIslandEdgeProfile resolveEdgeProfile(ResolvedFloatingChild entry, ResourceId parent, ModuleLog log) {
|
||||
FloatingIslandEdgeProfile profile = entry.edgeTaperProfile();
|
||||
if (profile != null) {
|
||||
return profile;
|
||||
}
|
||||
@@ -195,21 +191,21 @@ public final class FloatingIslandSample {
|
||||
return FloatingIslandEdgeProfile.DEFAULT;
|
||||
}
|
||||
|
||||
public static FloatingIslandSample sample(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, IrisData data, Engine engine, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
List<FloatingChildBiome> settings = FloatingChildren.declaredBy(parent);
|
||||
public static FloatingIslandSample sample(ResourceId parent, int wx, int wz, int chunkHeight, FloatingWorld world, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
List<FloatingChildBiome> settings = world.declaredBy(parent);
|
||||
if (settings.isEmpty()) {
|
||||
return reject(REJECT_NO_ENTRIES);
|
||||
}
|
||||
KList<ResolvedFloatingChild> entries = new KList<>(FloatingChildren.of(data).of(settings));
|
||||
return sample(parent, entries, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler, log);
|
||||
KList<ResolvedFloatingChild> entries = new KList<>(world.resolve(settings));
|
||||
return sample(parent, entries, wx, wz, chunkHeight, world, boundarySampler, log);
|
||||
}
|
||||
|
||||
static FloatingIslandSample sample(IrisBiome parent, KList<ResolvedFloatingChild> entries, int wx, int wz, int chunkHeight, long baseSeed, IrisData data, Engine engine, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
int boundaryFieldWidth = maximumEdgeFieldWidth(entries, baseSeed, data, parent, log);
|
||||
static FloatingIslandSample sample(ResourceId parent, KList<ResolvedFloatingChild> entries, int wx, int wz, int chunkHeight, FloatingWorld world, FloatingIslandBoundarySampler boundarySampler, ModuleLog log) {
|
||||
int boundaryFieldWidth = maximumEdgeFieldWidth(entries, parent, log);
|
||||
int parentBoundaryDistance = boundarySampler.edgeDistance(parent, wx, wz, boundaryFieldWidth);
|
||||
|
||||
if (FloatingChildren.merges(parent)) {
|
||||
return sampleMerged(parent, entries, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler,
|
||||
if (world.merges(parent)) {
|
||||
return sampleMerged(parent, entries, wx, wz, chunkHeight, world, boundarySampler,
|
||||
parentBoundaryDistance, boundaryFieldWidth, log);
|
||||
}
|
||||
|
||||
@@ -219,7 +215,7 @@ public final class FloatingIslandSample {
|
||||
entry = entries.getFirst();
|
||||
} else {
|
||||
ResolvedFloatingChild reference = entries.getFirst();
|
||||
CNG picker = reference.getPickerCng(baseSeed, data);
|
||||
NoiseSampler picker = reference.pickerNoise();
|
||||
if (picker == null) {
|
||||
warnNullCng("pickerStyle", parent, log);
|
||||
return reject(REJECT_NO_PICK);
|
||||
@@ -233,20 +229,20 @@ public final class FloatingIslandSample {
|
||||
ownershipBoundaryDistance = ownership.boundaryDistance();
|
||||
}
|
||||
|
||||
return sampleEntry(parent, entry, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler,
|
||||
return sampleEntry(parent, entry, wx, wz, chunkHeight, world, boundarySampler,
|
||||
parentBoundaryDistance, ownershipBoundaryDistance, log);
|
||||
}
|
||||
|
||||
private static FloatingIslandSample sampleMerged(IrisBiome parent, KList<ResolvedFloatingChild> entries,
|
||||
int wx, int wz, int chunkHeight, long baseSeed, IrisData data,
|
||||
Engine engine, FloatingIslandBoundarySampler boundarySampler,
|
||||
private static FloatingIslandSample sampleMerged(ResourceId parent, KList<ResolvedFloatingChild> entries,
|
||||
int wx, int wz, int chunkHeight, FloatingWorld world,
|
||||
FloatingIslandBoundarySampler boundarySampler,
|
||||
int parentBoundaryDistance, int boundaryFieldWidth, ModuleLog log) {
|
||||
KList<FloatingIslandSample> samples = new KList<>();
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
|
||||
for (ResolvedFloatingChild entry : entries) {
|
||||
FloatingIslandSample sample = sampleEntry(parent, entry, wx, wz, chunkHeight, baseSeed, data, engine,
|
||||
FloatingIslandSample sample = sampleEntry(parent, entry, wx, wz, chunkHeight, world,
|
||||
boundarySampler, parentBoundaryDistance, boundaryFieldWidth + 1, log);
|
||||
if (sample == null) {
|
||||
continue;
|
||||
@@ -308,12 +304,12 @@ public final class FloatingIslandSample {
|
||||
return new FloatingIslandSample(topEntry, minY, thickness, topIdx, solidCount, solidMask, entryMask);
|
||||
}
|
||||
|
||||
private static FloatingIslandSample sampleEntry(IrisBiome parent, ResolvedFloatingChild entry, int wx, int wz,
|
||||
int chunkHeight, long baseSeed, IrisData data, Engine engine,
|
||||
private static FloatingIslandSample sampleEntry(ResourceId parent, ResolvedFloatingChild entry, int wx, int wz,
|
||||
int chunkHeight, FloatingWorld world,
|
||||
FloatingIslandBoundarySampler boundarySampler,
|
||||
int parentBoundaryDistance, int ownershipBoundaryDistance, ModuleLog log) {
|
||||
FloatingIslandEdgeProfile edgeProfile = resolveEdgeProfile(entry, baseSeed, data, parent, log);
|
||||
CNG footprintCng = entry.getFootprintCng(baseSeed, data);
|
||||
FloatingIslandEdgeProfile edgeProfile = resolveEdgeProfile(entry, parent, log);
|
||||
NoiseSampler footprintCng = entry.footprintNoise();
|
||||
if (footprintCng == null) {
|
||||
warnNullCng("footprintStyle", parent, log);
|
||||
return reject(REJECT_NO_SEED);
|
||||
@@ -339,28 +335,28 @@ public final class FloatingIslandSample {
|
||||
return reject(REJECT_NO_THICKNESS);
|
||||
}
|
||||
|
||||
CNG altitudeCng = entry.getAltitudeCng(baseSeed, data);
|
||||
NoiseSampler altitudeCng = entry.altitudeNoise();
|
||||
if (altitudeCng == null) {
|
||||
warnNullCng("altitudeStyle", parent, log);
|
||||
return reject(REJECT_NO_SEED);
|
||||
}
|
||||
double altNoise = altitudeCng.noise(wx, wz);
|
||||
double altNoise = altitudeCng.sample(wx, wz);
|
||||
double altClamped = Math.max(0, Math.min(1, altNoise));
|
||||
int worldMin = engine.getWorld().minHeight();
|
||||
int worldMin = world.minHeight();
|
||||
int minAlt = Math.max(0, entry.settings().minHeightAboveSurface() - worldMin);
|
||||
int maxAlt = Math.max(minAlt, entry.settings().maxHeightAboveSurface() - worldMin);
|
||||
int baseY = minAlt + (int) Math.round(altClamped * (maxAlt - minAlt));
|
||||
|
||||
IrisBiome target = entry.getRealBiome(parent, data);
|
||||
int fullTopHeight = computeTopHeight(entry, target, engine, baseSeed, wx, wz, data, log);
|
||||
ResourceId target = entry.realBiome(parent);
|
||||
int fullTopHeight = computeTopHeight(entry, target, world, wx, wz, log);
|
||||
int topH = roundedEdgeHeight(fullTopHeight, edgeFade);
|
||||
|
||||
CNG bottomCng = entry.getBottomCng(baseSeed, data);
|
||||
NoiseSampler bottomCng = entry.bottomNoise();
|
||||
if (bottomCng == null) {
|
||||
warnNullCng("bottomStyle", parent, log);
|
||||
return reject(REJECT_NO_SEED);
|
||||
}
|
||||
double bottomNoise = bottomCng.noise(wx, wz);
|
||||
double bottomNoise = bottomCng.sample(wx, wz);
|
||||
double bottomClamped = Math.max(0, Math.min(1, bottomNoise));
|
||||
double bottomShaped = Math.pow(bottomClamped, Math.max(0.1, entry.settings().bottomExponent()));
|
||||
int minDepth = Math.max(0, entry.settings().bottomDepthMin());
|
||||
@@ -412,11 +408,11 @@ public final class FloatingIslandSample {
|
||||
}
|
||||
|
||||
boolean[] solidMask = new boolean[thickness];
|
||||
CNG wallWarp = entry.getWallWarpCng(baseSeed, data);
|
||||
NoiseSampler wallWarp = entry.wallWarpNoise();
|
||||
double warpAmp = Math.max(0, entry.settings().wallWarpAmplitude());
|
||||
double effectiveWarpAmp = effectiveWallWarpAmplitude(warpAmp, edgeFade);
|
||||
CaveProfileSampler carvingProfileSampler = entry.getCarvingProfileSampler(engine, data);
|
||||
CNG carve = carvingProfileSampler == null && !entry.hasCarvingReference() ? entry.getCarveCng(baseSeed, data) : null;
|
||||
CaveProfileSampler carvingProfileSampler = entry.carvingProfileSampler();
|
||||
NoiseSampler carve = carvingProfileSampler == null && !entry.hasCarvingReference() ? entry.carveNoise() : null;
|
||||
double carveThreshold = entry.settings().carveThreshold();
|
||||
boolean useWarp = wallWarp != null && effectiveWarpAmp > 0;
|
||||
boolean useProfileCarve = carvingProfileSampler != null;
|
||||
@@ -484,7 +480,7 @@ public final class FloatingIslandSample {
|
||||
return amplitude * fade;
|
||||
}
|
||||
|
||||
static boolean directCarveEnabled(ResolvedFloatingChild entry, CaveProfileSampler carvingProfileSampler, CNG carve, double carveThreshold) {
|
||||
static boolean directCarveEnabled(ResolvedFloatingChild entry, CaveProfileSampler carvingProfileSampler, NoiseSampler carve, double carveThreshold) {
|
||||
return carvingProfileSampler == null && (entry == null || !entry.hasCarvingReference()) && carve != null && carveThreshold < 1.0;
|
||||
}
|
||||
|
||||
@@ -492,9 +488,9 @@ public final class FloatingIslandSample {
|
||||
return edgeFade >= 1.0 && support.isFullySurrounded();
|
||||
}
|
||||
|
||||
static int carveSolidInterior(boolean[] solidMask, boolean[] lateralCarveMask, int botY, int wx, int wz, CNG carve, double carveThreshold) {
|
||||
static int carveSolidInterior(boolean[] solidMask, boolean[] lateralCarveMask, int botY, int wx, int wz, NoiseSampler carve, double carveThreshold) {
|
||||
return carveSolidInterior(solidMask, lateralCarveMask, botY, wx, wz, (x, y, z) -> {
|
||||
double carveNoise = carve.noise(x, y, z);
|
||||
double carveNoise = carve.sample(x, y, z);
|
||||
double carveClamped = Math.max(0, Math.min(1, carveNoise));
|
||||
return carveClamped > carveThreshold;
|
||||
});
|
||||
@@ -612,7 +608,7 @@ public final class FloatingIslandSample {
|
||||
return cardinal >= CARVE_CARDINAL_SUPPORT && cardinal + diagonal >= CARVE_TOTAL_SUPPORT;
|
||||
}
|
||||
|
||||
static boolean hasFootprintNeighborSupport(CNG footprintCng, int wx, int wz, double signedCut) {
|
||||
static boolean hasFootprintNeighborSupport(NoiseSampler footprintCng, int wx, int wz, double signedCut) {
|
||||
return footprintNeighborSupport(footprintCng, wx, wz, signedCut).hasSolidSupport();
|
||||
}
|
||||
|
||||
@@ -620,7 +616,7 @@ public final class FloatingIslandSample {
|
||||
return support.canFillPinhole();
|
||||
}
|
||||
|
||||
static NeighborSupport footprintNeighborSupport(CNG footprintCng, int wx, int wz, double signedCut) {
|
||||
static NeighborSupport footprintNeighborSupport(NoiseSampler footprintCng, int wx, int wz, double signedCut) {
|
||||
int cardinal = 0;
|
||||
int diagonal = 0;
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
@@ -642,7 +638,7 @@ public final class FloatingIslandSample {
|
||||
return new NeighborSupport(cardinal, diagonal);
|
||||
}
|
||||
|
||||
static NeighborSupport layerNeighborSupport(CNG footprintCng, CNG wallWarp, boolean useWarp, double warpAmp, int wx, int wy, int wz, double signedCut) {
|
||||
static NeighborSupport layerNeighborSupport(NoiseSampler footprintCng, NoiseSampler wallWarp, boolean useWarp, double warpAmp, int wx, int wy, int wz, double signedCut) {
|
||||
int cardinal = 0;
|
||||
int diagonal = 0;
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
@@ -663,45 +659,34 @@ public final class FloatingIslandSample {
|
||||
return new NeighborSupport(cardinal, diagonal);
|
||||
}
|
||||
|
||||
static boolean layerFootprintSolid(CNG footprintCng, CNG wallWarp, boolean useWarp, double warpAmp, int wx, int wy, int wz, double signedCut) {
|
||||
static boolean layerFootprintSolid(NoiseSampler footprintCng, NoiseSampler wallWarp, boolean useWarp, double warpAmp, int wx, int wy, int wz, double signedCut) {
|
||||
double sx = wx;
|
||||
double sz = wz;
|
||||
if (useWarp) {
|
||||
double wnX = wallWarp.noise(wx, wy, wz);
|
||||
double wnX = wallWarp.sample(wx, wy, wz);
|
||||
double signedWarpX = signedFromUnit(wnX);
|
||||
sx = wx + signedWarpX * warpAmp;
|
||||
double wnZ = wallWarp.noise(wx + 1987.3, wy, wz + 2341.1);
|
||||
double wnZ = wallWarp.sample(wx + 1987.3, wy, wz + 2341.1);
|
||||
double signedWarpZ = signedFromUnit(wnZ);
|
||||
sz = wz + signedWarpZ * warpAmp;
|
||||
}
|
||||
double layerFoot = footprintCng.noise(sx, sz);
|
||||
double layerFoot = footprintCng.sample(sx, sz);
|
||||
return signedFromUnit(layerFoot) > signedCut;
|
||||
}
|
||||
|
||||
private static double footprintSigned(CNG footprintCng, int wx, int wz) {
|
||||
IdentityHashMap<CNG, Long2DoubleOpenHashMap> memoByCng = FOOTPRINT_MEMO.get();
|
||||
Long2DoubleOpenHashMap memo = memoByCng.get(footprintCng);
|
||||
if (memo == null) {
|
||||
memo = new Long2DoubleOpenHashMap(512);
|
||||
memo.defaultReturnValue(Double.NaN);
|
||||
memoByCng.put(footprintCng, memo);
|
||||
}
|
||||
|
||||
long key = columnKey(wx, wz);
|
||||
double cached = memo.get(key);
|
||||
if (!Double.isNaN(cached)) {
|
||||
private static double footprintSigned(NoiseSampler footprintCng, int wx, int wz) {
|
||||
HashMap<Column, Double> memo = FOOTPRINT_MEMO.get().computeIfAbsent(footprintCng, ignored -> new HashMap<>(FOOTPRINT_MEMO_CAPACITY));
|
||||
Column key = new Column(wx, wz);
|
||||
Double cached = memo.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
double signed = signedFromUnit(footprintCng.noise(wx, wz));
|
||||
double signed = signedFromUnit(footprintCng.sample(wx, wz));
|
||||
memo.put(key, signed);
|
||||
return signed;
|
||||
}
|
||||
|
||||
private static long columnKey(int wx, int wz) {
|
||||
return ((long) wx << 32) ^ (wz & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
private static double signedFromUnit(double value) {
|
||||
return (Math.max(0, Math.min(1, value)) * 2.0) - 1.0;
|
||||
}
|
||||
@@ -775,7 +760,7 @@ public final class FloatingIslandSample {
|
||||
}
|
||||
}
|
||||
|
||||
private static int computeTopHeight(ResolvedFloatingChild entry, IrisBiome target, Engine engine, long baseSeed, int wx, int wz, IrisData data, ModuleLog log) {
|
||||
private static int computeTopHeight(ResolvedFloatingChild entry, ResourceId target, FloatingWorld world, int wx, int wz, ModuleLog log) {
|
||||
int maxTopHeight = Math.max(0, entry.settings().maxTopHeight());
|
||||
if (maxTopHeight == 0) {
|
||||
return 0;
|
||||
@@ -783,12 +768,12 @@ public final class FloatingIslandSample {
|
||||
return switch (entry.settings().topShapeMode()) {
|
||||
case FLAT -> maxTopHeight;
|
||||
case NOISE -> {
|
||||
CNG topCng = entry.getTopShapeCng(baseSeed, data);
|
||||
NoiseSampler topCng = entry.topShapeNoise();
|
||||
if (topCng == null) {
|
||||
warnNullCng("topShapeStyle", null, log);
|
||||
yield maxTopHeight / 2;
|
||||
}
|
||||
double n = topCng.noise(wx, wz);
|
||||
double n = topCng.sample(wx, wz);
|
||||
double clamped = Math.max(0, Math.min(1, n));
|
||||
double amp = Math.max(0, Math.min(1, entry.settings().topShapeAmp()));
|
||||
yield (int) Math.round(clamped * amp * maxTopHeight);
|
||||
@@ -797,7 +782,7 @@ public final class FloatingIslandSample {
|
||||
if (target == null) {
|
||||
yield maxTopHeight / 2;
|
||||
}
|
||||
double h = target.getHeight(engine, wx, wz, baseSeed);
|
||||
double h = world.host().biomeHeight(target, wx, wz, world.baseSeed());
|
||||
int rounded = (int) Math.round(h);
|
||||
if (rounded < 0) {
|
||||
yield 0;
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import art.arcane.iris.builtin.carve.CaveProfile;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* What the floating islands of one world are made from: the world's hosts, noise and seeds, the floating children each
|
||||
* biome declares, and the {@link ResolvedFloatingChild} of every child met, one per decoded entry. One per world ({@link #of}).
|
||||
*/
|
||||
public final class FloatingWorld {
|
||||
private static final long BASE_SEED_SALT = 0x5EED_F107_00F1B10CL;
|
||||
|
||||
private final FloatingHost host;
|
||||
private final ObjectHost objects;
|
||||
private final NoiseFactory noise;
|
||||
private final long baseSeed;
|
||||
private final long carveSeed;
|
||||
private final int minHeight;
|
||||
private final List<CarvingEntry> dimensionCarving;
|
||||
private final Map<FloatingChildBiome, ResolvedFloatingChild> resolved = new ConcurrentHashMap<>();
|
||||
|
||||
FloatingWorld(FloatingHost host, ObjectHost objects, NoiseFactory noise, long terrainSeed, long carveSeed, int minHeight,
|
||||
List<CarvingEntry> dimensionCarving) {
|
||||
this.host = host;
|
||||
this.objects = objects;
|
||||
this.noise = noise;
|
||||
this.baseSeed = terrainSeed ^ BASE_SEED_SALT;
|
||||
this.carveSeed = carveSeed;
|
||||
this.minHeight = minHeight;
|
||||
this.dimensionCarving = List.copyOf(dimensionCarving);
|
||||
}
|
||||
|
||||
/** The floating islands of {@code world}. */
|
||||
public static FloatingWorld of(PackWorld world) {
|
||||
return world.state(FloatingWorld.class, FloatingWorld::create);
|
||||
}
|
||||
|
||||
private static FloatingWorld create(PackWorld world) {
|
||||
return new FloatingWorld(FloatingHost.of(world), ObjectHost.of(world), world.resources().noise(), IrisSeed.TERRAIN.of(world),
|
||||
IrisSeed.CARVE.of(world), world.minHeight(), dimensionCarvingOf(world));
|
||||
}
|
||||
|
||||
private static List<CarvingEntry> dimensionCarvingOf(PackWorld world) {
|
||||
return world.settings().declared(CarvingSettings.class).stream()
|
||||
.filter(entry -> entry.level() == Target.DIMENSION)
|
||||
.map(Entry::value)
|
||||
.findFirst()
|
||||
.map(CarvingSettings::entries)
|
||||
.orElse(List.of());
|
||||
}
|
||||
|
||||
public FloatingHost host() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public ObjectHost objects() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
public NoiseFactory noise() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
/** The seed every island's noise and column random derive from. */
|
||||
public long baseSeed() {
|
||||
return baseSeed;
|
||||
}
|
||||
|
||||
long carveSeed() {
|
||||
return carveSeed;
|
||||
}
|
||||
|
||||
/** The platform's Y of the dimension's bottom. */
|
||||
public int minHeight() {
|
||||
return minHeight;
|
||||
}
|
||||
|
||||
/** The floating children {@code biome} declares, in the order it lists them; none when it declares none. */
|
||||
public List<FloatingChildBiome> declaredBy(ResourceId biome) {
|
||||
return objects.biomeDeclaration(biome, FloatingChildSettings.class).map(FloatingChildSettings::children).orElse(List.of());
|
||||
}
|
||||
|
||||
/** Whether {@code biome} samples every floating child on its own and unions their islands instead of picking one per column. */
|
||||
public boolean merges(ResourceId biome) {
|
||||
return objects.biomeDeclaration(biome, MergeFloatingChildrenSettings.class).map(MergeFloatingChildrenSettings::merge).orElse(false);
|
||||
}
|
||||
|
||||
public ResolvedFloatingChild resolve(FloatingChildBiome settings) {
|
||||
return resolved.computeIfAbsent(settings, declared -> new ResolvedFloatingChild(declared, this));
|
||||
}
|
||||
|
||||
public List<ResolvedFloatingChild> resolve(List<FloatingChildBiome> settings) {
|
||||
return settings.stream().map(this::resolve).toList();
|
||||
}
|
||||
|
||||
/** The surface object placements {@code biome} declares. */
|
||||
public static List<ObjectPlacement> surfaceObjects(ObjectHost objects, ResourceId biome) {
|
||||
return objects.biomeDeclaration(biome, ObjectSettings.class).map(ObjectSettings::objects).orElse(List.of()).stream()
|
||||
.filter(placement -> placement.carvingSupport().supportsSurface())
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** The dimension's carving entry with this id (the last of several with one id); empty when it declares none. */
|
||||
Optional<CarvingEntry> dimensionCarving(String id) {
|
||||
CarvingEntry found = null;
|
||||
for (CarvingEntry entry : dimensionCarving) {
|
||||
if (entry != null && !entry.id().isBlank() && entry.id().trim().equals(id)) {
|
||||
found = entry;
|
||||
}
|
||||
}
|
||||
return Optional.ofNullable(found);
|
||||
}
|
||||
|
||||
/** The cave profile {@code biome} declares; null when it declares none. */
|
||||
CaveProfile caveProfile(ResourceId biome) {
|
||||
return objects.biomeDeclaration(biome, CaveProfile.class).orElse(null);
|
||||
}
|
||||
}
|
||||
+94
-136
@@ -19,190 +19,159 @@
|
||||
package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.builtin.carve.CaveProfile;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisValues;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CaveProfiles;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CaveProfileSampler;
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A {@link FloatingChildBiome} made ready for one engine: the noise its styles build (each from the world seed it is first
|
||||
* asked with), the edge taper profile, the biome it targets, the carving profile sampler and the objects it hosts. The
|
||||
* settings class held these on itself; the engine now keeps one of these per decoded entry ({@link FloatingChildren}).
|
||||
* A {@link FloatingChildBiome} made ready for one world: the noise its styles build (each from the world's floating seed),
|
||||
* the edge taper profile, the biome it targets, the carving profile sampler and the objects it hosts. One per decoded entry
|
||||
* ({@link FloatingWorld#resolve}).
|
||||
*/
|
||||
public final class ResolvedFloatingChild implements IRare {
|
||||
private final FloatingChildBiome settings;
|
||||
private final IrisGeneratorStyle footprintStyle;
|
||||
private final IrisGeneratorStyle edgeTaperVariationStyle;
|
||||
private final IrisGeneratorStyle pickerStyle;
|
||||
private final IrisGeneratorStyle altitudeStyle;
|
||||
private final IrisGeneratorStyle topShapeStyle;
|
||||
private final IrisGeneratorStyle bottomStyle;
|
||||
private final IrisGeneratorStyle wallWarpStyle;
|
||||
private final IrisGeneratorStyle carveStyle;
|
||||
private final AtomicCache<IrisBiome> resolvedBiome = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> footprintCache = new AtomicCache<>();
|
||||
private final AtomicCache<FloatingIslandEdgeProfile> edgeTaperProfileCache = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> pickerCache = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> altitudeCache = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> topShapeCache = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> bottomCache = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> wallWarpCache = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> carveCache = new AtomicCache<>();
|
||||
private final AtomicCache<CaveProfileSampler> carvingProfileSamplerCache = new AtomicCache<>(true);
|
||||
private final AtomicCache<IrisObjectScale> shrinkScaleCache = new AtomicCache<>();
|
||||
public final class ResolvedFloatingChild {
|
||||
private static final long FOOTPRINT_SALT = 0xF007B17DL;
|
||||
private static final long EDGE_VARIATION_SALT = 0xED6E7A9E5L;
|
||||
private static final long PICKER_SALT = 0x91C4E72DL;
|
||||
private static final long ALTITUDE_SALT = 0xA17DEBBL;
|
||||
private static final long TOP_SHAPE_SALT = 0x70970601DEFL;
|
||||
private static final long BOTTOM_SALT = 0xB0770075CAFEL;
|
||||
private static final long WALL_WARP_SALT = 0xA117BA17E0FL;
|
||||
private static final long CARVE_SALT = 0xCA5EC1EE5EL;
|
||||
private static final double MIN_SHRINK_FACTOR = 0.01;
|
||||
|
||||
public ResolvedFloatingChild(FloatingChildBiome settings) {
|
||||
private final FloatingChildBiome settings;
|
||||
private final FloatingWorld world;
|
||||
private final AtomicCache<Optional<ResourceId>> namedBiome = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> footprintCache = new AtomicCache<>();
|
||||
private final AtomicCache<FloatingIslandEdgeProfile> edgeTaperProfileCache = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> pickerCache = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> altitudeCache = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> topShapeCache = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> bottomCache = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> wallWarpCache = new AtomicCache<>();
|
||||
private final AtomicCache<NoiseSampler> carveCache = new AtomicCache<>();
|
||||
private final AtomicCache<CaveProfileSampler> carvingProfileSamplerCache = new AtomicCache<>(true);
|
||||
|
||||
ResolvedFloatingChild(FloatingChildBiome settings, FloatingWorld world) {
|
||||
this.settings = settings;
|
||||
this.footprintStyle = IrisValues.generatorStyle(settings.footprintStyle());
|
||||
this.edgeTaperVariationStyle = IrisValues.generatorStyle(settings.edgeTaperVariationStyle());
|
||||
this.pickerStyle = IrisValues.generatorStyle(settings.pickerStyle());
|
||||
this.altitudeStyle = IrisValues.generatorStyle(settings.altitudeStyle());
|
||||
this.topShapeStyle = IrisValues.generatorStyle(settings.topShapeStyle());
|
||||
this.bottomStyle = IrisValues.generatorStyle(settings.bottomStyle());
|
||||
this.wallWarpStyle = settings.wallWarpStyle().map(IrisValues::generatorStyle).orElse(null);
|
||||
this.carveStyle = settings.carveStyle().map(IrisValues::generatorStyle).orElse(null);
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public FloatingChildBiome settings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRarity() {
|
||||
public int rarity() {
|
||||
return settings.rarity();
|
||||
}
|
||||
|
||||
public CNG getFootprintCng(long baseSeed, IrisData data) {
|
||||
return footprintCache.aquire(() -> footprintStyle.create(new RNG(baseSeed ^ 0xF007B17DL), data));
|
||||
public NoiseSampler footprintNoise() {
|
||||
return footprintCache.aquire(() -> noise(settings.footprintStyle(), FOOTPRINT_SALT));
|
||||
}
|
||||
|
||||
public FloatingIslandEdgeProfile getEdgeTaperProfile(long baseSeed, IrisData data) {
|
||||
public FloatingIslandEdgeProfile edgeTaperProfile() {
|
||||
return edgeTaperProfileCache.aquire(() -> {
|
||||
int width = FloatingIslandEdgeProfile.clampWidth(settings.edgeTaperWidth());
|
||||
double amplitude = FloatingIslandEdgeProfile.clampVariationAmplitude(
|
||||
settings.edgeTaperVariationAmplitude(), width);
|
||||
CNG variation = amplitude > 0.0D
|
||||
? edgeTaperVariationStyle.create(new RNG(baseSeed ^ 0xED6E7A9E5L), data)
|
||||
: null;
|
||||
double amplitude = FloatingIslandEdgeProfile.clampVariationAmplitude(settings.edgeTaperVariationAmplitude(), width);
|
||||
NoiseSampler variation = amplitude > 0.0D ? noise(settings.edgeTaperVariationStyle(), EDGE_VARIATION_SALT) : null;
|
||||
return new FloatingIslandEdgeProfile(width, settings.edgeTaperExponent(), amplitude, variation);
|
||||
});
|
||||
}
|
||||
|
||||
public CNG getPickerCng(long baseSeed, IrisData data) {
|
||||
return pickerCache.aquire(() -> pickerStyle.create(new RNG(baseSeed ^ 0x91C4E72DL), data));
|
||||
public NoiseSampler pickerNoise() {
|
||||
return pickerCache.aquire(() -> noise(settings.pickerStyle(), PICKER_SALT));
|
||||
}
|
||||
|
||||
public CNG getAltitudeCng(long baseSeed, IrisData data) {
|
||||
return altitudeCache.aquire(() -> altitudeStyle.create(new RNG(baseSeed ^ 0xA17DEBBL), data));
|
||||
public NoiseSampler altitudeNoise() {
|
||||
return altitudeCache.aquire(() -> noise(settings.altitudeStyle(), ALTITUDE_SALT));
|
||||
}
|
||||
|
||||
public CNG getTopShapeCng(long baseSeed, IrisData data) {
|
||||
return topShapeCache.aquire(() -> topShapeStyle.create(new RNG(baseSeed ^ 0x70970601DEFL), data));
|
||||
public NoiseSampler topShapeNoise() {
|
||||
return topShapeCache.aquire(() -> noise(settings.topShapeStyle(), TOP_SHAPE_SALT));
|
||||
}
|
||||
|
||||
public CNG getBottomCng(long baseSeed, IrisData data) {
|
||||
return bottomCache.aquire(() -> bottomStyle.create(new RNG(baseSeed ^ 0xB0770075CAFEL), data));
|
||||
public NoiseSampler bottomNoise() {
|
||||
return bottomCache.aquire(() -> noise(settings.bottomStyle(), BOTTOM_SALT));
|
||||
}
|
||||
|
||||
public CNG getWallWarpCng(long baseSeed, IrisData data) {
|
||||
if (wallWarpStyle == null) {
|
||||
return null;
|
||||
}
|
||||
return wallWarpCache.aquire(() -> wallWarpStyle.create(new RNG(baseSeed ^ 0xA117BA17E0FL), data));
|
||||
public NoiseSampler wallWarpNoise() {
|
||||
Optional<NoiseStyle> style = settings.wallWarpStyle();
|
||||
return style.isEmpty() ? null : wallWarpCache.aquire(() -> noise(style.get(), WALL_WARP_SALT));
|
||||
}
|
||||
|
||||
public CNG getCarveCng(long baseSeed, IrisData data) {
|
||||
if (carveStyle == null) {
|
||||
return null;
|
||||
}
|
||||
return carveCache.aquire(() -> carveStyle.create(new RNG(baseSeed ^ 0xCA5EC1EE5EL), data));
|
||||
public NoiseSampler carveNoise() {
|
||||
Optional<NoiseStyle> style = settings.carveStyle();
|
||||
return style.isEmpty() ? null : carveCache.aquire(() -> noise(style.get(), CARVE_SALT));
|
||||
}
|
||||
|
||||
public CaveProfileSampler getCarvingProfileSampler(Engine engine, IrisData data) {
|
||||
private NoiseSampler noise(NoiseStyle style, long salt) {
|
||||
return world.noise().sampler(style, world.baseSeed() ^ salt);
|
||||
}
|
||||
|
||||
public CaveProfileSampler carvingProfileSampler() {
|
||||
if (!hasCarvingReference()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return carvingProfileSamplerCache.aquire(() -> {
|
||||
IrisBiome resolved = resolveCarvingBiome(settings.carving(), engine, data);
|
||||
CaveProfile profile = resolved == null ? null : CaveProfiles.declaredBy(resolved);
|
||||
CaveProfile profile = carvingBiome().map(world::caveProfile).orElse(null);
|
||||
if (profile == null || !profile.enabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CaveProfileSampler(data.getPackResources().noise(), engine.getSeedManager().getCarve(), profile);
|
||||
return new CaveProfileSampler(world.noise(), world.carveSeed(), profile);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasCarvingReference() {
|
||||
return !settings.carving().isBlank();
|
||||
}
|
||||
|
||||
/** The biome whose cave profile carves the island: the biome of the dimension's carving entry the id names, or the biome the id names. */
|
||||
Optional<ResourceId> carvingBiome() {
|
||||
String carving = settings.carving();
|
||||
return !carving.isBlank();
|
||||
Optional<CarvingEntry> entry = world.dimensionCarving(carving);
|
||||
if (entry.isEmpty()) {
|
||||
return world.host().biome(carving);
|
||||
}
|
||||
String biomeKey = entry.get().biome().trim();
|
||||
return biomeKey.isEmpty() ? Optional.empty() : world.host().biome(biomeKey);
|
||||
}
|
||||
|
||||
static IrisBiome resolveCarvingBiome(String carving, Engine engine, IrisData data) {
|
||||
if (carving == null || carving.isBlank() || engine == null || data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CarvingEntry entry = dimensionCarvingEntry(carving, engine);
|
||||
if (entry != null) {
|
||||
String biomeKey = entry.biome().trim();
|
||||
return biomeKey.isEmpty() || data.getBiomeLoader() == null ? null : data.getBiomeLoader().load(biomeKey);
|
||||
}
|
||||
|
||||
if (data.getBiomeLoader() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return data.getBiomeLoader().load(carving);
|
||||
public KList<ObjectPlacement> resolveTopObjects(ResourceId target) {
|
||||
List<ObjectPlacement> surface = settings.inheritObjects() && target != null ? FloatingWorld.surfaceObjects(world.objects(), target) : List.of();
|
||||
return topObjects(settings, surface);
|
||||
}
|
||||
|
||||
/** The dimension's carving entry with this id (the last of several with one id); null when it declares none. */
|
||||
private static CarvingEntry dimensionCarvingEntry(String id, Engine engine) {
|
||||
CarvingEntry found = null;
|
||||
for (CarvingEntry entry : engine.getDimension().getModuleSettings().find(CarvingSettings.class).map(CarvingSettings::entries).orElse(List.of())) {
|
||||
if (entry != null && !entry.id().isBlank() && entry.id().trim().equals(id)) {
|
||||
found = entry;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public KList<IrisObjectPlacement> resolveTopObjects(IrisBiome target) {
|
||||
KList<IrisObjectPlacement> surfaceObjects = (settings.inheritObjects() && target != null) ? ObjectPlacements.surface(target) : new KList<>();
|
||||
return resolveTopObjectsFromSurface(surfaceObjects);
|
||||
}
|
||||
|
||||
KList<IrisObjectPlacement> resolveTopObjectsFromSurface(KList<IrisObjectPlacement> surfaceObjects) {
|
||||
/** The placements on the island's top: the inherited {@code surfaceObjects}, the child's overrides, or both, as its mode says. */
|
||||
public static KList<ObjectPlacement> topObjects(FloatingChildBiome settings, List<ObjectPlacement> surfaceObjects) {
|
||||
return switch (settings.topObjectMode()) {
|
||||
case REPLACE -> new KList<>(settings.topObjectOverrides());
|
||||
case MERGE -> {
|
||||
KList<IrisObjectPlacement> merged = new KList<>();
|
||||
KList<ObjectPlacement> merged = new KList<>();
|
||||
merged.addAll(surfaceObjects);
|
||||
merged.addAll(settings.topObjectOverrides());
|
||||
yield merged;
|
||||
}
|
||||
case INHERIT_ONLY -> surfaceObjects;
|
||||
case INHERIT_ONLY -> new KList<>(surfaceObjects);
|
||||
};
|
||||
}
|
||||
|
||||
public KList<IrisObjectPlacement> resolveBottomObjects(IrisBiome target) {
|
||||
public KList<ObjectPlacement> resolveBottomObjects() {
|
||||
return bottomObjects(settings);
|
||||
}
|
||||
|
||||
/** The placements hung under the island: the child's overrides, unless its mode only inherits, which hangs nothing. */
|
||||
public static KList<ObjectPlacement> bottomObjects(FloatingChildBiome settings) {
|
||||
return switch (settings.bottomObjectMode()) {
|
||||
case INHERIT_ONLY -> new KList<>();
|
||||
case MERGE, REPLACE -> new KList<>(settings.bottomObjectOverrides());
|
||||
@@ -214,27 +183,16 @@ public final class ResolvedFloatingChild implements IRare {
|
||||
return shrink > 0 && shrink < 1.0;
|
||||
}
|
||||
|
||||
public IrisObjectScale getShrinkScale() {
|
||||
return shrinkScaleCache.aquire(() -> {
|
||||
IrisObjectScale s = new IrisObjectScale();
|
||||
s.setSize(Math.max(0.01, Math.min(1.0, settings.objectShrinkFactor())));
|
||||
return s;
|
||||
});
|
||||
/** How much the island shrinks the objects it hosts. */
|
||||
public double shrinkFactor() {
|
||||
return Math.max(MIN_SHRINK_FACTOR, Math.min(1.0, settings.objectShrinkFactor()));
|
||||
}
|
||||
|
||||
public IrisBiome getRealBiome(IrisBiome parent, IrisData data) {
|
||||
return resolvedBiome.aquire(() -> {
|
||||
String biome = settings.biome();
|
||||
if (biome.isBlank() || biome.equals(parent.getLoadKey())) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
IrisBiome loaded = data.getBiomeLoader().load(biome);
|
||||
if (loaded == null) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
return loaded;
|
||||
});
|
||||
/** The biome the island's palette, decorators and objects come from: the biome the child names, or {@code parent}. */
|
||||
public ResourceId realBiome(ResourceId parent) {
|
||||
if (settings.biome().isBlank()) {
|
||||
return parent;
|
||||
}
|
||||
return namedBiome.aquire(() -> world.host().biome(settings.biome())).orElse(parent);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user