9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2026-01-04 15:31:38 +00:00

Fix min/max of cuboid region vectors

This commit is contained in:
SamB440
2021-10-10 15:22:57 +01:00
parent 4b9a1679ef
commit 8eae49e10e

View File

@@ -1,6 +1,7 @@
package net.islandearth.rpgregions.api.integrations.rpgregions.region;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class CuboidRegion extends RPGRegionsRegion {
@@ -11,16 +12,16 @@ public class CuboidRegion extends RPGRegionsRegion {
@Override
public boolean isWithinBounds(Location location) {
if (getPoints().size() < 2) return false;
Location min = getPoints().get(0);
Location max = getPoints().get(1);
if (min.getY() > max.getY()) { // todo improve this
max = getPoints().get(0);
min = getPoints().get(1);
removePoint(max);
removePoint(min);
addPoint(min);
addPoint(max);
}
return location.toVector().isInAABB(getPoints().get(0).toVector(), getPoints().get(1).toVector());
Location first = getPoints().get(0);
Location second = getPoints().get(1);
final double x1 = first.getX();
final double x2 = second.getX();
final double y1 = first.getY();
final double y2 = second.getY();
final double z1 = first.getZ();
final double z2 = second.getZ();
Vector min = new Vector(Math.min(x1, x2), Math.min(y1, y2), Math.min(z1, z2));
Vector max = new Vector(Math.max(x1, x2), Math.max(y1, y2), Math.max(z1, z2));
return location.toVector().isInAABB(min, max);
}
}