item drop multiplication fix

master
Perttu Ahola 2011-04-19 17:09:45 +03:00
parent a7d36a50bb
commit 3c61d57f6d
3 changed files with 31 additions and 13 deletions

View File

@ -180,6 +180,16 @@ ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos
} }
} }
u16 CraftItem::getDropCount()
{
// Special cases
if(m_subname == "rat")
return 1;
// Default
else
return InventoryItem::getDropCount();
}
bool CraftItem::isCookable() bool CraftItem::isCookable()
{ {
if(m_subname == "lump_of_iron") if(m_subname == "lump_of_iron")

View File

@ -59,6 +59,8 @@ public:
virtual std::string getText() { return ""; } virtual std::string getText() { return ""; }
// Creates an object from the item, to be placed in the world. // Creates an object from the item, to be placed in the world.
virtual ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos); virtual ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
// Gets amount of items that dropping one SAO will decrement
virtual u16 getDropCount(){ return getCount(); }
/* /*
Quantity methods Quantity methods
@ -279,6 +281,7 @@ public:
} }
ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos); ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
u16 getDropCount();
virtual bool addableTo(InventoryItem *other) virtual bool addableTo(InventoryItem *other)
{ {

View File

@ -2470,22 +2470,27 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
dout_server<<"Placed object"<<std::endl; dout_server<<"Placed object"<<std::endl;
// If item has count<=1, delete it if(g_settings.getBool("creative_mode") == false)
if(item->getCount() <= 1)
{ {
InventoryList *ilist = player->inventory.getList("main"); // Delete the right amount of items from the slot
if(g_settings.getBool("creative_mode") == false && ilist) u16 dropcount = item->getDropCount();
// Delete item if all gone
if(item->getCount() <= dropcount)
{ {
// Remove from inventory and send inventory if(item->getCount() < dropcount)
ilist->deleteItem(item_i); dstream<<"WARNING: Server: dropped more items"
// Send inventory <<" than the slot contains"<<std::endl;
SendInventory(peer_id);
InventoryList *ilist = player->inventory.getList("main");
if(ilist)
// Remove from inventory and send inventory
ilist->deleteItem(item_i);
} }
} // Else decrement it
// Else decrement it else
else item->remove(dropcount);
{
item->remove(1);
// Send inventory // Send inventory
SendInventory(peer_id); SendInventory(peer_id);
} }