Class Tile

java.lang.Object
com.valhalla.sdk.api.math.Tile
All Implemented Interfaces:
Locatable

public final class Tile extends Object implements Locatable
Immutable world coordinate expressed as X, Y, and plane.

Distance helpers use Chebyshev distance unless their name explicitly refers to walking or squared Euclidean distance. Equality includes the plane.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    World plane, conventionally from 0 through 3.
    final int
    World X coordinate.
    final int
    World Y coordinate.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the origin tile (0, 0, 0).
    Tile(int x, int y)
    Creates a tile on plane zero.
    Tile(int x, int y, int plane)
    Creates a world tile.
  • Method Summary

    Modifier and Type
    Method
    Description
    Clones this coordinate.
    Copies this coordinate.
    int
    Measures direct distance to the local player.
    int
    distance(Tile other)
    Measures Chebyshev distance, ignoring plane.
    long
    Computes squared Euclidean X/Y distance without taking a square root.
    int
    Measures Chebyshev distance, ignoring plane.
    boolean
    equals(Object value)
     
    getArea(int radius)
    Creates an inclusive square area centered on this tile.
    int
    Returns the scene-local X coordinate.
    int
    Returns the scene-local Y coordinate.
    int
    Returns the world plane.
    Randomizes this tile with the default deviation.
    getRandomized(int deviation)
    Randomizes X and Y independently within an inclusive deviation.
    int
    Returns the map-region identifier.
    Returns this location as a tile.
    int
    Returns the world X coordinate.
    int
    Returns the world Y coordinate.
    int
    Returns the world plane using Z terminology.
    int
     
    boolean
    isWithinDistance(Tile other, int distance)
    Tests same-plane Chebyshev proximity.
     
    translate(int deltaX, int deltaY)
    Translates X and Y while retaining the plane.
    translate(int deltaX, int deltaY, int deltaPlane)
    Translates all three coordinates.
    translate(Tile delta)
    Treats another tile as an X/Y/plane offset.
    int
    Returns exact local collision distance when available, otherwise a conservative estimate.
    withPlane(int newPlane)
    Changes only this coordinate's plane.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.valhalla.sdk.api.entities.Locatable

    canReach, canReach, isInArea
  • Field Details

    • x

      public final int x
      World X coordinate.
    • y

      public final int y
      World Y coordinate.
    • plane

      public final int plane
      World plane, conventionally from 0 through 3.
  • Constructor Details

    • Tile

      public Tile()
      Creates the origin tile (0, 0, 0).
    • Tile

      public Tile(int x, int y)
      Creates a tile on plane zero.
      Parameters:
      x - world X coordinate
      y - world Y coordinate
    • Tile

      public Tile(int x, int y, int plane)
      Creates a world tile.
      Parameters:
      x - world X coordinate
      y - world Y coordinate
      plane - world plane
  • Method Details

    • getX

      public int getX()
      Returns the world X coordinate.
      Specified by:
      getX in interface Locatable
      Returns:
      world X coordinate
    • getY

      public int getY()
      Returns the world Y coordinate.
      Specified by:
      getY in interface Locatable
      Returns:
      world Y coordinate
    • getPlane

      public int getPlane()
      Returns the world plane.
      Specified by:
      getPlane in interface Locatable
      Returns:
      world plane
    • getZ

      public int getZ()
      Returns the world plane using Z terminology.
      Specified by:
      getZ in interface Locatable
      Returns:
      world plane; alias for getPlane()
    • getTile

      public Tile getTile()
      Returns this location as a tile.
      Specified by:
      getTile in interface Locatable
      Returns:
      this immutable tile
    • copy

      public Tile copy()
      Copies this coordinate.
      Returns:
      a distinct tile with the same coordinates
    • clone

      public Tile clone()
      Clones this coordinate.
      Overrides:
      clone in class Object
      Returns:
      a distinct tile with the same coordinates
    • translate

      public Tile translate(int deltaX, int deltaY)
      Translates X and Y while retaining the plane.
      Parameters:
      deltaX - X offset
      deltaY - Y offset
      Returns:
      translated tile
    • translate

      public Tile translate(Tile delta)
      Treats another tile as an X/Y/plane offset.
      Parameters:
      delta - coordinate offsets
      Returns:
      translated tile
    • translate

      public Tile translate(int deltaX, int deltaY, int deltaPlane)
      Translates all three coordinates.
      Parameters:
      deltaX - X offset
      deltaY - Y offset
      deltaPlane - plane offset
      Returns:
      translated tile
    • withPlane

      public Tile withPlane(int newPlane)
      Changes only this coordinate's plane.
      Parameters:
      newPlane - replacement plane
      Returns:
      tile with unchanged X/Y and the supplied plane
    • getArea

      public Area getArea(int radius)
      Creates an inclusive square area centered on this tile.
      Parameters:
      radius - non-negative tile radius
      Returns:
      square area on this tile's plane
    • getGridX

      public int getGridX()
      Returns the scene-local X coordinate.
      Specified by:
      getGridX in interface Locatable
      Returns:
      scene-local X coordinate relative to the current scene base
    • getGridY

      public int getGridY()
      Returns the scene-local Y coordinate.
      Specified by:
      getGridY in interface Locatable
      Returns:
      scene-local Y coordinate relative to the current scene base
    • getRandomized

      public Tile getRandomized()
      Randomizes this tile with the default deviation.
      Returns:
      a tile randomized by at most two tiles on each axis
    • getRandomized

      public Tile getRandomized(int deviation)
      Randomizes X and Y independently within an inclusive deviation.
      Parameters:
      deviation - non-negative maximum axis offset
      Returns:
      randomized tile on the same plane
    • distanceTo

      public int distanceTo(Tile other)
      Measures Chebyshev distance, ignoring plane.
      Specified by:
      distanceTo in interface Locatable
      Parameters:
      other - comparison tile
      Returns:
      maximum absolute X/Y difference
    • distance

      public int distance()
      Measures direct distance to the local player.
      Specified by:
      distance in interface Locatable
      Returns:
      Chebyshev distance to the current local player tile
    • distance

      public int distance(Tile other)
      Measures Chebyshev distance, ignoring plane.
      Parameters:
      other - comparison tile
      Returns:
      maximum absolute X/Y difference
    • walkingDistance

      public int walkingDistance(Tile other)
      Returns exact local collision distance when available, otherwise a conservative estimate.
      Specified by:
      walkingDistance in interface Locatable
      Parameters:
      other - destination tile
      Returns:
      path length, or three times Chebyshev distance when no exact route is available
    • distanceSquaredTo

      public long distanceSquaredTo(Tile other)
      Computes squared Euclidean X/Y distance without taking a square root.
      Parameters:
      other - comparison tile
      Returns:
      squared X/Y distance as a long
    • isWithinDistance

      public boolean isWithinDistance(Tile other, int distance)
      Tests same-plane Chebyshev proximity.
      Specified by:
      isWithinDistance in interface Locatable
      Parameters:
      other - comparison tile
      distance - inclusive, non-negative radius
      Returns:
      true when the plane matches and distance is within the radius
    • getRegionId

      public int getRegionId()
      Returns the map-region identifier.
      Specified by:
      getRegionId in interface Locatable
      Returns:
      packed 64-by-64 map-region identifier
    • equals

      public boolean equals(Object value)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object