diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-06 18:58:31 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-06 18:58:31 +0200 |
commit | 4c370798d52b1b7c055c49ff4a38f73cf720c82e (patch) | |
tree | cb9c7233b4b55d8e6cb1fab410b81ea16f89d353 /source/BlockArea.cpp | |
parent | Lua plugins can get player's equipped item (diff) | |
download | cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.tar cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.tar.gz cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.tar.bz2 cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.tar.lz cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.tar.xz cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.tar.zst cuberite-4c370798d52b1b7c055c49ff4a38f73cf720c82e.zip |
Diffstat (limited to 'source/BlockArea.cpp')
-rw-r--r-- | source/BlockArea.cpp | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/source/BlockArea.cpp b/source/BlockArea.cpp index caeaf609e..8c3888782 100644 --- a/source/BlockArea.cpp +++ b/source/BlockArea.cpp @@ -50,6 +50,7 @@ void cBlockArea::Clear(void) +
bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes)
{
// Normalize the coords:
@@ -66,6 +67,11 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ std::swap(a_MinBlockZ, a_MaxBlockZ);
}
+ // Include the Max coords:
+ a_MaxBlockX += 1;
+ a_MaxBlockY += 1;
+ a_MaxBlockZ += 1;
+
// Check coords validity:
if (a_MinBlockY < 0)
{
@@ -111,6 +117,7 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ Clear();
return false;
}
+
return true;
}
@@ -120,15 +127,66 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ bool cBlockArea::Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
{
- // TODO
- ASSERT(!"Not implemented yet");
- return false;
+ ASSERT((a_DataTypes & GetDataTypes()) == a_DataTypes); // Are you requesting only the data that I have?
+ a_DataTypes = a_DataTypes & GetDataTypes(); // For release builds, silently cut off the datatypes that I don't have
+
+ // Check coords validity:
+ if (a_MinBlockY < 0)
+ {
+ LOGWARNING("cBlockArea:Read(): MinBlockY less than zero, adjusting to zero");
+ a_MinBlockY = 0;
+ }
+ else if (a_MinBlockY >= cChunkDef::Height - m_SizeY)
+ {
+ LOGWARNING("cBlockArea::Read(): MinBlockY + m_SizeY more than chunk height, adjusting to chunk height");
+ a_MinBlockY = cChunkDef::Height - m_SizeY - 1;
+ }
+
+ return a_World->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
}
+void cBlockArea::DumpToRawFile(const AString & a_FileName)
+{
+ cFile f;
+ if (!f.Open(a_FileName, cFile::fmWrite))
+ {
+ LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str());
+ return;
+ }
+ UInt32 SizeX = ntohl(m_SizeX);
+ UInt32 SizeY = ntohl(m_SizeY);
+ UInt32 SizeZ = ntohl(m_SizeZ);
+ f.Write(&SizeX, 4);
+ f.Write(&SizeY, 4);
+ f.Write(&SizeZ, 4);
+ unsigned char DataTypes = GetDataTypes();
+ f.Write(&DataTypes, 1);
+ int NumBlocks = GetBlockCount();
+ if (HasBlockTypes())
+ {
+ f.Write(m_BlockTypes, NumBlocks * sizeof(BLOCKTYPE));
+ }
+ if (HasBlockMetas())
+ {
+ f.Write(m_BlockMetas, NumBlocks);
+ }
+ if (HasBlockLights())
+ {
+ f.Write(m_BlockLight, NumBlocks);
+ }
+ if (HasBlockSkyLights())
+ {
+ f.Write(m_BlockSkyLight, NumBlocks);
+ }
+}
+
+
+
+
void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
{
@@ -623,4 +681,3 @@ void cBlockArea::cChunkReader::BlockSkyLight(const NIBBLETYPE * a_BlockSkyLight) -
|