From c5c68f481b527f540232c110604f400fbcf8a3c2 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 1 Nov 2011 14:54:32 +0100 Subject: [PATCH] Moved all command-implementing methods to the bottom of the file. --- .../java/com/sk89q/worldedit/EditSession.java | 316 +++++++++--------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index fd2da128a..2720dfcea 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -545,6 +545,164 @@ public class EditSession { return fastMode; } + /** + * Set a block by chance. + * + * @param pos + * @param block + * @param c 0-1 chance + * @return whether a block was changed + * @throws MaxChangedBlocksException + */ + public boolean setChanceBlockIfAir(Vector pos, BaseBlock block, double c) + throws MaxChangedBlocksException { + if (Math.random() <= c) { + return setBlockIfAir(pos, block); + } + return false; + } + + /** + * Count the number of blocks of a list of types in a region. + * + * @param region + * @param searchIDs + * @return + */ + public int countBlocks(Region region, Set searchIDs) { + int count = 0; + + if (region instanceof CuboidRegion) { + // Doing this for speed + 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) { + for (int z = minZ; z <= maxZ; ++z) { + Vector pt = new Vector(x, y, z); + + if (searchIDs.contains(getBlockType(pt))) { + ++count; + } + } + } + } + } else { + for (Vector pt : region) { + if (searchIDs.contains(getBlockType(pt))) { + ++count; + } + } + } + + return count; + } + + /** + * Returns the highest solid 'terrain' block which can occur naturally. + * + * @param x + * @param z + * @param minY minimal height + * @param maxY maximal height + * @param naturalOnly look at natural blocks or all blocks + * @return height of highest block found or 'minY' + */ + public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { + return getHighestTerrainBlock(x, z, minY, maxY, false); + } + + /** + * Returns the highest solid 'terrain' block which can occur naturally. + * + * @param x + * @param z + * @param minY minimal height + * @param maxY maximal height + * @param naturalOnly look at natural blocks or all blocks + * @return height of highest block found or 'minY' + */ + public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean naturalOnly) { + for (int y = maxY; y >= minY; --y) { + Vector pt = new Vector(x, y, z); + int id = getBlockType(pt); + if (naturalOnly ? BlockType.isNaturalTerrainBlock(id) : !BlockType.canPassThrough(id)) { + return y; + } + } + return minY; + } + + /** + * Gets the list of missing blocks and clears the list for the next + * operation. + * + * @return + */ + public Set popMissingBlocks() { + Set missingBlocks = this.missingBlocks; + this.missingBlocks = new HashSet(); + return missingBlocks; + } + + /** + * @return the blockBag + */ + public BlockBag getBlockBag() { + return blockBag; + } + + /** + * @param blockBag the blockBag to set + */ + public void setBlockBag(BlockBag blockBag) { + this.blockBag = blockBag; + } + + /** + * Get the world. + * + * @return + */ + public LocalWorld getWorld() { + return world; + } + + /** + * Get the number of blocks changed, including repeated block changes. + * + * @return + */ + public int getBlockChangeCount() { + return original.size(); + } + + /** + * Get the mask. + * + * @return mask, may be null + */ + public Mask getMask() { + return mask; + } + + /** + * Set a mask. + * + * @param mask mask or null + */ + public void setMask(Mask mask) { + this.mask = mask; + } + /** * Finish off the queue. */ @@ -2220,23 +2378,6 @@ public class EditSession { return affected; } - /** - * Set a block by chance. - * - * @param pos - * @param block - * @param c 0-1 chance - * @return whether a block was changed - * @throws MaxChangedBlocksException - */ - public boolean setChanceBlockIfAir(Vector pos, BaseBlock block, double c) - throws MaxChangedBlocksException { - if (Math.random() <= c) { - return setBlockIfAir(pos, block); - } - return false; - } - /** * Makes a pumpkin patch. * @@ -2413,50 +2554,6 @@ public class EditSession { return affected; } - /** - * Count the number of blocks of a list of types in a region. - * - * @param region - * @param searchIDs - * @return - */ - public int countBlocks(Region region, Set searchIDs) { - int count = 0; - - if (region instanceof CuboidRegion) { - // Doing this for speed - 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) { - for (int z = minZ; z <= maxZ; ++z) { - Vector pt = new Vector(x, y, z); - - if (searchIDs.contains(getBlockType(pt))) { - ++count; - } - } - } - } - } else { - for (Vector pt : region) { - if (searchIDs.contains(getBlockType(pt))) { - ++count; - } - } - } - - return count; - } - /** * Get the block distribution inside a region. * @@ -2514,101 +2611,4 @@ public class EditSession { return distribution; } - - /** - * Returns the highest solid 'terrain' block which can occur naturally. - * - * @param x - * @param z - * @param minY minimal height - * @param maxY maximal height - * @param naturalOnly look at natural blocks or all blocks - * @return height of highest block found or 'minY' - */ - public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { - return getHighestTerrainBlock(x, z, minY, maxY, false); - } - - /** - * Returns the highest solid 'terrain' block which can occur naturally. - * - * @param x - * @param z - * @param minY minimal height - * @param maxY maximal height - * @param naturalOnly look at natural blocks or all blocks - * @return height of highest block found or 'minY' - */ - public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean naturalOnly) { - for (int y = maxY; y >= minY; --y) { - Vector pt = new Vector(x, y, z); - int id = getBlockType(pt); - if (naturalOnly ? BlockType.isNaturalTerrainBlock(id) : !BlockType.canPassThrough(id)) { - return y; - } - } - return minY; - } - - /** - * Gets the list of missing blocks and clears the list for the next - * operation. - * - * @return - */ - public Set popMissingBlocks() { - Set missingBlocks = this.missingBlocks; - this.missingBlocks = new HashSet(); - return missingBlocks; - } - - /** - * @return the blockBag - */ - public BlockBag getBlockBag() { - return blockBag; - } - - /** - * @param blockBag the blockBag to set - */ - public void setBlockBag(BlockBag blockBag) { - this.blockBag = blockBag; - } - - /** - * Get the world. - * - * @return - */ - public LocalWorld getWorld() { - return world; - } - - /** - * Get the number of blocks changed, including repeated block changes. - * - * @return - */ - public int getBlockChangeCount() { - return original.size(); - } - - /** - * Get the mask. - * - * @return mask, may be null - */ - public Mask getMask() { - return mask; - } - - /** - * Set a mask. - * - * @param mask mask or null - */ - public void setMask(Mask mask) { - this.mask = mask; - } }