world_format.txt 16 KB

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