Record Class TileCoord

java.lang.Object
java.lang.Record
io.hymods.lib.tiles.TileCoord
Record Components:
x - Tile X coordinate in world space
z - Tile Z coordinate in world space

public record TileCoord(int x, int z) extends Record
Represents a tile coordinate in world space. Tiles are fixed regions of the world, each covering TILE_SIZE_CHUNKS chunks.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    add(int dx, int dz)
    Add an offset to this tile coordinate.
    double
    centerBlockX(int tileSizeChunks)
    Get the center block X coordinate of this tile.
    double
    centerBlockZ(int tileSizeChunks)
    Get the center block Z coordinate of this tile.
    final boolean
    Indicates whether some other object is "equal to" this one.
    static TileCoord
    fromBlock(double blockX, double blockZ, int tileSizeChunks)
    Calculate the tile coordinate that contains a given block coordinate.
    static TileCoord
    fromChunk(int chunkX, int chunkZ, int tileSizeChunks)
    Calculate the tile coordinate that contains a given chunk coordinate.
    final int
    Returns a hash code value for this object.
    int
    maxChunkX(int tileSizeChunks)
    Get the maximum chunk X coordinate covered by this tile (inclusive).
    int
    maxChunkZ(int tileSizeChunks)
    Get the maximum chunk Z coordinate covered by this tile (inclusive).
    double
    minBlockX(int tileSizeChunks)
    Get the minimum block X coordinate of this tile.
    double
    minBlockZ(int tileSizeChunks)
    Get the minimum block Z coordinate of this tile.
    int
    minChunkX(int tileSizeChunks)
    Get the minimum chunk X coordinate covered by this tile.
    int
    minChunkZ(int tileSizeChunks)
    Get the minimum chunk Z coordinate covered by this tile.
    Calculate offset from another tile coordinate.
    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
  • Field Details

  • Constructor Details

    • TileCoord

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

    • fromChunk

      public static TileCoord fromChunk(int chunkX, int chunkZ, int tileSizeChunks)
      Calculate the tile coordinate that contains a given chunk coordinate.
      Parameters:
      chunkX - Chunk X coordinate
      chunkZ - Chunk Z coordinate
      tileSizeChunks - Size of each tile in chunks
      Returns:
      The tile coordinate containing this chunk
    • fromBlock

      public static TileCoord fromBlock(double blockX, double blockZ, int tileSizeChunks)
      Calculate the tile coordinate that contains a given block coordinate.
      Parameters:
      blockX - Block X coordinate
      blockZ - Block Z coordinate
      tileSizeChunks - Size of each tile in chunks
      Returns:
      The tile coordinate containing this block
    • minChunkX

      public int minChunkX(int tileSizeChunks)
      Get the minimum chunk X coordinate covered by this tile.
    • minChunkZ

      public int minChunkZ(int tileSizeChunks)
      Get the minimum chunk Z coordinate covered by this tile.
    • maxChunkX

      public int maxChunkX(int tileSizeChunks)
      Get the maximum chunk X coordinate covered by this tile (inclusive).
    • maxChunkZ

      public int maxChunkZ(int tileSizeChunks)
      Get the maximum chunk Z coordinate covered by this tile (inclusive).
    • centerBlockX

      public double centerBlockX(int tileSizeChunks)
      Get the center block X coordinate of this tile.
    • centerBlockZ

      public double centerBlockZ(int tileSizeChunks)
      Get the center block Z coordinate of this tile.
    • minBlockX

      public double minBlockX(int tileSizeChunks)
      Get the minimum block X coordinate of this tile.
    • minBlockZ

      public double minBlockZ(int tileSizeChunks)
      Get the minimum block Z coordinate of this tile.
    • offset

      public TileCoord offset(TileCoord other)
      Calculate offset from another tile coordinate.
      Parameters:
      other - The other tile coordinate
      Returns:
      A new TileCoord representing the offset (this - other)
    • add

      public TileCoord add(int dx, int dz)
      Add an offset to this tile coordinate.
      Parameters:
      dx - X offset
      dz - Z offset
      Returns:
      A new TileCoord with the offset applied
    • 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
    • hashCode

      public final 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
    • equals

      public final boolean equals(Object o)
      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:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • 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