diff options
Diffstat (limited to 'src/server.cpp')
-rw-r--r-- | src/server.cpp | 123 |
1 files changed, 70 insertions, 53 deletions
diff --git a/src/server.cpp b/src/server.cpp index e2e6ce46b..ab60be5cc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2368,77 +2368,94 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; } + // Skip if object has been removed + if(obj->m_removed) + return; + //TODO: Check that object is reasonably close // Left click, pick object up (usually) if(button == 0) { - InventoryList *ilist = player->inventory.getList("main"); - if(g_settings.getBool("creative_mode") == false && ilist != NULL) - { + /* + Try creating inventory item + */ + InventoryItem *item = obj->createPickedUpItem(); - // Skip if inventory has no free space - if(ilist->getUsedSlots() == ilist->getSize()) + if(item) + { + if(g_settings.getBool("creative_mode") == false) { - dout_server<<"Player inventory has no free space"<<std::endl; - return; - } + InventoryList *ilist = player->inventory.getList("main"); + if(ilist != NULL) + { + // Skip if inventory has no free space + if(ilist->getUsedSlots() == ilist->getSize()) + { + dout_server<<"Player inventory has no free space"<<std::endl; + return; + } - // Skip if object has been removed - if(obj->m_removed) - return; - - /* - Create the inventory item - */ - InventoryItem *item = obj->createPickedUpItem(); - - if(item) - { - // Add to inventory and send inventory - ilist->addItem(item); - UpdateCrafting(player->peer_id); - SendInventory(player->peer_id); + // Add to inventory and send inventory + ilist->addItem(item); + UpdateCrafting(player->peer_id); + SendInventory(player->peer_id); - // Remove object from environment - obj->m_removed = true; + // Remove object from environment + obj->m_removed = true; + } } - else - { - /* - Item cannot be picked up. Punch it instead. - */ + } + else + { + /* + Item cannot be picked up. Punch it instead. + */ - ToolItem *titem = NULL; - std::string toolname = ""; + ToolItem *titem = NULL; + std::string toolname = ""; - InventoryList *mlist = player->inventory.getList("main"); - if(mlist != NULL) + InventoryList *mlist = player->inventory.getList("main"); + if(mlist != NULL) + { + InventoryItem *item = mlist->getItem(item_i); + if(item && (std::string)item->getName() == "ToolItem") { - InventoryItem *item = mlist->getItem(item_i); - if(item && (std::string)item->getName() == "ToolItem") - { - titem = (ToolItem*)item; - toolname = titem->getToolName(); - } + titem = (ToolItem*)item; + toolname = titem->getToolName(); } + } - v3f playerpos = player->getPosition(); - v3f objpos = obj->getBasePosition(); - v3f dir = (objpos - playerpos).normalize(); - - u16 wear = obj->punch(toolname, dir); - - if(titem) - { - bool weared_out = titem->addWear(wear); - if(weared_out) - mlist->deleteItem(item_i); - SendInventory(player->peer_id); - } + v3f playerpos = player->getPosition(); + v3f objpos = obj->getBasePosition(); + v3f dir = (objpos - playerpos).normalize(); + + u16 wear = obj->punch(toolname, dir); + + if(titem) + { + bool weared_out = titem->addWear(wear); + if(weared_out) + mlist->deleteItem(item_i); + SendInventory(player->peer_id); } } } + // Right click, do something with object + if(button == 1) + { + // Track hp changes super-crappily + u16 oldhp = player->hp; + + // Do stuff + obj->rightClick(player); + + // Send back stuff + if(player->hp != oldhp) + { + SendPlayerHP(player); + } + } } else if(command == TOSERVER_GROUND_ACTION) { |