add biome specific vars

This commit is contained in:
dfsek 2021-01-27 00:37:30 -07:00
parent f6967be95f
commit dfec463765
2 changed files with 21 additions and 0 deletions

View File

@ -48,12 +48,16 @@ public class GeneratorBuilder {
private double blendWeight;
private Map<String, Double> variables = new HashMap<>();
public WorldGenerator build(long seed) {
synchronized(gens) {
return gens.computeIfAbsent(seed, k -> {
NoiseSampler noise;
NoiseSampler elevation;
NoiseSampler carving;
Scope biomeScope = new Scope().withParent(varScope);
variables.forEach((id, val) -> biomeScope.create(id).setValue(val));
try {
noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap);
elevation = elevationEquation == null ? new ConstantSampler(0) : new ExpressionSampler(elevationEquation, varScope, seed, noiseBuilderMap);
@ -66,6 +70,10 @@ public class GeneratorBuilder {
}
}
public void setVariables(Map<String, Double> variables) {
this.variables = variables;
}
public void setBlendWeight(double blendWeight) {
this.blendWeight = blendWeight;
}

View File

@ -26,6 +26,7 @@ import parsii.eval.Parser;
import parsii.eval.Scope;
import parsii.tokenizer.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -42,6 +43,11 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Default
private String extend = null;
@Value("variables")
@Abstractable
@Default
private Map<String, Double> variables = new HashMap<>();
@Value("carving.equation")
@Abstractable
@Default
@ -308,11 +314,18 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
return blendStep;
}
public Map<String, Double> getVariables() {
return variables;
}
@Override
public boolean validate() throws ValidationException {
color |= 0x1fe00000; // Alpha adjustment
Parser tester = new Parser();
Scope testScope = new Scope().withParent(pack.getVarScope());
variables.forEach((id, val) -> testScope.create(id).setValue(val));
testScope.create("x");
testScope.create("y");
testScope.create("z");