From f46c70093ce42a0b82368f97d9e9ff518cc301ef Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 1 Mar 2019 19:29:34 -0500 Subject: [PATCH] Fix the long-range build tool's ability to build mid-air. --- .../src/main/java/com/sk89q/worldedit/util/Location.java | 3 +++ .../main/java/com/sk89q/worldedit/util/TargetBlock.java | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java index 8e95e9eb0..ea161111b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java @@ -208,6 +208,9 @@ public class Location { * @return the direction vector */ public Vector3 getDirection() { + if (Float.isNaN(getYaw()) && Float.isNaN(getPitch())) { + return Vector3.ZERO; + } double yaw = Math.toRadians(this.getYaw()); double pitch = Math.toRadians(this.getPitch()); double xz = Math.cos(pitch); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index 60c979dee..9d0cf2baa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -189,11 +189,16 @@ public class TargetBlock { public Location getAnyTargetBlockFace() { 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() { - getAnyTargetBlock(); + getTargetBlock(); + if (getCurrentBlock() == null) return null; return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector())); }