summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp37
-rw-r--r--src/WorldStorage/WSSAnvil.cpp34
2 files changed, 59 insertions, 12 deletions
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index fd356c7de..b696a8f69 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -88,23 +88,48 @@ void cNBTChunkSerializer::Finish(void)
void cNBTChunkSerializer::AddItem(const cItem & a_Item, int a_Slot, const AString & a_CompoundName)
{
m_Writer.BeginCompound(a_CompoundName);
- m_Writer.AddShort("id", (short)(a_Item.m_ItemType));
- m_Writer.AddShort("Damage", a_Item.m_ItemDamage);
- m_Writer.AddByte ("Count", a_Item.m_ItemCount);
+ m_Writer.AddShort("id", (short)(a_Item.m_ItemType));
+ m_Writer.AddShort("Damage", a_Item.m_ItemDamage);
+ m_Writer.AddByte ("Count", a_Item.m_ItemCount);
if (a_Slot >= 0)
{
m_Writer.AddByte ("Slot", (unsigned char)a_Slot);
}
- // Write the enchantments:
- if (!a_Item.m_Enchantments.IsEmpty() || ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)))
+ // Write the tag compound (for enchantment, firework, custom name and repair cost):
+ if (
+ (!a_Item.m_Enchantments.IsEmpty()) ||
+ ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)) ||
+ (a_Item.m_RepairCost > 0) ||
+ (a_Item.m_CustomName != "") ||
+ (a_Item.m_Lore != "")
+ )
{
m_Writer.BeginCompound("tag");
+ if (a_Item.m_RepairCost > 0)
+ {
+ m_Writer.AddInt("RepairCost", (Int32)a_Item.m_RepairCost);
+ }
+
+ if ((a_Item.m_CustomName != "") || (a_Item.m_Lore != ""))
+ {
+ m_Writer.BeginCompound("display");
+ if (a_Item.m_CustomName != "")
+ {
+ m_Writer.AddString("Name", a_Item.m_CustomName);
+ }
+ if (a_Item.m_Lore != "")
+ {
+ m_Writer.AddString("Lore", a_Item.m_Lore);
+ }
+ m_Writer.EndCompound();
+ }
+
if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR))
{
cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, m_Writer, (ENUM_ITEM_ID)a_Item.m_ItemType);
}
-
+
if (!a_Item.m_Enchantments.IsEmpty())
{
const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index f33178173..b1c6238ab 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -645,18 +645,16 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_
}
int Damage = a_NBT.FindChildByName(a_TagIdx, "Damage");
- if ((Damage < 0) || (a_NBT.GetType(Damage) != TAG_Short))
+ if ((Damage > 0) && (a_NBT.GetType(Damage) == TAG_Short))
{
- return false;
+ a_Item.m_ItemDamage = a_NBT.GetShort(Damage);
}
- a_Item.m_ItemDamage = a_NBT.GetShort(Damage);
int Count = a_NBT.FindChildByName(a_TagIdx, "Count");
- if ((Count < 0) || (a_NBT.GetType(Count) != TAG_Byte))
+ if ((Count > 0) && (a_NBT.GetType(Count) == TAG_Byte))
{
- return false;
+ a_Item.m_ItemCount = a_NBT.GetByte(Count);
}
- a_Item.m_ItemCount = a_NBT.GetByte(Count);
// Find the "tag" tag, used for enchantments and other extra data
int TagTag = a_NBT.FindChildByName(a_TagIdx, "tag");
@@ -666,6 +664,29 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_
return true;
}
+ // Load repair cost:
+ int RepairCost = a_NBT.FindChildByName(TagTag, "RepairCost");
+ if ((RepairCost > 0) && (a_NBT.GetType(RepairCost) == TAG_Int))
+ {
+ a_Item.m_RepairCost = (UInt16)a_NBT.GetInt(RepairCost);
+ }
+
+ // Load display name:
+ int DisplayTag = a_NBT.FindChildByName(TagTag, "display");
+ if (DisplayTag > 0)
+ {
+ int DisplayName = a_NBT.FindChildByName(DisplayTag, "Name");
+ if ((DisplayName > 0) && (a_NBT.GetType(DisplayName) == TAG_String))
+ {
+ a_Item.m_CustomName = a_NBT.GetString(DisplayName);
+ }
+ int Lore = a_NBT.FindChildByName(DisplayTag, "Lore");
+ if ((Lore > 0) && (a_NBT.GetType(Lore) == TAG_String))
+ {
+ a_Item.m_Lore = a_NBT.GetString(Lore);
+ }
+ }
+
// Load enchantments:
const char * EnchName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
int EnchTag = a_NBT.FindChildByName(TagTag, EnchName);
@@ -674,6 +695,7 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_
EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, a_NBT, EnchTag);
}
+ // Load firework data:
int FireworksTag = a_NBT.FindChildByName(TagTag, ((a_Item.m_ItemType == E_ITEM_FIREWORK_STAR) ? "Fireworks" : "Explosion"));
if (EnchTag > 0)
{