From 187896c5eda814b367906757badfe9ee309d9b6b Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Wed, 2 Nov 2011 03:39:02 +0100 Subject: [PATCH] Made //deform round the results before lookup and fixed some potential issues. --- .../java/com/sk89q/worldedit/EditSession.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 0af77f520..96d93d3ba 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2674,19 +2674,35 @@ public class EditSession { final RValue y = expression.getVariable("y"); final RValue z = expression.getVariable("z"); - int affected = 0; + Vector zero2 = zero.add(0.5, 0.5, 0.5); + + final DoubleArrayList queue = new DoubleArrayList(false); for (BlockVector position : region) { + // offset, scale final Vector scaled = position.subtract(zero).divide(unit); + // transform 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(); + // unscale, unoffset, round-nearest + final BlockVector sourcePosition = sourceScaled.multiply(unit).add(zero2).toBlockPoint(); + // read block from world BaseBlock material = new BaseBlock(world.getBlockType(sourcePosition), world.getBlockData(sourcePosition)); + // queue operation + queue.put(position, material); + } + + int affected = 0; + for (Map.Entry entry : queue) { + BlockVector position = entry.getKey(); + BaseBlock material = entry.getValue(); + + // set at new position if (setBlock(position, material)) { ++affected; }