+ else if(command == TOCLIENT_BLOCKDATA)
+ {
+ // Ignore too small packet
+ if(datasize < 8)
+ return;
+
+ v3s16 p;
+ p.X = readS16(&data[2]);
+ p.Y = readS16(&data[4]);
+ p.Z = readS16(&data[6]);
+
+ /*dout_client<<DTIME<<"Client: Thread: BLOCKDATA for ("
+ <<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
+ /*dstream<<DTIME<<"Client: Thread: BLOCKDATA for ("
+ <<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
+
+ std::string datastring((char*)&data[8], datasize-8);
+ std::istringstream istr(datastring, std::ios_base::binary);
+
+ MapSector *sector;
+ MapBlock *block;
+
+ v2s16 p2d(p.X, p.Z);
+ sector = m_env.getMap().emergeSector(p2d);
+
+ assert(sector->getPos() == p2d);
+
+ //TimeTaker timer("MapBlock deSerialize");
+ // 0ms
+
+ block = sector->getBlockNoCreateNoEx(p.Y);
+ if(block)
+ {
+ /*
+ Update an existing block
+ */
+ //dstream<<"Updating"<<std::endl;
+ block->deSerialize(istr, ser_version);
+ }
+ else
+ {
+ /*
+ Create a new block
+ */
+ //dstream<<"Creating new"<<std::endl;
+ block = new MapBlock(&m_env.getMap(), p);
+ block->deSerialize(istr, ser_version);
+ sector->insertBlock(block);
+
+ //DEBUG
+ /*NodeMod mod;
+ mod.type = NODEMOD_CHANGECONTENT;
+ mod.param = CONTENT_MESE;
+ block->setTempMod(v3s16(8,10,8), mod);
+ block->setTempMod(v3s16(8,9,8), mod);
+ block->setTempMod(v3s16(8,8,8), mod);
+ block->setTempMod(v3s16(8,7,8), mod);
+ block->setTempMod(v3s16(8,6,8), mod);*/
+ }
+
+#if 0
+ /*
+ Acknowledge block
+ */
+ /*
+ [0] u16 command
+ [2] u8 count
+ [3] v3s16 pos_0
+ [3+6] v3s16 pos_1
+ ...
+ */
+ u32 replysize = 2+1+6;
+ SharedBuffer<u8> reply(replysize);
+ writeU16(&reply[0], TOSERVER_GOTBLOCKS);
+ reply[2] = 1;
+ writeV3S16(&reply[3], p);
+ // Send as reliable
+ m_con.Send(PEER_ID_SERVER, 1, reply, true);
+#endif
+
+ /*
+ Update Mesh of this block and blocks at x-, y- and z-.
+ Environment should not be locked as it interlocks with the
+ main thread, from which is will want to retrieve textures.
+ */
+
+ //m_env.getClientMap().updateMeshes(block->getPos(), getDayNightRatio());
+ /*
+ Add it to mesh update queue and set it to be acknowledged after update.
+ */
+ //std::cerr<<"Adding mesh update task for received block"<<std::endl;
+ addUpdateMeshTaskWithEdge(p, true);
+ }