Class ChunkPart

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

public class ChunkPart extends Object
Represents a chunk part. A chunk part contains the terrain voxel data. Each chunk contains multiple chunk parts along y.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Y size (vertically) of a chunk part (in blocks)
    static final int
    Raw 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 int
    When extracting the strength (STRENGTH_BITS), shift the result by this value to the right to get a value between 0 and 100.
    static final int
    Raw 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 Type
    Method
    Description
    boolean
     
    int
    Gets the x offset of the chunk.
    int
    Gets the y offset (vertical) of the chunk part.
    int
    Gets 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.
    int
    getRawTerrainID(int x, int y, int z)
    Gets the raw terrain id at a particular index.
    static int
    getRawTerrainIndex(int x, int y, int z)
     
    byte[]
    Gets the 3d terrain voxel data as a flattened byte array.
    int
    getTerrainID(int x, int y, int z)
    Gets the terrain id at a particular index.
    static int
    getTerrainIndex(int x, int y, int z)
     
    int
     
    boolean
    Gets whether or not this chunk was loaded from database.
    boolean
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SIZE_Y

      public static final int SIZE_Y
      Y size (vertically) of a chunk part (in blocks)
    • TERRAIN_BITS

      public static final int TERRAIN_BITS
      Raw 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_BITS
      Raw 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_BITSHIFT
      When 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 (see Chunk.SIZE_X, SIZE_Y and Chunk.SIZE_Z). To access the array from an x, y and z coordinate, use getTerrainIndex(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, use getRawTerrainIndex(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
      1//Get player chunk and block position
      2Vector3i chunkPosition = player.getChunkPosition();
      3Vector3i blockPosition = player.getBlockPosition();
      4
      5//Get the related chunk part and terrain id at that position
      6ChunkPart cp = World.getChunkPart(chunkPosition.x, chunkPosition.y, chunkPosition.z);
      7int id = cp.getTerrainID(blockPosition.x, blockPosition.y - 1, blockPosition.z);
      8
      9//Convert the id to the terrain enum and check if it's hellstone (or hellstone glow)
      10Terrain terrain = Terrain.get(id);
      11if (terrain == Terrain.Hellstone || terrain == Terrain.HellstoneGlow) {
      12 System.out.println("Terrain is hellstone!");
      13}
    • getRawTerrainID

      public int getRawTerrainID(int x, int y, int z)
      Gets the raw terrain id at a particular index. Unlike the regular terrain id (see getTerrainID(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

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

      public int hashCode()
      Overrides:
      hashCode in class Object