From b56f6664d5ffd6d4c62266685be094b1efca5199 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 12 Mar 2017 05:51:56 +1100 Subject: [PATCH] Fix some pattern stuff --- .../com/boydti/fawe/object/brush/SplineBrush.java | 2 +- .../com/boydti/fawe/object/brush/TargetMode.java | 8 ++++---- .../boydti/fawe/object/extent/PatternTransform.java | 4 ++-- .../com/boydti/fawe/object/pattern/BiomePattern.java | 4 ++-- .../fawe/object/pattern/Linear3DBlockPattern.java | 6 +++--- .../fawe/object/pattern/LinearBlockPattern.java | 4 ++-- .../boydti/fawe/object/pattern/MaskedPattern.java | 10 +++++----- .../com/boydti/fawe/object/pattern/NoXPattern.java | 8 ++++---- .../com/boydti/fawe/object/pattern/NoYPattern.java | 8 ++++---- .../com/boydti/fawe/object/pattern/NoZPattern.java | 8 ++++---- .../boydti/fawe/object/pattern/OffsetPattern.java | 10 +++++----- .../boydti/fawe/object/pattern/PatternExtent.java | 10 +++++----- .../fawe/object/pattern/RandomOffsetPattern.java | 10 +++++----- .../boydti/fawe/object/pattern/RelativePattern.java | 12 ++++++------ .../object/pattern/SolidRandomOffsetPattern.java | 12 ++++++------ .../object/pattern/SurfaceRandomOffsetPattern.java | 12 ++++++------ .../main/java/com/sk89q/worldedit/EditSession.java | 9 ++++++--- .../sk89q/worldedit/function/block/BlockReplace.java | 2 +- .../worldedit/function/pattern/ClipboardPattern.java | 3 +-- .../worldedit/function/pattern/RandomPattern.java | 4 ++-- .../java/com/sk89q/worldedit/patterns/Pattern.java | 4 ++-- 21 files changed, 76 insertions(+), 74 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index ee65deb4..273464c5 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -73,7 +73,7 @@ public class SplineBrush implements Brush { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { - if (x != 0 || y != 0 && z != 0) { + if (x != 0 || y != 0 || z != 0) { Vector pos = new Vector(x, y, z); if (!directions.contains(pos)) { directions.add(pos); diff --git a/core/src/main/java/com/boydti/fawe/object/brush/TargetMode.java b/core/src/main/java/com/boydti/fawe/object/brush/TargetMode.java index 84a3547e..7e611327 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/TargetMode.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/TargetMode.java @@ -1,8 +1,8 @@ package com.boydti.fawe.object.brush; public enum TargetMode { - TARGET_BLOCK_RANGE, - FOWARD_POINT_PITCH, - TARGET_POINT_HEIGHT, - TARGET_FACE_RANGE, +TARGET_BLOCK_RANGE, +FOWARD_POINT_PITCH, +TARGET_POINT_HEIGHT, +TARGET_FACE_RANGE, } diff --git a/core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java b/core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java index adadab2b..2efd9ee6 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java @@ -16,6 +16,6 @@ public class PatternTransform extends ResettableExtent { @Override public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { - return pattern.apply(getExtent(), location); + return pattern.apply(getExtent(), location, location); } -} +} \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java index e7c9bd66..5f7a84ab 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java @@ -23,8 +23,8 @@ public class BiomePattern extends ExistingPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - return extent.setBiome(new Vector2D(position.getBlockX(), position.getBlockZ()), biome); + public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + return extent.setBiome(new Vector2D(setPosition.getBlockX(), setPosition.getBlockZ()), biome); } public class BiomePatternException extends RuntimeException { diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java index e357bbe2..f3f114f2 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java @@ -29,11 +29,11 @@ public class Linear3DBlockPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length; + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + int index = (get.getBlockX() + get.getBlockY() + get.getBlockZ()) % patternsArray.length; if (index < 0) { index += patternsArray.length; } - return patternsArray[index].apply(extent, position); + return patternsArray[index].apply(extent, set, get); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java index 3fee51ed..f7da63b3 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java @@ -29,11 +29,11 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { if (index == patternsArray.length) { index = 0; } - return patternsArray[index++].apply(extent, position); + return patternsArray[index++].apply(extent, set, get); } @Override diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java index 25e63d1b..8271e84b 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java @@ -35,11 +35,11 @@ public class MaskedPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - patternExtent.setTarget(position); - if (mask.test(position)) { - return patternExtent.getAndResetTarget(extent, position); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + patternExtent.setTarget(get); + if (mask.test(get)) { + return patternExtent.getAndResetTarget(extent, set, get); } - return secondaryPattern.apply(extent, position); + return secondaryPattern.apply(extent, set, get); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java index 7dcb4992..4e82ec25 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java @@ -26,9 +26,9 @@ public class NoXPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector pos) throws WorldEditException { - mutable.mutY((pos.getY())); - mutable.mutZ((pos.getZ())); - return pattern.apply(extent, mutable); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutY((get.getY())); + mutable.mutZ((get.getZ())); + return pattern.apply(extent, set, mutable); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java index 5769139c..8f00a2ae 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java @@ -26,9 +26,9 @@ public class NoYPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector pos) throws WorldEditException { - mutable.mutX((pos.getX())); - mutable.mutZ((pos.getZ())); - return pattern.apply(extent, mutable); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutX((get.getX())); + mutable.mutZ((get.getZ())); + return pattern.apply(extent, set, mutable); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java index 99a2cb62..72f2dafa 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java @@ -26,9 +26,9 @@ public class NoZPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector pos) throws WorldEditException { - mutable.mutX((pos.getX())); - mutable.mutY((pos.getY())); - return pattern.apply(extent, mutable); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutX((get.getX())); + mutable.mutY((get.getY())); + return pattern.apply(extent, set, mutable); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java index a86e86c5..e5ce4d80 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java @@ -30,10 +30,10 @@ public class OffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - mutable.mutX((position.getX() + dx)); - mutable.mutY((position.getY() + dy)); - mutable.mutZ((position.getZ() + dz)); - return pattern.apply(extent, mutable); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutX((get.getX() + dx)); + mutable.mutY((get.getY() + dy)); + mutable.mutZ((get.getZ() + dz)); + return pattern.apply(extent, set, mutable); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java b/core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java index 56af2d51..86164841 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java @@ -67,13 +67,13 @@ public class PatternExtent extends AbstractPattern implements Extent { this.target = vector; } - public boolean getAndResetTarget(Extent extent, Vector position) throws WorldEditException { + public boolean getAndResetTarget(Extent extent, Vector set, Vector get) throws WorldEditException { BaseBlock result = block; if (result != null) { block = null; - return extent.setBlock(position, result); + return extent.setBlock(set, result); } else { - return pattern.apply(extent, target); + return pattern.apply(extent, set, target); } } @@ -119,7 +119,7 @@ public class PatternExtent extends AbstractPattern implements Extent { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - return pattern.apply(extent, position); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + return pattern.apply(extent, set, get); } } diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java index d1062b81..798de693 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java @@ -35,10 +35,10 @@ public class RandomOffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); - mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); - mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); - return pattern.apply(extent, mutable); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutX((get.getX() + r.nextInt(dx2) - dx)); + mutable.mutY((get.getY() + r.nextInt(dy2) - dy)); + mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz)); + return pattern.apply(extent, set, mutable); } } \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java index 57617e41..d3dba982 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java @@ -31,14 +31,14 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter } @Override - public boolean apply(Extent extent, Vector pos) throws WorldEditException { + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { if (origin == null) { - origin = new Vector(pos); + origin = new Vector(get); } - mutable.mutX((pos.getX() - origin.getX())); - mutable.mutY((pos.getY() - origin.getY())); - mutable.mutZ((pos.getZ() - origin.getZ())); - return pattern.apply(extent, mutable); + mutable.mutX((get.getX() - origin.getX())); + mutable.mutY((get.getY() - origin.getY())); + mutable.mutZ((get.getZ() - origin.getZ())); + return pattern.apply(extent, set, mutable); } @Override diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java index 971b009f..10373d74 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java @@ -50,15 +50,15 @@ public class SolidRandomOffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); - mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); - mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutX((get.getX() + r.nextInt(dx2) - dx)); + mutable.mutY((get.getY() + r.nextInt(dy2) - dy)); + mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz)); BaseBlock block = pattern.apply(mutable); if (solid[FaweCache.getCombined(block)]) { - return pattern.apply(extent, mutable); + return pattern.apply(extent, set, mutable); } else { - return pattern.apply(extent, position); + return pattern.apply(extent, set, get); } } } \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java index 11278430..36dcf591 100644 --- a/core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java +++ b/core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java @@ -52,17 +52,17 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); - mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); - mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + mutable.mutX((get.getX() + r.nextInt(dx2) - dx)); + mutable.mutY((get.getY() + r.nextInt(dy2) - dy)); + mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz)); BaseBlock block = pattern.apply(mutable); if (solid[FaweCache.getCombined(block)]) { mutable.mutY(mutable.getY() + 1); if (!solid[FaweCache.getCombined(pattern.apply(mutable))]) { - return pattern.apply(extent, mutable); + return pattern.apply(extent, set, mutable); } } - return pattern.apply(extent, position); + return pattern.apply(extent, set, get); } } \ No newline at end of file diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 2735f993..8da155eb 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -180,6 +180,8 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting private FawePlayer player; private FaweChangeSet changeTask; + private MutableBlockVector mutable = new MutableBlockVector(); + private int changes = 0; private BlockBag blockBag; @@ -1108,7 +1110,8 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting public boolean setBlock(int x, int y, int z, Pattern pattern) { this.changes++; try { - return pattern.apply(extent, MutableBlockVector.get(x, y, z)); + mutable.setComponents(x, y, z); + return pattern.apply(extent, mutable, mutable); } catch (WorldEditException e) { throw new RuntimeException("Unexpected exception", e); } @@ -1132,7 +1135,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting public boolean setBlock(final Vector position, final Pattern pattern) throws MaxChangedBlocksException { this.changes++; try { - return pattern.apply(this.extent, position); + return pattern.apply(this.extent, position, position); } catch (WorldEditException e) { throw new RuntimeException(e); } @@ -2943,7 +2946,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting } } this.changes++; - pattern.apply(this.extent, position); + pattern.apply(this.extent, position, position); } } catch (WorldEditException e) { throw new RuntimeException(e); diff --git a/core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java b/core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java index 63379cd1..221dd22c 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java +++ b/core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java @@ -55,7 +55,7 @@ public class BlockReplace implements RegionFunction { @Override public boolean apply(Vector position) throws WorldEditException { - return pattern.apply(extent, position); + return pattern.apply(extent, position, position); } public static Class inject() { diff --git a/core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java b/core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java index c8a46cd2..7853c57a 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java +++ b/core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java @@ -16,6 +16,7 @@ public class ClipboardPattern extends AbstractPattern { private final Clipboard clipboard; private final int sx, sy, sz; private final Vector min; + private MutableBlockVector mutable = new MutableBlockVector(); /** * Create a new clipboard pattern. @@ -32,8 +33,6 @@ public class ClipboardPattern extends AbstractPattern { this.min = clipboard.getMinimumPoint(); } - private MutableBlockVector mutable = new MutableBlockVector(); - @Override public BaseBlock apply(Vector position) { int xp = position.getBlockX() % sx; diff --git a/core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java b/core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java index e035e9ee..fd6da837 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java +++ b/core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java @@ -43,8 +43,8 @@ public class RandomPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector position) throws WorldEditException { - return collection.next().apply(extent, position); + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + return collection.next().apply(extent, set, get); } private static class Chance { diff --git a/core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java b/core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java index a5ca040a..6e30a069 100644 --- a/core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java +++ b/core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java @@ -39,8 +39,8 @@ public interface Pattern{ */ public BaseBlock next(Vector position); - default boolean apply(Extent extent, Vector position) throws WorldEditException { - return extent.setBlock(position, next(position)); + default boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + return extent.setBlock(setPosition, next(getPosition)); } /**