summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-01-19 17:52:45 +0100
committerTycho <work.tycho+git@gmail.com>2014-01-19 17:52:45 +0100
commitf13a14d2cf4a7858c22fe003acff6753d0d50ba1 (patch)
treef5be449d907c142d6560fb025db11bc6d01dc147
parentSpilt Writing of Enchantments to seperate class (diff)
downloadcuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.tar
cuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.tar.gz
cuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.tar.bz2
cuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.tar.lz
cuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.tar.xz
cuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.tar.zst
cuberite-f13a14d2cf4a7858c22fe003acff6753d0d50ba1.zip
Diffstat (limited to '')
-rw-r--r--src/Enchantments.h11
-rw-r--r--src/Protocol/Protocol132.cpp4
-rw-r--r--src/Protocol/Protocol17x.cpp4
-rw-r--r--src/WorldStorage/EnchantmentSerializer.cpp5
-rw-r--r--src/WorldStorage/EnchantmentSerializer.h12
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp2
-rw-r--r--src/WorldStorage/WSSAnvil.cpp2
7 files changed, 23 insertions, 17 deletions
diff --git a/src/Enchantments.h b/src/Enchantments.h
index 0f23f8657..e984df92e 100644
--- a/src/Enchantments.h
+++ b/src/Enchantments.h
@@ -8,6 +8,7 @@
#pragma once
+#include "WorldStorage/EnchantmentSerializer.h"
@@ -20,7 +21,6 @@ class cParsedNBT;
-// tolua_begin
/** Class that stores item enchantments or stored-enchantments
The enchantments may be serialized to a stringspec and read back from such stringspec.
@@ -29,11 +29,12 @@ mapping each enchantment's id onto its level. ID may be either a number or the e
Level value of 0 means no such enchantment, and it will not be stored in the m_Enchantments.
Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs.
*/
+// tolua_begin
class cEnchantments
{
-friend class cEnchantmentSerializer;
public:
/// Individual enchantment IDs, corresponding to their NBT IDs ( http://www.minecraftwiki.net/wiki/Data_Values#Enchantment_IDs )
+
enum
{
enchProtection = 0,
@@ -97,7 +98,11 @@ public:
/// Returns true if a_Other doesn't contain exactly the same enchantments and levels
bool operator !=(const cEnchantments & a_Other) const;
-
+ /// Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments")
+ friend void EnchantmentSerializer::WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName);
+
+ /// Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments)
+ friend void EnchantmentSerializer::ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx);
protected:
/// Maps enchantment ID -> enchantment level
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index 501a8474e..b4ca37d37 100644
--- a/src/Protocol/Protocol132.cpp
+++ b/src/Protocol/Protocol132.cpp
@@ -764,7 +764,7 @@ void cProtocol132::WriteItem(const cItem & a_Item)
// Send the enchantments:
cFastNBTWriter Writer;
const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
- cEnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, Writer, TagName);
+ EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, Writer, TagName);
Writer.Finish();
AString Compressed;
CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
@@ -850,7 +850,7 @@ int cProtocol132::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
)
)
{
- cEnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
+ EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
}
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 44db659a5..c64441a1e 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1697,7 +1697,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
)
)
{
- cEnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
+ EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
}
else if ((NBT.GetType(tag) == TAG_Compound) && (NBT.GetName(tag) == "display")) // Custom name and lore tag
{
@@ -1782,7 +1782,7 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
if (!a_Item.m_Enchantments.IsEmpty())
{
const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
- cEnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments,Writer, TagName);
+ EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments,Writer, TagName);
}
if (!a_Item.IsBothNameAndLoreEmpty())
{
diff --git a/src/WorldStorage/EnchantmentSerializer.cpp b/src/WorldStorage/EnchantmentSerializer.cpp
index a481f1682..56072207f 100644
--- a/src/WorldStorage/EnchantmentSerializer.cpp
+++ b/src/WorldStorage/EnchantmentSerializer.cpp
@@ -2,9 +2,10 @@
#include "Globals.h"
#include "EnchantmentSerializer.h"
+#include "Enchantments.h"
#include "FastNBT.h"
-void cEnchantmentSerializer::WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName)
+void EnchantmentSerializer::WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName)
{
// Write the enchantments into the specified NBT writer
// begin with the LIST tag of the specified name ("ench" or "StoredEnchantments")
@@ -24,7 +25,7 @@ void cEnchantmentSerializer::WriteToNBTCompound(cEnchantments const& a_Enchantme
-void cEnchantmentSerializer::ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx)
+void EnchantmentSerializer::ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx)
{
// Read the enchantments from the specified NBT list tag (ench or StoredEnchantments)
diff --git a/src/WorldStorage/EnchantmentSerializer.h b/src/WorldStorage/EnchantmentSerializer.h
index d616b0f62..9ed362900 100644
--- a/src/WorldStorage/EnchantmentSerializer.h
+++ b/src/WorldStorage/EnchantmentSerializer.h
@@ -1,17 +1,17 @@
#pragma once
-#include "Enchantments.h"
+class cEnchantments;
+class cFastNBTWriter;
+class cParsedNBT;
-class cEnchantmentSerializer
+namespace EnchantmentSerializer
{
-public:
-
/// Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments")
- static void WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName);
+ void WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName);
/// Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments)
- static void ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx);
+ void ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx);
};
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 51e1a8d1b..91cc6b06d 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -92,7 +92,7 @@ void cNBTChunkSerializer::AddItem(const cItem & a_Item, int a_Slot, const AStrin
{
const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
m_Writer.BeginCompound("tag");
- cEnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, m_Writer, TagName);
+ EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, m_Writer, TagName);
m_Writer.EndCompound();
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 702b809fb..25661de76 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -640,7 +640,7 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_
int EnchTag = a_NBT.FindChildByName(TagTag, EnchName);
if (EnchTag > 0)
{
- cEnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, a_NBT, EnchTag);
+ EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, a_NBT, EnchTag);
}
return true;