summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2014-03-10 17:07:46 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2014-03-10 17:07:46 +0100
commit0cce0478d846114f49c4b8fe201aee7a1bb06b22 (patch)
treebb0bce87ded48eccd1bb913153b7e4f935462326
parentMerge pull request #770 from xdot/master (diff)
downloadcuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.tar
cuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.tar.gz
cuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.tar.bz2
cuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.tar.lz
cuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.tar.xz
cuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.tar.zst
cuberite-0cce0478d846114f49c4b8fe201aee7a1bb06b22.zip
-rw-r--r--src/BlockArea.cpp19
-rw-r--r--src/BlockArea.h5
-rw-r--r--src/WorldStorage/SchematicFileSerializer.cpp23
3 files changed, 47 insertions, 0 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index d07ef747a..986b2ee25 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -168,6 +168,7 @@ cBlockArea::cBlockArea(void) :
m_SizeX(0),
m_SizeY(0),
m_SizeZ(0),
+ m_Offset(0,0,0),
m_BlockTypes(NULL),
m_BlockMetas(NULL),
m_BlockLight(NULL),
@@ -254,6 +255,24 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
+void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ)
+{
+ m_Offset.Set(a_OffsetX, a_OffsetY, a_OffsetZ);
+}
+
+
+
+
+
+void cBlockArea::SetOffset(Vector3i a_Offset)
+{
+ m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z);
+}
+
+
+
+
+
void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
{
m_OriginX = a_OriginX;
diff --git a/src/BlockArea.h b/src/BlockArea.h
index 0703f195e..d89c9b372 100644
--- a/src/BlockArea.h
+++ b/src/BlockArea.h
@@ -209,6 +209,8 @@ public:
void SetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight);
void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight);
void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight);
+ void SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ);
+ void SetOffset (Vector3i a_Offset);
// Getters:
BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const;
@@ -219,6 +221,7 @@ public:
NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
+ Vector3i GetOffset (void) const {return m_Offset;}
void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
@@ -299,6 +302,8 @@ protected:
int m_SizeY;
int m_SizeZ;
+ Vector3i m_Offset;
+
BLOCKTYPE * m_BlockTypes;
NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access
NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index b021aeb0c..0aea931eb 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -177,6 +177,25 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
a_BlockArea.Clear();
a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes);
+ int TOffsetX = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetX");
+ int TOffsetY = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetY");
+ int TOffsetZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetZ");
+
+ if (
+ (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) ||
+ (a_NBT.GetType(TOffsetX) != TAG_Int) ||
+ (a_NBT.GetType(TOffsetY) != TAG_Int) ||
+ (a_NBT.GetType(TOffsetZ) != TAG_Int)
+ )
+ {
+ // Not every schematic file has an offset, so we shoudn't give a warn message.
+ a_BlockArea.SetOffset(0, 0, 0);
+ }
+ else
+ {
+ a_BlockArea.SetOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ));
+ }
+
// Copy the block types and metas:
int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
@@ -234,6 +253,10 @@ AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockA
Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
}
+ Writer.AddInt("WEOffsetX", a_BlockArea.m_Offset.x);
+ Writer.AddInt("WEOffsetY", a_BlockArea.m_Offset.y);
+ Writer.AddInt("WEOffsetZ", a_BlockArea.m_Offset.z);
+
// TODO: Save entities and block entities
Writer.BeginList("Entities", TAG_Compound);
Writer.EndList();