mapformat.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. =================================================
  2. Minetest World Format used as of 0.4.dev-20120322
  3. =================================================
  4. This applies to a world format carrying the block serialization version 22
  5. which is used at least in version 0.4.dev-20120322.
  6. The block serialization version used is 22. It does not fully specify every
  7. aspect of this format; if compliance with this format is to be checked, it
  8. needs to be done by detecting if the files and data indeed follows it.
  9. Legacy stuff
  10. =============
  11. Data can, in theory, be contained in the flat file directory structure
  12. described below in Version 17, but it is not officially supported. Also you
  13. may stumble upon all kinds of oddities in not-so-recent formats.
  14. Files
  15. ======
  16. Everything is contained in a directory, the name of which is freeform, but
  17. often serves as the name of the world.
  18. Currently the authentication and ban data is stored on a per-world basis. It
  19. can be copied over from an old world to a newly created world.
  20. World
  21. |-- auth.txt ----- Authentication data
  22. |-- env_meta.txt - Environment metadata
  23. |-- ipban.txt ---- Banned ips/users
  24. |-- map_meta.txt - Map metadata
  25. |-- map.sqlite --- Map data
  26. |-- players ------ Player directory
  27. | |-- player1 -- Player file
  28. | '-- Foo ------ Player file
  29. `-- world.mt ----- World metadata
  30. auth.txt
  31. ---------
  32. Contains authentication data, player per line.
  33. <name>:<password hash>:<privilege1,...>
  34. Format of password hash is <name><password> SHA1'd, in the base64 encoding.
  35. Example lines:
  36. - Player "celeron55", no password, privileges "interact" and "shout":
  37. celeron55::interact,shout
  38. - Player "Foo", password "bar", privilege "shout":
  39. foo:iEPX+SQWIR3p67lj/0zigSWTKHg:shout
  40. - Player "bar", no password, no privileges:
  41. bar::
  42. env_meta.txt
  43. -------------
  44. Simple global environment variables.
  45. Example content (added indentation):
  46. game_time = 73471
  47. time_of_day = 19118
  48. EnvArgsEnd
  49. ipban.txt
  50. ----------
  51. Banned IP addresses and usernames.
  52. Example content (added indentation):
  53. 123.456.78.9|foo
  54. 123.456.78.10|bar
  55. map_meta.txt
  56. -------------
  57. Simple global map variables.
  58. Example content (added indentation):
  59. seed = 7980462765762429666
  60. [end_of_params]
  61. map.sqlite
  62. -----------
  63. Map data.
  64. See Map File Format below.
  65. player1, Foo
  66. -------------
  67. Player data.
  68. Filename can be anything.
  69. See Player File Format below.
  70. world.mt
  71. ---------
  72. World metadata.
  73. Example content (added indentation):
  74. gameid = mesetint
  75. Player File Format
  76. ===================
  77. - Should be pretty self-explanatory.
  78. - Note: position is in nodes * 10
  79. Example content (added indentation):
  80. hp = 11
  81. name = celeron55
  82. pitch = 39.77
  83. position = (-5231.97,15,1961.41)
  84. version = 1
  85. yaw = 101.37
  86. PlayerArgsEnd
  87. List main 32
  88. Item default:torch 13
  89. Item default:pick_steel 1 50112
  90. Item experimental:tnt
  91. Item default:cobble 99
  92. Item default:pick_stone 1 13104
  93. Item default:shovel_steel 1 51838
  94. Item default:dirt 61
  95. Item default:rail 78
  96. Item default:coal_lump 3
  97. Item default:cobble 99
  98. Item default:leaves 22
  99. Item default:gravel 52
  100. Item default:axe_steel 1 2045
  101. Item default:cobble 98
  102. Item default:sand 61
  103. Item default:water_source 94
  104. Item default:glass 2
  105. Item default:mossycobble
  106. Item default:pick_steel 1 64428
  107. Item animalmaterials:bone
  108. Item default:sword_steel
  109. Item default:sapling
  110. Item default:sword_stone 1 10647
  111. Item default:dirt 99
  112. Empty
  113. Empty
  114. Empty
  115. Empty
  116. Empty
  117. Empty
  118. Empty
  119. Empty
  120. EndInventoryList
  121. List craft 9
  122. Empty
  123. Empty
  124. Empty
  125. Empty
  126. Empty
  127. Empty
  128. Empty
  129. Empty
  130. Empty
  131. EndInventoryList
  132. List craftpreview 1
  133. Empty
  134. EndInventoryList
  135. List craftresult 1
  136. Empty
  137. EndInventoryList
  138. EndInventory
  139. Map File Format
  140. ================
  141. Minetest maps consist of MapBlocks, chunks of 16x16x16 nodes.
  142. In addition to the bulk node data, MapBlocks stored on disk also contain
  143. other things.
  144. History
  145. --------
  146. We need a bit of history in here. Initially Minetest stored maps in a
  147. format called the "sectors" format. It was a directory/file structure like
  148. this:
  149. sectors2/XXX/ZZZ/YYYY
  150. For example, the MapBlock at (0,1,-2) was this file:
  151. sectors2/000/ffd/0001
  152. Eventually Minetest outgrow this directory structure, as filesystems were
  153. struggling under the amount of files and directories.
  154. Large servers seriously needed a new format, and thus the base of the
  155. current format was invented, suggested by celeron55 and implemented by
  156. JacobF.
  157. SQLite3 was slammed in, and blocks files were directly inserted as blobs
  158. in a single table, indexed by integer primary keys, oddly mangled from
  159. coordinates.
  160. Today we know that SQLite3 allows multiple primary keys (which would allow
  161. storing coordinates separately), but the format has been kept unchanged for
  162. that part. So, this is where it has come.
  163. </history>
  164. So here goes
  165. -------------
  166. map.sqlite is an sqlite3 database, containg a single table, called
  167. "blocks". It looks like this:
  168. CREATE TABLE `blocks` (`pos` INT NOT NULL PRIMARY KEY,`data` BLOB);
  169. The key
  170. --------
  171. "pos" is created from the three coordinates of a MapBlock using this
  172. algorithm, defined here in Python:
  173. def getBlockAsInteger(p):
  174. return int64(p[2]*16777216 + p[1]*4096 + p[0])
  175. def int64(u):
  176. while u >= 2**63:
  177. u -= 2**64
  178. while u <= -2**63:
  179. u += 2**64
  180. return u
  181. It can be converted the other way by using this code:
  182. def getIntegerAsBlock(i):
  183. x = unsignedToSigned(i % 4096, 2048)
  184. i = int((i - x) / 4096)
  185. y = unsignedToSigned(i % 4096, 2048)
  186. i = int((i - y) / 4096)
  187. z = unsignedToSigned(i % 4096, 2048)
  188. return x,y,z
  189. def unsignedToSigned(i, max_positive):
  190. if i < max_positive:
  191. return i
  192. else:
  193. return i - 2*max_positive
  194. The blob
  195. ---------
  196. The blob is the data that would have otherwise gone into the file.
  197. See below for description.
  198. MapBlock serialization format
  199. ==============================
  200. NOTE: Byte order is MSB first (big-endian).
  201. NOTE: Zlib data is in such a format that Python's zlib at least can
  202. directly decompress.
  203. u8 version
  204. - map format version number, this one is version 22
  205. u8 flags
  206. - Flag bitmasks:
  207. - 0x01: is_underground: Should be set to 0 if there will be no light
  208. obstructions above the block. If/when sunlight of a block is updated
  209. and there is no block above it, this value is checked for determining
  210. whether sunlight comes from the top.
  211. - 0x02: day_night_differs: Whether the lighting of the block is different
  212. on day and night. Only blocks that have this bit set are updated when
  213. day transforms to night.
  214. - 0x04: lighting_expired: If true, lighting is invalid and should be
  215. updated. If you can't calculate lighting in your generator properly,
  216. you could try setting this 1 to everything and setting the uppermost
  217. block in every sector as is_underground=0. I am quite sure it doesn't
  218. work properly, though.
  219. - 0x08: generated: True if the block has been generated. If false, block
  220. is mostly filled with CONTENT_IGNORE and is likely to contain eg. parts
  221. of trees of neighboring blocks.
  222. u8 content_width
  223. - Number of bytes in the content (param0) fields of nodes
  224. - Always 1
  225. u8 params_width
  226. - Number of bytes used for parameters per node
  227. - Always 2
  228. zlib-compressed node data:
  229. - content:
  230. u8[4096]: param0 fields
  231. u8[4096]: param1 fields
  232. u8[4096]: param2 fields
  233. - The location of a node in each of those arrays is (z*16*16 + y*16 + x).
  234. zlib-compressed node metadata list
  235. - content:
  236. u16 version (=1)
  237. u16 count of metadata
  238. foreach count:
  239. u16 position (p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X)
  240. u16 type_id
  241. u16 content_size
  242. u8[content_size] (content of metadata)
  243. u16 mapblockobject_count
  244. - Always 0
  245. - Should be removed in version 23 (TODO)
  246. u8 static object version:
  247. - Always 0
  248. u16 static_object_count
  249. foreach static_object_count:
  250. u8 type (object type-id)
  251. s32 pos_x_nodes * 10000
  252. s32 pos_y_nodes * 10000
  253. s32 pos_z_nodes * 10000
  254. u16 data_size
  255. u8[data_size] data
  256. u32 timestamp
  257. - Timestamp when last saved, as seconds from starting the game.
  258. - 0xffffffff = invalid/unknown timestamp, nothing should be done with the time
  259. difference when loaded
  260. u8 name-id-mapping version
  261. - Always 0
  262. u16 num_name_id_mappings
  263. foreach num_name_id_mappings
  264. u16 id
  265. u16 name_len
  266. u8[name_len] name
  267. EOF.
  268. Format of nodes
  269. ----------------
  270. A node is composed of the u8 fields param0, param1 and param2.
  271. The content id of a node is determined as so:
  272. - If param0 < 0x80,
  273. content_id = param0
  274. - Otherwise
  275. content_id = (param0<<4) + (param2>>4)
  276. The purpose of param1 and param2 depend on the definition of the node.
  277. The name-id-mapping
  278. --------------------
  279. The mapping maps node content ids to node names.
  280. Node metadata format
  281. ---------------------
  282. 1: Generic metadata
  283. serialized inventory
  284. u32 len
  285. u8[len] text
  286. u16 len
  287. u8[len] owner
  288. u16 len
  289. u8[len] infotext
  290. u16 len
  291. u8[len] inventory drawspec
  292. u8 allow_text_input (bool)
  293. u8 removal_disabled (bool)
  294. u8 enforce_owner (bool)
  295. u32 num_vars
  296. foreach num_vars
  297. u16 len
  298. u8[len] name
  299. u32 len
  300. u8[len] value
  301. 14: Sign metadata
  302. u16 text_len
  303. u8[text_len] text
  304. 15: Chest metadata
  305. serialized inventory
  306. 16: Furnace metadata
  307. TBD
  308. 17: Locked Chest metadata
  309. u16 len
  310. u8[len] owner
  311. serialized inventory
  312. Static objects
  313. ---------------
  314. Static objects are persistent freely moving objects in the world.
  315. Object types:
  316. 1: Test object
  317. 2: Item
  318. 3: Rat (deprecated)
  319. 4: Oerkki (deprecated)
  320. 5: Firefly (deprecated)
  321. 6: MobV2 (deprecated)
  322. 7: LuaEntity
  323. 1: Item:
  324. u8 version
  325. version 0:
  326. u16 len
  327. u8[len] itemstring
  328. 7: LuaEntity:
  329. u8 version
  330. version 1:
  331. u16 len
  332. u8[len] entity name
  333. u32 len
  334. u8[len] static data
  335. s16 hp
  336. s32 velocity.x * 10000
  337. s32 velocity.y * 10000
  338. s32 velocity.z * 10000
  339. s32 yaw * 1000
  340. Itemstring format
  341. ------------------
  342. eg. 'default:dirt 5'
  343. eg. 'default:pick_wood 21323'
  344. eg. '"default:apple" 2'
  345. eg. 'default:apple'
  346. - The wear value in tools is 0...65535
  347. - There are also a number of older formats that you might stumble upon:
  348. eg. 'node "default:dirt" 5'
  349. eg. 'NodeItem default:dirt 5'
  350. eg. 'ToolItem WPick 21323'
  351. Inventory serialization format
  352. -------------------------------
  353. - The inventory serialization format is line-based
  354. - The newline character used is "\n"
  355. - The end condition of a serialized inventory is always "EndInventory\n"
  356. - All the slots in a list must always be serialized.
  357. Example (format does not include "---"):
  358. ---
  359. List foo 4
  360. Item default:sapling
  361. Item default:sword_stone 1 10647
  362. Item default:dirt 99
  363. Empty
  364. EndInventoryList
  365. List bar 9
  366. Empty
  367. Empty
  368. Empty
  369. Empty
  370. Empty
  371. Empty
  372. Empty
  373. Empty
  374. Empty
  375. EndInventoryList
  376. EndInventory
  377. ---
  378. ==============================================
  379. Minetest World Format used as of 2011-05 or so
  380. ==============================================
  381. Map data serialization format version 17.
  382. 0.3.1 does not use this format, but a more recent one. This exists here for
  383. historical reasons.
  384. Directory structure:
  385. sectors/XXXXZZZZ or sectors2/XXX/ZZZ
  386. XXXX, ZZZZ, XXX and ZZZ being the hexadecimal X and Z coordinates.
  387. Under these, the block files are stored, called YYYY.
  388. There also exists files map_meta.txt and chunk_meta, that are used by the
  389. generator. If they are not found or invalid, the generator will currently
  390. behave quite strangely.
  391. The MapBlock file format (sectors2/XXX/ZZZ/YYYY):
  392. -------------------------------------------------
  393. NOTE: Byte order is MSB first.
  394. u8 version
  395. - map format version number, this one is version 17
  396. u8 flags
  397. - Flag bitmasks:
  398. - 0x01: is_underground: Should be set to 0 if there will be no light
  399. obstructions above the block. If/when sunlight of a block is updated and
  400. there is no block above it, this value is checked for determining whether
  401. sunlight comes from the top.
  402. - 0x02: day_night_differs: Whether the lighting of the block is different on
  403. day and night. Only blocks that have this bit set are updated when day
  404. transforms to night.
  405. - 0x04: lighting_expired: If true, lighting is invalid and should be updated.
  406. If you can't calculate lighting in your generator properly, you could try
  407. setting this 1 to everything and setting the uppermost block in every
  408. sector as is_underground=0. I am quite sure it doesn't work properly,
  409. though.
  410. zlib-compressed map data:
  411. - content:
  412. u8[4096]: content types
  413. u8[4096]: param1 values
  414. u8[4096]: param2 values
  415. zlib-compressed node metadata
  416. - content:
  417. u16 version (=1)
  418. u16 count of metadata
  419. foreach count:
  420. u16 position (= p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X)
  421. u16 type_id
  422. u16 content_size
  423. u8[content_size] misc. stuff contained in the metadata
  424. u16 mapblockobject_count
  425. - always write as 0.
  426. - if read != 0, just fail.
  427. foreach mapblockobject_count:
  428. - deprecated, should not be used. Length of this data can only be known by
  429. properly parsing it. Just hope not to run into any of this.
  430. u8 static object version:
  431. - currently 0
  432. u16 static_object_count
  433. foreach static_object_count:
  434. u8 type (object type-id)
  435. s32 pos_x * 1000
  436. s32 pos_y * 1000
  437. s32 pos_z * 1000
  438. u16 data_size
  439. u8[data_size] data
  440. u32 timestamp
  441. - Timestamp when last saved, as seconds from starting the game.
  442. - 0xffffffff = invalid/unknown timestamp, nothing will be done with the time
  443. difference when loaded (recommended)
  444. Node metadata format:
  445. ---------------------
  446. Sign metadata:
  447. u16 string_len
  448. u8[string_len] string
  449. Furnace metadata:
  450. TBD
  451. Chest metadata:
  452. TBD
  453. Locking Chest metadata:
  454. u16 string_len
  455. u8[string_len] string
  456. TBD
  457. // END