Class ChunkUtil

java.lang.Object
com.hypixel.hytale.math.util.ChunkUtil

public class ChunkUtil extends Object
A util for chunk's, chunk index packing and unpacking
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
    Deprecated.
    Limit only applies to legacy storage/world gens.
    static final int
    Deprecated.
    Limit only applies to legacy storage/world gens.
    static final int
    Deprecated.
    Limit only applies to legacy storage/world gens.
    static final int
    Deprecated.
    Limit only applies to legacy storage/world gens.
    static final int
    Theoretical inclusive maximum chunk coordinate such that worldCoordFromLocalCoord(int, int) does not under or overflow for inputs chunkCoord=MAX_CHUNK_COORD and localCoord=[0,32).
    static final int
    Theoretical inclusive minimum chunk coordinate such that worldCoordFromLocalCoord(int, int) does not under or overflow for inputs chunkCoord=MIN_CHUNK_COORD and localCoord=[0,32).
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final long
     
    static final int
     
    static final int
     
    static final int
     
    static final int
    Deprecated.
    Limit only applies to legacy storage/world gens.
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    chunkCoordinate(double block)
    Gets the chunk coordinate for the given block coordinate.
    static int
    chunkCoordinate(int block)
    Gets the chunk coordinate for the given block coordinate.
    static int
    chunkCoordinate(long block)
    Gets the chunk coordinate for the given block coordinate.
    static int
    indexBlock(int x, int y, int z)
    Gets the block index for the given X, Y, and Z coordinates.
    static int
    indexBlockFromColumn(int column, int y)
    Gets the block index from the given column index and Y coordinate.
    static long
    indexChunk(int x, int z)
    Transform the provided chunk (x, z) coordinates into a chunk index.
    static long
    indexChunkFromBlock(double blockX, double blockZ)
    Transform the provided block (x, z) coordinates into a chunk index.
    static long
    indexChunkFromBlock(int blockX, int blockZ)
    Transform the provided block (x, z) coordinates into a chunk index.
    static int
    indexColumn(int x, int z)
    Returns the column index for the given X and Z coordinates.
    static int
    indexSection(int y)
    Gets the section index for the given Y coordinate.
    static byte[]
    intToByteArray(int[] data)
    Converts an int array to a byte array in little-endian order.
    static boolean
    isBorderBlock(int x, int z)
    Checks if the given local chunk coordinates are on the border of the chunk.
    static boolean
    isBorderBlockGlobal(int x, int z)
    Checks if the given global block coordinates are on the border of the chunk.
    static boolean
    isInsideChunk(int chunkX, int chunkZ, int x, int z)
    Checks if the given block coordinates are inside the specified chunk.
    static boolean
    isInsideChunkRelative(int x, int z)
    Checks if the given relative chunk coordinates are inside the chunk bounds.
    static boolean
    isSameChunk(int x0, int z0, int x1, int z1)
    Checks if the two sets of block coordinates are in the same chunk.
    static boolean
    isSameChunkSection(int x0, int y0, int z0, int x1, int y1, int z1)
    Checks if the two sets of block coordinates are in the same chunk section.
    static boolean
    isValidChunkCoord(int chunkCoord)
    Determines if the given chunk coordinate is within the theoretical min/max coordinate range for chunks.
    static boolean
    isValidChunkCoords(int chunkCoordX, int chunkCoordZ)
    Determines if the give chunk coordinate components both lie within the theoretical min/max coordinate range for chunks.
    static boolean
    isValidChunkIndex(long chunkIndex)
    Determines if the coordinate components of the given chunk index both lie within the theoretical min/max coordinate range for chunks.
    static boolean
    isWithinLocalChunk(int x, int z)
    Checks if the given local chunk coordinates are within the chunk bounds.
    static int
    Gets the local coordinate within a chunk for the given value.
    static int
    maxBlock(int index)
    Gets the maximum block coordinate for the given chunk index.
    static int
    minBlock(int index)
    Gets the minimum block coordinate for the given chunk index.
    static byte[]
    shortToByteArray(short[] data)
    Converts a short array to a byte array in little-endian order.
    static int
    worldCoordFromLocalCoord(int chunkCoord, int localCoord)
    Translate a local coord within a chunk to a world coord.
    static int
    xFromColumn(int index)
    Gets the x coordinate from a column index.
    static int
    xFromIndex(int index)
    Gets the X coordinate from a block index.
    static int
    xOfChunkIndex(long index)
    Gets the x coordinate from a chunk index.
    static int
    yFromIndex(int index)
    Gets the y coordinate from a block index.
    static int
    zFromColumn(int index)
    Gets the Z coordinate from a column index.
    static int
    zFromIndex(int index)
    Gets the z coordinate from a block index.
    static int
    zOfChunkIndex(long index)
    Gets the z coordinate from a chunk index.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BITS

      public static final int BITS
      See Also:
    • SIZE

      public static final int SIZE
      See Also:
    • SIZE_2

      public static final int SIZE_2
      See Also:
    • SIZE_MINUS_1

      public static final int SIZE_MINUS_1
      See Also:
    • SIZE_MASK

      public static final int SIZE_MASK
      See Also:
    • SIZE_COLUMNS

      public static final int SIZE_COLUMNS
      See Also:
    • SIZE_COLUMNS_MASK

      public static final int SIZE_COLUMNS_MASK
      See Also:
    • SIZE_BLOCKS

      public static final int SIZE_BLOCKS
      See Also:
    • SIZE_BLOCKS_MASK

      public static final int SIZE_BLOCKS_MASK
      See Also:
    • BITS2

      public static final int BITS2
      See Also:
    • NON_CHUNK_MASK

      public static final int NON_CHUNK_MASK
      See Also:
    • HEIGHT_SECTIONS

      @Deprecated public static final int HEIGHT_SECTIONS
      Deprecated.
      Limit only applies to legacy storage/world gens. You shouldn't assume this limit anymore and instead check for null section references.
      See Also:
    • HEIGHT

      @Deprecated public static final int HEIGHT
      Deprecated.
      Limit only applies to legacy storage/world gens. You shouldn't assume this limit anymore and instead check for null section references.
      See Also:
    • HEIGHT_MINUS_1

      @Deprecated public static final int HEIGHT_MINUS_1
      Deprecated.
      Limit only applies to legacy storage/world gens. You shouldn't assume this limit anymore and instead check for null section references.
      See Also:
    • HEIGHT_MASK

      @Deprecated public static final int HEIGHT_MASK
      Deprecated.
      Limit only applies to legacy storage/world gens. You shouldn't assume this limit anymore and instead check for null section references.
    • SIZE_BLOCKS_COLUMN

      @Deprecated public static final int SIZE_BLOCKS_COLUMN
      Deprecated.
      Limit only applies to legacy storage/world gens. You shouldn't assume this limit anymore and instead check for null section references.
      See Also:
    • NOT_FOUND

      public static final long NOT_FOUND
    • MIN_Y

      public static final int MIN_Y
      See Also:
    • MIN_ENTITY_Y

      public static final int MIN_ENTITY_Y
      See Also:
    • MIN_SECTION

      public static final int MIN_SECTION
      See Also:
    • MIN_CHUNK_COORD

      public static final int MIN_CHUNK_COORD
      Theoretical inclusive minimum chunk coordinate such that worldCoordFromLocalCoord(int, int) does not under or overflow for inputs chunkCoord=MIN_CHUNK_COORD and localCoord=[0,32).

      Note: The practical minimum chunk coordinate that systems throughout the engine actually support may be much higher than this value.

      See Also:
    • MAX_CHUNK_COORD

      public static final int MAX_CHUNK_COORD
      Theoretical inclusive maximum chunk coordinate such that worldCoordFromLocalCoord(int, int) does not under or overflow for inputs chunkCoord=MAX_CHUNK_COORD and localCoord=[0,32).

      Note: The practical maximum chunk coordinate that systems throughout the engine actually support may be much lower than this value.

      See Also:
  • Method Details

    • shortToByteArray

      public static byte[] shortToByteArray(@Nonnull short[] data)
      Converts a short array to a byte array in little-endian order.
      Parameters:
      data - The short array to convert.
      Returns:
      the resulting byte array.
    • intToByteArray

      public static byte[] intToByteArray(@Nonnull int[] data)
      Converts an int array to a byte array in little-endian order.
      Parameters:
      data - The int array to convert.
      Returns:
      the resulting byte array.
    • indexColumn

      public static int indexColumn(int x, int z)
      Returns the column index for the given X and Z coordinates.
      Parameters:
      x - The X coordinate.
      z - The Z coordinate.
      Returns:
      the column index.
    • xFromColumn

      public static int xFromColumn(int index)
      Gets the x coordinate from a column index.
      Parameters:
      index - The column index.
      Returns:
      the x coordinate from the column index.
    • zFromColumn

      public static int zFromColumn(int index)
      Gets the Z coordinate from a column index.
      Parameters:
      index - The column index.
      Returns:
      the Z coordinate from the column index.
    • indexSection

      public static int indexSection(int y)
      Gets the section index for the given Y coordinate.
      Parameters:
      y - The Y coordinate.
      Returns:
      the section index.
    • indexBlockFromColumn

      public static int indexBlockFromColumn(int column, int y)
      Gets the block index from the given column index and Y coordinate.
      Parameters:
      column - The column index.
      y - The Y coordinate.
      Returns:
      the block index.
    • indexBlock

      public static int indexBlock(int x, int y, int z)
      Gets the block index for the given X, Y, and Z coordinates.
      Parameters:
      x - The X coordinate.
      y - The Y coordinate.
      z - The Z coordinate.
      Returns:
      the block index.
    • xFromIndex

      public static int xFromIndex(int index)
      Gets the X coordinate from a block index.
      Parameters:
      index - The block index.
      Returns:
      the X coordinate from the block index.
    • yFromIndex

      public static int yFromIndex(int index)
      Gets the y coordinate from a block index.
      Parameters:
      index - The block index.
      Returns:
      the Y coordinate from the block index.
    • zFromIndex

      public static int zFromIndex(int index)
      Gets the z coordinate from a block index.
      Parameters:
      index - The block index.
      Returns:
      the Z coordinate from the block index.
    • localCoordinate

      public static int localCoordinate(long v)
      Gets the local coordinate within a chunk for the given value.
      Parameters:
      v - The value to get the local coordinate for.
      Returns:
      the local coordinate within a chunk.
    • chunkCoordinate

      public static int chunkCoordinate(double block)
      Gets the chunk coordinate for the given block coordinate.
      Parameters:
      block - The block coordinate.
      Returns:
      the chunk coordinate.
    • chunkCoordinate

      public static int chunkCoordinate(int block)
      Gets the chunk coordinate for the given block coordinate.
      Parameters:
      block - The block coordinate.
      Returns:
      the chunk coordinate.
    • chunkCoordinate

      public static int chunkCoordinate(long block)
      Gets the chunk coordinate for the given block coordinate.
      Parameters:
      block - The block coordinate.
      Returns:
      the chunk coordinate.
    • minBlock

      public static int minBlock(int index)
      Gets the minimum block coordinate for the given chunk index.
      Parameters:
      index - The chunk index.
      Returns:
      the minimum block coordinate for the chunk index.
    • maxBlock

      public static int maxBlock(int index)
      Gets the maximum block coordinate for the given chunk index.
      Parameters:
      index - The chunk index.
      Returns:
      the maximum block coordinate for the chunk index.
    • isWithinLocalChunk

      public static boolean isWithinLocalChunk(int x, int z)
      Checks if the given local chunk coordinates are within the chunk bounds.
      Parameters:
      x - The local X coordinate.
      z - The local Z coordinate.
      Returns:
      true if the coordinates are within the chunk bounds, false otherwise.
    • isBorderBlock

      public static boolean isBorderBlock(int x, int z)
      Checks if the given local chunk coordinates are on the border of the chunk.
      Parameters:
      x - The local X coordinate.
      z - The local Z coordinate.
      Returns:
      true if the coordinates are on the border of the chunk, false otherwise.
    • isBorderBlockGlobal

      public static boolean isBorderBlockGlobal(int x, int z)
      Checks if the given global block coordinates are on the border of the chunk.
      Parameters:
      x - The global X coordinate.
      z - The global Z coordinate.
      Returns:
      true if the coordinates are on the border of the chunk, false otherwise.
    • isInsideChunk

      public static boolean isInsideChunk(int chunkX, int chunkZ, int x, int z)
      Checks if the given block coordinates are inside the specified chunk.
      Parameters:
      chunkX - The chunk X coordinate.
      chunkZ - The chunk Z coordinate.
      x - The block X coordinate.
      z - The block Z coordinate.
      Returns:
      true if the block coordinates are inside the specified chunk, false otherwise.
    • isSameChunk

      public static boolean isSameChunk(int x0, int z0, int x1, int z1)
      Checks if the two sets of block coordinates are in the same chunk.
      Parameters:
      x0 - The first X coordinate.
      z0 - The first Z coordinate.
      x1 - The second X coordinate.
      z1 - The second Z coordinate.
      Returns:
      true if both sets of coordinates are in the same chunk, false otherwise.
    • isSameChunkSection

      public static boolean isSameChunkSection(int x0, int y0, int z0, int x1, int y1, int z1)
      Checks if the two sets of block coordinates are in the same chunk section.
      Parameters:
      x0 - The first X coordinate.
      y0 - The first Y coordinate.
      z0 - The first Z coordinate.
      x1 - The second X coordinate.
      y1 - The second Y coordinate.
      z1 - The second Z coordinate.
      Returns:
      true if both sets of coordinates are in the same chunk section, false otherwise.
    • isInsideChunkRelative

      public static boolean isInsideChunkRelative(int x, int z)
      Checks if the given relative chunk coordinates are inside the chunk bounds.
      Parameters:
      x - The relative X coordinate.
      z - The relative Z coordinate.
      Returns:
      true if the coordinates are inside the chunk bounds, false otherwise.
    • xOfChunkIndex

      public static int xOfChunkIndex(long index)
      Gets the x coordinate from a chunk index.
      Parameters:
      index - The chunk index.
      Returns:
      the X coordinate from the chunk index.
      See Also:
    • zOfChunkIndex

      public static int zOfChunkIndex(long index)
      Gets the z coordinate from a chunk index.
      Parameters:
      index - The chunk index.
      Returns:
      the Z coordinate from the chunk index.
      See Also:
    • indexChunk

      public static long indexChunk(int x, int z)
      Transform the provided chunk (x, z) coordinates into a chunk index.

      The chunk index is created by combining all the bits from the two provided int's (2x 32-bit) into a single long (64-bit). The most significant 32-bits are the x coordinate and the least significant 32-bits are the z coordinate.

      Parameters:
      x - The chunk X coordinate.
      z - The chunk Z coordinate.
      Returns:
      the chunk index for the chunk at (x, z).
    • indexChunkFromBlock

      public static long indexChunkFromBlock(int blockX, int blockZ)
      Transform the provided block (x, z) coordinates into a chunk index.
      Parameters:
      blockX - The block X coordinate.
      blockZ - The block Z coordinate.
      Returns:
      the chunk index for the chunk that contains the block at (x, z).
      See Also:
    • indexChunkFromBlock

      public static long indexChunkFromBlock(double blockX, double blockZ)
      Transform the provided block (x, z) coordinates into a chunk index.
      Parameters:
      blockX - The block X coordinate.
      blockZ - The block Z coordinate.
      Returns:
      the chunk index for the chunk that contains the block at (x, z).
      See Also:
    • worldCoordFromLocalCoord

      public static int worldCoordFromLocalCoord(int chunkCoord, int localCoord)
      Translate a local coord within a chunk to a world coord.
      Parameters:
      chunkCoord - The chunk coord for the axis corresponding to the local coord.
      localCoord - The local coord to translate.
      Returns:
      the equivalent world coord.
    • isValidChunkIndex

      public static boolean isValidChunkIndex(long chunkIndex)
      Determines if the coordinate components of the given chunk index both lie within the theoretical min/max coordinate range for chunks.
      Parameters:
      chunkIndex - the index of the chunk to validate.
      Returns:
      true if the chunk index corresponds to valid chunk coordinates, false otherwise
    • isValidChunkCoords

      public static boolean isValidChunkCoords(int chunkCoordX, int chunkCoordZ)
      Determines if the give chunk coordinate components both lie within the theoretical min/max coordinate range for chunks.
      Parameters:
      chunkCoordX - the x-coordinate of the chunk to validate
      chunkCoordZ - the z-coordinate of the chunk to validate
      Returns:
      true if both coordinates are valid, false otherwise
    • isValidChunkCoord

      public static boolean isValidChunkCoord(int chunkCoord)
      Determines if the given chunk coordinate is within the theoretical min/max coordinate range for chunks.
      Parameters:
      chunkCoord - the chunk coordinate to be validated.
      Returns:
      true if the chunk coordinate falls within the defined range, false otherwise