Class BlockUtils

java.lang.Object
net.paulem.arcana.utils.BlockUtils

public class BlockUtils extends Object
Utility methods for working with blocks and locations, such as enumerating nearby locations, walking between two points, and converting block faces to vectors.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.util.Vector
    faceToVector(org.bukkit.block.BlockFace face)
    Converts a BlockFace to a unit vector pointing in that direction.
    static org.bukkit.util.Vector
    faceToVector(org.bukkit.block.BlockFace face, int distance)
    Converts a BlockFace to a vector pointing in that direction, scaled by distance.
    static List<org.bukkit.Location>
    getBlocksAround(org.bukkit.Location center, int radiusX, int radiusY, int radiusZ)
    Returns every location inside the cuboid centered on center, extending radiusX, radiusY and radiusZ blocks on each axis (inclusive).
    static List<org.bukkit.block.Block>
    getBlocksBetween(org.bukkit.Location loc1, org.bukkit.Location loc2)
    Walks from loc1 towards loc2 and collects the blocks encountered along the way.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BlockUtils

      public BlockUtils()
  • Method Details

    • getBlocksAround

      public static List<org.bukkit.Location> getBlocksAround(org.bukkit.Location center, int radiusX, int radiusY, int radiusZ)
      Returns every location inside the cuboid centered on center, extending radiusX, radiusY and radiusZ blocks on each axis (inclusive). The center location itself is included in the result.
      Parameters:
      center - the center of the cuboid
      radiusX - the radius on the X axis
      radiusY - the radius on the Y axis
      radiusZ - the radius on the Z axis
      Returns:
      the list of locations contained in the cuboid
    • getBlocksBetween

      public static List<org.bukkit.block.Block> getBlocksBetween(org.bukkit.Location loc1, org.bukkit.Location loc2)
      Walks from loc1 towards loc2 and collects the blocks encountered along the way. The straight-line distance between the two locations is split into unit-length steps, and the block at each step is added to the result until the block at loc2 is reached or the computed number of steps is exhausted. If both locations are at the same position, a single-element list containing that block is returned.
      Parameters:
      loc1 - the starting location
      loc2 - the ending location
      Returns:
      the list of blocks encountered while walking from loc1 to loc2
    • faceToVector

      public static org.bukkit.util.Vector faceToVector(org.bukkit.block.BlockFace face)
      Converts a BlockFace to a unit vector pointing in that direction.
      Parameters:
      face - the block face to convert
      Returns:
      a vector of length 1 pointing towards face
    • faceToVector

      public static org.bukkit.util.Vector faceToVector(org.bukkit.block.BlockFace face, int distance)
      Converts a BlockFace to a vector pointing in that direction, scaled by distance.
      Parameters:
      face - the block face to convert
      distance - the length to scale the resulting vector to
      Returns:
      a vector pointing towards face, scaled by distance