mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 04:38:35 +00:00
Implement more noise patterns
This commit is contained in:
@ -0,0 +1,34 @@
|
||||
package com.boydti.fawe.object.random;
|
||||
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.noise.NoiseGenerator;
|
||||
|
||||
public class NoiseRandom implements SimpleRandom {
|
||||
|
||||
private final NoiseGenerator generator;
|
||||
private final double scale;
|
||||
|
||||
/**
|
||||
* Create a new NoiseRandom instance using a specific {@link NoiseGenerator} and a scale.
|
||||
*
|
||||
* @param generator The generator to use for the noise
|
||||
* @param scale The scale of the noise
|
||||
*/
|
||||
public NoiseRandom(NoiseGenerator generator, double scale) {
|
||||
this.generator = generator;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble(int x, int y, int z) {
|
||||
return cap(this.generator.noise(Vector3.at(x, y, z).multiply(this.scale)));
|
||||
}
|
||||
|
||||
// workaround for noise generators returning [0, 1]
|
||||
private double cap(double d) {
|
||||
if (d >= 1.0) {
|
||||
return 0x1.fffffffffffffp-1; // very close to 1 but less
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
@ -2,10 +2,29 @@ package com.boydti.fawe.object.random;
|
||||
|
||||
public interface SimpleRandom {
|
||||
|
||||
/**
|
||||
* Generate a random double from three integer components.
|
||||
* The generated value is between 0 (inclusive) and 1 (exclusive).
|
||||
*
|
||||
* @param x the first component
|
||||
* @param y the second component
|
||||
* @param z the third component
|
||||
* @return a double between 0 (inclusive) and 1 (exclusive)
|
||||
*/
|
||||
double nextDouble(int x, int y, int z);
|
||||
|
||||
default int nextInt(int x, int y, int z, int len) {
|
||||
/**
|
||||
* Generate a random integer from three integer components.
|
||||
* The generated value is between 0 (inclusive) and 1 (exclusive)
|
||||
*
|
||||
* @param x the first component
|
||||
* @param y the second component
|
||||
* @param z the third component
|
||||
* @param bound the upper bound (exclusive)
|
||||
* @return a random integer between 0 (inclusive) and {@code bound} (exclusive)
|
||||
*/
|
||||
default int nextInt(int x, int y, int z, int bound) {
|
||||
double val = nextDouble(x, y, z);
|
||||
return (int) (val * len);
|
||||
return (int) (val * bound);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package com.boydti.fawe.object.random;
|
||||
|
||||
public class SimplexRandom implements SimpleRandom {
|
||||
private final double scale;
|
||||
|
||||
public SimplexRandom(double scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble(int x, int y, int z) {
|
||||
return (SimplexNoise.noise(x * scale, y * scale, z * scale) + 1) * 0.5;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user