mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-02 16:05:29 +00:00
allow configuration of 2d/3d noise in palettes
This commit is contained in:
parent
623a4dea4f
commit
8a10a9807d
@ -29,11 +29,21 @@ public class ProbabilityCollection<E> {
|
||||
return (E) array[r.nextInt(array.length)];
|
||||
}
|
||||
|
||||
private static double getNoise(double x, double y, double z, NoiseSampler sampler) {
|
||||
double n = sampler.getNoise(x, y, z);
|
||||
return FastMath.min(FastMath.max(n, -1), 1);
|
||||
}
|
||||
|
||||
private static double getNoise(double x, double z, NoiseSampler sampler) {
|
||||
double n = sampler.getNoise(x, z);
|
||||
return FastMath.min(FastMath.max(n, -1), 1);
|
||||
}
|
||||
|
||||
public E get(NoiseSampler n, double x, double y, double z) {
|
||||
if(array.length == 0) return null;
|
||||
return (E) array[FastMath.min(FastMath.floorToInt(((getNoise(x, y, z, n) + 1D) / 2D) * array.length), array.length - 1)];
|
||||
}
|
||||
|
||||
public E get(NoiseSampler n, double x, double z) {
|
||||
if(array.length == 0) return null;
|
||||
return (E) array[FastMath.min(FastMath.floorToInt(((getNoise(x, z, n) + 1D) / 2D) * array.length), array.length - 1)];
|
||||
|
@ -6,16 +6,18 @@ import java.util.List;
|
||||
|
||||
public class NoisePalette<E> extends Palette<E> {
|
||||
private final NoiseSampler r;
|
||||
private final boolean is2D;
|
||||
|
||||
public NoisePalette(NoiseSampler r) {
|
||||
public NoisePalette(NoiseSampler r, boolean is2D) {
|
||||
this.r = r;
|
||||
this.is2D = is2D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int layer, int x, int z) {
|
||||
if(layer > this.getSize()) return this.getLayers().get(this.getLayers().size() - 1).get(r, x, z);
|
||||
public E get(int layer, double x, double y, double z) {
|
||||
if(layer > this.getSize()) return this.getLayers().get(this.getLayers().size() - 1).get(r, x, y, z, is2D);
|
||||
List<PaletteLayer<E>> pl = getLayers();
|
||||
if(layer >= pl.size()) return pl.get(pl.size() - 1).get(r, x, z);
|
||||
return pl.get(layer).get(r, x, z);
|
||||
if(layer >= pl.size()) return pl.get(pl.size() - 1).get(r, x, y, z, is2D);
|
||||
return pl.get(layer).get(r, x, y, z, is2D);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public abstract class Palette<E> {
|
||||
* @param layer - The layer at which to fetch the material.
|
||||
* @return BlockData - The material fetched.
|
||||
*/
|
||||
public abstract E get(int layer, int x, int z);
|
||||
public abstract E get(int layer, double x, double y, double z);
|
||||
|
||||
|
||||
public int getSize() {
|
||||
@ -104,8 +104,9 @@ public abstract class Palette<E> {
|
||||
return m;
|
||||
}
|
||||
|
||||
public E get(NoiseSampler random, int x, int z) {
|
||||
if(col) return this.collection.get(random, x, z);
|
||||
public E get(NoiseSampler random, double x, double y, double z, boolean is2D) {
|
||||
if(col && is2D) return this.collection.get(random, x, z);
|
||||
else if(col) return this.collection.get(random, x, y, z);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class RandomPalette<E> extends Palette<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int layer, int x, int z) {
|
||||
public E get(int layer, double x, double y, double z) {
|
||||
if(layer > this.getSize()) return this.getLayers().get(this.getLayers().size() - 1).get(r);
|
||||
List<PaletteLayer<E>> pl = getLayers();
|
||||
if(layer >= pl.size()) return pl.get(pl.size() - 1).get(r);
|
||||
|
@ -10,7 +10,7 @@ public class SinglePalette<E> extends Palette<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int i, int i1, int i2) {
|
||||
public E get(int layer, double x, double y, double z) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
public class PaletteFactory implements TerraFactory<PaletteTemplate, Palette<BlockData>> {
|
||||
@Override
|
||||
public Palette<BlockData> build(PaletteTemplate config, TerraPlugin main) {
|
||||
Palette<BlockData> palette = new NoisePalette<>(config.getNoise().build(2403));
|
||||
Palette<BlockData> palette = new NoisePalette<>(config.getNoise().build(2403), config.getNoise().getDimensions() == 2);
|
||||
for(PaletteLayer layer : config.getPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize());
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class PaletteTemplate extends AbstractableTemplate {
|
||||
|
||||
public PaletteTemplate() {
|
||||
noise.setType(FastNoiseLite.NoiseType.WhiteNoise);
|
||||
noise.setDimensions(3);
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
|
@ -114,7 +114,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
|
||||
if(sampler.sample(x, y, z) > 0) {
|
||||
justSet = true;
|
||||
data = PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel, cx, cz);
|
||||
data = PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel, cx, y, cz);
|
||||
chunk.setBlock(x, y, z, data);
|
||||
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
|
||||
prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector3(x, y + 1, z), c.getSlabPalettes(),
|
||||
@ -122,7 +122,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
}
|
||||
paletteLevel++;
|
||||
} else if(y <= sea) {
|
||||
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
|
||||
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, y, z + zOrig));
|
||||
if(justSet && c.doSlabs()) {
|
||||
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
|
||||
}
|
||||
@ -144,18 +144,18 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
|
||||
private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
|
||||
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
|
||||
if(sampler.sample(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
|
||||
if(sampler.sample(block.getX(), block.getY() - 0.4, block.getZ()) > thresh) {
|
||||
if(stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
||||
if(stairPalette != null) {
|
||||
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()).clone();
|
||||
BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
|
||||
if(stair instanceof Stairs) {
|
||||
Stairs stairNew = (Stairs) stair;
|
||||
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockData slab = slabs.getOrDefault(down.getMaterial(), blank).get(0, block.getBlockX(), block.getBlockZ());
|
||||
BlockData slab = slabs.getOrDefault(down.getMaterial(), blank).get(0, block.getX(), block.getY(), block.getZ());
|
||||
if(slab instanceof Waterlogged) {
|
||||
((Waterlogged) slab).setWaterlogged(orig.matches(water));
|
||||
} else if(orig.matches(water)) return;
|
||||
@ -165,11 +165,11 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
|
||||
private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
|
||||
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
|
||||
if(sampler.sample(block.getBlockX(), block.getBlockY() + 0.4, block.getBlockZ()) > thresh) {
|
||||
if(sampler.sample(block.getX(), block.getY() + 0.4, block.getZ()) > thresh) {
|
||||
if(stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
|
||||
if(stairPalette != null) {
|
||||
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()).clone();
|
||||
BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
|
||||
if(stair instanceof Stairs) {
|
||||
Stairs stairNew = (Stairs) stair.clone();
|
||||
stairNew.setHalf(Bisected.Half.TOP);
|
||||
@ -177,7 +177,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockData slab = slabs.getOrDefault(up.getMaterial(), blank).get(0, block.getBlockX(), block.getBlockZ()).clone();
|
||||
BlockData slab = slabs.getOrDefault(up.getMaterial(), blank).get(0, block.getX(), block.getY(), block.getZ()).clone();
|
||||
if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
|
||||
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
|
||||
if(slab instanceof Waterlogged) {
|
||||
@ -189,14 +189,14 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
|
||||
private boolean placeStair(BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, double thresh, Sampler sampler, Stairs stairNew) {
|
||||
|
||||
if(sampler.sample(block.getBlockX() - 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
|
||||
if(sampler.sample(block.getBlockX() - 0.55, block.getY(), block.getZ()) > thresh) {
|
||||
|
||||
stairNew.setFacing(BlockFace.WEST);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.55) > thresh) {
|
||||
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() - 0.55) > thresh) {
|
||||
stairNew.setFacing(BlockFace.NORTH);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.55) > thresh) {
|
||||
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() + 0.55) > thresh) {
|
||||
stairNew.setFacing(BlockFace.SOUTH);
|
||||
} else if(sampler.sample(block.getBlockX() + 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
|
||||
} else if(sampler.sample(block.getX() + 0.55, block.getY(), block.getZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.EAST);
|
||||
} else stairNew = null;
|
||||
if(stairNew != null) {
|
||||
|
@ -106,7 +106,7 @@ public class TerraFlora implements Flora {
|
||||
|
||||
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (FastMath.abs(i));
|
||||
BlockData data = floraPalette.get((ceiling ? lvl : size - lvl - 1), location.getBlockX(), location.getBlockZ()).clone();
|
||||
BlockData data = floraPalette.get((ceiling ? lvl : size - lvl - 1), location.getX(), location.getY(), location.getZ()).clone();
|
||||
if(doRotation) {
|
||||
if(data instanceof Directional) {
|
||||
((Directional) data).setFacing(oneFace);
|
||||
|
Loading…
x
Reference in New Issue
Block a user