Class ChunkPart
java.lang.Object
net.risingworld.api.objects.world.ChunkPart
Represents a chunk part. A chunk part contains the terrain voxel data. Each chunk contains multiple chunk parts
along y.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intY size (vertically) of a chunk part (in blocks)static final intRaw terrain data (stored as short) contains the actual terrain id (last 8 bits) and an optional strength value between 0 and 100 (first 8 bits).static final intWhen extracting the strength (STRENGTH_BITS), shift the result by this value to the right to get a value between 0 and 100.static final intRaw terrain data (stored as short) contains the actual terrain id (last 8 bits) and an optional strength value between 0 and 100 (first 8 bits). -
Method Summary
Modifier and TypeMethodDescriptionbooleanintGets the x offset of the chunk.intGets the y offset (vertical) of the chunk part.intGets the z offset of the chunk.byte[]Gets the raw compressed terrrain data of this chunk part.short[]Gets the raw terrain data of this chunk part.intgetRawTerrainID(int x, int y, int z) Gets the raw terrain id at a particular index.static intgetRawTerrainIndex(int x, int y, int z) byte[]Gets the 3d terrain voxel data as a flattened byte array.intgetTerrainID(int x, int y, int z) Gets the terrain id at a particular index.static intgetTerrainIndex(int x, int y, int z) inthashCode()booleanGets whether or not this chunk was loaded from database.booleanisValid()
-
Field Details
-
SIZE_Y
public static final int SIZE_YY size (vertically) of a chunk part (in blocks) -
TERRAIN_BITS
public static final int TERRAIN_BITSRaw terrain data (stored as short) contains the actual terrain id (last 8 bits) and an optional strength value between 0 and 100 (first 8 bits). TERRAIN_BITS represents the bitmask to extract the terrain ID from raw data(id & TERRAIN_BITS)- See Also:
-
STRENGTH_BITS
public static final int STRENGTH_BITSRaw terrain data (stored as short) contains the actual terrain id (last 8 bits) and an optional strength value between 0 and 100 (first 8 bits). STRENGTH_BITS represents the bitmask to extract the strength value from raw data, but also remember to shift it to the right((id & STRENGTH_BITS) >> STRENGTH_BITSHIFT)- See Also:
-
STRENGTH_BITSHIFT
public static final int STRENGTH_BITSHIFTWhen extracting the strength (STRENGTH_BITS), shift the result by this value to the right to get a value between 0 and 100.
To get a float, multiply the value by 0.01f- See Also:
-
-
Method Details
-
isValid
public boolean isValid() -
getChunkPositionX
public int getChunkPositionX()Gets the x offset of the chunk.- Returns:
- the x chunk offset.
-
getChunkPositionY
public int getChunkPositionY()Gets the y offset (vertical) of the chunk part.- Returns:
- the y chunk part offset.
-
getChunkPositionZ
public int getChunkPositionZ()Gets the z offset of the chunk.- Returns:
- the z chunk offset.
-
isLoadedFromDB
public boolean isLoadedFromDB()Gets whether or not this chunk was loaded from database. This means the chunk had been modified in the past- Returns:
- true if this is a modified chunk which was loaded from database, false if this is a naturally generated chunk.
-
getTerrain
public byte[] getTerrain()Gets the 3d terrain voxel data as a flattened byte array.
The array has a size of 32x64x32 (seeChunk.SIZE_X,SIZE_YandChunk.SIZE_Z). To access the array from an x, y and z coordinate, usegetTerrainIndex(int, int, int)- Returns:
- a byte array (copy) with size Chunk.SIZE_X * ChunkPart.SIZE_Y * Chunk.SIZE_Z representing the terrain voxel data (terrain ids).
-
getRawTerrain
public short[] getRawTerrain()Gets the raw terrain data of this chunk part. The terrain data is a flattened array with the size of 36x68x36: Each dimension includes 2 neighbour chunk cells in each direction. The terrain data is stored as short (16 bit value), where the first 8 bits contain the terrain "strength modifier" (a value between 0 and 100) and the last 8 bits contain the actual terrain id
To access the array from an x, y and z coordinate, usegetRawTerrainIndex(int, int, int)- Returns:
- a short array (copy) representing the raw (uncompressed) terrain data.
- See Also:
-
getRawCompressedTerrain
public byte[] getRawCompressedTerrain()Gets the raw compressed terrrain data of this chunk part.- Returns:
- the raw compressed terrain data as a byte array (copy).
-
getTerrainID
public int getTerrainID(int x, int y, int z) Gets the terrain id at a particular index.- Parameters:
x- the x coordinate in the chunk (between 0 and Chunk.SIZE_X).y- the y coordinate (vertical) in the chunk (between 0 and ChunkPart.SIZE_Y).z- the z coordinate in the chunk (between 0 and Chunk.SIZE_Z).- Returns:
- the terrain id, containing the terrain material at the given position in the chunk.
- Example: Check if terrain at player position is hellstone
-
getRawTerrainID
public int getRawTerrainID(int x, int y, int z) Gets the raw terrain id at a particular index. Unlike the regular terrain id (seegetTerrainID(int, int, int)), it also contains an optional strength value (which modifies the smoothness of the terrain). The terrain data is stored as 16 bit value, where the first 8 bits contain the terrain "strength modifier" (a value between 0 and 100) and the last 8 bits contain the actual terrain id- Parameters:
x- the x coordinate in the chunk (between 0 and Chunk.SIZE_X).y- the y coordinate (vertical) in the chunk (between 0 and ChunkPart.SIZE_Y).z- the z coordinate in the chunk (between 0 and Chunk.SIZE_Z).- Returns:
- the terrain id, containing the terrain material at the given position in the chunk.
-
getTerrainIndex
public static int getTerrainIndex(int x, int y, int z) -
getRawTerrainIndex
public static int getRawTerrainIndex(int x, int y, int z) -
equals
-
hashCode
public int hashCode()
-