From be44e1449cdf1b9692c3f23af235e5974136408a Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 11 Dec 2020 11:34:56 +0000 Subject: [PATCH] remove mutability in clipboards (particularly clipboard pattern) fixes #776 --- .../fawe/object/clipboard/CPUOptimizedClipboard.java | 8 +------- .../fawe/object/clipboard/DiskOptimizedClipboard.java | 3 +-- .../fawe/object/clipboard/MemoryOptimizedClipboard.java | 7 +------ .../function/pattern/RepeatingExtentPattern.java | 4 +--- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index 859b3a233..944fb5446 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -116,14 +116,8 @@ public class CPUOptimizedClipboard extends LinearClipboard { return nbtMapIndex.get(index); } - private int yLast; - private int yLastI; - private int zLast; - private int zLastI; - public int getIndex(int x, int y, int z) { - return x + ((yLast == y) ? yLastI : (yLastI = (yLast = y) * getArea())) + ((zLast == z) ? zLastI - : (zLastI = (zLast = z) * getWidth())); + return x + y * getArea() + z * getWidth(); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index aa2160029..c7100a531 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -324,8 +324,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable } public int getIndex(int x, int y, int z) { - return x + (ylast == y ? ylasti : (ylasti = (ylast = y) * getArea())) + (zlast == z - ? zlasti : (zlasti = (zlast = z) * getWidth())); + return x + y * getArea() + z * getWidth(); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 341fa7d4e..766057964 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -193,13 +193,8 @@ public class MemoryOptimizedClipboard extends LinearClipboard { return nbtMap.values(); } - private int ylast; - private int ylasti; - private int zlast; - private int zlasti; - public int getIndex(int x, int y, int z) { - return x + ((ylast == y) ? ylasti : (ylasti = (ylast = y) * getArea())) + ((zlast == z) ? zlasti : (zlasti = (zlast = z) * getWidth())); + return x + y * getArea() + z * getWidth(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java index e39051981..e4d5488ef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java @@ -32,7 +32,6 @@ import static com.google.common.base.Preconditions.checkNotNull; public class RepeatingExtentPattern extends AbstractExtentPattern { private final BlockVector3 size; - private final MutableBlockVector3 mutable; private BlockVector3 origin; private BlockVector3 offset; @@ -47,7 +46,6 @@ public class RepeatingExtentPattern extends AbstractExtentPattern { setOrigin(origin); setOffset(offset); size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1); - this.mutable = new MutableBlockVector3(); } /** @@ -93,7 +91,7 @@ public class RepeatingExtentPattern extends AbstractExtentPattern { int x = Math.abs(position.getX() + offset.getX()) % size.getBlockX() + origin.getX(); int y = Math.abs(position.getY() + offset.getY()) % size.getBlockY() + origin.getY(); int z = Math.abs(position.getZ() + offset.getZ()) % size.getBlockZ() + origin.getZ(); - return getExtent().getFullBlock(mutable.setComponents(x, y, z)); + return getExtent().getFullBlock(x, y, z); } }