diff options
author | JacobF <queatz@gmail.com> | 2011-09-01 17:16:55 -0400 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-09-06 16:36:11 +0300 |
commit | c68ea19e8dd54c497b0fd3f16f26d063318e8bf6 (patch) | |
tree | e62c483bb35e0b7c13f8c7f05267b1aab78e9aa9 /src | |
parent | 2d872ce3fab0887f97adb4d57fc043e08f44d276 (diff) | |
download | minetest-c68ea19e8dd54c497b0fd3f16f26d063318e8bf6.tar.gz minetest-c68ea19e8dd54c497b0fd3f16f26d063318e8bf6.tar.bz2 minetest-c68ea19e8dd54c497b0fd3f16f26d063318e8bf6.zip |
Now SAOs will reflect changes to their temporary inventory object
Also, the temp item wasn't being deleted, might have been a memory leak.
Now you will only eat 1 item off a stack
Diffstat (limited to 'src')
-rw-r--r-- | src/content_sao.cpp | 5 | ||||
-rw-r--r-- | src/inventory.cpp | 19 | ||||
-rw-r--r-- | src/inventory.h | 2 |
3 files changed, 21 insertions, 5 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 638f50c9d..0bb518c16 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -226,6 +226,11 @@ void ItemSAO::rightClick(Player *player) if(to_be_deleted) m_removed = true; + else + // Reflect changes to the item here + m_inventorystring = item->getItemString(); + + delete item; } /* diff --git a/src/inventory.cpp b/src/inventory.cpp index 116ceeb6d..f31e19f77 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -122,16 +122,20 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is) } } +std::string InventoryItem::getItemString() { + // Get item string + std::ostringstream os(std::ios_base::binary); + serialize(os); + return os.str(); +} + ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f pos) { /* Create an ItemSAO */ - // Get item string - std::ostringstream os(std::ios_base::binary); - serialize(os); // Create object - ServerActiveObject *obj = new ItemSAO(env, 0, pos, os.str()); + ServerActiveObject *obj = new ItemSAO(env, 0, pos, getItemString()); return obj; } @@ -200,12 +204,17 @@ bool CraftItem::use(ServerEnvironment *env, Player *player) { if(item_craft_is_eatable(m_subname)) { + u16 result_count = getCount() - 1; // Eat one at a time s16 hp_change = item_craft_eat_hp_change(m_subname); if(player->hp + hp_change > 20) player->hp = 20; else player->hp += hp_change; - return true; + + if(result_count < 1) + return true; + else + setCount(result_count); } return false; } diff --git a/src/inventory.h b/src/inventory.h index b19a365c8..44ba6a5ad 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -58,6 +58,8 @@ public: #endif // Shall return a text to show in the GUI virtual std::string getText() { return ""; } + // Returns the string used for inventory + virtual std::string getItemString(); // Creates an object from the item, to be placed in the world. virtual ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos); // Gets amount of items that dropping one SAO will decrement |