Skip to content

Commit

Permalink
boundingboxes are forever
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsinco committed Dec 25, 2024
1 parent 7ce3a89 commit d6a92f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ val langVersion = 17
val encoding = "UTF-8"

group = "com.dre.brewery"
version = "3.4.5"
version = "3.4.6-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/com/dre/brewery/BarrelBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public abstract class BarrelBody {

protected final Block spigot;
protected BoundingBox bounds;
protected final BoundingBox bounds;
protected byte signoffset;

public BarrelBody(Block spigot, byte signoffset) {
Expand All @@ -65,17 +65,17 @@ public BarrelBody(Block spigot, byte signoffset) {
public BarrelBody(Block spigot, byte signoffset, BoundingBox bounds) {
this.spigot = spigot;
this.signoffset = signoffset;

if (boundsSeemBad(bounds)) {
this.bounds = bounds;
if (this.bounds == null || this.bounds.isBad()) {
// If loading from old data, or block locations are missing, or other error, regenerate BoundingBox
// This will only be done in those extreme cases.
if (!Bukkit.isPrimaryThread()) {
BreweryPlugin.getScheduler().runTask(spigot.getLocation(), this::regenerateBounds);
} else {

// Barrels can be loaded async!
if (Bukkit.isPrimaryThread()) {
this.regenerateBounds();
} else {
BreweryPlugin.getScheduler().runTask(spigot.getLocation(), this::regenerateBounds);
}
} else {
this.bounds = bounds;
}
}

Expand All @@ -89,7 +89,7 @@ public void destroySign() {
}

/**
* Quick check if the bounds are valid or seem corrupt
*
*/
public static boolean boundsSeemBad(BoundingBox bounds) {
if (bounds == null) return true;
Expand Down Expand Up @@ -295,13 +295,14 @@ public Block checkSBarrel() {
x = startX;
y++;
}
bounds = new BoundingBox(
bounds.resize(
spigot.getX() + startX,
spigot.getY(),
spigot.getZ() + startZ,
spigot.getX() + endX,
spigot.getY() + 1,
spigot.getZ() + endZ);
spigot.getZ() + endZ
);
return null;
}

Expand Down Expand Up @@ -369,14 +370,15 @@ public Block checkLBarrel() {
x = startX;
y++;
}
bounds = new BoundingBox(

bounds.resize(
spigot.getX() + startX,
spigot.getY(),
spigot.getZ() + startZ,
spigot.getX() + endX,
spigot.getY() + 2,
spigot.getZ() + endZ);

spigot.getZ() + endZ
);
return null;
}

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/dre/brewery/utility/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class BoundingBox {

private final int x1, y1, z1, x2, y2, z2;
private int x1, y1, z1, x2, y2, z2;

public BoundingBox(int x1, int y1, int z1, int x2, int y2, int z2) {
this.x1 = Math.min(x1, x2);
Expand All @@ -54,6 +54,21 @@ public long area() {
return ((long) (x2 - x1 + 1)) * ((long) (y2 - y1 + 1)) * ((long) (z2 - z1 + 1));
}

// Quick check if the bounds are valid or seem corrupt
public boolean isBad() {
long area = this.area();
return area > 64 || area < 4;
}

public void resize(int x1, int y1, int z1, int x2, int y2, int z2) {
this.x1 = Math.min(x1, x2);
this.y1 = Math.min(y1, y2);
this.z1 = Math.min(z1, z2);
this.x2 = Math.max(x2, x1);
this.y2 = Math.max(y2, y1);
this.z2 = Math.max(z2, z1);
}

public String serialize() {
return x1 + "," + y1 + "," + z1 + "," + x2 + "," + y2 + "," + z2;
}
Expand Down

0 comments on commit d6a92f9

Please sign in to comment.