From 4a92df6ff021f1bfa645f97fd551c648d1ef8e3b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 4 Apr 2011 15:13:19 +0300 Subject: Chests work now! --- src/server.cpp | 158 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 33 deletions(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index 4f3846cf8..a70c42a35 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2460,6 +2460,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) InventoryAction *a = InventoryAction::deSerialize(is); if(a != NULL) { + // Create context + InventoryContext c; + c.current_player = player; + /* Handle craftresult specially if not in creative mode */ @@ -2468,50 +2472,60 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) && g_settings.getBool("creative_mode") == false) { IMoveAction *ma = (IMoveAction*)a; - // Don't allow moving anything to craftresult - if(ma->to_name == "craftresult") - { - // Do nothing - disable_action = true; - } - // When something is removed from craftresult - if(ma->from_name == "craftresult") + if(ma->to_inv == "current_player" && + ma->from_inv == "current_player") { - disable_action = true; - // Remove stuff from craft - InventoryList *clist = player->inventory.getList("craft"); - if(clist) + // Don't allow moving anything to craftresult + if(ma->to_list == "craftresult") { - u16 count = ma->count; - if(count == 0) - count = 1; - clist->decrementMaterials(count); + // Do nothing + disable_action = true; } - // Do action - // Feed action to player inventory - a->apply(&player->inventory); - // Eat it - delete a; - // If something appeared in craftresult, throw it - // in the main list - InventoryList *rlist = player->inventory.getList("craftresult"); - InventoryList *mlist = player->inventory.getList("main"); - if(rlist && mlist && rlist->getUsedSlots() == 1) + // When something is removed from craftresult + if(ma->from_list == "craftresult") { - InventoryItem *item1 = rlist->changeItem(0, NULL); - mlist->addItem(item1); + disable_action = true; + // Remove stuff from craft + InventoryList *clist = player->inventory.getList("craft"); + if(clist) + { + u16 count = ma->count; + if(count == 0) + count = 1; + clist->decrementMaterials(count); + } + // Do action + // Feed action to player inventory + //a->apply(&player->inventory); + a->apply(&c, this); + // Eat it + delete a; + // If something appeared in craftresult, throw it + // in the main list + InventoryList *rlist = player->inventory.getList("craftresult"); + InventoryList *mlist = player->inventory.getList("main"); + if(rlist && mlist && rlist->getUsedSlots() == 1) + { + InventoryItem *item1 = rlist->changeItem(0, NULL); + mlist->addItem(item1); + } } } } + if(disable_action == false) { // Feed action to player inventory - a->apply(&player->inventory); - // Eat it + //a->apply(&player->inventory); + a->apply(&c, this); + // Eat the action delete a; } - // Send inventory - SendInventory(player->peer_id); + else + { + // Send inventory + SendInventory(player->peer_id); + } } else { @@ -2679,6 +2693,63 @@ void Server::onMapEditEvent(MapEditEvent *event) m_unsent_map_edit_queue.push_back(e); } +Inventory* Server::getInventory(InventoryContext *c, std::string id) +{ + if(id == "current_player") + { + assert(c->current_player); + return &(c->current_player->inventory); + } + + Strfnd fn(id); + std::string id0 = fn.next(":"); + + if(id0 == "nodemeta") + { + v3s16 p; + p.X = stoi(fn.next(",")); + p.Y = stoi(fn.next(",")); + p.Z = stoi(fn.next(",")); + NodeMetadata *meta = m_env.getMap().getNodeMetadata(p); + if(meta) + return meta->getInventory(); + dstream<<"nodemeta at ("<current_player); + // Send inventory + SendInventory(c->current_player->peer_id); + return; + } + + Strfnd fn(id); + std::string id0 = fn.next(":"); + + if(id0 == "nodemeta") + { + v3s16 p; + p.X = stoi(fn.next(",")); + p.Y = stoi(fn.next(",")); + p.Z = stoi(fn.next(",")); + assert(c->current_player); + RemoteClient *client = getClient(c->current_player->peer_id); + v3s16 blockpos = getNodeBlockPos(p); + client->SetBlockNotSent(blockpos); + return; + } + + dstream<<__FUNCTION_NAME<<": unknown id "< Server::getPlayerInfo() { DSTACK(__FUNCTION_NAME); @@ -3027,7 +3098,8 @@ void Server::SendInventory(u16 peer_id) specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { - rlist->addItem(new MapBlockObjectItem("Sign")); + //rlist->addItem(new MapBlockObjectItem("Sign")); + rlist->addItem(new MaterialItem(CONTENT_SIGN_WALL, 1)); found = true; } } @@ -3092,6 +3164,26 @@ void Server::SendInventory(u16 peer_id) found = true; } } + + // Chest1 + if(!found) + { + ItemSpec specs[9]; + specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + if(checkItemCombination(items, specs)) + { + rlist->addItem(new MaterialItem(CONTENT_CHEST, 1)); + found = true; + } + } + } } // if creative_mode == false -- cgit v1.2.3