Enchantments are now stored in Anvil world and in player inventory
git-svn-id: http://mc-server.googlecode.com/svn/trunk@1541 0a769ca7-a7f5-676a-18bf-c427514a06d6master
parent
098c237a39
commit
73f787feb3
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -97,8 +97,17 @@ void cItem::GetJson( Json::Value & a_OutValue ) const
|
|||
{
|
||||
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)
|
||||
{
|
||||
|
@ -107,6 +116,8 @@ void cItem::FromJson( const Json::Value & a_Value )
|
|||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue