mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Resolve ore chance fields once per ore list and seed
- Add OreBandsRuntime holding the chance field of every generator in a band list - Resolve ore band runtimes per column painter and reuse them while the column keeps the same bands - Index ore bands by generator so placement reads the held chance field instead of a per-block lookup
This commit is contained in:
1 parent
f630996c22
commit
188994e97b
8 files changed
+198
-66
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -11,20 +10,24 @@ import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* One ore list (a biome's, region's or dimension's surface or underground ores) indexed by Y. Each Y
|
||||
* holds the generators whose range contains it, in list order, so resolving a block tries exactly
|
||||
* the generators that could place there and still returns the first one that does.
|
||||
* holds the indices of the generators whose range contains it, in list order, so resolving a block tries exactly
|
||||
* the generators that could place there and still returns the first one that does. The seeded chance fields live in
|
||||
* an {@link OreBandsRuntime}, aligned with {@link #generators()}.
|
||||
*/
|
||||
public final class IrisOreBands {
|
||||
public static final IrisOreBands EMPTY = new IrisOreBands(new IrisOreGenerator[0], 0, -1, null);
|
||||
private static final int MAXIMUM_INDEXED_HEIGHT = 8192;
|
||||
|
||||
private final IrisOreGenerator[] generators;
|
||||
private final int[] everyGenerator;
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final IrisOreGenerator[][] byY;
|
||||
private final int[][] byY;
|
||||
|
||||
private IrisOreBands(IrisOreGenerator[] generators, int minY, int maxY, IrisOreGenerator[][] byY) {
|
||||
private IrisOreBands(IrisOreGenerator[] generators, int minY, int maxY, int[][] byY) {
|
||||
this.generators = generators;
|
||||
this.everyGenerator = new int[generators.length];
|
||||
Arrays.setAll(everyGenerator, index -> index);
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
this.byY = byY;
|
||||
@@ -57,19 +60,19 @@ public final class IrisOreBands {
|
||||
height > MAXIMUM_INDEXED_HEIGHT ? null : index(generators, minY, (int) height));
|
||||
}
|
||||
|
||||
private static IrisOreGenerator[][] index(IrisOreGenerator[] generators, int minY, int height) {
|
||||
IrisOreGenerator[][] byY = new IrisOreGenerator[height][];
|
||||
IrisOreGenerator[] scratch = new IrisOreGenerator[generators.length];
|
||||
IrisOreGenerator[] previous = null;
|
||||
private static int[][] index(IrisOreGenerator[] generators, int minY, int height) {
|
||||
int[][] byY = new int[height][];
|
||||
int[] scratch = new int[generators.length];
|
||||
int[] previous = null;
|
||||
for (int offset = 0; offset < height; offset++) {
|
||||
int y = minY + offset;
|
||||
int count = 0;
|
||||
for (IrisOreGenerator generator : generators) {
|
||||
if (generator.getRange().contains(y)) {
|
||||
scratch[count++] = generator;
|
||||
for (int index = 0; index < generators.length; index++) {
|
||||
if (generators[index].getRange().contains(y)) {
|
||||
scratch[count++] = index;
|
||||
}
|
||||
}
|
||||
IrisOreGenerator[] candidates = Arrays.copyOf(scratch, count);
|
||||
int[] candidates = Arrays.copyOf(scratch, count);
|
||||
byY[offset] = previous != null && Arrays.equals(previous, candidates) ? previous : candidates;
|
||||
previous = byY[offset];
|
||||
}
|
||||
@@ -92,13 +95,18 @@ public final class IrisOreBands {
|
||||
return y >= minY && y <= maxY;
|
||||
}
|
||||
|
||||
/** The banded generators in list order; chance fields built for them must keep this order. */
|
||||
public IrisOreGenerator[] generators() {
|
||||
return generators.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* The ore placed at a Y inside {@link #contains(int)}, or null when no generator places one.
|
||||
*/
|
||||
public NativeBlockState generate(int x, int y, int z, RNG rng, PackRuntime runtime) {
|
||||
IrisOreGenerator[] candidates = byY == null ? generators : byY[y - minY];
|
||||
for (IrisOreGenerator candidate : candidates) {
|
||||
NativeBlockState ore = candidate.generate(x, y, z, rng, runtime);
|
||||
NativeBlockState generate(int x, int y, int z, RNG rng, IrisOreGenerator.OreChance[] chances, PackRuntime runtime) {
|
||||
int[] candidates = byY == null ? everyGenerator : byY[y - minY];
|
||||
for (int index : candidates) {
|
||||
NativeBlockState ore = generators[index].generate(x, y, z, rng, chances[index], runtime);
|
||||
if (ore != null) {
|
||||
return ore;
|
||||
}
|
||||
|
||||
@@ -62,18 +62,28 @@ public class IrisOreGenerator {
|
||||
}
|
||||
|
||||
public NativeBlockState generate(int x, int y, int z, RNG rng, PackRuntime runtime) {
|
||||
if (threshold <= 0 || !range.contains(y)) {
|
||||
if (!canPlaceAt(y)) {
|
||||
return null;
|
||||
}
|
||||
return placeByChance(x, y, z, rng, runtime.oreChance(this, rng.getSeed()), runtime);
|
||||
}
|
||||
|
||||
if (palette.getPalette().isEmpty()) {
|
||||
/** Places with a chance field already resolved for {@code rng}'s seed, as {@link OreBandsRuntime} holds them. */
|
||||
public NativeBlockState generate(int x, int y, int z, RNG rng, OreChance chance, PackRuntime runtime) {
|
||||
if (!canPlaceAt(y)) {
|
||||
return null;
|
||||
}
|
||||
return placeByChance(x, y, z, rng, chance, runtime);
|
||||
}
|
||||
|
||||
if (runtime.oreChance(this, rng.getSeed()).sample(x, y, z) > threshold) {
|
||||
private boolean canPlaceAt(int y) {
|
||||
return threshold > 0 && range.contains(y) && !palette.getPalette().isEmpty();
|
||||
}
|
||||
|
||||
private NativeBlockState placeByChance(int x, int y, int z, RNG rng, OreChance chance, PackRuntime runtime) {
|
||||
if (chance.sample(x, y, z) > threshold) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return palette.get(rng, x, y, z, runtime);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
/**
|
||||
* What one engine derives from an {@link IrisOreBands} for one seed: the chance field of every banded generator,
|
||||
* resolved once so placing ores block by block reads plain fields instead of looking each generator up.
|
||||
*/
|
||||
public final class OreBandsRuntime {
|
||||
private final IrisOreBands bands;
|
||||
private final PackRuntime runtime;
|
||||
private final IrisOreGenerator.OreChance[] chances;
|
||||
|
||||
public OreBandsRuntime(IrisOreBands bands, long seed, PackRuntime runtime) {
|
||||
this.bands = bands;
|
||||
this.runtime = runtime;
|
||||
IrisOreGenerator[] generators = bands.generators();
|
||||
this.chances = new IrisOreGenerator.OreChance[generators.length];
|
||||
for (int index = 0; index < generators.length; index++) {
|
||||
chances[index] = runtime.oreChance(generators[index], seed);
|
||||
}
|
||||
}
|
||||
|
||||
public IrisOreBands bands() {
|
||||
return bands;
|
||||
}
|
||||
|
||||
public boolean hasOres() {
|
||||
return bands.hasOres();
|
||||
}
|
||||
|
||||
public int lowestY() {
|
||||
return bands.lowestY();
|
||||
}
|
||||
|
||||
public int highestY() {
|
||||
return bands.highestY();
|
||||
}
|
||||
|
||||
public boolean contains(int y) {
|
||||
return bands.contains(y);
|
||||
}
|
||||
|
||||
/** The ore placed at a Y inside {@link #contains(int)}, or null when no generator places one. */
|
||||
public NativeBlockState generate(int x, int y, int z, RNG rng) {
|
||||
return bands.generate(x, y, z, rng, chances, runtime);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,9 @@ import art.arcane.iris.generation.decoration.DecoratorRuntime;
|
||||
import art.arcane.iris.generation.decoration.DepositRuntime;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
import art.arcane.iris.generation.decoration.OreBandsRuntime;
|
||||
import art.arcane.iris.generation.noise.ExpressionRuntime;
|
||||
import art.arcane.iris.generation.noise.GeneratorRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisExpression;
|
||||
@@ -62,6 +64,7 @@ public final class PackRuntime {
|
||||
private static final int MATERIAL_PALETTE_SEED_CAPACITY = 32;
|
||||
private static final int CARVING_CHILD_SEED_CAPACITY = 8;
|
||||
private static final int ORE_CHANCE_SEED_CAPACITY = 32;
|
||||
private static final int ORE_BANDS_SEED_CAPACITY = 8;
|
||||
private static final int SURFACE_WARP_SEED_CAPACITY = 8;
|
||||
|
||||
private final Engine engine;
|
||||
@@ -77,6 +80,8 @@ public final class PackRuntime {
|
||||
entry -> new SeedTable<>(CARVING_CHILD_SEED_CAPACITY, seed -> entry.createChildrenGenerator(seed, this)));
|
||||
private final RuntimeTable<IrisOreGenerator, SeedTable<IrisOreGenerator.OreChance>> oreChances = new RuntimeTable<>(
|
||||
ore -> new SeedTable<>(ORE_CHANCE_SEED_CAPACITY, seed -> ore.createChance(seed, this)));
|
||||
private final RuntimeTable<IrisOreBands, SeedTable<OreBandsRuntime>> oreBands = new RuntimeTable<>(
|
||||
bands -> new SeedTable<>(ORE_BANDS_SEED_CAPACITY, seed -> new OreBandsRuntime(bands, seed, this)));
|
||||
private final RuntimeTable<IrisObjectPlacement, SeedTable<CNG>> surfaceWarps = new RuntimeTable<>(
|
||||
placement -> new SeedTable<>(SURFACE_WARP_SEED_CAPACITY, seed -> placement.createSurfaceWarp(seed, this)));
|
||||
private final ConcurrentMap<String, StructureGraphCompilation> structureGraphs = new ConcurrentHashMap<>();
|
||||
@@ -182,6 +187,11 @@ public final class PackRuntime {
|
||||
return oreChances.get(ore).get(seed);
|
||||
}
|
||||
|
||||
/** An ore list's chance fields for one seed, resolved together so painting a column holds them directly. */
|
||||
public OreBandsRuntime oreBands(IrisOreBands bands, long seed) {
|
||||
return oreBands.get(bands).get(seed);
|
||||
}
|
||||
|
||||
/** Object placements warp by the engine's component seed, so a placement keeps one warp generator per seed. */
|
||||
public CNG surfaceWarp(IrisObjectPlacement placement, long seed) {
|
||||
return surfaceWarps.get(placement).get(seed);
|
||||
|
||||
+28
-20
@@ -31,6 +31,7 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.OreBandsRuntime;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.generation.terrain.Terrain3DColumn;
|
||||
@@ -156,14 +157,14 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
private final ChunkedDataCache<NativeBlockState> rockCache;
|
||||
private final ChunkedDataCache<NativeBlockState> fluidCache;
|
||||
private final UpperDimensionContext upperContext;
|
||||
private final IrisOreBands dimensionSurfaceOres;
|
||||
private final IrisOreBands dimensionUndergroundOres;
|
||||
private final OreBandsRuntime dimensionSurfaceOres;
|
||||
private final OreBandsRuntime dimensionUndergroundOres;
|
||||
private final NativeBlockState air;
|
||||
private final NativeBlockState bedrock;
|
||||
private IrisOreBands biomeSurfaceOres;
|
||||
private IrisOreBands regionSurfaceOres;
|
||||
private IrisOreBands biomeUndergroundOres;
|
||||
private IrisOreBands regionUndergroundOres;
|
||||
private OreBandsRuntime biomeSurfaceOres;
|
||||
private OreBandsRuntime regionSurfaceOres;
|
||||
private OreBandsRuntime biomeUndergroundOres;
|
||||
private OreBandsRuntime regionUndergroundOres;
|
||||
private int surfaceOreTop;
|
||||
private int surfaceOreFloor;
|
||||
private int undergroundOreTop;
|
||||
@@ -194,8 +195,8 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
rockCache = context.getRock();
|
||||
fluidCache = context.getFluid();
|
||||
upperContext = getEngine().getUpperContext();
|
||||
dimensionSurfaceOres = hideOres ? IrisOreBands.EMPTY : dimension.getSurfaceOreBands();
|
||||
dimensionUndergroundOres = hideOres ? IrisOreBands.EMPTY : dimension.getUndergroundOreBands();
|
||||
dimensionSurfaceOres = ores(hideOres ? IrisOreBands.EMPTY : dimension.getSurfaceOreBands(), null);
|
||||
dimensionUndergroundOres = ores(hideOres ? IrisOreBands.EMPTY : dimension.getUndergroundOreBands(), null);
|
||||
air = AIR.get();
|
||||
bedrock = BEDROCK.get();
|
||||
}
|
||||
@@ -235,10 +236,10 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
: fluidCache.get(xf, zf);
|
||||
NativeBlockState rock = rockCache.get(xf, zf);
|
||||
NativeBlockState mappedSurfaceBlock = complex.getImageMapRuntime().sampleSurfaceBlock(realX, realZ);
|
||||
biomeSurfaceOres = hideOres ? IrisOreBands.EMPTY : biome.getSurfaceOreBands();
|
||||
regionSurfaceOres = hideOres ? IrisOreBands.EMPTY : region.getSurfaceOreBands();
|
||||
biomeUndergroundOres = hideOres ? IrisOreBands.EMPTY : biome.getUndergroundOreBands();
|
||||
regionUndergroundOres = hideOres ? IrisOreBands.EMPTY : region.getUndergroundOreBands();
|
||||
biomeSurfaceOres = ores(hideOres ? IrisOreBands.EMPTY : biome.getSurfaceOreBands(), biomeSurfaceOres);
|
||||
regionSurfaceOres = ores(hideOres ? IrisOreBands.EMPTY : region.getSurfaceOreBands(), regionSurfaceOres);
|
||||
biomeUndergroundOres = ores(hideOres ? IrisOreBands.EMPTY : biome.getUndergroundOreBands(), biomeUndergroundOres);
|
||||
regionUndergroundOres = ores(hideOres ? IrisOreBands.EMPTY : region.getUndergroundOreBands(), regionUndergroundOres);
|
||||
surfaceOreTop = oreTop(biomeSurfaceOres, regionSurfaceOres, dimensionSurfaceOres);
|
||||
surfaceOreFloor = oreFloor(biomeSurfaceOres, regionSurfaceOres, dimensionSurfaceOres);
|
||||
undergroundOreTop = oreTop(biomeUndergroundOres, regionUndergroundOres, dimensionUndergroundOres);
|
||||
@@ -404,7 +405,14 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
runState = null;
|
||||
}
|
||||
|
||||
private static int oreTop(IrisOreBands first, IrisOreBands second, IrisOreBands third) {
|
||||
private OreBandsRuntime ores(IrisOreBands bands, OreBandsRuntime previousColumn) {
|
||||
if (previousColumn != null && previousColumn.bands() == bands) {
|
||||
return previousColumn;
|
||||
}
|
||||
return runtime.oreBands(bands, rng.getSeed());
|
||||
}
|
||||
|
||||
private static int oreTop(OreBandsRuntime first, OreBandsRuntime second, OreBandsRuntime third) {
|
||||
int top = Integer.MIN_VALUE;
|
||||
if (first.hasOres()) {
|
||||
top = Math.max(top, first.highestY());
|
||||
@@ -418,7 +426,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
return top;
|
||||
}
|
||||
|
||||
private static int oreFloor(IrisOreBands first, IrisOreBands second, IrisOreBands third) {
|
||||
private static int oreFloor(OreBandsRuntime first, OreBandsRuntime second, OreBandsRuntime third) {
|
||||
int floor = Integer.MAX_VALUE;
|
||||
if (first.hasOres()) {
|
||||
floor = Math.min(floor, first.lowestY());
|
||||
@@ -435,13 +443,13 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
private NativeBlockState surfaceOre(int realX, int y, int realZ) {
|
||||
NativeBlockState ore = null;
|
||||
if (biomeSurfaceOres.contains(y)) {
|
||||
ore = biomeSurfaceOres.generate(realX, y, realZ, rng, runtime);
|
||||
ore = biomeSurfaceOres.generate(realX, y, realZ, rng);
|
||||
}
|
||||
if (ore == null && regionSurfaceOres.contains(y)) {
|
||||
ore = regionSurfaceOres.generate(realX, y, realZ, rng, runtime);
|
||||
ore = regionSurfaceOres.generate(realX, y, realZ, rng);
|
||||
}
|
||||
if (ore == null && dimensionSurfaceOres.contains(y)) {
|
||||
ore = dimensionSurfaceOres.generate(realX, y, realZ, rng, runtime);
|
||||
ore = dimensionSurfaceOres.generate(realX, y, realZ, rng);
|
||||
}
|
||||
return ore;
|
||||
}
|
||||
@@ -449,13 +457,13 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
private NativeBlockState undergroundOre(int realX, int y, int realZ) {
|
||||
NativeBlockState ore = null;
|
||||
if (biomeUndergroundOres.contains(y)) {
|
||||
ore = biomeUndergroundOres.generate(realX, y, realZ, rng, runtime);
|
||||
ore = biomeUndergroundOres.generate(realX, y, realZ, rng);
|
||||
}
|
||||
if (ore == null && regionUndergroundOres.contains(y)) {
|
||||
ore = regionUndergroundOres.generate(realX, y, realZ, rng, runtime);
|
||||
ore = regionUndergroundOres.generate(realX, y, realZ, rng);
|
||||
}
|
||||
if (ore == null && dimensionUndergroundOres.contains(y)) {
|
||||
ore = dimensionUndergroundOres.generate(realX, y, realZ, rng, runtime);
|
||||
ore = dimensionUndergroundOres.generate(realX, y, realZ, rng);
|
||||
}
|
||||
return ore;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package art.arcane.iris.structure.placement;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.OreBandsRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stage.IrisTerrainNormalActuator;
|
||||
@@ -72,12 +73,12 @@ public final class IrisStructureStrata implements StructureStrata {
|
||||
private final KList<NativeBlockState> layers;
|
||||
private final NativeBlockState mapped;
|
||||
private final NativeBlockState rock;
|
||||
private final IrisOreBands biomeSurface;
|
||||
private final IrisOreBands regionSurface;
|
||||
private final IrisOreBands dimensionSurface;
|
||||
private final IrisOreBands biomeUnderground;
|
||||
private final IrisOreBands regionUnderground;
|
||||
private final IrisOreBands dimensionUnderground;
|
||||
private final OreBandsRuntime biomeSurface;
|
||||
private final OreBandsRuntime regionSurface;
|
||||
private final OreBandsRuntime dimensionSurface;
|
||||
private final OreBandsRuntime biomeUnderground;
|
||||
private final OreBandsRuntime regionUnderground;
|
||||
private final OreBandsRuntime dimensionUnderground;
|
||||
|
||||
private StrataColumn(int x, int z, int surface, boolean submerged, KList<NativeBlockState> layers,
|
||||
NativeBlockState mapped, NativeBlockState rock, IrisBiome biome, IrisRegion region) {
|
||||
@@ -88,12 +89,12 @@ public final class IrisStructureStrata implements StructureStrata {
|
||||
this.layers = layers;
|
||||
this.mapped = mapped;
|
||||
this.rock = rock;
|
||||
biomeSurface = hideOres ? IrisOreBands.EMPTY : biome.getSurfaceOreBands();
|
||||
regionSurface = hideOres ? IrisOreBands.EMPTY : region.getSurfaceOreBands();
|
||||
dimensionSurface = hideOres ? IrisOreBands.EMPTY : dimension.getSurfaceOreBands();
|
||||
biomeUnderground = hideOres ? IrisOreBands.EMPTY : biome.getUndergroundOreBands();
|
||||
regionUnderground = hideOres ? IrisOreBands.EMPTY : region.getUndergroundOreBands();
|
||||
dimensionUnderground = hideOres ? IrisOreBands.EMPTY : dimension.getUndergroundOreBands();
|
||||
biomeSurface = ores(biome.getSurfaceOreBands());
|
||||
regionSurface = ores(region.getSurfaceOreBands());
|
||||
dimensionSurface = ores(dimension.getSurfaceOreBands());
|
||||
biomeUnderground = ores(biome.getUndergroundOreBands());
|
||||
regionUnderground = ores(region.getUndergroundOreBands());
|
||||
dimensionUnderground = ores(dimension.getUndergroundOreBands());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,16 +121,20 @@ public final class IrisStructureStrata implements StructureStrata {
|
||||
return layers.size();
|
||||
}
|
||||
|
||||
private NativeBlockState ore(IrisOreBands first, IrisOreBands second, IrisOreBands third, int internalY) {
|
||||
private OreBandsRuntime ores(IrisOreBands bands) {
|
||||
return runtime.oreBands(hideOres ? IrisOreBands.EMPTY : bands, rng.getSeed());
|
||||
}
|
||||
|
||||
private NativeBlockState ore(OreBandsRuntime first, OreBandsRuntime second, OreBandsRuntime third, int internalY) {
|
||||
NativeBlockState ore = null;
|
||||
if (first.contains(internalY)) {
|
||||
ore = first.generate(x, internalY, z, rng, runtime);
|
||||
ore = first.generate(x, internalY, z, rng);
|
||||
}
|
||||
if (ore == null && second.contains(internalY)) {
|
||||
ore = second.generate(x, internalY, z, rng, runtime);
|
||||
ore = second.generate(x, internalY, z, rng);
|
||||
}
|
||||
if (ore == null && third.contains(internalY)) {
|
||||
ore = third.generate(x, internalY, z, rng, runtime);
|
||||
ore = third.generate(x, internalY, z, rng);
|
||||
}
|
||||
return ore;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class IrisOreBandsTest {
|
||||
}
|
||||
for (int x = -3; x <= 3; x++) {
|
||||
assertSame("trial " + trial + " y " + y + " x " + x,
|
||||
scan(ores, x, y, 5 - x), bands.generate(x, y, 5 - x, RNG_SOURCE, PackRuntime.standalone(null)));
|
||||
scan(ores, x, y, 5 - x), generate(bands, x, y, 5 - x));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,10 @@ public class IrisOreBandsTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static NativeBlockState generate(IrisOreBands bands, int x, int y, int z) {
|
||||
return PackRuntime.standalone(null).oreBands(bands, RNG_SOURCE.getSeed()).generate(x, y, z, RNG_SOURCE);
|
||||
}
|
||||
|
||||
private static NativeBlockState scan(KList<IrisOreGenerator> ores, int x, int y, int z) {
|
||||
for (IrisOreGenerator ore : ores) {
|
||||
NativeBlockState state = ore.generate(x, y, z, RNG_SOURCE, PackRuntime.standalone(null));
|
||||
@@ -110,10 +114,10 @@ public class IrisOreBandsTest {
|
||||
ores.add(generator(1D, 57D, 1D, 2L));
|
||||
ores.add(generator(58D, 58D, 1D, 3L));
|
||||
IrisOreBands bands = IrisOreBands.of(ores);
|
||||
assertSame(scan(ores, 0, 0, 0), bands.generate(0, 0, 0, RNG_SOURCE, PackRuntime.standalone(null)));
|
||||
assertSame(scan(ores, 0, 30, 0), bands.generate(0, 30, 0, RNG_SOURCE, PackRuntime.standalone(null)));
|
||||
assertSame(scan(ores, 0, 58, 0), bands.generate(0, 58, 0, RNG_SOURCE, PackRuntime.standalone(null)));
|
||||
assertNull(bands.contains(59) ? bands.generate(0, 59, 0, RNG_SOURCE, PackRuntime.standalone(null)) : null);
|
||||
assertSame(scan(ores, 0, 0, 0), generate(bands, 0, 0, 0));
|
||||
assertSame(scan(ores, 0, 30, 0), generate(bands, 0, 30, 0));
|
||||
assertSame(scan(ores, 0, 58, 0), generate(bands, 0, 58, 0));
|
||||
assertNull(bands.contains(59) ? generate(bands, 0, 59, 0) : null);
|
||||
}
|
||||
private static final class FixedPalette extends IrisMaterialPalette {
|
||||
private final NativeBlockState state;
|
||||
|
||||
+23
-4
@@ -3,7 +3,11 @@ package art.arcane.iris.structure.placement;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.generation.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
@@ -110,11 +114,12 @@ public class IrisStructureStrataTest {
|
||||
public void oreBandsAreSampledAtEachHeightSoAFillNeverStretchesOneOreBlock() {
|
||||
dimension.setHideOresForHiddenOre(false);
|
||||
NativeBlockState coal = state("minecraft:coal_ore");
|
||||
IrisOreBands bands = mock(IrisOreBands.class);
|
||||
IrisOreGenerator coalSeam = new IrisOreGenerator()
|
||||
.setPalette(new FixedPalette(coal))
|
||||
.setThreshold(1D)
|
||||
.setRange(new IrisRange(40 - MIN_HEIGHT, 40 - MIN_HEIGHT));
|
||||
when(biome.getSurfaceOreBands()).thenReturn(IrisOreBands.EMPTY);
|
||||
when(biome.getUndergroundOreBands()).thenReturn(bands);
|
||||
when(bands.contains(anyInt())).thenReturn(true);
|
||||
when(bands.generate(eq(3), eq(40 - MIN_HEIGHT), eq(5), any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(coal);
|
||||
when(biome.getUndergroundOreBands()).thenReturn(IrisOreBands.of(new KList<>(List.of(coalSeam))));
|
||||
|
||||
StructureStrata.Column column = IrisStructureStrata.world(engine).column(3, 5, 90, false);
|
||||
|
||||
@@ -122,6 +127,20 @@ public class IrisStructureStrataTest {
|
||||
assertSame(rock, column.block(41));
|
||||
}
|
||||
|
||||
private static final class FixedPalette extends IrisMaterialPalette {
|
||||
private final NativeBlockState state;
|
||||
|
||||
private FixedPalette(NativeBlockState state) {
|
||||
this.state = state;
|
||||
setPalette(new KList<>(new IrisBlockData()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBlockState get(RNG rng, double x, double y, double z, PackRuntime runtime) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
private static NativeBlockState state(String key) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn(key);
|
||||
|
||||
Reference in new issue
Block a user