diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-02-25 09:51:52 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-02-25 09:51:52 +0000 |
commit | bb4c973ada2802d3683b1572e768b30c1e90c025 (patch) | |
tree | a99856daec1edb82ed68d1b9bb9f9a27d0c6add8 /src | |
parent | a69e19a9f78fbbff7b8e0d0bddad93812270987d (diff) | |
download | bukkit-bb4c973ada2802d3683b1572e768b30c1e90c025.tar bukkit-bb4c973ada2802d3683b1572e768b30c1e90c025.tar.gz bukkit-bb4c973ada2802d3683b1572e768b30c1e90c025.tar.lz bukkit-bb4c973ada2802d3683b1572e768b30c1e90c025.tar.xz bukkit-bb4c973ada2802d3683b1572e768b30c1e90c025.zip |
Added easy locToBlock in Location
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/Location.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java index 2d24bded..250be215 100644 --- a/src/main/java/org/bukkit/Location.java +++ b/src/main/java/org/bukkit/Location.java @@ -98,7 +98,7 @@ public class Location implements Cloneable { * @return block X */ public int getBlockX() { - return (int)Math.floor(x); + return locToBlock(x); } /** @@ -126,7 +126,7 @@ public class Location implements Cloneable { * @return block y */ public int getBlockY() { - return (int)Math.floor(y); + return locToBlock(y); } /** @@ -154,7 +154,7 @@ public class Location implements Cloneable { * @return block z */ public int getBlockZ() { - return (int)Math.floor(z); + return locToBlock(z); } /** @@ -273,4 +273,14 @@ public class Location implements Cloneable { public Location clone() { return new Location(world, x, y, z, yaw, pitch); } + + /** + * Safely converts a double (location coordinate) to an int (block coordinate) + * + * @param loc Precise coordinate + * @return Block coordinate + */ + public static int locToBlock(double loc) { + return (int)Math.floor(loc); + } } |