diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-12 17:37:14 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:40 +0200 |
commit | 1320d07068f25ff23ea27e120983c006f75bec24 (patch) | |
tree | 3357de80e98ecdb045c31213a551eb93fe5250b9 /src/inventory.cpp | |
parent | 0b97ad838466ed44296a2c663b2dc034feb51f67 (diff) | |
download | minetest-1320d07068f25ff23ea27e120983c006f75bec24.tar.gz minetest-1320d07068f25ff23ea27e120983c006f75bec24.tar.bz2 minetest-1320d07068f25ff23ea27e120983c006f75bec24.zip |
Scripting WIP: dynamic object stuff
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 45646a69a..c9ba9b4e5 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -205,22 +205,23 @@ InventoryItem *CraftItem::createCookResult() const return item_craft_create_cook_result(m_subname); } -bool CraftItem::use(ServerEnvironment *env, Player *player) +bool CraftItem::use(ServerEnvironment *env, ServerActiveObject *user) { - 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; + if(!item_craft_is_eatable(m_subname)) + return false; + + u16 result_count = getCount() - 1; // Eat one at a time + s16 hp_change = item_craft_eat_hp_change(m_subname); + s16 hp = user->getHP(); + hp += hp_change; + if(hp < 0) + hp = 0; + user->setHP(hp); + + if(result_count < 1) + return true; - if(result_count < 1) - return true; - else - setCount(result_count); - } + setCount(result_count); return false; } |