From 8bb0629d79ecc5b9b5100dcbf7dfa4c3b47cdfc9 Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 2 Aug 2011 15:46:11 -0700 Subject: [PATCH] Added //naturalize. --- plugin.yml | 210 +++++++++--------- .../java/com/sk89q/worldedit/EditSession.java | 73 ++++++ .../worldedit/commands/RegionCommands.java | 17 ++ 3 files changed, 197 insertions(+), 103 deletions(-) diff --git a/plugin.yml b/plugin.yml index e662e702e..d53ef2cac 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: WorldEdit main: com.sk89q.worldedit.bukkit.WorldEditPlugin -version: "${project.version}" +version: ${project.version} commands: chunkinfo: description: Get information about the chunk that you are inside @@ -14,10 +14,6 @@ commands: description: Delete chunks that your selection includes usage: / permissions: 'worldedit.delchunks' - clearclipboard: - description: Clear your clipboard - usage: / - permissions: 'worldedit.clipboard.clear' /load: description: Load a schematic into your clipboard usage: / @@ -46,6 +42,19 @@ commands: description: Paste the clipboard's contents usage: / [-ao] permissions: 'worldedit.clipboard.paste' + clearclipboard: + description: Clear your clipboard + usage: / + permissions: 'worldedit.clipboard.clear' + /limit: + description: Modify block change limit + usage: / + permissions: 'worldedit.limit' + /gmask: + description: Set the global mask + usage: / [mask] + aliases: ['gmask'] + permissions: 'worldedit.global-mask' we: description: WorldEdit commands usage: / @@ -61,15 +70,6 @@ commands: description: Search for an item usage: / [-bi] aliases: ['/l', 'search'] - /limit: - description: Modify block change limit - usage: / - permissions: 'worldedit.limit' - /gmask: - description: Set the global mask - usage: / [mask] - aliases: ['gmask'] - permissions: 'worldedit.global-mask' /hcyl: description: Generate a hollow cylinder usage: / [height] @@ -94,32 +94,36 @@ commands: description: Generate pumpkin patches usage: / [size] permissions: 'worldedit.generation.pumpkins' - clearhistory: - description: Clear your history - usage: / - permissions: 'worldedit.history.clear' - /redo: - description: Redoes the last action (from history) - usage: / [times] - aliases: ['redo'] - permissions: 'worldedit.history.redo' /undo: description: Undoes the last action usage: / [times] aliases: ['undo'] permissions: 'worldedit.history.undo' + /redo: + description: Redoes the last action (from history) + usage: / [times] + aliases: ['redo'] + permissions: 'worldedit.history.redo' + clearhistory: + description: Clear your history + usage: / + permissions: 'worldedit.history.clear' unstuck: description: Escape from being stuck inside a block usage: / permissions: 'worldedit.navigation.unstuck' ascend: description: Go up a floor - usage: / + usage: / [# of levels] permissions: 'worldedit.navigation.ascend' descend: description: Go down a floor - usage: / + usage: / [# of floors] permissions: 'worldedit.navigation.descend' + ceil: + description: Go to the celing + usage: / [clearance] + permissions: 'worldedit.navigation.ceiling' thru: description: Passthrough walls usage: / @@ -128,18 +132,30 @@ commands: description: Teleport to a location usage: / permissions: 'worldedit.navigation.jumpto' - ceil: - description: Go to the celing - usage: / [clearance] - permissions: 'worldedit.navigation.ceiling' up: description: Go upwards some distance usage: / permissions: 'worldedit.navigation.up' + /replace: + description: Replace all blocks in the selection with another + usage: / [from-block] + permissions: 'worldedit.region.replace' + /stack: + description: Repeat the contents of the selection + usage: / [-sa] [count] [direction] + permissions: 'worldedit.region.stack' + /set: + description: Set all the blocks inside the selection to a block + usage: / + permissions: 'worldedit.region.set' /overlay: description: Set a block on top of blocks in the region usage: / permissions: 'worldedit.region.overlay' + /naturalize: + description: 3 layers of dirt on top then rock below + usage: / + permissions: 'worldedit.region.naturalize' /walls: description: Build the four sides of the selection usage: / @@ -153,38 +169,46 @@ commands: description: Smooth the elevation in the selection usage: / [iterations] permissions: 'worldedit.region.smooth' - /regen: - description: Regenerates the contents of the selection - usage: / - permissions: 'worldedit.regen' - /replace: - description: Replace all blocks in the selection with another - usage: / [from-block] - permissions: 'worldedit.region.replace' - /stack: - description: Repeat the contents of the selection - usage: / [-sa] [count] [direction] - permissions: 'worldedit.region.stack' - /set: - description: Set all the blocks inside the selection to a block - usage: / - permissions: 'worldedit.region.set' /move: description: Move the contents of the selection usage: / [-s] [count] [direction] [leave-id] permissions: 'worldedit.region.move' - .s: - description: Execute last CraftScript - usage: / [args...] - permissions: 'worldedit.scripting.execute' + /regen: + description: Regenerates the contents of the selection + usage: / + permissions: 'worldedit.regen' cs: description: Execute a CraftScript usage: / [args...] permissions: 'worldedit.scripting.execute' + .s: + description: Execute last CraftScript + usage: / [args...] + permissions: 'worldedit.scripting.execute' + /count: + description: Counts the number of a certain type of block + usage: / + permissions: 'worldedit.analysis.count' + /size: + description: Get information about the selection + usage: / + permissions: 'worldedit.selection.size' + /shift: + description: Shift the selection area + usage: / [direction] + permissions: 'worldedit.selection.shift' + /sel: + description: Choose a region selector + usage: / [type] + aliases: [','] /chunk: description: Set the selection to your current chunk usage: / permissions: 'worldedit.selection.chunk' + /expand: + description: Expand the selection area + usage: / [reverse-amount] + permissions: 'worldedit.selection.expand' /contract: description: Contract the selection area usage: / [reverse-amount] [direction] @@ -217,34 +241,14 @@ commands: description: Outset the selection area usage: / [-hv] permissions: 'worldedit.selection.outset' - /distr: - description: Get the distribution of blocks in the selection - usage: / [-c] - permissions: 'worldedit.analysis.distr' - /count: - description: Counts the number of a certain type of block - usage: / - permissions: 'worldedit.analysis.count' - /size: - description: Get information about the selection - usage: / - permissions: 'worldedit.selection.size' - /shift: - description: Shift the selection area - usage: / [direction] - permissions: 'worldedit.selection.shift' - /expand: - description: Expand the selection area - usage: / [reverse-amount] - permissions: 'worldedit.selection.expand' - /sel: - description: Choose a region selector - usage: / [type] - aliases: [','] /inset: description: Inset the selection area usage: / [-hv] permissions: 'worldedit.selection.inset' + /distr: + description: Get the distribution of blocks in the selection + usage: / [-c] + permissions: 'worldedit.analysis.distr' snapshot: description: Snapshot commands usage: / @@ -254,6 +258,14 @@ commands: usage: / [snapshot] aliases: ['/restore'] permissions: 'worldedit.snapshots.restore' + size: + description: Set the brush size + usage: / [pattern] + permissions: 'worldedit.brush.options.size' + mask: + description: Set the brush mask + usage: / [mask] + permissions: 'worldedit.brush.options.mask' /: description: Toggle the super pickaxe pickaxe function usage: / @@ -271,21 +283,21 @@ commands: usage: / [pattern] aliases: ['material', 'fill'] permissions: 'worldedit.brush.options.material' - size: - description: Set the brush size - usage: / [pattern] - permissions: 'worldedit.brush.options.size' range: description: Set the brush range - usage: / [range] + usage: / [pattern] permissions: 'worldedit.brush.options.range' - mask: - description: Set the brush mask - usage: / [mask] - permissions: 'worldedit.brush.options.mask' + info: + description: Block information tool + usage: / + permissions: 'worldedit.tool.info' none: description: Turn off all superpickaxe alternate modes usage: / + tree: + description: Tree generator tool + usage: / [type] + permissions: 'worldedit.tool.tree' repl: description: Block replacer tool usage: / @@ -307,18 +319,23 @@ commands: description: Floating tree remover tool usage: / permissions: 'worldedit.tool.deltree' - info: - description: Block information tool - usage: / - permissions: 'worldedit.tool.info' - tree: - description: Tree generator tool - usage: / [type] - permissions: 'worldedit.tool.tree' + remove: + description: Remove all entities of a type + usage: / + aliases: ['rem', 'rement'] + permissions: 'worldedit.remove' + /fill: + description: Fill a hole + usage: / [depth] + permissions: 'worldedit.fill' /fillr: description: Fill a hole recursively usage: / [depth] permissions: 'worldedit.fill.recursive' + /drain: + description: Drain a pool + usage: / + permissions: 'worldedit.drain' fixlava: description: Fix lava to be stationary usage: / @@ -360,16 +377,3 @@ commands: description: Kill all or nearby mobs usage: / [-p] [radius] permissions: 'worldedit.butcher' - remove: - description: Remove all entities of a type - usage: / - aliases: ['rem', 'rement'] - permissions: 'worldedit.remove' - /fill: - description: Fill a hole - usage: / [depth] - permissions: 'worldedit.fill' - /drain: - description: Drain a pool - usage: / - permissions: 'worldedit.drain' diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 7482a558a..0eb92c9de 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -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. * diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index d14c0696b..5ff3ba607 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -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 = "",