cache last noise result for rule sequences

This commit is contained in:
Frank 2021-12-08 20:43:03 +01:00
parent e8a40246b4
commit 338aee76e9

View file

@ -13,16 +13,24 @@ public class SulphuricSurfaceNoiseCondition extends SurfaceNoiseCondition {
this.threshold = threshold;
}
private int lastX = Integer.MIN_VALUE;
private int lastZ = Integer.MIN_VALUE;
private double lastValue = 0;
@Override
public boolean test(SurfaceRulesContextAccessor context) {
final int x = context.getBlockX();
final int z = context.getBlockZ();
if (lastX==x && lastZ==z) return lastValue < threshold;
double value = NOISE.eval(x * 0.03, z * 0.03) + NOISE.eval(x * 0.1, z * 0.1) * 0.3 + MHelper.randRange(
-0.1,
0.1,
MHelper.RANDOM
);
lastX=x;
lastZ=z;
lastValue=value;
return value < threshold;
}
}