public class Location extends java.lang.Object implements java.lang.Cloneable, ConfigurationSerializable
Vector
重合的).
这里的翻译分别取偏航角、俯仰角.另请参见util包下的Vector(向量)、EulerAngle(欧拉角), 阅读本文档及其相关文档
建议您具备高中数学必修4相关知识.构造器和说明 |
---|
Location(World world,
double x,
double y,
double z)
以给定的坐标构造一个Location对象.
|
Location(World world,
double x,
double y,
double z,
float yaw,
float pitch)
以给定的坐标和朝向构造一个Location对象.
|
限定符和类型 | 方法和说明 |
---|---|
Location |
add(double x,
double y,
double z)
将本位置的坐标加上另一个位置的坐标.
|
Location |
add(Location vec)
将本位置的坐标加上另一个位置的坐标.
|
Location |
add(Vector vec)
将本位置的坐标加上一个向量的坐标.
|
void |
checkFinite()
检测该Location的xyz坐标和偏航角、俯仰角是否合法
(限制的最大值为Double.MAX_VALUE).
|
Location |
clone() |
static Location |
deserialize(java.util.Map<java.lang.String,java.lang.Object> args)
实现配置序列化与反序列化所需方法.
|
double |
distance(Location o)
获取本位置与与另一个位置之间的距离.
|
double |
distanceSquared(Location o)
获取本位置与与另一个位置之间的距离的平方.
|
boolean |
equals(java.lang.Object obj) |
Block |
getBlock()
获取本位置对应的方块.
|
int |
getBlockX()
获取向下取整的x轴坐标, 表示本位置包含的方块.
|
int |
getBlockY()
获取向下取整的y轴坐标, 表示本位置包含的方块.
|
int |
getBlockZ()
获取向下取整的z轴坐标, 表示本位置包含的方块.
|
Chunk |
getChunk()
获取此位置位于哪一区块.
|
Vector |
getDirection()
获取本位置所面向的方向的单位向量.
|
float |
getPitch()
获取本位置的俯仰角(pitch), 以度为单位.
|
World |
getWorld()
获取本位置所在的世界.
|
double |
getX()
获取本位置的x轴坐标.
|
double |
getY()
获取本位置的y轴坐标.
|
float |
getYaw()
获取本位置的偏航角(yaw), 以度为单位.
|
double |
getZ()
获取本位置的z坐标轴.
|
int |
hashCode() |
double |
length()
获取位置的模值,定义为 sqrt(x^2+y^2+z^2).
|
double |
lengthSquared()
获取位置长度(又称模)的平方 (三个坐标分别平方然后加起来).
|
static int |
locToBlock(double loc)
把double类型数值(位置坐标)安全地转换为int类型数值(方块坐标).
|
Location |
multiply(double m)
坐标数乘, 将所有坐标轴上扩展某个倍数.
|
java.util.Map<java.lang.String,java.lang.Object> |
serialize()
Creates a Map representation of this class.
|
Location |
setDirection(Vector vector)
|
void |
setPitch(float pitch)
设置本位置的俯仰角(pitch), 以度为单位.
|
void |
setWorld(World world)
设置本位置所在的世界.
|
void |
setX(double x)
设置本位置的x轴坐标.
|
void |
setY(double y)
设置本位置的y轴坐标.
|
void |
setYaw(float yaw)
设置本位置的偏航角(yaw), 以度为单位.
|
void |
setZ(double z)
设置本位置的z坐标轴.
|
Location |
subtract(double x,
double y,
double z)
从本位置的坐标中减去另一个位置的坐标.
|
Location |
subtract(Location vec)
将本位置的坐标减去另一个位置的坐标.
|
Location |
subtract(Vector vec)
从本位置的坐标中减去向量的坐标.
|
java.lang.String |
toString() |
Vector |
toVector()
基于此位置构造一个新的
向量 . |
Location |
zero()
清零此位置的xyz坐标数值.
|
public Location(World world, double x, double y, double z)
原文:Constructs a new Location with the given coordinates
world
- 位置所在世界x
- 位置x轴坐标y
- 位置y轴坐标z
- 位置z轴坐标public Location(World world, double x, double y, double z, float yaw, float pitch)
原文:Constructs a new Location with the given coordinates and direction
world
- 位置所在世界x
- 位置x轴坐标y
- 位置y轴坐标z
- 位置z轴坐标yaw
- x轴平面上的绝对的旋转角度, 以度为单位pitch
- y轴平面上的绝对的旋转角度, 以度为单位public void setWorld(World world)
原文:Sets the world that this location resides in
world
- 位置所在的新世界public World getWorld()
原文:Gets the world that this location resides in
public Chunk getChunk()
原文:Gets the chunk at the represented location
public Block getBlock()
原文:Gets the block at the represented location
public void setX(double x)
原文:Sets the x-coordinate of this location
x
- x轴坐标public double getX()
原文:Gets the x-coordinate of this location
public int getBlockX()
原文:Gets the floored value of the X component, indicating the block that this location is contained with.
public void setY(double y)
原文:Sets the y-coordinate of this location
y
- y轴坐标public double getY()
原文:Gets the y-coordinate of this location
public int getBlockY()
原文:Gets the floored value of the Y component, indicating the block that this location is contained with.
public void setZ(double z)
原文:Sets the z-coordinate of this location
z
- z坐标轴public double getZ()
原文:Gets the z-coordinate of this location
public int getBlockZ()
原文:Gets the floored value of the Z component, indicating the block that this location is contained with.
public void setYaw(float yaw)
原文:Sets the yaw of this location, measured in degrees.
yaw
- 自转角(偏航角)public float getYaw()
原文:Gets the yaw of this location, measured in degrees.
public void setPitch(float pitch)
原文:Sets the pitch of this location, measured in degrees.
pitch
- 倾斜角(俯仰角)public float getPitch()
原文:Gets the pitch of this location, measured in degrees.
public Vector getDirection()
原文:Gets a unit-vector pointing in the direction that this Location is facing.
public Location setDirection(Vector vector)
vector
- 方向向量public Location add(Location vec)
原文:Adds the location by another.
vec
- 另一个位置java.lang.IllegalArgumentException
- 若两个位置所处世界各不相同Vector
public Location add(Vector vec)
原文:Adds the location by a vector.
vec
- 向量Vector
public Location add(double x, double y, double z)
原文:Adds the location by another. Not world-aware.
x
- X坐标y
- Y坐标z
- Z坐标Vector
public Location subtract(Location vec)
原文:Subtracts the location by another.
vec
- 另一个位置java.lang.IllegalArgumentException
- 若两个位置所处世界各不相同Vector
public Location subtract(Vector vec)
原文:Subtracts the location by a vector.
vec
- 向量Vector
public Location subtract(double x, double y, double z)
原文:Subtracts the location by another. Not world-aware and orientation independent.
x
- X coordinatey
- Y coordinatez
- Z coordinateVector
public double length()
Double.NaN
.
与位置所处世界无关且其方向角独立不参与运算.
原文:Gets the magnitude of the location, defined as sqrt(x^2+y^2+z^2). The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the location's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long. Not world-aware and orientation independent.
Vector
public double lengthSquared()
原文:Gets the magnitude of the location squared. Not world-aware and orientation independent.
Vector
public double distance(Location o)
Double.NaN
.
原文:Get the distance between this location and another. The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the location's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the distance is too long.
o
- The other locationjava.lang.IllegalArgumentException
- for differing worldsVector
public double distanceSquared(Location o)
原文:Get the squared distance between this location and another.
o
- 另一个位置java.lang.IllegalArgumentException
- 若两个位置所处世界各不相同Vector
public Location multiply(double m)
原文:Performs scalar multiplication, multiplying all components with a scalar. Not world-aware.
m
- 因数,即数乘的倍数,整数Vector
public Location zero()
原文:Zero this location's components. Not world-aware.
Vector
public boolean equals(java.lang.Object obj)
equals
在类中 java.lang.Object
public int hashCode()
hashCode
在类中 java.lang.Object
public java.lang.String toString()
toString
在类中 java.lang.Object
public Vector toVector()
public Location clone()
clone
在类中 java.lang.Object
public void checkFinite() throws java.lang.IllegalArgumentException
原文:Check if each component of this Location is finite.
java.lang.IllegalArgumentException
- 若有任意一个坐标/角度值不合法时抛出public static int locToBlock(double loc)
原文:Safely converts a double (location coordinate) to an int (block coordinate)
loc
- 精确坐标public java.util.Map<java.lang.String,java.lang.Object> serialize()
ConfigurationSerializable
This class must provide a method to restore this class, as defined in
the ConfigurationSerializable
interface javadocs.
serialize
在接口中 ConfigurationSerializable
public static Location deserialize(java.util.Map<java.lang.String,java.lang.Object> args)
原文:Required method for deserialization
args
- 需要反序列化的mapjava.lang.IllegalArgumentException
- 如果位置所处世界不存在ConfigurationSerializable