Class Chunk
java.lang.Object
net.risingworld.api.objects.world.Chunk
Represents an chunk. A chunk has an x and z coordinate, so it only exists horizontally. It contains
the LOD terrain representation, objects, construction elements, plants and several ChunkParts (vertically) - they
contain the actual terrain voxel data.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Gets whether or not this chunk contains water.boolean
Gets all construction elements in this chunk (e.g blocks, cylinders, window frames etc).Gets all object elements in this chunk (e.g furniture, workbenches, doors etc).Plant[]
Gets all plants in this chunk (e.g trees, flowers, scrubs etc).getChunkPart
(int cy) Gets a chunk part associated to this chunk.int
Gets the x offset of the chunk.int
Gets the z offset of the chunk.float
getLODSurfaceLevel
(int x, int z, boolean includeWater) Gets the surface level/elevation (world y position) of the LOD terrain at a given position (between 0 and Chunk.SIZE_X/Z).byte
getLODSurfaceTexture
(int x, int z) float[]
Gets the LOD terrain as a flattened float array (representing the terrain level/elevation).byte[]
Gets the raw compressed LOD terrrain data.byte[]
Gets the raw LOD terrain data.static int
getRawTerrainIndex
(int layer, int x, int z) static int
getTerrainIndex
(int x, int z) int
hashCode()
boolean
Gets whether or not this chunk was loaded from database.boolean
isValid()
Checks if this chunk is valid (i.e.
-
Field Details
-
SIZE_X
public static final int SIZE_XX size of a chunk (in blocks) -
SIZE_Z
public static final int SIZE_ZZ size of a chunk (in blocks)
-
-
Method Details
-
isValid
public boolean isValid()Checks if this chunk is valid (i.e. whether or not it exists).- Returns:
- true if this is a valid chunk, false if not.
-
getChunkPositionX
public int getChunkPositionX()Gets the x offset of the chunk.- Returns:
- the x chunk offset.
-
getChunkPositionZ
public int getChunkPositionZ()Gets the z offset of the chunk.- Returns:
- the z chunk offset.
-
getChunkPart
Gets a chunk part associated to this chunk. Chunk parts contain the actual 3d terrain voxel data.- Parameters:
cy
- the y chunk part offset.- Returns:
- the according chunk part, or null if this chunk part does not exist.
-
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.
-
containsWater
public boolean containsWater()Gets whether or not this chunk contains water.- Returns:
- true if this chunk contains water, false if not.
-
getLODTerrain
public float[] getLODTerrain()Gets the LOD terrain as a flattened float array (representing the terrain level/elevation). If you want to get the terrain level at a particular position, you could also usegetLODSurfaceLevel(int, int, boolean)
, but if you want to get the terrain level of several or all positions, it's better to use this method instead.
The array has a size of 32x32 (seeSIZE_X
andSIZE_Z
). To access the array from an x and z coordinate, usegetTerrainIndex(int, int)
- Returns:
- a float array (copy) with size Chunk.SIZE_X * Chunk.SIZE_Z representing the LOD terrain elevation.
- Example: Check if terrain in a chunk is below sea level
-
getRawLODTerrain
public byte[] getRawLODTerrain()Gets the raw LOD terrain data. The terrain data is a flattened array with the size of 36x36x7: Width and height include 2 neighbour chunk cells in each direction (chunk size 32 + 2 + 2 = 36), and 6 bytes per layer (byte 1: texture, byte 2: terrain lvl short 1st byte, byte 3: terrain lvl short 2nd byte, byte 4: water texture, byte 5: water lvl short 1st byte, byte 6: water lvl short 2nd byte, byte 7: biome).
To access the array from a layer, x and z coordinate, usegetRawTerrainIndex(int, int, int)
Please note: The data layout may change in a future update, so it's better to use the high level methods to access the LOD data (e.ggetLODTerrain()
)!- Returns:
- a byte array (copy) representing the raw (uncompressed) LOD terrain data.
- See Also:
-
getRawCompressedLODTerrain
public byte[] getRawCompressedLODTerrain()Gets the raw compressed LOD terrrain data.
Please note: The data layout may change in a future update, so it's better to use the high level methods to access the LOD data (e.ggetLODTerrain()
)!- Returns:
- the raw compressed LOD terrain data as a byte array (copy).
-
getLODSurfaceLevel
public float getLODSurfaceLevel(int x, int z, boolean includeWater) Gets the surface level/elevation (world y position) of the LOD terrain at a given position (between 0 and Chunk.SIZE_X/Z).- Parameters:
x
- the x coordinate in the chunk (between 0 and Chunk.SIZE_X).z
- the z coordinate in the chunk (between 0 and Chunk.SIZE_Z).includeWater
- if true, water will also be taken into consideration, false the game only looks for solid terrain.- Returns:
- the surface elevation at a given position.
-
getLODSurfaceTexture
public byte getLODSurfaceTexture(int x, int z) -
getAllObjects
Gets all object elements in this chunk (e.g furniture, workbenches, doors etc). If this chunk does not contain any objects, null is returned.- Returns:
- a new array containing all objects in this chunk, or null if this chunk does not contain any objects.
-
getAllConstructionElements
Gets all construction elements in this chunk (e.g blocks, cylinders, window frames etc). If this chunk does not contain any construction elements, null is returned.- Returns:
- a new array containing all construction elements in this chunk, or null if this chunk does not contain any construction elements.
-
getAllPlants
Gets all plants in this chunk (e.g trees, flowers, scrubs etc). If this chunk does not contain any vegetation, null is returned.- Returns:
- a new array containing all plants in this chunk, or null if this chunk does not contain any plants.
-
getTerrainIndex
public static int getTerrainIndex(int x, int z) -
getRawTerrainIndex
public static int getRawTerrainIndex(int layer, int x, int z) -
equals
-
hashCode
public int hashCode()
-