use of com.sk89q.worldedit.regions.shape.ArbitraryBiomeShape in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method makeBiomeShape.
public int makeBiomeShape(final Region region, final Vector3 zero, final Vector3 unit, final BiomeType biomeType, final String expressionString, final boolean hollow, final int timeout) throws ExpressionException {
final Expression expression = Expression.compile(expressionString, "x", "y", "z");
expression.optimize();
final EditSession editSession = this;
final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(editSession, unit, zero);
expression.setEnvironment(environment);
AtomicInteger timedOut = new AtomicInteger();
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {
@Override
protected BiomeType getBiome(int x, int y, int z, BiomeType defaultBiomeType) {
environment.setCurrentBlock(x, y, z);
double scaledX = (x - zero.getX()) / unit.getX();
double scaledY = (y - zero.getY()) / unit.getY();
double scaledZ = (z - zero.getZ()) / unit.getZ();
try {
if (expression.evaluate(new double[] { scaledX, scaledY, scaledZ }, timeout) <= 0) {
return null;
}
// TODO: Allow biome setting via a script variable (needs BiomeType<->int mapping)
return defaultBiomeType;
} catch (ExpressionTimeoutException e) {
timedOut.getAndIncrement();
return null;
} catch (Exception e) {
LOGGER.warn("Failed to create shape", e);
return null;
}
}
};
int changed = shape.generate(this, biomeType, hollow);
if (timedOut.get() > 0) {
throw new ExpressionTimeoutException(String.format("%d biomes changed. %d biomes took too long to evaluate (increase time with //timeout)", changed, timedOut.get()));
}
return changed;
}
Aggregations