mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Merge master (T, C, L) into wave3/s: iris:post reads T's post and terrain settings, iris:perfection C's hideOresForHiddenOre; a layer's block picks move into the shared, portable LayerBlocks so terrain, caves and post keep one noise per layer; PendingSettings is gone
This commit is contained in:
commit
2148eb28cd
140 files changed
+5658
-3746
No files matched your search
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* 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.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersMaxSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayerBlocks;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.PaletteLayer;
|
||||
import art.arcane.iris.builtin.terrain.SeaLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.WallSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisValues;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* What the terrain module keeps for one world about the layers of its biomes: each layer made ready ({@link ResolvedLayer})
|
||||
* and the noise that sets the thickness of a biome's layers, and the blocks the layers of a biome stack up to at a column.
|
||||
* A biome's layers are its {@link LayersSettings}, {@link SeaLayersSettings} and {@link CaveCeilingLayersSettings}; a biome
|
||||
* that declares no layers has the one layer of grass the settings default to.
|
||||
*
|
||||
* <p>The noise of a biome's layers is built once, from the random of the first column asked for, as it always was.
|
||||
*/
|
||||
public final class BiomeLayers {
|
||||
private static final int SURFACE_HEIGHT_SEED = 7235;
|
||||
private static final int SEA_HEIGHT_SEED = 7735;
|
||||
private static final int LOCKED_LAYERS_REFERENCE_HEIGHT = 512;
|
||||
private static final LayersSettings DEFAULT_LAYERS = new LayersSettings();
|
||||
private static final PaletteLayer NO_LAYER = PaletteLayer.withoutBlocks();
|
||||
|
||||
private static final class States {
|
||||
private static final PlatformBlockState BARRIER = B.getState("BARRIER");
|
||||
}
|
||||
|
||||
private final Supplier<LayerBlocks> layerBlocks;
|
||||
private final Map<PaletteLayer, ResolvedLayer> resolved = new ConcurrentHashMap<>();
|
||||
private final Map<LayersSettings, AtomicCache<KList<CNG>>> surfaceHeights = new ConcurrentHashMap<>();
|
||||
private final Map<SeaLayersSettings, AtomicCache<KList<CNG>>> seaHeights = new ConcurrentHashMap<>();
|
||||
private volatile Double busiestBiomeLayerCount;
|
||||
|
||||
/** The layers of the world {@code engine} generates now. */
|
||||
public static BiomeLayers of(Engine engine) {
|
||||
return engine.getGeneration().state(BiomeLayers.class,
|
||||
generating -> new BiomeLayers(() -> LayerBlocks.of(generating.getGeneration().world())));
|
||||
}
|
||||
|
||||
/** The layers of a world whose layer blocks {@code layerBlocks} gives, asked for when a layer first picks a block. */
|
||||
public BiomeLayers(Supplier<LayerBlocks> layerBlocks) {
|
||||
this.layerBlocks = layerBlocks;
|
||||
}
|
||||
|
||||
/** {@code layer} ready for this world; its block picks are the world's {@link LayerBlocks}. */
|
||||
public ResolvedLayer resolve(PaletteLayer layer) {
|
||||
return resolved.computeIfAbsent(layer, declared -> ResolvedLayer.of(declared, layerBlocks));
|
||||
}
|
||||
|
||||
/** The biome's wall, which places no block when the biome declares none. */
|
||||
public ResolvedLayer wall(IrisBiome biome) {
|
||||
PaletteLayer layer = biome.getModuleSettings().find(WallSettings.class).map(WallSettings::layer).orElse(NO_LAYER);
|
||||
return resolve(layer);
|
||||
}
|
||||
|
||||
/** The layers of the biome's surface, top first. */
|
||||
public static List<PaletteLayer> layersOf(IrisBiome biome) {
|
||||
return surfaceSettings(biome).layers();
|
||||
}
|
||||
|
||||
/** The noise style of each layer of the biome's surface, top first, as Iris's generators know them. */
|
||||
public static List<NoiseStyle> layerStyles(IrisBiome biome) {
|
||||
return layersOf(biome).stream().map(layer -> IrisValues.generatorStyle(layer.style()).getStyle()).toList();
|
||||
}
|
||||
|
||||
/** The most layers any biome the dimension reaches has, which is what studio's layer load view compares a biome with. */
|
||||
public double busiestLayerCount(Engine engine) {
|
||||
Double cached = busiestBiomeLayerCount;
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
double busiest = 0D;
|
||||
for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
busiest = Math.max(busiest, layersOf(biome).size());
|
||||
}
|
||||
busiestBiomeLayerCount = busiest;
|
||||
return busiest;
|
||||
}
|
||||
|
||||
/** The blocks the biome's layers stack up to at the column, top first, at most {@code maxDepth} of them. */
|
||||
public KList<PlatformBlockState> generateLayers(IrisBiome biome, IrisDimension dimension, double wx, double wz, RNG random, int maxDepth, int height, IrisData data, IrisComplex complex) {
|
||||
if (isLocked(biome)) {
|
||||
return generateLockedLayers(biome, wx, wz, random, maxDepth, height, complex);
|
||||
}
|
||||
|
||||
KList<PlatformBlockState> blocks = new KList<>();
|
||||
if (maxDepth <= 0) {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
LayersSettings settings = surfaceSettings(biome);
|
||||
List<PaletteLayer> layers = settings.layers();
|
||||
if (layers.isEmpty()) {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
KList<CNG> heightNoises = surfaceHeightNoises(settings, random);
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
ResolvedLayer layer = resolve(layers.get(i));
|
||||
double depth = layerDepth(layer, heightNoises.get(i), wx, wz, complex);
|
||||
if (depth <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stackLayer(blocks, layer, i, depth, wx, wz, random, maxDepth);
|
||||
if (blocks.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
|
||||
separateLayers(blocks, dimension, maxDepth);
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** The blocks the biome's cave ceiling layers stack up to at the column, nearest the ceiling first, at most {@code maxDepth} of them. */
|
||||
public KList<PlatformBlockState> generateCeilingLayers(IrisBiome biome, IrisDimension dimension, double wx, double wz, RNG random, int maxDepth, int height, IrisData data, IrisComplex complex) {
|
||||
KList<PlatformBlockState> blocks = new KList<>();
|
||||
if (maxDepth <= 0) {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
List<PaletteLayer> ceilingLayers = biome.getModuleSettings().find(CaveCeilingLayersSettings.class)
|
||||
.map(CaveCeilingLayersSettings::layers).orElse(List.of());
|
||||
if (ceilingLayers.isEmpty()) {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
KList<CNG> heightNoises = surfaceHeightNoises(surfaceSettings(biome), random);
|
||||
// Ceiling layers reuse the surface-layer height noise, so entries beyond the surface layers have none; skip them.
|
||||
int usableLayers = Math.min(ceilingLayers.size(), heightNoises.size());
|
||||
for (int i = 0; i < usableLayers; i++) {
|
||||
ResolvedLayer layer = resolve(ceilingLayers.get(i));
|
||||
double depth = layerThickness(layer, heightNoises.get(i), wx, wz);
|
||||
if (depth <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stackLayer(blocks, layer, i, depth, wx, wz, random, maxDepth);
|
||||
if (blocks.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
|
||||
separateLayers(blocks, dimension, maxDepth);
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** The blocks of the biome's sea layers at the column, from the water surface down, at most {@code maxDepth} of them. */
|
||||
public KList<PlatformBlockState> generateSeaLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepth, IrisData data) {
|
||||
KList<PlatformBlockState> blocks = new KList<>();
|
||||
SeaLayersSettings settings = biome.getModuleSettings().find(SeaLayersSettings.class).orElse(null);
|
||||
if (settings == null || settings.layers().isEmpty()) {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
List<PaletteLayer> layers = settings.layers();
|
||||
KList<CNG> heightNoises = seaHeightNoises(settings, random);
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
ResolvedLayer layer = resolve(layers.get(i));
|
||||
int depth = heightNoises.get(i).fit(layer.minHeight(), layer.maxHeight(), wx / layer.zoom(), wz / layer.zoom());
|
||||
if (depth < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stackLayer(blocks, layer, i, depth, wx, wz, random, maxDepth);
|
||||
if (blocks.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private KList<PlatformBlockState> generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthLimit, int height, IrisComplex complex) {
|
||||
KList<PlatformBlockState> stacked = new KList<>();
|
||||
KList<PlatformBlockState> locked = new KList<>();
|
||||
int maxDepth = Math.min(maxDepthLimit, lockedLayersMax(biome));
|
||||
if (maxDepth <= 0) {
|
||||
return stacked;
|
||||
}
|
||||
|
||||
LayersSettings settings = surfaceSettings(biome);
|
||||
List<PaletteLayer> layers = settings.layers();
|
||||
if (!layers.isEmpty()) {
|
||||
KList<CNG> heightNoises = surfaceHeightNoises(settings, random);
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
ResolvedLayer layer = resolve(layers.get(i));
|
||||
double depth = layerDepth(layer, heightNoises.get(i), wx, wz, complex);
|
||||
if (depth <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stackLayerUnlimited(stacked, layer, i, depth, wx, wz, random);
|
||||
}
|
||||
}
|
||||
|
||||
if (stacked.isEmpty()) {
|
||||
return locked;
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxDepth; i++) {
|
||||
int offset = (LOCKED_LAYERS_REFERENCE_HEIGHT - height) - i;
|
||||
locked.add(stacked.get(Math.max(offset % stacked.size(), 0)));
|
||||
}
|
||||
|
||||
return locked;
|
||||
}
|
||||
|
||||
private void stackLayer(KList<PlatformBlockState> blocks, ResolvedLayer layer, int index, double depth, double wx, double wz, RNG random, int maxDepth) {
|
||||
for (int j = 0; j < depth; j++) {
|
||||
if (blocks.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
|
||||
addBlock(blocks, layer, index, j, wx, wz, random);
|
||||
}
|
||||
}
|
||||
|
||||
private void stackLayerUnlimited(KList<PlatformBlockState> blocks, ResolvedLayer layer, int index, double depth, double wx, double wz, RNG random) {
|
||||
for (int j = 0; j < depth; j++) {
|
||||
addBlock(blocks, layer, index, j, wx, wz, random);
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds the layer's block {@code j} blocks down; a layer that fails to pick adds nothing. */
|
||||
private void addBlock(KList<PlatformBlockState> blocks, ResolvedLayer layer, int index, int j, double wx, double wz, RNG random) {
|
||||
double zoom = layer.zoom();
|
||||
try {
|
||||
blocks.add(layer.get(random, index + j, (wx + j) / zoom, j, (wz - j) / zoom));
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** The barrier blocks a dimension puts between layers to show them apart. */
|
||||
private void separateLayers(KList<PlatformBlockState> blocks, IrisDimension dimension, int maxDepth) {
|
||||
if (!dimension.isExplodeBiomePalettes()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int j = 0; j < dimension.getExplodeBiomePaletteSize(); j++) {
|
||||
blocks.add(States.BARRIER);
|
||||
if (blocks.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** How thick the layer is at the column: nothing where the slope is outside the layer's limits. */
|
||||
private double layerDepth(ResolvedLayer layer, CNG heightNoise, double wx, double wz, IrisComplex complex) {
|
||||
double depth = layerThickness(layer, heightNoise, wx, wz);
|
||||
SlopeClip slope = layer.slopeCondition();
|
||||
if (!slope.isDefault() && !slope.isValid(complex.getSlopeStream().get(wx, wz))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
private double layerThickness(ResolvedLayer layer, CNG heightNoise, double wx, double wz) {
|
||||
double zoom = layer.zoom();
|
||||
return heightNoise.fit(layer.minHeight(), layer.maxHeight(), wx / zoom, wz / zoom);
|
||||
}
|
||||
|
||||
private KList<CNG> surfaceHeightNoises(LayersSettings settings, RNG rng) {
|
||||
AtomicCache<KList<CNG>> cache = surfaceHeights.computeIfAbsent(settings, declared -> new AtomicCache<>());
|
||||
return heightNoises(cache, settings.layers(), SURFACE_HEIGHT_SEED, rng);
|
||||
}
|
||||
|
||||
private KList<CNG> seaHeightNoises(SeaLayersSettings settings, RNG rng) {
|
||||
AtomicCache<KList<CNG>> cache = seaHeights.computeIfAbsent(settings, declared -> new AtomicCache<>());
|
||||
return heightNoises(cache, settings.layers(), SEA_HEIGHT_SEED, rng);
|
||||
}
|
||||
|
||||
private KList<CNG> heightNoises(AtomicCache<KList<CNG>> cache, List<PaletteLayer> layers, int firstSeed, RNG rng) {
|
||||
KList<CNG> cached = cache.getIfPresent();
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
return cache.aquire(() -> {
|
||||
KList<CNG> noises = new KList<>();
|
||||
int seed = firstSeed;
|
||||
for (PaletteLayer layer : layers) {
|
||||
noises.add(resolve(layer).heightNoise(rng.nextParallelRNG((seed++) * seed * seed * seed)));
|
||||
}
|
||||
return noises;
|
||||
});
|
||||
}
|
||||
|
||||
private static LayersSettings surfaceSettings(IrisBiome biome) {
|
||||
return biome.getModuleSettings().find(LayersSettings.class).orElse(DEFAULT_LAYERS);
|
||||
}
|
||||
|
||||
private static boolean isLocked(IrisBiome biome) {
|
||||
return biome.getModuleSettings().find(LockLayersSettings.class).map(LockLayersSettings::locked).orElse(false);
|
||||
}
|
||||
|
||||
private static int lockedLayersMax(IrisBiome biome) {
|
||||
return biome.getModuleSettings().find(LockLayersMaxSettings.class).map(LockLayersMaxSettings::layers).orElse(LockLayersMaxSettings.DEFAULT_LAYERS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A palette's blocks as the platform's, the way terrain layers and palettes always picked from them. */
|
||||
final class PaletteBlocks {
|
||||
private PaletteBlocks() {
|
||||
}
|
||||
|
||||
/** The platform's block of each spec that has one, each repeated by its weight. */
|
||||
static List<PlatformBlockState> weighted(BlockRegistry registry, List<BlockSpec> palette) {
|
||||
List<PlatformBlockState> weighted = new ArrayList<>();
|
||||
for (BlockSpec spec : palette) {
|
||||
PlatformBlockState state = B.getState(registry.resolve(spec).key());
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
for (int n = 0; n < spec.weight(); n++) {
|
||||
weighted.add(state);
|
||||
}
|
||||
}
|
||||
return List.copyOf(weighted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.terrain.LayerBlocks;
|
||||
import art.arcane.iris.builtin.terrain.PaletteLayer;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* One {@link PaletteLayer} made ready for one world: its blocks as the platform's, and the noise that decides how thick
|
||||
* it is here, built when first asked for. Which block it picks where is the world's {@link LayerBlocks}, shared with
|
||||
* every other module that picks from the layer.
|
||||
*
|
||||
* <p>The thickness noise is built once, from the random of whoever asks first, as the layers of a biome always were.
|
||||
*/
|
||||
public final class ResolvedLayer {
|
||||
private final PaletteLayer settings;
|
||||
private final Supplier<LayerBlocks> layerBlocks;
|
||||
private final AtomicCache<List<PlatformBlockState>> blocks = new AtomicCache<>();
|
||||
private final AtomicCache<CNG> heightNoise = new AtomicCache<>();
|
||||
|
||||
private ResolvedLayer(PaletteLayer settings, Supplier<LayerBlocks> layerBlocks) {
|
||||
this.settings = settings;
|
||||
this.layerBlocks = layerBlocks;
|
||||
}
|
||||
|
||||
/** {@code settings} ready for the world whose layer blocks {@code layerBlocks} gives, asked for when first needed. */
|
||||
static ResolvedLayer of(PaletteLayer settings, Supplier<LayerBlocks> layerBlocks) {
|
||||
return new ResolvedLayer(settings, layerBlocks);
|
||||
}
|
||||
|
||||
public PaletteLayer settings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public int minHeight() {
|
||||
return settings.minHeight();
|
||||
}
|
||||
|
||||
public int maxHeight() {
|
||||
return settings.maxHeight();
|
||||
}
|
||||
|
||||
public double zoom() {
|
||||
return settings.zoom();
|
||||
}
|
||||
|
||||
public SlopeClip slopeCondition() {
|
||||
return settings.slopeCondition();
|
||||
}
|
||||
|
||||
/** Whether the layer lists any block, which is not the same as picking one: a listed block may have no weight. */
|
||||
public boolean hasPalette() {
|
||||
return !settings.palette().isEmpty();
|
||||
}
|
||||
|
||||
/** The noise that sets the layer's thickness, built from {@code rng} unless an earlier caller's is already kept. */
|
||||
public CNG heightNoise(RNG rng) {
|
||||
CNG cached = heightNoise.getIfPresent();
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
return heightNoise.aquire(() -> CNG.signature(rng.nextParallelRNG(settings.minHeight() * settings.maxHeight() + blocks().size())));
|
||||
}
|
||||
|
||||
/** The layer's block at the position, picked as {@link LayerBlocks#pick} says, or null when the palette has no block. */
|
||||
public PlatformBlockState get(RNG parent, int signature, double x, double y, double z) {
|
||||
int index = layerBlocks.get().pick(settings, parent, signature, x, y, z);
|
||||
return index == LayerBlocks.NONE ? null : blocks().get(index);
|
||||
}
|
||||
|
||||
/** {@link #get(RNG, int, double, double, double)} for a layer asked once per column, such as a slab or a wall. */
|
||||
public PlatformBlockState get(RNG rng, double x, double y, double z) {
|
||||
return get(rng, 0, x, y, z);
|
||||
}
|
||||
|
||||
private List<PlatformBlockState> blocks() {
|
||||
List<PlatformBlockState> cached = blocks.getIfPresent();
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
return blocks.aquire(() -> layerBlocks.get().blocks(settings).stream().map(block -> B.getState(block.key())).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.FluidPaletteSettings;
|
||||
import art.arcane.iris.builtin.terrain.RockPaletteSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.UpperDimensionContext;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* What the terrain module keeps for one world about the palettes that fill its terrain: the rock below the biomes' layers
|
||||
* and the fluid of its oceans and aquifers, as a block for every column, and the rock of an upper dimension. They are the
|
||||
* dimension's {@link RockPaletteSettings} and {@link FluidPaletteSettings}.
|
||||
*
|
||||
* <p>The noise of a palette is seeded from the world's complex seed and a signature of its own, as the complex always did, so
|
||||
* a column's rock and fluid do not depend on who asks first.
|
||||
*/
|
||||
public final class TerrainPalettes {
|
||||
private static final int ROCK_SIGNATURE = 45;
|
||||
private static final int FLUID_SIGNATURE = 78;
|
||||
/** The salt Iris's material palettes always added to the seed of the noise that picks their blocks. */
|
||||
private static final int PALETTE_NOISE_SALT = -23_498_896;
|
||||
|
||||
/** A block for every column. */
|
||||
@FunctionalInterface
|
||||
public interface ColumnBlocks {
|
||||
/** The block at the column, or null when the palette has no block. */
|
||||
PlatformBlockState at(double x, double z);
|
||||
}
|
||||
|
||||
private final Engine engine;
|
||||
private final AtomicCache<ColumnBlocks> rock = new AtomicCache<>();
|
||||
private final AtomicCache<ColumnBlocks> fluid = new AtomicCache<>();
|
||||
private final Map<UpperDimensionContext, ColumnBlocks> upperRocks = new ConcurrentHashMap<>();
|
||||
|
||||
TerrainPalettes(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/** The palettes of the world {@code engine} generates now. */
|
||||
public static TerrainPalettes of(Engine engine) {
|
||||
return engine.getGeneration().state(TerrainPalettes.class, TerrainPalettes::new);
|
||||
}
|
||||
|
||||
/** Builds the rock and fluid noise now instead of when first asked for. */
|
||||
public void warm() {
|
||||
rock();
|
||||
fluid();
|
||||
}
|
||||
|
||||
/** The rock at the column, below the biome's layers. */
|
||||
public PlatformBlockState rockAt(double x, double z) {
|
||||
return rock().at(x, z);
|
||||
}
|
||||
|
||||
/** The fluid at the column, above the terrain up to the fluid height. */
|
||||
public PlatformBlockState fluidAt(double x, double z) {
|
||||
return fluid().at(x, z);
|
||||
}
|
||||
|
||||
/** The rock at the column of the upper dimension: the world's own when the upper dimension is the dimension itself. */
|
||||
public PlatformBlockState upperRockAt(UpperDimensionContext upper, double x, double z) {
|
||||
return upperRocks.computeIfAbsent(upper, this::upperRock).at(x, z);
|
||||
}
|
||||
|
||||
private ColumnBlocks rock() {
|
||||
return rock.aquireOrThrow(() -> columns(rockPalette(engine.getDimension()), complexRng().nextParallelRNG(ROCK_SIGNATURE), engine.getData()));
|
||||
}
|
||||
|
||||
private ColumnBlocks fluid() {
|
||||
return fluid.aquireOrThrow(() -> columns(fluidPalette(engine.getDimension()), complexRng().nextParallelRNG(FLUID_SIGNATURE), engine.getData()));
|
||||
}
|
||||
|
||||
private RNG complexRng() {
|
||||
return new RNG(engine.getSeedManager().getComplex());
|
||||
}
|
||||
|
||||
private ColumnBlocks upperRock(UpperDimensionContext upper) {
|
||||
if (upper.isSelfReferencing()) {
|
||||
return rock();
|
||||
}
|
||||
|
||||
long seedOffset = upper.getDimension().getLoadKey().hashCode();
|
||||
RNG rng = new RNG(engine.getSeedManager().getComplex() ^ seedOffset);
|
||||
return columns(rockPalette(upper.getDimension()), rng.nextParallelRNG(ROCK_SIGNATURE), upper.getData());
|
||||
}
|
||||
|
||||
private static PaletteSpec rockPalette(IrisDimension dimension) {
|
||||
return dimension.getModuleSettings().find(RockPaletteSettings.class).orElseGet(RockPaletteSettings::new).palette();
|
||||
}
|
||||
|
||||
private static PaletteSpec fluidPalette(IrisDimension dimension) {
|
||||
return dimension.getModuleSettings().find(FluidPaletteSettings.class).orElseGet(FluidPaletteSettings::new).palette();
|
||||
}
|
||||
|
||||
/** The palette's blocks over the columns, picked by its noise: the noise at a column, from 0 to 1, is how far down the weighted list the block is. */
|
||||
private static ColumnBlocks columns(PaletteSpec palette, RNG rng, IrisData data) {
|
||||
IrisPackResources resources = data.getPackResources();
|
||||
List<PlatformBlockState> blocks = PaletteBlocks.weighted(resources.blocks(), palette.palette());
|
||||
if (blocks.isEmpty()) {
|
||||
return (x, z) -> null;
|
||||
}
|
||||
|
||||
long seed = rng.getSeed() + (PALETTE_NOISE_SALT + blocks.size());
|
||||
NoiseSampler noise = resources.noise().sampler(palette.style(), seed);
|
||||
int last = blocks.size() - 1;
|
||||
return (x, z) -> blocks.get((int) Math.round(noise.sample(x, z) * last));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user