summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-02 23:21:32 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-02 23:21:32 +0200
commit73f787feb328ffe349d803ca01363ba57178760b (patch)
treef3be3b285756e5d56aa602924dd4eee0db14735d
parentShift + click doesn't "destroy" item enchantment (diff)
downloadcuberite-73f787feb328ffe349d803ca01363ba57178760b.tar
cuberite-73f787feb328ffe349d803ca01363ba57178760b.tar.gz
cuberite-73f787feb328ffe349d803ca01363ba57178760b.tar.bz2
cuberite-73f787feb328ffe349d803ca01363ba57178760b.tar.lz
cuberite-73f787feb328ffe349d803ca01363ba57178760b.tar.xz
cuberite-73f787feb328ffe349d803ca01363ba57178760b.tar.zst
cuberite-73f787feb328ffe349d803ca01363ba57178760b.zip
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua10
-rw-r--r--source/Enchantments.cpp2
-rw-r--r--source/Enchantments.h2
-rw-r--r--source/Item.cpp19
-rw-r--r--source/WorldStorage/WSSAnvil.cpp17
5 files changed, 42 insertions, 8 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index fb2601470..7c20e90e6 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -594,8 +594,16 @@ function HandleTestWndCmd(a_Split, a_Player)
end
local Window = cLuaWindow(WindowType, WindowSizeX, WindowSizeY, "TestWnd");
+ local Item2 = cItem(E_ITEM_DIAMOND_SWORD, 1, 0, "1=1");
+ local Item3 = cItem(E_ITEM_DIAMOND_SHOVEL);
+ Item3.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 4);
+ local Item4 = cItem(E_ITEM_DIAMOND_PICKAXE);
+ Item4.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 5);
+ Item4.m_Enchantments:SetLevel(cEnchantments.enchEfficiency, 3);
Window:SetSlot(a_Player, 0, cItem(E_ITEM_DIAMOND, 64));
- Window:SetSlot(a_Player, 1, cItem(E_ITEM_DIAMOND_SWORD, 1, 0, "1=1"));
+ Window:SetSlot(a_Player, 1, Item2);
+ Window:SetSlot(a_Player, 2, Item3);
+ Window:SetSlot(a_Player, 3, Item4);
Window:SetOnClosing(OnClosing);
Window:SetOnSlotChanged(OnSlotChanged);
diff --git a/source/Enchantments.cpp b/source/Enchantments.cpp
index 69bf8f7eb..d0bf8c731 100644
--- a/source/Enchantments.cpp
+++ b/source/Enchantments.cpp
@@ -165,7 +165,7 @@ void cEnchantments::WriteToNBTCompound(cFastNBTWriter & a_Writer, const AString
-void cEnchantments::ParseFromNBT(cParsedNBT & a_NBT, int a_EnchListTagIdx)
+void cEnchantments::ParseFromNBT(const cParsedNBT & a_NBT, int a_EnchListTagIdx)
{
// Read the enchantments from the specified NBT list tag (ench or StoredEnchantments)
diff --git a/source/Enchantments.h b/source/Enchantments.h
index 6b3b4679b..96ebc1880 100644
--- a/source/Enchantments.h
+++ b/source/Enchantments.h
@@ -90,7 +90,7 @@ public:
void WriteToNBTCompound(cFastNBTWriter & a_Writer, const AString & a_ListTagName) const;
/// Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments)
- void ParseFromNBT(cParsedNBT & a_NBT, int a_EnchListTagIdx);
+ void ParseFromNBT(const cParsedNBT & a_NBT, int a_EnchListTagIdx);
protected:
/// Maps enchantment ID -> enchantment level
diff --git a/source/Item.cpp b/source/Item.cpp
index e2cacdac1..569d04980 100644
--- a/source/Item.cpp
+++ b/source/Item.cpp
@@ -90,23 +90,34 @@ bool cItem::IsStackableWith(const cItem & a_OtherStack) const
-void cItem::GetJson( Json::Value & a_OutValue ) const
+void cItem::GetJson(Json::Value & a_OutValue) const
{
a_OutValue["ID"] = m_ItemType;
- if( m_ItemType > 0 )
+ if (m_ItemType > 0)
{
a_OutValue["Count"] = m_ItemCount;
a_OutValue["Health"] = m_ItemDamage;
+ AString Enchantments(m_Enchantments.ToString());
+ if (!Enchantments.empty())
+ {
+ a_OutValue["ench"] = Enchantments;
+ }
}
}
-void cItem::FromJson( const Json::Value & a_Value )
+
+
+
+
+void cItem::FromJson(const Json::Value & a_Value)
{
m_ItemType = (ENUM_ITEM_ID)a_Value.get("ID", -1 ).asInt();
- if( m_ItemType > 0 )
+ if (m_ItemType > 0)
{
m_ItemCount = (char)a_Value.get("Count", -1 ).asInt();
m_ItemDamage = (short)a_Value.get("Health", -1 ).asInt();
+ m_Enchantments.Clear();
+ m_Enchantments.AddFromString(a_Value.get("ench", "").asString());
}
}
diff --git a/source/WorldStorage/WSSAnvil.cpp b/source/WorldStorage/WSSAnvil.cpp
index 14b87670d..1b70083c2 100644
--- a/source/WorldStorage/WSSAnvil.cpp
+++ b/source/WorldStorage/WSSAnvil.cpp
@@ -615,7 +615,22 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_
}
a_Item.m_ItemCount = a_NBT.GetByte(Count);
- // TODO: enchantments and other item properties
+ // Find the "tag" tag, used for enchantments and other extra data
+ int TagTag = a_NBT.FindChildByName(a_TagIdx, "tag");
+ if (TagTag <= 0)
+ {
+ // No extra data
+ return true;
+ }
+
+ // Load enchantments:
+ const char * EnchName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
+ int EnchTag = a_NBT.FindChildByName(TagTag, EnchName);
+ if (EnchTag > 0)
+ {
+ a_Item.m_Enchantments.ParseFromNBT(a_NBT, EnchTag);
+ }
+
return true;
}