forked from Mirrorlandia_minetest/minetest
Inventory: Make addList() consistent (#11382)
Fixes list clearing for inv:set_list() using same size, since 2db6b07. addList() now clears the list in all cases. Use setSize() to resize without clearing.
This commit is contained in:
parent
72927b73ca
commit
f2fd443262
@ -938,19 +938,16 @@ void Inventory::deSerialize(std::istream &is)
|
|||||||
InventoryList * Inventory::addList(const std::string &name, u32 size)
|
InventoryList * Inventory::addList(const std::string &name, u32 size)
|
||||||
{
|
{
|
||||||
setModified();
|
setModified();
|
||||||
|
|
||||||
|
// Remove existing lists
|
||||||
s32 i = getListIndex(name);
|
s32 i = getListIndex(name);
|
||||||
if(i != -1)
|
if (i != -1) {
|
||||||
{
|
delete m_lists[i];
|
||||||
if(m_lists[i]->getSize() != size)
|
m_lists[i] = new InventoryList(name, size, m_itemdef);
|
||||||
{
|
m_lists[i]->setModified();
|
||||||
delete m_lists[i];
|
|
||||||
m_lists[i] = new InventoryList(name, size, m_itemdef);
|
|
||||||
m_lists[i]->setModified();
|
|
||||||
}
|
|
||||||
return m_lists[i];
|
return m_lists[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//don't create list with invalid name
|
//don't create list with invalid name
|
||||||
if (name.find(' ') != std::string::npos)
|
if (name.find(' ') != std::string::npos)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -298,7 +298,7 @@ public:
|
|||||||
void serialize(std::ostream &os, bool incremental = false) const;
|
void serialize(std::ostream &os, bool incremental = false) const;
|
||||||
void deSerialize(std::istream &is);
|
void deSerialize(std::istream &is);
|
||||||
|
|
||||||
// Adds a new list or clears and resizes an existing one
|
// Creates a new list if none exists or truncates existing lists
|
||||||
InventoryList * addList(const std::string &name, u32 size);
|
InventoryList * addList(const std::string &name, u32 size);
|
||||||
InventoryList * getList(const std::string &name);
|
InventoryList * getList(const std::string &name);
|
||||||
const InventoryList * getList(const std::string &name) const;
|
const InventoryList * getList(const std::string &name) const;
|
||||||
|
@ -1359,9 +1359,9 @@ void read_inventory_list(lua_State *L, int tableindex,
|
|||||||
|
|
||||||
// Get Lua-specified items to insert into the list
|
// Get Lua-specified items to insert into the list
|
||||||
std::vector<ItemStack> items = read_items(L, tableindex,srv);
|
std::vector<ItemStack> items = read_items(L, tableindex,srv);
|
||||||
size_t listsize = (forcesize > 0) ? forcesize : items.size();
|
size_t listsize = (forcesize >= 0) ? forcesize : items.size();
|
||||||
|
|
||||||
// Create or clear list
|
// Create or resize/clear list
|
||||||
InventoryList *invlist = inv->addList(name, listsize);
|
InventoryList *invlist = inv->addList(name, listsize);
|
||||||
if (!invlist) {
|
if (!invlist) {
|
||||||
luaL_error(L, "inventory list: cannot create list named '%s'", name);
|
luaL_error(L, "inventory list: cannot create list named '%s'", name);
|
||||||
|
Loading…
Reference in New Issue
Block a user