use of com.sk89q.worldedit.internal.expression.EvaluationException in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method deformRegion.
/**
* Internal version of {@link EditSession#deformRegion(Region, Vector3, Vector3, String, int)}.
*
* <p>
* The Expression class is subject to change. Expressions should be provided via the string overload.
* </p>
*/
public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final Expression expression, final int timeout) throws ExpressionException, MaxChangedBlocksException {
final Variable x = expression.getSlots().getVariable("x").orElseThrow(IllegalStateException::new);
final Variable y = expression.getSlots().getVariable("y").orElseThrow(IllegalStateException::new);
final Variable z = expression.getSlots().getVariable("z").orElseThrow(IllegalStateException::new);
final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero);
expression.setEnvironment(environment);
// FAWE start
final Vector3 zero2 = zero.add(0.5, 0.5, 0.5);
RegionVisitor visitor = new RegionVisitor(region, position -> {
try {
// offset, scale
final Vector3 scaled = position.toVector3().subtract(zero).divide(unit);
// transform
expression.evaluate(new double[] { scaled.getX(), scaled.getY(), scaled.getZ() }, timeout);
int xv = (int) (x.getValue() * unit.getX() + zero2.getX());
int yv = (int) (y.getValue() * unit.getY() + zero2.getY());
int zv = (int) (z.getValue() * unit.getZ() + zero2.getZ());
BlockState get;
if (yv >= minY && yv <= maxY) {
get = getBlock(xv, yv, zv);
} else {
get = BlockTypes.AIR.getDefaultState();
}
// read block from world
return setBlock(position, get);
} catch (EvaluationException e) {
throw new RuntimeException(e);
}
}, this);
Operations.completeBlindly(visitor);
changes += visitor.getAffected();
return changes;
// FAWE end
}
Aggregations