world_format.txt 15 KB

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