mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +00:00
basic framework
This commit is contained in:
@@ -91,6 +91,10 @@ public final class MathUtil {
|
||||
return Math.sqrt(((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1)));
|
||||
}
|
||||
|
||||
public static int normalizeIndex(double val, int size) {
|
||||
return FastMath.max(FastMath.min(FastMath.floorToInt(((val + 1D) / 2D) * size), size - 1), 0);
|
||||
}
|
||||
|
||||
public static long squash(int first, int last) {
|
||||
return (((long) first) << 32) | (last & 0xffffffffL);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.api.math;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
@@ -29,24 +28,14 @@ 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)];
|
||||
return (E) array[MathUtil.normalizeIndex(n.getNoise(x, y, z), array.length)];
|
||||
}
|
||||
|
||||
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)];
|
||||
return (E) array[MathUtil.normalizeIndex(n.getNoise(x, z), array.length)];
|
||||
}
|
||||
|
||||
public int getTotalProbability() {
|
||||
|
||||
@@ -22,4 +22,6 @@ public interface Biome {
|
||||
* @return BiomeTerrain - The terrain generation instance.
|
||||
*/
|
||||
Generator getGenerator(World w);
|
||||
|
||||
int getColor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user