Added easy locToBlock in Location

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-02-25 09:51:52 +00:00
parent f712d6011d
commit 54e0c4db29

View file

@ -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);
}
}