From 02a70cca4a9df46cfcd72a1b303c3ff1b558f6d1 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 31 Oct 2011 22:00:53 +0100 Subject: [PATCH] Added Pattern.next(int, int, int). This method can be used to avoid creating short-lived vectors in tight loops. --- .../worldedit/patterns/ClipboardPattern.java | 20 +++++++++++++++---- .../com/sk89q/worldedit/patterns/Pattern.java | 9 +++++++++ .../worldedit/patterns/RandomFillPattern.java | 4 ++++ .../patterns/SingleBlockPattern.java | 4 ++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java b/src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java index 23227cd9b..f0eeef808 100644 --- a/src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java +++ b/src/main/java/com/sk89q/worldedit/patterns/ClipboardPattern.java @@ -54,10 +54,22 @@ public class ClipboardPattern implements Pattern { * @return */ public BaseBlock next(Vector pos) { - int x = Math.abs(pos.getBlockX()) % size.getBlockX(); - int y = Math.abs(pos.getBlockY()) % size.getBlockY(); - int z = Math.abs(pos.getBlockZ()) % size.getBlockZ(); + return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + } - return clipboard.getPoint(new Vector(x, y, z)); + /** + * Get next block. + * + * @param x + * @param y + * @param z + * @return + */ + public BaseBlock next(int x, int y, int z) { + int xp = Math.abs(x) % size.getBlockX(); + int yp = Math.abs(y) % size.getBlockY(); + int zp = Math.abs(z) % size.getBlockZ(); + + return clipboard.getPoint(new Vector(xp, yp, zp)); } } diff --git a/src/main/java/com/sk89q/worldedit/patterns/Pattern.java b/src/main/java/com/sk89q/worldedit/patterns/Pattern.java index d5d84e4c6..5d3c2bab3 100644 --- a/src/main/java/com/sk89q/worldedit/patterns/Pattern.java +++ b/src/main/java/com/sk89q/worldedit/patterns/Pattern.java @@ -37,4 +37,13 @@ public interface Pattern { * @return */ public BaseBlock next(Vector pos); + + /** + * Get a block for a position. This return value of this method does + * not have to be consistent for the same position. + * + * @param pos + * @return + */ + public BaseBlock next(int x, int y, int z); } diff --git a/src/main/java/com/sk89q/worldedit/patterns/RandomFillPattern.java b/src/main/java/com/sk89q/worldedit/patterns/RandomFillPattern.java index dc418368e..bc0eaf90d 100644 --- a/src/main/java/com/sk89q/worldedit/patterns/RandomFillPattern.java +++ b/src/main/java/com/sk89q/worldedit/patterns/RandomFillPattern.java @@ -82,4 +82,8 @@ public class RandomFillPattern implements Pattern { throw new RuntimeException("ProportionalFillPattern"); } + + public BaseBlock next(int x, int y, int z) { + return next(null); + } } diff --git a/src/main/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java b/src/main/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java index 8caef32e4..1f7e3a800 100644 --- a/src/main/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java +++ b/src/main/java/com/sk89q/worldedit/patterns/SingleBlockPattern.java @@ -52,6 +52,10 @@ public class SingleBlockPattern implements Pattern { return block; } + public BaseBlock next(int x, int y, int z) { + return block; + } + /** * Get the block. *