MCPcopy Create free account
hub / github.com/cuberite/cuberite / ResolveItem

Method ResolveItem

src/BlockID.cpp:66–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65
66 bool ResolveItem(const AString & a_ItemName, cItem & a_Item)
67 {
68 // Split into parts divided by either ':' or '^'
69 AStringVector Split = StringSplitAndTrim(a_ItemName, ":^");
70 if (Split.empty())
71 {
72 return false;
73 }
74
75 ItemMap::iterator itr = m_Map.find(Split[0]);
76 if (itr != m_Map.end())
77 {
78 // Resolved as a string, assign the type and the default damage / count
79 a_Item.m_ItemType = itr->second.first;
80 a_Item.m_ItemDamage = itr->second.second;
81 if (a_Item.m_ItemDamage == -1)
82 {
83 a_Item.m_ItemDamage = 0;
84 }
85 }
86 else
87 {
88 // Not a resolvable string, try pure numbers: "45:6", "45^6" etc.
89 a_Item.m_ItemType = (short)atoi(Split[0].c_str());
90 if ((a_Item.m_ItemType == 0) && (Split[0] != "0"))
91 {
92 // Parsing the number failed
93 return false;
94 }
95 }
96
97 // Parse the damage, if present:
98 if (Split.size() < 2)
99 {
100 // Not present, set the item as valid and return success:
101 a_Item.m_ItemCount = 1;
102 return true;
103 }
104
105 a_Item.m_ItemDamage = atoi(Split[1].c_str());
106 if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0"))
107 {
108 // Parsing the number failed
109 return false;
110 }
111 a_Item.m_ItemCount = 1;
112 return true;
113 }
114
115
116 AString Desolve(short a_ItemType, short a_ItemDamage)

Callers 1

StringToItemFunction · 0.80

Calls 5

StringSplitAndTrimFunction · 0.85
emptyMethod · 0.80
endMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected