Added EditSession.moveRegion.

This commit is contained in:
TomyLobo 2013-08-04 01:22:29 +02:00
parent cd5f832adf
commit c1396a2468

View File

@ -44,6 +44,7 @@
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.TreeGenerator;
/**
@ -1835,6 +1836,54 @@ public int stackCuboidRegion(Region region, Vector dir, int count,
return affected;
}
/**
* Move a region.
*
* @param region
* @param dir
* @param distance
* @param copyAir
* @param replace
* @return number of blocks moved
* @throws MaxChangedBlocksException
* @throws RegionOperationException
*/
public int moveRegion(Region region, Vector dir, int distance,
boolean copyAir, BaseBlock replace)
throws MaxChangedBlocksException, RegionOperationException {
int affected = 0;
final Vector shift = dir.multiply(distance);
final Region newRegion = region.clone();
newRegion.shift(shift);
final Map<Vector, BaseBlock> delayed = new LinkedHashMap<Vector, BaseBlock>();
for (Vector pos : region) {
final BaseBlock block = getBlock(pos);
if (!block.isAir() || copyAir) {
final Vector newPos = pos.add(shift);
delayed.put(newPos, getBlock(pos));
// Don't want to replace the old block if it's in
// the new area
if (!newRegion.contains(pos)) {
setBlock(pos, replace);
}
}
}
for (Map.Entry<Vector, BaseBlock> entry : delayed.entrySet()) {
setBlock(entry.getKey(), entry.getValue());
++affected;
}
return affected;
}
/**
* Move a cuboid region.
*