world_format.txt 17 KB

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