Skip to content

Commit

Permalink
Fix BoundingBox Conversion
Browse files Browse the repository at this point in the history
See #228
  • Loading branch information
Sn0wStorm committed Dec 13, 2019
1 parent e7a77bf commit a9fedea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/com/dre/brewery/BarrelBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public BarrelBody(Barrel barrel, byte signoffset, BoundingBox bounds) {
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);
Expand Down
8 changes: 8 additions & 0 deletions src/com/dre/brewery/P.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ private void setupMetrics() {
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;
Expand All @@ -309,6 +313,10 @@ private void setupMetrics() {
Map<String, Map<String, Integer>> 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;
Expand Down
6 changes: 5 additions & 1 deletion src/com/dre/brewery/filedata/BData.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ public static void loadWorldData(String uuid, World world, FileConfiguration dat
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;
Expand Down
9 changes: 5 additions & 4 deletions src/com/dre/brewery/utility/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public boolean contains(Block block) {
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() {
Expand All @@ -39,14 +39,15 @@ public String serialize() {
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);
Expand Down

0 comments on commit a9fedea

Please sign in to comment.