From f15670379da5529d38936d0a87a50b0dc72c6e8f Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 24 Dec 2010 03:08:05 +0200 Subject: base stuff for item->object conversion --- src/server.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 86 insertions(+), 27 deletions(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index d7bd22668..db4e04228 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1635,7 +1635,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) } catch(InvalidPositionException &e) { - derr_server<<"PICK_OBJECT block not found"<getTypeId() == MAPBLOCKOBJECT_TYPE_ITEM) + { + item = ((ItemObject*)obj)->createInventoryItem(); + } + // Else create an item of the object + else + { + item = new MapBlockObjectItem + (obj->getInventoryString()); + } + // Add to inventory and send inventory - InventoryItem *item = new MapBlockObjectItem - (obj->getInventoryString()); ilist->addItem(item); SendInventory(player->peer_id); } @@ -2021,17 +2035,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) v.blitBack(modified_blocks); } /* - Handle block object items + Handle other items */ - else if(std::string("MBOItem") == item->getName()) + else { - MapBlockObjectItem *oitem = (MapBlockObjectItem*)item; - - /*dout_server<<"Trying to place a MapBlockObjectItem: " - "inventorystring=\"" - <getInventoryString() - <<"\""<createObject - (pos, player->getYaw(), player->getPitch()); + /* + Handle block object items + */ + if(std::string("MBOItem") == item->getName()) + { + MapBlockObjectItem *oitem = (MapBlockObjectItem*)item; + + /*dout_server<<"Trying to place a MapBlockObjectItem: " + "inventorystring=\"" + <getInventoryString() + <<"\""<createObject + (pos, player->getYaw(), player->getPitch()); + } + /* + Handle other items + */ + else + { + dout_server<<"Placing a miscellaneous item on map" + <serialize(os); + dout_server<<"Item string is \""<setItemString(os.str()); + obj = iobj; + } if(obj == NULL) - derr_server<<"WARNING: oitem created NULL object" + { + derr_server<<"WARNING: item resulted in NULL object, " + <<"not placing onto map" <addObject(obj); - block->addObject(obj); - - //dout_server<<"Placed object"<inventory.getList("main"); - if(g_settings.getBool("creative_mode") == false && ilist) - { - // Remove from inventory and send inventory - ilist->deleteItem(item_i); - // Send inventory - SendInventory(peer_id); + InventoryList *ilist = player->inventory.getList("main"); + if(g_settings.getBool("creative_mode") == false && ilist) + { + // Remove from inventory and send inventory + ilist->deleteItem(item_i); + // Send inventory + SendInventory(peer_id); + } } } @@ -2445,6 +2488,12 @@ void Server::peerAdded(con::Peer *peer) if(g_settings.getBool("creative_mode")) { + // Give a good pick + { + InventoryItem *item = new ToolItem("STPick", 32000); + bool r = player->inventory.addItem("main", item); + assert(r == true); + } // Give all materials assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE); for(u16 i=0; iinventory.addItem("main", item); + assert(r == true); + } + { + InventoryItem *item = new ToolItem("STPick", 32000); + bool r = player->inventory.addItem("main", item); + assert(r == true); + } /*// Give some lights { InventoryItem *item = new MaterialItem(CONTENT_TORCH, 999); -- cgit v1.2.3