From fcafd5a2e0f87fcc79e0a723241604aeca50d017 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 15 Jan 2014 22:38:03 +0000 Subject: Implemented custom names and lore + Added custom names and lore + Added saving and loading + Added writing and parsing of NBT --- src/Item.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index a44515019..9170006b6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -91,28 +91,6 @@ bool cItem::DamageItem(short a_Amount) -bool cItem::IsStackableWith(const cItem & a_OtherStack) const -{ - if (a_OtherStack.m_ItemType != m_ItemType) - { - return false; - } - if (a_OtherStack.m_ItemDamage != m_ItemDamage) - { - return false; - } - if (a_OtherStack.m_Enchantments != m_Enchantments) - { - return false; - } - - return true; -} - - - - - bool cItem::IsFullStack(void) const { return (m_ItemCount >= ItemHandler(m_ItemType)->GetMaxStackSize()); @@ -153,6 +131,14 @@ void cItem::GetJson(Json::Value & a_OutValue) const { a_OutValue["ench"] = Enchantments; } + if (!IsCustomNameEmpty()) + { + a_OutValue["Name"] = m_CustomName; + } + if (!IsLoreEmpty()) + { + a_OutValue["Lore"] = m_Lore; + } } } @@ -169,6 +155,8 @@ void cItem::FromJson(const Json::Value & a_Value) m_ItemDamage = (short)a_Value.get("Health", -1 ).asInt(); m_Enchantments.Clear(); m_Enchantments.AddFromString(a_Value.get("ench", "").asString()); + m_CustomName = a_Value.get("Name", "").asString(); + m_Lore = a_Value.get("Lore", "").asString(); } } -- cgit v1.2.3 From 5d03e49c138ad45486452a5ecaebf162a4882c71 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 16 Jan 2014 18:44:11 +0000 Subject: Possibly did what xoft wanted --- src/Item.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 9170006b6..58b3d41c9 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -99,6 +99,25 @@ bool cItem::IsFullStack(void) const +void cItem::CustomCopy(cItem & a_OtherItem, bool a_CopyType, bool a_CopyCount, bool a_CopyDamage, bool a_CopyEnchantments, bool a_CopyCustomName, bool a_CopyLore) +{ + if (a_CopyType) + m_ItemType = a_OtherItem.m_ItemType; + if (a_CopyCount) + m_ItemCount = a_OtherItem.m_ItemCount; + if (a_CopyDamage) + m_ItemDamage = a_OtherItem.m_ItemDamage; + if (a_CopyEnchantments) + m_Enchantments = a_OtherItem.m_Enchantments; + if (a_CopyCustomName) + m_CustomName = a_OtherItem.m_CustomName; + if (a_CopyLore) + m_Lore = a_OtherItem.m_Lore; +} + + + + char cItem::GetMaxStackSize(void) const { -- cgit v1.2.3 From 952c53eb4eb3178f70f1910baabda877da00dfa3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 16 Jan 2014 21:41:55 +0000 Subject: Removed CustomCopy() --- src/Item.cpp | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 58b3d41c9..9170006b6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -99,25 +99,6 @@ bool cItem::IsFullStack(void) const -void cItem::CustomCopy(cItem & a_OtherItem, bool a_CopyType, bool a_CopyCount, bool a_CopyDamage, bool a_CopyEnchantments, bool a_CopyCustomName, bool a_CopyLore) -{ - if (a_CopyType) - m_ItemType = a_OtherItem.m_ItemType; - if (a_CopyCount) - m_ItemCount = a_OtherItem.m_ItemCount; - if (a_CopyDamage) - m_ItemDamage = a_OtherItem.m_ItemDamage; - if (a_CopyEnchantments) - m_Enchantments = a_OtherItem.m_Enchantments; - if (a_CopyCustomName) - m_CustomName = a_OtherItem.m_CustomName; - if (a_CopyLore) - m_Lore = a_OtherItem.m_Lore; -} - - - - char cItem::GetMaxStackSize(void) const { -- cgit v1.2.3