Cuberite
A lightweight, fast and extensible game server for Minecraft
ChunkDesc.cpp
Go to the documentation of this file.
1 
2 // ChunkDesc.cpp
3 
4 // Implements 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 #include "Globals.h"
7 #include "ChunkDesc.h"
8 #include "../Noise/Noise.h"
9 #include "../BlockEntities/BlockEntity.h"
10 #include "../Entities/Entity.h"
11 
12 
13 
14 
15 
17  m_Coords(a_Coords),
18  m_bUseDefaultBiomes(true),
19  m_bUseDefaultHeight(true),
20  m_bUseDefaultComposition(true),
21  m_bUseDefaultFinish(true)
22 {
24  /*
25  memset(m_BlockTypes, 0, sizeof(cChunkDef::BlockTypes));
26  memset(m_BlockMeta, 0, sizeof(cChunkDef::BlockNibbles));
27  */
28  memset(m_BiomeMap, 0, sizeof(cChunkDef::BiomeMap));
29  memset(m_HeightMap, 0, sizeof(cChunkDef::HeightMap));
30 }
31 
32 
33 
34 
35 
37 {
38  // Nothing needed yet
39 }
40 
41 
42 
43 
44 
46 {
47  m_Coords = a_Coords;
48 }
49 
50 
51 
52 
53 
54 void cChunkDesc::FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
55 {
56  m_BlockArea.Fill(cBlockArea::baTypes | cBlockArea::baMetas, a_BlockType, a_BlockMeta);
57 }
58 
59 
60 
61 
62 
63 void cChunkDesc::SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
64 {
65  m_BlockArea.SetRelBlockTypeMeta(a_RelX, a_RelY, a_RelZ, a_BlockType, a_BlockMeta);
66 }
67 
68 
69 
70 
71 
72 void cChunkDesc::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const
73 {
74  m_BlockArea.GetRelBlockTypeMeta(a_RelX, a_RelY, a_RelZ, a_BlockType, a_BlockMeta);
75 }
76 
77 
78 
79 
80 
81 void cChunkDesc::SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
82 {
83  cChunkDef::SetBlock(m_BlockArea.GetBlockTypes(), a_RelX, a_RelY, a_RelZ, a_BlockType);
84 }
85 
86 
87 
88 
89 
90 BLOCKTYPE cChunkDesc::GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
91 {
92  return cChunkDef::GetBlock(m_BlockArea.GetBlockTypes(), a_RelX, a_RelY, a_RelZ);
93 }
94 
95 
96 
97 
98 
99 NIBBLETYPE cChunkDesc::GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
100 {
101  return m_BlockArea.GetRelBlockMeta(a_RelX, a_RelY, a_RelZ);
102 }
103 
104 
105 
106 
107 
108 void cChunkDesc::SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
109 {
110  m_BlockArea.SetRelBlockMeta(a_RelX, a_RelY, a_RelZ, a_BlockMeta);
111 }
112 
113 
114 
115 
116 
117 void cChunkDesc::SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID)
118 {
119  cChunkDef::SetBiome(m_BiomeMap, a_RelX, a_RelZ, a_BiomeID);
120 }
121 
122 
123 
124 
125 
126 EMCSBiome cChunkDesc::GetBiome(int a_RelX, int a_RelZ) const
127 {
128  return cChunkDef::GetBiome(m_BiomeMap, a_RelX, a_RelZ);
129 }
130 
131 
132 
133 
134 
135 void cChunkDesc::SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height)
136 {
137  cChunkDef::SetHeight(m_HeightMap, a_RelX, a_RelZ, a_Height);
138 }
139 
140 
141 
142 
143 
144 HEIGHTTYPE cChunkDesc::GetHeight(int a_RelX, int a_RelZ) const
145 {
146  return cChunkDef::GetHeight(m_HeightMap, a_RelX, a_RelZ);
147 }
148 
149 
150 
151 
152 
154 {
155  for (int z = 0; z < cChunkDef::Width; z++)
156  {
157  for (int x = 0; x < cChunkDef::Width; x++)
158  {
159  for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--)
160  {
161  if (a_Shape[y + x * 256 + z * 16 * 256] != 0)
162  {
164  break;
165  }
166  } // for y
167  } // for x
168  } // for z
169 }
170 
171 
172 
173 
174 
176 {
177  for (int z = 0; z < cChunkDef::Width; z++)
178  {
179  for (int x = 0; x < cChunkDef::Width; x++)
180  {
181  int height = cChunkDef::GetHeight(m_HeightMap, x, z);
182  for (int y = 0; y <= height; y++)
183  {
184  a_Shape[y + x * 256 + z * 16 * 256] = 1;
185  }
186 
187  for (int y = height + 1; y < cChunkDef::Height; y++)
188  {
189  a_Shape[y + x * 256 + z * 16 * 256] = 0;
190  } // for y
191  } // for x
192  } // for z
193 }
194 
195 
196 
197 
198 
199 void cChunkDesc::SetUseDefaultBiomes(bool a_bUseDefaultBiomes)
200 {
201  m_bUseDefaultBiomes = a_bUseDefaultBiomes;
202 }
203 
204 
205 
206 
207 
209 {
210  return m_bUseDefaultBiomes;
211 }
212 
213 
214 
215 
216 
217 void cChunkDesc::SetUseDefaultHeight(bool a_bUseDefaultHeight)
218 {
219  m_bUseDefaultHeight = a_bUseDefaultHeight;
220 }
221 
222 
223 
224 
225 
227 {
228  return m_bUseDefaultHeight;
229 }
230 
231 
232 
233 
234 
235 void cChunkDesc::SetUseDefaultComposition(bool a_bUseDefaultComposition)
236 {
237  m_bUseDefaultComposition = a_bUseDefaultComposition;
238 }
239 
240 
241 
242 
243 
245 {
247 }
248 
249 
250 
251 
252 
253 void cChunkDesc::SetUseDefaultFinish(bool a_bUseDefaultFinish)
254 {
255  m_bUseDefaultFinish = a_bUseDefaultFinish;
256 }
257 
258 
259 
260 
261 
263 {
264  return m_bUseDefaultFinish;
265 }
266 
267 
268 
269 
270 
271 void cChunkDesc::WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy)
272 {
273  m_BlockArea.Merge(a_BlockArea, a_RelX, a_RelY, a_RelZ, a_MergeStrategy);
274 }
275 
276 
277 
278 
279 
280 void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ)
281 {
282  // Normalize the coords:
283  if (a_MinRelX > a_MaxRelX)
284  {
285  std::swap(a_MinRelX, a_MaxRelX);
286  }
287  if (a_MinRelY > a_MaxRelY)
288  {
289  std::swap(a_MinRelY, a_MaxRelY);
290  }
291  if (a_MinRelZ > a_MaxRelZ)
292  {
293  std::swap(a_MinRelZ, a_MaxRelZ);
294  }
295 
296  // Include the Max coords:
297  a_MaxRelX += 1;
298  a_MaxRelY += 1;
299  a_MaxRelZ += 1;
300 
301  // Check coords validity:
302  if (a_MinRelX < 0)
303  {
304  LOGWARNING("%s: MinRelX less than zero, adjusting to zero", __FUNCTION__);
305  a_MinRelX = 0;
306  }
307  else if (a_MinRelX >= cChunkDef::Width)
308  {
309  LOGWARNING("%s: MinRelX more than chunk width, adjusting to chunk width", __FUNCTION__);
310  a_MinRelX = cChunkDef::Width - 1;
311  }
312  if (a_MaxRelX < 0)
313  {
314  LOGWARNING("%s: MaxRelX less than zero, adjusting to zero", __FUNCTION__);
315  a_MaxRelX = 0;
316  }
317  else if (a_MaxRelX > cChunkDef::Width)
318  {
319  LOGWARNING("%s: MaxRelX more than chunk width, adjusting to chunk width", __FUNCTION__);
320  a_MaxRelX = cChunkDef::Width;
321  }
322 
323  if (a_MinRelY < 0)
324  {
325  LOGWARNING("%s: MinRelY less than zero, adjusting to zero", __FUNCTION__);
326  a_MinRelY = 0;
327  }
328  else if (a_MinRelY >= cChunkDef::Height)
329  {
330  LOGWARNING("%s: MinRelY more than chunk height, adjusting to chunk height", __FUNCTION__);
331  a_MinRelY = cChunkDef::Height - 1;
332  }
333  if (a_MaxRelY < 0)
334  {
335  LOGWARNING("%s: MaxRelY less than zero, adjusting to zero", __FUNCTION__);
336  a_MaxRelY = 0;
337  }
338  else if (a_MaxRelY > cChunkDef::Height)
339  {
340  LOGWARNING("%s: MaxRelY more than chunk height, adjusting to chunk height", __FUNCTION__);
341  a_MaxRelY = cChunkDef::Height;
342  }
343 
344  if (a_MinRelZ < 0)
345  {
346  LOGWARNING("%s: MinRelZ less than zero, adjusting to zero", __FUNCTION__);
347  a_MinRelZ = 0;
348  }
349  else if (a_MinRelZ >= cChunkDef::Width)
350  {
351  LOGWARNING("%s: MinRelZ more than chunk width, adjusting to chunk width", __FUNCTION__);
352  a_MinRelZ = cChunkDef::Width - 1;
353  }
354  if (a_MaxRelZ < 0)
355  {
356  LOGWARNING("%s: MaxRelZ less than zero, adjusting to zero", __FUNCTION__);
357  a_MaxRelZ = 0;
358  }
359  else if (a_MaxRelZ > cChunkDef::Width)
360  {
361  LOGWARNING("%s: MaxRelZ more than chunk width, adjusting to chunk width", __FUNCTION__);
362  a_MaxRelZ = cChunkDef::Width;
363  }
364 
365  // Prepare the block area:
366  int SizeX = a_MaxRelX - a_MinRelX;
367  int SizeY = a_MaxRelY - a_MinRelY;
368  int SizeZ = a_MaxRelZ - a_MinRelZ;
369  a_Dest.Clear();
370  a_Dest.m_Origin.x = m_Coords.m_ChunkX * cChunkDef::Width + a_MinRelX;
371  a_Dest.m_Origin.y = a_MinRelY;
372  a_Dest.m_Origin.z = m_Coords.m_ChunkZ * cChunkDef::Width + a_MinRelZ;
373  a_Dest.SetSize(SizeX, SizeY, SizeZ, cBlockArea::baTypes | cBlockArea::baMetas);
374 
375  for (int y = 0; y < SizeY; y++)
376  {
377  int CDY = a_MinRelY + y;
378  for (int z = 0; z < SizeZ; z++)
379  {
380  int CDZ = a_MinRelZ + z;
381  for (int x = 0; x < SizeX; x++)
382  {
383  int CDX = a_MinRelX + x;
385  NIBBLETYPE BlockMeta;
386  GetBlockTypeMeta(CDX, CDY, CDZ, BlockType, BlockMeta);
387  a_Dest.SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta);
388  } // for x
389  } // for z
390  } // for y
391 }
392 
393 
394 
395 
396 
398 {
399  HEIGHTTYPE MaxHeight = m_HeightMap[0];
400  for (size_t i = 1; i < ARRAYCOUNT(m_HeightMap); i++)
401  {
402  if (m_HeightMap[i] > MaxHeight)
403  {
404  MaxHeight = m_HeightMap[i];
405  }
406  }
407  return MaxHeight;
408 }
409 
410 
411 
412 
413 
415 {
416  HEIGHTTYPE MinHeight = m_HeightMap[0];
417  for (size_t i = 1; i < ARRAYCOUNT(m_HeightMap); i++)
418  {
419  if (m_HeightMap[i] < MinHeight)
420  {
421  MinHeight = m_HeightMap[i];
422  }
423  }
424  return MinHeight;
425 }
426 
427 
428 
429 
430 
432  int a_MinX, int a_MaxX,
433  int a_MinY, int a_MaxY,
434  int a_MinZ, int a_MaxZ,
435  BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
436 )
437 {
438  int MinX = std::max(a_MinX, 0);
439  int MinY = std::max(a_MinY, 0);
440  int MinZ = std::max(a_MinZ, 0);
441  int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
442  int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
443  int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
444 
445  for (int y = MinY; y <= MaxY; y++)
446  {
447  for (int z = MinZ; z <= MaxZ; z++)
448  {
449  for (int x = MinX; x <= MaxX; x++)
450  {
451  SetBlockTypeMeta(x, y, z, a_BlockType, a_BlockMeta);
452  }
453  } // for z
454  } // for y
455 }
456 
457 
458 
459 
460 
462  int a_MinX, int a_MaxX,
463  int a_MinY, int a_MaxY,
464  int a_MinZ, int a_MaxZ,
465  BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta,
466  BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
467 )
468 {
469  int MinX = std::max(a_MinX, 0);
470  int MinY = std::max(a_MinY, 0);
471  int MinZ = std::max(a_MinZ, 0);
472  int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
473  int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
474  int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
475 
476  for (int y = MinY; y <= MaxY; y++)
477  {
478  for (int z = MinZ; z <= MaxZ; z++)
479  {
480  for (int x = MinX; x <= MaxX; x++)
481  {
483  NIBBLETYPE BlockMeta;
484  GetBlockTypeMeta(x, y, z, BlockType, BlockMeta);
485  if ((BlockType == a_SrcType) && (BlockMeta == a_SrcMeta))
486  {
487  SetBlockTypeMeta(x, y, z, a_DstType, a_DstMeta);
488  }
489  }
490  } // for z
491  } // for y
492 }
493 
494 
495 
496 
497 
499  int a_MinX, int a_MaxX,
500  int a_MinY, int a_MaxY,
501  int a_MinZ, int a_MaxZ,
502  BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
503 )
504 {
505  int MinX = std::max(a_MinX, 0);
506  int MinY = std::max(a_MinY, 0);
507  int MinZ = std::max(a_MinZ, 0);
508  int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
509  int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
510  int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
511 
512  for (int y = MinY; y <= MaxY; y++)
513  {
514  for (int z = MinZ; z <= MaxZ; z++)
515  {
516  for (int x = MinX; x <= MaxX; x++)
517  {
518  switch (GetBlockType(x, y, z))
519  {
520  case E_BLOCK_AIR:
521  case E_BLOCK_WATER:
523  {
524  SetBlockTypeMeta(x, y, z, a_DstType, a_DstMeta);
525  break;
526  }
527  } // switch (GetBlockType)
528  } // for x
529  } // for z
530  } // for y
531 }
532 
533 
534 
535 
536 
538  int a_MinX, int a_MaxX,
539  int a_MinY, int a_MaxY,
540  int a_MinZ, int a_MaxZ,
541  BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
542  int a_RandomSeed, int a_ChanceOutOf10k
543 )
544 {
545  cNoise Noise(a_RandomSeed);
546  int MinX = std::max(a_MinX, 0);
547  int MinY = std::max(a_MinY, 0);
548  int MinZ = std::max(a_MinZ, 0);
549  int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
550  int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
551  int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
552 
553  for (int y = MinY; y <= MaxY; y++)
554  {
555  for (int z = MinZ; z <= MaxZ; z++)
556  {
557  for (int x = MinX; x <= MaxX; x++)
558  {
559  int rnd = (Noise.IntNoise3DInt(x, y, z) / 7) % 10000;
560  if (rnd <= a_ChanceOutOf10k)
561  {
562  SetBlockTypeMeta(x, y, z, a_BlockType, a_BlockMeta);
563  }
564  }
565  } // for z
566  } // for y
567 }
568 
569 
570 
571 
572 
573 cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
574 {
575  const auto Idx = cChunkDef::MakeIndex(a_RelX, a_RelY, a_RelZ);
576  const auto itr = m_BlockEntities.find(Idx);
577 
578  if (itr != m_BlockEntities.end())
579  {
580  // Already in the list:
581  cBlockEntity * BlockEntity = itr->second.get();
582  if (BlockEntity->GetBlockType() == GetBlockType(a_RelX, a_RelY, a_RelZ))
583  {
584  // Correct type, already present. Return it:
585  return BlockEntity;
586  }
587  else
588  {
589  // Wrong type, the block type has been overwritten. Erase and create new:
590  m_BlockEntities.erase(itr);
591  }
592  }
593 
594  int AbsX = a_RelX + m_Coords.m_ChunkX * cChunkDef::Width;
595  int AbsZ = a_RelZ + m_Coords.m_ChunkZ * cChunkDef::Width;
596 
597  // The block entity is not created yet, try to create it and add to list:
598  auto be = cBlockEntity::CreateByBlockType(GetBlockType(a_RelX, a_RelY, a_RelZ), GetBlockMeta(a_RelX, a_RelY, a_RelZ), {AbsX, a_RelY, AbsZ});
599  if (be == nullptr)
600  {
601  // No block entity for this block type
602  return nullptr;
603  }
604  auto res = m_BlockEntities.emplace(Idx, std::move(be));
605  return res.first->second.get();
606 }
607 
608 
609 
610 
611 
613 {
614  for (int x = 0; x < cChunkDef::Width; x++)
615  {
616  for (int z = 0; z < cChunkDef::Width; z++)
617  {
618  HEIGHTTYPE Height = 0;
619  for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--)
620  {
621  BLOCKTYPE BlockType = GetBlockType(x, y, z);
622  if (BlockType != E_BLOCK_AIR)
623  {
624  Height = y;
625  break;
626  }
627  } // for y
628  SetHeight(x, z, Height);
629  } // for z
630  } // for x
631 }
632 
633 
634 
635 
636 
638 {
639  const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas();
640  for (size_t i = 0; i < ARRAYCOUNT(a_DestMetas); i++)
641  {
642  a_DestMetas[i] = static_cast<NIBBLETYPE>(AreaMetas[2 * i] | (AreaMetas[2 * i + 1] << 4));
643  }
644 }
645 
646 
647 
648 
649 
650 #ifndef NDEBUG
651 
653 {
654  for (int x = 0; x < cChunkDef::Width; x++)
655  {
656  for (int z = 0; z < cChunkDef::Width; z++)
657  {
658  for (int y = cChunkDef::Height - 1; y > 0; y--)
659  {
660  BLOCKTYPE BlockType = GetBlockType(x, y, z);
661  if (BlockType != E_BLOCK_AIR)
662  {
663  int Height = GetHeight(x, z);
664  ASSERT(Height == y);
665  break;
666  }
667  } // for y
668  } // for z
669  } // for x
670 }
671 
672 #endif // !NDEBUG
673 
674 
675 
676 
677 
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:18
@ E_BLOCK_WATER
Definition: BlockType.h:18
@ E_BLOCK_AIR
Definition: BlockType.h:10
@ E_BLOCK_STATIONARY_WATER
Definition: BlockType.h:19
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char HEIGHTTYPE
The type used by the heightmap.
Definition: ChunkDef.h:47
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:231
#define ASSERT(x)
Definition: Globals.h:276
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
BlockType
Definition: BlockTypes.h:4
void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Creates a new area of the specified size and contents.
Definition: BlockArea.cpp:338
void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Definition: BlockArea.cpp:1849
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: BlockArea.cpp:1796
NIBBLETYPE * GetBlockMetas(void) const
Definition: BlockArea.h:390
Vector3i m_Origin
Definition: BlockArea.h:460
bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
Clears the data stored and prepares a fresh new block area with the specified dimensions.
Definition: BlockArea.cpp:2076
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
Definition: BlockArea.h:389
void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta=0, NIBBLETYPE a_BlockLight=0, NIBBLETYPE a_BlockSkyLight=0x0f)
Fills the entire block area with the specified data.
Definition: BlockArea.cpp:773
NIBBLETYPE GetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: BlockArea.cpp:1733
eMergeStrategy
The per-block strategy to use when merging another block area into this object.
Definition: BlockArea.h:59
void Merge(const cBlockArea &a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy)
Merges another block area into this one, using the specified block combinating strategy This function...
Definition: BlockArea.cpp:742
void SetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
Definition: BlockArea.cpp:1656
void Clear(void)
Clears the data stored to reclaim memory.
Definition: BlockArea.cpp:323
static OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World=nullptr)
Creates a new block entity for the specified block type at the specified absolute pos.
Definition: BlockEntity.cpp:77
BLOCKTYPE GetBlockType() const
Definition: BlockEntity.h:97
Wraps the chunk coords into a single structure.
Definition: ChunkDef.h:57
int m_ChunkZ
Definition: ChunkDef.h:60
int m_ChunkX
Definition: ChunkDef.h:59
static void SetHeight(HeightMap &a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
Definition: ChunkDef.h:311
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:132
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, Vector3i a_RelPos)
Definition: ChunkDef.h:280
static size_t MakeIndex(int x, int y, int z)
Definition: ChunkDef.h:227
static const int Width
Definition: ChunkDef.h:124
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
Definition: ChunkDef.h:143
static const int Height
Definition: ChunkDef.h:125
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Definition: ChunkDef.h:303
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
Definition: ChunkDef.h:319
static void SetBiome(BiomeMap &a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
Definition: ChunkDef.h:327
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
Definition: ChunkDef.h:264
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:137
HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const
Definition: ChunkDesc.cpp:144
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
bool IsUsingDefaultHeight(void) const
Definition: ChunkDesc.cpp:226
EMCSBiome GetBiome(int a_RelX, int a_RelZ) const
Definition: ChunkDesc.cpp:126
cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
Returns the block entity at the specified coords.
Definition: ChunkDesc.cpp:573
void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
Definition: ChunkDesc.cpp:81
bool IsUsingDefaultBiomes(void) const
Definition: ChunkDesc.cpp:208
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
void SetUseDefaultBiomes(bool a_bUseDefaultBiomes)
Definition: ChunkDesc.cpp:199
void SetUseDefaultHeight(bool a_bUseDefaultHeight)
Definition: ChunkDesc.cpp:217
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
void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height)
Definition: ChunkDesc.cpp:135
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:63
bool IsUsingDefaultFinish(void) const
Definition: ChunkDesc.cpp:262
bool m_bUseDefaultHeight
Definition: ChunkDesc.h:265
void SetUseDefaultComposition(bool a_bUseDefaultComposition)
Definition: ChunkDesc.cpp:235
void SetChunkCoords(cChunkCoords a_Coords)
Definition: ChunkDesc.cpp:45
cBlockArea m_BlockArea
Definition: ChunkDesc.h:259
void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:108
bool m_bUseDefaultBiomes
Definition: ChunkDesc.h:264
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
NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: ChunkDesc.cpp:99
void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:54
cChunkDef::BiomeMap m_BiomeMap
Definition: ChunkDesc.h:258
void SetUseDefaultFinish(bool a_bUseDefaultFinish)
Definition: ChunkDesc.cpp:253
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
bool m_bUseDefaultComposition
Definition: ChunkDesc.h:266
void VerifyHeightmap(void)
Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column.
Definition: ChunkDesc.cpp:652
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
cBlockEntities m_BlockEntities
Definition: ChunkDesc.h:262
HEIGHTTYPE GetMinHeight(void) const
Returns the minimum height value in the heightmap.
Definition: ChunkDesc.cpp:414
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
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
bool m_bUseDefaultFinish
Definition: ChunkDesc.h:267
bool IsUsingDefaultComposition(void) const
Definition: ChunkDesc.cpp:244
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
Definition: ChunkDesc.cpp:90
cChunkCoords m_Coords
Definition: ChunkDesc.h:256
void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID)
Definition: ChunkDesc.cpp:117
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
cChunkDef::HeightMap m_HeightMap
Definition: ChunkDesc.h:260
void UpdateHeightmap(void)
Updates the heightmap to match the current contents.
Definition: ChunkDesc.cpp:612
void SetHeightFromShape(const Shape &a_Shape)
Sets the heightmap to match the given shape data.
Definition: ChunkDesc.cpp:153
HEIGHTTYPE GetMaxHeight(void) const
Returns the maximum height value in the heightmap.
Definition: ChunkDesc.cpp:397
cChunkDesc(cChunkCoords a_Coords)
Definition: ChunkDesc.cpp:16
Definition: Noise.h:20
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const
Definition: Noise.h:254
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17