Added pattern support to /replacenear, //walls, and //faces

This commit is contained in:
zml2008
2011-08-21 23:55:50 -07:00
parent 9e13e25760
commit 91b7b8444f
3 changed files with 140 additions and 8 deletions

View File

@ -1162,6 +1162,70 @@ public class EditSession {
return affected;
}
/**
* Make faces of the region (as if it was a cuboid if it's not).
*
* @param region
* @param pattern
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int makeCuboidFaces(Region region, Pattern pattern)
throws MaxChangedBlocksException {
int affected = 0;
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
int minX = min.getBlockX();
int minY = min.getBlockY();
int minZ = min.getBlockZ();
int maxX = max.getBlockX();
int maxY = max.getBlockY();
int maxZ = max.getBlockZ();
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
Vector minV = new Vector(x, y, minZ);
if (setBlock(min, pattern.next(minV))) {
++affected;
}
Vector maxV = new Vector(x, y, maxZ);
if (setBlock(maxV, pattern.next(maxV))) {
++affected;
}
++affected;
}
}
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
Vector minV = new Vector(minX, y, z);
if (setBlock(minV, pattern.next(minV))) {
++affected;
}
Vector maxV = new Vector(maxX, y, z);
if (setBlock(maxV, pattern.next(maxV))) {
++affected;
}
}
}
for (int z = minZ; z <= maxZ; ++z) {
for (int x = minX; x <= maxX; ++x) {
Vector minV = new Vector(x, minY, z);
if (setBlock(minV, pattern.next(minV))) {
++affected;
}
Vector maxV = new Vector(x, maxY, z);
if (setBlock(maxV, pattern.next(maxV))) {
++affected;
}
}
}
return affected;
}
/**
* Make walls of the region (as if it was a cuboid if it's not).
@ -1211,6 +1275,58 @@ public class EditSession {
return affected;
}
/**
* Make walls of the region (as if it was a cuboid if it's not).
*
* @param region
* @param block
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int makeCuboidWalls(Region region, Pattern pattern)
throws MaxChangedBlocksException {
int affected = 0;
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
int minX = min.getBlockX();
int minY = min.getBlockY();
int minZ = min.getBlockZ();
int maxX = max.getBlockX();
int maxY = max.getBlockY();
int maxZ = max.getBlockZ();
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
Vector minV = new Vector(x, y, minZ);
if (setBlock(minV, pattern.next(minV))) {
++affected;
}
Vector maxV = new Vector(x, y, maxZ);
if (setBlock(maxV, pattern.next(maxV))) {
++affected;
}
++affected;
}
}
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
Vector minV = new Vector(minX, y, z);
if (setBlock(minV, pattern.next(minV))) {
++affected;
}
Vector maxV = new Vector(maxX, y, z);
if (setBlock(maxV, pattern.next(maxV))) {
++affected;
}
}
}
return affected;
}
/**
* Overlays a layer of blocks over a cuboid area.
*