From a9fedeab327a4b1c4ebfdee11f2bf4a5c6590e0d Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 13 Dec 2019 22:16:17 +0100 Subject: [PATCH] Fix BoundingBox Conversion See #228 --- src/com/dre/brewery/BarrelBody.java | 1 + src/com/dre/brewery/P.java | 8 ++++++++ src/com/dre/brewery/filedata/BData.java | 6 +++++- src/com/dre/brewery/utility/BoundingBox.java | 9 +++++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/com/dre/brewery/BarrelBody.java b/src/com/dre/brewery/BarrelBody.java index da0c617..279c29a 100644 --- a/src/com/dre/brewery/BarrelBody.java +++ b/src/com/dre/brewery/BarrelBody.java @@ -36,6 +36,7 @@ public class BarrelBody { if (bounds == null || bounds.area() > 64 ) { // If loading from old data, or block locations are missing, or other error, regenerate BoundingBox // This will only be done in those extreme cases. + P.p.log("Regenerating Barrel BoundingBox: " + (bounds == null ? "was null" : "area=" + bounds.area())); Block broken = getBrokenBlock(true); if (broken != null) { barrel.remove(broken, null, true); diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index eef6c95..8ef2bea 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -298,6 +298,10 @@ public class P extends JavaPlugin { metrics.addCustomChart(new Metrics.SimplePie("v2_mc_version", () -> { String mcv = Bukkit.getBukkitVersion(); mcv = mcv.substring(0, mcv.indexOf('.', 2)); + int index = mcv.indexOf('-'); + if (index > -1) { + mcv = mcv.substring(0, index); + } if (mcv.matches("^\\d\\.\\d{1,2}$")) { // Start, digit, dot, 1-2 digits, end return mcv; @@ -309,6 +313,10 @@ public class P extends JavaPlugin { Map> map = new HashMap<>(3); String mcv = Bukkit.getBukkitVersion(); mcv = mcv.substring(0, mcv.indexOf('.', 2)); + int index = mcv.indexOf('-'); + if (index > -1) { + mcv = mcv.substring(0, index); + } if (mcv.matches("^\\d\\.\\d{1,2}$")) { // Start, digit, dot, 1-2 digits, end mcv = "MC " + mcv; diff --git a/src/com/dre/brewery/filedata/BData.java b/src/com/dre/brewery/filedata/BData.java index 37e4263..6b8cac3 100644 --- a/src/com/dre/brewery/filedata/BData.java +++ b/src/com/dre/brewery/filedata/BData.java @@ -337,7 +337,11 @@ public class BData { System.arraycopy(wo, 0, points, st.length, woLength); } int[] locs = ArrayUtils.toPrimitive(Arrays.stream(points).map(s -> P.p.parseInt(s)).toArray(Integer[]::new)); - box = BoundingBox.fromPoints(locs); + try { + box = BoundingBox.fromPoints(locs); + } catch (Exception e) { + e.printStackTrace(); + } } Barrel b; diff --git a/src/com/dre/brewery/utility/BoundingBox.java b/src/com/dre/brewery/utility/BoundingBox.java index a9160b7..7b95615 100644 --- a/src/com/dre/brewery/utility/BoundingBox.java +++ b/src/com/dre/brewery/utility/BoundingBox.java @@ -28,8 +28,8 @@ public class BoundingBox { return contains(block.getX(), block.getY(), block.getZ()); } - public int area() { - return (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1); + public long area() { + return ((long) (x2 - x1 + 1)) * ((long) (y2 - y1 + 1)) * ((long) (z2 - z1 + 1)); } public String serialize() { @@ -39,14 +39,15 @@ public class BoundingBox { public static BoundingBox fromPoints(int[] locations) { if (locations.length % 3 != 0) throw new IllegalArgumentException("Locations has to be pairs of three"); - int length = locations.length / 3; + int length = locations.length - 2; + int minx = Integer.MAX_VALUE, miny = Integer.MAX_VALUE, minz = Integer.MAX_VALUE, maxx = Integer.MIN_VALUE, maxy = Integer.MIN_VALUE, maxz = Integer.MIN_VALUE; - for (int i = 0; i < length; i++) { + for (int i = 0; i < length; i += 3) { minx = Math.min(locations[i], minx); miny = Math.min(locations[i + 1], miny); minz = Math.min(locations[i + 2], minz);