Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockArea.h
Go to the documentation of this file.
1 
2 // BlockArea.h
3 
4 // Interfaces to the cBlockArea object representing an area of block data that can be queried from cWorld and then accessed again without further queries
5 // The object also supports writing the blockdata back into cWorld, even into other coords
6 
7 // NOTE: All Nibble values (meta, blocklight, skylight) are stored one-nibble-per-byte for faster access / editting!
8 // NOTE: Lua bindings for this object explicitly check parameter values. C++ code is expected to pass in valid params, so the functions ASSERT on invalid params.
9 // This includes the datatypes (must be present / valid combination), coords and sizes.
10 
11 
12 
13 
14 
15 #pragma once
16 
17 #include "BlockType.h"
18 #include "ForEachChunkProvider.h"
19 #include "ChunkDataCallback.h"
20 #include "Cuboid.h"
21 #include "FunctionRef.h"
23 
24 
25 
26 
27 // fwd:
28 class cCuboid;
29 class cItem;
30 class cItems;
32 
33 
34 
35 
36 // tolua_begin
38 {
39  // tolua_end
41  // tolua_begin
42 
43 public:
44 
46  enum
47  {
48  baTypes = 1,
49  baMetas = 2,
50  baLight = 4,
52  // baEntities = 16, // Not supported yet
54  } ;
55 
59  {
68  } ;
69 
70  cBlockArea(void);
71 
74  static bool IsValidDataTypeCombination(int a_DataTypes);
75 
77  void Clear(void);
78 
79  // tolua_end
80 
84  void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas | baBlockEntities);
85 
89  void Create(const Vector3i & a_Size, int a_DataTypes = baTypes | baMetas | baBlockEntities);
90 
91  // tolua_begin
92 
94  void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ);
95 
97  void SetOrigin(const Vector3i & a_Origin);
98 
100  bool IsValidRelCoords(int a_RelX, int a_RelY, int a_RelZ) const;
101 
103  bool IsValidRelCoords(const Vector3i & a_RelCoords) const;
104 
106  bool IsValidCoords(int a_BlockX, int a_BlockY, int a_BlockZ) const;
107 
109  bool IsValidCoords(const Vector3i & a_Coords) const;
110 
111  // tolua_end
112 
114  bool Read(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas | baBlockEntities);
115 
117  bool Read(cForEachChunkProvider & a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes = baTypes | baMetas | baBlockEntities);
118 
120  bool Read(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes = baTypes | baMetas | baBlockEntities);
121 
122  // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write
123  // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again
124 
127  bool Write(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes);
128 
131  bool Write(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ)
132  {
133  // Write all available data
134  return Write(a_ForEachChunkProvider, a_MinBlockX, a_MinBlockY, a_MinBlockZ, GetDataTypes());
135  }
136 
139  bool Write(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes);
140 
143  bool Write(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_MinCoords)
144  {
145  // Write all available data
146  return Write(a_ForEachChunkProvider, a_MinCoords.x, a_MinCoords.y, a_MinCoords.z, GetDataTypes());
147  }
148 
149  // tolua_begin
150 
152  void CopyTo(cBlockArea & a_Into) const;
153 
155  void CopyFrom(const cBlockArea & a_From);
156 
158  void DumpToRawFile(const AString & a_FileName);
159 
161  void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
162 
164  void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
165 
237  void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy);
238 
241  void Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy);
242 
244  void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f);
245 
246  // tolua_end
247 
249  void FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ,
250  int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
251  NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
252  );
253 
255  void FillRelCuboid(const cCuboid & a_RelCuboid,
256  int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
257  NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
258  );
259 
261  void RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2,
262  int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
263  NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
264  );
265 
267  void RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2,
268  int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
269  NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
270  );
271 
272  // tolua_begin
273 
275  void RotateCCW(void);
276 
278  void RotateCW(void);
279 
281  void MirrorXY(void);
282 
284  void MirrorXZ(void);
285 
287  void MirrorYZ(void);
288 
290  void RotateCCWNoMeta(void);
291 
293  void RotateCWNoMeta(void);
294 
296  void MirrorXYNoMeta(void);
297 
299  void MirrorXZNoMeta(void);
300 
302  void MirrorYZNoMeta(void);
303 
304  // tolua_end
305 
306  // Setters:
307  void SetRelBlockType (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType);
308  void SetBlockType (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType);
309  void SetRelBlockMeta (int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta);
310  void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta);
311  void SetRelBlockLight (int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockLight);
312  void SetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight);
313  void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight);
314  void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight);
315 
316  // tolua_begin
317 
318  void SetWEOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ);
319  void SetWEOffset (const Vector3i & a_Offset);
320  const Vector3i & GetWEOffset (void) const {return m_WEOffset;}
321 
322  // tolua_end
323 
324  // Getters:
325  BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const;
326  BLOCKTYPE GetBlockType (int a_BlockX, int a_BlockY, int a_BlockZ) const;
327  NIBBLETYPE GetRelBlockMeta (int a_RelX, int a_RelY, int a_RelZ) const;
328  NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ) const;
329  NIBBLETYPE GetRelBlockLight (int a_RelX, int a_RelY, int a_RelZ) const;
330  NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
331  NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
332  NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
333 
334  void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
335  void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
336 
337  void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
338  void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
339 
340  const Vector3i & GetSize(void) const { return m_Size; }
341  const Vector3i & GetOrigin(void) const { return m_Origin; }
342 
343  // tolua_begin
344 
345  cCuboid GetBounds(void) const;
346 
347  int GetSizeX(void) const { return m_Size.x; }
348  int GetSizeY(void) const { return m_Size.y; }
349  int GetSizeZ(void) const { return m_Size.z; }
350 
352  int GetVolume(void) const { return m_Size.x * m_Size.y * m_Size.z; }
353 
354  int GetOriginX(void) const { return m_Origin.x; }
355  int GetOriginY(void) const { return m_Origin.y; }
356  int GetOriginZ(void) const { return m_Origin.z; }
357 
359  int GetDataTypes(void) const;
360 
361  bool HasBlockTypes (void) const { return (m_BlockTypes != nullptr); }
362  bool HasBlockMetas (void) const { return (m_BlockMetas != nullptr); }
363  bool HasBlockLights (void) const { return (m_BlockLight != nullptr); }
364  bool HasBlockSkyLights(void) const { return (m_BlockSkyLight != nullptr); }
365  bool HasBlockEntities (void) const { return (m_BlockEntities != nullptr); }
366 
369  size_t CountNonAirBlocks(void) const;
370 
373  size_t CountSpecificBlocks(BLOCKTYPE a_BlockType) const;
374 
378  size_t CountSpecificBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const;
379 
380  // tolua_end
381 
385  void GetNonAirCropRelCoords(int & a_MinRelX, int & a_MinRelY, int & a_MinRelZ, int & a_MaxRelX, int & a_MaxRelY, int & a_MaxRelZ, BLOCKTYPE a_IgnoreBlockType = E_BLOCK_AIR);
386 
387  // Clients can use these for faster access to all blocktypes. Be careful though!
389  BLOCKTYPE * GetBlockTypes (void) const { return m_BlockTypes.get(); }
390  NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas.get(); } // NOTE: one byte per block!
391  NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight.get(); } // NOTE: one byte per block!
392  NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight.get(); } // NOTE: one byte per block!
393  size_t GetBlockCount(void) const { return static_cast<size_t>(m_Size.x * m_Size.y * m_Size.z); }
394  static size_t MakeIndexForSize(Vector3i a_RelPos, Vector3i a_Size);
395 
397  size_t MakeIndex(Vector3i a_RelPos) const
398  {
399  return MakeIndexForSize(a_RelPos, m_Size);
400  }
401 
404  size_t MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const
405  {
406  return MakeIndexForSize({ a_RelX, a_RelY, a_RelZ }, m_Size);
407  }
408 
412  bool DoWithBlockEntityRelAt(int a_RelX, int a_RelY, int a_RelZ, cBlockEntityCallback a_Callback);
413 
417  bool DoWithBlockEntityAt (int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback a_Callback);
418 
423  bool ForEachBlockEntity(cBlockEntityCallback a_Callback);
424 
427 
428 
429 
430 protected:
431 
432  friend class cChunkDesc;
434 
436  public cChunkDataCallback
437  {
438  public:
439  cChunkReader(cBlockArea & a_Area);
440 
441  protected:
447 
448  void CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc);
449 
450  // cChunkDataCallback overrides:
451  virtual bool Coords(int a_ChunkX, int a_ChunkZ) override;
452  virtual void ChunkData(const ChunkBlockData & a_BlockData, const ChunkLightData & a_LightData) override;
453  virtual void BlockEntity(cBlockEntity * a_BlockEntity) override;
454  } ;
455 
456  using NIBBLEARRAY = std::unique_ptr<NIBBLETYPE[]>;
457  using BLOCKARRAY = std::unique_ptr<BLOCKTYPE[]>;
458  using cBlockEntitiesPtr = std::unique_ptr<cBlockEntities>;
459 
462 
466 
468  NIBBLEARRAY m_BlockMetas; // Each meta is stored as a separate byte for faster access
469  NIBBLEARRAY m_BlockLight; // Each light value is stored as a separate byte for faster access
470  NIBBLEARRAY m_BlockSkyLight; // Each light value is stored as a separate byte for faster access
471 
476 
478  bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes);
479 
480  // Basic Setters:
481  void SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array);
482  void SetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array);
483 
484  // Basic Getters:
485  NIBBLETYPE GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE * a_Array) const;
486  NIBBLETYPE GetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const;
487 
488  // Crop helpers:
489  void CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
490  void CropNibbles (NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
491 
492  // Expand helpers:
493  void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
494  void ExpandNibbles (NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
495 
498  void RelSetData(
499  int a_RelX, int a_RelY, int a_RelZ,
500  int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
501  NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
502  );
503 
504  template <bool MetasValid>
505  void MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE * SrcMetas, NIBBLETYPE * DstMetas);
506 
510  void MergeBlockEntities(int a_RelX, int a_RelY, int a_RelZ, const cBlockArea & a_Src);
511 
513  void RescanBlockEntities(void);
514 
517 
520 
521  // tolua_begin
522 } ;
523 // tolua_end
524 
525 
526 
527 
@ E_BLOCK_AIR
Definition: BlockType.h:10
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define ASSERT(x)
Definition: Globals.h:276
std::string AString
Definition: StringUtils.h:11
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
void SetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: BlockArea.cpp:1787
void MergeByStrategy(const cBlockArea &a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE *SrcMetas, NIBBLETYPE *DstMetas)
Definition: BlockArea.cpp:2416
size_t MakeIndex(Vector3i a_RelPos) const
Returns the index into the internal arrays for the specified coords.
Definition: BlockArea.h:397
cBlockEntitiesPtr m_BlockEntities
The block entities contained within the area.
Definition: BlockArea.h:475
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
Expands the internal contents by the specified amount of blocks from each border.
Definition: BlockArea.cpp:698
void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
Resets the origin.
Definition: BlockArea.cpp:387
static bool IsValidDataTypeCombination(int a_DataTypes)
Returns true if the datatype combination is valid.
Definition: BlockArea.cpp:304
void MirrorYZ(void)
Mirrors the entire area around the YZ plane.
Definition: BlockArea.cpp:1275
NIBBLETYPE GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE *a_Array) const
Definition: BlockArea.cpp:2244
NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) const
Definition: BlockArea.cpp:1742
int GetVolume(void) const
Returns the volume of the area, as number of blocks.
Definition: BlockArea.h:352
bool DoWithBlockEntityRelAt(int a_RelX, int a_RelY, int a_RelZ, cBlockEntityCallback a_Callback)
Calls the callback for the block entity at the specified coords.
Definition: BlockArea.cpp:2158
bool Write(cForEachChunkProvider &a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
Writes the area back into cWorld at the coords specified.
Definition: BlockArea.cpp:518
const Vector3i & GetSize(void) const
Definition: BlockArea.h:340
NIBBLETYPE * GetBlockMetas(void) const
Definition: BlockArea.h:390
Vector3i m_Size
Definition: BlockArea.h:461
BLOCKARRAY m_BlockTypes
Definition: BlockArea.h:467
void FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta=0, NIBBLETYPE a_BlockLight=0, NIBBLETYPE a_BlockSkyLight=0x0f)
Fills a cuboid inside the block area with the specified data.
Definition: BlockArea.cpp:831
bool ForEachBlockEntity(cBlockEntityCallback a_Callback)
Calls the callback for all the block entities.
Definition: BlockArea.cpp:2187
void SetBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight)
Definition: BlockArea.cpp:1683
Vector3i m_WEOffset
An extra data value sometimes stored in the .schematic file.
Definition: BlockArea.h:465
void SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ)
Definition: BlockArea.cpp:369
std::unique_ptr< BLOCKTYPE[]> BLOCKARRAY
Definition: BlockArea.h:457
bool HasBlockSkyLights(void) const
Definition: BlockArea.h:364
void MirrorXY(void)
Mirrors the entire area around the XY plane.
Definition: BlockArea.cpp:1161
void RescanBlockEntities(void)
Updates m_BlockEntities to remove BEs that no longer match the blocktype at their coords,...
Definition: BlockArea.cpp:2627
size_t CountSpecificBlocks(BLOCKTYPE a_BlockType) const
Returns how many times the specified block is contained in the area.
Definition: BlockArea.cpp:1920
void MirrorYZNoMeta(void)
Mirrors the entire area around the YZ plane, doesn't use blockhandlers for block meta.
Definition: BlockArea.cpp:1562
bool Write(cForEachChunkProvider &a_ForEachChunkProvider, const Vector3i &a_MinCoords)
Writes the area back into cWorld at the coords specified.
Definition: BlockArea.h:143
void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
Crops the internal contents by the specified amount of blocks from each border.
Definition: BlockArea.cpp:635
void RotateCCWNoMeta(void)
Rotates the entire area counter-clockwise around the Y axis, doesn't use blockhandlers for block meta...
Definition: BlockArea.cpp:1332
void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight)
Definition: BlockArea.cpp:1692
int GetOriginZ(void) const
Definition: BlockArea.h:356
void CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
Definition: BlockArea.cpp:2253
void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
Definition: BlockArea.cpp:2302
@ baSkyLight
Definition: BlockArea.h:51
@ baBlockEntities
Definition: BlockArea.h:53
cBlockEntity * GetBlockEntityRel(Vector3i a_RelPos)
Returns the cBlockEntity at the specified coords, or nullptr if none.
Definition: BlockArea.cpp:2685
void GetNonAirCropRelCoords(int &a_MinRelX, int &a_MinRelY, int &a_MinRelZ, int &a_MaxRelX, int &a_MaxRelY, int &a_MaxRelZ, BLOCKTYPE a_IgnoreBlockType=E_BLOCK_AIR)
Returns the minimum and maximum coords in each direction for the first non-ignored block in each dire...
Definition: BlockArea.cpp:1979
void MirrorXYNoMeta(void)
Mirrors the entire area around the XY plane, doesn't use blockhandlers for block meta.
Definition: BlockArea.cpp:1454
void GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Definition: BlockArea.cpp:1840
NIBBLETYPE GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE *a_Array) const
Definition: BlockArea.cpp:2230
const Vector3i & GetWEOffset(void) const
Definition: BlockArea.h:320
size_t CountNonAirBlocks(void) const
Returns the count of blocks that are not air.
Definition: BlockArea.cpp:1889
NIBBLEARRAY m_BlockMetas
Definition: BlockArea.h:468
Vector3i m_Origin
Definition: BlockArea.h:460
bool Write(cForEachChunkProvider &a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ)
Writes the area back into cWorld at the coords specified.
Definition: BlockArea.h:131
void SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType)
Definition: BlockArea.cpp:1647
NIBBLEARRAY m_BlockLight
Definition: BlockArea.h:469
void SetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight)
Definition: BlockArea.cpp:1701
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
NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const
Definition: BlockArea.cpp:1769
void SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
Definition: BlockArea.cpp:1616
bool HasBlockLights(void) const
Definition: BlockArea.h:363
bool HasBlockEntities(void) const
Definition: BlockArea.h:365
size_t GetBlockCount(void) const
Definition: BlockArea.h:393
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback a_Callback)
Calls the callback for the block entity at the specified coords.
Definition: BlockArea.cpp:2178
void CopyFrom(const cBlockArea &a_From)
Copies the contents from the specified BlockArea into this object.
Definition: BlockArea.cpp:587
int GetSizeY(void) const
Definition: BlockArea.h:348
NIBBLETYPE GetRelBlockLight(int a_RelX, int a_RelY, int a_RelZ) const
Definition: BlockArea.cpp:1751
bool HasBlockTypes(void) const
Definition: BlockArea.h:361
cBlockArea(void)
void RotateCW(void)
Rotates the entire area clockwise around the Y axis.
Definition: BlockArea.cpp:1101
int GetDataTypes(void) const
Returns the datatypes that are stored in the object (bitmask of baXXX values)
Definition: BlockArea.cpp:2046
void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta)
Definition: BlockArea.cpp:1665
void CropNibbles(NIBBLEARRAY &a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
Definition: BlockArea.cpp:2278
int GetOriginY(void) const
Definition: BlockArea.h:355
void MirrorXZ(void)
Mirrors the entire area around the XZ plane.
Definition: BlockArea.cpp:1218
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
int GetOriginX(void) const
Definition: BlockArea.h:354
void RotateCCW(void)
Rotates the entire area counter-clockwise around the Y axis.
Definition: BlockArea.cpp:1041
BLOCKTYPE GetRelBlockType(int a_RelX, int a_RelY, int a_RelZ) const
Definition: BlockArea.cpp:1710
void RelSetData(int a_RelX, int a_RelY, int a_RelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight)
Sets the specified datatypes at the specified location.
Definition: BlockArea.cpp:2360
void SetRelBlockLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockLight)
Definition: BlockArea.cpp:1674
int GetSizeZ(void) const
Definition: BlockArea.h:349
void RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta=0, NIBBLETYPE a_BlockLight=0, NIBBLETYPE a_BlockSkyLight=0x0f)
Draws a line between two points with the specified data.
Definition: BlockArea.cpp:908
void MirrorXZNoMeta(void)
Mirrors the entire area around the XZ plane, doesn't use blockhandlers for block meta.
Definition: BlockArea.cpp:1508
cCuboid GetBounds(void) const
Definition: BlockArea.cpp:1877
DISALLOW_COPY_AND_ASSIGN(cBlockArea)
NIBBLETYPE * GetBlockSkyLight(void) const
Definition: BlockArea.h:392
NIBBLETYPE GetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: BlockArea.cpp:1733
NIBBLETYPE * GetBlockLight(void) const
Definition: BlockArea.h:391
eMergeStrategy
The per-block strategy to use when merging another block area into this object.
Definition: BlockArea.h:59
@ msOverwrite
Definition: BlockArea.h:60
@ msSimpleCompare
Definition: BlockArea.h:66
@ msDifference
Definition: BlockArea.h:65
@ msSpongePrint
Definition: BlockArea.h:64
bool Read(cForEachChunkProvider &a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Reads an area of blocks specified.
Definition: BlockArea.cpp:445
void DumpToRawFile(const AString &a_FileName)
For testing purposes only, dumps the area into a file.
Definition: BlockArea.cpp:596
int GetSizeX(void) const
Definition: BlockArea.h:347
void SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Value, NIBBLETYPE *a_Array)
Definition: BlockArea.cpp:2207
bool IsValidRelCoords(int a_RelX, int a_RelY, int a_RelZ) const
Returns true if the specified relative coords are within this area's coord range (0 - m_Size).
Definition: BlockArea.cpp:405
void CopyTo(cBlockArea &a_Into) const
Copies this object's contents into the specified BlockArea.
Definition: BlockArea.cpp:544
std::unique_ptr< NIBBLETYPE[]> NIBBLEARRAY
Definition: BlockArea.h:456
static size_t MakeIndexForSize(Vector3i a_RelPos, Vector3i a_Size)
Definition: BlockArea.cpp:2142
std::unique_ptr< cBlockEntities > cBlockEntitiesPtr
Definition: BlockArea.h:458
const cBlockEntities & GetBlockEntities(void) const
Direct read-only access to block entities.
Definition: BlockArea.h:426
bool HasBlockMetas(void) const
Definition: BlockArea.h:362
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
size_t MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const
OBSOLETE, use the Vector3i-based overload instead.
Definition: BlockArea.h:404
void MergeBlockEntities(int a_RelX, int a_RelY, int a_RelZ, const cBlockArea &a_Src)
Updates m_BlockEntities to remove BEs that no longer match the blocktype at their coords,...
Definition: BlockArea.cpp:2574
void RotateCWNoMeta(void)
Rotates the entire area clockwise around the Y axis, doesn't use blockhandlers for block meta.
Definition: BlockArea.cpp:1393
void SetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE *a_Array)
Definition: BlockArea.cpp:2221
bool IsValidCoords(int a_BlockX, int a_BlockY, int a_BlockZ) const
Returns true if the specified coords are within this area's coord range (as indicated by m_Origin).
Definition: BlockArea.cpp:427
void ExpandNibbles(NIBBLEARRAY &a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
Definition: BlockArea.cpp:2331
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
NIBBLEARRAY m_BlockSkyLight
Definition: BlockArea.h:470
const Vector3i & GetOrigin(void) const
Definition: BlockArea.h:341
void RemoveNonMatchingBlockEntities(void)
Removes from m_BlockEntities those BEs that no longer match the blocktype at their coords.
Definition: BlockArea.cpp:2663
BLOCKTYPE GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const
Definition: BlockArea.cpp:1724
virtual bool Coords(int a_ChunkX, int a_ChunkZ) override
Definition: BlockArea.cpp:2781
virtual void BlockEntity(cBlockEntity *a_BlockEntity) override
Definition: BlockArea.cpp:2925
cChunkReader(cBlockArea &a_Area)
Definition: BlockArea.cpp:2702
cCuboid m_AreaBounds
Bounds of the whole area being read, in world coords.
Definition: BlockArea.h:443
void CopyNibbles(NIBBLETYPE *a_AreaDst, const NIBBLETYPE *a_ChunkSrc)
Definition: BlockArea.cpp:2715
virtual void ChunkData(const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData) override
Definition: BlockArea.cpp:2792
Definition: Cuboid.h:10
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17
std::unordered_map< size_t, OwnedBlockEntity > cBlockEntities
Definition: BlockEntity.h:17