world_format.txt 16 KB

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