summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-06-08 21:52:13 +0200
committerMattes D <github@xoft.cz>2015-06-08 21:52:13 +0200
commitdb863422b8a49bbd43fc0204e36f7a2bdc51a674 (patch)
treead10ff1cbc0f692bce7a44c969b3a9e20e06ac91 /src
parentMerge pull request #2212 from mc-server/revert-2179-ChunkQueueCollapsing (diff)
downloadcuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.tar
cuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.tar.gz
cuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.tar.bz2
cuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.tar.lz
cuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.tar.xz
cuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.tar.zst
cuberite-db863422b8a49bbd43fc0204e36f7a2bdc51a674.zip
Diffstat (limited to 'src')
-rw-r--r--src/BlockArea.cpp59
-rw-r--r--src/BlockArea.h9
2 files changed, 68 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:
diff --git a/src/BlockArea.h b/src/BlockArea.h
index 4b672029b..a9963b4ef 100644
--- a/src/BlockArea.h
+++ b/src/BlockArea.h
@@ -308,6 +308,15 @@ public:
Returns 0 if blocktypes not available. Block metas are ignored (if present, air with any meta is still considered air). */
size_t CountNonAirBlocks(void) const;
+ /** Returns how many times the specified block is contained in the area.
+ The blocks' meta values are ignored, only the blocktype is compared. */
+ size_t CountSpecificBlocks(BLOCKTYPE a_BlockType) const;
+
+ /** Returns how many times the specified block is contained in the area.
+ Both the block's type and meta must match in order to be counted in.
+ If the block metas aren't present in the area, logs a warning and ignores the meta specification. */
+ size_t CountSpecificBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const;
+
// tolua_end
/** Returns the minimum and maximum coords in each direction for the first non-ignored block in each direction.