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 Details

  • Method Details

    • add

      @NotNull public BlockPosition add​(int x, int y, int z)
      Adds offsets to this block position.
      Parameters:
      x - the X offset
      y - the Y offset
      z - the Z offset
      Returns:
      the instance of this block position
    • subtract

      @NotNull public BlockPosition subtract​(int x, int y, int z)
      Subtracts offsets to this block position.
      Parameters:
      x - the X offset
      y - the Y offset
      z - the Z offset
      Returns:
      the instance of this block position
    • add

      @NotNull public BlockPosition add​(@NotNull BlockPosition pos)
      Adds offsets to this block position.
      Parameters:
      pos - the pos to add
      Returns:
      the instance of this block position
    • subtract

      @NotNull public BlockPosition subtract​(@NotNull BlockPosition pos)
      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

      public int getManhattanDistance​(@NotNull BlockPosition blockPosition)
      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

      public double getDistance​(@NotNull BlockPosition blockPosition)
      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

      public int getDistanceSquared​(@NotNull BlockPosition blockPosition)
      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

      @NotNull public BlockPosition copy()
      Copies this block position.
      Returns:
      the cloned block position
    • toPosition

      @NotNull public Position toPosition()
      Converts this block position to a Position.
      Returns:
      the converted Position
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object