From 3c61d57f6d7f627b32b4a8c2f461a8e01e7ac378 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 19 Apr 2011 17:09:45 +0300 Subject: item drop multiplication fix --- src/inventory.cpp | 10 ++++++++++ src/inventory.h | 3 +++ src/server.cpp | 31 ++++++++++++++++++------------- 3 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/inventory.cpp b/src/inventory.cpp index b6560063f..289b5bb2b 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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") diff --git a/src/inventory.h b/src/inventory.h index cb45371e4..d2d23542e 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -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) { diff --git a/src/server.cpp b/src/server.cpp index 6a0c13040..154603a47 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2470,22 +2470,27 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) dout_server<<"Placed object"<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"<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); } -- cgit v1.2.3