mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Implement metadata-aware version of InvRef:remove_item() (#15771)
This commit is contained in:
parent
0890125962
commit
e51221d247
6 changed files with 41 additions and 24 deletions
|
@ -693,11 +693,11 @@ bool InventoryList::containsItem(const ItemStack &item, bool match_meta) const
|
|||
return false;
|
||||
}
|
||||
|
||||
ItemStack InventoryList::removeItem(const ItemStack &item)
|
||||
ItemStack InventoryList::removeItem(const ItemStack &item, bool match_meta)
|
||||
{
|
||||
ItemStack removed;
|
||||
for (auto i = m_items.rbegin(); i != m_items.rend(); ++i) {
|
||||
if (i->name == item.name) {
|
||||
if (i->name == item.name && (!match_meta || i->metadata == item.metadata)) {
|
||||
u32 still_to_remove = item.count - removed.count;
|
||||
ItemStack leftover = removed.addItem(i->takeItem(still_to_remove),
|
||||
m_itemdef);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue