mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +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)];
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user