Package net.paulem.arcana.regions
Class ChunkKey
java.lang.Object
net.paulem.arcana.regions.ChunkKey
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 TypeMethodDescriptionlongasLong()Packs this key's x and z coordinates into a single long value, suitable for use as a compact map key or for reconstruction viafromLong(long).intdistanceTo(ChunkKey other) Computes the Manhattan distance, in chunks, between this key and another.booleanCompares this key to another object for equality based on chunk x and z coordinates.static ChunkKeyfromChunk(org.bukkit.Chunk chunk) Creates aChunkKeyfrom the coordinates of the given chunk.static ChunkKeyfromCoordinates(int x, int z) Creates aChunkKeyfrom block coordinates, converting them to chunk coordinates.static ChunkKeyfromLocation(org.bukkit.Location location) Creates aChunkKeyfor the chunk containing the given location.static ChunkKeyfromLong(long key) Creates aChunkKeyfrom a packed long representation, as produced byasLong().intintintintgetRelative(int x, int z) Creates a newChunkKeyoffset from this one by the given amount of chunks.inthashCode()booleanisInChunk(org.bukkit.Chunk chunk) Checks whether this key refers to the same coordinates as the given chunk.org.bukkit.ChunktoChunk(org.bukkit.World world) Resolves this key to the actualChunkin the given world.toString()
-
Method Details
-
fromChunk
Creates aChunkKeyfrom the coordinates of the given chunk.- Parameters:
chunk- the chunk to create the key from- Returns:
- a new
ChunkKeymatching the chunk's coordinates
-
fromLocation
Creates aChunkKeyfor the chunk containing the given location.- Parameters:
location- the location to derive the chunk coordinates from- Returns:
- a new
ChunkKeyfor the chunk containing the location
-
fromCoordinates
Creates aChunkKeyfrom block coordinates, converting them to chunk coordinates.- Parameters:
x- the block x coordinatez- the block z coordinate- Returns:
- a new
ChunkKeyfor the chunk containing the given block coordinates
-
fromLong
Creates aChunkKeyfrom a packed long representation, as produced byasLong().- Parameters:
key- the packed chunk coordinates- Returns:
- a new
ChunkKeydecoded 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:
trueif the chunk has the same x and z coordinates as this key
-
getRelative
Creates a newChunkKeyoffset from this one by the given amount of chunks.- Parameters:
x- the x offset, in chunksz- the z offset, in chunks- Returns:
- a new
ChunkKeyrelative to this one
-
distanceTo
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
Compares this key to another object for equality based on chunk x and z coordinates. -
hashCode
public int hashCode() -
toChunk
public org.bukkit.Chunk toChunk(org.bukkit.World world) Resolves this key to the actualChunkin 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 viafromLong(long).- Returns:
- the packed representation of this chunk key
-
toString
-