summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2017-06-25 11:39:39 +0200
committerGitHub <noreply@github.com>2017-06-25 11:39:39 +0200
commitc08cc0533fbf344be5243485f39a471268855149 (patch)
treef9b5c51903572e2eafa7b4781a06768b1ed554db /src
parentcad10ce3b747b721fd63784915e05f12bc488128 (diff)
downloadminetest-c08cc0533fbf344be5243485f39a471268855149.tar.gz
minetest-c08cc0533fbf344be5243485f39a471268855149.tar.bz2
minetest-c08cc0533fbf344be5243485f39a471268855149.zip
Inventory: Fix wrong stack size behaviour and item loss (#6039)
Also fix itemFits and remove constness-nonsense
Diffstat (limited to 'src')
-rw-r--r--src/database-postgresql.cpp2
-rw-r--r--src/database-sqlite3.cpp2
-rw-r--r--src/inventory.cpp12
-rw-r--r--src/inventory.h5
4 files changed, 8 insertions, 13 deletions
diff --git a/src/database-postgresql.cpp b/src/database-postgresql.cpp
index ac25afd48..3c54f48d1 100644
--- a/src/database-postgresql.cpp
+++ b/src/database-postgresql.cpp
@@ -584,7 +584,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
if (itemStr.length() > 0) {
ItemStack stack;
stack.deSerialize(itemStr);
- invList->addItem(pg_to_uint(results2, row2, 0), stack);
+ invList->changeItem(pg_to_uint(results2, row2, 0), stack);
}
}
PQclear(results2);
diff --git a/src/database-sqlite3.cpp b/src/database-sqlite3.cpp
index 22765c8d2..77451fadb 100644
--- a/src/database-sqlite3.cpp
+++ b/src/database-sqlite3.cpp
@@ -565,7 +565,7 @@ bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
if (itemStr.length() > 0) {
ItemStack stack;
stack.deSerialize(itemStr);
- invList->addItem(sqlite_to_uint(m_stmt_player_load_inventory_items, 0), stack);
+ invList->changeItem(sqlite_to_uint(m_stmt_player_load_inventory_items, 0), stack);
}
}
sqlite3_reset(m_stmt_player_load_inventory_items);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 24eebba80..4da380a24 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -254,11 +254,8 @@ std::string ItemStack::getItemString() const
}
-ItemStack ItemStack::addItem(const ItemStack &newitem_,
- IItemDefManager *itemdef)
+ItemStack ItemStack::addItem(ItemStack newitem, IItemDefManager *itemdef)
{
- ItemStack newitem = newitem_;
-
// If the item is empty or the position invalid, bail out
if(newitem.empty())
{
@@ -267,7 +264,7 @@ ItemStack ItemStack::addItem(const ItemStack &newitem_,
// If this is an empty item, it's an easy job.
else if(empty())
{
- const u16 stackMax = getStackMax(itemdef);
+ const u16 stackMax = newitem.getStackMax(itemdef);
*this = newitem;
@@ -303,11 +300,10 @@ ItemStack ItemStack::addItem(const ItemStack &newitem_,
return newitem;
}
-bool ItemStack::itemFits(const ItemStack &newitem_,
+bool ItemStack::itemFits(ItemStack newitem,
ItemStack *restitem,
IItemDefManager *itemdef) const
{
- ItemStack newitem = newitem_;
// If the item is empty or the position invalid, bail out
if(newitem.empty())
@@ -317,7 +313,7 @@ bool ItemStack::itemFits(const ItemStack &newitem_,
// If this is an empty item, it's an easy job.
else if(empty())
{
- const u16 stackMax = getStackMax(itemdef);
+ const u16 stackMax = newitem.getStackMax(itemdef);
// If the item fits fully, delete it
if (newitem.count <= stackMax) {
diff --git a/src/inventory.h b/src/inventory.h
index 04c8156c8..2f8757f1c 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -143,13 +143,12 @@ struct ItemStack
// If cannot be added at all, returns the item back.
// If can be added partly, decremented item is returned back.
// If can be added fully, empty item is returned.
- ItemStack addItem(const ItemStack &newitem,
- IItemDefManager *itemdef);
+ ItemStack addItem(ItemStack newitem, IItemDefManager *itemdef);
// Checks whether newitem could be added.
// If restitem is non-NULL, it receives the part of newitem that
// would be left over after adding.
- bool itemFits(const ItemStack &newitem,
+ bool itemFits(ItemStack newitem,
ItemStack *restitem, // may be NULL
IItemDefManager *itemdef) const;