mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
allow configuration of 2d/3d noise in palettes
This commit is contained in:
@@ -29,11 +29,21 @@ public class ProbabilityCollection<E> {
|
|||||||
return (E) array[r.nextInt(array.length)];
|
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) {
|
private static double getNoise(double x, double z, NoiseSampler sampler) {
|
||||||
double n = sampler.getNoise(x, z);
|
double n = sampler.getNoise(x, z);
|
||||||
return FastMath.min(FastMath.max(n, -1), 1);
|
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) {
|
public E get(NoiseSampler n, double x, double z) {
|
||||||
if(array.length == 0) return null;
|
if(array.length == 0) return null;
|
||||||
return (E) array[FastMath.min(FastMath.floorToInt(((getNoise(x, z, n) + 1D) / 2D) * array.length), array.length - 1)];
|
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> {
|
public class NoisePalette<E> extends Palette<E> {
|
||||||
private final NoiseSampler r;
|
private final NoiseSampler r;
|
||||||
|
private final boolean is2D;
|
||||||
|
|
||||||
public NoisePalette(NoiseSampler r) {
|
public NoisePalette(NoiseSampler r, boolean is2D) {
|
||||||
this.r = r;
|
this.r = r;
|
||||||
|
this.is2D = is2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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, x, z);
|
if(layer > this.getSize()) return this.getLayers().get(this.getLayers().size() - 1).get(r, x, y, z, is2D);
|
||||||
List<PaletteLayer<E>> pl = getLayers();
|
List<PaletteLayer<E>> pl = getLayers();
|
||||||
if(layer >= pl.size()) return pl.get(pl.size() - 1).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, z);
|
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.
|
* @param layer - The layer at which to fetch the material.
|
||||||
* @return BlockData - The material fetched.
|
* @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() {
|
public int getSize() {
|
||||||
@@ -104,8 +104,9 @@ public abstract class Palette<E> {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public E get(NoiseSampler random, int x, int z) {
|
public E get(NoiseSampler random, double x, double y, double z, boolean is2D) {
|
||||||
if(col) return this.collection.get(random, x, z);
|
if(col && is2D) return this.collection.get(random, x, z);
|
||||||
|
else if(col) return this.collection.get(random, x, y, z);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class RandomPalette<E> extends Palette<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
if(layer > this.getSize()) return this.getLayers().get(this.getLayers().size() - 1).get(r);
|
||||||
List<PaletteLayer<E>> pl = getLayers();
|
List<PaletteLayer<E>> pl = getLayers();
|
||||||
if(layer >= pl.size()) return pl.get(pl.size() - 1).get(r);
|
if(layer >= pl.size()) return pl.get(pl.size() - 1).get(r);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class SinglePalette<E> extends Palette<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public E get(int i, int i1, int i2) {
|
public E get(int layer, double x, double y, double z) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import com.dfsek.terra.config.templates.PaletteTemplate;
|
|||||||
public class PaletteFactory implements TerraFactory<PaletteTemplate, Palette<BlockData>> {
|
public class PaletteFactory implements TerraFactory<PaletteTemplate, Palette<BlockData>> {
|
||||||
@Override
|
@Override
|
||||||
public Palette<BlockData> build(PaletteTemplate config, TerraPlugin main) {
|
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()) {
|
for(PaletteLayer layer : config.getPalette()) {
|
||||||
palette.add(layer.getLayer(), layer.getSize());
|
palette.add(layer.getLayer(), layer.getSize());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class PaletteTemplate extends AbstractableTemplate {
|
|||||||
|
|
||||||
public PaletteTemplate() {
|
public PaletteTemplate() {
|
||||||
noise.setType(FastNoiseLite.NoiseType.WhiteNoise);
|
noise.setType(FastNoiseLite.NoiseType.WhiteNoise);
|
||||||
|
noise.setDimensions(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
|||||||
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
|
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
|
||||||
if(sampler.sample(x, y, z) > 0) {
|
if(sampler.sample(x, y, z) > 0) {
|
||||||
justSet = true;
|
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);
|
chunk.setBlock(x, y, z, data);
|
||||||
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
|
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
|
||||||
prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector3(x, y + 1, z), c.getSlabPalettes(),
|
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++;
|
paletteLevel++;
|
||||||
} else if(y <= sea) {
|
} 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()) {
|
if(justSet && c.doSlabs()) {
|
||||||
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
|
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,
|
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) {
|
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) {
|
if(stairs != null) {
|
||||||
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
||||||
if(stairPalette != null) {
|
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) {
|
if(stair instanceof Stairs) {
|
||||||
Stairs stairNew = (Stairs) stair;
|
Stairs stairNew = (Stairs) stair;
|
||||||
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
|
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) {
|
if(slab instanceof Waterlogged) {
|
||||||
((Waterlogged) slab).setWaterlogged(orig.matches(water));
|
((Waterlogged) slab).setWaterlogged(orig.matches(water));
|
||||||
} else if(orig.matches(water)) return;
|
} 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,
|
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) {
|
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) {
|
if(stairs != null) {
|
||||||
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
|
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
|
||||||
if(stairPalette != null) {
|
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) {
|
if(stair instanceof Stairs) {
|
||||||
Stairs stairNew = (Stairs) stair.clone();
|
Stairs stairNew = (Stairs) stair.clone();
|
||||||
stairNew.setHalf(Bisected.Half.TOP);
|
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 Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
|
||||||
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
|
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
|
||||||
if(slab instanceof Waterlogged) {
|
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) {
|
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);
|
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);
|
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);
|
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);
|
stairNew.setFacing(BlockFace.EAST);
|
||||||
} else stairNew = null;
|
} else stairNew = null;
|
||||||
if(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
|
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||||
int lvl = (FastMath.abs(i));
|
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(doRotation) {
|
||||||
if(data instanceof Directional) {
|
if(data instanceof Directional) {
|
||||||
((Directional) data).setFacing(oneFace);
|
((Directional) data).setFacing(oneFace);
|
||||||
|
|||||||
Reference in New Issue
Block a user