From e9250d6e7cc0dc77e4bbf1c93ac09b4d008a9992 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 4 Mar 2017 22:07:03 +1100 Subject: [PATCH] Add flag for copy brush random rotate --- build.gradle | 2 +- .../com/boydti/fawe/object/brush/CopyPastaBrush.java | 10 +++++++++- .../com/sk89q/worldedit/command/BrushCommands.java | 9 +++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 6283b4ec..4e13926e 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext { date = git.head().date.format("yy.MM.dd") revision = "-${git.head().abbreviatedId}" parents = git.head().parentIds; - index = -76; // Offset to mach CI + index = -77; // Offset to mach CI int major, minor, patch; major = minor = patch = 0; for (;parents != null && !parents.isEmpty();index++) { diff --git a/core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java index 8d9eb668..c50d7068 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java @@ -2,6 +2,7 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FawePlayer; +import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.clipboard.ResizableClipboardBuilder; import com.boydti.fawe.object.function.NullRegionFunction; @@ -20,6 +21,7 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; @@ -27,11 +29,13 @@ public class CopyPastaBrush implements Brush, ResettableTool { private final BrushTool tool; private final LocalSession session; + private final boolean randomRotate; - public CopyPastaBrush(BrushTool tool, LocalSession session) { + public CopyPastaBrush(BrushTool tool, LocalSession session, boolean randomRotate) { this.tool = tool; session.setClipboard(null); this.session = session; + this.randomRotate = randomRotate; } @Override @@ -82,6 +86,10 @@ public class CopyPastaBrush implements Brush, ResettableTool { BBC.COMMAND_COPY.send(fp, blocks); return; } else { + if (randomRotate) { + int rotate = 90 * PseudoRandom.random.nextInt(4); + clipboard.setTransform(rotate != 0 ? new AffineTransform().rotateY(rotate) : new AffineTransform()); + } Clipboard faweClip = clipboard.getClipboard(); Region region = faweClip.getRegion(); Vector centerOffset = region.getCenter().subtract(faweClip.getOrigin()); 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 d0ad5b8d..2c7e78ca 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -401,7 +401,7 @@ public class BrushCommands { max = 2 ) @CommandPermissions("worldedit.brush.sphere") - public void circleBrush(Player player, LocalSession session, Pattern fill, @Optional("5") double radius, @Switch('h') boolean hollow) throws WorldEditException { + public void circleBrush(Player player, LocalSession session, Pattern fill, @Optional("5") double radius) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player.getItemInHand(), player); tool.setSize(radius); @@ -760,16 +760,17 @@ public class BrushCommands { desc = "Copy Paste brush", help = "Left click the base of an object to copy.\n" + - "Right click to paste", + "Right click to paste\n" + + "The -r flag Will apply random rotation on paste", min = 0, max = 1 ) @CommandPermissions("worldedit.brush.copy") - public void copy(Player player, LocalSession session, @Optional("5") double radius) throws WorldEditException { + public void copy(Player player, LocalSession session, @Optional("5") double radius, @Switch('r') boolean rotate) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player.getItemInHand(), player); tool.setSize(radius); - tool.setBrush(new CopyPastaBrush(tool, session), "worldedit.brush.copy", player); + tool.setBrush(new CopyPastaBrush(tool, session, rotate), "worldedit.brush.copy", player); player.print(BBC.getPrefix() + BBC.BRUSH_COPY.f(radius)); }