summaryrefslogtreecommitdiffstats
path: root/src/BlockArea.cpp
diff options
context:
space:
mode:
authorJulian Laubstein <julianlaubstein@yahoo.de>2015-06-08 23:05:49 +0200
committerJulian Laubstein <julianlaubstein@yahoo.de>2015-06-08 23:05:49 +0200
commit87a8df7cdec4b914e82177a84694d9f5b4760d4d (patch)
treead10ff1cbc0f692bce7a44c969b3a9e20e06ac91 /src/BlockArea.cpp
parentMerge pull request #2212 from mc-server/revert-2179-ChunkQueueCollapsing (diff)
parentcBlockArea: Added CountSpecificBlocks() API function. (diff)
downloadcuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.tar
cuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.tar.gz
cuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.tar.bz2
cuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.tar.lz
cuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.tar.xz
cuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.tar.zst
cuberite-87a8df7cdec4b914e82177a84694d9f5b4760d4d.zip
Diffstat (limited to 'src/BlockArea.cpp')
-rw-r--r--src/BlockArea.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index 7982afc31..938351207 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -1665,6 +1665,65 @@ size_t cBlockArea::CountNonAirBlocks(void) const
+size_t cBlockArea::CountSpecificBlocks(BLOCKTYPE a_BlockType) const
+{
+ // If blocktypes are not valid, log a warning and return zero occurences:
+ if (m_BlockTypes == nullptr)
+ {
+ LOGWARNING("%s: BlockTypes not available!", __FUNCTION__);
+ return 0;
+ }
+
+ // Count the blocks:
+ size_t num = GetBlockCount();
+ size_t res = 0;
+ for (size_t i = 0; i < num; i++)
+ {
+ if (m_BlockTypes[i] == a_BlockType)
+ {
+ res++;
+ }
+ }
+ return res;
+}
+
+
+
+
+
+size_t cBlockArea::CountSpecificBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const
+{
+ // If blocktypes are not valid, log a warning and return zero occurences:
+ if (m_BlockTypes == nullptr)
+ {
+ LOGWARNING("%s: BlockTypes not available!", __FUNCTION__);
+ return 0;
+ }
+
+ // If blockmetas are not valid, log a warning and count only blocktypes:
+ if (m_BlockMetas == nullptr)
+ {
+ LOGWARNING("%s: BlockMetas not available, comparing blocktypes only!", __FUNCTION__);
+ return CountSpecificBlocks(a_BlockType);
+ }
+
+ // Count the blocks:
+ size_t num = GetBlockCount();
+ size_t res = 0;
+ for (size_t i = 0; i < num; i++)
+ {
+ if ((m_BlockTypes[i] == a_BlockType) && (m_BlockMetas[i] == a_BlockMeta))
+ {
+ res++;
+ }
+ }
+ return res;
+}
+
+
+
+
+
void cBlockArea::GetNonAirCropRelCoords(int & a_MinRelX, int & a_MinRelY, int & a_MinRelZ, int & a_MaxRelX, int & a_MaxRelY, int & a_MaxRelZ, BLOCKTYPE a_IgnoreBlockType)
{
// Check if blocktypes are valid: