Package net.minestom.server.utils
Class BlockPosition
java.lang.Object
net.minestom.server.utils.BlockPosition
public class BlockPosition
extends java.lang.Object
Represents the position of a block, so with integers instead of floating numbers.
-
Constructor Summary
Constructors Constructor Description BlockPosition(float x, float y, float z)
Creates a newBlockPosition
.BlockPosition(int x, int y, int z)
Creates a newBlockPosition
.BlockPosition(Vector position)
Creates a newBlockPosition
from aVector
. -
Method Summary
Modifier and Type Method Description BlockPosition
add(int x, int y, int z)
Adds offsets to this block position.BlockPosition
add(BlockPosition pos)
Adds offsets to this block position.BlockPosition
copy()
Copies this block position.boolean
equals(java.lang.Object o)
double
getDistance(BlockPosition blockPosition)
Gets the distance to another block position.int
getDistanceSquared(BlockPosition blockPosition)
Gets the square distance to another block position.int
getManhattanDistance(BlockPosition blockPosition)
Gets the manhattan distance to another block position.int
getX()
Gets the block X.int
getY()
Gets the block Y.int
getZ()
Gets the block Z.int
hashCode()
void
setX(int x)
Changes the X field.void
setY(int y)
Changes the Y field.void
setZ(int z)
Changes the Z field.BlockPosition
subtract(int x, int y, int z)
Subtracts offsets to this block position.BlockPosition
subtract(BlockPosition pos)
Subtracts offsets to this block position.Position
toPosition()
Converts this block position to aPosition
.java.lang.String
toString()
-
Constructor Details
-
BlockPosition
public BlockPosition(int x, int y, int z)Creates a newBlockPosition
.- Parameters:
x
- the block Xy
- the block Yz
- the block Z
-
BlockPosition
public BlockPosition(float x, float y, float z)Creates a newBlockPosition
.Float positions are converted to block position, notably used by
Position.toBlockPosition()
.- Parameters:
x
- the block Xy
- the block Yz
- the block Z
-
BlockPosition
Creates a newBlockPosition
from aVector
.- Parameters:
position
- the position vector- See Also:
BlockPosition(float, float, float)
-
-
Method Details
-
add
Adds offsets to this block position.- Parameters:
x
- the X offsety
- the Y offsetz
- the Z offset- Returns:
- the instance of this block position
-
subtract
Subtracts offsets to this block position.- Parameters:
x
- the X offsety
- the Y offsetz
- the Z offset- Returns:
- the instance of this block position
-
add
Adds offsets to this block position.- Parameters:
pos
- the pos to add- Returns:
- the instance of this block position
-
subtract
Subtracts offsets to this block position.- Parameters:
pos
- the pos to subtract- Returns:
- the instance of this block position
-
getX
public int getX()Gets the block X.- Returns:
- the block X
-
setX
public void setX(int x)Changes the X field.WARNING: this will not change the block position.
- Parameters:
x
- the new X field
-
getY
public int getY()Gets the block Y.- Returns:
- the block Y
-
setY
public void setY(int y)Changes the Y field.WARNING: this will not change the block position.
- Parameters:
y
- the new Y field
-
getZ
public int getZ()Gets the block Z.- Returns:
- the block Z
-
setZ
public void setZ(int z)Changes the Z field.WARNING: this will not change the block position.
- Parameters:
z
- the new Z field
-
getManhattanDistance
Gets the manhattan distance to another block position.- Parameters:
blockPosition
- the block position to check the distance- Returns:
- the distance between 'this' and
blockPosition
-
getDistance
Gets the distance to another block position. In cases where performance matters,getDistanceSquared(BlockPosition)
should be used as it does not perform the expensive Math.sqrt method.- Parameters:
blockPosition
- the block position to check the distance- Returns:
- the distance between 'this' and
blockPosition
-
getDistanceSquared
Gets the square distance to another block position.- Parameters:
blockPosition
- the block position to check the distance- Returns:
- the distance between 'this' and
blockPosition
-
copy
Copies this block position.- Returns:
- the cloned block position
-
toPosition
Converts this block position to aPosition
.- Returns:
- the converted
Position
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-