Skip to content

Commit

Permalink
item drop multiplication fix
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron55 committed Apr 19, 2011
1 parent a7d36a5 commit 3c61d57
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/inventory.cpp
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions src/inventory.h
Expand Up @@ -59,6 +59,8 @@ class InventoryItem
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
Expand Down Expand Up @@ -279,6 +281,7 @@ class CraftItem : public InventoryItem
}

ServerActiveObject* createSAO(ServerEnvironment *env, u16 id, v3f pos);
u16 getDropCount();

virtual bool addableTo(InventoryItem *other)
{
Expand Down
31 changes: 18 additions & 13 deletions src/server.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3c61d57

Please sign in to comment.