mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Switched //faces and //walls to use visitors.
This commit is contained in:
parent
6c1ff02df5
commit
f509a3128e
@ -1006,265 +1006,119 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make faces of the region (as if it was a cuboid if it's not).
|
* Make the faces of the given region as if it was a {@link CuboidRegion}.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region the region
|
||||||
* @param block
|
* @param block the block to place
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int makeCuboidFaces(Region region, BaseBlock block)
|
public int makeCuboidFaces(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
return makeCuboidFaces(region, new SingleBlockPattern(block));
|
||||||
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) {
|
|
||||||
if (setBlock(new Vector(x, y, minZ), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
if (setBlock(new Vector(x, y, maxZ), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int y = minY; y <= maxY; ++y) {
|
|
||||||
for (int z = minZ; z <= maxZ; ++z) {
|
|
||||||
if (setBlock(new Vector(minX, y, z), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
if (setBlock(new Vector(maxX, y, z), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int z = minZ; z <= maxZ; ++z) {
|
|
||||||
for (int x = minX; x <= maxX; ++x) {
|
|
||||||
if (setBlock(new Vector(x, minY, z), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
if (setBlock(new Vector(x, maxY, z), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return affected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make faces of the region (as if it was a cuboid if it's not).
|
* Make the faces of the given region as if it was a {@link CuboidRegion}.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region the region
|
||||||
* @param pattern
|
* @param pattern the pattern to place
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||||
*/
|
*/
|
||||||
public int makeCuboidFaces(Region region, Pattern pattern)
|
public int makeCuboidFaces(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
checkNotNull(region);
|
||||||
int affected = 0;
|
checkNotNull(pattern);
|
||||||
|
|
||||||
Vector min = region.getMinimumPoint();
|
CuboidRegion cuboid = CuboidRegion.makeCuboid(region);
|
||||||
Vector max = region.getMaximumPoint();
|
Region faces = cuboid.getFaces();
|
||||||
|
return setBlocks(faces, pattern);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 faces of the region
|
* Make the faces of the given region. The method by which the faces are found
|
||||||
|
* may be inefficient, because there may not be an efficient implementation supported
|
||||||
|
* for that specific shape.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region the region
|
||||||
* @param pattern
|
* @param pattern the pattern to place
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||||
*/
|
*/
|
||||||
public int makeFaces(final Region region, Pattern pattern) throws MaxChangedBlocksException {
|
public int makeFaces(final Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||||
return new RegionShape(region).generate(this, pattern, true);
|
checkNotNull(region);
|
||||||
|
checkNotNull(pattern);
|
||||||
|
|
||||||
|
if (region instanceof CuboidRegion) {
|
||||||
|
return makeCuboidFaces(region, pattern);
|
||||||
|
} else {
|
||||||
|
return new RegionShape(region).generate(this, pattern, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make walls of the region (as if it was a cuboid if it's not).
|
* Make the walls (all faces but those parallel to the X-Z plane) of the given region
|
||||||
|
* as if it was a {@link CuboidRegion}.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region the region
|
||||||
* @param block
|
* @param block the block to place
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int makeCuboidWalls(Region region, BaseBlock block)
|
public int makeCuboidWalls(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
return makeCuboidWalls(region, new SingleBlockPattern(block));
|
||||||
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) {
|
|
||||||
if (setBlock(new Vector(x, y, minZ), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
if (setBlock(new Vector(x, y, maxZ), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int y = minY; y <= maxY; ++y) {
|
|
||||||
for (int z = minZ; z <= maxZ; ++z) {
|
|
||||||
if (setBlock(new Vector(minX, y, z), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
if (setBlock(new Vector(maxX, y, z), block)) {
|
|
||||||
++affected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return affected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make walls of the region (as if it was a cuboid if it's not).
|
* Make the walls (all faces but those parallel to the X-Z plane) of the given region
|
||||||
|
* as if it was a {@link CuboidRegion}.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region the region
|
||||||
* @param pattern
|
* @param pattern the pattern to place
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||||
*/
|
*/
|
||||||
public int makeCuboidWalls(Region region, Pattern pattern)
|
public int makeCuboidWalls(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
checkNotNull(region);
|
||||||
int affected = 0;
|
checkNotNull(pattern);
|
||||||
|
|
||||||
Vector min = region.getMinimumPoint();
|
CuboidRegion cuboid = CuboidRegion.makeCuboid(region);
|
||||||
Vector max = region.getMaximumPoint();
|
Region faces = cuboid.getWalls();
|
||||||
|
return setBlocks(faces, pattern);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make walls of the region
|
* Make the walls of the given region. The method by which the walls are found
|
||||||
|
* may be inefficient, because there may not be an efficient implementation supported
|
||||||
|
* for that specific shape.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region the region
|
||||||
* @param pattern
|
* @param pattern the pattern to place
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||||
*/
|
*/
|
||||||
public int makeWalls(final Region region, Pattern pattern) throws MaxChangedBlocksException {
|
public int makeWalls(final Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||||
final int minY = region.getMinimumPoint().getBlockY();
|
checkNotNull(region);
|
||||||
final int maxY = region.getMaximumPoint().getBlockY();
|
checkNotNull(pattern);
|
||||||
final ArbitraryShape shape = new RegionShape(region) {
|
|
||||||
@Override
|
|
||||||
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
|
|
||||||
if (y > maxY || y < minY) {
|
|
||||||
// Put holes into the floor and ceiling by telling ArbitraryShape that the shape goes on outside the region
|
|
||||||
return defaultMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.getMaterial(x, y, z, defaultMaterial);
|
if (region instanceof CuboidRegion) {
|
||||||
}
|
return makeCuboidWalls(region, pattern);
|
||||||
};
|
} else {
|
||||||
return shape.generate(this, pattern, true);
|
final int minY = region.getMinimumPoint().getBlockY();
|
||||||
|
final int maxY = region.getMaximumPoint().getBlockY();
|
||||||
|
final ArbitraryShape shape = new RegionShape(region) {
|
||||||
|
@Override
|
||||||
|
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
|
||||||
|
if (y > maxY || y < minY) {
|
||||||
|
// Put holes into the floor and ceiling by telling ArbitraryShape that the shape goes on outside the region
|
||||||
|
return defaultMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.getMaterial(x, y, z, defaultMaterial);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return shape.generate(this, pattern, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user