summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-03-09 13:53:50 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-03-09 13:53:50 +0100
commitc2978a34576192d79c1fdc4664eafe316be49e51 (patch)
tree48db5c74ed757bfdf178a70e77eddff693c76a35 /src/WorldStorage
parentHexified colours (diff)
parentUpdated Core (diff)
downloadcuberite-c2978a34576192d79c1fdc4664eafe316be49e51.tar
cuberite-c2978a34576192d79c1fdc4664eafe316be49e51.tar.gz
cuberite-c2978a34576192d79c1fdc4664eafe316be49e51.tar.bz2
cuberite-c2978a34576192d79c1fdc4664eafe316be49e51.tar.lz
cuberite-c2978a34576192d79c1fdc4664eafe316be49e51.tar.xz
cuberite-c2978a34576192d79c1fdc4664eafe316be49e51.tar.zst
cuberite-c2978a34576192d79c1fdc4664eafe316be49e51.zip
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/FastNBT.h57
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp15
-rw-r--r--src/WorldStorage/NBTChunkSerializer.h2
-rw-r--r--src/WorldStorage/SchematicFileSerializer.cpp133
-rw-r--r--src/WorldStorage/SchematicFileSerializer.h33
-rw-r--r--src/WorldStorage/ScoreboardSerializer.cpp14
-rw-r--r--src/WorldStorage/WSSAnvil.cpp36
-rw-r--r--src/WorldStorage/WSSAnvil.h1
-rw-r--r--src/WorldStorage/WSSCompact.cpp40
9 files changed, 282 insertions, 49 deletions
diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h
index e7e56282f..1b8b09c21 100644
--- a/src/WorldStorage/FastNBT.h
+++ b/src/WorldStorage/FastNBT.h
@@ -106,6 +106,10 @@ public:
/** Parses and contains the parsed data
Also implements data accessor functions for tree traversal and value getters
The data pointer passed in the constructor is assumed to be valid throughout the object's life. Care must be taken not to initialize from a temporary.
+The parser decomposes the input data into a tree of tags that is stored as an array of cFastNBTTag items,
+and accessing the tree is done by using the array indices for tags. Each tag stores the indices for its parent,
+first child, last child, prev sibling and next sibling, a value of -1 indicates that the indice is not valid.
+Each primitive tag also stores the length of the contained data, in bytes.
*/
class cParsedNBT
{
@@ -114,13 +118,32 @@ public:
bool IsValid(void) const {return m_IsValid; }
+ /** Returns the root tag of the hierarchy. */
int GetRoot(void) const {return 0; }
+
+ /** Returns the first child of the specified tag, or -1 if none / not applicable. */
int GetFirstChild (int a_Tag) const { return m_Tags[a_Tag].m_FirstChild; }
+
+ /** Returns the last child of the specified tag, or -1 if none / not applicable. */
int GetLastChild (int a_Tag) const { return m_Tags[a_Tag].m_LastChild; }
+
+ /** Returns the next sibling of the specified tag, or -1 if none. */
int GetNextSibling(int a_Tag) const { return m_Tags[a_Tag].m_NextSibling; }
+
+ /** Returns the previous sibling of the specified tag, or -1 if none. */
int GetPrevSibling(int a_Tag) const { return m_Tags[a_Tag].m_PrevSibling; }
- int GetDataLength (int a_Tag) const { return m_Tags[a_Tag].m_DataLength; }
+
+ /** Returns the length of the tag's data, in bytes.
+ Not valid for Compound or List tags! */
+ int GetDataLength (int a_Tag) const
+ {
+ ASSERT(m_Tags[a_Tag].m_Type != TAG_List);
+ ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound);
+ return m_Tags[a_Tag].m_DataLength;
+ }
+ /** Returns the data stored in this tag.
+ Not valid for Compound or List tags! */
const char * GetData(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type != TAG_List);
@@ -128,69 +151,88 @@ public:
return m_Data + m_Tags[a_Tag].m_DataStart;
}
+ /** Returns the direct child tag of the specified name, or -1 if no such tag. */
int FindChildByName(int a_Tag, const AString & a_Name) const
{
return FindChildByName(a_Tag, a_Name.c_str(), a_Name.length());
}
+ /** Returns the direct child tag of the specified name, or -1 if no such tag. */
int FindChildByName(int a_Tag, const char * a_Name, size_t a_NameLength = 0) const;
- int FindTagByPath (int a_Tag, const AString & a_Path) const;
+
+ /** Returns the child tag of the specified path (Name1\Name2\Name3...), or -1 if no such tag. */
+ int FindTagByPath(int a_Tag, const AString & a_Path) const;
eTagType GetType(int a_Tag) const { return m_Tags[a_Tag].m_Type; }
- /// Returns the children type for a list tag; undefined on other tags. If list empty, returns TAG_End
+ /** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */
eTagType GetChildrenType(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_List);
return (m_Tags[a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[m_Tags[a_Tag].m_FirstChild].m_Type;
}
+ /** Returns the value stored in a Byte tag. Not valid for any other tag type. */
inline unsigned char GetByte(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Byte);
return (unsigned char)(m_Data[m_Tags[a_Tag].m_DataStart]);
}
+ /** Returns the value stored in a Short tag. Not valid for any other tag type. */
inline Int16 GetShort(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Short);
return GetBEShort(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in an Int tag. Not valid for any other tag type. */
inline Int32 GetInt(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Int);
return GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in a Long tag. Not valid for any other tag type. */
inline Int64 GetLong(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Long);
return NetworkToHostLong8(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in a Float tag. Not valid for any other tag type. */
inline float GetFloat(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Float);
- // Cause a compile-time error if sizeof(int) != sizeof(float)
- char Check1[sizeof(int) - sizeof(float) + 1]; // sizeof(int) >= sizeof(float)
- char Check2[sizeof(float) - sizeof(int) + 1]; // sizeof(float) >= sizeof(int)
+ // Cause a compile-time error if sizeof(float) != 4
+ // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats
+ char Check1[5 - sizeof(float)]; // Fails if sizeof(float) > 4
+ char Check2[sizeof(float) - 3]; // Fails if sizeof(float) < 4
UNUSED(Check1);
UNUSED(Check2);
- int i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart);
+ Int32 i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart);
float f;
memcpy(&f, &i, sizeof(f));
return f;
}
+ /** Returns the value stored in a Double tag. Not valid for any other tag type. */
inline double GetDouble(int a_Tag) const
{
+ // Cause a compile-time error if sizeof(double) != 8
+ // If your platform produces a compiler error here, you'll need to add code that manually decodes 64-bit doubles
+ char Check1[9 - sizeof(double)]; // Fails if sizeof(double) > 8
+ char Check2[sizeof(double) - 7]; // Fails if sizeof(double) < 8
+ UNUSED(Check1);
+ UNUSED(Check2);
+
ASSERT(m_Tags[a_Tag].m_Type == TAG_Double);
return NetworkToHostDouble8(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in a String tag. Not valid for any other tag type. */
inline AString GetString(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_String);
@@ -199,6 +241,7 @@ public:
return res;
}
+ /** Returns the tag's name. For tags that are not named, returns an empty string. */
inline AString GetName(int a_Tag) const
{
AString res;
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 6d82cba86..e9fa11fe6 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -20,6 +20,7 @@
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../Entities/Entity.h"
#include "../Entities/FallingBlock.h"
@@ -283,6 +284,19 @@ void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead)
+void cNBTChunkSerializer::AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot)
+{
+ m_Writer.BeginCompound("");
+ AddBasicTileEntity(a_FlowerPot, "FlowerPot");
+ m_Writer.AddInt ("Item", (Int32) a_FlowerPot->GetItem().m_ItemType);
+ m_Writer.AddInt ("Data", (Int32) a_FlowerPot->GetItem().m_ItemDamage);
+ m_Writer.EndCompound();
+}
+
+
+
+
+
void cNBTChunkSerializer::AddBasicEntity(cEntity * a_Entity, const AString & a_ClassName)
{
m_Writer.AddString("id", a_ClassName);
@@ -695,6 +709,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity)
case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break;
case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break;
case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break;
+ case E_BLOCK_FLOWER_POT: AddFlowerPotEntity ((cFlowerPotEntity *) a_Entity); break;
case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break;
case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break;
case E_BLOCK_SIGN_POST:
diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h
index 5f9e16ed1..8a9e18413 100644
--- a/src/WorldStorage/NBTChunkSerializer.h
+++ b/src/WorldStorage/NBTChunkSerializer.h
@@ -30,6 +30,7 @@ class cJukeboxEntity;
class cNoteEntity;
class cSignEntity;
class cMobHeadEntity;
+class cFlowerPotEntity;
class cFallingBlock;
class cMinecart;
class cMinecartWithChest;
@@ -96,6 +97,7 @@ protected:
void AddSignEntity (cSignEntity * a_Sign);
void AddMobHeadEntity (cMobHeadEntity * a_MobHead);
void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock);
+ void AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot);
// Entities:
void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName);
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index 45fd967bd..b021aeb0c 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -1,10 +1,18 @@
+// SchematicFileSerializer.cpp
+
+// Implements the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file
+
#include "Globals.h"
#include "OSSupport/GZipFile.h"
#include "FastNBT.h"
-
#include "SchematicFileSerializer.h"
+#include "../StringCompression.h"
+
+
+
+
bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName)
{
@@ -40,48 +48,51 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, c
-bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName)
+bool cSchematicFileSerializer::LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData)
{
- cFastNBTWriter Writer("Schematic");
- Writer.AddShort("Width", a_BlockArea.m_SizeX);
- Writer.AddShort("Height", a_BlockArea.m_SizeY);
- Writer.AddShort("Length", a_BlockArea.m_SizeZ);
- Writer.AddString("Materials", "Alpha");
- if (a_BlockArea.HasBlockTypes())
+ // Uncompress the data:
+ AString UngzippedData;
+ if (UncompressStringGZIP(a_SchematicData.data(), a_SchematicData.size(), UngzippedData) != Z_OK)
{
- Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount());
- }
- else
- {
- AString Dummy(a_BlockArea.GetBlockCount(), 0);
- Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
+ LOG("%s: Cannot unGZip the schematic data.", __FUNCTION__);
+ return false;
}
- if (a_BlockArea.HasBlockMetas())
+
+ // Parse the NBT:
+ cParsedNBT NBT(UngzippedData.data(), UngzippedData.size());
+ if (!NBT.IsValid())
{
- Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount());
+ LOG("%s: Cannot parse the NBT in the schematic data.", __FUNCTION__);
+ return false;
}
- else
+
+ return LoadFromSchematicNBT(a_BlockArea, NBT);
+}
+
+
+
+
+
+bool cSchematicFileSerializer::SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName)
+{
+ // Serialize into NBT data:
+ AString NBT = SaveToSchematicNBT(a_BlockArea);
+ if (NBT.empty())
{
- AString Dummy(a_BlockArea.GetBlockCount(), 0);
- Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
+ LOG("%s: Cannot serialize the area into an NBT representation for file \"%s\".", __FUNCTION__, a_FileName.c_str());
+ return false;
}
- // TODO: Save entities and block entities
- Writer.BeginList("Entities", TAG_Compound);
- Writer.EndList();
- Writer.BeginList("TileEntities", TAG_Compound);
- Writer.EndList();
- Writer.Finish();
// Save to file
cGZipFile File;
if (!File.Open(a_FileName, cGZipFile::fmWrite))
{
- LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str());
+ LOG("%s: Cannot open file \"%s\" for writing.", __FUNCTION__, a_FileName.c_str());
return false;
}
- if (!File.Write(Writer.GetResult()))
+ if (!File.Write(NBT))
{
- LOG("Cannot write data to file \"%s\".", a_FileName.c_str());
+ LOG("%s: Cannot write data to file \"%s\".", __FUNCTION__, a_FileName.c_str());
return false;
}
return true;
@@ -92,6 +103,30 @@ bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, con
+bool cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea, AString & a_Out)
+{
+ // Serialize into NBT data:
+ AString NBT = SaveToSchematicNBT(a_BlockArea);
+ if (NBT.empty())
+ {
+ LOG("%s: Cannot serialize the area into an NBT representation.", __FUNCTION__);
+ return false;
+ }
+
+ // Gzip the data:
+ int res = CompressStringGZIP(NBT.data(), NBT.size(), a_Out);
+ if (res != Z_OK)
+ {
+ LOG("%s: Cannot Gzip the area data NBT representation: %d", __FUNCTION__, res);
+ return false;
+ }
+ return true;
+}
+
+
+
+
+
bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT)
{
int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");
@@ -170,3 +205,45 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
}
+
+
+
+AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea)
+{
+ cFastNBTWriter Writer("Schematic");
+ Writer.AddShort("Width", a_BlockArea.m_SizeX);
+ Writer.AddShort("Height", a_BlockArea.m_SizeY);
+ Writer.AddShort("Length", a_BlockArea.m_SizeZ);
+ Writer.AddString("Materials", "Alpha");
+ if (a_BlockArea.HasBlockTypes())
+ {
+ Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount());
+ }
+ else
+ {
+ AString Dummy(a_BlockArea.GetBlockCount(), 0);
+ Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
+ }
+ if (a_BlockArea.HasBlockMetas())
+ {
+ Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount());
+ }
+ else
+ {
+ AString Dummy(a_BlockArea.GetBlockCount(), 0);
+ Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
+ }
+
+ // TODO: Save entities and block entities
+ Writer.BeginList("Entities", TAG_Compound);
+ Writer.EndList();
+ Writer.BeginList("TileEntities", TAG_Compound);
+ Writer.EndList();
+ Writer.Finish();
+
+ return Writer.GetResult();
+}
+
+
+
+
diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h
index 9be2e5b57..05b6c74f4 100644
--- a/src/WorldStorage/SchematicFileSerializer.h
+++ b/src/WorldStorage/SchematicFileSerializer.h
@@ -1,4 +1,12 @@
+// SchematicFileSerializer.h
+
+// Declares the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file
+
+
+
+
+
#pragma once
#include "../BlockArea.h"
@@ -13,17 +21,34 @@ class cParsedNBT;
+
class cSchematicFileSerializer
{
public:
- /// Loads an area from a .schematic file. Returns true if successful
+ /** Loads an area from a .schematic file. Returns true if successful. */
static bool LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName);
- /// Saves the area into a .schematic file. Returns true if successful
- static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName);
+ /** Loads an area from a string containing the .schematic file data. Returns true if successful. */
+ static bool LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData);
+
+ /** Saves the area into a .schematic file. Returns true if successful. */
+ static bool SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName);
+
+ /** Saves the area into a string containing the .schematic file data.
+ Returns true if successful, false on failure. The data is stored into a_Out. */
+ static bool SaveToSchematicString(const cBlockArea & a_BlockArea, AString & a_Out);
private:
- /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful.
+ /** Loads the area from a schematic file uncompressed and parsed into a NBT tree.
+ Returns true if successful. */
static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT);
+
+ /** Saves the area into a NBT representation and returns the NBT data as a string.
+ Returns an empty string if failed. */
+ static AString SaveToSchematicNBT(const cBlockArea & a_BlockArea);
};
+
+
+
+
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index 9b8b661c4..6c885bb45 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -173,13 +173,13 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
a_Writer.BeginCompound("DisplaySlots");
- cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_LIST);
+ cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsList);
a_Writer.AddString("slot_0", (Objective == NULL) ? "" : Objective->GetName());
- Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_SIDEBAR);
+ Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsSidebar);
a_Writer.AddString("slot_1", (Objective == NULL) ? "" : Objective->GetName());
- Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME);
+ Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsName);
a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName());
a_Writer.EndCompound(); // DisplaySlots
@@ -280,7 +280,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name, DisplayName, Prefix, Suffix;
- bool AllowsFriendlyFire = false, CanSeeFriendlyInvisible = false;
+ bool AllowsFriendlyFire = true, CanSeeFriendlyInvisible = false;
int CurrLine = a_NBT.FindChildByName(Child, "Name");
if (CurrLine >= 0)
@@ -346,7 +346,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name = a_NBT.GetString(CurrLine);
- m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_LIST);
+ m_ScoreBoard->SetDisplay(Name, cScoreboard::dsList);
}
CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_1");
@@ -354,7 +354,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name = a_NBT.GetString(CurrLine);
- m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_SIDEBAR);
+ m_ScoreBoard->SetDisplay(Name, cScoreboard::dsSidebar);
}
CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_2");
@@ -362,7 +362,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name = a_NBT.GetString(CurrLine);
- m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_NAME);
+ m_ScoreBoard->SetDisplay(Name, cScoreboard::dsName);
}
return true;
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 0658d5029..07cf87ab3 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -25,6 +25,7 @@
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../Mobs/Monster.h"
@@ -578,6 +579,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
{
LoadDropperFromNBT(a_BlockEntities, a_NBT, Child);
}
+ else if (strncmp(a_NBT.GetData(sID), "FlowerPot", a_NBT.GetDataLength(sID)) == 0)
+ {
+ LoadFlowerPotFromNBT(a_BlockEntities, a_NBT, Child);
+ }
else if (strncmp(a_NBT.GetData(sID), "Furnace", a_NBT.GetDataLength(sID)) == 0)
{
LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child, a_BlockTypes, a_BlockMetas);
@@ -766,6 +771,37 @@ void cWSSAnvil::LoadDropperFromNBT(cBlockEntityList & a_BlockEntities, const cPa
+void cWSSAnvil::LoadFlowerPotFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
+ int x, y, z;
+ if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z))
+ {
+ return;
+ }
+ std::auto_ptr<cFlowerPotEntity> FlowerPot(new cFlowerPotEntity(x, y, z, m_World));
+ short ItemType = 0, ItemData = 0;
+
+ int currentLine = a_NBT.FindChildByName(a_TagIdx, "Item");
+ if (currentLine >= 0)
+ {
+ ItemType = (short) a_NBT.GetInt(currentLine);
+ }
+
+ currentLine = a_NBT.FindChildByName(a_TagIdx, "Data");
+ if (currentLine >= 0)
+ {
+ ItemData = (short) a_NBT.GetInt(currentLine);
+ }
+
+ FlowerPot->SetItem(cItem(ItemType, 1, ItemData));
+ a_BlockEntities.push_back(FlowerPot.release());
+}
+
+
+
+
+
void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas)
{
ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index 4acf3f2a1..b26345b13 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -135,6 +135,7 @@ protected:
void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadFlowerPotFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadFurnaceFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas);
void LoadHopperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 4c0684dd8..5e49e4909 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -12,8 +12,10 @@
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../BlockEntities/FurnaceEntity.h"
#include "../BlockEntities/JukeboxEntity.h"
+#include "../BlockEntities/MobHeadEntity.h"
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
@@ -75,12 +77,14 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity)
case E_BLOCK_CHEST: SaveInto = "Chests"; break;
case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break;
case E_BLOCK_DROPPER: SaveInto = "Droppers"; break;
+ case E_BLOCK_FLOWER_POT: SaveInto = "FlowerPots"; break;
case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break;
case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break;
case E_BLOCK_WALLSIGN: SaveInto = "Signs"; break;
case E_BLOCK_NOTE_BLOCK: SaveInto = "Notes"; break;
case E_BLOCK_JUKEBOX: SaveInto = "Jukeboxes"; break;
case E_BLOCK_COMMAND_BLOCK: SaveInto = "CommandBlocks"; break;
+ case E_BLOCK_HEAD: SaveInto = "MobHeads"; break;
default:
{
@@ -298,6 +302,21 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
}
} // for itr - AllDispensers[]
+ // Load Flowerpots:
+ Json::Value AllFlowerPots = a_Value.get("FlowerPots", Json::nullValue);
+ for (Json::Value::iterator itr = AllFlowerPots.begin(); itr != AllFlowerPots.end(); ++itr)
+ {
+ std::auto_ptr<cFlowerPotEntity> FlowerPotEntity(new cFlowerPotEntity(0, 0, 0, a_World));
+ if (!FlowerPotEntity->LoadFromJson(*itr))
+ {
+ LOGWARNING("ERROR READING FLOWERPOT FROM JSON!" );
+ }
+ else
+ {
+ a_BlockEntities.push_back(FlowerPotEntity.release());
+ }
+ } // for itr - AllFlowerPots[]
+
// Load furnaces:
Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue);
for (Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr)
@@ -331,7 +350,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
// Load note blocks:
Json::Value AllNotes = a_Value.get("Notes", Json::nullValue);
- for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr )
+ for (Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr)
{
std::auto_ptr<cNoteEntity> NoteEntity(new cNoteEntity(0, 0, 0, a_World));
if (!NoteEntity->LoadFromJson(*itr))
@@ -346,7 +365,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
// Load jukeboxes:
Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue);
- for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr )
+ for (Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr)
{
std::auto_ptr<cJukeboxEntity> JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World));
if (!JukeboxEntity->LoadFromJson(*itr))
@@ -361,7 +380,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
// Load command blocks:
Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue);
- for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr )
+ for (Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr)
{
std::auto_ptr<cCommandBlockEntity> CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World));
if (!CommandBlockEntity->LoadFromJson(*itr))
@@ -373,6 +392,21 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
a_BlockEntities.push_back(CommandBlockEntity.release());
}
} // for itr - AllCommandBlocks[]
+
+ // Load mob heads:
+ Json::Value AllMobHeads = a_Value.get("MobHeads", Json::nullValue);
+ for (Json::Value::iterator itr = AllMobHeads.begin(); itr != AllMobHeads.end(); ++itr)
+ {
+ std::auto_ptr<cMobHeadEntity> MobHeadEntity(new cMobHeadEntity(0, 0, 0, a_World));
+ if (!MobHeadEntity->LoadFromJson(*itr))
+ {
+ LOGWARNING("ERROR READING MOB HEAD FROM JSON!" );
+ }
+ else
+ {
+ a_BlockEntities.push_back(MobHeadEntity.release());
+ }
+ } // for itr - AllMobHeads[]
}