item drop multiplication fix
authorPerttu Ahola <celeron55@gmail.com>
Tue, 19 Apr 2011 14:09:45 +0000 (17:09 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 19 Apr 2011 14:09:45 +0000 (17:09 +0300)
src/inventory.cpp
src/inventory.h
src/server.cpp

index b6560063f39db38e4f62e7e9eeeebad233f69f37..289b5bb2b7dde6fce40a681aaed41ca655b55381 100644 (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()
 {
        if(m_subname == "lump_of_iron")
index cb45371e4a25b68bf6e58081b3d3aa865c5bc3fb..d2d23542ea3c95002d16b66a66c8c7b7c3379a54 100644 (file)
@@ -59,6 +59,8 @@ public:
        virtual std::string getText() { return ""; }
        // 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
+       virtual u16 getDropCount(){ return getCount(); }
 
        /*
                Quantity methods
@@ -279,6 +281,7 @@ public:
        }
 
        ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
+       u16 getDropCount();
 
        virtual bool addableTo(InventoryItem *other)
        {
index 6a0c1304053016b12a53a0c27dd0b7aba13a0da8..154603a47099b27401aef105c5e0030ae6e26b4c 100644 (file)
@@ -2470,22 +2470,27 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                        
                                        dout_server<<"Placed object"<<std::endl;
 
-                                       // If item has count<=1, delete it
-                                       if(item->getCount() <= 1)
+                                       if(g_settings.getBool("creative_mode") == false)
                                        {
-                                               InventoryList *ilist = player->inventory.getList("main");
-                                               if(g_settings.getBool("creative_mode") == false && ilist)
+                                               // Delete the right amount of items from the slot
+                                               u16 dropcount = item->getDropCount();
+                                               
+                                               // Delete item if all gone
+                                               if(item->getCount() <= dropcount)
                                                {
-                                                       // Remove from inventory and send inventory
-                                                       ilist->deleteItem(item_i);
-                                                       // Send inventory
-                                                       SendInventory(peer_id);
+                                                       if(item->getCount() < dropcount)
+                                                               dstream<<"WARNING: Server: dropped more items"
+                                                                               <<" than the slot contains"<<std::endl;
+                                                       
+                                                       InventoryList *ilist = player->inventory.getList("main");
+                                                       if(ilist)
+                                                               // Remove from inventory and send inventory
+                                                               ilist->deleteItem(item_i);
                                                }
-                                       }
-                                       // Else decrement it
-                                       else
-                                       {
-                                               item->remove(1);
+                                               // Else decrement it
+                                               else
+                                                       item->remove(dropcount);
+                                               
                                                // Send inventory
                                                SendInventory(peer_id);
                                        }