Class Chunk

java.lang.Object
net.risingworld.api.objects.world.Chunk

public class Chunk extends Object
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 Details

    • SIZE_X

      public static final int SIZE_X
      X size of a chunk (in blocks)
    • SIZE_Z

      public static final int SIZE_Z
      Z size of a chunk (in blocks)
  • Method Details

    • isValid

      public boolean isValid()
    • 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

      public ChunkPart getChunkPart(int cy)
      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 use getLODSurfaceLevel(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 (see SIZE_X and SIZE_Z). To access the array from an x and z coordinate, use getTerrainIndex(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
      1float[] terrain = chunk.getLODTerrain();
      2
      3for(int x = 0; x < Chunk.SIZE_X; x++) {
      4 for(int z = 0; z < Chunk.SIZE_Z; z++) {
      5 float lvl = terrain[Chunk.getTerrainIndex(x, z)];
      6 if(lvl < Utils.SEA_LEVEL) {
      7 System.out.println("Terrain is below sea level at " + x + " " + z);
      8 }
      9 }
      10}
    • 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, use getRawTerrainIndex(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.g getLODTerrain())!
      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.g getLODTerrain())!
      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)
    • getTerrainIndex

      public static int getTerrainIndex(int x, int z)
    • getRawTerrainIndex

      public static int getRawTerrainIndex(int layer, int x, int z)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object