world_format.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. auth_backend = files - which DB backend to use for authentication data
  113. mod_storage_backend = sqlite3 - which DB backend to use for mod storage
  114. server_announce = false - whether the server is publicly announced or not
  115. load_mod_<mod> = false - whether <mod> is to be loaded in this world
  116. For load_mod_<mod>, the possible values are:
  117. * `false` - Do not load the mod.
  118. * `true` - Load the mod from wherever it is found (may cause conflicts if the same mod appears also in some other place).
  119. * `mods/modpack/moddir` - Relative path to the mod
  120. * Must be one of the following:
  121. * `mods/`: mods in the user path's mods folder (ex `/home/user/.minetest/mods`)
  122. * `share/`: mods in the share's mods folder (ex: `/usr/share/minetest/mods`)
  123. * `/path/to/env`: you can use absolute paths to mods inside folders specified with the `MINETEST_MOD_PATH` env variable.
  124. * Other locations and absolute paths are not supported
  125. * Note that `moddir` is the directory name, not the mod name specified in mod.conf.
  126. PostgreSQL backend specific settings:
  127. pgsql_connection = host=127.0.0.1 port=5432 user=mt_user password=mt_password dbname=minetest
  128. pgsql_player_connection = (same parameters as above)
  129. pgsql_readonly_connection = (same parameters as above)
  130. pgsql_auth_connection = (same parameters as above)
  131. pgsql_mod_storage_connection = (same parameters as above)
  132. Redis backend specific settings:
  133. redis_address = 127.0.0.1 - Redis server address
  134. redis_hash = foo - Database hash
  135. redis_port = 6379 - (optional) connection port
  136. redis_password = hunter2 - (optional) server password
  137. Player File Format
  138. ===================
  139. - Should be pretty self-explanatory.
  140. - Note: position is in nodes * 10
  141. Example content (added indentation):
  142. hp = 11
  143. name = celeron55
  144. pitch = 39.77
  145. position = (-5231.97,15,1961.41)
  146. version = 1
  147. yaw = 101.37
  148. PlayerArgsEnd
  149. List main 32
  150. Item default:torch 13
  151. Item default:pick_steel 1 50112
  152. Item experimental:tnt
  153. Item default:cobble 99
  154. Item default:pick_stone 1 13104
  155. Item default:shovel_steel 1 51838
  156. Item default:dirt 61
  157. Item default:rail 78
  158. Item default:coal_lump 3
  159. Item default:cobble 99
  160. Item default:leaves 22
  161. Item default:gravel 52
  162. Item default:axe_steel 1 2045
  163. Item default:cobble 98
  164. Item default:sand 61
  165. Item default:water_source 94
  166. Item default:glass 2
  167. Item default:mossycobble
  168. Item default:pick_steel 1 64428
  169. Item animalmaterials:bone
  170. Item default:sword_steel
  171. Item default:sapling
  172. Item default:sword_stone 1 10647
  173. Item default:dirt 99
  174. Empty
  175. Empty
  176. Empty
  177. Empty
  178. Empty
  179. Empty
  180. Empty
  181. Empty
  182. EndInventoryList
  183. List craft 9
  184. Empty
  185. Empty
  186. Empty
  187. Empty
  188. Empty
  189. Empty
  190. Empty
  191. Empty
  192. Empty
  193. EndInventoryList
  194. List craftpreview 1
  195. Empty
  196. EndInventoryList
  197. List craftresult 1
  198. Empty
  199. EndInventoryList
  200. EndInventory
  201. Map File Format
  202. ================
  203. Minetest maps consist of MapBlocks, chunks of 16x16x16 nodes.
  204. In addition to the bulk node data, MapBlocks stored on disk also contain
  205. other things.
  206. History
  207. --------
  208. We need a bit of history in here. Initially Minetest stored maps in a
  209. format called the "sectors" format. It was a directory/file structure like
  210. this:
  211. sectors2/XXX/ZZZ/YYYY
  212. For example, the MapBlock at (0,1,-2) was this file:
  213. sectors2/000/ffd/0001
  214. Eventually Minetest outgrow this directory structure, as filesystems were
  215. struggling under the amount of files and directories.
  216. Large servers seriously needed a new format, and thus the base of the
  217. current format was invented, suggested by celeron55 and implemented by
  218. JacobF.
  219. SQLite3 was slammed in, and blocks files were directly inserted as blobs
  220. in a single table, indexed by integer primary keys, oddly mangled from
  221. coordinates.
  222. Today we know that SQLite3 allows multiple primary keys (which would allow
  223. storing coordinates separately), but the format has been kept unchanged for
  224. that part. So, this is where it has come.
  225. </history>
  226. So here goes
  227. -------------
  228. map.sqlite is an sqlite3 database, containing a single table, called
  229. "blocks". It looks like this:
  230. CREATE TABLE `blocks` (`pos` INT NOT NULL PRIMARY KEY,`data` BLOB);
  231. The key
  232. --------
  233. "pos" is created from the three coordinates of a MapBlock using this
  234. algorithm, defined here in Python:
  235. def getBlockAsInteger(p):
  236. return int64(p[2]*16777216 + p[1]*4096 + p[0])
  237. def int64(u):
  238. while u >= 2**63:
  239. u -= 2**64
  240. while u <= -2**63:
  241. u += 2**64
  242. return u
  243. It can be converted the other way by using this code:
  244. def getIntegerAsBlock(i):
  245. x = unsignedToSigned(i % 4096, 2048)
  246. i = int((i - x) / 4096)
  247. y = unsignedToSigned(i % 4096, 2048)
  248. i = int((i - y) / 4096)
  249. z = unsignedToSigned(i % 4096, 2048)
  250. return x,y,z
  251. def unsignedToSigned(i, max_positive):
  252. if i < max_positive:
  253. return i
  254. else:
  255. return i - 2*max_positive
  256. The blob
  257. ---------
  258. The blob is the data that would have otherwise gone into the file.
  259. See below for description.
  260. MapBlock serialization format
  261. ==============================
  262. NOTE: Byte order is MSB first (big-endian).
  263. NOTE: Zlib data is in such a format that Python's zlib at least can
  264. directly decompress.
  265. NOTE: Since version 29 zstd is used instead of zlib. In addition the entire
  266. block is first serialized and then compressed (except the version byte).
  267. u8 version
  268. - map format version number, see serialization.h for the latest number
  269. u8 flags
  270. - Flag bitmasks:
  271. - 0x01: is_underground: Should be set to 0 if there will be no light
  272. obstructions above the block. If/when sunlight of a block is updated
  273. and there is no block above it, this value is checked for determining
  274. whether sunlight comes from the top.
  275. - 0x02: day_night_differs: Whether the lighting of the block is different
  276. on day and night. Only blocks that have this bit set are updated when
  277. day transforms to night.
  278. - 0x04: lighting_expired: Not used in version 27 and above. If true,
  279. lighting is invalid and should be updated. If you can't calculate
  280. lighting in your generator properly, you could try setting this 1 to
  281. everything and setting the uppermost block in every sector as
  282. is_underground=0. I am quite sure it doesn't work properly, though.
  283. - 0x08: generated: True if the block has been generated. If false, block
  284. is mostly filled with CONTENT_IGNORE and is likely to contain eg. parts
  285. of trees of neighboring blocks.
  286. u16 lighting_complete
  287. - Added in version 27.
  288. - This contains 12 flags, each of them corresponds to a direction.
  289. - Indicates if the light is correct at the sides of a map block.
  290. Lighting may not be correct if the light changed, but a neighbor
  291. block was not loaded at that time.
  292. If these flags are false, Minetest will automatically recompute light
  293. when both this block and its required neighbor are loaded.
  294. - The bit order is:
  295. nothing, nothing, nothing, nothing,
  296. night X-, night Y-, night Z-, night Z+, night Y+, night X+,
  297. day X-, day Y-, day Z-, day Z+, day Y+, day X+.
  298. Where 'day' is for the day light bank, 'night' is for the night
  299. light bank.
  300. The 'nothing' bits should be always set, as they will be used
  301. to indicate if direct sunlight spreading is finished.
  302. - Example: if the block at (0, 0, 0) has
  303. lighting_complete = 0b1111111111111110,
  304. then Minetest will correct lighting in the day light bank when
  305. the block at (1, 0, 0) is also loaded.
  306. if map format version >= 29:
  307. u32 timestamp
  308. - Timestamp when last saved, as seconds from starting the game.
  309. - 0xffffffff = invalid/unknown timestamp, nothing should be done with the time
  310. difference when loaded
  311. u8 name_id_mapping_version
  312. - Should be zero for map format version 29.
  313. u16 num_name_id_mappings
  314. foreach num_name_id_mappings
  315. u16 id
  316. u16 name_len
  317. u8[name_len] name
  318. if map format version < 29:
  319. -- Nothing right here, timestamp and node id mappings are serialized later
  320. u8 content_width
  321. - Number of bytes in the content (param0) fields of nodes
  322. if map format version <= 23:
  323. - Always 1
  324. if map format version >= 24:
  325. - Always 2
  326. u8 params_width
  327. - Number of bytes used for parameters per node
  328. - Always 2
  329. node data (zlib-compressed if version < 29):
  330. if content_width == 1:
  331. - content:
  332. u8[4096]: param0 fields
  333. u8[4096]: param1 fields
  334. u8[4096]: param2 fields
  335. if content_width == 2:
  336. - content:
  337. u16[4096]: param0 fields
  338. u8[4096]: param1 fields
  339. u8[4096]: param2 fields
  340. - The location of a node in each of those arrays is (z*16*16 + y*16 + x).
  341. node metadata list (zlib-compressed if version < 29):
  342. - content:
  343. if map format version <= 22:
  344. u16 version (=1)
  345. u16 count of metadata
  346. foreach count:
  347. u16 position (p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X)
  348. u16 type_id
  349. u16 content_size
  350. u8[content_size] content of metadata. Format depends on type_id, see below.
  351. if map format version >= 23:
  352. u8 version -- Note: type was u16 for map format version <= 22
  353. -- = 1 for map format version < 28
  354. -- = 2 since map format version 28
  355. u16 count of metadata
  356. foreach count:
  357. u16 position (p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X)
  358. u32 num_vars
  359. foreach num_vars:
  360. u16 key_len
  361. u8[key_len] key
  362. u32 val_len
  363. u8[val_len] value
  364. u8 is_private -- only for version >= 2. 0 = not private, 1 = private
  365. serialized inventory
  366. - Node timers
  367. if map format version == 23:
  368. u8 unused version (always 0)
  369. if map format version == 24: (NOTE: Not released as stable)
  370. u8 nodetimer_version
  371. if nodetimer_version == 0:
  372. (nothing else)
  373. if nodetimer_version == 1:
  374. u16 num_of_timers
  375. foreach num_of_timers:
  376. u16 timer position (z*16*16 + y*16 + x)
  377. s32 timeout*1000
  378. s32 elapsed*1000
  379. if map format version >= 25:
  380. -- Nothing right here, node timers are serialized later
  381. u8 static object version:
  382. - Always 0
  383. u16 static_object_count
  384. foreach static_object_count:
  385. u8 type (object type-id)
  386. s32 pos_x_nodes * 10000
  387. s32 pos_y_nodes * 10000
  388. s32 pos_z_nodes * 10000
  389. u16 data_size
  390. u8[data_size] data
  391. if map format version < 29:
  392. u32 timestamp
  393. - Same meaning as the timestamp further up
  394. u8 name-id-mapping version
  395. - Always 0
  396. u16 num_name_id_mappings
  397. foreach num_name_id_mappings
  398. u16 id
  399. u16 name_len
  400. u8[name_len] name
  401. - Node timers
  402. if map format version >= 25:
  403. u8 length of the data of a single timer (always 2+4+4=10)
  404. u16 num_of_timers
  405. foreach num_of_timers:
  406. u16 timer position (z*16*16 + y*16 + x)
  407. s32 timeout*1000
  408. s32 elapsed*1000
  409. EOF.
  410. Format of nodes
  411. ----------------
  412. A node is composed of the u8 fields param0, param1 and param2.
  413. if map format version <= 23:
  414. The content id of a node is determined as so:
  415. - If param0 < 0x80,
  416. content_id = param0
  417. - Otherwise
  418. content_id = (param0<<4) + (param2>>4)
  419. if map format version >= 24:
  420. The content id of a node is param0.
  421. The purpose of param1 and param2 depend on the definition of the node.
  422. The name-id-mapping
  423. --------------------
  424. The mapping maps node content ids to node names.
  425. Node metadata format for map format versions <= 22
  426. ---------------------------------------------------
  427. The node metadata are serialized depending on the type_id field.
  428. 1: Generic metadata
  429. serialized inventory
  430. u32 len
  431. u8[len] text
  432. u16 len
  433. u8[len] owner
  434. u16 len
  435. u8[len] infotext
  436. u16 len
  437. u8[len] inventory drawspec
  438. u8 allow_text_input (bool)
  439. u8 removal_disabled (bool)
  440. u8 enforce_owner (bool)
  441. u32 num_vars
  442. foreach num_vars
  443. u16 len
  444. u8[len] name
  445. u32 len
  446. u8[len] value
  447. 14: Sign metadata
  448. u16 text_len
  449. u8[text_len] text
  450. 15: Chest metadata
  451. serialized inventory
  452. 16: Furnace metadata
  453. TBD
  454. 17: Locked Chest metadata
  455. u16 len
  456. u8[len] owner
  457. serialized inventory
  458. Static objects
  459. ---------------
  460. Static objects are persistent freely moving objects in the world.
  461. Object types:
  462. 1: Test object
  463. 7: LuaEntity
  464. 7: LuaEntity:
  465. u8 compatibility_byte (always 1)
  466. u16 len
  467. u8[len] entity name
  468. u32 len
  469. u8[len] static data
  470. s16 hp
  471. s32 velocity.x * 10000
  472. s32 velocity.y * 10000
  473. s32 velocity.z * 10000
  474. s32 yaw * 1000
  475. if PROTOCOL_VERSION >= 37:
  476. u8 version2 (=1)
  477. s32 pitch * 1000
  478. s32 roll * 1000
  479. Itemstring format
  480. ------------------
  481. eg. 'default:dirt 5'
  482. eg. 'default:pick_wood 21323'
  483. eg. '"default:apple" 2'
  484. eg. 'default:apple'
  485. - The wear value in tools is 0...65535
  486. - There are also a number of older formats that you might stumble upon:
  487. eg. 'node "default:dirt" 5'
  488. eg. 'NodeItem default:dirt 5'
  489. eg. 'ToolItem WPick 21323'
  490. Inventory serialization format
  491. -------------------------------
  492. - The inventory serialization format is line-based
  493. - The newline character used is "\n"
  494. - The end condition of a serialized inventory is always "EndInventory\n"
  495. - All the slots in a list must always be serialized.
  496. Example (format does not include "---"):
  497. ---
  498. List foo 4
  499. Item default:sapling
  500. Item default:sword_stone 1 10647
  501. Item default:dirt 99
  502. Empty
  503. EndInventoryList
  504. List bar 9
  505. Empty
  506. Empty
  507. Empty
  508. Empty
  509. Empty
  510. Empty
  511. Empty
  512. Empty
  513. Empty
  514. EndInventoryList
  515. EndInventory
  516. ---