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