mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
Add RandomFunction and seed variable
This commit is contained in:
parent
4ddb3a294e
commit
b43b9ee7b9
Binary file not shown.
@ -3,6 +3,7 @@ package com.dfsek.terra.generation.config;
|
||||
import com.dfsek.terra.config.genconfig.noise.NoiseConfig;
|
||||
import com.dfsek.terra.math.NoiseFunction2;
|
||||
import com.dfsek.terra.math.NoiseFunction3;
|
||||
import com.dfsek.terra.math.RandomFunction;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.biome.Generator;
|
||||
@ -36,12 +37,15 @@ public class WorldGenerator extends Generator {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map<String, NoiseConfig> noiseBuilders, Palette[] palettes, Palette[] slantPalettes, boolean preventSmooth) {
|
||||
Parser p = new Parser();
|
||||
p.registerFunction("rand", new RandomFunction());
|
||||
Parser ep = new Parser();
|
||||
ep.registerFunction("rand", new RandomFunction());
|
||||
|
||||
Scope s = new Scope().withParent(vScope);
|
||||
xVar = s.create("x");
|
||||
yVar = s.create("y");
|
||||
zVar = s.create("z");
|
||||
s.create("seed").setValue(seed);
|
||||
|
||||
this.preventSmooth = preventSmooth;
|
||||
|
||||
@ -63,6 +67,7 @@ public class WorldGenerator extends Generator {
|
||||
this.noiseExp = p.parse(equation, s).simplify();
|
||||
if(elevateEquation != null) {
|
||||
Scope es = new Scope().withParent(vScope);
|
||||
es.create("seed").setValue(seed);
|
||||
this.elevationXVar = es.create("x");
|
||||
this.elevationZVar = es.create("z");
|
||||
this.elevationExp = ep.parse(elevateEquation, es).simplify();
|
||||
|
30
src/main/java/com/dfsek/terra/math/RandomFunction.java
Normal file
30
src/main/java/com/dfsek/terra/math/RandomFunction.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.math;
|
||||
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
import parsii.eval.Expression;
|
||||
import parsii.eval.Function;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides access to a PRNG ({@link org.polydev.gaea.util.FastRandom})
|
||||
* <p>
|
||||
* Takes 1 argument, which sets the seed
|
||||
*/
|
||||
public class RandomFunction implements Function {
|
||||
@Override
|
||||
public int getNumberOfArguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(List<Expression> list) {
|
||||
long seed = (long) list.get(0).evaluate();
|
||||
return new FastRandom(seed).nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaturalFunction() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user