Class ChunkKey

java.lang.Object
net.paulem.arcana.regions.ChunkKey

public class ChunkKey extends Object
Represents the coordinates of a chunk, identified by its x and z chunk coordinates. Provides utility methods for converting to and from chunks, locations, block coordinates, and a compact packed-long representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Packs this key's x and z coordinates into a single long value, suitable for use as a compact map key or for reconstruction via fromLong(long).
    int
    Computes the Manhattan distance, in chunks, between this key and another.
    boolean
    Compares this key to another object for equality based on chunk x and z coordinates.
    static ChunkKey
    fromChunk(org.bukkit.Chunk chunk)
    Creates a ChunkKey from the coordinates of the given chunk.
    static ChunkKey
    fromCoordinates(int x, int z)
    Creates a ChunkKey from block coordinates, converting them to chunk coordinates.
    static ChunkKey
    fromLocation(org.bukkit.Location location)
    Creates a ChunkKey for the chunk containing the given location.
    static ChunkKey
    fromLong(long key)
    Creates a ChunkKey from a packed long representation, as produced by asLong().
    int
     
    int
     
    int
     
    int
     
    getRelative(int x, int z)
    Creates a new ChunkKey offset from this one by the given amount of chunks.
    int
     
    boolean
    isInChunk(org.bukkit.Chunk chunk)
    Checks whether this key refers to the same coordinates as the given chunk.
    org.bukkit.Chunk
    toChunk(org.bukkit.World world)
    Resolves this key to the actual Chunk in the given world.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • fromChunk

      public static ChunkKey fromChunk(org.bukkit.Chunk chunk)
      Creates a ChunkKey from the coordinates of the given chunk.
      Parameters:
      chunk - the chunk to create the key from
      Returns:
      a new ChunkKey matching the chunk's coordinates
    • fromLocation

      public static ChunkKey fromLocation(org.bukkit.Location location)
      Creates a ChunkKey for the chunk containing the given location.
      Parameters:
      location - the location to derive the chunk coordinates from
      Returns:
      a new ChunkKey for the chunk containing the location
    • fromCoordinates

      public static ChunkKey fromCoordinates(int x, int z)
      Creates a ChunkKey from block coordinates, converting them to chunk coordinates.
      Parameters:
      x - the block x coordinate
      z - the block z coordinate
      Returns:
      a new ChunkKey for the chunk containing the given block coordinates
    • fromLong

      public static ChunkKey fromLong(long key)
      Creates a ChunkKey from a packed long representation, as produced by asLong().
      Parameters:
      key - the packed chunk coordinates
      Returns:
      a new ChunkKey decoded from the packed value
    • getChunkX

      public int getChunkX()
      Returns:
      the x coordinate of the chunk
    • getChunkZ

      public int getChunkZ()
      Returns:
      the z coordinate of the chunk
    • isInChunk

      public boolean isInChunk(org.bukkit.Chunk chunk)
      Checks whether this key refers to the same coordinates as the given chunk.
      Parameters:
      chunk - the chunk to compare against
      Returns:
      true if the chunk has the same x and z coordinates as this key
    • getRelative

      public ChunkKey getRelative(int x, int z)
      Creates a new ChunkKey offset from this one by the given amount of chunks.
      Parameters:
      x - the x offset, in chunks
      z - the z offset, in chunks
      Returns:
      a new ChunkKey relative to this one
    • distanceTo

      public int distanceTo(ChunkKey other)
      Computes the Manhattan distance, in chunks, between this key and another.
      Parameters:
      other - the other chunk key
      Returns:
      the sum of the absolute differences of the x and z chunk coordinates
    • getBlockX

      public int getBlockX()
      Returns:
      the block x coordinate of this chunk's origin (its minimum x coordinate)
    • getBlockZ

      public int getBlockZ()
      Returns:
      the block z coordinate of this chunk's origin (its minimum z coordinate)
    • equals

      public boolean equals(Object o)
      Compares this key to another object for equality based on chunk x and z coordinates.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare against
      Returns:
      true if the object is a ChunkKey with the same coordinates
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      a hash code derived from the chunk x and z coordinates
    • toChunk

      public org.bukkit.Chunk toChunk(org.bukkit.World world)
      Resolves this key to the actual Chunk in the given world.
      Parameters:
      world - the world to resolve the chunk in
      Returns:
      the chunk at this key's coordinates in the given world
    • asLong

      public long asLong()
      Packs this key's x and z coordinates into a single long value, suitable for use as a compact map key or for reconstruction via fromLong(long).
      Returns:
      the packed representation of this chunk key
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representation of this chunk key, including its x and z coordinates