From cff2cc846a30a91aa7d563f4ec269928449e17fa Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 11 Mar 2017 21:10:58 +1100 Subject: [PATCH] Fix brush pattern reset + add offset transform --- .../boydti/fawe/object/brush/ScatterBrush.java | 2 -- .../object/extent/DefaultTransformParser.java | 15 +++++++++++++++ .../sk89q/worldedit/command/tool/BrushTool.java | 4 +++- .../extension/platform/PlatformManager.java | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) 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 f15a718d..ba067aba 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 @@ -40,8 +40,6 @@ public class ScatterBrush implements Brush { @Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { - // pick a bunch of random points - // expand randomly from them this.mask = editSession.getMask(); if (this.mask == null) { this.mask = Masks.alwaysTrue(); diff --git a/core/src/main/java/com/boydti/fawe/object/extent/DefaultTransformParser.java b/core/src/main/java/com/boydti/fawe/object/extent/DefaultTransformParser.java index 766d27e5..030a4c60 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/DefaultTransformParser.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/DefaultTransformParser.java @@ -75,6 +75,21 @@ public class DefaultTransformParser extends InputParser { Pattern pattern = worldEdit.getPatternFactory().parseFromInput(rest, context); return new PatternTransform(parent, pattern); } + case "#offset": { + try { + String[] split2 = component.split(":"); + double x = Math.abs(Expression.compile(split2[1]).evaluate()); + double y = Math.abs(Expression.compile(split2[2]).evaluate()); + double z = Math.abs(Expression.compile(split2[3]).evaluate()); + rest = rest.substring(Math.min(rest.length(), split2[1].length() + split2[2].length() + split2[3].length() + 3)); + if (!rest.isEmpty()) { + parent = parseFromInput(rest, context); + } + return new OffsetExtent(parent, (int) x, (int) y, (int) z); + } catch (NumberFormatException | ExpressionException e) { + throw new InputParseException("The correct format is #offset:::"); + } + } case "#scale": { try { String[] split2 = component.split(":"); diff --git a/core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index 13ae8f5e..90fd4322 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -13,6 +13,7 @@ import com.boydti.fawe.object.brush.visualization.VisualChunk; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.brush.visualization.VisualMode; import com.boydti.fawe.object.extent.ResettableExtent; +import com.boydti.fawe.object.pattern.PatternTraverser; import com.boydti.fawe.util.EditSessionBuilder; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; @@ -286,7 +287,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool BBC.NO_BLOCK.send(player); return true; } - BlockBag bag = session.getBlockBag(player); Request.request().setEditSession(editSession); if (current.mask != null) { @@ -319,6 +319,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool editSession.addTransform(current.transform); } try { + new PatternTraverser(current).reset(editSession); current.brush.build(editSession, target, current.material, current.size); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); // Never happens @@ -418,6 +419,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool } case OUTLINE: { BrushSettings current = getContext(); + new PatternTraverser(current).reset(editSession); current.brush.build(editSession, position, current.material, current.size); break; } diff --git a/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 7b4640d0..16777be3 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.command.tool.BlockTool; +import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.DoubleActionBlockTool; import com.sk89q.worldedit.command.tool.DoubleActionTraceTool; import com.sk89q.worldedit.command.tool.Tool; @@ -438,7 +439,11 @@ public class PlatformManager { fp.runAction(new Runnable() { @Override public void run() { - reset((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location); + if (tool instanceof BrushTool) { + ((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location); + } else { + reset((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location); + } } }, true, true); event.setCancelled(true);