1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Implement metadata-aware version of InvRef:remove_item() (#15771)

This commit is contained in:
Andrii Nemchenko 2025-02-22 17:18:48 +02:00 committed by GitHub
parent 0890125962
commit e51221d247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 24 deletions

View file

@ -319,9 +319,7 @@ int InvRef::l_contains_item(lua_State *L)
const char *listname = luaL_checkstring(L, 2);
ItemStack item = read_item(L, 3, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
bool match_meta = false;
if (lua_isboolean(L, 4))
match_meta = readParam<bool>(L, 4);
bool match_meta = readParam<bool>(L, 4, false);
if (list) {
lua_pushboolean(L, list->containsItem(item, match_meta));
} else {
@ -330,7 +328,7 @@ int InvRef::l_contains_item(lua_State *L)
return 1;
}
// remove_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
// remove_item(self, listname, itemstack or itemstring or table or nil, [match_meta]) -> itemstack
// Returns the items that were actually removed
int InvRef::l_remove_item(lua_State *L)
{
@ -339,8 +337,9 @@ int InvRef::l_remove_item(lua_State *L)
const char *listname = luaL_checkstring(L, 2);
ItemStack item = read_item(L, 3, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
bool match_meta = readParam<bool>(L, 4, false);
if(list){
ItemStack removed = list->removeItem(item);
ItemStack removed = list->removeItem(item, match_meta);
if(!removed.empty())
reportInventoryChange(L, ref);
LuaItemStack::create(L, removed);