Skip to content

Commit 8e3b63b

Browse files
ClobberXDsfan5
authored andcommittedMay 11, 2019
Define operators == and != for ItemStack
1 parent 72feab0 commit 8e3b63b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed
 

‎src/inventory.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,9 @@ bool InventoryList::operator == (const InventoryList &other) const
508508
return false;
509509
if(m_name != other.m_name)
510510
return false;
511-
for(u32 i=0; i<m_items.size(); i++)
512-
{
513-
ItemStack s1 = m_items[i];
514-
ItemStack s2 = other.m_items[i];
515-
if(s1.name != s2.name || s1.wear!= s2.wear || s1.count != s2.count ||
516-
s1.metadata != s2.metadata)
511+
for (u32 i = 0; i < m_items.size(); i++)
512+
if (m_items[i] != other.m_items[i])
517513
return false;
518-
}
519514

520515
return true;
521516
}

‎src/inventory.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ItemStack
4141

4242
// Serialization
4343
void serialize(std::ostream &os) const;
44-
// Deserialization. Pass itemdef unless you don't want aliases resolved.
44+
// Deserialization. Pass itemdef unless you don't want aliases resolved.
4545
void deSerialize(std::istream &is, IItemDefManager *itemdef = NULL);
4646
void deSerialize(const std::string &s, IItemDefManager *itemdef = NULL);
4747

@@ -161,6 +161,19 @@ struct ItemStack
161161
// Similar to takeItem, but keeps this ItemStack intact.
162162
ItemStack peekItem(u32 peekcount) const;
163163

164+
bool operator ==(const ItemStack &s) const
165+
{
166+
return (this->name == s.name &&
167+
this->count == s.count &&
168+
this->wear == s.wear &&
169+
this->metadata == s.metadata);
170+
}
171+
172+
bool operator !=(const ItemStack &s) const
173+
{
174+
return !(*this == s);
175+
}
176+
164177
/*
165178
Properties
166179
*/

0 commit comments

Comments
 (0)
Please sign in to comment.