From a7b457c35ca047ba6d4a708ad98a7a8ef276a1b4 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 30 Jan 2011 00:47:02 -0800 Subject: [PATCH] Added pattern support to //overlay. --- src/com/sk89q/worldedit/EditSession.java | 42 +++++++++++++++++++ .../worldedit/commands/RegionCommands.java | 10 ++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/com/sk89q/worldedit/EditSession.java b/src/com/sk89q/worldedit/EditSession.java index 945431f50..9c9948911 100755 --- a/src/com/sk89q/worldedit/EditSession.java +++ b/src/com/sk89q/worldedit/EditSession.java @@ -1124,6 +1124,48 @@ public class EditSession { return affected; } + /** + * Overlays a layer of blocks over a cuboid area. + * + * @param region + * @param pattern + * @return number of blocks affected + * @throws MaxChangedBlocksException + */ + public int overlayCuboidBlocks(Region region, Pattern pattern) + 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(); + + for (int x = minX; x <= maxX; x++) { + for (int z = minZ; z <= maxZ; z++) { + for (int y = upperY; y >= lowerY; y--) { + Vector above = new Vector(x, y + 1, z); + + if (y + 1 <= 127 && !getBlock(new Vector(x, y, z)).isAir() + && getBlock(above).isAir()) { + if (setBlock(above, pattern.next(above))) { + affected++; + } + break; + } + } + } + } + + return affected; + } + /** * Stack a cuboid region. * diff --git a/src/com/sk89q/worldedit/commands/RegionCommands.java b/src/com/sk89q/worldedit/commands/RegionCommands.java index b6757c028..61d715cdf 100644 --- a/src/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/com/sk89q/worldedit/commands/RegionCommands.java @@ -106,10 +106,16 @@ public class RegionCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - BaseBlock block = we.getBlock(player, args.getString(0)); + Pattern pat = we.getBlockPattern(player, args.getString(0)); Region region = session.getRegion(); - int affected = editSession.overlayCuboidBlocks(region, block); + int affected = 0; + if (pat instanceof SingleBlockPattern) { + affected = editSession.overlayCuboidBlocks(region, + ((SingleBlockPattern)pat).getBlock()); + } else { + affected = editSession.overlayCuboidBlocks(region, pat); + } player.print(affected + " block(s) have been overlayed."); }