diff options
author | madmaxoft <github@xoft.cz> | 2013-10-18 18:13:20 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-18 18:13:20 +0200 |
commit | 24aad485b922a5c6367f709821511892867df17f (patch) | |
tree | 804c1b082bac04d18350ce4044e21da8716069ad /source | |
parent | Fixed item-breaking. (diff) | |
download | cuberite-24aad485b922a5c6367f709821511892867df17f.tar cuberite-24aad485b922a5c6367f709821511892867df17f.tar.gz cuberite-24aad485b922a5c6367f709821511892867df17f.tar.bz2 cuberite-24aad485b922a5c6367f709821511892867df17f.tar.lz cuberite-24aad485b922a5c6367f709821511892867df17f.tar.xz cuberite-24aad485b922a5c6367f709821511892867df17f.tar.zst cuberite-24aad485b922a5c6367f709821511892867df17f.zip |
Diffstat (limited to 'source')
-rw-r--r-- | source/BlockID.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/source/BlockID.cpp b/source/BlockID.cpp index 2fe495c6f..95e1a63bf 100644 --- a/source/BlockID.cpp +++ b/source/BlockID.cpp @@ -79,40 +79,43 @@ public: bool ResolveItem(const AString & a_ItemName, cItem & a_Item) { - ItemMap::iterator itr = m_Map.find(a_ItemName); + // Split into parts divided by either ':' or '^' + AStringVector Split = StringSplitAndTrim(a_ItemName, ":^"); + if (Split.empty()) + { + return false; + } + + ItemMap::iterator itr = m_Map.find(Split[0]); if (itr != m_Map.end()) { + // Resolved as a string, assign the type and the default damage / count a_Item.m_ItemType = itr->second.first; a_Item.m_ItemDamage = itr->second.second; if (a_Item.m_ItemDamage == -1) { a_Item.m_ItemDamage = 0; } - a_Item.m_ItemCount = 1; - return true; - } - - // Not a resolvable string, try pure numbers: "45:6", "45^6" etc. - AStringVector Split = StringSplit(a_ItemName, ":"); - if (Split.size() == 1) - { - Split = StringSplit(a_ItemName, "^"); } - if (Split.empty()) - { - return false; - } - a_Item.m_ItemType = (short)atoi(Split[0].c_str()); - if ((a_Item.m_ItemType == 0) && (Split[0] != "0")) + else { - // Parsing the number failed - return false; + // Not a resolvable string, try pure numbers: "45:6", "45^6" etc. + a_Item.m_ItemType = (short)atoi(Split[0].c_str()); + if ((a_Item.m_ItemType == 0) && (Split[0] != "0")) + { + // Parsing the number failed + return false; + } } + + // Parse the damage, if present: if (Split.size() < 2) { + // Not present, set the item as valid and return success: a_Item.m_ItemCount = 1; return true; } + a_Item.m_ItemDamage = atoi(Split[1].c_str()); if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0")) { |