mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +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.
|
||||
*
|
||||
|
@ -121,6 +121,23 @@ public class RegionCommands {
|
||||
player.print(affected + " block(s) have been overlayed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/naturalize"},
|
||||
usage = "",
|
||||
desc = "3 layers of dirt on top then rock below",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.naturalize"})
|
||||
public static void naturalize(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int affected = editSession.naturalizeCuboidBlocks(region);
|
||||
player.print(affected + " block(s) have been naturalized.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/walls"},
|
||||
usage = "<block>",
|
||||
|
Reference in New Issue
Block a user