Contents
- Description
- Field Summary
- Method Summary
- Field Details
- Method Details
- shortToByteArray(short[])
- intToByteArray(int[])
- indexColumn(int, int)
- xFromColumn(int)
- zFromColumn(int)
- indexSection(int)
- indexBlockFromColumn(int, int)
- indexBlock(int, int, int)
- xFromIndex(int)
- yFromIndex(int)
- zFromIndex(int)
- localCoordinate(long)
- chunkCoordinate(double)
- chunkCoordinate(int)
- chunkCoordinate(long)
- minBlock(int)
- maxBlock(int)
- isWithinLocalChunk(int, int)
- isBorderBlock(int, int)
- isBorderBlockGlobal(int, int)
- isInsideChunk(int, int, int, int)
- isSameChunk(int, int, int, int)
- isSameChunkSection(int, int, int, int, int, int)
- isInsideChunkRelative(int, int)
- xOfChunkIndex(long)
- zOfChunkIndex(long)
- indexChunk(int, int)
- indexChunkFromBlock(int, int)
- indexChunkFromBlock(double, double)
- worldCoordFromLocalCoord(int, int)
- isValidChunkIndex(long)
- isValidChunkCoords(int, int)
- isValidChunkCoord(int)
Class ChunkUtil
java.lang.Object
com.hypixel.hytale.math.util.ChunkUtil
A util for chunk's, chunk index packing and unpacking
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intDeprecated.Limit only applies to legacy storage/world gens.static final intDeprecated.Limit only applies to legacy storage/world gens.static final intDeprecated.Limit only applies to legacy storage/world gens.static final intDeprecated.Limit only applies to legacy storage/world gens.static final intTheoretical inclusive maximum chunk coordinate such thatworldCoordFromLocalCoord(int, int)does not under or overflow for inputs chunkCoord=MAX_CHUNK_COORD and localCoord=[0,32).static final intTheoretical inclusive minimum chunk coordinate such thatworldCoordFromLocalCoord(int, int)does not under or overflow for inputs chunkCoord=MIN_CHUNK_COORD and localCoord=[0,32).static final intstatic final intstatic final intstatic final intstatic final longstatic final intstatic final intstatic final intstatic final intDeprecated.Limit only applies to legacy storage/world gens.static final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic intchunkCoordinate(double block) Gets the chunk coordinate for the given block coordinate.static intchunkCoordinate(int block) Gets the chunk coordinate for the given block coordinate.static intchunkCoordinate(long block) Gets the chunk coordinate for the given block coordinate.static intindexBlock(int x, int y, int z) Gets the block index for the given X, Y, and Z coordinates.static intindexBlockFromColumn(int column, int y) Gets the block index from the given column index and Y coordinate.static longindexChunk(int x, int z) Transform the provided chunk (x, z) coordinates into a chunk index.static longindexChunkFromBlock(double blockX, double blockZ) Transform the provided block (x, z) coordinates into a chunk index.static longindexChunkFromBlock(int blockX, int blockZ) Transform the provided block (x, z) coordinates into a chunk index.static intindexColumn(int x, int z) Returns the column index for the given X and Z coordinates.static intindexSection(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 booleanisBorderBlock(int x, int z) Checks if the given local chunk coordinates are on the border of the chunk.static booleanisBorderBlockGlobal(int x, int z) Checks if the given global block coordinates are on the border of the chunk.static booleanisInsideChunk(int chunkX, int chunkZ, int x, int z) Checks if the given block coordinates are inside the specified chunk.static booleanisInsideChunkRelative(int x, int z) Checks if the given relative chunk coordinates are inside the chunk bounds.static booleanisSameChunk(int x0, int z0, int x1, int z1) Checks if the two sets of block coordinates are in the same chunk.static booleanisSameChunkSection(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 booleanisValidChunkCoord(int chunkCoord) Determines if the given chunk coordinate is within the theoretical min/max coordinate range for chunks.static booleanisValidChunkCoords(int chunkCoordX, int chunkCoordZ) Determines if the give chunk coordinate components both lie within the theoretical min/max coordinate range for chunks.static booleanisValidChunkIndex(long chunkIndex) Determines if the coordinate components of the given chunk index both lie within the theoretical min/max coordinate range for chunks.static booleanisWithinLocalChunk(int x, int z) Checks if the given local chunk coordinates are within the chunk bounds.static intlocalCoordinate(long v) Gets the local coordinate within a chunk for the given value.static intmaxBlock(int index) Gets the maximum block coordinate for the given chunk index.static intminBlock(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 intworldCoordFromLocalCoord(int chunkCoord, int localCoord) Translate a local coord within a chunk to a world coord.static intxFromColumn(int index) Gets the x coordinate from a column index.static intxFromIndex(int index) Gets the X coordinate from a block index.static intxOfChunkIndex(long index) Gets the x coordinate from a chunk index.static intyFromIndex(int index) Gets the y coordinate from a block index.static intzFromColumn(int index) Gets the Z coordinate from a column index.static intzFromIndex(int index) Gets the z coordinate from a block index.static intzOfChunkIndex(long index) Gets the z coordinate from a chunk index.
-
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.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.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.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.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.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_COORDTheoretical inclusive minimum chunk coordinate such thatworldCoordFromLocalCoord(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_COORDTheoretical inclusive maximum chunk coordinate such thatworldCoordFromLocalCoord(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:
trueif the coordinates are within the chunk bounds,falseotherwise.
-
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:
trueif the coordinates are on the border of the chunk,falseotherwise.
-
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:
trueif the coordinates are on the border of the chunk,falseotherwise.
-
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:
trueif the block coordinates are inside the specified chunk,falseotherwise.
-
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:
trueif both sets of coordinates are in the same chunk,falseotherwise.
-
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:
trueif both sets of coordinates are in the same chunk section,falseotherwise.
-
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:
trueif the coordinates are inside the chunk bounds,falseotherwise.
-
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 singlelong(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 validatechunkCoordZ- 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:
trueif the chunk coordinate falls within the defined range, false otherwise
-