Fix the long-range build tool's ability to build mid-air.

This commit is contained in:
wizjany 2019-03-01 19:29:34 -05:00
parent 0656ef1920
commit f46c70093c
2 changed files with 10 additions and 2 deletions

View File

@ -208,6 +208,9 @@ public class Location {
* @return the direction vector * @return the direction vector
*/ */
public Vector3 getDirection() { public Vector3 getDirection() {
if (Float.isNaN(getYaw()) && Float.isNaN(getPitch())) {
return Vector3.ZERO;
}
double yaw = Math.toRadians(this.getYaw()); double yaw = Math.toRadians(this.getYaw());
double pitch = Math.toRadians(this.getPitch()); double pitch = Math.toRadians(this.getPitch());
double xz = Math.cos(pitch); double xz = Math.cos(pitch);

View File

@ -189,11 +189,16 @@ public class TargetBlock {
public Location getAnyTargetBlockFace() { public Location getAnyTargetBlockFace() {
getAnyTargetBlock(); getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector())); Location current = getCurrentBlock();
if (current != null)
return current.setDirection(current.toVector().subtract(getPreviousBlock().toVector()));
else
return new Location(world, targetPos.toVector3(), Float.NaN, Float.NaN);
} }
public Location getTargetBlockFace() { public Location getTargetBlockFace() {
getAnyTargetBlock(); getTargetBlock();
if (getCurrentBlock() == null) return null;
return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector())); return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector()));
} }