Record Class ChunkLocation

java.lang.Object
java.lang.Record
dev.wyck.misc.ChunkLocation
Record Components:
x - the chunk x coordinate
z - the chunk z coordinate

@NullMarked @AsOf("2.0.0") public record ChunkLocation(int x, int z) extends Record
A chunk location, represented as (x, z) chunk coordinates.
Since:
0.0.6
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChunkLocation(int x, int z)
    Creates an instance of a ChunkLocation record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the center block of this chunk in the given world.
    boolean
    Indicates whether some other object is "equal to" this one.
    fromBlockCoords(int blockX, int blockZ)
    Creates a ChunkLocation from block coordinates.
    Gets the biome of the center block of this chunk in the given world.
    int
    Returns a hash code value for this object.
    boolean
    isChunk(int chunkX, int chunkZ)
    Checks if this ChunkLocation matches the given chunk coordinates.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use isChunk(Chunk) or isChunk(int, int) instead.
    boolean
    isChunk(Chunk bukkitChunk)
    Checks if this ChunkLocation matches the given Bukkit Chunk.
    boolean
    isWithinRadius(ChunkLocation other, int radius)
    Checks if this ChunkLocation is within a certain radius of another ChunkLocation.
    Negates the chunk coordinates.
    of(int chunkX, int chunkZ)
    Creates a ChunkLocation from chunk coordinates.
    offset(int offsetX, int offsetZ)
    Offsets this ChunkLocation by the given x and z offsets.
    Offsets this ChunkLocation by another ChunkLocation.
    Converts this ChunkLocation to a Bukkit Chunk in the given world.
    Returns a string representation of this record class.
    int
    x()
    Returns the value of the x record component.
    int
    z()
    Returns the value of the z record component.

    Methods inherited from class Object

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

    • ChunkLocation

      public ChunkLocation(int x, int z)
      Creates an instance of a ChunkLocation record class.
      Parameters:
      x - the value for the x record component
      z - the value for the z record component
  • Method Details

    • of

      @AsOf("0.0.6") public static ChunkLocation of(int chunkX, int chunkZ)
      Creates a ChunkLocation from chunk coordinates.
      Parameters:
      chunkX - the chunk x coordinate
      chunkZ - the chunk z coordinate
      Returns:
      a ChunkLocation representing the given chunk coordinates
    • fromBlockCoords

      @AsOf("0.0.6") public static ChunkLocation fromBlockCoords(int blockX, int blockZ)
      Creates a ChunkLocation from block coordinates.
      Parameters:
      blockX - the block x coordinate
      blockZ - the block z coordinate
      Returns:
      a ChunkLocation representing the chunk containing the given block coordinates
    • isChunk

      @AsOf("0.0.6") public boolean isChunk(Chunk bukkitChunk)
      Checks if this ChunkLocation matches the given Bukkit Chunk.
      Parameters:
      bukkitChunk - the Bukkit Chunk to compare
      Returns:
      true if the coordinates match, false otherwise
    • isChunk

      @AsOf("0.0.6") public boolean isChunk(int chunkX, int chunkZ)
      Checks if this ChunkLocation matches the given chunk coordinates.
      Parameters:
      chunkX - the chunk x coordinate to compare
      chunkZ - the chunk z coordinate to compare
      Returns:
      true if the coordinates match, false otherwise
    • isChunk

      @Deprecated(forRemoval=true, since="2.0.0") public boolean isChunk(Object obj)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isChunk(Chunk) or isChunk(int, int) instead.
      Throws:
      UnsupportedOperationException - always
    • isWithinRadius

      @AsOf("0.0.11") public boolean isWithinRadius(ChunkLocation other, int radius)
      Checks if this ChunkLocation is within a certain radius of another ChunkLocation.
      Parameters:
      other - the other ChunkLocation to compare
      radius - the radius to check within
      Returns:
      true if this ChunkLocation is within the radius of the other, false otherwise
    • offset

      @AsOf("0.0.11") public ChunkLocation offset(int offsetX, int offsetZ)
      Offsets this ChunkLocation by the given x and z offsets.
      Parameters:
      offsetX - the x offset
      offsetZ - the z offset
      Returns:
      a new ChunkLocation with the offset applied
    • offset

      @AsOf("0.0.11") public ChunkLocation offset(ChunkLocation offset)
      Offsets this ChunkLocation by another ChunkLocation.
      Parameters:
      offset - the ChunkLocation to offset by
      Returns:
      a new ChunkLocation with the offset applied
    • negate

      @AsOf("0.0.11") public ChunkLocation negate()
      Negates the chunk coordinates.
      Returns:
      a new ChunkLocation with negated x and z coordinates
    • toBukkitChunk

      @AsOf("1.2.0") public CompletableFuture<Chunk> toBukkitChunk(World world)
      Converts this ChunkLocation to a Bukkit Chunk in the given world.
      Parameters:
      world - the world to get the chunk from
      Returns:
      the Bukkit Chunk at this ChunkLocation in the given world
    • centerBlock

      @AsOf("1.2.0") public CompletableFuture<Block> centerBlock(World world)
      Gets the center block of this chunk in the given world.
      Parameters:
      world - the world to get the block from
      Returns:
      the center block of this chunk in the given world
    • getCenterBiome

      @AsOf("1.2.0") public CompletableFuture<Biome> getCenterBiome(World world)
      Gets the biome of the center block of this chunk in the given world.
      Parameters:
      world - the world to get the biome from
      Returns:
      the biome of the center block of this chunk in the given world
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • x

      public int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • z

      public int z()
      Returns the value of the z record component.
      Returns:
      the value of the z record component