remove assumption that world starts at Y=0

This commit is contained in:
dfsek 2021-02-24 19:48:43 -07:00
parent dd446b3034
commit 4a47815be7
11 changed files with 51 additions and 58 deletions

View File

@ -32,4 +32,6 @@ public interface World extends Handle {
Block getBlockAt(Location l);
Entity spawnEntity(Location location, EntityType entityType);
int getMinHeight();
}

View File

@ -39,7 +39,7 @@ public class UserDefinedCarver extends Carver {
private final Expression yRad;
private final Expression zRad;
private final Map<World, CarverCache> cacheMap = new ConcurrentHashMap<>();
private final Map<Long, CarverCache> cacheMap = new ConcurrentHashMap<>();
private final TerraPlugin main;
private double step = 2;
private Range recalc = new Range(8, 10);
@ -108,7 +108,7 @@ public class UserDefinedCarver extends Carver {
@Override
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector3, CarvingType> consumer) {
synchronized(cacheMap) {
CarverCache cache = cacheMap.computeIfAbsent(w, world -> new CarverCache(world, main, this));
CarverCache cache = cacheMap.computeIfAbsent(w.getSeed(), world -> new CarverCache(w, main, this));
int carvingRadius = getCarvingRadius();
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {

View File

@ -116,7 +116,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
boolean justSet = false;
BlockData data = null;
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
for(int y = world.getMaxHeight() - 1; y >= world.getMinHeight(); y--) {
if(sampler.sample(x, y, z) > 0) {
justSet = true;
data = PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel, cx, y, cz);

View File

@ -16,9 +16,12 @@ import java.util.function.BiFunction;
* Contains method to get interpolated noise at a coordinate within the chunk.
*/
public class ChunkInterpolator3D implements ChunkInterpolator {
private final Interpolator3[][][] interpGrid = new Interpolator3[4][64][4];
private final Interpolator3[][][] interpGrid;
private final BiFunction<Generator, Vector3, Double> noiseGetter;
private final int min;
private final int max;
/**
* Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates.
*
@ -31,7 +34,15 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
int xOrigin = chunkX << 4;
int zOrigin = chunkZ << 4;
double[][][] noiseStorage = new double[5][5][65];
this.max = w.getMaxHeight();
this.min = w.getMinHeight();
int range = max - min + 1;
int size = range >> 2;
interpGrid = new Interpolator3[4][size][4];
double[][][] noiseStorage = new double[5][5][size + 1];
for(int x = 0; x < 5; x++) {
for(int z = 0; z < 5; z++) {
@ -47,7 +58,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
}
}
for(int y = 0; y < 65; y++) {
for(int y = 0; y < size + 1; y++) {
noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin);
}
}
@ -55,7 +66,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
for(int y = 0; y < 64; y++) {
for(int y = 0; y < size; y++) {
interpGrid[x][y][z] = new Interpolator3(
noiseStorage[x][z][y],
noiseStorage[x + 1][z][y],
@ -87,6 +98,6 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
*/
@Override
public double getNoise(double x, double y, double z) {
return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) y) / 4, 63)][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
}
}

View File

@ -77,6 +77,11 @@ public class BukkitWorld implements World {
return new BukkitEntity(delegate.spawnEntity(BukkitAdapter.adapt(location), ((BukkitEntityType) entityType).getHandle()));
}
@Override
public int getMinHeight() {
return 0;
}
@Override
public org.bukkit.World getHandle() {
return delegate;

View File

@ -1,50 +0,0 @@
package com.dfsek.terra.fabric.world.block.state;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.state.BlockState;
import com.dfsek.terra.fabric.world.block.FabricBlock;
public class FabricBlankBlockState implements BlockState {
private final FabricBlock delegate;
public FabricBlankBlockState(FabricBlock delegate) {
this.delegate = delegate;
}
@Override
public Block getHandle() {
return delegate;
}
@Override
public Block getBlock() {
return delegate;
}
@Override
public int getX() {
return delegate.getX();
}
@Override
public int getY() {
return delegate.getY();
}
@Override
public int getZ() {
return delegate.getZ();
}
@Override
public BlockData getBlockData() {
return delegate.getBlockData();
}
@Override
public boolean update(boolean applyPhysics) {
return true;
}
}

View File

@ -93,6 +93,11 @@ public class FabricWorld implements World, FabricWorldHandle {
return null;
}
@Override
public int getMinHeight() {
return 0;
}
@Override
public Handle getHandle() {
return null;

View File

@ -80,6 +80,11 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle {
return null;
}
@Override
public int getMinHeight() {
return 0;
}
@Override
public int hashCode() {
return ((ServerWorldAccess) handle.worldAccess).toServerWorld().hashCode();

View File

@ -80,6 +80,11 @@ public class FabricWorldAccess implements World, FabricWorldHandle {
return null;
}
@Override
public int getMinHeight() {
return 0;
}
@Override
public WorldAccess getHandle() {
return delegate;

View File

@ -91,6 +91,11 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle {
return null;
}
@Override
public int getMinHeight() {
return 0;
}
@Override
public Object getHandle() {
return delegate;

View File

@ -92,6 +92,11 @@ public class DirectWorld implements World {
return null;
}
@Override
public int getMinHeight() {
return 0;
}
@Override
public Object getHandle() {
return generator;