From 54e0c4db29e8d2d6060f975d5a8d368a33e64185 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 25 Feb 2011 09:51:52 +0000 Subject: [PATCH] Added easy locToBlock in Location By: Dinnerbone --- paper-api/src/main/java/org/bukkit/Location.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/Location.java b/paper-api/src/main/java/org/bukkit/Location.java index 2d24bdeda0..250be21568 100644 --- a/paper-api/src/main/java/org/bukkit/Location.java +++ b/paper-api/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); + } }