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

Method Desolve

src/BlockID.cpp:116–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115
116 AString Desolve(short a_ItemType, short a_ItemDamage)
117 {
118 // First try an exact match, both ItemType and ItemDamage ("birchplanks=5:2"):
119 for (ItemMap::iterator itr = m_Map.begin(), end = m_Map.end(); itr != end; ++itr)
120 {
121 if ((itr->second.first == a_ItemType) && (itr->second.second == a_ItemDamage))
122 {
123 return itr->first;
124 }
125 } // for itr - m_Map[]
126
127 // There is no exact match, try matching ItemType only ("planks=5"):
128 if (a_ItemDamage == 0)
129 {
130 for (ItemMap::iterator itr = m_Map.begin(), end = m_Map.end(); itr != end; ++itr)
131 {
132 if ((itr->second.first == a_ItemType) && (itr->second.second == -1))
133 {
134 return itr->first;
135 }
136 } // for itr - m_Map[]
137 }
138
139 // No match at all, synthesize a string ("5:1"):
140 AString res;
141 if (a_ItemDamage == -1)
142 {
143 Printf(res, "%d", a_ItemType);
144 }
145 else
146 {
147 Printf(res, "%d:%d", a_ItemType, a_ItemDamage);
148 }
149 return res;
150 }
151
152
153protected:

Callers 2

ItemToStringFunction · 0.80
ItemTypeToStringFunction · 0.80

Calls 3

PrintfFunction · 0.85
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected