mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
Added easy locToBlock in Location
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
f712d6011d
commit
54e0c4db29
1 changed files with 13 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue