mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
remove other assumptions that world bottom is y=0
This commit is contained in:
@@ -15,7 +15,7 @@ public class BufferedPulledBlock implements BufferedItem {
|
||||
@Override
|
||||
public void paste(Location origin) {
|
||||
Block pos = origin.getBlock();
|
||||
while(pos.getY() > 0) {
|
||||
while(pos.getY() > origin.getWorld().getMinHeight()) {
|
||||
if(!pos.isEmpty()) {
|
||||
pos.setBlockData(data, false);
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.api.world.carving;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -85,7 +86,7 @@ public abstract class Worm {
|
||||
return rad[index];
|
||||
}
|
||||
|
||||
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer) {
|
||||
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer, World world) {
|
||||
int xRad = getRadius(0);
|
||||
int yRad = getRadius(1);
|
||||
int zRad = getRadius(2);
|
||||
@@ -97,7 +98,7 @@ public abstract class Worm {
|
||||
if(!(FastMath.floorDiv(origin.getBlockZ() + z, 16) == chunkZ)) continue;
|
||||
for(int y = -yRad - 1; y <= yRad + 1; y++) {
|
||||
Vector3 position = origin.clone().add(new Vector3(x, y, z));
|
||||
if(position.getY() < 0 || position.getY() > 255) continue;
|
||||
if(position.getY() < world.getMinHeight() || position.getY() > 255) continue;
|
||||
double eq = ellipseEquation(x, y, z, xRad, yRad, zRad);
|
||||
if(eq <= 1 &&
|
||||
y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) {
|
||||
|
||||
@@ -14,6 +14,10 @@ public class PaletteHolder {
|
||||
|
||||
public Palette<BlockData> getPalette(int y) {
|
||||
int index = y + offset;
|
||||
return index >= 0 ? palettes[index] : palettes[0];
|
||||
return index >= 0
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,10 @@ public class PaletteHolderBuilder {
|
||||
public PaletteHolder build() {
|
||||
|
||||
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette<BlockData> d = null;
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -41,13 +42,13 @@ public class CarverCache {
|
||||
carving.step();
|
||||
TerraBiome biome = provider.getBiome(carving.getRunning().toLocation(w));
|
||||
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(CarverCache.this.carver)) { // Stop if we enter a biome this carver is not present in
|
||||
return new GlueList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
points.add(carving.getPoint());
|
||||
}
|
||||
return points;
|
||||
}
|
||||
return new GlueList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -14,6 +15,7 @@ public class CarverPalette {
|
||||
private final MaterialSet replace;
|
||||
private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>();
|
||||
private ProbabilityCollection<BlockData>[] layers;
|
||||
private int offset = 0;
|
||||
|
||||
public CarverPalette(MaterialSet replaceable, boolean blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
@@ -26,7 +28,12 @@ public class CarverPalette {
|
||||
}
|
||||
|
||||
public ProbabilityCollection<BlockData> get(int y) {
|
||||
return layers[y];
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < layers.length
|
||||
? layers[index]
|
||||
: layers[layers.length - 1]
|
||||
: layers[0];
|
||||
}
|
||||
|
||||
public boolean canReplace(BlockType material) {
|
||||
@@ -37,9 +44,11 @@ public class CarverPalette {
|
||||
* Build the palette to an array.
|
||||
*/
|
||||
public void build() {
|
||||
int size = map.lastKey() + 1;
|
||||
layers = new ProbabilityCollection[size];
|
||||
for(int y = 0; y < size; y++) {
|
||||
int min = FastMath.min(map.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(map.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
layers = new ProbabilityCollection[map.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(map.lastKey(), max); y++) {
|
||||
ProbabilityCollection<BlockData> d = null;
|
||||
for(Map.Entry<Integer, ProbabilityCollection<BlockData>> e : map.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
@@ -47,8 +56,9 @@ public class CarverPalette {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d == null) throw new IllegalArgumentException("Null collection at Y=" + y);
|
||||
layers[y] = d;
|
||||
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
|
||||
layers[y - min] = d;
|
||||
}
|
||||
offset = -min;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class UserDefinedCarver extends Carver {
|
||||
Vector3 origin = point.getOrigin();
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk.
|
||||
return;
|
||||
point.carve(chunkX, chunkZ, consumer);
|
||||
point.carve(chunkX, chunkZ, consumer, w);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class CavePopulator implements TerraBlockPopulator {
|
||||
Location mut = l.clone();
|
||||
BlockData orig = l.getBlock().getBlockData();
|
||||
do mut.subtract(0, 1, 0);
|
||||
while(mut.getY() > 0 && mut.getBlock().getBlockData().matches(orig));
|
||||
while(mut.getY() > world.getMinHeight() && mut.getBlock().getBlockData().matches(orig));
|
||||
try {
|
||||
if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) {
|
||||
mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
|
||||
|
||||
Reference in New Issue
Block a user