Cuberite
A lightweight, fast and extensible game server for Minecraft
ChunkDesc.h
Go to the documentation of this file.
1 
2 // ChunkDesc.h
3 
4 // Declares the cChunkDesc class representing the chunk description used while generating a chunk. This class is also exported to Lua for HOOK_CHUNK_GENERATING.
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "../BlockArea.h"
13 #include "../Cuboid.h"
14 
15 
16 
17 
18 
19 // fwd: ../BlockArea.h
20 class cBlockArea;
21 
22 
23 
24 
25 
26 // tolua_begin
28 {
29 public:
30  // tolua_end
31 
36  typedef Byte Shape[256 * 16 * 16];
37 
40 
41 
42  cChunkDesc(cChunkCoords a_Coords);
43  ~cChunkDesc();
44 
45  void SetChunkCoords(cChunkCoords a_Coords);
46 
47  // tolua_begin
48 
49  int GetChunkX() const { return m_Coords.m_ChunkX; } // Prefer GetChunkCoords() instead
50  int GetChunkZ() const { return m_Coords.m_ChunkZ; } // Prefer GetChunkCoords() instead
51 
52  // tolua_end
53 
54  cChunkCoords GetChunkCoords() const { return m_Coords; }
55 
56  // tolua_begin
57 
58  void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
59  void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
60 
61  // tolua_end
64  void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
65  // tolua_begin
66 
67  void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType);
68  BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const;
69 
70  void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta);
71  NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const;
72 
73  void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID);
74  EMCSBiome GetBiome(int a_RelX, int a_RelZ) const;
75 
76  // These operate on the heightmap, so they could get out of sync with the data
77  // Use UpdateHeightmap() to re-calculate heightmap from the block data
78  void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height);
79  HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const;
80 
81  // tolua_end
82 
85  void SetHeightFromShape(const Shape & a_Shape);
86 
88  void GetShapeFromHeight(Shape & a_Shape) const;
89 
90  // tolua_begin
91 
92  // Default generation:
93  void SetUseDefaultBiomes(bool a_bUseDefaultBiomes);
94  bool IsUsingDefaultBiomes(void) const;
95  void SetUseDefaultHeight(bool a_bUseDefaultHeight);
96  bool IsUsingDefaultHeight(void) const;
97  void SetUseDefaultComposition(bool a_bUseDefaultComposition);
98  bool IsUsingDefaultComposition(void) const;
99  void SetUseDefaultFinish(bool a_bUseDefaultFinish);
100  bool IsUsingDefaultFinish(void) const;
101 
103  void WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy = cBlockArea::msOverwrite);
104 
106  void ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ);
107 
109  HEIGHTTYPE GetMaxHeight(void) const;
110 
112  HEIGHTTYPE GetMinHeight(void) const;
113 
115  void FillRelCuboid(
116  int a_MinX, int a_MaxX,
117  int a_MinY, int a_MaxY,
118  int a_MinZ, int a_MaxZ,
119  BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
120  );
121 
123  void FillRelCuboid(const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
124  {
126  a_RelCuboid.p1.x, a_RelCuboid.p2.x,
127  a_RelCuboid.p1.y, a_RelCuboid.p2.y,
128  a_RelCuboid.p1.z, a_RelCuboid.p2.z,
129  a_BlockType, a_BlockMeta
130  );
131  }
132 
134  void ReplaceRelCuboid(
135  int a_MinX, int a_MaxX,
136  int a_MinY, int a_MaxY,
137  int a_MinZ, int a_MaxZ,
138  BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta,
139  BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
140  );
141 
144  const cCuboid & a_RelCuboid,
145  BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta,
146  BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
147  )
148  {
150  a_RelCuboid.p1.x, a_RelCuboid.p2.x,
151  a_RelCuboid.p1.y, a_RelCuboid.p2.y,
152  a_RelCuboid.p1.z, a_RelCuboid.p2.z,
153  a_SrcType, a_SrcMeta,
154  a_DstType, a_DstMeta
155  );
156  }
157 
159  void FloorRelCuboid(
160  int a_MinX, int a_MaxX,
161  int a_MinY, int a_MaxY,
162  int a_MinZ, int a_MaxZ,
163  BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
164  );
165 
168  const cCuboid & a_RelCuboid,
169  BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
170  )
171  {
173  a_RelCuboid.p1.x, a_RelCuboid.p2.x,
174  a_RelCuboid.p1.y, a_RelCuboid.p2.y,
175  a_RelCuboid.p1.z, a_RelCuboid.p2.z,
176  a_DstType, a_DstMeta
177  );
178  }
179 
181  void RandomFillRelCuboid(
182  int a_MinX, int a_MaxX,
183  int a_MinY, int a_MaxY,
184  int a_MinZ, int a_MaxZ,
185  BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
186  int a_RandomSeed, int a_ChanceOutOf10k
187  );
188 
191  const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
192  int a_RandomSeed, int a_ChanceOutOf10k
193  )
194  {
196  a_RelCuboid.p1.x, a_RelCuboid.p2.x,
197  a_RelCuboid.p1.y, a_RelCuboid.p2.y,
198  a_RelCuboid.p1.z, a_RelCuboid.p2.z,
199  a_BlockType, a_BlockMeta,
200  a_RandomSeed, a_ChanceOutOf10k
201  );
202  }
203 
207  cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ);
208 
211  void UpdateHeightmap(void);
212 
213  // tolua_end
214 
215  // Accessors used by cChunkGenerator::Generator descendants:
216  inline cChunkDef::BiomeMap & GetBiomeMap (void) { return m_BiomeMap; }
217  inline cChunkDef::BlockTypes & GetBlockTypes (void) { return *(reinterpret_cast<cChunkDef::BlockTypes *>(m_BlockArea.GetBlockTypes())); }
218  // CANNOT, different compression!
219  // inline cChunkDef::BlockNibbles & GetBlockMetas (void) { return *((cChunkDef::BlockNibbles *)m_BlockArea.GetBlockMetas()); }
220  inline BlockNibbleBytes & GetBlockMetasUncompressed(void) { return *(reinterpret_cast<BlockNibbleBytes *>(m_BlockArea.GetBlockMetas())); }
221  inline cChunkDef::HeightMap & GetHeightMap (void) { return m_HeightMap; }
222  inline cEntityList & GetEntities (void) { return m_Entities; }
223  inline cBlockEntities & GetBlockEntities (void) { return m_BlockEntities; }
224 
225  inline const cChunkDef::BiomeMap & GetBiomeMap() const { return m_BiomeMap; }
226  inline const cChunkDef::BlockTypes & GetBlockTypes() const { return *(reinterpret_cast<cChunkDef::BlockTypes *>(m_BlockArea.GetBlockTypes())); }
227  inline const cChunkDef::HeightMap & GetHeightMap() const { return m_HeightMap; }
228 
230  void CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas);
231 
232  #ifdef _DEBUG
233 
234  void VerifyHeightmap(void);
235  #endif // _DEBUG
236 
237 private:
239 
244  cBlockEntities m_BlockEntities; // Individual block entities are NOT owned by this object!
245 
250 } ; // tolua_export
251 
252 
253 
254 
HEIGHTTYPE GetMaxHeight(void) const
Returns the maximum height value in the heightmap.
Definition: ChunkDesc.cpp:397
BlockNibbleBytes & GetBlockMetasUncompressed(void)
Definition: ChunkDesc.h:220
std::map< size_t, cBlockEntity * > cBlockEntities
Definition: ChunkDef.h:34
NIBBLETYPE BlockNibbleBytes[cChunkDef::NumBlocks]
Uncompressed block metas, 1 meta per byte.
Definition: ChunkDesc.h:39
int GetChunkZ() const
Definition: ChunkDesc.h:50
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
Definition: ChunkDesc.h:36
void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
Definition: ChunkDesc.cpp:81
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)
Fills the relative cuboid with specified block; allows cuboid out of range of this chunk...
Definition: ChunkDesc.cpp:431
T x
Definition: Vector3.h:17
NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: ChunkDesc.cpp:99
cChunkDesc(cChunkCoords a_Coords)
Definition: ChunkDesc.cpp:16
bool m_bUseDefaultComposition
Definition: ChunkDesc.h:248
cChunkDef::BlockTypes & GetBlockTypes(void)
Definition: ChunkDesc.h:217
BLOCKTYPE BlockTypes[NumBlocks]
The type used for block type operations and storage, AXIS_ORDER ordering.
Definition: ChunkDef.h:150
void SetUseDefaultHeight(bool a_bUseDefaultHeight)
Definition: ChunkDesc.cpp:217
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
void GetShapeFromHeight(Shape &a_Shape) const
Sets the shape in a_Shape to match the heightmap stored currently in m_HeightMap. ...
Definition: ChunkDesc.cpp:175
eMergeStrategy
The per-block strategy to use when merging another block area into this object.
Definition: BlockArea.h:55
bool IsUsingDefaultBiomes(void) const
Definition: ChunkDesc.cpp:208
bool m_bUseDefaultBiomes
Definition: ChunkDesc.h:246
static const int NumBlocks
Definition: ChunkDef.h:136
bool m_bUseDefaultFinish
Definition: ChunkDesc.h:249
void ReplaceRelCuboid(const cCuboid &a_RelCuboid, BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta, BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta)
Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this...
Definition: ChunkDesc.h:143
Vector3i p1
Definition: Cuboid.h:13
cChunkCoords m_Coords
Definition: ChunkDesc.h:238
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Returns the BlockType and BlockMeta at the specified coords.
Definition: ChunkDesc.cpp:72
cChunkDef::HeightMap m_HeightMap
Definition: ChunkDesc.h:242
cEntityList m_Entities
Definition: ChunkDesc.h:243
EMCSBiome GetBiome(int a_RelX, int a_RelZ) const
Definition: ChunkDesc.cpp:126
void SetUseDefaultFinish(bool a_bUseDefaultFinish)
Definition: ChunkDesc.cpp:253
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
bool IsUsingDefaultComposition(void) const
Definition: ChunkDesc.cpp:244
const cChunkDef::BiomeMap & GetBiomeMap() const
Definition: ChunkDesc.h:225
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:21
void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:108
cChunkDef::BiomeMap m_BiomeMap
Definition: ChunkDesc.h:240
unsigned char HEIGHTTYPE
The type used by the heightmap.
Definition: ChunkDef.h:48
void WriteBlockArea(const cBlockArea &a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy=cBlockArea::msOverwrite)
Writes the block area into the chunk, with its origin set at the specified relative coords...
Definition: ChunkDesc.cpp:271
T y
Definition: Vector3.h:17
void UpdateHeightmap(void)
Updates the heightmap to match the current contents.
Definition: ChunkDesc.cpp:612
bool IsUsingDefaultFinish(void) const
Definition: ChunkDesc.cpp:262
T z
Definition: Vector3.h:17
void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height)
Definition: ChunkDesc.cpp:135
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
Definition: ChunkDesc.cpp:90
cChunkCoords GetChunkCoords() const
Definition: ChunkDesc.h:54
void ReadBlockArea(cBlockArea &a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ)
Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas.
Definition: ChunkDesc.cpp:280
void CompressBlockMetas(cChunkDef::BlockNibbles &a_DestMetas)
Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byt...
Definition: ChunkDesc.cpp:637
cChunkDef::HeightMap & GetHeightMap(void)
Definition: ChunkDesc.h:221
const cChunkDef::HeightMap & GetHeightMap() const
Definition: ChunkDesc.h:227
cBlockEntities m_BlockEntities
Definition: ChunkDesc.h:244
std::vector< OwnedEntity > cEntityList
Definition: ChunkDef.h:33
const cChunkDef::BlockTypes & GetBlockTypes() const
Definition: ChunkDesc.h:226
cBlockArea m_BlockArea
Definition: ChunkDesc.h:241
void SetUseDefaultComposition(bool a_bUseDefaultComposition)
Definition: ChunkDesc.cpp:235
void RandomFillRelCuboid(const cCuboid &a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_RandomSeed, int a_ChanceOutOf10k)
Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of th...
Definition: ChunkDesc.h:190
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)
Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air...
Definition: ChunkDesc.cpp:498
cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
Returns the block entity at the specified coords.
Definition: ChunkDesc.cpp:573
Definition: Cuboid.h:9
cEntityList & GetEntities(void)
Definition: ChunkDesc.h:222
int m_ChunkZ
Definition: ChunkDef.h:60
HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const
Definition: ChunkDesc.cpp:144
HEIGHTTYPE GetMinHeight(void) const
Returns the minimum height value in the heightmap.
Definition: ChunkDesc.cpp:414
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)
Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of th...
Definition: ChunkDesc.cpp:537
bool IsUsingDefaultHeight(void) const
Definition: ChunkDesc.cpp:226
void FillRelCuboid(const cCuboid &a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Fills the relative cuboid with specified block; allows cuboid out of range of this chunk...
Definition: ChunkDesc.h:123
int m_ChunkX
Definition: ChunkDef.h:59
bool m_bUseDefaultHeight
Definition: ChunkDesc.h:247
void FloorRelCuboid(const cCuboid &a_RelCuboid, BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta)
Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air...
Definition: ChunkDesc.h:167
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)
Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this...
Definition: ChunkDesc.cpp:461
void SetChunkCoords(cChunkCoords a_Coords)
Definition: ChunkDesc.cpp:45
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
Definition: BlockArea.h:386
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
Definition: ChunkDef.h:153
void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID)
Definition: ChunkDesc.cpp:117
int GetChunkX() const
Definition: ChunkDesc.h:49
NIBBLETYPE * GetBlockMetas(void) const
Definition: BlockArea.h:387
unsigned char Byte
Definition: Globals.h:117
void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:54
cBlockEntities & GetBlockEntities(void)
Definition: ChunkDesc.h:223
Vector3i p2
Definition: Cuboid.h:13
void SetUseDefaultBiomes(bool a_bUseDefaultBiomes)
Definition: ChunkDesc.cpp:199
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
Definition: ChunkDef.h:142
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:147
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:63
cChunkDef::BiomeMap & GetBiomeMap(void)
Definition: ChunkDesc.h:216
void SetHeightFromShape(const Shape &a_Shape)
Sets the heightmap to match the given shape data.
Definition: ChunkDesc.cpp:153