mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Added //naturalize.
This commit is contained in:
@ -1296,6 +1296,79 @@ public class EditSession {
|
||||
return affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the first 3 layers into dirt/grass and the bottom layers
|
||||
* into rock, like a natural Minecraft mountain.
|
||||
*
|
||||
* @param region
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public int naturalizeCuboidBlocks(Region region)
|
||||
throws MaxChangedBlocksException {
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
|
||||
int upperY = Math.min(127, max.getBlockY() + 1);
|
||||
int lowerY = Math.max(0, min.getBlockY() - 1);
|
||||
|
||||
int affected = 0;
|
||||
|
||||
int minX = min.getBlockX();
|
||||
int minZ = min.getBlockZ();
|
||||
int maxX = max.getBlockX();
|
||||
int maxZ = max.getBlockZ();
|
||||
|
||||
BaseBlock grass = new BaseBlock(BlockID.GRASS);
|
||||
BaseBlock dirt = new BaseBlock(BlockID.DIRT);
|
||||
BaseBlock stone = new BaseBlock(BlockID.STONE);
|
||||
|
||||
for (int x = minX; x <= maxX; ++x) {
|
||||
for (int z = minZ; z <= maxZ; ++z) {
|
||||
int level = -1;
|
||||
|
||||
for (int y = upperY; y >= lowerY; --y) {
|
||||
Vector pt = new Vector(x, y, z);
|
||||
Vector above = new Vector(x, y + 1, z);
|
||||
int blockType = getBlockType(pt);
|
||||
|
||||
boolean isTransformable =
|
||||
blockType == BlockID.GRASS
|
||||
|| blockType == BlockID.DIRT
|
||||
|| blockType == BlockID.STONE;
|
||||
|
||||
// Still searching for the top block
|
||||
if (level == -1) {
|
||||
if (!isTransformable) {
|
||||
continue; // Not transforming this column yet
|
||||
}
|
||||
|
||||
level = 0;
|
||||
}
|
||||
|
||||
if (level >= 0) {
|
||||
if (isTransformable) {
|
||||
if (level == 0) {
|
||||
setBlock(pt, grass);
|
||||
affected++;
|
||||
} else if (level <= 2) {
|
||||
setBlock(pt, dirt);
|
||||
affected++;
|
||||
} else {
|
||||
setBlock(pt, stone);
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
|
||||
level++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stack a cuboid region.
|
||||
*
|
||||
|
Reference in New Issue
Block a user