Klasse 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.
  • Felddetails

    • 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)
  • Methodendetails

    • isValid

      public boolean isValid()
      Checks if this chunk is valid (i.e. whether or not it exists).
      Gibt zurück:
      true if this is a valid chunk, false if not.
    • getChunkPositionX

      public int getChunkPositionX()
      Gets the x offset of the chunk.
      Gibt zurück:
      the x chunk offset.
    • getChunkPositionZ

      public int getChunkPositionZ()
      Gets the z offset of the chunk.
      Gibt zurück:
      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.
      Parameter:
      cy - the y chunk part offset.
      Gibt zurück:
      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
      Gibt zurück:
      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.
      Gibt zurück:
      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)
      Gibt zurück:
      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())!
      Gibt zurück:
      a byte array (copy) representing the raw (uncompressed) LOD terrain data.
      Siehe auch:
    • 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())!
      Gibt zurück:
      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).
      Parameter:
      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.
      Gibt zurück:
      the surface elevation at a given position.
    • getLODSurfaceTexture

      public byte getLODSurfaceTexture(int x, int z)
    • getAllObjects

      public ObjectElement[] 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.
      Gibt zurück:
      a new array containing all objects in this chunk, or null if this chunk does not contain any objects.
    • getAllConstructionElements

      public ConstructionElement[] 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.
      Gibt zurück:
      a new array containing all construction elements in this chunk, or null if this chunk does not contain any construction elements.
    • getAllPlants

      public Plant[] getAllPlants()
      Gets all plants in this chunk (e.g trees, flowers, scrubs etc). If this chunk does not contain any vegetation, null is returned.
      Gibt zurück:
      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

      public boolean equals(Object o)
      Setzt außer Kraft:
      equals in Klasse Object
    • hashCode

      public int hashCode()
      Setzt außer Kraft:
      hashCode in Klasse Object