Fix BoundingBox Conversion

See #228
This commit is contained in:
Sn0wStorm
2019-12-13 22:16:17 +01:00
parent e7a77bf2a1
commit a9fedeab32
4 changed files with 19 additions and 5 deletions
+1
View File
@@ -36,6 +36,7 @@ public class BarrelBody {
if (bounds == null || bounds.area() > 64 ) { if (bounds == null || bounds.area() > 64 ) {
// If loading from old data, or block locations are missing, or other error, regenerate BoundingBox // If loading from old data, or block locations are missing, or other error, regenerate BoundingBox
// This will only be done in those extreme cases. // 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); Block broken = getBrokenBlock(true);
if (broken != null) { if (broken != null) {
barrel.remove(broken, null, true); barrel.remove(broken, null, true);
+8
View File
@@ -298,6 +298,10 @@ public class P extends JavaPlugin {
metrics.addCustomChart(new Metrics.SimplePie("v2_mc_version", () -> { metrics.addCustomChart(new Metrics.SimplePie("v2_mc_version", () -> {
String mcv = Bukkit.getBukkitVersion(); String mcv = Bukkit.getBukkitVersion();
mcv = mcv.substring(0, mcv.indexOf('.', 2)); 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}$")) { if (mcv.matches("^\\d\\.\\d{1,2}$")) {
// Start, digit, dot, 1-2 digits, end // Start, digit, dot, 1-2 digits, end
return mcv; return mcv;
@@ -309,6 +313,10 @@ public class P extends JavaPlugin {
Map<String, Map<String, Integer>> map = new HashMap<>(3); Map<String, Map<String, Integer>> map = new HashMap<>(3);
String mcv = Bukkit.getBukkitVersion(); String mcv = Bukkit.getBukkitVersion();
mcv = mcv.substring(0, mcv.indexOf('.', 2)); 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}$")) { if (mcv.matches("^\\d\\.\\d{1,2}$")) {
// Start, digit, dot, 1-2 digits, end // Start, digit, dot, 1-2 digits, end
mcv = "MC " + mcv; mcv = "MC " + mcv;
+5 -1
View File
@@ -337,7 +337,11 @@ public class BData {
System.arraycopy(wo, 0, points, st.length, woLength); System.arraycopy(wo, 0, points, st.length, woLength);
} }
int[] locs = ArrayUtils.toPrimitive(Arrays.stream(points).map(s -> P.p.parseInt(s)).toArray(Integer[]::new)); 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; Barrel b;
+5 -4
View File
@@ -28,8 +28,8 @@ public class BoundingBox {
return contains(block.getX(), block.getY(), block.getZ()); return contains(block.getX(), block.getY(), block.getZ());
} }
public int area() { public long area() {
return (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1); return ((long) (x2 - x1 + 1)) * ((long) (y2 - y1 + 1)) * ((long) (z2 - z1 + 1));
} }
public String serialize() { public String serialize() {
@@ -39,14 +39,15 @@ public class BoundingBox {
public static BoundingBox fromPoints(int[] locations) { public static BoundingBox fromPoints(int[] locations) {
if (locations.length % 3 != 0) throw new IllegalArgumentException("Locations has to be pairs of three"); 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, int minx = Integer.MAX_VALUE,
miny = Integer.MAX_VALUE, miny = Integer.MAX_VALUE,
minz = Integer.MAX_VALUE, minz = Integer.MAX_VALUE,
maxx = Integer.MIN_VALUE, maxx = Integer.MIN_VALUE,
maxy = Integer.MIN_VALUE, maxy = Integer.MIN_VALUE,
maxz = 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); minx = Math.min(locations[i], minx);
miny = Math.min(locations[i + 1], miny); miny = Math.min(locations[i + 1], miny);
minz = Math.min(locations[i + 2], minz); minz = Math.min(locations[i + 2], minz);