Move MapBlock (de)serializing code out of Database class

**Backup your worlds before trying this**
This also fixes #1340
`p3d`/`blockpos` is inconsistent. (I'd use `blockpos`)  Also, use references and const (`const std::string &data`) if possible to reduce copies.