From ec455189dc1725170a41f0295892c81ddeb10643 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 11 Mar 2017 21:26:35 +1100 Subject: [PATCH] Add scatter overlay --- .../fawe/object/brush/ScatterBrush.java | 7 +++++- .../object/brush/ScatterOverlayBrush.java | 23 +++++++++++++++++++ .../fawe/object/mask/AdjacentAnyMask.java | 15 +++++++----- .../worldedit/command/BrushCommands.java | 15 +++++++++--- 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java diff --git a/core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java index ba067aba..e5061fc4 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java @@ -24,6 +24,7 @@ public class ScatterBrush implements Brush { private final int count; private final int distance; private Mask mask; + private AdjacentAnyMask adjacent; public ScatterBrush(int count, int distance) { this.count = count; @@ -44,7 +45,7 @@ public class ScatterBrush implements Brush { if (this.mask == null) { this.mask = Masks.alwaysTrue(); } - final AdjacentAnyMask adjacent = new AdjacentAnyMask(editSession, Arrays.asList(new BaseBlock(0))); + this.adjacent = new AdjacentAnyMask(editSession, Arrays.asList(new BaseBlock(0))); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); @@ -83,6 +84,10 @@ public class ScatterBrush implements Brush { return mask.test(pos); } + public Vector getDirection(Vector pt) { + return adjacent.direction(pt); + } + public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException { editSession.setBlock(pt, p); } diff --git a/core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java new file mode 100644 index 00000000..fa29ebd8 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java @@ -0,0 +1,23 @@ +package com.boydti.fawe.object.brush; + +import com.boydti.fawe.object.collection.LocalBlockVectorSet; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.function.pattern.Pattern; + +public class ScatterOverlayBrush extends ScatterBrush { + public ScatterOverlayBrush(int count, int distance) { + super(count, distance); + } + + @Override + public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException { + int x = pt.getBlockX(); + int y = pt.getBlockY(); + int z = pt.getBlockZ(); + Vector dir = getDirection(pt); + dir.setComponents(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ()); + editSession.setBlock(dir, p); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java b/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java index 9c49e737..73e99397 100644 --- a/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java +++ b/core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java @@ -11,6 +11,9 @@ import java.util.Collection; * Just an optimized version of the Adjacent Mask for single adjacency */ public class AdjacentAnyMask extends BlockMask { + + private MutableBlockVector mutable = new MutableBlockVector(); + public AdjacentAnyMask(Extent extent, Collection blocks) { super(extent, blocks); } @@ -43,19 +46,19 @@ public class AdjacentAnyMask extends BlockMask { int y = v.getBlockY(); int z = v.getBlockZ(); v.mutY(y + 1); - if (super.test(v)) { v.mutY(y); return MutableBlockVector.get(0, 1, 0); } + if (super.test(v)) { v.mutY(y); return mutable.setComponents(0, 1, 0); } v.mutY(y - 1); - if (super.test(v)) { v.mutY(y); return MutableBlockVector.get(0, -1, 0); } + if (super.test(v)) { v.mutY(y); return mutable.setComponents(0, -1, 0); } v.mutY(y); v.mutX(x + 1); - if (super.test(v)) { v.mutX(x); return MutableBlockVector.get(1, 0, 0); } + if (super.test(v)) { v.mutX(x); return mutable.setComponents(1, 0, 0); } v.mutX(x - 1); - if (super.test(v)) { v.mutX(x); return MutableBlockVector.get(-1, 0, 0); } + if (super.test(v)) { v.mutX(x); return mutable.setComponents(-1, 0, 0); } v.mutX(x); v.mutZ(z + 1); - if (super.test(v)) { v.mutZ(z); return MutableBlockVector.get(0, 0, 1); } + if (super.test(v)) { v.mutZ(z); return mutable.setComponents(0, 0, 1); } v.mutZ(z - 1); - if (super.test(v)) { v.mutZ(z); return MutableBlockVector.get(0, 0, - 1); } + if (super.test(v)) { v.mutZ(z); return mutable.setComponents(0, 0, - 1); } v.mutZ(z); return null; } diff --git a/core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 6bdac07b..591b3241 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -36,6 +36,7 @@ import com.boydti.fawe.object.brush.RaiseBrush; import com.boydti.fawe.object.brush.RecurseBrush; import com.boydti.fawe.object.brush.ScatterBrush; import com.boydti.fawe.object.brush.ScatterCommand; +import com.boydti.fawe.object.brush.ScatterOverlayBrush; import com.boydti.fawe.object.brush.ShatterBrush; import com.boydti.fawe.object.brush.SplatterBrush; import com.boydti.fawe.object.brush.SplineBrush; @@ -68,6 +69,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.command.tool.BrushTool; +import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.command.tool.brush.ButcherBrush; import com.sk89q.worldedit.command.tool.brush.ClipboardBrush; import com.sk89q.worldedit.command.tool.brush.CylinderBrush; @@ -570,17 +572,24 @@ public class BrushCommands { usage = " [radius=5] [points=5] [distance=1]", desc = "Scatter blocks on a surface", help = - "Chooses the scatter brush.", + "Chooses the scatter brush.\n" + + " The -o flag will overlay the block", min = 1, max = 4 ) @CommandPermissions("worldedit.brush.scatter") - public void scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("5") double points, @Optional("1") double distance) throws WorldEditException { + public void scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("5") double points, @Optional("1") double distance, @Switch('o') boolean overlay) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player); tool.setFill(fill); tool.setSize(radius); - tool.setBrush(new ScatterBrush((int) points, (int) distance), "worldedit.brush.scatter", player); + Brush brush; + if (overlay) { + brush = new ScatterOverlayBrush((int) points, (int) distance); + } else { + brush = new ScatterBrush((int) points, (int) distance); + } + tool.setBrush(brush, "worldedit.brush.scatter", player); player.print(BBC.getPrefix() + BBC.BRUSH_SCATTER.f(radius, points)); }