1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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
This commit is contained in:
JacobF 2011-09-01 17:16:55 -04:00 committed by Perttu Ahola
parent 2d872ce3fa
commit c68ea19e8d
3 changed files with 21 additions and 5 deletions

View file

@ -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;
}