Skip to content

Commit

Permalink
Sanitize min and max positions for main constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Sep 22, 2024
1 parent 96c6e94 commit 910f4be
Showing 1 changed file with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,37 @@ public class Bounds {
public Bounds() {
}

public Bounds(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;

this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
public Bounds(Position min, Position max) {
this(min.blockX(), min.blockY(), min.blockZ(), max.blockX(), max.blockY(), max.blockZ());
}

public Bounds(Position min, Position max) {
public Bounds(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
// Sanitize min max
if (min.blockX() > max.blockX()) {
int temp = min.blockX();
min = Position.block(max.blockX(), min.blockY(), min.blockZ());
max = Position.block(temp, max.blockY(), max.blockZ());
if (minX > maxX) {
int temp = minX;
minX = maxX;
maxX = temp;
}

if (min.blockY() > max.blockY()) {
int temp = min.blockY();
min = Position.block(min.blockX(), max.blockY(), min.blockZ());
max = Position.block(max.blockX(), temp, max.blockZ());
if (minY > maxY) {
int temp = minY;
minY = maxY;
maxY = temp;
}

if (min.blockZ() > max.blockZ()) {
int temp = min.blockZ();
min = Position.block(min.blockX(), min.blockY(), max.blockZ());
max = Position.block(max.blockX(), max.blockY(), temp);
if (minZ > maxZ) {
int temp = minZ;
minZ = maxZ;
maxZ = temp;
}

this.minX = min.blockX();
this.minY = min.blockY();
this.minZ = min.blockZ();
this.minX = minX;
this.minY = minY;
this.minZ = minZ;

this.maxX = max.blockX();
this.maxY = max.blockY();
this.maxZ = max.blockZ();
this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
}

public int getMinX() {
Expand Down

0 comments on commit 910f4be

Please sign in to comment.