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 double blendWeight;
private Map<String, Double> variables = new HashMap<>();
public WorldGenerator build(long seed) { public WorldGenerator build(long seed) {
synchronized(gens) { synchronized(gens) {
return gens.computeIfAbsent(seed, k -> { return gens.computeIfAbsent(seed, k -> {
NoiseSampler noise; NoiseSampler noise;
NoiseSampler elevation; NoiseSampler elevation;
NoiseSampler carving; NoiseSampler carving;
Scope biomeScope = new Scope().withParent(varScope);
variables.forEach((id, val) -> biomeScope.create(id).setValue(val));
try { try {
noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap); noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap);
elevation = elevationEquation == null ? new ConstantSampler(0) : new ExpressionSampler(elevationEquation, 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) { public void setBlendWeight(double blendWeight) {
this.blendWeight = blendWeight; this.blendWeight = blendWeight;
} }

View File

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