summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-05-01 11:49:41 +0200
committerMattes D <github@xoft.cz>2015-05-01 11:49:41 +0200
commit259132d17e53ec99c4eb00cd856260d14ea1234d (patch)
treebcb6ff9fc661b0fc1d8ad492f12c874227b4d949
parentMerge pull request #1923 from mc-server/ReadWholeFileFix (diff)
parentAdded cBlockArea:CountNonAirBlocks API function. (diff)
downloadcuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.tar
cuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.tar.gz
cuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.tar.bz2
cuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.tar.lz
cuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.tar.xz
cuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.tar.zst
cuberite-259132d17e53ec99c4eb00cd856260d14ea1234d.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua1
-rw-r--r--src/BlockArea.cpp31
-rw-r--r--src/BlockArea.h6
3 files changed, 37 insertions, 1 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 7c9a2e0cb..7c0a8e818 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -99,6 +99,7 @@ g_APIDesc =
Clear = { Params = "", Return = "", Notes = "Clears the object, resets it to zero size" },
CopyFrom = { Params = "BlockAreaSrc", Return = "", Notes = "Copies contents from BlockAreaSrc into self" },
CopyTo = { Params = "BlockAreaDst", Return = "", Notes = "Copies contents from self into BlockAreaDst." },
+ CountNonAirBlocks = { Params = "", Return = "number", Notes = "Returns the count of blocks that are not air. Returns 0 if blocktypes not available. Block metas are ignored (if present, air with any meta is still considered air)." },
Create = { Params = "SizeX, SizeY, SizeZ, [DataTypes]", Return = "", Notes = "Initializes this BlockArea to an empty area of the specified size and origin of {0, 0, 0}. Any previous contents are lost." },
Crop = { Params = "AddMinX, SubMaxX, AddMinY, SubMaxY, AddMinZ, SubMaxZ", Return = "", Notes = "Crops the specified number of blocks from each border. Modifies the size of this blockarea object." },
DumpToRawFile = { Params = "FileName", Return = "", Notes = "Dumps the raw data into a file. For debugging purposes only." },
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index 600940d96..89cf18d4a 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -1634,6 +1634,37 @@ void cBlockArea::GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTY
+size_t cBlockArea::CountNonAirBlocks(void) const
+{
+ // Check if blocktypes are valid:
+ if (m_BlockTypes == nullptr)
+ {
+ LOGWARNING("%s: BlockTypes have not been read!", __FUNCTION__);
+ return 0;
+ }
+
+ // Count the blocks:
+ size_t res = 0;
+ for (int y = 0; y < m_Size.y; y++)
+ {
+ for (int z = 0; z < m_Size.z; z++)
+ {
+ for (int x = 0; x < m_Size.x; x++)
+ {
+ if (m_BlockTypes[MakeIndex(x, y, z)] != E_BLOCK_AIR)
+ {
+ ++res;
+ }
+ } // for x
+ } // for z
+ } // for y
+ 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 ce417ceb4..856df542f 100644
--- a/src/BlockArea.h
+++ b/src/BlockArea.h
@@ -303,7 +303,11 @@ public:
bool HasBlockMetas (void) const { return (m_BlockMetas != nullptr); }
bool HasBlockLights (void) const { return (m_BlockLight != nullptr); }
bool HasBlockSkyLights(void) const { return (m_BlockSkyLight != nullptr); }
-
+
+ /** Returns the count of blocks that are not air.
+ 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;
+
// tolua_end
/** Returns the minimum and maximum coords in each direction for the first non-ignored block in each direction.