Interface ChunkLayout
-
public interface ChunkLayout
A class for information about the chunk coordinate space, aka the layout. This can be used to obtain information about the chunk size and the space bounds, validate coordinates, convert from chunk to world and vice-versa and translate coordinates; among other things.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.Optional<Vector3i>
addToChunk(int cx, int cy, int cz, int ox, int oy, int oz)
Adds the chunk offset to the chunk coordinates.default java.util.Optional<Vector3i>
addToChunk(Vector3i chunkCoords, Vector3i chunkOffset)
Adds the chunk offset to the chunk coordinates.Vector3i
chunkSize()
Returns the size of the chunks in blocks.Vector3i
forceToChunk(int x, int y, int z)
Converts world coordinates to chunk coordinates.default Vector3i
forceToChunk(Vector3i worldCoords)
Converts world coordinates to chunk coordinates.Vector3i
forceToWorld(int x, int y, int z)
Converts chunk coordinates to world coordinates.default Vector3i
forceToWorld(Vector3i chunkCoords)
Converts chunk coordinates to world coordinates.boolean
isInChunk(int x, int y, int z)
Returns true if the local coordinates fit in a chunk.boolean
isInChunk(int wx, int wy, int wz, int cx, int cy, int cz)
Returns true if the world coordinates fit in the chunk at the given coordinates.default boolean
isInChunk(Vector3i localCoords)
Returns true if the local coordinates fit in a chunk.default boolean
isInChunk(Vector3i worldCoords, Vector3i chunkCoords)
Returns true if the world coordinates fit in the chunk at the given coordinates.default boolean
isValidChunk(int x, int y, int z)
Returns true if the coordinates are valid chunk coordinates.default boolean
isValidChunk(Vector3i coords)
Returns true if the coordinates are valid chunk coordinates.default java.util.Optional<Vector3i>
moveToChunk(int x, int y, int z, Direction direction)
Moves chunk coordinates one step in the given direction.default java.util.Optional<Vector3i>
moveToChunk(int x, int y, int z, Direction direction, int steps)
Moves chunk coordinates a number of steps in the given direction.default java.util.Optional<Vector3i>
moveToChunk(Vector3i chunkCoords, Direction direction)
Moves chunk coordinates one step in the given direction.default java.util.Optional<Vector3i>
moveToChunk(Vector3i chunkCoords, Direction direction, int steps)
Moves chunk coordinates a number of steps in the given direction.Vector3i
spaceMax()
Returns the maximum coordinates for chunks for each axis.Vector3i
spaceMin()
Returns the minimum coordinates for chunks for each axis.Vector3i
spaceOrigin()
Returns the origin of the chunk coordinate space.Vector3i
spaceSize()
Gets the total size of the chunk space, which is equivalent tospaceMax()
-spaceMin()
+ 1.default java.util.Optional<Vector3i>
toChunk(int x, int y, int z)
Converts world coordinates to chunk coordinates.default java.util.Optional<Vector3i>
toChunk(Vector3i worldCoords)
Converts world coordinates to chunk coordinates.default java.util.Optional<Vector3i>
toWorld(int x, int y, int z)
Converts chunk coordinates to world coordinates.default java.util.Optional<Vector3i>
toWorld(Vector3i chunkCoords)
Converts chunk coordinates to world coordinates.
-
-
-
Method Detail
-
chunkSize
Vector3i chunkSize()
Returns the size of the chunks in blocks. The axes are matched to the corresponding vector components.- Returns:
- The size of chunks
-
spaceMax
Vector3i spaceMax()
Returns the maximum coordinates for chunks for each axis. The axes are matched to the corresponding vector components. Due to the limited precision of 32bit integers, there always is a practical limit.- Returns:
- The maximum coordinates of chunks
-
spaceMin
Vector3i spaceMin()
Returns the minimum coordinates for chunks for each axis. The axes are matched to the corresponding vector components. Due to the limited precision of 32bit integers, there always is a practical limit.- Returns:
- The minimum coordinates of chunks
-
spaceSize
Vector3i spaceSize()
Gets the total size of the chunk space, which is equivalent tospaceMax()
-spaceMin()
+ 1.- Returns:
- The total size of the chunk space
-
spaceOrigin
Vector3i spaceOrigin()
Returns the origin of the chunk coordinate space. NormallyVector3i.ZERO
.- Returns:
- The origin of the chunk coordinate space
-
isValidChunk
default boolean isValidChunk(Vector3i coords)
Returns true if the coordinates are valid chunk coordinates. False if otherwise.- Parameters:
coords
- The coordinates to validate- Returns:
- Whether or not the coordinates are valid for chunks
-
isValidChunk
default boolean isValidChunk(int x, int y, int z)
Returns true if the coordinates are valid chunk coordinates. False if otherwise.- Parameters:
x
- The x coordinate to validatey
- The y coordinate to validatez
- The z coordinate to validate- Returns:
- Whether or not the coordinates are valid for chunks
-
isInChunk
default boolean isInChunk(Vector3i localCoords)
Returns true if the local coordinates fit in a chunk. That is they are positive and smaller than the chunk's size.- Parameters:
localCoords
- The coordinates to check- Returns:
- Whether or not the coordinates fit in a chunk
-
isInChunk
boolean isInChunk(int x, int y, int z)
Returns true if the local coordinates fit in a chunk. That is they are positive and smaller than the chunk's size.- Parameters:
x
- The x local coordinate to validatey
- The y local coordinate to validatez
- The z local coordinate to validate- Returns:
- Whether or not the coordinates fit in a chunk
-
isInChunk
default boolean isInChunk(Vector3i worldCoords, Vector3i chunkCoords)
Returns true if the world coordinates fit in the chunk at the given coordinates.- Parameters:
worldCoords
- The world coordinates to validatechunkCoords
- The chunk coordinates in which they must fit- Returns:
- Whether or not the world coordinates fit in the chunk
-
isInChunk
boolean isInChunk(int wx, int wy, int wz, int cx, int cy, int cz)
Returns true if the world coordinates fit in the chunk at the given coordinates.- Parameters:
wx
- The x world coordinate to validatewy
- The y world coordinate to validatewz
- The z world coordinate to validatecx
- The x chunk coordinate in which they must fitcy
- The y chunk coordinate in which they must fitcz
- The z chunk coordinate in which they must fit- Returns:
- Whether or not the world coordinates fit in the chunk
-
toChunk
default java.util.Optional<Vector3i> toChunk(Vector3i worldCoords)
Converts world coordinates to chunk coordinates. Returns nothing if the conversion failed because the resulting chunk coordinates aren't valid.- Parameters:
worldCoords
- The world coordinates to convert to chunk coordinates- Returns:
- The chunk coordinates on success, else nothing
-
toChunk
default java.util.Optional<Vector3i> toChunk(int x, int y, int z)
Converts world coordinates to chunk coordinates. Returns nothing if the conversion failed because the resulting chunk coordinates aren't valid.- Parameters:
x
- The x world coordinate to convert to chunk coordinatesy
- The y world coordinate to convert to chunk coordinatesz
- The z world coordinate to convert to chunk coordinates- Returns:
- The chunk coordinates on success, else nothing
-
toWorld
default java.util.Optional<Vector3i> toWorld(Vector3i chunkCoords)
Converts chunk coordinates to world coordinates. Returns nothing if the conversion failed because the given chunk coordinates aren't valid.- Parameters:
chunkCoords
- The chunk coordinates to convert to world coordinates- Returns:
- The world coordinates on success, else nothing
-
toWorld
default java.util.Optional<Vector3i> toWorld(int x, int y, int z)
Converts chunk coordinates to world coordinates. Returns nothing if the conversion failed because the given chunk coordinates aren't valid.- Parameters:
x
- The x chunk coordinate to convert to world coordinatesy
- The y chunk coordinate to convert to world coordinatesz
- The z chunk coordinate to convert to world coordinates- Returns:
- The world coordinates on success, else nothing
-
forceToChunk
default Vector3i forceToChunk(Vector3i worldCoords)
Converts world coordinates to chunk coordinates. This method never fails and can returns invalid chunk coordinates.- Parameters:
worldCoords
- The world coordinates to convert to chunk coordinates- Returns:
- The chunk coordinates
-
forceToChunk
Vector3i forceToChunk(int x, int y, int z)
Converts world coordinates to chunk coordinates. This method never fails and can return invalid chunk coordinates.- Parameters:
x
- The x world coordinate to convert to chunk coordinatesy
- The y world coordinate to convert to chunk coordinatesz
- The z world coordinate to convert to chunk coordinates- Returns:
- The chunk coordinates
-
forceToWorld
default Vector3i forceToWorld(Vector3i chunkCoords)
Converts chunk coordinates to world coordinates. This method never fails and can returns invalid world coordinates.- Parameters:
chunkCoords
- The chunk coordinates to convert to world coordinates- Returns:
- The world coordinates
-
forceToWorld
Vector3i forceToWorld(int x, int y, int z)
Converts chunk coordinates to world coordinates. This method never fails and can returns invalid world coordinates.- Parameters:
x
- The x chunk coordinate to convert to world coordinatesy
- The y chunk coordinate to convert to world coordinatesz
- The z chunk coordinate to convert to world coordinates- Returns:
- The world coordinates
-
addToChunk
default java.util.Optional<Vector3i> addToChunk(Vector3i chunkCoords, Vector3i chunkOffset)
Adds the chunk offset to the chunk coordinates. Returns nothing if the new coordinates are not valid.- Parameters:
chunkCoords
- The chunk coordinates to add tochunkOffset
- The chunk offset to add to the chunk coordinates- Returns:
- The new chunk coordinates if they are valid
-
addToChunk
default java.util.Optional<Vector3i> addToChunk(int cx, int cy, int cz, int ox, int oy, int oz)
Adds the chunk offset to the chunk coordinates. Returns nothing if the new coordinates are not valid.- Parameters:
cx
- The x chunk coordinate to add tocy
- The y chunk coordinate to add tocz
- The z chunk coordinate to add toox
- The x chunk offset to add to the chunk coordinatesoy
- The y chunk offset to add to the chunk coordinatesoz
- The z chunk offset to add to the chunk coordinates- Returns:
- The new chunk coordinates if they are valid
-
moveToChunk
default java.util.Optional<Vector3i> moveToChunk(Vector3i chunkCoords, Direction direction)
Moves chunk coordinates one step in the given direction. Returns nothing if the new coordinates are not valid.Direction.Division.SECONDARY_ORDINAL
directions are not a valid argument. These will throw an exception.- Parameters:
chunkCoords
- The chunk coordinates to move fromdirection
- The direction in which to move a step- Returns:
- The new chunk coordinates if they are valid
- Throws:
java.lang.IllegalArgumentException
- If the direction is aDirection.Division.SECONDARY_ORDINAL
-
moveToChunk
default java.util.Optional<Vector3i> moveToChunk(int x, int y, int z, Direction direction)
Moves chunk coordinates one step in the given direction. Returns nothing if the new coordinates are not valid.Direction.Division.SECONDARY_ORDINAL
directions are not a valid argument. These will throw an exception.- Parameters:
x
- The x chunk coordinate to move fromy
- The y chunk coordinate to move fromz
- The z chunk coordinate to move fromdirection
- The direction in which to move a step- Returns:
- The new chunk coordinates if they are valid
- Throws:
java.lang.IllegalArgumentException
- If the direction is aDirection.Division.SECONDARY_ORDINAL
-
moveToChunk
default java.util.Optional<Vector3i> moveToChunk(Vector3i chunkCoords, Direction direction, int steps)
Moves chunk coordinates a number of steps in the given direction. Returns nothing if the new coordinates are not valid.Direction.Division.SECONDARY_ORDINAL
directions are not a valid argument. These will throw an exception.- Parameters:
chunkCoords
- The chunk coordinates to move fromdirection
- The direction in which to movesteps
- The number of steps to take- Returns:
- The new chunk coordinates if they are valid
- Throws:
java.lang.IllegalArgumentException
- If the direction is aDirection.Division.SECONDARY_ORDINAL
-
moveToChunk
default java.util.Optional<Vector3i> moveToChunk(int x, int y, int z, Direction direction, int steps)
Moves chunk coordinates a number of steps in the given direction. Returns nothing if the new coordinates are not valid.Direction.Division.SECONDARY_ORDINAL
directions are not a valid argument. These will throw an exception.- Parameters:
x
- The x chunk coordinate to move fromy
- The y chunk coordinate to move fromz
- The z chunk coordinate to move fromdirection
- The direction in which to movesteps
- The number of steps to take- Returns:
- The new chunk coordinates if they are valid
- Throws:
java.lang.IllegalArgumentException
- If the direction is aDirection.Division.SECONDARY_ORDINAL
-
-