Merge upstream port lane a

This commit is contained in:
piexel committed 2026-11-10 01:31:27 +01:00
commit 11f45a4077
35 files changed
+767 -489

No files matched your search

@@ -48,6 +48,7 @@ import java.util.stream.Stream;
public class CustomBiomeSource extends BiomeSource {
private static final int NOISE_BIOME_CACHE_MAX = 262144;
private static final int NOISE_BIOME_CACHE_CHECK_Y_MASK = 63;
private static final int STRONGHOLD_RING_SEARCH_Y = 0;
private static final int STRONGHOLD_RING_SEARCH_RADIUS = 112;
private static final int STRONGHOLD_RING_SEARCH_QUART_STEP = 4;
@@ -452,7 +453,7 @@ public class CustomBiomeSource extends BiomeSource {
return existingHolder;
}
if (noiseBiomeCache.size() > NOISE_BIOME_CACHE_MAX) {
if ((y & NOISE_BIOME_CACHE_CHECK_Y_MASK) == 0 && noiseBiomeCache.size() > NOISE_BIOME_CACHE_MAX) {
noiseBiomeCache.clear();
}
@@ -72,7 +72,9 @@ public final class ModdedBlockResolution {
"pink_shulker_box", "gray_shulker_box", "light_gray_shulker_box", "cyan_shulker_box",
"purple_shulker_box", "blue_shulker_box", "brown_shulker_box", "green_shulker_box",
"red_shulker_box", "black_shulker_box", "barrel", "dispenser", "dropper", "hopper", "furnace",
"blast_furnace");
"blast_furnace", "copper_chest", "exposed_copper_chest", "weathered_copper_chest",
"oxidized_copper_chest", "waxed_copper_chest", "waxed_exposed_copper_chest",
"waxed_weathered_copper_chest", "waxed_oxidized_copper_chest");
private static final Set<Block> STORAGE_CHEST = storageChestSet();
private static final Set<Block> DEEPSLATE = blockSet(
"deepslate", "deepslate_bricks", "deepslate_brick_slab", "deepslate_brick_stairs",
@@ -22,6 +22,7 @@ import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.core.content.ContentEntity;
import art.arcane.iris.core.content.ContentItem;
import art.arcane.iris.core.content.ContentSpawns;
import art.arcane.iris.modded.api.ModdedCustomContentRegistry;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.volmlib.util.math.RNG;
@@ -248,7 +249,8 @@ public final class ModdedEntitySpawner {
}
}
static boolean isAreaClearForSpawn(ServerLevel level, ContentEntity entity, int blockX, int blockY, int blockZ) {
static boolean isAreaClearForSpawn(ServerLevel level, ContentEntity entity, ContentSpawns.Surface surface,
int blockX, int blockY, int blockZ) {
if (entity.isSpecial()) {
return true;
}
@@ -256,10 +258,33 @@ public final class ModdedEntitySpawner {
if (type == null) {
return true;
}
if (surface.isFluid()) {
return isFluidAreaClearForSpawn(blockX, blockY, blockZ, type.getWidth(), type.getHeight(),
position -> ModdedWorldManager.matchesSurface(surface, level.getBlockState(position)));
}
return isAreaClearForSpawn(blockX, blockY, blockZ, type.getWidth(), type.getHeight(),
position -> level.getBlockState(position).is(Blocks.AIR));
}
static boolean isFluidAreaClearForSpawn(int blockX, int blockY, int blockZ,
float width, float height, Predicate<BlockPos> isFluid) {
int startX = (int) Math.floor(blockX + 0.5 - width / 2D);
int endX = (int) Math.floor(Math.nextDown(blockX + 0.5 + width / 2D));
int endY = (int) Math.floor(Math.nextDown(blockY + 0.5 + height));
int startZ = (int) Math.floor(blockZ + 0.5 - width / 2D);
int endZ = (int) Math.floor(Math.nextDown(blockZ + 0.5 + width / 2D));
for (int x = startX; x <= endX; x++) {
for (int y = blockY; y <= endY; y++) {
for (int z = startZ; z <= endZ; z++) {
if (!isFluid.test(new BlockPos(x, y, z))) {
return false;
}
}
}
}
return true;
}
static boolean isAreaClearForSpawn(int blockX, int blockY, int blockZ, float width, float height, Predicate<BlockPos> isAir) {
int radius = (int) (width / 2F);
int endY = blockY + (int) height;
@@ -465,12 +465,14 @@ public final class ModdedWorldManager implements EngineWorldManager {
}
private static boolean surfaceAllows(ContentSpawns.Attempt attempt, ServerLevel level) {
BlockState below = level.getBlockState(new BlockPos(attempt.x(), attempt.worldY() - 1, attempt.z()));
return matchesSurface(attempt.surface(), below)
&& ModdedEntitySpawner.isAreaClearForSpawn(level, attempt.entity(), attempt.x(), attempt.worldY(), attempt.z());
int surfaceY = attempt.surface().isFluid() ? attempt.worldY() : attempt.worldY() - 1;
BlockState surfaceBlock = level.getBlockState(new BlockPos(attempt.x(), surfaceY, attempt.z()));
return matchesSurface(attempt.surface(), surfaceBlock)
&& ModdedEntitySpawner.isAreaClearForSpawn(level, attempt.entity(), attempt.surface(),
attempt.x(), attempt.worldY(), attempt.z());
}
private static boolean matchesSurface(ContentSpawns.Surface surface, BlockState below) {
static boolean matchesSurface(ContentSpawns.Surface surface, BlockState below) {
if (ModdedBlockResolution.isSolid(below)) {
return surface == ContentSpawns.Surface.LAND || surface == ContentSpawns.Surface.OVERWORLD
|| (surface == ContentSpawns.Surface.ANIMAL && isAnimalGround(below));
@@ -2,6 +2,7 @@ package art.arcane.iris.modded;
import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -52,6 +53,33 @@ public class ModdedBlockResolutionContractTest {
assertEquals(Blocks.OAK_LOG, state.handle().getBlock());
}
@Test
public void copperChestVariantsReceiveIrisLootAndPostLoadUpdates() {
for (String key : new String[]{"copper_chest", "exposed_copper_chest", "weathered_copper_chest",
"oxidized_copper_chest", "waxed_copper_chest", "waxed_exposed_copper_chest",
"waxed_weathered_copper_chest", "waxed_oxidized_copper_chest"}) {
ModdedBlockState state = ModdedBlockResolution.getOrNull("minecraft:" + key);
assertNotNull(key, state);
assertTrue(key, state.isStorage());
assertTrue(key, state.isStorageChest());
assertTrue(key, state.isUpdatable());
}
}
@Test
public void furnacesAreStorageButNotLootChests() {
for (Block block : new Block[]{Blocks.FURNACE, Blocks.BLAST_FURNACE, Blocks.SMOKER}) {
assertTrue(block.toString(), ModdedBlockResolution.isStorage(block.defaultBlockState()));
assertFalse(block.toString(), ModdedBlockResolution.isStorageChest(block.defaultBlockState()));
}
for (String key : new String[]{"stone", "ender_chest", "copper_block"}) {
ModdedBlockState state = ModdedBlockResolution.getOrNull("minecraft:" + key);
assertNotNull(key, state);
assertFalse(key, state.isStorage());
assertFalse(key, state.isStorageChest());
}
}
@Test
public void cactusPlacementRequiresNativeCactusSupport() {
assertTrue(ModdedBlockResolution.canPlaceOnto(Blocks.CACTUS, Blocks.CACTUS));
@@ -51,6 +51,34 @@ public class ModdedEntitySpawnerParityTest {
assertFalse(clear);
}
@Test
public void fractionalFluidVolumeIncludesHorizontalEdgesAndCenteredHeight() {
Set<BlockPos> checked = new HashSet<>();
assertTrue(ModdedEntitySpawner.isFluidAreaClearForSpawn(-1, 78, -1, 1.3F, 0.8F, position -> {
checked.add(position);
return true;
}));
assertEquals(18, checked.size());
assertTrue(checked.contains(new BlockPos(-2, 79, -2)));
assertTrue(checked.contains(new BlockPos(0, 78, 0)));
assertFalse(ModdedEntitySpawner.isFluidAreaClearForSpawn(-1, 78, -1, 1.3F, 0.8F,
position -> !position.equals(new BlockPos(-2, 79, -2))));
}
@Test
public void exactUpperBoundaryDoesNotRequireFluidOutsideTheBody() {
Set<BlockPos> checked = new HashSet<>();
assertTrue(ModdedEntitySpawner.isFluidAreaClearForSpawn(0, 78, 0, 1F, 0.5F, position -> {
checked.add(position);
return true;
}));
assertEquals(Set.of(new BlockPos(0, 78, 0)), checked);
}
@Test
public void spawnSafetyRequiresTheTargetChunkAndAllEightNeighbors() {
Set<Long> loaded = new HashSet<>();
@@ -93,7 +93,8 @@ public interface EntitySpawns {
/**
* One entity to spawn at a block. The host spawns it only if the block's light level lies in the range (when the
* range is restricted) and, when {@code checkSurface}, the block below suits the entity's {@code surface} and the
* space the entity needs is free.
* space the entity needs is free. An entity of a fluid surface is always checked, and needs the block it spawns in
* and the space it fills to be that fluid.
*
* @param at world X and Z, Y the height above the dimension's bottom
* @param entity what to spawn
@@ -126,6 +127,11 @@ public interface EntitySpawns {
/** Solid ground or water. */
OVERWORLD,
/** Within lava. */
LAVA
LAVA;
/** Whether the entity lives in the fluid, so the block it spawns in must be that fluid. */
public boolean isFluid() {
return this == WATER || this == LAVA;
}
}
}
-1
View File
@@ -604,7 +604,6 @@ List<String> requiredBukkitArtifactEntries = [
'art/arcane/iris/engine/platform/PlatformChunkGenerator.class',
'art/arcane/iris/core/lifecycle/WorldLifecycleStaging.class',
'art/arcane/iris/util/simd/VectorSimdKernels.class',
'art/arcane/iris/util/simd/VectorNoiseKernels2D.class',
'art/arcane/iris/util/project/agent/Agent.class',
'art/arcane/iris/util/common/misc/getHardware.class',
'art/arcane/volmlib/util/io/JarScanner.class',
@@ -30,7 +30,11 @@ public final class ContentSpawns {
/** The ground or fluid an entity spawns on. */
public enum Surface {
LAND, ANIMAL, WATER, OVERWORLD, LAVA
LAND, ANIMAL, WATER, OVERWORLD, LAVA;
public boolean isFluid() {
return this == WATER || this == LAVA;
}
}
/**
@@ -0,0 +1,26 @@
package art.arcane.iris.engine;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.volmlib.util.math.RNG;
public final class ContinentGenerator {
private static final int CONTINENT_SEED_SALT = 234234565;
private ContinentGenerator() {
}
public static CNG create(IrisDimension dimension, RNG parentSeedSource, IrisData packData) {
return dimension.getContinentalStyle()
.createScaledGenerator(deriveContinentSeed(parentSeedSource), packData, inverseContinentZoom(dimension));
}
static RNG deriveContinentSeed(RNG parentSeedSource) {
return parentSeedSource.nextParallelRNG(CONTINENT_SEED_SALT);
}
private static double inverseContinentZoom(IrisDimension dimension) {
return 1D / dimension.getContinentZoom();
}
}
@@ -248,8 +248,7 @@ public class IrisComplex implements DataProvider {
inferredStreams.put(InferredType.SHORE, shoreBiomeStream);
bridgeStream = focusBiome != null ? ProceduralStream.of((x, z) -> focusBiome.getInferredType(),
Interpolated.of(a -> 0D, a -> focusBiome.getInferredType())) :
engine.getDimension().getContinentalStyle().create(rng.nextParallelRNG(234234565), getData())
.bake().scale(1D / engine.getDimension().getContinentZoom()).bake().stream()
ContinentGenerator.create(engine.getDimension(), rng, getData()).stream()
.convert((v) -> v >= engine.getDimension().getLandChance() ? InferredType.SEA : InferredType.LAND)
.cache2D("bridgeStream", engine, cacheSize);
ProceduralStream<IrisBiome> proceduralBaseBiomeStream = focusBiome != null ? ProceduralStream.of((x, z) -> implode(focusBiome, x, z),
@@ -703,9 +702,19 @@ public class IrisComplex implements DataProvider {
if (generators.length == 0) {
return 0D;
}
if (!Double.isFinite(low) || !Double.isFinite(high)) {
throw new IllegalStateException("Terrain generator bounds were not finite at " + x + "," + z
+ " (generator=" + generators[0].getLoadKey() + ", bounds=" + low + ".." + high + ").");
}
double height = 0D;
for (IrisGenerator generator : generators) {
height += M.lerp(low, high, generator.getHeight(x, z, seed));
double noise = generator.getHeight(x, z, seed);
if (!Double.isFinite(noise)) {
throw new IllegalStateException("Terrain generator noise was not finite at " + x + "," + z
+ " (generator=" + generator.getLoadKey() + ", noise=" + noise
+ ", bounds=" + low + ".." + high + ").");
}
height += M.lerp(low, high, noise);
}
return height / generators.length;
}
@@ -166,9 +166,7 @@ public class UpperDimensionContext implements DataProvider {
inferredStreams.put(InferredType.SEA, seaBiomeStream);
inferredStreams.put(InferredType.SHORE, shoreBiomeStream);
ProceduralStream<InferredType> bridgeStream = upperDim.getContinentalStyle()
.create(rng.nextParallelRNG(234234565), upperData)
.bake().scale(1D / upperDim.getContinentZoom()).bake().stream()
ProceduralStream<InferredType> bridgeStream = ContinentGenerator.create(upperDim, rng, upperData).stream()
.convert(v -> v >= upperDim.getLandChance() ? InferredType.SEA : InferredType.LAND);
ProceduralStream<IrisBiome> proceduralBaseBiomeStream = bridgeStream
@@ -368,12 +368,38 @@ final class WorldEntitySpawner {
}
private static boolean surfaceAllows(Location l, EntitySpawns.Attempt attempt) {
if (!BukkitSurfaces.matches(attempt.surface(), l.clone().subtract(0, 1, 0).getBlock())) {
EntitySpawns.Surface surface = attempt.surface();
boolean fluid = surface.isFluid();
if (!BukkitSurfaces.matches(surface, l.clone().subtract(0, fluid ? 0 : 1, 0).getBlock())) {
return false;
}
Vector3d boundingBox = BukkitPlatform.entityBoundingBox(BukkitEntitySpawner.bukkitType(attempt.entity()));
return boundingBox == null || isAreaClearForSpawn(l, boundingBox);
if (boundingBox == null) {
return true;
}
return fluid ? isFluidAreaClearForSpawn(l, boundingBox, surface) : isAreaClearForSpawn(l, boundingBox);
}
private static boolean isFluidAreaClearForSpawn(Location center, Vector3d boundingBox, EntitySpawns.Surface surface) {
World world = center.getWorld();
int startX = (int) Math.floor(center.getX() + 0.5 - boundingBox.x / 2);
int endX = (int) Math.floor(Math.nextDown(center.getX() + 0.5 + boundingBox.x / 2));
int startY = center.getBlockY();
int endY = (int) Math.floor(Math.nextDown(center.getY() + 0.5 + boundingBox.y));
int startZ = (int) Math.floor(center.getZ() + 0.5 - boundingBox.z / 2);
int endZ = (int) Math.floor(Math.nextDown(center.getZ() + 0.5 + boundingBox.z / 2));
for (int x = startX; x <= endX; x++) {
for (int y = startY; y <= endY; y++) {
for (int z = startZ; z <= endZ; z++) {
if (!BukkitSurfaces.matches(surface, world.getBlockAt(x, y, z))) {
return false;
}
}
}
}
return true;
}
private static boolean isAreaClearForSpawn(Location center, Vector3d boundingBox) {
@@ -104,6 +104,10 @@ public class IrisGeneratorStyle {
return createNoCache(rng, data, false, 0, false, resolveEngine(data));
}
public CNG createScaledGenerator(RNG rng, IrisData data, double scaleFactor) {
return createNoCache(rng, data).bake().scale(scaleFactor).bake();
}
public CNG createForPrebake(RNG rng, IrisData data, int fallbackCacheSize) {
return createNoCache(rng, data, false, Math.max(0, fallbackCacheSize), true, resolveEngine(data));
}
@@ -73,6 +73,7 @@ import java.util.Objects;
@EqualsAndHashCode(callSuper = false)
public class IrisBiome extends IrisRegistrant implements IRare {
private static final int BIOME_GENERATOR_CACHE_SIZE = 8;
private static final int CHILDREN_SEED_SALT = 2137;
private final transient AtomicCache<KMap<String, IrisBiomeGeneratorLink>> genCache = new AtomicCache<>();
private final transient AtomicCache<KMap<String, Integer>> genCacheMax = new AtomicCache<>();
@@ -296,7 +297,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
public CNG getChildrenGenerator(RNG random, int sig, double scale) {
double childScale = getChildStyle().isSeeded() ? 1 : scale;
return childrenCell.aquire(() -> getChildStyle().create(random.nextParallelRNG(sig * 2137), getLoader()).bake().scale(childScale).bake());
return childrenCell.aquire(() -> getChildStyle().createScaledGenerator(random.nextParallelRNG(sig * CHILDREN_SEED_SALT), getLoader(), childScale));
}
public boolean isLand() {
@@ -83,6 +83,7 @@ import static art.arcane.iris.util.common.data.registry.Particles.ITEM;
*/
public final class BukkitEntitySpawner {
private static final long RISE_START_DEPTH_BLOCKS = 5;
private static final int CHUNK_SHIFT = 4;
private static final int RISE_MAX_TICKS = 100;
private static final int RISE_NO_DAMAGE_TICKS = 100000;
private static final double RISE_STEP_BLOCKS = 0.1;
@@ -173,10 +174,10 @@ public final class BukkitEntitySpawner {
}
/** Players watching an entity that rises out of the ground see it start five blocks below the spot. */
private static Location startBelowGroundWhenWatched(Location at) {
static Location startBelowGroundWhenWatched(Location at) {
AtomicReference<Location> start = new AtomicReference<>(at);
try {
J.sfut(() -> {
J.runRegionFuture(at.getWorld(), at.getBlockX() >> CHUNK_SHIFT, at.getBlockZ() >> CHUNK_SHIFT, () -> {
if (Chunks.hasPlayersNearby(start.get())) {
Location b = start.get().clone();
start.set(new Location(b.getWorld(), b.getX(), b.getY() - RISE_START_DEPTH_BLOCKS, b.getZ()));
@@ -1,8 +0,0 @@
package art.arcane.iris.util.simd;
public interface NoiseKernels2D {
String describe();
void simplexFractalFBM(long seed, int octaves, double frequency, double lacunarity, double gain,
double fractalBounding, double[] xs, double[] zs, double[] out, int length);
}
@@ -1,99 +0,0 @@
package art.arcane.iris.util.simd;
public final class ScalarNoiseKernels2D implements NoiseKernels2D {
static final double F2 = 0.5D * (Math.sqrt(3.0D) - 1.0D);
static final double G2 = (3.0D - Math.sqrt(3.0D)) / 6.0D;
static final long X_PRIME = 1619L;
static final long Y_PRIME = 31337L;
static final double[] GRAD_2D = {-1D, -1D, 1D, -1D, -1D, 1D, 1D, 1D, 0D, -1D, -1D, 0D, 0D, 1D, 1D, 0D};
@Override
public String describe() {
return "scalar";
}
static long fastFloor(double f) {
return f >= 0D ? (long) f : (long) f - 1L;
}
static double gradCoord2D(long seed, long x, long y, double xd, double yd) {
long hash = seed;
hash ^= X_PRIME * x;
hash ^= Y_PRIME * y;
hash = hash * hash * hash * 60493L;
hash = (hash >> 13) ^ hash;
int gradientIndex = ((int) hash & 7) << 1;
return (xd * GRAD_2D[gradientIndex]) + (yd * GRAD_2D[gradientIndex + 1]);
}
static double singleSimplex(long seed, double x, double y) {
double t = (x + y) * F2;
long i = fastFloor(x + t);
long j = fastFloor(y + t);
t = (i + j) * G2;
double x0 = x - (i - t);
double y0 = y - (j - t);
long i1;
long j1;
if (x0 > y0) {
i1 = 1L;
j1 = 0L;
} else {
i1 = 0L;
j1 = 1L;
}
double x1 = x0 - i1 + G2;
double y1 = y0 - j1 + G2;
double x2 = x0 - 1D + (2D * G2);
double y2 = y0 - 1D + (2D * G2);
double n0;
double n1;
double n2;
double a = 0.5D - x0 * x0 - y0 * y0;
if (a < 0D) {
n0 = 0D;
} else {
a *= a;
n0 = a * a * gradCoord2D(seed, i, j, x0, y0);
}
double b = 0.5D - x1 * x1 - y1 * y1;
if (b < 0D) {
n1 = 0D;
} else {
b *= b;
n1 = b * b * gradCoord2D(seed, i + i1, j + j1, x1, y1);
}
double c = 0.5D - x2 * x2 - y2 * y2;
if (c < 0D) {
n2 = 0D;
} else {
c *= c;
n2 = c * c * gradCoord2D(seed, i + 1L, j + 1L, x2, y2);
}
return 50D * (n0 + n1 + n2);
}
static double simplexFractalFBMScalar(long seed, int octaves, double frequency, double lacunarity, double gain,
double fractalBounding, double xIn, double yIn) {
double x = xIn * frequency;
double y = yIn * frequency;
long s = seed;
double sum = singleSimplex(s, x, y);
double amp = 1D;
for (int o = 1; o < octaves; o++) {
x *= lacunarity;
y *= lacunarity;
amp *= gain;
sum += singleSimplex(++s, x, y) * amp;
}
return sum * fractalBounding;
}
@Override
public void simplexFractalFBM(long seed, int octaves, double frequency, double lacunarity, double gain,
double fractalBounding, double[] xs, double[] zs, double[] out, int length) {
for (int k = 0; k < length; k++) {
out[k] = simplexFractalFBMScalar(seed, octaves, frequency, lacunarity, gain, fractalBounding, xs[k], zs[k]);
}
}
}
@@ -54,36 +54,6 @@ public final class SimdSupport {
return vector == null ? new ScalarSimdKernels() : vector;
}
private static final NoiseKernels2D NOISE_KERNELS_2D = selectNoiseKernels2D();
public static NoiseKernels2D noiseKernels2D() {
return NOISE_KERNELS_2D;
}
public static NoiseKernels2D createVectorNoiseKernels2D() {
if (!MODULE_PRESENT) {
return null;
}
try {
Class<?> cls = Class.forName("art.arcane.iris.util.simd.VectorNoiseKernels2D");
boolean profitable = (boolean) cls.getMethod("profitable").invoke(null);
if (!profitable) {
return null;
}
return (NoiseKernels2D) cls.getDeclaredConstructor().newInstance();
} catch (Throwable e) {
return null;
}
}
private static NoiseKernels2D selectNoiseKernels2D() {
if (!simdEnabledInSettings()) {
return new ScalarNoiseKernels2D();
}
NoiseKernels2D vector = createVectorNoiseKernels2D();
return vector == null ? new ScalarNoiseKernels2D() : vector;
}
private static boolean simdEnabledInSettings() {
try {
return IrisSettings.get().getPerformance().isSimdKernels();
@@ -1,129 +0,0 @@
package art.arcane.iris.util.simd;
import jdk.incubator.vector.DoubleVector;
import jdk.incubator.vector.LongVector;
import jdk.incubator.vector.VectorMask;
import jdk.incubator.vector.VectorOperators;
import jdk.incubator.vector.VectorSpecies;
public final class VectorNoiseKernels2D implements NoiseKernels2D {
private static final VectorSpecies<Double> DS = DoubleVector.SPECIES_PREFERRED;
private static final VectorSpecies<Long> LS = LongVector.SPECIES_PREFERRED;
private static final boolean ALIGNED = DS.length() == LS.length();
private static final int MIN_PROFITABLE_LANES = 4;
private static final boolean PROFITABLE = ALIGNED && DS.length() >= MIN_PROFITABLE_LANES;
private static final double[] GRAD_X = {-1D, 1D, -1D, 1D, 0D, -1D, 0D, 1D};
private static final double[] GRAD_Y = {-1D, -1D, 1D, 1D, -1D, 0D, 1D, 0D};
private static final double F2 = ScalarNoiseKernels2D.F2;
private static final double G2 = ScalarNoiseKernels2D.G2;
private static final long X_PRIME = ScalarNoiseKernels2D.X_PRIME;
private static final long Y_PRIME = ScalarNoiseKernels2D.Y_PRIME;
private static final ThreadLocal<long[]> LONG_SCRATCH = ThreadLocal.withInitial(() -> new long[LS.length()]);
public static boolean lanesAligned() {
return ALIGNED;
}
public static boolean profitable() {
return PROFITABLE;
}
@Override
public String describe() {
return DS.length() + "x64 lanes, " + DS.vectorShape();
}
private static LongVector floorToLong(DoubleVector f) {
LongVector truncated = (LongVector) f.convertShape(VectorOperators.D2L, LS, 0);
VectorMask<Long> negative = f.compare(VectorOperators.LT, 0D).cast(LS);
return truncated.sub(1L, negative);
}
private static DoubleVector toDouble(LongVector v) {
return (DoubleVector) v.convertShape(VectorOperators.L2D, DS, 0);
}
private static DoubleVector gradCoord(long seed, LongVector i, LongVector j, DoubleVector xd, DoubleVector yd,
int[] idxScratch) {
LongVector hash = LongVector.broadcast(LS, seed)
.lanewise(VectorOperators.XOR, i.mul(X_PRIME))
.lanewise(VectorOperators.XOR, j.mul(Y_PRIME));
hash = hash.mul(hash).mul(hash).mul(60493L);
LongVector shifted = hash.lanewise(VectorOperators.ASHR, 13);
hash = shifted.lanewise(VectorOperators.XOR, hash);
LongVector idx = hash.lanewise(VectorOperators.AND, 7L);
long[] tmp = LONG_SCRATCH.get();
idx.intoArray(tmp, 0);
for (int l = 0; l < idxScratch.length; l++) {
idxScratch[l] = (int) tmp[l];
}
DoubleVector gx = DoubleVector.fromArray(DS, GRAD_X, 0, idxScratch, 0);
DoubleVector gy = DoubleVector.fromArray(DS, GRAD_Y, 0, idxScratch, 0);
return xd.mul(gx).add(yd.mul(gy));
}
private static DoubleVector corner(DoubleVector xk, DoubleVector yk, DoubleVector grad) {
DoubleVector t = DoubleVector.broadcast(DS, 0.5D).sub(xk.mul(xk)).sub(yk.mul(yk));
VectorMask<Double> negative = t.compare(VectorOperators.LT, 0D);
DoubleVector t2 = t.mul(t);
DoubleVector t4 = t2.mul(t2);
return t4.mul(grad).blend(0D, negative);
}
private static DoubleVector singleSimplexVector(long seed, DoubleVector x, DoubleVector y, int[] idxScratch) {
DoubleVector t = x.add(y).mul(F2);
LongVector i = floorToLong(x.add(t));
LongVector j = floorToLong(y.add(t));
DoubleVector skew = toDouble(i.add(j)).mul(G2);
DoubleVector x0 = x.sub(toDouble(i).sub(skew));
DoubleVector y0 = y.sub(toDouble(j).sub(skew));
VectorMask<Double> xGreater = x0.compare(VectorOperators.GT, y0);
VectorMask<Long> xGreaterL = xGreater.cast(LS);
LongVector i1 = LongVector.zero(LS).blend(1L, xGreaterL);
LongVector j1 = LongVector.broadcast(LS, 1L).blend(0L, xGreaterL);
DoubleVector x1 = x0.sub(toDouble(i1)).add(G2);
DoubleVector y1 = y0.sub(toDouble(j1)).add(G2);
DoubleVector x2 = x0.sub(1D).add(2D * G2);
DoubleVector y2 = y0.sub(1D).add(2D * G2);
DoubleVector n0 = corner(x0, y0, gradCoord(seed, i, j, x0, y0, idxScratch));
DoubleVector n1 = corner(x1, y1, gradCoord(seed, i.add(i1), j.add(j1), x1, y1, idxScratch));
DoubleVector n2 = corner(x2, y2, gradCoord(seed, i.add(1L), j.add(1L), x2, y2, idxScratch));
return n0.add(n1).add(n2).mul(50D);
}
@Override
public void simplexFractalFBM(long seed, int octaves, double frequency, double lacunarity, double gain,
double fractalBounding, double[] xs, double[] zs, double[] out, int length) {
if (!ALIGNED) {
tailScalar(seed, octaves, frequency, lacunarity, gain, fractalBounding, xs, zs, out, 0, length);
return;
}
int lanes = DS.length();
int bound = DS.loopBound(length);
int[] idxScratch = new int[lanes];
int k = 0;
for (; k < bound; k += lanes) {
DoubleVector x = DoubleVector.fromArray(DS, xs, k).mul(frequency);
DoubleVector y = DoubleVector.fromArray(DS, zs, k).mul(frequency);
long s = seed;
DoubleVector sum = singleSimplexVector(s, x, y, idxScratch);
double amp = 1D;
for (int o = 1; o < octaves; o++) {
x = x.mul(lacunarity);
y = y.mul(lacunarity);
amp *= gain;
sum = sum.add(singleSimplexVector(++s, x, y, idxScratch).mul(amp));
}
sum.mul(fractalBounding).intoArray(out, k);
}
tailScalar(seed, octaves, frequency, lacunarity, gain, fractalBounding, xs, zs, out, k, length);
}
private static void tailScalar(long seed, int octaves, double frequency, double lacunarity, double gain,
double fractalBounding, double[] xs, double[] zs, double[] out, int from, int length) {
for (int k = from; k < length; k++) {
out[k] = ScalarNoiseKernels2D.simplexFractalFBMScalar(seed, octaves, frequency, lacunarity, gain,
fractalBounding, xs[k], zs[k]);
}
}
}
@@ -0,0 +1,102 @@
package art.arcane.iris.engine;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
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.util.project.noise.CNG;
import art.arcane.volmlib.util.math.RNG;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotSame;
import static org.mockito.Mockito.mock;
public class ContinentGeneratorTest {
private static final long WORLD_SEED = 7L;
private static final double CONTINENT_ZOOM = 4D;
private static final double CHILD_SCALE = 3D;
private static final int CHILD_SIGNATURE = 5;
private static final int CHILDREN_SEED_SALT = 2137;
private static final double[][] SAMPLE_BLOCKS = {{0D, 0D}, {137D, -52D}, {-480D, 911D}, {2048D, 2048D}};
private final IrisData packData = mock(IrisData.class);
@Test
public void continentMapIsTheUnscaledNoiseShrunkByTheContinentZoom() {
IrisDimension dimension = dimensionWithContinentZoom();
CNG unscaled = dimension.getContinentalStyle()
.createNoCache(ContinentGenerator.deriveContinentSeed(new RNG(WORLD_SEED)), packData);
CNG continent = ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData);
assertArrayEquals(sample(unscaled, 1D / CONTINENT_ZOOM), sample(continent, 1D), 0D);
}
@Test
public void rebuildingTheContinentMapZoomsItOnlyOnce() {
IrisDimension dimension = dimensionWithContinentZoom();
double[] first = sample(ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData), 1D);
double[] rebuilt = sample(ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData), 1D);
assertArrayEquals(first, rebuilt, 0D);
}
@Test
public void buildingTheContinentMapLeavesTheSharedStyleGeneratorUnscaled() {
IrisDimension dimension = dimensionWithContinentZoom();
RNG continentSeed = ContinentGenerator.deriveContinentSeed(new RNG(WORLD_SEED));
double[] before = sample(dimension.getContinentalStyle().create(continentSeed, packData), 1D);
ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData);
assertArrayEquals(before, sample(dimension.getContinentalStyle().create(continentSeed, packData), 1D), 0D);
}
@Test
public void childGeneratorsOfTwoBiomesSharingAStyleAreScaledOnlyOnce() {
IrisGeneratorStyle sharedStyle = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
IrisBiome first = biomeWithChildStyle(sharedStyle);
IrisBiome second = biomeWithChildStyle(sharedStyle);
CNG firstChildren = first.getChildrenGenerator(new RNG(WORLD_SEED), CHILD_SIGNATURE, CHILD_SCALE);
CNG secondChildren = second.getChildrenGenerator(new RNG(WORLD_SEED), CHILD_SIGNATURE, CHILD_SCALE);
assertNotSame(firstChildren, secondChildren);
assertArrayEquals(sample(firstChildren, 1D), sample(secondChildren, 1D), 0D);
}
@Test
public void childGeneratorLeavesTheSharedStyleGeneratorUnscaled() {
IrisGeneratorStyle sharedStyle = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
IrisBiome biome = biomeWithChildStyle(sharedStyle);
RNG childSeed = new RNG(WORLD_SEED).nextParallelRNG(CHILD_SIGNATURE * CHILDREN_SEED_SALT);
double[] before = sample(sharedStyle.create(childSeed, packData), 1D);
biome.getChildrenGenerator(new RNG(WORLD_SEED), CHILD_SIGNATURE, CHILD_SCALE);
assertArrayEquals(before, sample(sharedStyle.create(childSeed, packData), 1D), 0D);
}
private IrisBiome biomeWithChildStyle(IrisGeneratorStyle childStyle) {
IrisBiome biome = new IrisBiome().setChildStyle(childStyle);
biome.setLoader(packData);
return biome;
}
private static IrisDimension dimensionWithContinentZoom() {
return new IrisDimension()
.setContinentalStyle(new IrisGeneratorStyle(NoiseStyle.SIMPLEX))
.setContinentZoom(CONTINENT_ZOOM);
}
private static double[] sample(CNG generator, double blockScale) {
double[] samples = new double[SAMPLE_BLOCKS.length];
for (int i = 0; i < SAMPLE_BLOCKS.length; i++) {
samples[i] = generator.noise(SAMPLE_BLOCKS[i][0] * blockScale, SAMPLE_BLOCKS[i][1] * blockScale);
}
return samples;
}
}
@@ -0,0 +1,75 @@
package art.arcane.iris.engine;
import art.arcane.iris.engine.object.terrain.IrisGenerator;
import art.arcane.volmlib.util.math.M;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class IrisComplexNonFiniteHeightTest {
private static final double[] NON_FINITE = {Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
@Test
public void finiteBoundsAndNoiseKeepTheAverageUnchanged() {
CountingGenerator first = new CountingGenerator("a", 0.25D);
CountingGenerator second = new CountingGenerator("b", 3D);
double expected = (M.lerp(-9D, 12D, 0.25D) + M.lerp(-9D, 12D, 3D)) / 2;
double actual = IrisComplex.averageGeneratorHeights(new IrisGenerator[]{first, second}, -9D, 12D, 1D, 2D, 7L);
assertEquals(Double.doubleToLongBits(expected), Double.doubleToLongBits(actual));
}
@Test
public void nonFiniteBoundsFailBeforeSamplingWithColumnAndGeneratorDetails() {
for (double invalid : NON_FINITE) {
for (double[] bounds : new double[][]{{invalid, 1D}, {0D, invalid}, {invalid, invalid}}) {
CountingGenerator generator = new CountingGenerator("diagnostic/terrain", 0.3D);
IllegalStateException failure = assertThrows(IllegalStateException.class,
() -> IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator},
bounds[0], bounds[1], 671D, 2437D, 7331L));
assertTrue(failure.getMessage().contains("671.0,2437.0"));
assertTrue(failure.getMessage().contains("generator=diagnostic/terrain"));
assertTrue(failure.getMessage().contains("bounds=" + bounds[0] + ".." + bounds[1]));
assertEquals(0, generator.calls);
}
}
}
@Test
public void nonFiniteNoiseFailsAtItsFirstSampleWithObservedValue() {
for (double invalid : NON_FINITE) {
CountingGenerator valid = new CountingGenerator("valid", 0.3D);
CountingGenerator broken = new CountingGenerator("diagnostic/cliffs", invalid);
CountingGenerator unsampled = new CountingGenerator("unsampled", 0.5D);
IllegalStateException failure = assertThrows(IllegalStateException.class,
() -> IrisComplex.averageGeneratorHeights(new IrisGenerator[]{valid, broken, unsampled},
0D, 44D, 671D, 2437D, 7331L));
assertTrue(failure.getMessage().contains("671.0,2437.0"));
assertTrue(failure.getMessage().contains("generator=diagnostic/cliffs"));
assertTrue(failure.getMessage().contains("noise=" + invalid));
assertTrue(failure.getMessage().contains("bounds=0.0..44.0"));
assertEquals(1, valid.calls);
assertEquals(1, broken.calls);
assertEquals(0, unsampled.calls);
}
}
private static final class CountingGenerator extends IrisGenerator {
private final double noise;
private int calls;
private CountingGenerator(String loadKey, double noise) {
this.noise = noise;
setLoadKey(loadKey);
}
@Override
public double getHeight(double x, double z, long seed) {
calls++;
return noise;
}
}
}
@@ -13,6 +13,8 @@ import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -367,6 +369,94 @@ public class DecoratorCoreTest {
assertSame(STONE, DecoratorCore.fixFacesForHunk(scene(hunk(1, 1, 1)), STONE, 0, 0, 0, 0, 0));
}
@Test
public void aCurtainHangsFromTheWallItsTopStrandFaces() {
Hunk<BlockState> output = hunk(16, 8, 16);
output.set(8, 6, 8, STONE);
output.set(8, 5, 7, STONE);
output.set(9, 4, 8, STONE);
placeCurtain(output);
assertEquals(Set.of("north", "up"), setFaces(output.get(8, 5, 8)));
assertEquals(Set.of("north"), setFaces(output.get(8, 4, 8)));
assertEquals(Set.of("north"), setFaces(output.get(8, 3, 8)));
}
@Test
public void aCurtainHangsUnderAnOpenCeiling() {
Hunk<BlockState> output = hunk(16, 8, 16);
output.set(8, 6, 8, STONE);
placeCurtain(output);
assertEquals(Set.of("north", "up"), setFaces(output.get(8, 5, 8)));
assertEquals(Set.of("north"), setFaces(output.get(8, 4, 8)));
assertEquals(Set.of("north"), setFaces(output.get(8, 3, 8)));
}
@Test
public void anAuthoredSideFaceNothingHoldsIsDroppedAndTheVineReattaches() {
Hunk<BlockState> walled = hunk(16, 8, 16);
walled.set(9, 3, 8, STONE);
assertEquals(Set.of("east"), setFaces(DecoratorCore.fixFacesForHunk(scene(walled), authoredVine("north"), 8, 8, 8, 3, 8)));
assertEquals(Set.of("up"), setFaces(DecoratorCore.fixFacesForHunk(scene(hunk(16, 8, 16)), authoredVine("north"), 8, 8, 8, 3, 8)));
}
@Test
public void anAuthoredSideFaceAWallHoldsKeepsItsDirection() {
Hunk<BlockState> output = hunk(16, 8, 16);
output.set(8, 3, 7, STONE);
output.set(9, 3, 8, STONE);
assertEquals(Set.of("north"), setFaces(DecoratorCore.fixFacesForHunk(scene(output), authoredVine("north"), 8, 8, 8, 3, 8)));
}
@Test
public void aVineWithoutAnAuthoredSideFaceReattachesToEverySturdyNeighbour() {
Hunk<BlockState> output = hunk(16, 8, 16);
output.set(7, 3, 8, STONE);
output.set(8, 3, 9, STONE);
output.set(8, 4, 8, STONE);
BlockState fixed = DecoratorCore.fixFacesForHunk(scene(output), authoredVine("up"), 8, 8, 8, 3, 8);
assertEquals(Set.of("south", "west", "up"), setFaces(fixed));
}
@Test
public void glowLichenSideFaceIsNotHeldByTheLichenAboveIt() {
BlockState lichen = BlockState.parse("minecraft:glow_lichen[down=false,east=false,north=true,south=false,up=false,west=false]");
Hunk<BlockState> output = hunk(16, 8, 16);
output.set(8, 2, 8, STONE);
output.set(8, 4, 8, lichen);
assertEquals(Set.of("down"), setFaces(DecoratorCore.fixFacesForHunk(scene(output), lichen, 8, 8, 8, 3, 8)));
}
private static void placeCurtain(Hunk<BlockState> output) {
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
BlockState vine = authoredVine("north");
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(3);
when(decorator.topThreshold()).thenReturn(1.0);
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(vine);
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(vine);
DecoratorCore.placeStackDown(decorator, scene(output), 8, 8, 8, 8, 5, 0, 3, new DecoratorCore.PlaceOpts());
}
private static BlockState authoredVine(String face) {
return BlockState.parse("minecraft:vine[east=false,north=false,south=false,up=false,west=false]").withProperty(face, "true");
}
private static Set<String> setFaces(BlockState state) {
return state.properties().entrySet().stream()
.filter(property -> "true".equals(property.getValue()))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}
private static BlockState vine() {
return BlockState.parse("minecraft:vine[down=false,east=false,north=false,south=false,up=false,west=false]");
}
@@ -0,0 +1,70 @@
package art.arcane.iris.engine.decorator;
import art.arcane.iris.builtin.decorant.DecorationPart;
import art.arcane.iris.engine.modifier.ApiChunk;
import com.volmit.block.BlockState;
import com.volmit.host.ArrayHunk;
import com.volmit.host.ModuleLogs;
import com.volmit.hunk.Hunk;
import com.volmit.world.BiomeKind;
import com.volmit.world.TerrainSampler;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IrisSeaSurfaceDecoratorBoundsTest {
private static final int WORLD_HEIGHT = 8;
private static final int TALL_STACK = 30;
private static final double TOP_THRESHOLD = 0.9;
private static final BlockState AIR = ApiChunk.AIR;
private static final BlockState BODY = new BlockState("minecraft:kelp_plant");
private static final BlockState TOP = new BlockState("minecraft:kelp");
private static final DecoratedBiome BIOME = new DecoratedBiome("ocean", null, BiomeKind.SEA);
@Test
public void stackClippedByTheCeilingEndsOnTheTopBlock() {
Hunk<BlockState> blocks = decorate(4, TALL_STACK);
assertSame(BODY, blocks.get(0, 5, 0));
assertSame(BODY, blocks.get(0, 6, 0));
assertSame(TOP, blocks.get(0, 7, 0));
}
@Test
public void stackOfOneBelowTheCeilingIsTheTopBlock() {
Hunk<BlockState> blocks = decorate(6, 1);
assertSame(TOP, blocks.get(0, 7, 0));
}
@Test
public void baseAtTheCeilingPlacesNothing() {
Hunk<BlockState> blocks = decorate(WORLD_HEIGHT - 1, TALL_STACK);
for (int y = 0; y < WORLD_HEIGHT; y++) {
assertSame(AIR, blocks.get(0, y, 0));
}
}
private Hunk<BlockState> decorate(int height, int stackHeight) {
TerrainSampler terrain = mock(TerrainSampler.class);
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
BiomeDecorators decorators = mock(BiomeDecorators.class);
when(decorators.decorators(BIOME, DecorationPart.SEA_SURFACE)).thenReturn(new ResolvedDecorator[]{decorator});
when(decorator.passesChanceGate(anyDouble(), anyDouble())).thenReturn(true);
when(decorator.isStacking()).thenReturn(true);
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(stackHeight);
when(decorator.topThreshold()).thenReturn(TOP_THRESHOLD);
when(decorator.blockAt(anyDouble(), anyDouble(), anyDouble())).thenReturn(BODY);
when(decorator.topBlockAt(anyDouble(), anyDouble(), anyDouble())).thenReturn(TOP);
Hunk<BlockState> blocks = new ArrayHunk<>(BlockState.class, 1, WORLD_HEIGHT, 1, AIR);
DecorationScene scene = new DecorationScene(blocks, ApiChunk.blockRegistry(), terrain, null, decorators, 17L,
ModuleLogs.discarding());
new IrisSeaSurfaceDecorator(scene).decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, height, WORLD_HEIGHT);
return blocks;
}
}
@@ -133,7 +133,7 @@ public final class ApiChunk implements GenerationContext {
private static final Set<String> FOLIAGE = Set.of("minecraft:short_grass", "minecraft:poppy", "minecraft:tall_grass",
"minecraft:fern");
private static final Set<String> SOILS = Set.of("minecraft:grass_block", "minecraft:dirt", "minecraft:sand");
private static final Set<String> VINES = Set.of("minecraft:vine");
private static final Set<String> VINES = Set.of("minecraft:vine", "minecraft:glow_lichen");
private static final Comparator<BlockPosition> VISIT_ORDER = Comparator.comparingInt(BlockPosition::x)
.thenComparingInt(BlockPosition::y).thenComparingInt(BlockPosition::z);
@@ -93,20 +93,18 @@ public class FloatingIslandBoundarySamplerTest {
}
@Test
public void parent_cachesResolvedBiomeColumns() {
public void parent_readsOnlyTheQueriedColumnWithoutBuildingTheBoundaryField() {
ResourceId parent = ResourceId.parse("ns:parent");
ResourceId other = ResourceId.parse("ns:other");
AtomicInteger calls = new AtomicInteger();
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> {
calls.incrementAndGet();
return parent;
return x == 12 && z == -9 ? parent : other;
});
assertSame(parent, sampler.parent(12, -9));
int firstReadCount = calls.get();
assertSame(parent, sampler.parent(12, -9));
assertEquals(firstReadCount, calls.get());
int rawWidth = 16 + (FloatingIslandBoundarySampler.EDGE_FADE_RADIUS * 2) + 2;
assertEquals(rawWidth * rawWidth, firstReadCount);
assertSame(other, sampler.parent(13, -9));
assertEquals(2, calls.get());
}
@Test
@@ -0,0 +1,45 @@
package art.arcane.iris.engine.platform;
import art.arcane.iris.util.common.plugin.Chunks;
import art.arcane.iris.util.common.scheduling.J;
import org.bukkit.Location;
import org.bukkit.World;
import org.junit.Test;
import org.mockito.MockedStatic;
import java.util.concurrent.CompletableFuture;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
public class BukkitEntitySpawnerRiseStartTest {
private static final double SPAWN_Y = 70;
private static final double RISE_START_Y = 65;
@Test
public void watchedRiseStartRunsThroughTheRegionFutureAndNeverThroughTheNextTickFuture() {
World world = mock(World.class);
Location at = new Location(world, 33, SPAWN_Y, -17);
try (MockedStatic<J> scheduling = mockStatic(J.class);
MockedStatic<Chunks> chunks = mockStatic(Chunks.class)) {
scheduling.when(() -> J.runRegionFuture(eq(world), anyInt(), anyInt(), any(Runnable.class)))
.thenAnswer(invocation -> {
invocation.<Runnable>getArgument(3).run();
return CompletableFuture.completedFuture(null);
});
chunks.when(() -> Chunks.hasPlayersNearby(any(Location.class))).thenReturn(true);
Location start = BukkitEntitySpawner.startBelowGroundWhenWatched(at);
assertEquals(RISE_START_Y, start.getY(), 0.0);
scheduling.verify(() -> J.runRegionFuture(eq(world), eq(2), eq(-2), any(Runnable.class)));
scheduling.verify(() -> J.sfut(any(Runnable.class)), never());
}
}
}
@@ -25,7 +25,9 @@ import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.spawn.SpawnGroup;
import art.arcane.iris.builtin.spawn.SpawnMarker;
import art.arcane.iris.builtin.spawn.SpawnSurface;
import art.arcane.iris.builtin.spawn.Spawner;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.engine.object.world.IrisWorld;
@@ -143,6 +145,53 @@ public class EntitySpawningTest {
}
}
@Test
public void aMarkerSpawnOfAFluidEntityStillChecksItsSurface() {
Spawner spawner = TestSettings.of(Spawner.class, "{\"spawns\": [{\"entity\": \"cod\", \"minSpawns\": 1, \"maxSpawns\": 1}]}");
fixture.resource(SpawnResources.SPAWNERS, "reef/fish", spawner);
fixture.resource(SpawnResources.MARKERS, "reef", TestSettings.of(SpawnMarker.class, "{}"));
fixture.resource(SpawnResources.ENTITIES, "cod", TestSettings.of(EntityDefinition.class, "{\"type\": \"minecraft:cod\", \"surface\": \"WATER\"}"));
when(engine.getMinHeight()).thenReturn(-64);
EntitySpawns.Plan plan = new EntitySpawning()
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, world.resources().idOf("reef"), world.resources().idOf("reef/fish"), false))
.orElseThrow();
assertEquals(1, plan.attempts().size());
assertTrue(plan.attempts().get(0).checkSurface());
assertEquals(EntitySpawns.Surface.WATER, plan.attempts().get(0).surface());
}
@Test
public void landEntitiesStandOnTheTopWhileFluidEntitiesSpawnWithinTheFluid() {
assertEquals(Integer.valueOf(79), EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.LAND, 77, 78));
assertEquals(Integer.valueOf(78), EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.WATER, 77, 78));
assertEquals(Integer.valueOf(78), EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.LAVA, 77, 78));
}
@Test
public void aColumnWithoutFluidHasNoPlaceForAFluidEntity() {
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.WATER, 78, 78));
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.UNDERWATER, SpawnSurface.WATER, 78, 78));
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.BEACH, SpawnSurface.LAND, 78, 78));
}
@Test
public void underwaterAndBeachEntitiesSpawnBetweenTheFloorAndTheTop() {
for (SpawnGroup group : List.of(SpawnGroup.UNDERWATER, SpawnGroup.BEACH)) {
for (int i = 0; i < 50; i++) {
int y = EntitySpawning.surfaceSpawnY(group, SpawnSurface.WATER, 60, 64);
assertTrue(y >= 61 && y <= 64);
}
}
}
@Test
public void caveEntitiesNeverTakeAColumnHeight() {
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.CAVE, SpawnSurface.LAND, 60, 64));
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.CAVE, SpawnSurface.WATER, 60, 64));
}
@Test
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
fixture.resource(SpawnResources.SPAWNERS, "empty", new Spawner());
@@ -1,120 +0,0 @@
package art.arcane.iris.util.simd;
import art.arcane.iris.util.project.noise.FastNoiseDouble;
import art.arcane.iris.util.project.noise.FastNoiseDouble.FractalType;
import art.arcane.iris.util.project.noise.FastNoiseDouble.NoiseType;
import art.arcane.volmlib.util.math.RNG;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class NoiseKernels2DParityTest {
private static FastNoiseDouble oracle(long seed, int octaves) {
FastNoiseDouble n = new FastNoiseDouble(seed);
n.setNoiseType(NoiseType.SimplexFractal);
n.setFractalType(FractalType.FBM);
n.setFractalOctaves(octaves);
return n;
}
private static void assertKernelMatchesOracle(NoiseKernels2D kernel) {
RNG rng = new RNG(99L);
for (int octaves = 1; octaves <= 8; octaves++) {
FastNoiseDouble n = oracle(1337L + octaves, octaves);
int length = 256;
double[] xs = new double[length];
double[] zs = new double[length];
double[] expected = new double[length];
double[] out = new double[length];
for (int k = 0; k < length; k++) {
double x = (rng.nextDouble() - 0.5D) * 1_000_000D;
double z = (rng.nextDouble() - 0.5D) * 1_000_000D;
xs[k] = x;
zs[k] = z;
expected[k] = n.GetSimplexFractal(x, z);
}
kernel.simplexFractalFBM(1337L + octaves, octaves, n.getFrequency(), 2.0D, 0.5D, n.getFractalBounding(), xs, zs, out, length);
for (int k = 0; k < length; k++) {
assertEquals("octaves=" + octaves + " idx=" + k, expected[k], out[k], 0D);
}
}
}
@Test
public void scalarKernelIsBitExactToOracle() {
assertKernelMatchesOracle(new ScalarNoiseKernels2D());
}
@Test
public void vectorKernelSingleOctaveIsBitExactToOracle() {
org.junit.Assume.assumeTrue(VectorNoiseKernels2D.lanesAligned());
FastNoiseDouble n = oracle(202020L, 1);
RNG rng = new RNG(7L);
int length = 333;
double[] xs = new double[length];
double[] zs = new double[length];
double[] expected = new double[length];
double[] out = new double[length];
for (int k = 0; k < length; k++) {
double x = (rng.nextDouble() - 0.5D) * 800_000D;
double z = (rng.nextDouble() - 0.5D) * 800_000D;
xs[k] = x;
zs[k] = z;
expected[k] = n.GetSimplexFractal(x, z);
}
new VectorNoiseKernels2D().simplexFractalFBM(202020L, 1, n.getFrequency(), 2.0D, 0.5D, n.getFractalBounding(), xs, zs, out, length);
for (int k = 0; k < length; k++) {
assertEquals("idx=" + k, expected[k], out[k], 0D);
}
}
@Test
public void vectorKernelAllOctavesAreBitExactToOracle() {
org.junit.Assume.assumeTrue(VectorNoiseKernels2D.lanesAligned());
assertKernelMatchesOracle(new VectorNoiseKernels2D());
}
@Test
public void simdSupportReturnsBitExactNoiseKernel() {
NoiseKernels2D kernel = SimdSupport.noiseKernels2D();
org.junit.Assert.assertNotNull(kernel);
assertKernelMatchesOracle(kernel);
}
@Test
public void simdSupportNeverSelectsVectorBelowProfitableLanes() {
if (VectorNoiseKernels2D.profitable()) {
org.junit.Assert.assertTrue(SimdSupport.createVectorNoiseKernels2D() instanceof VectorNoiseKernels2D);
} else {
org.junit.Assert.assertTrue(SimdSupport.noiseKernels2D() instanceof ScalarNoiseKernels2D);
}
}
@Test
public void vectorMatchesScalarAcrossEdgeCases() {
org.junit.Assume.assumeTrue(VectorNoiseKernels2D.lanesAligned());
NoiseKernels2D scalar = new ScalarNoiseKernels2D();
NoiseKernels2D vector = new VectorNoiseKernels2D();
RNG rng = new RNG(31337L);
int[] lengths = {1, 3, 7, 8, 9, 255, 256, 257};
double[] edgeCoords = {-4.0D, -3.0D, -1.0D, -0.0D, 0.0D, 1.0D, 4.0D, 1_000_000.0D, -1_000_000.0D};
for (int octaves = 1; octaves <= 8; octaves++) {
for (int length : lengths) {
double[] xs = new double[length];
double[] zs = new double[length];
double[] a = new double[length];
double[] b = new double[length];
for (int k = 0; k < length; k++) {
boolean edge = (k % 3) == 0;
xs[k] = edge ? edgeCoords[k % edgeCoords.length] : (rng.nextDouble() - 0.5D) * 2_000_000D;
zs[k] = edge ? edgeCoords[(k + 1) % edgeCoords.length] : (rng.nextDouble() - 0.5D) * 2_000_000D;
}
scalar.simplexFractalFBM(77L, octaves, 0.01D, 2.0D, 0.5D, 0.6667D, xs, zs, a, length);
vector.simplexFractalFBM(77L, octaves, 0.01D, 2.0D, 0.5D, 0.6667D, xs, zs, b, length);
for (int k = 0; k < length; k++) {
assertEquals("oct=" + octaves + " len=" + length + " idx=" + k, a[k], b[k], 0D);
}
}
}
}
}
@@ -36,5 +36,9 @@ public enum SpawnSurface {
OVERWORLD,
@Desc("Within lava")
LAVA
LAVA;
public boolean isFluid() {
return this == WATER || this == LAVA;
}
}
@@ -34,6 +34,7 @@ final class DecoratorCore {
private static final long SEED_OFFSET = 29356788L;
private static final long PART_FACTOR = 10439677L;
private static final String HALF = "half";
private static final ResourceId VINE = ResourceId.parse("minecraft:vine");
private static final ResourceId WEEPING_VINES = ResourceId.parse("minecraft:weeping_vines");
private static final ResourceId WEEPING_VINES_PLANT = ResourceId.parse("minecraft:weeping_vines_plant");
private static final ResourceId TWISTING_VINES = ResourceId.parse("minecraft:twisting_vines");
@@ -49,6 +50,9 @@ final class DecoratorCore {
new Face(BlockFace.DOWN, "down", 0, -1, 0));
private static final Map<BlockFace, BlockFace> OPPOSITES = Map.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.SOUTH, BlockFace.NORTH,
BlockFace.EAST, BlockFace.WEST, BlockFace.WEST, BlockFace.EAST, BlockFace.UP, BlockFace.DOWN, BlockFace.DOWN, BlockFace.UP);
private static final Face UP_FACE = FACES.get(4);
private static final Face DOWN_FACE = FACES.get(5);
private static final List<Face> SIDE_FACES = FACES.subList(0, 4);
private static final int CHUNK_LAST = 15;
static final ThreadLocal<PlaceOpts> SCRATCH_OPTS = ThreadLocal.withInitial(PlaceOpts::new);
@@ -360,15 +364,20 @@ final class DecoratorCore {
}
/**
* A vine placed at {@code x}, {@code y}, {@code z} (the chunk's local column {@code rX}, {@code rZ}) faces the neighbours that
* can hold it: the blocks the mantle planned there, else the chunk's own blocks. A vine with no such neighbour faces down,
* or up when it cannot face down. Any other block is returned as it is.
* A vine placed at {@code x}, {@code y}, {@code z} (the chunk's local column {@code rX}, {@code rZ}) keeps the side faces its
* pack gave it where a sturdy neighbour or the vine above holds them, and faces up under a sturdy ceiling. A vine none of its side
* faces can hold faces the neighbours that can hold it instead, down, or up when it cannot face down. Any other block is returned
* as it is.
*/
static BlockState fixFacesForHunk(DecorationScene scene, BlockState b, int rX, int rZ, int x, int y, int z) {
if (b == null || !scene.has(BlockTrait.VINE, b)) {
return b;
}
Hunk<BlockState> hunk = scene.blocks();
BlockState kept = keepSupportedSides(scene, b, rX, rZ, x, y, z);
if (kept != null) {
return kept;
}
BlockState fixed = b;
for (Face face : FACES) {
if (b.properties().containsKey(face.property())) {
@@ -378,30 +387,9 @@ final class DecoratorCore {
boolean found = false;
for (Face face : FACES) {
int yy = y + face.dy();
BlockFace opposite = OPPOSITES.get(face.face());
BlockState planned = scene.plannedAt(x + face.dx(), yy, z + face.dz());
BlockState support = planned == null ? AIR : planned;
if (scene.registry().canAttach(b, support, opposite)) {
if (b.properties().containsKey(face.property())) {
found = true;
fixed = fixed.withProperty(face.property(), "true");
}
continue;
}
int xx = rX + face.dx();
int zz = rZ + face.dz();
if (xx < 0 || xx > CHUNK_LAST || zz < 0 || zz > CHUNK_LAST || yy < 0 || yy >= hunk.height()) {
continue;
}
if (scene.registry().canAttach(b, hunk.get(xx, yy, zz), opposite)) {
if (b.properties().containsKey(face.property())) {
found = true;
fixed = fixed.withProperty(face.property(), "true");
}
if (b.properties().containsKey(face.property()) && holds(scene, b, face, rX, rZ, x, y, z)) {
found = true;
fixed = fixed.withProperty(face.property(), "true");
}
}
if (!found) {
@@ -413,6 +401,68 @@ final class DecoratorCore {
return fixed;
}
private static BlockState keepSupportedSides(DecorationScene scene, BlockState b, int rX, int rZ, int x, int y, int z) {
boolean vine = VINE.equals(b.material());
boolean ceiling = holds(scene, b, UP_FACE, rX, rZ, x, y, z);
BlockState kept = b;
boolean heldSide = false;
for (Face face : SIDE_FACES) {
if (!isSet(b, face)) {
continue;
}
if (holds(scene, b, face, rX, rZ, x, y, z) || vine && (ceiling || vineAboveCarries(scene, face, rX, rZ, x, y, z))) {
heldSide = true;
} else {
kept = kept.withProperty(face.property(), "false");
}
}
if (!heldSide) {
return null;
}
if (b.properties().containsKey(UP_FACE.property())) {
kept = kept.withProperty(UP_FACE.property(), String.valueOf(ceiling));
}
if (isSet(b, DOWN_FACE) && !holds(scene, b, DOWN_FACE, rX, rZ, x, y, z)) {
kept = kept.withProperty(DOWN_FACE.property(), "false");
}
return kept;
}
private static boolean isSet(BlockState block, Face face) {
return "true".equals(block.properties().get(face.property()));
}
/** Whether the neighbour on {@code face}, the block the mantle planned there else the chunk's own, can hold {@code b}. */
private static boolean holds(DecorationScene scene, BlockState b, Face face, int rX, int rZ, int x, int y, int z) {
int yy = y + face.dy();
BlockFace opposite = OPPOSITES.get(face.face());
BlockState planned = scene.plannedAt(x + face.dx(), yy, z + face.dz());
if (scene.registry().canAttach(b, planned == null ? AIR : planned, opposite)) {
return true;
}
Hunk<BlockState> hunk = scene.blocks();
int xx = rX + face.dx();
int zz = rZ + face.dz();
if (xx < 0 || xx > CHUNK_LAST || zz < 0 || zz > CHUNK_LAST || yy < 0 || yy >= hunk.height()) {
return false;
}
return scene.registry().canAttach(b, hunk.get(xx, yy, zz), opposite);
}
private static boolean vineAboveCarries(DecorationScene scene, Face face, int rX, int rZ, int x, int y, int z) {
if (carries(scene.plannedAt(x, y + 1, z), face)) {
return true;
}
Hunk<BlockState> hunk = scene.blocks();
return y + 1 < hunk.height() && carries(hunk.get(rX, y + 1, rZ), face);
}
private static boolean carries(BlockState block, Face face) {
return block != null && VINE.equals(block.material()) && isSet(block, face);
}
static boolean canGoOn(DecorationScene scene, BlockState decorator, BlockState surface) {
return decorator != null && surface != null && scene.canGoOn(decorator, surface);
}
@@ -29,6 +29,12 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
@Override
public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1,
DecoratedBiome biome, int height, int max) {
var data = scene.blocks();
int maxBaseY = Math.min(max, Math.min(scene.worldHeight(), data.height()) - 1);
if (height < 0 || height >= maxBaseY) {
return;
}
RNG rng = getRNG(realX, realZ);
ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ, decorators.log());
@@ -36,11 +42,9 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
return;
}
var data = scene.blocks();
if (!decorator.isStacking()) {
int targetY = height + 1;
if (height >= 0 && targetY < scene.worldHeight()
&& DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
if (DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
BlockState block = decorator.blockAt(realX, height, realZ);
if (block != null) {
data.set(x, targetY, z, block);
@@ -54,28 +58,15 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
stack = (int) Math.ceil((double) (max - height) * ((double) stack / 100));
}
if (stack == 1) {
int targetY = height + 1;
if (targetY >= data.height() || !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
return;
}
stack = Math.min(stack, maxBaseY - height);
BlockState block = decorator.topBlockAt(realX, height, realZ);
if (block != null) {
data.set(x, targetY, z, block);
}
return;
}
int engineHeight = scene.worldHeight();
for (int i = 0; i < stack; i++) {
int h = height + i;
int targetY = h + 1;
if (h >= max || targetY >= engineHeight
|| !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
if (!DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
break;
}
double threshold = ((double) i) / (stack - 1);
double threshold = stack == 1 ? 1.0 : ((double) i) / (stack - 1);
BlockState block = threshold >= decorator.topThreshold()
? decorator.topBlockAt(realX, h, realZ)
: decorator.blockAt(realX, h, realZ);
@@ -47,7 +47,7 @@ public final class FloatingIslandBoundarySampler {
}
public ResourceId parent(int x, int z) {
return parentField(x, z, EDGE_TAPER_WIDTH).parent(x, z);
return source.sample(x, z);
}
public double edgeFade(ResourceId parent, int x, int z) {
@@ -229,10 +229,6 @@ public final class FloatingIslandBoundarySampler {
build(source);
}
private ResourceId parent(int x, int z) {
return parents[geometry.index(x - minX, z - minZ)];
}
private int edgeDistance(ResourceId expected, int x, int z) {
int index = geometry.index(x - minX, z - minZ);
if (!sameBiome(expected, parents[index]) || !viable[index]) {
@@ -22,6 +22,7 @@ import art.arcane.iris.builtin.IrisSeedPurposes;
import art.arcane.iris.builtin.loot.LootResolver;
import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.spawn.EntitySpawn;
import art.arcane.iris.builtin.spawn.SpawnGroup;
import art.arcane.iris.builtin.spawn.SpawnMarker;
import art.arcane.iris.builtin.spawn.SpawnSurface;
import art.arcane.iris.builtin.spawn.Spawner;
@@ -155,28 +156,47 @@ public final class EntitySpawning implements EntitySpawns {
private Optional<Plan> planChunkSpawn(PackWorld world, RunningWorld running, Chunk chunk, Candidate chosen) {
EntitySpawn spawn = chosen.spawn();
EntityDefinition entity = entityOf(world, chosen);
if (entity == null) {
return Optional.empty();
}
int count = LootResolver.inclusive(RNG.r, spawn.minSpawns(), spawn.maxSpawns());
List<Attempt> attempts = new ArrayList<>();
for (int i = 0; i < count; i++) {
int x = (chunk.chunkX() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE);
int z = (chunk.chunkZ() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE);
BlockPosition at = spawnPosition(running, chosen.spawner(), chunk.chunkX(), chunk.chunkZ(), x, z);
BlockPosition at = spawnPosition(running, chosen.spawner(), entity.surface(), chunk.chunkX(), chunk.chunkZ(), x, z);
if (at != null) {
addAttempt(attempts, world, chosen, at, true);
addAttempt(attempts, world, chosen, entity, at, true);
}
}
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(world.resources().idOf(chosen.key()), chunk.chunkX(), chunk.chunkZ(), false, attempts));
}
/** Where a spawner of its group puts an entity at the column; null when it has no place for one. */
private static BlockPosition spawnPosition(RunningWorld running, Spawner spawner, int chunkX, int chunkZ, int x, int z) {
int height = running.highest(x, z, true);
int heightWithFluid = running.highest(x, z, false);
return switch (spawner.group()) {
case NORMAL -> new BlockPosition(x, heightWithFluid + 1, z);
case CAVE -> caveSpawnPosition(running, chunkX, chunkZ);
case UNDERWATER, BEACH -> new BlockPosition(x, RNG.r.i(height + 1, heightWithFluid), z);
};
/** Where a spawner of its group puts an entity of the surface at the column; null when it has no place for one. */
private static BlockPosition spawnPosition(RunningWorld running, Spawner spawner, SpawnSurface surface, int chunkX, int chunkZ, int x, int z) {
if (spawner.group() == SpawnGroup.CAVE) {
return caveSpawnPosition(running, chunkX, chunkZ);
}
int floor = running.highest(x, z, true);
int top = running.highest(x, z, false);
Integer y = surfaceSpawnY(spawner.group(), surface, floor, top);
return y == null ? null : new BlockPosition(x, y, z);
}
/**
* The height an entity of the surface spawns at in a column whose solid ground ends at {@code floor} and whose
* fluid or ground ends at {@code top}; null when the column has no room for it. Entities that need fluid are
* placed within it, whichever the group.
*/
static Integer surfaceSpawnY(SpawnGroup group, SpawnSurface surface, int floor, int top) {
if (group == SpawnGroup.CAVE) {
return null;
}
if (group == SpawnGroup.NORMAL && !surface.isFluid()) {
return top + 1;
}
return top > floor ? LootResolver.inclusive(RNG.r, floor + 1, top) : null;
}
static BlockPosition caveSpawnPosition(RunningWorld running, int chunkX, int chunkZ) {
@@ -199,6 +219,11 @@ public final class EntitySpawning implements EntitySpawns {
}
EntitySpawn spawn = RarityWeighting.expand(candidates, EntitySpawn::rarity).getRandom();
EntityDefinition entity = entityOf(world, new Candidate(spawnerKey, spawner, spawn));
if (entity == null) {
return Optional.empty();
}
BlockPosition position = marker.position();
int chunkX = PowerOfTwoCoordinates.blockToChunkFloor(position.x());
int chunkZ = PowerOfTwoCoordinates.blockToChunkFloor(position.z());
@@ -214,7 +239,7 @@ public final class EntitySpawning implements EntitySpawns {
List<Attempt> attempts = new ArrayList<>();
BlockPosition above = new BlockPosition(position.x(), position.y() + AIR_ABOVE_MARKER, position.z());
for (int i = 0; i < count; i++) {
addAttempt(attempts, world, new Candidate(spawnerKey, spawner, spawn), above, false);
addAttempt(attempts, world, new Candidate(spawnerKey, spawner, spawn), entity, above, false);
}
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(marker.spawner(), chunkX, chunkZ, exhaustsMarker, attempts));
}
@@ -223,16 +248,20 @@ public final class EntitySpawning implements EntitySpawns {
return marker.exhaustionChance() > RNG.r.nextDouble();
}
private void addAttempt(List<Attempt> attempts, PackWorld world, Candidate candidate, BlockPosition at, boolean checkSurface) {
private static EntityDefinition entityOf(PackWorld world, Candidate candidate) {
EntityDefinition entity = SpawnResources.entity(world.resources(), candidate.spawn().entity());
if (entity == null) {
world.log().debug(" You are trying to spawn an entity that does not exist!");
return;
}
return entity;
}
/** Entities that need fluid are always checked: the fluid is what keeps them where they can live. */
private void addAttempt(List<Attempt> attempts, PackWorld world, Candidate candidate, EntityDefinition entity, BlockPosition at, boolean checkSurface) {
Range light = candidate.spawner().allowedLightLevels();
boolean checked = checkSurface || entity.surface().isFluid();
resolution(world).resolve(entity, entityRandom(world).rng()).ifPresent(spec -> attempts.add(new Attempt(at, spec,
surfaceOf(entity.surface()), (int) Math.ceil(light.min()), (int) Math.floor(light.max()), checkSurface)));
surfaceOf(entity.surface()), (int) Math.ceil(light.min()), (int) Math.floor(light.max()), checked)));
}
private static EntityResolution resolution(PackWorld world) {
+10 -5
View File
@@ -6,9 +6,13 @@ on**. The Volmit dev/test machines are Apple Silicon, where the wide-SIMD path
(4+ double lanes) does not exist. Copy the built artifact to a Windows/x86 box
(AVX2 = 4 lanes, AVX-512 = 8 lanes) and run it to get real numbers for that CPU.
The six kernel classes are copied verbatim (logic byte-for-byte) from
`Iris/core/.../util/simd/`. This tool is intentionally a duplicate so it builds
and runs on its own with no Gradle, no VolmLib, and no Iris on the classpath.
The three array kernel classes are copied verbatim (logic byte-for-byte) from
`Iris/core/.../util/simd/`. The three 2D noise kernel classes are a candidate
implementation that Iris does not ship: it measured 0.07x against scalar on
2-lane NEON and was removed, and this harness keeps it so the same question can be
answered on a wider CPU before anyone rebuilds it. This tool is intentionally a
duplicate so it builds and runs on its own with no Gradle, no VolmLib, and no Iris
on the classpath.
## Requirements
@@ -98,7 +102,8 @@ run.bat --mode both (default)
throughput will be (cache behavior, allocation, and surrounding code differ in
the real engine).
- **Effort 1 array kernels** (`roundToInt` / `sum` / `max`) run unconditionally
in real Iris. **Effort 2 noise** (`simplexFractalFBM`) is currently unwired in
Iris and gated to 4+ double lanes; this tool force-measures it regardless.
in real Iris. **Effort 2 noise** (`simplexFractalFBM`) is not part of
Iris; this tool force-measures the candidate kernel regardless of the 4+ double
lane gate.
- Vector-API auto-vectorization and cost depend heavily on the JDK version and
CPU. Run on the actual target hardware; do not extrapolate across machines.