mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-21 14:39:01 +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
|
* @return block X
|
||||||
*/
|
*/
|
||||||
public int getBlockX() {
|
public int getBlockX() {
|
||||||
return (int)Math.floor(x);
|
return locToBlock(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +126,7 @@ public class Location implements Cloneable {
|
||||||
* @return block y
|
* @return block y
|
||||||
*/
|
*/
|
||||||
public int getBlockY() {
|
public int getBlockY() {
|
||||||
return (int)Math.floor(y);
|
return locToBlock(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,7 +154,7 @@ public class Location implements Cloneable {
|
||||||
* @return block z
|
* @return block z
|
||||||
*/
|
*/
|
||||||
public int getBlockZ() {
|
public int getBlockZ() {
|
||||||
return (int)Math.floor(z);
|
return locToBlock(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -273,4 +273,14 @@ public class Location implements Cloneable {
|
||||||
public Location clone() {
|
public Location clone() {
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
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…
Add table
Reference in a new issue