mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Baseline IrisModule before the IrisApi port
This commit is contained in:
commit
05ab5ba0cf
397 files changed
+56200
No files matched your search
@@ -0,0 +1,777 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.engine.UpperDimensionContext;
|
||||
import art.arcane.iris.engine.actuator.IrisDecorantActuator;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationPart;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorator;
|
||||
import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.documentation.ChunkCoordinates;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.volmlib.util.math.M;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import lombok.Data;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class IrisCarveModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
private static final byte LIQUID_FLUID = 1;
|
||||
private static final ThreadLocal<IrisCarveScratch> SCRATCH = ThreadLocal.withInitial(IrisCarveScratch::new);
|
||||
private static final int CAVE_BIOME_BLEND_RADIUS = 3;
|
||||
private static final int CAVE_BIOME_BLEND_CENTER_WEIGHT = 4;
|
||||
private static final int CAVE_BIOME_BLEND_TOTAL_WEIGHT = 8;
|
||||
private static final MatterCavern BASIC_CAVERN = new MatterCavern(true, "", (byte) 0);
|
||||
private final RNG rng;
|
||||
private final PlatformBlockState AIR = B.getState("CAVE_AIR");
|
||||
private final PlatformBlockState LAVA = B.getState("LAVA");
|
||||
private final IrisDecorantActuator decorant;
|
||||
|
||||
public IrisCarveModifier(Engine engine) {
|
||||
super(engine, "Carve");
|
||||
rng = new RNG(getEngine().getSeedManager().getCarve());
|
||||
decorant = new IrisDecorantActuator(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ChunkCoordinates
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch caveStopwatch = PrecisionStopwatch.start();
|
||||
Mantle<Matter> mantle = getEngine().getMantle().getMantle();
|
||||
IrisDimensionCarvingResolver.State resolverState = new IrisDimensionCarvingResolver.State();
|
||||
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache = new Long2ObjectOpenHashMap<>(2048);
|
||||
IrisCarveScratch scratch = SCRATCH.get();
|
||||
scratch.reset();
|
||||
CarveWallBuffer walls = scratch.walls;
|
||||
CarveColumnMask[] columnMasks = scratch.columnMasks;
|
||||
CarveColumnMask[] boundaryMasks = scratch.boundaryMasks;
|
||||
int[] surfaceHeights = scratch.surfaceHeights;
|
||||
Map<String, IrisBiome> customBiomeCache = scratch.customBiomeCache;
|
||||
UpperDimensionContext upperCtx = getEngine().getUpperContext();
|
||||
boolean protectUpper = upperCtx != null && !getEngine().getDimension().isUpperDimensionCarving();
|
||||
int[] upperSurfaceHeights = protectUpper ? scratch.getOrCreateUpperSurfaceHeights() : null;
|
||||
int chunkBlockX = PowerOfTwoCoordinates.chunkToBlock(x);
|
||||
int chunkBlockZ = PowerOfTwoCoordinates.chunkToBlock(z);
|
||||
for (int columnIndex = 0; columnIndex < 256; columnIndex++) {
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
surfaceHeights[columnIndex] = context.getRoundedHeight(localX, localZ);
|
||||
if (protectUpper) {
|
||||
int worldX = localX + chunkBlockX;
|
||||
int worldZ = localZ + chunkBlockZ;
|
||||
int rawUpper = upperCtx.getUpperSurfaceY(worldX, worldZ);
|
||||
int gap = getEngine().getDimension().getUpperDimensionGap();
|
||||
upperSurfaceHeights[columnIndex] = Math.max(rawUpper, surfaceHeights[columnIndex] + gap);
|
||||
}
|
||||
}
|
||||
|
||||
MantleChunk<Matter> mantleChunk = mantle.getChunk(x, z).use();
|
||||
try {
|
||||
PrecisionStopwatch resolveStopwatch = PrecisionStopwatch.start();
|
||||
int worldHeightSpan = getEngine().getWorld().maxHeight() - getEngine().getWorld().minHeight();
|
||||
int caveLavaHeight = getEngine().getDimension().getCaveLavaHeight();
|
||||
mantleChunk.iterate(MatterCavern.class, (xx, yy, zz, cavern) -> {
|
||||
if (cavern == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (yy >= worldHeightSpan || yy <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int rx = xx & 15;
|
||||
int rz = zz & 15;
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(rx, rz);
|
||||
|
||||
if (upperSurfaceHeights != null && yy >= upperSurfaceHeights[columnIndex]) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlatformBlockState current = output.getRaw(rx, yy, rz);
|
||||
boolean explicitCarveIntent = hasExplicitCarveIntent(cavern);
|
||||
|
||||
if (shouldPreserveExistingFluid(cavern, current)) {
|
||||
return;
|
||||
}
|
||||
|
||||
columnMasks[columnIndex].add(yy);
|
||||
|
||||
if (!cavern.getCustomBiome().isEmpty()) {
|
||||
scratch.customCaveBiomePresent = true;
|
||||
}
|
||||
|
||||
if (current.isAir() && !explicitCarveIntent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (explicitCarveIntent) {
|
||||
// Only a fluid cavern consumes the fluid sample, and on the maintenance path that
|
||||
// sample is a full procedural stream evaluation, so never take it per voxel.
|
||||
PlatformBlockState fluid = isFluidIntent(cavern) ? context.getFluid().get(rx, rz) : null;
|
||||
output.setRaw(rx, yy, rz, resolveExplicitCarveState(cavern, fluid, LAVA, AIR));
|
||||
} else if (usesDefaultLava(caveLavaHeight, yy)) {
|
||||
output.setRaw(rx, yy, rz, LAVA);
|
||||
} else {
|
||||
output.setRaw(rx, yy, rz, AIR);
|
||||
}
|
||||
});
|
||||
if (scratch.customCaveBiomePresent) {
|
||||
addInternalWallsFromMantle(mantleChunk, walls, columnMasks);
|
||||
} else {
|
||||
addInternalWallsFromMasks(walls, columnMasks);
|
||||
}
|
||||
addCrossChunkBoundaryWalls(mantle, mantleChunk, walls, boundaryMasks, x, z, surfaceHeights);
|
||||
getEngine().getMetrics().getCarveResolve().put(resolveStopwatch.getMilliseconds());
|
||||
|
||||
PrecisionStopwatch applyStopwatch = PrecisionStopwatch.start();
|
||||
try {
|
||||
walls.forEach((rx, yy, rz, cavern) -> {
|
||||
int worldX = rx + chunkBlockX;
|
||||
int worldZ = rz + chunkBlockZ;
|
||||
String customBiome = cavern.getCustomBiome();
|
||||
IrisBiome biome = customBiome.isEmpty()
|
||||
? resolveCaveBiome(caveBiomeCache, worldX, yy, worldZ, resolverState)
|
||||
: resolveCustomBiome(customBiomeCache, customBiome);
|
||||
|
||||
if (biome != null) {
|
||||
PlatformBlockState data = biome.getWall().get(rng, worldX, yy, worldZ, getData());
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(rx, rz);
|
||||
|
||||
if (data != null && B.isSolid(output.getRaw(rx, yy, rz)) && yy < surfaceHeights[columnIndex]) {
|
||||
output.setRaw(rx, yy, rz, data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (int columnIndex = 0; columnIndex < 256; columnIndex++) {
|
||||
processColumnFromMask(output, mantleChunk, mantle, columnMasks[columnIndex], columnIndex, x, z, resolverState, caveBiomeCache, customBiomeCache);
|
||||
}
|
||||
|
||||
for (int columnIndex = 0; columnIndex < 256; columnIndex++) {
|
||||
if (boundaryMasks[columnIndex].isEmpty() || !columnMasks[columnIndex].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
processBoundaryColumnFromMask(output, boundaryMasks[columnIndex], walls, columnIndex, x, z, resolverState, caveBiomeCache, customBiomeCache);
|
||||
}
|
||||
|
||||
// Surface-break carving must not leave an ore cap suspended across the opening.
|
||||
for (int columnIndex = 0; columnIndex < surfaceHeights.length; columnIndex++) {
|
||||
int surfaceY = surfaceHeights[columnIndex];
|
||||
if (surfaceY <= 0 || surfaceY >= output.getHeight()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int belowY = surfaceY - 1;
|
||||
if (!columnMasks[columnIndex].contains(belowY) && !boundaryMasks[columnIndex].contains(belowY)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
PlatformBlockState surface = output.getRaw(localX, surfaceY, localZ);
|
||||
PlatformBlockState below = output.getRaw(localX, belowY, localZ);
|
||||
if (isUnsupportedSurfaceOre(surface, below)) {
|
||||
output.setRaw(localX, surfaceY, localZ, AIR);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
getEngine().getMetrics().getCarveApply().put(applyStopwatch.getMilliseconds());
|
||||
}
|
||||
} finally {
|
||||
getEngine().getMetrics().getCave().put(caveStopwatch.getMilliseconds());
|
||||
mantleChunk.release();
|
||||
}
|
||||
}
|
||||
|
||||
static boolean hasExplicitCarveIntent(MatterCavern cavern) {
|
||||
return cavern != null && (isFluidIntent(cavern) || cavern.isLava() || cavern.getLiquid() == 3);
|
||||
}
|
||||
|
||||
static boolean isFluidIntent(MatterCavern cavern) {
|
||||
return cavern != null && cavern.getLiquid() == LIQUID_FLUID;
|
||||
}
|
||||
|
||||
static boolean shouldPreserveExistingFluid(MatterCavern cavern, PlatformBlockState current) {
|
||||
return B.isFluid(current) && !hasExplicitCarveIntent(cavern);
|
||||
}
|
||||
|
||||
static boolean usesDefaultLava(int caveLavaHeight, int y) {
|
||||
return y <= caveLavaHeight;
|
||||
}
|
||||
|
||||
static boolean isUnsupportedSurfaceOre(PlatformBlockState surface, PlatformBlockState below) {
|
||||
return B.isOre(surface) && !B.isSolid(below);
|
||||
}
|
||||
|
||||
static PlatformBlockState resolveExplicitCarveState(MatterCavern cavern, PlatformBlockState fluid,
|
||||
PlatformBlockState lava, PlatformBlockState air) {
|
||||
if (cavern == null) {
|
||||
return null;
|
||||
}
|
||||
if (isFluidIntent(cavern)) {
|
||||
return fluid;
|
||||
}
|
||||
if (cavern.isLava()) {
|
||||
return lava;
|
||||
}
|
||||
return cavern.getLiquid() == 3 ? air : null;
|
||||
}
|
||||
|
||||
private void addInternalWallsFromMasks(CarveWallBuffer walls, CarveColumnMask[] columnMasks) {
|
||||
for (int columnIndex = 0; columnIndex < 256; columnIndex++) {
|
||||
CarveColumnMask columnMask = columnMasks[columnIndex];
|
||||
if (columnMask.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int rx = columnIndex >> 4;
|
||||
int rz = columnIndex & 15;
|
||||
int yy = columnMask.nextSetBit(0);
|
||||
while (yy >= 0) {
|
||||
if (rz < 15 && !columnMasks[columnIndex + 1].contains(yy)) {
|
||||
walls.put(rx, yy, rz + 1, BASIC_CAVERN);
|
||||
}
|
||||
if (rx < 15 && !columnMasks[columnIndex + 16].contains(yy)) {
|
||||
walls.put(rx + 1, yy, rz, BASIC_CAVERN);
|
||||
}
|
||||
if (rz > 0 && !columnMasks[columnIndex - 1].contains(yy)) {
|
||||
walls.put(rx, yy, rz - 1, BASIC_CAVERN);
|
||||
}
|
||||
if (rx > 0 && !columnMasks[columnIndex - 16].contains(yy)) {
|
||||
walls.put(rx - 1, yy, rz, BASIC_CAVERN);
|
||||
}
|
||||
yy = columnMask.nextSetBit(yy + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addInternalWallsFromMantle(MantleChunk<Matter> mc, CarveWallBuffer walls, CarveColumnMask[] columnMasks) {
|
||||
for (int columnIndex = 0; columnIndex < 256; columnIndex++) {
|
||||
CarveColumnMask columnMask = columnMasks[columnIndex];
|
||||
if (columnMask.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int rx = columnIndex >> 4;
|
||||
int rz = columnIndex & 15;
|
||||
int yy = columnMask.nextSetBit(0);
|
||||
while (yy >= 0) {
|
||||
MatterCavern cavern = mc.get(rx, yy, rz, MatterCavern.class);
|
||||
if (cavern != null) {
|
||||
if (rz < 15 && mc.get(rx, yy, rz + 1, MatterCavern.class) == null) {
|
||||
walls.put(rx, yy, rz + 1, cavern);
|
||||
}
|
||||
if (rx < 15 && mc.get(rx + 1, yy, rz, MatterCavern.class) == null) {
|
||||
walls.put(rx + 1, yy, rz, cavern);
|
||||
}
|
||||
if (rz > 0 && mc.get(rx, yy, rz - 1, MatterCavern.class) == null) {
|
||||
walls.put(rx, yy, rz - 1, cavern);
|
||||
}
|
||||
if (rx > 0 && mc.get(rx - 1, yy, rz, MatterCavern.class) == null) {
|
||||
walls.put(rx - 1, yy, rz, cavern);
|
||||
}
|
||||
}
|
||||
yy = columnMask.nextSetBit(yy + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCrossChunkBoundaryWalls(
|
||||
Mantle<Matter> mantle,
|
||||
MantleChunk<Matter> mc,
|
||||
CarveWallBuffer walls,
|
||||
CarveColumnMask[] boundaryMasks,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
int[] surfaceHeights
|
||||
) {
|
||||
int baseX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int baseZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
int maxSurfaceY = 0;
|
||||
for (int index = 0; index < surfaceHeights.length; index++) {
|
||||
if (surfaceHeights[index] > maxSurfaceY) {
|
||||
maxSurfaceY = surfaceHeights[index];
|
||||
}
|
||||
}
|
||||
int maxY = Math.min(getEngine().getWorld().maxHeight() - getEngine().getWorld().minHeight() - 1, maxSurfaceY + 1);
|
||||
if (maxY < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
MantleChunk<Matter> west = existingMantleChunk(mantle, chunkX - 1, chunkZ);
|
||||
MantleChunk<Matter> east = existingMantleChunk(mantle, chunkX + 1, chunkZ);
|
||||
MantleChunk<Matter> north = existingMantleChunk(mantle, chunkX, chunkZ - 1);
|
||||
MantleChunk<Matter> south = existingMantleChunk(mantle, chunkX, chunkZ + 1);
|
||||
if (west == null && east == null && north == null && south == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int yy = 1; yy <= maxY; yy++) {
|
||||
for (int offset = 0; offset < 16; offset++) {
|
||||
if (west != null) {
|
||||
tryAddBoundaryWall(mc, west, walls, boundaryMasks, 0, yy, offset, 15, offset);
|
||||
}
|
||||
if (east != null) {
|
||||
tryAddBoundaryWall(mc, east, walls, boundaryMasks, 15, yy, offset, 0, offset);
|
||||
}
|
||||
if (north != null) {
|
||||
tryAddBoundaryWall(mc, north, walls, boundaryMasks, offset, yy, 0, offset, 15);
|
||||
}
|
||||
if (south != null) {
|
||||
tryAddBoundaryWall(mc, south, walls, boundaryMasks, offset, yy, 15, offset, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tryAddBoundaryWall(
|
||||
MantleChunk<Matter> mc,
|
||||
MantleChunk<Matter> neighborChunk,
|
||||
CarveWallBuffer walls,
|
||||
CarveColumnMask[] boundaryMasks,
|
||||
int localX,
|
||||
int yy,
|
||||
int localZ,
|
||||
int neighborX,
|
||||
int neighborZ
|
||||
) {
|
||||
if (mc.get(localX, yy, localZ, MatterCavern.class) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MatterCavern neighbor = neighborChunk.get(neighborX, yy, neighborZ, MatterCavern.class);
|
||||
if (neighbor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
walls.put(localX, yy, localZ, neighbor);
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(localX, localZ);
|
||||
boundaryMasks[columnIndex].add(yy);
|
||||
}
|
||||
|
||||
private MantleChunk<Matter> existingMantleChunk(Mantle<Matter> mantle, int chunkX, int chunkZ) {
|
||||
TectonicPlate<Matter> plate = mantle.getLoadedRegions().get(Mantle.key(chunkX >> 5, chunkZ >> 5));
|
||||
if (plate == null || plate.isClosed()) {
|
||||
return null;
|
||||
}
|
||||
return plate.get(chunkX & 31, chunkZ & 31);
|
||||
}
|
||||
|
||||
private void processColumnFromMask(
|
||||
Hunk<PlatformBlockState> output,
|
||||
MantleChunk<Matter> mc,
|
||||
Mantle<Matter> mantle,
|
||||
CarveColumnMask columnMask,
|
||||
int columnIndex,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache,
|
||||
Map<String, IrisBiome> customBiomeCache
|
||||
) {
|
||||
if (columnMask == null || columnMask.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int firstHeight = columnMask.nextSetBit(0);
|
||||
if (firstHeight < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int rx = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int rz = columnIndex & 15;
|
||||
int worldX = rx + PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int worldZ = rz + PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
CaveZone zone = new CaveZone();
|
||||
zone.setFloor(firstHeight);
|
||||
int buf = firstHeight - 1;
|
||||
int y = firstHeight;
|
||||
|
||||
while (y >= 0) {
|
||||
if (y <= getEngine().getHeight()) {
|
||||
if (y == buf + 1) {
|
||||
buf = y;
|
||||
zone.ceiling = buf;
|
||||
} else {
|
||||
if (zone.isValid(getEngine())) {
|
||||
processZone(output, mc, mantle, zone, rx, rz, worldX, worldZ, resolverState, caveBiomeCache, customBiomeCache);
|
||||
}
|
||||
zone = new CaveZone();
|
||||
zone.setFloor(y);
|
||||
buf = y;
|
||||
}
|
||||
}
|
||||
|
||||
y = columnMask.nextSetBit(y + 1);
|
||||
}
|
||||
|
||||
if (zone.isValid(getEngine())) {
|
||||
processZone(output, mc, mantle, zone, rx, rz, worldX, worldZ, resolverState, caveBiomeCache, customBiomeCache);
|
||||
}
|
||||
}
|
||||
|
||||
private void processBoundaryColumnFromMask(
|
||||
Hunk<PlatformBlockState> output,
|
||||
CarveColumnMask boundaryMask,
|
||||
CarveWallBuffer walls,
|
||||
int columnIndex,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache,
|
||||
Map<String, IrisBiome> customBiomeCache
|
||||
) {
|
||||
int firstHeight = boundaryMask.nextSetBit(0);
|
||||
if (firstHeight < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int rx = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int rz = columnIndex & 15;
|
||||
int worldX = rx + PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int worldZ = rz + PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
int zoneFloor = firstHeight;
|
||||
int zoneCeiling = firstHeight;
|
||||
int y = boundaryMask.nextSetBit(firstHeight + 1);
|
||||
|
||||
while (y >= 0) {
|
||||
if (y == zoneCeiling + 1) {
|
||||
zoneCeiling = y;
|
||||
} else {
|
||||
paintBoundaryZone(output, walls, rx, rz, worldX, worldZ, zoneFloor, zoneCeiling, resolverState, caveBiomeCache, customBiomeCache);
|
||||
zoneFloor = y;
|
||||
zoneCeiling = y;
|
||||
}
|
||||
y = boundaryMask.nextSetBit(y + 1);
|
||||
}
|
||||
|
||||
paintBoundaryZone(output, walls, rx, rz, worldX, worldZ, zoneFloor, zoneCeiling, resolverState, caveBiomeCache, customBiomeCache);
|
||||
}
|
||||
|
||||
private void paintBoundaryZone(
|
||||
Hunk<PlatformBlockState> output,
|
||||
CarveWallBuffer walls,
|
||||
int rx,
|
||||
int rz,
|
||||
int worldX,
|
||||
int worldZ,
|
||||
int zoneFloor,
|
||||
int zoneCeiling,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache,
|
||||
Map<String, IrisBiome> customBiomeCache
|
||||
) {
|
||||
IrisBiome floorBiome = resolveCaveBoundaryBiome(
|
||||
walls.get(rx, zoneFloor, rz), worldX, zoneFloor, worldZ,
|
||||
resolverState, caveBiomeCache, customBiomeCache);
|
||||
IrisBiome ceilingBiome = resolveCaveBoundaryBiome(
|
||||
walls.get(rx, zoneCeiling, rz), worldX, zoneCeiling, worldZ,
|
||||
resolverState, caveBiomeCache, customBiomeCache);
|
||||
if (floorBiome == null && ceilingBiome == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (floorBiome != null) {
|
||||
KList<PlatformBlockState> floorLayers = floorBiome.generateLayers(
|
||||
getDimension(), worldX, worldZ, rng, 3, zoneFloor, getData(), getComplex());
|
||||
for (int i = 0; i < zoneFloor - 1; i++) {
|
||||
if (!floorLayers.hasIndex(i)) {
|
||||
break;
|
||||
}
|
||||
int floorY = zoneFloor - i - 1;
|
||||
if (floorY < 0) {
|
||||
break;
|
||||
}
|
||||
PlatformBlockState existing = output.getRaw(rx, floorY, rz);
|
||||
PlatformBlockState layer = floorLayers.get(i);
|
||||
if (!B.isSolid(existing) || !canReplaceCaveFloorLayer(output, rx, floorY, rz, layer)) {
|
||||
continue;
|
||||
}
|
||||
if (B.isOre(existing)) {
|
||||
output.setRaw(rx, floorY, rz, B.toDeepSlateOre(existing, layer));
|
||||
continue;
|
||||
}
|
||||
output.setRaw(rx, floorY, rz, layer);
|
||||
}
|
||||
}
|
||||
|
||||
if (ceilingBiome != null) {
|
||||
int worldMaxY = getEngine().getWorld().maxHeight() - getEngine().getWorld().minHeight();
|
||||
KList<PlatformBlockState> ceilingLayers = ceilingBiome.generateCeilingLayers(
|
||||
getDimension(), worldX, worldZ, rng, 3, zoneCeiling, getData(), getComplex());
|
||||
for (int i = 0; i < ceilingLayers.size(); i++) {
|
||||
int ceilingY = zoneCeiling + i + 1;
|
||||
if (ceilingY >= worldMaxY) {
|
||||
break;
|
||||
}
|
||||
PlatformBlockState existing = output.getRaw(rx, ceilingY, rz);
|
||||
if (!B.isSolid(existing)) {
|
||||
continue;
|
||||
}
|
||||
PlatformBlockState layer = ceilingLayers.get(i);
|
||||
if (B.isOre(existing)) {
|
||||
output.setRaw(rx, ceilingY, rz, B.toDeepSlateOre(existing, layer));
|
||||
continue;
|
||||
}
|
||||
output.setRaw(rx, ceilingY, rz, layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1-in-16 marker roll from a SplitMix64 finalizer over (carve seed, block position, salt).
|
||||
* Deterministic per seed and position, thread-order independent, allocation free.
|
||||
*/
|
||||
private boolean markerRoll(int x, int y, int z, long salt) {
|
||||
long h = (getEngine().getSeedManager().getCarve() + salt) ^ BlockPosition.toLong(x, y, z);
|
||||
h = (h ^ (h >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
h = (h ^ (h >>> 27)) * 0x94D049BB133111EBL;
|
||||
h ^= h >>> 31;
|
||||
return (h & 15L) == 0L;
|
||||
}
|
||||
|
||||
private void processZone(Hunk<PlatformBlockState> output, MantleChunk<Matter> mc, Mantle<Matter> mantle, CaveZone zone, int rx, int rz, int xx, int zz, IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache, Map<String, IrisBiome> customBiomeCache) {
|
||||
int maxY = output.getHeight();
|
||||
|
||||
if (zone.ceiling + 1 < maxY && B.isDecorant(output.getRaw(rx, zone.ceiling + 1, rz))) {
|
||||
output.setRaw(rx, zone.ceiling + 1, rz, AIR);
|
||||
}
|
||||
|
||||
if (B.isDecorant(output.getRaw(rx, zone.ceiling, rz))) {
|
||||
output.setRaw(rx, zone.ceiling, rz, AIR);
|
||||
}
|
||||
|
||||
// Seed-derived and position-keyed, never Math.random(): these markers persist into the
|
||||
// mantle and drive cave spawning, so the same seed must stamp the same markers on
|
||||
// every run and every platform. Inline mix, no allocation on this hot path.
|
||||
if (markerRoll(xx, zone.ceiling, zz, 0x9E3779B97F4A7C15L)) {
|
||||
mantle.set(xx, zone.ceiling, zz, MarkerMatter.CAVE_CEILING);
|
||||
}
|
||||
|
||||
if (markerRoll(xx, zone.floor, zz, 0xC2B2AE3D27D4EB4FL)) {
|
||||
mantle.set(xx, zone.floor, zz, MarkerMatter.CAVE_FLOOR);
|
||||
}
|
||||
|
||||
IrisBiome floorBiome = resolveCaveBoundaryBiome(mc, rx, zone.floor, rz, xx, zz, resolverState, caveBiomeCache, customBiomeCache);
|
||||
IrisBiome ceilingBiome = resolveCaveBoundaryBiome(mc, rx, zone.ceiling, rz, xx, zz, resolverState, caveBiomeCache, customBiomeCache);
|
||||
if (floorBiome == null && ceilingBiome == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (floorBiome != null) {
|
||||
KList<PlatformBlockState> floorBlocks = floorBiome.generateLayers(getDimension(), xx, zz, rng, 3, zone.floor, getData(), getComplex());
|
||||
for (int i = 0; i < zone.floor - 1; i++) {
|
||||
if (!floorBlocks.hasIndex(i)) {
|
||||
break;
|
||||
}
|
||||
int y = zone.floor - i - 1;
|
||||
PlatformBlockState block = floorBlocks.get(i);
|
||||
PlatformBlockState existing = output.getRaw(rx, y, rz);
|
||||
if (!B.isSolid(existing) || !canReplaceCaveFloorLayer(output, rx, y, rz, block)) {
|
||||
continue;
|
||||
}
|
||||
if (B.isOre(existing)) {
|
||||
output.setRaw(rx, y, rz, B.toDeepSlateOre(existing, block));
|
||||
continue;
|
||||
}
|
||||
output.setRaw(rx, y, rz, block);
|
||||
}
|
||||
}
|
||||
|
||||
if (ceilingBiome != null) {
|
||||
KList<PlatformBlockState> ceilingBlocks = ceilingBiome.generateCeilingLayers(getDimension(), xx, zz, rng, 3, zone.ceiling, getData(), getComplex());
|
||||
for (int i = 0; i < ceilingBlocks.size(); i++) {
|
||||
int cy = zone.ceiling + i + 1;
|
||||
if (cy >= maxY) {
|
||||
break;
|
||||
}
|
||||
PlatformBlockState block = ceilingBlocks.get(i);
|
||||
PlatformBlockState existing = output.getRaw(rx, cy, rz);
|
||||
if (!B.isSolid(existing)) {
|
||||
continue;
|
||||
}
|
||||
if (B.isOre(existing)) {
|
||||
output.setRaw(rx, cy, rz, B.toDeepSlateOre(existing, block));
|
||||
continue;
|
||||
}
|
||||
output.setRaw(rx, cy, rz, block);
|
||||
}
|
||||
}
|
||||
|
||||
IrisDecorator[] surfaceDecorators = floorBiome == null
|
||||
? new IrisDecorator[0]
|
||||
: floorBiome.getDecoratorBucket(IrisDecorationPart.NONE);
|
||||
if (surfaceDecorators.length > 0 && hasStableCaveFloorSupport(output, rx, zone.getFloor(), rz)) {
|
||||
decorant.getSurfaceDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, floorBiome, InferredType.CAVE, zone.getFloor() - 1, zone.airThickness());
|
||||
}
|
||||
|
||||
IrisDecorator[] ceilingDecorators = ceilingBiome == null
|
||||
? new IrisDecorator[0]
|
||||
: ceilingBiome.getDecoratorBucket(IrisDecorationPart.CEILING);
|
||||
if (ceilingDecorators.length > 0 && zone.getCeiling() + 1 < maxY && B.isSolid(output.getRaw(rx, zone.getCeiling() + 1, rz))) {
|
||||
decorant.getCeilingDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, ceilingBiome, InferredType.CAVE, zone.getCeiling(), zone.airThickness());
|
||||
}
|
||||
}
|
||||
|
||||
IrisBiome resolveCaveBoundaryBiome(MantleChunk<Matter> mantleChunk, int x, int y, int z, int worldX, int worldZ, IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache, Map<String, IrisBiome> customBiomeCache) {
|
||||
MatterCavern cavern = dataIfPresent(mantleChunk, x, y, z, MatterCavern.class);
|
||||
return resolveCaveBoundaryBiome(
|
||||
cavern, worldX, y, worldZ, resolverState, caveBiomeCache, customBiomeCache);
|
||||
}
|
||||
|
||||
private static <T> T dataIfPresent(MantleChunk<Matter> mantleChunk, int x, int y, int z, Class<T> type) {
|
||||
int section = y >> 4;
|
||||
if (y < 0 || !mantleChunk.exists(section)) {
|
||||
return null;
|
||||
}
|
||||
Matter matter = mantleChunk.get(section);
|
||||
if (matter == null || !matter.hasSlice(type)) {
|
||||
return null;
|
||||
}
|
||||
return matter.<T>getSlice(type).get(x & 15, y & 15, z & 15);
|
||||
}
|
||||
|
||||
IrisBiome resolveCaveBoundaryBiome(MatterCavern cavern, int worldX, int y, int worldZ, IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache, Map<String, IrisBiome> customBiomeCache) {
|
||||
if (cavern != null && !cavern.getCustomBiome().isEmpty()) {
|
||||
return resolveCustomBiome(customBiomeCache, cavern.getCustomBiome());
|
||||
}
|
||||
return resolveCaveBiome(caveBiomeCache, worldX, y, worldZ, resolverState);
|
||||
}
|
||||
|
||||
static boolean canReplaceCaveFloorLayer(Hunk<PlatformBlockState> output, int x, int y, int z, PlatformBlockState layer) {
|
||||
return !isGravityAffected(layer) || y > 0 && B.isSolid(output.getRaw(x, y - 1, z));
|
||||
}
|
||||
|
||||
static boolean hasStableCaveFloorSupport(Hunk<PlatformBlockState> output, int x, int floorY, int z) {
|
||||
if (floorY <= 0) {
|
||||
return false;
|
||||
}
|
||||
PlatformBlockState support = output.getRaw(x, floorY - 1, z);
|
||||
if (!B.isSolid(support)) {
|
||||
return false;
|
||||
}
|
||||
return !isGravityAffected(support) || floorY > 1 && B.isSolid(output.getRaw(x, floorY - 2, z));
|
||||
}
|
||||
|
||||
static boolean isGravityAffected(PlatformBlockState state) {
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
String key = IrisProceduralBlocks.materialKey(state);
|
||||
return key.equals("minecraft:sand")
|
||||
|| key.equals("minecraft:red_sand")
|
||||
|| key.equals("minecraft:gravel")
|
||||
|| key.equals("minecraft:suspicious_sand")
|
||||
|| key.equals("minecraft:suspicious_gravel")
|
||||
|| key.endsWith("_concrete_powder");
|
||||
}
|
||||
|
||||
private IrisBiome resolveCaveBiome(Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache, int x, int y, int z, IrisDimensionCarvingResolver.State resolverState) {
|
||||
IrisBiome center = sampleCaveBiome(caveBiomeCache, x, y, z, resolverState);
|
||||
if (center == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IrisBiome xPos = sampleCaveBiome(caveBiomeCache, x + CAVE_BIOME_BLEND_RADIUS, y, z, resolverState);
|
||||
IrisBiome xNeg = sampleCaveBiome(caveBiomeCache, x - CAVE_BIOME_BLEND_RADIUS, y, z, resolverState);
|
||||
IrisBiome zPos = sampleCaveBiome(caveBiomeCache, x, y, z + CAVE_BIOME_BLEND_RADIUS, resolverState);
|
||||
IrisBiome zNeg = sampleCaveBiome(caveBiomeCache, x, y, z - CAVE_BIOME_BLEND_RADIUS, resolverState);
|
||||
|
||||
if (xPos == center && xNeg == center && zPos == center && zNeg == center) {
|
||||
return center;
|
||||
}
|
||||
|
||||
int roll = Math.floorMod(rng.nextParallelRNG(BlockPosition.toLong(x, y, z)).nextInt(), CAVE_BIOME_BLEND_TOTAL_WEIGHT);
|
||||
if (roll < CAVE_BIOME_BLEND_CENTER_WEIGHT) {
|
||||
return center;
|
||||
}
|
||||
roll -= CAVE_BIOME_BLEND_CENTER_WEIGHT;
|
||||
if (roll == 0) {
|
||||
return xPos != null ? xPos : center;
|
||||
}
|
||||
if (roll == 1) {
|
||||
return xNeg != null ? xNeg : center;
|
||||
}
|
||||
if (roll == 2) {
|
||||
return zPos != null ? zPos : center;
|
||||
}
|
||||
return zNeg != null ? zNeg : center;
|
||||
}
|
||||
|
||||
private IrisBiome sampleCaveBiome(Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache, int x, int y, int z, IrisDimensionCarvingResolver.State resolverState) {
|
||||
long key = BlockPosition.toLong(x, y, z);
|
||||
IrisBiome cachedBiome = caveBiomeCache.get(key);
|
||||
if (cachedBiome != null) {
|
||||
return cachedBiome;
|
||||
}
|
||||
|
||||
IrisBiome resolvedBiome = getEngine().getCaveBiome(x, y, z, resolverState);
|
||||
if (resolvedBiome != null) {
|
||||
caveBiomeCache.put(key, resolvedBiome);
|
||||
}
|
||||
return resolvedBiome;
|
||||
}
|
||||
|
||||
private IrisBiome resolveCustomBiome(Map<String, IrisBiome> customBiomeCache, String customBiome) {
|
||||
if (customBiomeCache.containsKey(customBiome)) {
|
||||
return customBiomeCache.get(customBiome);
|
||||
}
|
||||
|
||||
IrisBiome loaded = getEngine().getData().getBiomeLoader().load(customBiome);
|
||||
customBiomeCache.put(customBiome, loaded);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CaveZone {
|
||||
private int ceiling = -1;
|
||||
private int floor = -1;
|
||||
|
||||
public int airThickness() {
|
||||
return (ceiling - floor) - 1;
|
||||
}
|
||||
|
||||
public boolean isValid(Engine engine) {
|
||||
return floor < ceiling && ceiling - floor >= 1 && floor >= 0 && ceiling <= engine.getHeight() && airThickness() > 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return floor + "-" + ceiling;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class IrisCarveScratch {
|
||||
final CarveColumnMask[] columnMasks = new CarveColumnMask[256];
|
||||
final CarveColumnMask[] boundaryMasks = new CarveColumnMask[256];
|
||||
final int[] surfaceHeights = new int[256];
|
||||
final CarveWallBuffer walls = new CarveWallBuffer(512);
|
||||
final Map<String, IrisBiome> customBiomeCache = new HashMap<>();
|
||||
int[] upperSurfaceHeights;
|
||||
boolean customCaveBiomePresent;
|
||||
|
||||
IrisCarveScratch() {
|
||||
for (int index = 0; index < columnMasks.length; index++) {
|
||||
columnMasks[index] = new CarveColumnMask();
|
||||
boundaryMasks[index] = new CarveColumnMask();
|
||||
}
|
||||
}
|
||||
|
||||
int[] getOrCreateUpperSurfaceHeights() {
|
||||
if (upperSurfaceHeights == null) {
|
||||
upperSurfaceHeights = new int[256];
|
||||
}
|
||||
return upperSurfaceHeights;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
for (int index = 0; index < columnMasks.length; index++) {
|
||||
columnMasks[index].clear();
|
||||
boundaryMasks[index].clear();
|
||||
}
|
||||
walls.clear();
|
||||
customBiomeCache.clear();
|
||||
customCaveBiomePresent = false;
|
||||
}
|
||||
}
|
||||
|
||||
final class CarveColumnMask {
|
||||
private long[] words = new long[8];
|
||||
private int maxWord = -1;
|
||||
|
||||
void add(int y) {
|
||||
if (y < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int wordIndex = y >> 6;
|
||||
if (wordIndex >= words.length) {
|
||||
words = Arrays.copyOf(words, Math.max(words.length << 1, wordIndex + 1));
|
||||
}
|
||||
|
||||
words[wordIndex] |= 1L << (y & 63);
|
||||
if (wordIndex > maxWord) {
|
||||
maxWord = wordIndex;
|
||||
}
|
||||
}
|
||||
|
||||
int nextSetBit(int fromBit) {
|
||||
if (maxWord < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int startBit = Math.max(0, fromBit);
|
||||
int wordIndex = startBit >> 6;
|
||||
if (wordIndex > maxWord) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
long word = words[wordIndex] & (-1L << (startBit & 63));
|
||||
while (true) {
|
||||
if (word != 0L) {
|
||||
return (wordIndex << 6) + Long.numberOfTrailingZeros(word);
|
||||
}
|
||||
|
||||
wordIndex++;
|
||||
if (wordIndex > maxWord) {
|
||||
return -1;
|
||||
}
|
||||
word = words[wordIndex];
|
||||
}
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return maxWord < 0;
|
||||
}
|
||||
|
||||
boolean contains(int y) {
|
||||
if (y < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int wordIndex = y >> 6;
|
||||
if (wordIndex > maxWord) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (words[wordIndex] & (1L << (y & 63))) != 0L;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
if (maxWord < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int index = 0; index <= maxWord; index++) {
|
||||
words[index] = 0L;
|
||||
}
|
||||
maxWord = -1;
|
||||
}
|
||||
}
|
||||
|
||||
final class CarveWallBuffer {
|
||||
private static final int EMPTY_KEY = -1;
|
||||
private static final double LOAD_FACTOR = 0.75D;
|
||||
|
||||
private int[] keys;
|
||||
private MatterCavern[] values;
|
||||
private int mask;
|
||||
private int resizeAt;
|
||||
private int size;
|
||||
|
||||
CarveWallBuffer(int expectedSize) {
|
||||
int capacity = 1;
|
||||
int minimumCapacity = Math.max(8, expectedSize);
|
||||
while (capacity < minimumCapacity) {
|
||||
capacity <<= 1;
|
||||
}
|
||||
|
||||
keys = new int[capacity];
|
||||
Arrays.fill(keys, EMPTY_KEY);
|
||||
values = new MatterCavern[capacity];
|
||||
mask = capacity - 1;
|
||||
resizeAt = Math.max(1, (int) (capacity * LOAD_FACTOR));
|
||||
}
|
||||
|
||||
void put(int x, int y, int z, MatterCavern value) {
|
||||
int key = pack(x, y, z);
|
||||
int index = mix(key) & mask;
|
||||
|
||||
while (true) {
|
||||
int existingKey = keys[index];
|
||||
if (existingKey == EMPTY_KEY) {
|
||||
keys[index] = key;
|
||||
values[index] = value;
|
||||
size++;
|
||||
if (size >= resizeAt) {
|
||||
resize();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (existingKey == key) {
|
||||
values[index] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
index = (index + 1) & mask;
|
||||
}
|
||||
}
|
||||
|
||||
MatterCavern get(int x, int y, int z) {
|
||||
int key = pack(x, y, z);
|
||||
int index = mix(key) & mask;
|
||||
while (true) {
|
||||
int existingKey = keys[index];
|
||||
if (existingKey == EMPTY_KEY) {
|
||||
return null;
|
||||
}
|
||||
if (existingKey == key) {
|
||||
return values[index];
|
||||
}
|
||||
index = (index + 1) & mask;
|
||||
}
|
||||
}
|
||||
|
||||
void forEach(Consumer consumer) {
|
||||
for (int index = 0; index < keys.length; index++) {
|
||||
int key = keys[index];
|
||||
if (key == EMPTY_KEY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MatterCavern cavern = values[index];
|
||||
if (cavern != null) {
|
||||
consumer.accept(unpackX(key), unpackY(key), unpackZ(key), cavern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
Arrays.fill(keys, EMPTY_KEY);
|
||||
Arrays.fill(values, null);
|
||||
size = 0;
|
||||
}
|
||||
|
||||
private void resize() {
|
||||
int[] oldKeys = keys;
|
||||
MatterCavern[] oldValues = values;
|
||||
int nextCapacity = oldKeys.length << 1;
|
||||
keys = new int[nextCapacity];
|
||||
Arrays.fill(keys, EMPTY_KEY);
|
||||
values = new MatterCavern[nextCapacity];
|
||||
mask = nextCapacity - 1;
|
||||
resizeAt = Math.max(1, (int) (nextCapacity * LOAD_FACTOR));
|
||||
size = 0;
|
||||
|
||||
for (int index = 0; index < oldKeys.length; index++) {
|
||||
int key = oldKeys[index];
|
||||
MatterCavern value = oldValues[index];
|
||||
if (key != EMPTY_KEY && value != null) {
|
||||
reinsert(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reinsert(int key, MatterCavern value) {
|
||||
int index = mix(key) & mask;
|
||||
while (keys[index] != EMPTY_KEY) {
|
||||
index = (index + 1) & mask;
|
||||
}
|
||||
|
||||
keys[index] = key;
|
||||
values[index] = value;
|
||||
size++;
|
||||
}
|
||||
|
||||
private int pack(int x, int y, int z) {
|
||||
return (y << 8) | PowerOfTwoCoordinates.packLocal16(x & 15, z & 15);
|
||||
}
|
||||
|
||||
private int unpackX(int key) {
|
||||
return PowerOfTwoCoordinates.unpackLocal16X(key & 255);
|
||||
}
|
||||
|
||||
private int unpackY(int key) {
|
||||
return key >> 8;
|
||||
}
|
||||
|
||||
private int unpackZ(int key) {
|
||||
return PowerOfTwoCoordinates.unpackLocal16Z(key);
|
||||
}
|
||||
|
||||
private int mix(int value) {
|
||||
int mixed = value * 0x9E3779B9;
|
||||
return mixed ^ (mixed >>> 16);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface Consumer {
|
||||
void accept(int x, int y, int z, MatterCavern cavern);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
public class IrisCustomModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
public IrisCustomModifier(Engine engine) {
|
||||
super(engine, "Custom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
MantleChunk<Matter> mc = getEngine().getMantle().getMantle().getChunk(x >> 4, z >> 4);
|
||||
if (!mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) {
|
||||
return;
|
||||
}
|
||||
mc.use();
|
||||
|
||||
BurstExecutor burst = MultiBurst.burst.burst(output.getHeight());
|
||||
burst.setMulticore(multicore);
|
||||
// complete() must run before release() even when queueing throws — detached burst
|
||||
// tasks must never write into a released chunk, and a lost permit wedges close().
|
||||
try {
|
||||
for (int y = 0; y < output.getHeight(); y++) {
|
||||
int finalY = y;
|
||||
burst.queue(() -> {
|
||||
for (int rX = 0; rX < output.getWidth(); rX++) {
|
||||
for (int rZ = 0; rZ < output.getDepth(); rZ++) {
|
||||
PlatformBlockState b = output.get(rX, finalY, rZ);
|
||||
if (b == null || !b.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
String placementKey = b.deferredPlacementKey();
|
||||
PlatformBlockState baseState = b.placementBaseState();
|
||||
if (placementKey == null || baseState == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mc.getOrCreate(finalY >> 4)
|
||||
.slice(Identifier.class)
|
||||
.set(rX, finalY & 15, rZ, Identifier.fromString(placementKey));
|
||||
output.set(rX, finalY, rZ, baseState);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
burst.complete();
|
||||
} finally {
|
||||
mc.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositHeightDistribution;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositPlacementScope;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositVariant;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.volmlib.util.data.HeightMap;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
|
||||
public class IrisDepositModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
private final RNG rng;
|
||||
|
||||
public IrisDepositModifier(Engine engine) {
|
||||
super(engine, "Deposit");
|
||||
rng = new RNG(getEngine().getSeedManager().getDeposit());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
generateDeposits(output, Math.floorDiv(x, 16), Math.floorDiv(z, 16), multicore, context);
|
||||
getEngine().getMetrics().getDeposit().put(p.getMilliseconds());
|
||||
}
|
||||
|
||||
public void generateDeposits(Hunk<PlatformBlockState> terrain, int x, int z, boolean multicore, ChunkContext context) {
|
||||
IrisRegion region = context.getRegion().get(7, 7);
|
||||
IrisBiome biome = context.getBiome().get(7, 7);
|
||||
BurstExecutor burst = burst().burst(multicore);
|
||||
|
||||
long seed = x * 341873128712L + z * 132897987541L;
|
||||
long mask = 0;
|
||||
MantleChunk chunk = getEngine().getMantle().getMantle().getChunk(x, z).use();
|
||||
try {
|
||||
for (IrisDepositGenerator k : getDimension().getDeposits()) {
|
||||
long finalSeed = seed * ++mask;
|
||||
burst.queue(() -> generate(k, chunk, terrain, rng.nextParallelRNG(finalSeed), x, z, false, context));
|
||||
}
|
||||
|
||||
for (IrisDepositGenerator k : region.getDeposits()) {
|
||||
long finalSeed = seed * ++mask;
|
||||
burst.queue(() -> generate(k, chunk, terrain, rng.nextParallelRNG(finalSeed), x, z, false, context));
|
||||
}
|
||||
|
||||
for (IrisDepositGenerator k : biome.getDeposits()) {
|
||||
long finalSeed = seed * ++mask;
|
||||
burst.queue(() -> generate(k, chunk, terrain, rng.nextParallelRNG(finalSeed), x, z, false, context));
|
||||
}
|
||||
} finally {
|
||||
// complete() must run before release() even when queueing throws — already
|
||||
// submitted burst tasks must never write into a released chunk.
|
||||
try {
|
||||
burst.complete();
|
||||
} finally {
|
||||
chunk.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generate(IrisDepositGenerator k, MantleChunk chunk, Hunk<PlatformBlockState> data, RNG rng, int cx, int cz, boolean safe, ChunkContext context) {
|
||||
generate(k, chunk, data, rng, cx, cz, safe, null, context);
|
||||
}
|
||||
|
||||
public void generate(IrisDepositGenerator k, MantleChunk chunk, Hunk<PlatformBlockState> data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) {
|
||||
IrisDimensionCarvingResolver.State carvingState = new IrisDimensionCarvingResolver.State();
|
||||
if (k.getSpawnChance() < rng.d())
|
||||
return;
|
||||
|
||||
for (int l = 0; l < rng.i(k.getMinPerChunk(), k.getMaxPerChunk() + 1); l++) {
|
||||
if (k.getPerClumpSpawnChance() < rng.d())
|
||||
continue;
|
||||
|
||||
IrisObject clump = k.getClump(getEngine(), rng, getData());
|
||||
|
||||
int dim = clump.getW();
|
||||
int min = dim / 2;
|
||||
int max = (int) (16D - dim / 2D);
|
||||
|
||||
if (min > max || min < 0 || max > 15) {
|
||||
min = 6;
|
||||
max = 9;
|
||||
}
|
||||
|
||||
int x = rng.i(min, max + 1);
|
||||
int z = rng.i(min, max + 1);
|
||||
int terrainSurface = getDepositTerrainSurface(cx, cz, x, z, he, context);
|
||||
int height = k.getPlacementScope() == IrisDepositPlacementScope.TERRAIN
|
||||
? depositSurfaceLimit(terrainSurface, k.getSurfaceClearance())
|
||||
: getEngine().getHeight() - 1;
|
||||
|
||||
if (height < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int y = sampleHeight(
|
||||
k.getHeightDistribution(), rng, k.getMinHeight(), k.getMaxHeight(),
|
||||
Math.min(height, getEngine().getHeight() - 1));
|
||||
if (y == Integer.MIN_VALUE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean clippedHeight = k.getHeightDistribution() == IrisDepositHeightDistribution.CLIPPED_UNIFORM;
|
||||
if (clippedHeight && y > height - 2)
|
||||
continue;
|
||||
|
||||
int biomeY = Math.max(0, Math.min(getEngine().getHeight() - 1, y));
|
||||
boolean oreDeposit = k.isOre(getData());
|
||||
IrisBiome surfaceBiome = context.getBiome().get(x, z);
|
||||
IrisBiome depositBiome = oreDeposit || k.usesCaveBiomeFilter()
|
||||
? getEngine().getCaveBiome(
|
||||
(cx << 4) + x, biomeY, (cz << 4) + z, carvingState)
|
||||
: null;
|
||||
if (!k.matchesBiome(surfaceBiome, depositBiome)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oreDeposit) {
|
||||
if (depositBiome != null) {
|
||||
double frequencyMultiplier = depositBiome.getOreDepositFrequencyMultiplier();
|
||||
if (frequencyMultiplier < 1D
|
||||
&& !passesOreFrequency(frequencyMultiplier, rng.d())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double sizeMultiplier = depositBiome.getOreDepositSizeMultiplier();
|
||||
if (sizeMultiplier != 1D) {
|
||||
IrisObject scaledClump = k.getClump(getEngine(), rng, getData(), sizeMultiplier);
|
||||
int scaledDimension = scaledClump.getW();
|
||||
x = clampDepositCenter(x, scaledDimension, 16);
|
||||
if (clippedHeight) {
|
||||
y = clampDepositCenter(y, scaledDimension, getEngine().getHeight());
|
||||
}
|
||||
z = clampDepositCenter(z, scaledDimension, 16);
|
||||
clump = scaledClump;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IrisDimension dimension = getDimension();
|
||||
|
||||
for (art.arcane.iris.util.common.math.IrisBlockVector j : clump.getBlocks().keys()) {
|
||||
int nx = j.getBlockX() + x;
|
||||
int ny = j.getBlockY() + y;
|
||||
int nz = j.getBlockZ() + z;
|
||||
|
||||
if (nx > 15 || nx < 0 || ny >= getEngine().getHeight() || ny < 0 || nz < 0 || nz > 15) {
|
||||
continue;
|
||||
}
|
||||
int columnSurface = getDepositTerrainSurface(cx, cz, nx, nz, he, context);
|
||||
if (!placementSurfaceAllows(
|
||||
k.getPlacementScope(), ny, columnSurface, k.getSurfaceClearance())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlatformBlockState current = data.get(nx, ny, nz);
|
||||
if (!canReplaceDepositTarget(current)) {
|
||||
continue;
|
||||
}
|
||||
if (!k.canReplace(current)) {
|
||||
continue;
|
||||
}
|
||||
if (!k.isReplaceBedrock() && IrisProceduralBlocks.materialKey(current).equals("minecraft:bedrock")) {
|
||||
continue;
|
||||
}
|
||||
if (shouldDiscardExposed(
|
||||
k.getDiscardChanceOnAirExposure(), rng.d(), isAdjacentToAir(data, nx, ny, nz))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (chunk.get(nx, ny, nz, MatterCavern.class) == null) {
|
||||
PlatformBlockState ore = clump.getBlocks().get(j);
|
||||
PlatformBlockState remapped = resolveDepositVariant(
|
||||
cx, cz, nx, ny, nz, ore, dimension, context, carvingState);
|
||||
PlatformBlockState finalBlock = remapped != null
|
||||
? remapped
|
||||
: B.toDeepSlateOre(current, ore);
|
||||
data.set(nx, ny, nz, finalBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getDepositTerrainSurface(
|
||||
int cx, int cz, int localX, int localZ, HeightMap heightMap,
|
||||
ChunkContext context) {
|
||||
return heightMap != null
|
||||
? heightMap.getHeight((cx << 4) + localX, (cz << 4) + localZ)
|
||||
: context.getRoundedHeight(localX, localZ);
|
||||
}
|
||||
|
||||
static int depositSurfaceLimit(int surfaceY) {
|
||||
return depositSurfaceLimit(surfaceY, 7);
|
||||
}
|
||||
|
||||
static int depositSurfaceLimit(int surfaceY, int surfaceClearance) {
|
||||
return surfaceY - Math.max(0, surfaceClearance);
|
||||
}
|
||||
|
||||
static boolean placementSurfaceAllows(
|
||||
IrisDepositPlacementScope scope, int candidateY, int surfaceY, int surfaceClearance) {
|
||||
int clearance = Math.max(0, surfaceClearance);
|
||||
return switch (scope) {
|
||||
case ABOVE_TERRAIN -> candidateY > surfaceY + clearance;
|
||||
case FULL_HEIGHT -> true;
|
||||
case TERRAIN -> candidateY <= surfaceY - clearance;
|
||||
};
|
||||
}
|
||||
|
||||
static int absoluteWorldY(int minHeight, int localY) {
|
||||
return minHeight + localY;
|
||||
}
|
||||
|
||||
static boolean canReplaceDepositTarget(PlatformBlockState state) {
|
||||
return state != null && !state.isAir() && !state.isFluid();
|
||||
}
|
||||
|
||||
static int sampleHeight(
|
||||
IrisDepositHeightDistribution distribution, RNG rng,
|
||||
int configuredMinimum, int configuredMaximum, int clippedMaximum) {
|
||||
int minimum = distribution == IrisDepositHeightDistribution.CLIPPED_UNIFORM
|
||||
? Math.max(0, configuredMinimum)
|
||||
: configuredMinimum;
|
||||
int maximum = distribution == IrisDepositHeightDistribution.CLIPPED_UNIFORM
|
||||
? Math.min(clippedMaximum, configuredMaximum)
|
||||
: configuredMaximum;
|
||||
if (minimum > maximum) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
if (minimum == maximum) {
|
||||
return minimum;
|
||||
}
|
||||
if (distribution != IrisDepositHeightDistribution.TRIANGLE) {
|
||||
return minimum + rng.nextInt(maximum - minimum + 1);
|
||||
}
|
||||
|
||||
int span = maximum - minimum;
|
||||
int lowerHalf = span / 2;
|
||||
int upperHalf = span - lowerHalf;
|
||||
return minimum + rng.nextInt(upperHalf + 1) + rng.nextInt(lowerHalf + 1);
|
||||
}
|
||||
|
||||
static boolean shouldDiscardExposed(double chance, double sample, boolean adjacentToAir) {
|
||||
return adjacentToAir && chance > 0D && sample < Math.min(1D, chance);
|
||||
}
|
||||
|
||||
static boolean isAdjacentToAir(Hunk<PlatformBlockState> data, int x, int y, int z) {
|
||||
return isAirAt(data, x - 1, y, z)
|
||||
|| isAirAt(data, x + 1, y, z)
|
||||
|| isAirAt(data, x, y - 1, z)
|
||||
|| isAirAt(data, x, y + 1, z)
|
||||
|| isAirAt(data, x, y, z - 1)
|
||||
|| isAirAt(data, x, y, z + 1);
|
||||
}
|
||||
|
||||
private static boolean isAirAt(Hunk<PlatformBlockState> data, int x, int y, int z) {
|
||||
if (x < 0 || x >= data.getWidth()
|
||||
|| y < 0 || y >= data.getHeight()
|
||||
|| z < 0 || z >= data.getDepth()) {
|
||||
return false;
|
||||
}
|
||||
PlatformBlockState state = data.getRaw(x, y, z);
|
||||
return state == null || state.isAir();
|
||||
}
|
||||
|
||||
static boolean passesOreFrequency(double multiplier, double sample) {
|
||||
return multiplier >= 1D || sample < Math.max(0D, multiplier);
|
||||
}
|
||||
|
||||
static int clampDepositCenter(int center, int dimension, int limit) {
|
||||
int minimum = dimension / 2;
|
||||
int maximum = (int) (limit - dimension / 2D);
|
||||
return Math.max(minimum, Math.min(center, maximum));
|
||||
}
|
||||
|
||||
private PlatformBlockState resolveDepositVariant(int cx, int cz, int nx, int localY, int nz, PlatformBlockState ore, IrisDimension dimension, ChunkContext context, IrisDimensionCarvingResolver.State carvingState) {
|
||||
int worldX = (cx << 4) + nx;
|
||||
int worldZ = (cz << 4) + nz;
|
||||
int worldY = absoluteWorldY(getEngine().getMinHeight(), localY);
|
||||
|
||||
IrisBiome biome = getEngine().getCaveBiome(worldX, localY, worldZ, carvingState);
|
||||
if (biome != null) {
|
||||
PlatformBlockState match = matchDepositVariant(biome.getDepositVariants(), ore, worldY);
|
||||
if (match != null) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
IrisRegion region = context.getRegion().get(nx, nz);
|
||||
if (region != null) {
|
||||
PlatformBlockState match = matchDepositVariant(region.getDepositVariants(), ore, worldY);
|
||||
if (match != null) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
if (dimension != null) {
|
||||
PlatformBlockState match = matchDepositVariant(dimension.getDepositVariants(), ore, worldY);
|
||||
if (match != null) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private PlatformBlockState matchDepositVariant(java.util.List<IrisDepositVariant> variants, PlatformBlockState ore, int y) {
|
||||
if (variants == null || variants.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (IrisDepositVariant variant : variants) {
|
||||
if (y < variant.getMinHeight() || y > variant.getMaxHeight()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlatformBlockState swapped = variant.remapOrNull(ore, getData());
|
||||
if (swapped != null) {
|
||||
return swapped;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.decorator.FloatingDecorator;
|
||||
import art.arcane.iris.engine.decorator.IrisSeaSurfaceDecorator;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.engine.framework.EngineDecorator;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingBottomPaletteMode;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.terrain.IrisBiomePaletteLayer;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorationPart;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.terrain.floating.IrisFloatingChildBiomes;
|
||||
import art.arcane.iris.engine.object.placement.IrisSlopeClip;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
|
||||
import static art.arcane.iris.engine.mantle.EngineMantle.AIR;
|
||||
|
||||
public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
public static final long FLOATING_BASE_SEED_SALT = 0x5EED_F107_00F1B10CL;
|
||||
private static final Runnable NOOP_DECORATION_MISS = () -> {
|
||||
};
|
||||
private final RNG rng;
|
||||
private final EngineDecorator seaSurfaceDecorator;
|
||||
|
||||
private static KList<PlatformBlockState> generateBottomPaletteLayers(IrisFloatingChildBiomes entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, IrisData data, IrisComplex complex) {
|
||||
if (entry == null || entry.getBottomPaletteMode() != FloatingBottomPaletteMode.CUSTOM || entry.getBottomPalette() == null || entry.getBottomPalette().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return generatePaletteLayers(dimension, entry.getBottomPalette(), wx, wz, random.nextParallelRNG(0xB0770B), paletteDepth, data, complex);
|
||||
}
|
||||
|
||||
private static KList<PlatformBlockState> generatePaletteLayers(IrisDimension dimension, KList<IrisBiomePaletteLayer> layers, double wx, double wz, RNG random, int maxDepth, IrisData data, IrisComplex complex) {
|
||||
KList<PlatformBlockState> generated = new KList<>();
|
||||
if (layers == null || layers.isEmpty() || maxDepth <= 0) {
|
||||
return generated;
|
||||
}
|
||||
|
||||
int generatorSeed = 7235;
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
IrisBiomePaletteLayer layer = layers.get(i);
|
||||
CNG heightGenerator = layer.getHeightGenerator(random.nextParallelRNG((generatorSeed++) * generatorSeed * generatorSeed * generatorSeed), data);
|
||||
if (heightGenerator == null) {
|
||||
continue;
|
||||
}
|
||||
double layerDepth = heightGenerator.fit(layer.getMinHeight(), layer.getMaxHeight(), wx / layer.getZoom(), wz / layer.getZoom());
|
||||
IrisSlopeClip slopeClip = layer.getSlopeCondition();
|
||||
|
||||
if (slopeClip != null && !slopeClip.isDefault() && complex != null && !slopeClip.isValid(complex.getSlopeStream().get(wx, wz))) {
|
||||
layerDepth = 0;
|
||||
}
|
||||
|
||||
if (layerDepth <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < layerDepth; j++) {
|
||||
if (generated.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.getZoom(), j, (wz - j) / layer.getZoom(), data));
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (generated.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (dimension != null && dimension.isExplodeBiomePalettes()) {
|
||||
PlatformBlockState barrier = B.getState("minecraft:barrier");
|
||||
for (int j = 0; j < dimension.getExplodeBiomePaletteSize(); j++) {
|
||||
generated.add(barrier);
|
||||
|
||||
if (generated.size() >= maxDepth) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
private static boolean usesBottomPalette(IrisFloatingChildBiomes entry) {
|
||||
FloatingBottomPaletteMode mode = entry == null || entry.getBottomPaletteMode() == null ? FloatingBottomPaletteMode.DEPTH : entry.getBottomPaletteMode();
|
||||
return mode != FloatingBottomPaletteMode.DEPTH;
|
||||
}
|
||||
|
||||
private static int[] bottomDepths(FloatingIslandSample sample, int chunkHeight) {
|
||||
int[] bottomDepths = new int[sample.solidMask.length];
|
||||
for (int i = 0; i < bottomDepths.length; i++) {
|
||||
bottomDepths[i] = -1;
|
||||
}
|
||||
|
||||
IdentityHashMap<IrisFloatingChildBiomes, Integer> depthByEntry = new IdentityHashMap<>();
|
||||
int max = Math.min(sample.topIdx, sample.solidMask.length - 1);
|
||||
for (int k = 0; k <= max; k++) {
|
||||
if (!sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
IrisFloatingChildBiomes entry = sample.entryAt(k);
|
||||
int depth = depthByEntry.getOrDefault(entry, 0);
|
||||
bottomDepths[k] = depth;
|
||||
depthByEntry.put(entry, depth + 1);
|
||||
}
|
||||
|
||||
return bottomDepths;
|
||||
}
|
||||
|
||||
private static PlatformBlockState selectPaletteBlock(IrisFloatingChildBiomes entry, KList<PlatformBlockState> topBlocks, KList<PlatformBlockState> bottomBlocks, int topDepth, int bottomDepth, PlatformBlockState fallbackSolid) {
|
||||
FloatingBottomPaletteMode mode = entry == null || entry.getBottomPaletteMode() == null ? FloatingBottomPaletteMode.DEPTH : entry.getBottomPaletteMode();
|
||||
if (mode == FloatingBottomPaletteMode.MIRROR_TOP) {
|
||||
return paletteBlock(topBlocks, Math.min(topDepth, bottomDepth), fallbackSolid);
|
||||
}
|
||||
if (mode == FloatingBottomPaletteMode.CUSTOM && bottomDepth < topDepth) {
|
||||
if (bottomBlocks != null && !bottomBlocks.isEmpty()) {
|
||||
return paletteBlock(bottomBlocks, bottomDepth, fallbackSolid);
|
||||
}
|
||||
return paletteBlock(topBlocks, bottomDepth, fallbackSolid);
|
||||
}
|
||||
return paletteBlock(topBlocks, topDepth, fallbackSolid);
|
||||
}
|
||||
|
||||
private static PlatformBlockState paletteBlock(KList<PlatformBlockState> blocks, int depth, PlatformBlockState fallbackSolid) {
|
||||
if (blocks == null || blocks.isEmpty()) {
|
||||
return fallbackSolid;
|
||||
}
|
||||
PlatformBlockState block = blocks.hasIndex(depth) ? blocks.get(depth) : blocks.getLast();
|
||||
return block == null ? fallbackSolid : block;
|
||||
}
|
||||
|
||||
private PaletteContext createPaletteContext(IrisBiome parent, IrisFloatingChildBiomes entry, IrisDimension dimension, int wx, int wz, long colSeed, int paletteDepth, IrisData data, IrisComplex complex) {
|
||||
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data);
|
||||
int entrySeed = entry == null || entry.getBiome() == null ? 0 : entry.getBiome().hashCode();
|
||||
RNG layerRng = rng.nextParallelRNG((int) (colSeed ^ 0x7A4E ^ entrySeed));
|
||||
KList<PlatformBlockState> topBlocks = target == null ? null : target.generateLayers(dimension, wx, wz, layerRng, paletteDepth, paletteDepth, data, complex);
|
||||
if (topBlocks == null || topBlocks.isEmpty()) {
|
||||
topBlocks = parent.generateLayers(dimension, wx, wz, layerRng, paletteDepth, paletteDepth, data, complex);
|
||||
}
|
||||
KList<PlatformBlockState> bottomBlocks = generateBottomPaletteLayers(entry, dimension, wx, wz, layerRng, paletteDepth, data, complex);
|
||||
return new PaletteContext(topBlocks, bottomBlocks, B.getState("minecraft:stone"));
|
||||
}
|
||||
|
||||
private static final class PaletteContext {
|
||||
private final KList<PlatformBlockState> topBlocks;
|
||||
private final KList<PlatformBlockState> bottomBlocks;
|
||||
private final PlatformBlockState fallbackSolid;
|
||||
|
||||
private PaletteContext(KList<PlatformBlockState> topBlocks, KList<PlatformBlockState> bottomBlocks, PlatformBlockState fallbackSolid) {
|
||||
this.topBlocks = topBlocks;
|
||||
this.bottomBlocks = bottomBlocks;
|
||||
this.fallbackSolid = fallbackSolid;
|
||||
}
|
||||
}
|
||||
|
||||
public IrisFloatingChildBiomeModifier(Engine engine) {
|
||||
super(engine, "FloatingChildBiomes");
|
||||
rng = new RNG(engine.getSeedManager().getTerrain() ^ 0x7EB0A73F1DCE514DL);
|
||||
seaSurfaceDecorator = new IrisSeaSurfaceDecorator(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
int chunkHeight = output.getHeight();
|
||||
IrisData data = getData();
|
||||
IrisDimension dimension = getDimension();
|
||||
IrisComplex complex = getComplex();
|
||||
long baseSeed = getEngine().getSeedManager().getTerrain() ^ FLOATING_BASE_SEED_SALT;
|
||||
FloatingIslandBoundarySampler boundarySampler = context.getFloatingIslandBoundarySampler();
|
||||
FloatingIslandSample.clearChunkMemo();
|
||||
|
||||
for (int xf = 0; xf < 16; xf++) {
|
||||
for (int zf = 0; zf < 16; zf++) {
|
||||
int wx = x + xf;
|
||||
int wz = z + zf;
|
||||
IrisBiome parent = boundarySampler.parent(wx, wz);
|
||||
if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, getEngine(), boundarySampler);
|
||||
if (sample == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long colSeed = FloatingIslandSample.columnSeed(baseSeed, wx, wz);
|
||||
int paletteDepth = Math.max(4, sample.solidCount + 4);
|
||||
IdentityHashMap<IrisFloatingChildBiomes, PaletteContext> paletteContexts = new IdentityHashMap<>();
|
||||
IdentityHashMap<IrisFloatingChildBiomes, Integer> topDepthByEntry = new IdentityHashMap<>();
|
||||
int[] bottomDepths = bottomDepths(sample, chunkHeight);
|
||||
for (int k = sample.topIdx; k >= 0; k--) {
|
||||
if (!sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
IrisFloatingChildBiomes entry = sample.entryAt(k);
|
||||
PaletteContext paletteContext = paletteContexts.get(entry);
|
||||
if (paletteContext == null) {
|
||||
paletteContext = createPaletteContext(parent, entry, dimension, wx, wz, colSeed, paletteDepth, data, complex);
|
||||
paletteContexts.put(entry, paletteContext);
|
||||
}
|
||||
int depth = topDepthByEntry.getOrDefault(entry, 0);
|
||||
int bottomDepth = bottomDepths == null || bottomDepths[k] < 0 ? depth : bottomDepths[k];
|
||||
PlatformBlockState block = selectPaletteBlock(entry, paletteContext.topBlocks, paletteContext.bottomBlocks, depth, bottomDepth, paletteContext.fallbackSolid);
|
||||
if (block != null) {
|
||||
output.set(xf, y, zf, block);
|
||||
}
|
||||
topDepthByEntry.put(entry, depth + 1);
|
||||
}
|
||||
|
||||
IrisFloatingChildBiomes entry = sample.entry;
|
||||
Integer localFluidHeight = entry.getLocalFluidHeight();
|
||||
if (localFluidHeight != null && localFluidHeight > 0) {
|
||||
PlatformBlockState fluid = B.getStateOrNull(entry.getFluidBlock());
|
||||
if (fluid == null) {
|
||||
fluid = B.getState("minecraft:water");
|
||||
}
|
||||
int fluidCap = Math.min(sample.thickness - 1, localFluidHeight);
|
||||
for (int k = 1; k <= fluidCap; k++) {
|
||||
if (sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
boolean hasSolidBelow = false;
|
||||
for (int kb = k - 1; kb >= 0; kb--) {
|
||||
if (sample.solidMask[kb]) {
|
||||
hasSolidBelow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasSolidBelow) {
|
||||
output.set(xf, y, zf, fluid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeIslandSkyBiomes(parent, wx, wz, sample, chunkHeight, data);
|
||||
}
|
||||
}
|
||||
|
||||
getEngine().getMetrics().getTerrain().put(p.getMilliseconds());
|
||||
}
|
||||
|
||||
public void decorateColumns(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
int chunkHeight = output.getHeight();
|
||||
IrisData data = getData();
|
||||
IrisComplex complex = getComplex();
|
||||
long baseSeed = getEngine().getSeedManager().getTerrain() ^ FLOATING_BASE_SEED_SALT;
|
||||
FloatingIslandBoundarySampler boundarySampler = context.getFloatingIslandBoundarySampler();
|
||||
|
||||
for (int xf = 0; xf < 16; xf++) {
|
||||
for (int zf = 0; zf < 16; zf++) {
|
||||
int wx = x + xf;
|
||||
int wz = z + zf;
|
||||
IrisBiome parent = boundarySampler.parent(wx, wz);
|
||||
if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, getEngine(), boundarySampler);
|
||||
if (sample == null) {
|
||||
continue;
|
||||
}
|
||||
IrisFloatingChildBiomes entry = sample.entry;
|
||||
IrisBiome target = entry.getRealBiome(parent, data);
|
||||
|
||||
if (!entry.isInheritDecorators() || target == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int topY = sample.topY();
|
||||
int max = Math.max(1, chunkHeight - topY);
|
||||
if (topY + 1 < chunkHeight) {
|
||||
PlatformBlockState above = output.get(xf, topY + 1, zf);
|
||||
if (above == null || above.isAir()) {
|
||||
try {
|
||||
RNG colRng = rng.nextParallelRNG((int) FloatingIslandSample.columnSeed(baseSeed, wx, wz));
|
||||
FloatingDecorator.decorateColumn(getEngine(), target, IrisDecorationPart.NONE, xf, zf, wx, wz, topY, max, output, colRng, NOOP_DECORATION_MISS);
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Integer localFluidHeight = entry.getLocalFluidHeight();
|
||||
if (localFluidHeight != null && localFluidHeight > 0) {
|
||||
int fluidCap = Math.min(sample.thickness - 1, localFluidHeight);
|
||||
int fluidTopY = -1;
|
||||
for (int k = 1; k <= fluidCap; k++) {
|
||||
if (sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
boolean hasSolidBelow = false;
|
||||
for (int kb = k - 1; kb >= 0; kb--) {
|
||||
if (sample.solidMask[kb]) {
|
||||
hasSolidBelow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasSolidBelow && y > fluidTopY) {
|
||||
fluidTopY = y;
|
||||
}
|
||||
}
|
||||
if (fluidTopY > 0 && fluidTopY + 1 < chunkHeight && B.isAir(output.get(xf, fluidTopY + 1, zf))) {
|
||||
try {
|
||||
seaSurfaceDecorator.decorate(xf, zf, wx, wx + 1, wx - 1, wz, wz + 1, wz - 1, output, target, fluidTopY, chunkHeight);
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeIslandSkyBiomes(IrisBiome parent, int wx, int wz, FloatingIslandSample sample, int chunkHeight, IrisData data) {
|
||||
try {
|
||||
IdentityHashMap<IrisFloatingChildBiomes, MatterBiomeInject> matterByEntry = new IdentityHashMap<>();
|
||||
for (int k = 0; k <= sample.topIdx; k++) {
|
||||
if (!sample.solidMask[k]) {
|
||||
continue;
|
||||
}
|
||||
int y = sample.islandBaseY + k;
|
||||
if (y < 0 || y >= chunkHeight) {
|
||||
continue;
|
||||
}
|
||||
IrisFloatingChildBiomes entry = sample.entryAt(k);
|
||||
MatterBiomeInject matter = matterByEntry.get(entry);
|
||||
if (matter == null) {
|
||||
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data);
|
||||
if (target == null) {
|
||||
continue;
|
||||
}
|
||||
matter = createSkyBiomeMatter(target, wx, wz);
|
||||
matterByEntry.put(entry, matter);
|
||||
}
|
||||
getEngine().getMantle().getMantle().set(wx, y, wz, matter);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private MatterBiomeInject createSkyBiomeMatter(IrisBiome target, int wx, int wz) {
|
||||
if (target.isCustom()) {
|
||||
IrisBiomeCustom custom = target.getCustomBiome(rng, getEngine(), wx, 0, wz);
|
||||
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(getDimension().getLoadKey() + ":" + custom.getId()));
|
||||
}
|
||||
|
||||
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(target.getSkyBiomeKey(rng, getEngine(), wx, 0, wz)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class IrisPerfectionModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
private static final class States {
|
||||
private static final PlatformBlockState AIR = B.getState("AIR");
|
||||
private static final PlatformBlockState WATER = B.getState("WATER");
|
||||
private static final Map<String, PlatformBlockState> ORE_BASES = buildOreBases();
|
||||
}
|
||||
|
||||
public IrisPerfectionModifier(Engine engine) {
|
||||
super(engine, "Perfection");
|
||||
}
|
||||
|
||||
private static Map<String, PlatformBlockState> buildOreBases() {
|
||||
Map<String, PlatformBlockState> map = new HashMap<>();
|
||||
PlatformBlockState stone = B.getState("STONE");
|
||||
PlatformBlockState deepslate = B.getState("DEEPSLATE");
|
||||
PlatformBlockState netherrack = B.getState("NETHERRACK");
|
||||
PlatformBlockState blackstone = B.getState("BLACKSTONE");
|
||||
map.put("minecraft:coal_ore", stone);
|
||||
map.put("minecraft:copper_ore", stone);
|
||||
map.put("minecraft:iron_ore", stone);
|
||||
map.put("minecraft:gold_ore", stone);
|
||||
map.put("minecraft:redstone_ore", stone);
|
||||
map.put("minecraft:lapis_ore", stone);
|
||||
map.put("minecraft:diamond_ore", stone);
|
||||
map.put("minecraft:emerald_ore", stone);
|
||||
map.put("minecraft:deepslate_coal_ore", deepslate);
|
||||
map.put("minecraft:deepslate_copper_ore", deepslate);
|
||||
map.put("minecraft:deepslate_iron_ore", deepslate);
|
||||
map.put("minecraft:deepslate_gold_ore", deepslate);
|
||||
map.put("minecraft:deepslate_redstone_ore", deepslate);
|
||||
map.put("minecraft:deepslate_lapis_ore", deepslate);
|
||||
map.put("minecraft:deepslate_diamond_ore", deepslate);
|
||||
map.put("minecraft:deepslate_emerald_ore", deepslate);
|
||||
map.put("minecraft:nether_gold_ore", netherrack);
|
||||
map.put("minecraft:nether_quartz_ore", netherrack);
|
||||
map.put("minecraft:ancient_debris", netherrack);
|
||||
map.put("minecraft:gilded_blackstone", blackstone);
|
||||
return map;
|
||||
}
|
||||
|
||||
private static String baseKey(PlatformBlockState state) {
|
||||
String key = state.key();
|
||||
int bracket = key.indexOf('[');
|
||||
return bracket < 0 ? key : key.substring(0, bracket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
if (getDimension().isHideOresForHiddenOre()) {
|
||||
hideOres(output, multicore);
|
||||
}
|
||||
AtomicBoolean changed = new AtomicBoolean(true);
|
||||
BurstExecutor burst = burst().burst(multicore);
|
||||
while (changed.get()) {
|
||||
changed.set(false);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int finalI = i;
|
||||
burst.queue(() -> {
|
||||
List<Integer> surfaces = new ArrayList<>();
|
||||
List<Integer> ceilings = new ArrayList<>();
|
||||
for (int j = 0; j < 16; j++) {
|
||||
surfaces.clear();
|
||||
ceilings.clear();
|
||||
int top = getHeight(output, finalI, j);
|
||||
boolean inside = true;
|
||||
surfaces.add(top);
|
||||
|
||||
for (int k = top; k >= 0; k--) {
|
||||
PlatformBlockState b = output.get(finalI, k, j);
|
||||
boolean now = b != null && !(B.isAir(b) || B.isFluid(b));
|
||||
|
||||
if (now != inside) {
|
||||
inside = now;
|
||||
|
||||
if (inside) {
|
||||
surfaces.add(k);
|
||||
} else {
|
||||
ceilings.add(k + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int k : surfaces) {
|
||||
PlatformBlockState tip = output.get(finalI, k, j);
|
||||
|
||||
if (tip == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean remove = false;
|
||||
boolean remove2 = false;
|
||||
|
||||
if (B.isDecorant(tip)) {
|
||||
PlatformBlockState bel = output.get(finalI, k - 1, j);
|
||||
|
||||
if (bel == null) {
|
||||
remove = true;
|
||||
} else if (!B.canPlaceOnto(tip, bel)) {
|
||||
remove = true;
|
||||
} else if (IrisProceduralBlocks.hasProperty(bel, "half")) {
|
||||
PlatformBlockState bb = output.get(finalI, k - 2, j);
|
||||
if (bb == null || !B.canPlaceOnto(bel, bb)) {
|
||||
remove = true;
|
||||
remove2 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
changed.set(true);
|
||||
output.set(finalI, k, j, States.AIR);
|
||||
|
||||
if (remove2) {
|
||||
output.set(finalI, k - 1, j, States.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
burst.complete();
|
||||
}
|
||||
|
||||
getEngine().getMetrics().getPerfection().put(p.getMilliseconds());
|
||||
}
|
||||
|
||||
private void hideOres(Hunk<PlatformBlockState> output, boolean multicore) {
|
||||
BurstExecutor burst = burst().burst(multicore);
|
||||
int height = output.getHeight();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int finalI = i;
|
||||
burst.queue(() -> {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
for (int k = height - 1; k >= 0; k--) {
|
||||
PlatformBlockState block = output.get(finalI, k, j);
|
||||
if (block == null) {
|
||||
continue;
|
||||
}
|
||||
PlatformBlockState base = States.ORE_BASES.get(baseKey(block));
|
||||
if (base != null) {
|
||||
output.set(finalI, k, j, base);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
burst.complete();
|
||||
}
|
||||
|
||||
private int getHeight(Hunk<PlatformBlockState> output, int x, int z) {
|
||||
for (int i = output.getHeight() - 1; i >= 0; i--) {
|
||||
PlatformBlockState b = output.get(x, i, z);
|
||||
|
||||
if (b != null) {
|
||||
if (!B.isAir(b) && !B.isFluid(b)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.engine.object.placement.IrisSlopeClip;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
public class IrisPostModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
private static final class States {
|
||||
private static final PlatformBlockState AIR = B.getState("AIR");
|
||||
}
|
||||
|
||||
private final RNG rng;
|
||||
|
||||
public IrisPostModifier(Engine engine) {
|
||||
super(engine, "Post");
|
||||
rng = new RNG(getEngine().getSeedManager().getPost());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
// The post stage runs sequentially on production (multicore false); an uncontended
|
||||
// monitor per probe is still a monitor times ~10k probes per chunk.
|
||||
Hunk<PlatformBlockState> sync = multicore ? output.synchronize() : output;
|
||||
int width = output.getWidth();
|
||||
int depth = output.getDepth();
|
||||
int planeWidth = width + 2;
|
||||
int[] heights = heightPlane(x, z, width, depth, planeWidth);
|
||||
IrisDimension dimension = getDimension();
|
||||
boolean walls = dimension.isPostProcessingWalls();
|
||||
boolean slabs = dimension.isPostProcessingSlabs();
|
||||
int fluidHeight = dimension.getFluidHeight();
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < depth; j++) {
|
||||
post(i, j, sync, i + x, j + z, context, heights, planeWidth, walls, slabs, fluidHeight);
|
||||
}
|
||||
}
|
||||
|
||||
getEngine().getMetrics().getPost().put(p.getMilliseconds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Every column reads its own height plus its four neighbours, so adjacent columns would otherwise
|
||||
* resolve the same height stream entry up to five times. Resolve the padded plane once instead. The
|
||||
* four diagonal corners are never read, so they are left unresolved.
|
||||
*/
|
||||
private int[] heightPlane(int x, int z, int width, int depth, int planeWidth) {
|
||||
int[] heights = new int[planeWidth * (depth + 2)];
|
||||
EngineMantle mantle = getEngine().getMantle();
|
||||
|
||||
for (int j = -1; j <= depth; j++) {
|
||||
boolean edge = j == -1 || j == depth;
|
||||
int from = edge ? 0 : -1;
|
||||
int to = edge ? width - 1 : width;
|
||||
int row = (j + 1) * planeWidth;
|
||||
|
||||
for (int i = from; i <= to; i++) {
|
||||
heights[row + i + 1] = mantle.trueHeight(x + i, z + j);
|
||||
}
|
||||
}
|
||||
|
||||
return heights;
|
||||
}
|
||||
|
||||
private void post(int currentPostX, int currentPostZ, Hunk<PlatformBlockState> currentData, int x, int z, ChunkContext context, int[] heights, int planeWidth, boolean walls, boolean slabs, int fluidHeight) {
|
||||
// x/z are world coordinates, the hunk is indexed relative to this chunk origin.
|
||||
int originX = x - currentPostX;
|
||||
int originZ = z - currentPostZ;
|
||||
int center = (currentPostZ + 1) * planeWidth + currentPostX + 1;
|
||||
int h = heights[center];
|
||||
int ha = heights[center + 1];
|
||||
int hb = heights[center + planeWidth];
|
||||
int hc = heights[center - 1];
|
||||
int hd = heights[center - planeWidth];
|
||||
|
||||
// Floating Nibs
|
||||
int g = 0;
|
||||
|
||||
if (h < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
g += ha < h - 1 ? 1 : 0;
|
||||
g += hb < h - 1 ? 1 : 0;
|
||||
g += hc < h - 1 ? 1 : 0;
|
||||
g += hd < h - 1 ? 1 : 0;
|
||||
|
||||
if (g == 4 && isAir(x, h - 1, z, originX, originZ, currentData)) {
|
||||
setPostBlock(x, h, z, States.AIR, originX, originZ, currentData);
|
||||
|
||||
for (int i = h - 1; i > 0; i--) {
|
||||
if (!isAir(x, i, z, originX, originZ, currentData)) {
|
||||
h = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nibs
|
||||
g = 0;
|
||||
g += ha == h - 1 ? 1 : 0;
|
||||
g += hb == h - 1 ? 1 : 0;
|
||||
g += hc == h - 1 ? 1 : 0;
|
||||
g += hd == h - 1 ? 1 : 0;
|
||||
|
||||
if (g >= 4) {
|
||||
PlatformBlockState bcState = getPostBlock(x, h, z, originX, originZ, currentData);
|
||||
PlatformBlockState bState = getPostBlock(x, h + 1, z, originX, originZ, currentData);
|
||||
|
||||
if (bState.isOccluding() && bState.isSolid()) {
|
||||
if (bcState.isSolid()) {
|
||||
setPostBlock(x, h, z, bState, originX, originZ, currentData);
|
||||
h--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Potholes
|
||||
g = 0;
|
||||
g += ha == h + 1 ? 1 : 0;
|
||||
g += hb == h + 1 ? 1 : 0;
|
||||
g += hc == h + 1 ? 1 : 0;
|
||||
g += hd == h + 1 ? 1 : 0;
|
||||
|
||||
if (g >= 4) {
|
||||
PlatformBlockState ba = getPostBlock(x, ha, z, originX, originZ, currentData);
|
||||
PlatformBlockState bb = getPostBlock(x, hb, z, originX, originZ, currentData);
|
||||
PlatformBlockState bc = getPostBlock(x, hc, z, originX, originZ, currentData);
|
||||
PlatformBlockState bd = getPostBlock(x, hd, z, originX, originZ, currentData);
|
||||
g = 0;
|
||||
g = B.isSolid(ba) ? g + 1 : g;
|
||||
g = B.isSolid(bb) ? g + 1 : g;
|
||||
g = B.isSolid(bc) ? g + 1 : g;
|
||||
g = B.isSolid(bd) ? g + 1 : g;
|
||||
|
||||
if (g >= 3) {
|
||||
setPostBlock(x, h + 1, z, getPostBlock(x, h, z, originX, originZ, currentData), originX, originZ, currentData);
|
||||
h++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wall Patcher
|
||||
IrisBiome biome = context.getBiome().get(currentPostX, currentPostZ);
|
||||
|
||||
if (walls) {
|
||||
if (!biome.getWall().getPalette().isEmpty()) {
|
||||
if (ha < h - 2 || hb < h - 2 || hc < h - 2 || hd < h - 2) {
|
||||
boolean brokeGround = false;
|
||||
int max = Math.abs(Math.max(h - ha, Math.max(h - hb, Math.max(h - hc, h - hd))));
|
||||
|
||||
for (int i = h; i > h - max; i--) {
|
||||
PlatformBlockState d = biome.getWall().get(rng, x + i, i + h, z + i, getData());
|
||||
|
||||
if (d != null) {
|
||||
if (isAirOrWater(x, i, z, originX, originZ, currentData)) {
|
||||
if (brokeGround) {
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
setPostBlock(x, i, z, d, originX, originZ, currentData);
|
||||
brokeGround = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Slab
|
||||
if (slabs) {
|
||||
//@builder
|
||||
if ((ha == h + 1 && isSolidNonSlab(x + 1, ha, z, originX, originZ, currentData))
|
||||
|| (hb == h + 1 && isSolidNonSlab(x, hb, z + 1, originX, originZ, currentData))
|
||||
|| (hc == h + 1 && isSolidNonSlab(x - 1, hc, z, originX, originZ, currentData))
|
||||
|| (hd == h + 1 && isSolidNonSlab(x, hd, z - 1, originX, originZ, currentData)))
|
||||
//@done
|
||||
{
|
||||
IrisSlopeClip sc = biome.getSlab().getSlopeCondition();
|
||||
PlatformBlockState d = sc.isValid(getComplex().getSlopeStream().get(x, z)) ? biome.getSlab().get(rng, x, h, z, getData()) : null;
|
||||
|
||||
if (d != null) {
|
||||
boolean cancel = B.isAir(d);
|
||||
|
||||
if (IrisProceduralBlocks.materialKey(d).equals("minecraft:snow") && h + 1 <= fluidHeight) {
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (isSnowLayer(x, h, z, originX, originZ, currentData)) {
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (!cancel && isAirOrWater(x, h + 1, z, originX, originZ, currentData)) {
|
||||
setPostBlock(x, h + 1, z, d, originX, originZ, currentData);
|
||||
h++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Waterlogging
|
||||
PlatformBlockState b = getPostBlock(x, h, z, originX, originZ, currentData);
|
||||
|
||||
if (IrisProceduralBlocks.hasProperty(b, "waterlogged")) {
|
||||
boolean w = false;
|
||||
|
||||
if (h <= fluidHeight + 1) {
|
||||
if (isWaterOrWaterlogged(x, h + 1, z, originX, originZ, currentData)) {
|
||||
w = true;
|
||||
} else if ((isWaterOrWaterlogged(x + 1, h, z, originX, originZ, currentData) || isWaterOrWaterlogged(x - 1, h, z, originX, originZ, currentData) || isWaterOrWaterlogged(x, h, z + 1, originX, originZ, currentData) || isWaterOrWaterlogged(x, h, z - 1, originX, originZ, currentData))) {
|
||||
w = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (w != "true".equals(IrisProceduralBlocks.propertyValue(b, "waterlogged"))) {
|
||||
setPostBlock(x, h, z, b.withProperty("waterlogged", String.valueOf(w)), originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
|
||||
// Foliage
|
||||
b = getPostBlock(x, h + 1, z, originX, originZ, currentData);
|
||||
|
||||
if (B.isVineBlock(b)) {
|
||||
PlatformBlockState result = b;
|
||||
int finalH = h + 1;
|
||||
|
||||
for (String face : IrisProceduralBlocks.FACE_PROPERTIES) {
|
||||
if (!IrisProceduralBlocks.hasProperty(b, face)) {
|
||||
continue;
|
||||
}
|
||||
int[] mod = IrisProceduralBlocks.faceOffset(face);
|
||||
PlatformBlockState d = getPostBlock(x + mod[0], finalH + mod[1], z + mod[2], originX, originZ, currentData);
|
||||
result = result.withProperty(face, String.valueOf(!B.isAir(d) && !B.isVineBlock(d)));
|
||||
}
|
||||
if (!result.equals(b)) {
|
||||
setPostBlock(x, h + 1, z, result, originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
|
||||
if (B.isFoliage(b) || IrisProceduralBlocks.materialKey(b).equals("minecraft:dead_bush")) {
|
||||
PlatformBlockState onto = getPostBlock(x, h, z, originX, originZ, currentData);
|
||||
|
||||
if (!B.canPlaceOnto(b, onto) && !B.isDecorant(b)) {
|
||||
setPostBlock(x, h + 1, z, States.AIR, originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAir(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
String material = IrisProceduralBlocks.materialKey(getPostBlock(x, y, z, originX, originZ, currentData));
|
||||
return material.equals("minecraft:air") || material.equals("minecraft:cave_air");
|
||||
}
|
||||
|
||||
public boolean hasGravity(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
String material = IrisProceduralBlocks.materialKey(getPostBlock(x, y, z, originX, originZ, currentData));
|
||||
return material.equals("minecraft:sand") || material.equals("minecraft:red_sand") || material.endsWith("_concrete_powder");
|
||||
}
|
||||
|
||||
public boolean isSolid(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
PlatformBlockState d = getPostBlock(x, y, z, originX, originZ, currentData);
|
||||
return B.isSolid(d) && !B.isVineBlock(d);
|
||||
}
|
||||
|
||||
public boolean isSolidNonSlab(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
PlatformBlockState d = getPostBlock(x, y, z, originX, originZ, currentData);
|
||||
return B.isSolid(d) && !IrisProceduralBlocks.materialKey(d).endsWith("_slab");
|
||||
}
|
||||
|
||||
public boolean isAirOrWater(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
String material = IrisProceduralBlocks.materialKey(getPostBlock(x, y, z, originX, originZ, currentData));
|
||||
return material.equals("minecraft:water") || material.equals("minecraft:air") || material.equals("minecraft:cave_air");
|
||||
}
|
||||
|
||||
public boolean isSlab(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
return IrisProceduralBlocks.materialKey(getPostBlock(x, y, z, originX, originZ, currentData)).endsWith("_slab");
|
||||
}
|
||||
|
||||
public boolean isSnowLayer(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
return IrisProceduralBlocks.materialKey(getPostBlock(x, y, z, originX, originZ, currentData)).equals("minecraft:snow");
|
||||
}
|
||||
|
||||
public boolean isWater(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
return IrisProceduralBlocks.materialKey(getPostBlock(x, y, z, originX, originZ, currentData)).equals("minecraft:water");
|
||||
}
|
||||
|
||||
public boolean isWaterOrWaterlogged(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
PlatformBlockState d = getPostBlock(x, y, z, originX, originZ, currentData);
|
||||
return IrisProceduralBlocks.materialKey(d).equals("minecraft:water") || "true".equals(IrisProceduralBlocks.propertyValue(d, "waterlogged"));
|
||||
}
|
||||
|
||||
public boolean isLiquid(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
return IrisProceduralBlocks.hasProperty(getPostBlock(x, y, z, originX, originZ, currentData), "level");
|
||||
}
|
||||
|
||||
public void setPostBlock(int x, int y, int z, PlatformBlockState d, int originX, int originZ, Hunk<PlatformBlockState> currentData) {
|
||||
int lx = x - originX;
|
||||
int lz = z - originZ;
|
||||
|
||||
if (lx < 0 || lz < 0 || lx >= currentData.getWidth() || lz >= currentData.getDepth() || y < 0 || y >= currentData.getHeight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentData.set(lx, y, lz, d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Neighbour columns can sit one block outside this chunk, and the blocks of an adjacent chunk are not
|
||||
* available while generating this one. Resolve the hunk index relative to the chunk origin and let
|
||||
* getClosest clamp to the nearest in-chunk column instead of wrapping to the opposite chunk edge.
|
||||
*/
|
||||
public PlatformBlockState getPostBlock(int x, int y, int z, int originX, int originZ, Hunk<PlatformBlockState> h) {
|
||||
PlatformBlockState b = h.getClosest(x - originX, y, z - originZ);
|
||||
|
||||
return b == null ? States.AIR : b;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user