Skip to content

Commit

Permalink
fixed offset sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
kurrycat committed Apr 21, 2023
1 parent 32d4e2b commit 35f0492
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ public boolean isTryingToLandOn() {
return playerBB.minY() < boundingBox.maxY() && playerBB.minY() >= boundingBox.minY() && playerBB.minY() < lastPlayerBB.minY();
}

private double calculateOffsetDist(Vector3D offset) {
double xSign = Math.signum(offset.getX());
double zSign = Math.signum(offset.getZ());

if(xSign <= 0 && zSign >= 0) {
return offset.getX();
} else if(xSign >= 0 && zSign <= 0) {
return offset.getZ();
} else if(xSign <= 0 && zSign <= 0) {
return -offset.lengthXZ();
} else {
return offset.lengthXZ();
}
}

public Vector3D saveOffsetIfInRange() {
if (!isTryingToLandOn()) return null;
BoundingBox3D playerBB = landingMode.getPlayerBB();
Expand All @@ -58,23 +73,8 @@ public Vector3D saveOffsetIfInRange() {
offsets.remove(0);

if (pb == null) pb = offset;
else {
//TODO: find a way to tell which offset is better than another


//not working
Vector3D diff = Vector3D.ZERO;
Vector3D testVec = Math.signum(pb.getX()) != Math.signum(offset.getX()) && Math.signum(pb.getZ()) != Math.signum(offset.getZ())
? pb.mult(-1) : pb;
if (testVec.signXZ() > 0 && offset.signXZ() > 0)
diff = offset.sub(testVec);
else if (Math.signum(offset.getZ()) == Math.signum(testVec.getZ()))
diff = new Vector3D(offset.getX() - testVec.getX(), 0, 0);
else if (Math.signum(offset.getX()) == Math.signum(testVec.getX()))
diff = new Vector3D(0, 0, offset.getZ() - testVec.getZ());

if (diff.getX() + diff.getZ() > 0)
pb = offset;
else if(calculateOffsetDist(offset) > calculateOffsetDist(pb)){
pb = offset;
}
if (pbX == null || offset.getX() > pbX.getX()) pbX = offset;
if (pbZ == null || offset.getZ() > pbZ.getZ()) pbZ = offset;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/github/kurrycat/mpkmod/util/Vector3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public double length() {
return Math.sqrt(lengthSqr());
}

public double lengthXZ() {
return Math.sqrt(lengthXZSqr());
}

@Override
public String toString() {
return "[" + x + ", " + y + ", " + z + "]";
Expand Down

0 comments on commit 35f0492

Please sign in to comment.