From 2b94ddf7ed2025bf264d017809874f8f1f5fd3fd Mon Sep 17 00:00:00 2001 From: zml2008 Date: Wed, 17 Aug 2011 00:33:46 -0700 Subject: [PATCH] Added flag to //smooth to only use "natural" blocks --- .../java/com/sk89q/worldedit/EditSession.java | 10 ++-- .../java/com/sk89q/worldedit/HeightMap.java | 4 +- .../worldedit/commands/BrushCommands.java | 5 +- .../worldedit/commands/RegionCommands.java | 3 +- .../worldedit/tools/brushes/SmoothBrush.java | 6 ++- src/main/resources/plugin.yml | 50 ++++++++++++------- 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 7fb351139..1fcaf01ac 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2378,12 +2378,12 @@ public class EditSession { * maximal height * @return height of highest block found or 'minY' */ - public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { + 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 (!BlockType.canPassThrough(id) /*id == 1 // stone + if (naturalOnly ? + id == 1 // stone || id == 2 // grass || id == 3 // dirt || id == 7 // bedrock @@ -2400,8 +2400,8 @@ public class EditSession { || id == 16 // gold ore || id == 56 // diamond ore || id == 73 // redstone ore - || id == 74 // redstone ore (active)*/ - ) { + || id == 74 // redstone ore (active) + : !BlockType.canPassThrough(id)) { return y; } } diff --git a/src/main/java/com/sk89q/worldedit/HeightMap.java b/src/main/java/com/sk89q/worldedit/HeightMap.java index a3d7d2738..981579228 100644 --- a/src/main/java/com/sk89q/worldedit/HeightMap.java +++ b/src/main/java/com/sk89q/worldedit/HeightMap.java @@ -44,7 +44,7 @@ public class HeightMap { * @param region */ - public HeightMap(EditSession session, Region region) { + public HeightMap(EditSession session, Region region, boolean naturalOnly) { this.session = session; this.region = region; @@ -60,7 +60,7 @@ public class HeightMap { data = new int[width * height]; for (int z = 0; z < height; ++z) { for (int x = 0; x < width; ++x) { - data[z * width + x] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY); + data[z * width + x] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY, naturalOnly); } } } diff --git a/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java b/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java index 2f356b459..53045a6ae 100644 --- a/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java @@ -171,6 +171,7 @@ public class BrushCommands { @Command( aliases = {"smooth"}, usage = "[size] [iterations]", + flags = "n", desc = "Choose the terrain softener brush", min = 0, max = 2 @@ -193,9 +194,9 @@ public class BrushCommands { BrushTool tool = session.getBrushTool(player.getItemInHand()); tool.setSize(radius); - tool.setBrush(new SmoothBrush(iterations), "worldedit.brush.smooth"); + tool.setBrush(new SmoothBrush(iterations, args.hasFlag('n')), "worldedit.brush.smooth"); - player.print(String.format("Smooth brush equipped (%.0f x %dx).", + player.print(String.format("Smooth brush equipped (%.0f x %dx, using " + (args.hasFlag('n') ? "natural blocks only" : "any block") + ").", radius, iterations)); } diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index 23cc19f72..d76976ec4 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -186,6 +186,7 @@ public class RegionCommands { @Command( aliases = {"/smooth"}, usage = "[iterations]", + flags = "n", desc = "Smooth the elevation in the selection", min = 0, max = 1 @@ -201,7 +202,7 @@ public class RegionCommands { iterations = args.getInteger(0); } - HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld())); + HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld()), args.hasFlag('n')); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); int affected = heightMap.applyFilter(filter, iterations); player.print("Terrain's height map smoothed. " + affected + " block(s) changed."); diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java index 8dea6a6c0..e607922d4 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java @@ -31,9 +31,11 @@ import com.sk89q.worldedit.regions.Region; public class SmoothBrush implements Brush { private int iterations; + private boolean naturalOnly; - public SmoothBrush(int iterations) { + public SmoothBrush(int iterations, boolean naturalOnly) { this.iterations = iterations; + this.naturalOnly = naturalOnly; } public void build(EditSession editSession, Vector pos, Pattern mat, double size) @@ -42,7 +44,7 @@ public class SmoothBrush implements Brush { Vector min = pos.subtract(rad, rad, rad); Vector max = pos.add(rad, rad + 10, rad); Region region = new CuboidRegion(min, max); - HeightMap heightMap = new HeightMap(editSession, region); + HeightMap heightMap = new HeightMap(editSession, region, naturalOnly); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); heightMap.applyFilter(filter, iterations); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7b51f05d9..528a7c2d6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -96,8 +96,12 @@ commands: permissions: 'worldedit.generation.pumpkins' /pyramid: description: Generate a filled pyramid - usage: / [inverted] - permissions: 'worldedit.generation.sphere' + usage: / + permissions: 'worldedit.generation.pyramid' + /hpyramid: + description: Generate a hollow pyramid + usage: / + permissions: 'worldedit.generation.pyramid' /undo: description: Undoes the last action usage: / [times] @@ -165,13 +169,13 @@ commands: usage: / permissions: 'worldedit.region.walls' /faces: - description: Build the walls, ceiling, and roof of a selection + description: Build the walls, ceiling, and floor of a selection usage: / aliases: ['/outline'] permissions: 'worldedit.region.faces' /smooth: description: Smooth the elevation in the selection - usage: / [iterations] + usage: / [-n] [iterations] permissions: 'worldedit.region.smooth' /move: description: Move the contents of the selection @@ -201,25 +205,29 @@ commands: description: Shift the selection area usage: / [direction] permissions: 'worldedit.selection.shift' - /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' + /sel: + description: Choose a region selector + usage: / [type] + aliases: [','] + /chunk: + description: Set the selection to your current chunk. The -s flag extends your current selection to the encompassed chunks. + usage: / [-s] + permissions: 'worldedit.selection.chunk' /contract: description: Contract the selection area usage: / [reverse-amount] [direction] permissions: 'worldedit.selection.contract' /pos1: description: Set position 1 - usage: / + usage: / [coordinates] permissions: 'worldedit.selection.pos' /pos2: description: Set position 2 - usage: / + usage: / [coordinates] permissions: 'worldedit.selection.pos' /hpos1: description: Set position 1 to targeted block @@ -249,10 +257,6 @@ commands: description: Get the distribution of blocks in the selection usage: / [-c] permissions: 'worldedit.analysis.distr' - /sel: - description: Choose a region selector - usage: / [type] - aliases: [','] snapshot: description: Snapshot commands usage: / @@ -270,9 +274,13 @@ commands: description: Set the brush mask usage: / [mask] permissions: 'worldedit.brush.options.mask' + range: + description: Set the brush range + usage: / [pattern] + permissions: 'worldedit.brush.options.range' /: description: Toggle the super pickaxe pickaxe function - usage: / + usage: / [on|off] aliases: [','] permissions: 'worldedit.superpickaxe' superpickaxe: @@ -287,10 +295,6 @@ commands: usage: / [pattern] aliases: ['material', 'fill'] permissions: 'worldedit.brush.options.material' - range: - description: Set the brush range - usage: / [pattern] - permissions: 'worldedit.brush.options.range' info: description: Block information tool usage: / @@ -323,6 +327,10 @@ commands: description: Floating tree remover tool usage: / permissions: 'worldedit.tool.deltree' + farwand: + description: Wand at a distance tool + usage: / + permissions: 'worldedit.tool.farwand' remove: description: Remove all entities of a type usage: / @@ -372,6 +380,10 @@ commands: description: Thaws the area usage: / [radius] permissions: 'worldedit.thaw' + green: + description: Greens the area + usage: / [radius] + permissions: 'worldedit.green' ex: description: Extinguish nearby fire usage: / [radius]