2013-01-25 05:12:29 -05:00
// ChunkDesc.h
// Declares the cChunkDesc class representing the chunk description used while generating a chunk. This class is also exported to Lua for HOOK_CHUNK_GENERATING.
# pragma once
2013-03-19 04:32:02 -04:00
# include "../BlockArea.h"
2013-03-30 17:03:56 -04:00
# include "../ChunkDef.h"
# include "../Cuboid.h"
2013-01-25 05:12:29 -05:00
2013-02-08 15:57:42 -05:00
// fwd: ../BlockArea.h
class cBlockArea ;
2013-02-08 11:01:44 -05:00
// tolua_begin
class cChunkDesc
{
2013-01-25 05:12:29 -05:00
public :
2013-02-08 11:01:44 -05:00
// tolua_end
2014-11-12 15:24:26 -05:00
/** The datatype used to represent the entire chunk worth of shape.
0 = air
1 = solid
2014-11-15 14:23:47 -05:00
Indexed as [ y + 256 * x + 256 * 16 * z ] . */
2014-11-12 15:24:26 -05:00
typedef Byte Shape [ 256 * 16 * 16 ] ;
2013-01-25 05:12:29 -05:00
2014-01-30 11:41:57 -05:00
/** Uncompressed block metas, 1 meta per byte */
2013-05-05 15:56:45 -04:00
typedef NIBBLETYPE BlockNibbleBytes [ cChunkDef : : NumBlocks ] ;
2014-11-12 15:24:26 -05:00
2013-02-08 15:57:42 -05:00
cChunkDesc ( int a_ChunkX , int a_ChunkZ ) ;
2013-02-08 11:01:44 -05:00
~ cChunkDesc ( ) ;
2013-01-25 05:12:29 -05:00
2013-09-25 03:02:49 -04:00
void SetChunkCoords ( int a_ChunkX , int a_ChunkZ ) ;
2013-01-25 05:12:29 -05:00
// tolua_begin
2013-03-17 13:55:03 -04:00
int GetChunkX ( void ) const { return m_ChunkX ; }
int GetChunkZ ( void ) const { return m_ChunkZ ; }
2013-02-08 11:01:44 -05:00
void FillBlocks ( BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
2013-02-08 15:57:42 -05:00
void SetBlockTypeMeta ( int a_RelX , int a_RelY , int a_RelZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
void GetBlockTypeMeta ( int a_RelX , int a_RelY , int a_RelZ , BLOCKTYPE & a_BlockType , NIBBLETYPE & a_BlockMeta ) ;
2013-01-25 05:12:29 -05:00
2013-02-08 11:01:44 -05:00
void SetBlockType ( int a_RelX , int a_RelY , int a_RelZ , BLOCKTYPE a_BlockType ) ;
BLOCKTYPE GetBlockType ( int a_RelX , int a_RelY , int a_RelZ ) ;
2013-01-25 05:12:29 -05:00
2013-02-08 11:01:44 -05:00
void SetBlockMeta ( int a_RelX , int a_RelY , int a_RelZ , NIBBLETYPE a_BlockMeta ) ;
NIBBLETYPE GetBlockMeta ( int a_RelX , int a_RelY , int a_RelZ ) ;
2014-02-03 15:26:17 -05:00
void SetBiome ( int a_RelX , int a_RelZ , EMCSBiome a_BiomeID ) ;
2013-02-08 11:01:44 -05:00
EMCSBiome GetBiome ( int a_RelX , int a_RelZ ) ;
2014-01-30 11:41:57 -05:00
// These operate on the heightmap, so they could get out of sync with the data
2014-11-12 15:24:26 -05:00
// Use UpdateHeightmap() to re-calculate heightmap from the block data
2013-02-08 11:01:44 -05:00
void SetHeight ( int a_RelX , int a_RelZ , int a_Height ) ;
int GetHeight ( int a_RelX , int a_RelZ ) ;
2014-11-12 15:24:26 -05:00
// tolua_end
/** Sets the heightmap to match the given shape data.
Note that this ignores overhangs ; the method is mostly used by old composition generators . */
void SetHeightFromShape ( const Shape & a_Shape ) ;
/** Sets the shape in a_Shape to match the heightmap stored currently in m_HeightMap. */
void GetShapeFromHeight ( Shape & a_Shape ) const ;
// tolua_begin
2013-02-08 11:01:44 -05:00
// Default generation:
void SetUseDefaultBiomes ( bool a_bUseDefaultBiomes ) ;
bool IsUsingDefaultBiomes ( void ) const ;
void SetUseDefaultHeight ( bool a_bUseDefaultHeight ) ;
bool IsUsingDefaultHeight ( void ) const ;
void SetUseDefaultComposition ( bool a_bUseDefaultComposition ) ;
bool IsUsingDefaultComposition ( void ) const ;
void SetUseDefaultFinish ( bool a_bUseDefaultFinish ) ;
bool IsUsingDefaultFinish ( void ) const ;
2013-01-25 05:12:29 -05:00
2014-01-30 11:41:57 -05:00
/** Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data overwrite everything in the chunk. */
2013-03-19 04:32:02 -04:00
void WriteBlockArea ( const cBlockArea & a_BlockArea , int a_RelX , int a_RelY , int a_RelZ , cBlockArea : : eMergeStrategy a_MergeStrategy = cBlockArea : : msOverwrite ) ;
2013-02-08 15:57:42 -05:00
2014-01-30 11:41:57 -05:00
/** Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas */
2013-02-08 15:57:42 -05:00
void ReadBlockArea ( cBlockArea & a_Dest , int a_MinRelX , int a_MaxRelX , int a_MinRelY , int a_MaxRelY , int a_MinRelZ , int a_MaxRelZ ) ;
2014-11-12 15:24:26 -05:00
/** Returns the maximum height value in the heightmap. */
2013-03-17 13:55:03 -04:00
HEIGHTTYPE GetMaxHeight ( void ) const ;
2014-11-12 15:24:26 -05:00
/** Returns the minimum height value in the heightmap. */
HEIGHTTYPE GetMinHeight ( void ) const ;
2013-03-17 13:55:03 -04:00
2014-01-30 11:41:57 -05:00
/** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */
2013-03-30 17:03:56 -04:00
void FillRelCuboid (
int a_MinX , int a_MaxX ,
int a_MinY , int a_MaxY ,
int a_MinZ , int a_MaxZ ,
BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta
) ;
2014-01-30 11:41:57 -05:00
/** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */
2013-03-30 17:03:56 -04:00
void FillRelCuboid ( const cCuboid & a_RelCuboid , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta )
{
FillRelCuboid (
a_RelCuboid . p1 . x , a_RelCuboid . p2 . x ,
a_RelCuboid . p1 . y , a_RelCuboid . p2 . y ,
a_RelCuboid . p1 . z , a_RelCuboid . p2 . z ,
a_BlockType , a_BlockMeta
) ;
}
2013-03-29 16:47:51 -04:00
2014-01-30 11:41:57 -05:00
/** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */
2013-03-30 17:03:56 -04:00
void ReplaceRelCuboid (
int a_MinX , int a_MaxX ,
int a_MinY , int a_MaxY ,
int a_MinZ , int a_MaxZ ,
BLOCKTYPE a_SrcType , NIBBLETYPE a_SrcMeta ,
BLOCKTYPE a_DstType , NIBBLETYPE a_DstMeta
) ;
2013-03-29 16:47:51 -04:00
2014-01-30 11:41:57 -05:00
/** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */
2013-03-30 17:03:56 -04:00
void ReplaceRelCuboid (
const cCuboid & a_RelCuboid ,
BLOCKTYPE a_SrcType , NIBBLETYPE a_SrcMeta ,
BLOCKTYPE a_DstType , NIBBLETYPE a_DstMeta
)
{
ReplaceRelCuboid (
a_RelCuboid . p1 . x , a_RelCuboid . p2 . x ,
a_RelCuboid . p1 . y , a_RelCuboid . p2 . y ,
a_RelCuboid . p1 . z , a_RelCuboid . p2 . z ,
a_SrcType , a_SrcMeta ,
a_DstType , a_DstMeta
) ;
}
2014-01-30 11:41:57 -05:00
/** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */
2013-03-31 12:22:35 -04:00
void FloorRelCuboid (
int a_MinX , int a_MaxX ,
int a_MinY , int a_MaxY ,
int a_MinZ , int a_MaxZ ,
BLOCKTYPE a_DstType , NIBBLETYPE a_DstMeta
) ;
2014-01-30 11:41:57 -05:00
/** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */
2013-03-31 12:22:35 -04:00
void FloorRelCuboid (
const cCuboid & a_RelCuboid ,
BLOCKTYPE a_DstType , NIBBLETYPE a_DstMeta
)
{
FloorRelCuboid (
a_RelCuboid . p1 . x , a_RelCuboid . p2 . x ,
a_RelCuboid . p1 . y , a_RelCuboid . p2 . y ,
a_RelCuboid . p1 . z , a_RelCuboid . p2 . z ,
a_DstType , a_DstMeta
) ;
}
2013-03-31 15:05:41 -04:00
2014-01-30 11:41:57 -05:00
/** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */
2013-03-31 15:05:41 -04:00
void RandomFillRelCuboid (
int a_MinX , int a_MaxX ,
int a_MinY , int a_MaxY ,
int a_MinZ , int a_MaxZ ,
BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ,
int a_RandomSeed , int a_ChanceOutOf10k
) ;
2014-01-30 11:41:57 -05:00
/** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */
2013-03-31 15:05:41 -04:00
void RandomFillRelCuboid (
const cCuboid & a_RelCuboid , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ,
int a_RandomSeed , int a_ChanceOutOf10k
)
{
RandomFillRelCuboid (
a_RelCuboid . p1 . x , a_RelCuboid . p2 . x ,
a_RelCuboid . p1 . y , a_RelCuboid . p2 . y ,
a_RelCuboid . p1 . z , a_RelCuboid . p2 . z ,
a_BlockType , a_BlockMeta ,
a_RandomSeed , a_ChanceOutOf10k
) ;
}
2014-01-30 11:41:57 -05:00
/** Returns the block entity at the specified coords.
If there is no block entity at those coords , tries to create one , based on the block type
2014-10-20 16:55:07 -04:00
If the blocktype doesn ' t support a block entity , returns nullptr . */
2013-11-14 09:37:09 -05:00
cBlockEntity * GetBlockEntity ( int a_RelX , int a_RelY , int a_RelZ ) ;
2013-01-25 05:12:29 -05:00
2014-01-30 11:41:57 -05:00
/** Updates the heightmap to match the current contents.
Useful for plugins when writing custom block areas into the chunk */
void UpdateHeightmap ( void ) ;
2013-11-14 09:37:09 -05:00
// tolua_end
2013-01-25 05:12:29 -05:00
// Accessors used by cChunkGenerator::Generator descendants:
2013-05-05 15:56:45 -04:00
inline cChunkDef : : BiomeMap & GetBiomeMap ( void ) { return m_BiomeMap ; }
inline cChunkDef : : BlockTypes & GetBlockTypes ( void ) { return * ( ( cChunkDef : : BlockTypes * ) m_BlockArea . GetBlockTypes ( ) ) ; }
2014-07-17 16:50:58 -04:00
// CANNOT, different compression!
2013-05-05 15:56:45 -04:00
// inline cChunkDef::BlockNibbles & GetBlockMetas (void) { return *((cChunkDef::BlockNibbles *)m_BlockArea.GetBlockMetas()); }
inline BlockNibbleBytes & GetBlockMetasUncompressed ( void ) { return * ( ( BlockNibbleBytes * ) m_BlockArea . GetBlockMetas ( ) ) ; }
inline cChunkDef : : HeightMap & GetHeightMap ( void ) { return m_HeightMap ; }
inline cEntityList & GetEntities ( void ) { return m_Entities ; }
inline cBlockEntityList & GetBlockEntities ( void ) { return m_BlockEntities ; }
2013-02-08 11:01:44 -05:00
2014-01-30 11:41:57 -05:00
/** Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byte) */
2013-03-19 04:32:02 -04:00
void CompressBlockMetas ( cChunkDef : : BlockNibbles & a_DestMetas ) ;
2013-05-05 07:42:09 -04:00
# ifdef _DEBUG
2014-01-30 11:41:57 -05:00
/** Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column */
2013-05-05 07:42:09 -04:00
void VerifyHeightmap ( void ) ;
# endif // _DEBUG
2013-01-25 05:12:29 -05:00
private :
2013-02-08 15:57:42 -05:00
int m_ChunkX ;
int m_ChunkZ ;
2013-02-08 11:01:44 -05:00
cChunkDef : : BiomeMap m_BiomeMap ;
2013-03-19 04:32:02 -04:00
cBlockArea m_BlockArea ;
2013-02-08 11:01:44 -05:00
cChunkDef : : HeightMap m_HeightMap ;
cEntityList m_Entities ; // Individual entities are NOT owned by this object!
cBlockEntityList m_BlockEntities ; // Individual block entities are NOT owned by this object!
2013-01-25 05:12:29 -05:00
bool m_bUseDefaultBiomes ;
bool m_bUseDefaultHeight ;
bool m_bUseDefaultComposition ;
bool m_bUseDefaultFinish ;
} ; // tolua_export