From 158e51191f3c66fa74206f7f936f2fc4f4a8c107 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 31 Jan 2023 11:21:11 +0100 Subject: [PATCH] Linear Patterns require flooring division (#2079) Use floorDiv in linear patterns --- .../core/function/pattern/Linear2DBlockPattern.java | 5 ++++- .../core/function/pattern/Linear3DBlockPattern.java | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear2DBlockPattern.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear2DBlockPattern.java index 0762eb67c..7c923c4d4 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear2DBlockPattern.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear2DBlockPattern.java @@ -7,6 +7,8 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; +import static java.lang.Math.floorDiv; + public class Linear2DBlockPattern extends AbstractPattern { private final Pattern[] patternsArray; @@ -37,7 +39,8 @@ public class Linear2DBlockPattern extends AbstractPattern { @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - int index = (get.getBlockX() / this.xScale + get.getBlockZ() / this.zScale) % patternsArray.length; + int index = (floorDiv(get.getBlockX(), this.xScale) + + floorDiv(get.getBlockZ(), this.zScale)) % patternsArray.length; if (index < 0) { index += patternsArray.length; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear3DBlockPattern.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear3DBlockPattern.java index c132fbcdd..04028244d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear3DBlockPattern.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern/Linear3DBlockPattern.java @@ -7,6 +7,8 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; +import static java.lang.Math.floorDiv; + public class Linear3DBlockPattern extends AbstractPattern { private final Pattern[] patternsArray; @@ -41,8 +43,8 @@ public class Linear3DBlockPattern extends AbstractPattern { @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - int index = (get.getBlockX() / this.xScale - + get.getBlockY() / this.yScale + get.getBlockZ() / this.zScale) % patternsArray.length; + int index = (floorDiv(get.getBlockX(), this.xScale) + + floorDiv(get.getBlockY(), this.yScale) + floorDiv(get.getBlockZ(), this.zScale)) % patternsArray.length; if (index < 0) { index += patternsArray.length; }