Added a //deform command, which deforms a region given an expression that operates on the x/y/z variables.

This commit is contained in:
TomyLobo
2011-11-01 15:23:42 +01:00
parent a5e5880064
commit 4f1196ce2d
2 changed files with 74 additions and 0 deletions

View File

@ -2642,4 +2642,33 @@ public class EditSession {
return shape.generate(this, pattern, hollow);
}
public int deformRegion(final Region region, final Vector zero, final Vector unit, final String expressionString) throws ExpressionException, MaxChangedBlocksException {
final Expression expression = Expression.compile(expressionString, "x", "y", "z");
expression.optimize();
final RValue x = expression.getVariable("x");
final RValue y = expression.getVariable("y");
final RValue z = expression.getVariable("z");
int affected = 0;
for (BlockVector position : region) {
final Vector scaled = position.subtract(zero).divide(unit);
expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ());
final Vector sourceScaled = new Vector(x.getValue(), y.getValue(), z.getValue());
final BlockVector sourcePosition = sourceScaled.multiply(unit).add(zero).toBlockPoint();
BaseBlock material = new BaseBlock(world.getBlockType(sourcePosition), world.getBlockData(sourcePosition));
if (setBlock(position, material)) {
++affected;
}
}
return affected;
}
}