<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://olddev.minetest.org/index.php?action=history&amp;feed=atom&amp;title=Minetest_Schematic_File_Format</id>
	<title>Minetest Schematic File Format - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://olddev.minetest.org/index.php?action=history&amp;feed=atom&amp;title=Minetest_Schematic_File_Format"/>
	<link rel="alternate" type="text/html" href="https://olddev.minetest.org/index.php?title=Minetest_Schematic_File_Format&amp;action=history"/>
	<updated>2026-04-15T01:24:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.7</generator>
	<entry>
		<id>https://olddev.minetest.org/index.php?title=Minetest_Schematic_File_Format&amp;diff=114&amp;oldid=prev</id>
		<title>&gt;Rubenwardy: lua_api.txt -&gt; lua_api.md</title>
		<link rel="alternate" type="text/html" href="https://olddev.minetest.org/index.php?title=Minetest_Schematic_File_Format&amp;diff=114&amp;oldid=prev"/>
		<updated>2023-05-01T11:18:09Z</updated>

		<summary type="html">&lt;p&gt;lua_api.txt -&amp;gt; lua_api.md&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The '''Minetest Schematic File Format''' if the file format used when schematics are seralized by e.g. minetest.create_schematic. Schematic files are supposed to have “.mts” as a file name suffix. This document describes the MTS format native to Minetest.&lt;br /&gt;
== Informal definition ==&lt;br /&gt;
Warning: This definition has not been proofread yet! Don't rely on it 100% yet.&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
An MTS file has 3 sections, in this order:&lt;br /&gt;
&lt;br /&gt;
* Header&lt;br /&gt;
* Name ID Table&lt;br /&gt;
* Node Definitions Section&lt;br /&gt;
&lt;br /&gt;
All values are stored in ''big endian'' format.&lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
| Offset  | Length | Description                              |&lt;br /&gt;
|---------|--------|------------------------------------------|&lt;br /&gt;
|       0 |      4 | magic number, ASCII letters &amp;quot;MTSM&amp;quot;       |&lt;br /&gt;
|       4 |      2 | file format version, currently 4         |&lt;br /&gt;
|       6 |      2 | size X                                   |&lt;br /&gt;
|       8 |      2 | size Y                                   |&lt;br /&gt;
|      10 |      2 | size Z                                   |&lt;br /&gt;
|      12 |      Y | layer probability values                 |&lt;br /&gt;
|    12+Y |      2 | number of strings in Name ID Table       |&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Layer probability values: This is a sequence of unsigned 8-bit numbers (0-255) for each Y layer. Each Y layer has a chance of appearing with the given probability. The probability ranges from 0 to 127, with 0 meaning 0% probability and 127 meaning 100% probability. Bit 7 is reserved and must be 0, meaning that values greater than 127 should be avoided.&lt;br /&gt;
&lt;br /&gt;
The header is followed by the Name ID Table, which is followed by the Node Definitons section.&lt;br /&gt;
&lt;br /&gt;
=== Name ID Table ===&lt;br /&gt;
&lt;br /&gt;
For each string, the following record format repeats:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
| Offset | Length | Description              |&lt;br /&gt;
|--------|--------|--------------------------|&lt;br /&gt;
|      0 |      2 | length of the string (N) |&lt;br /&gt;
|      2 |      N | string, node itemstring  |&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The node IDs in the next section reference these.&lt;br /&gt;
&lt;br /&gt;
=== Node Definitons Section ===&lt;br /&gt;
&lt;br /&gt;
This part of the file is zlib compressed, with the deflate algorithm using gz header bytes&lt;br /&gt;
[http://tools.ietf.org/html/rfc1950 RFC 1950], but not with the gzip header which has magic bytes too. After uncompressing,&lt;br /&gt;
the format is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
| Offset  | Length     | Description                              |&lt;br /&gt;
|---------|------------|------------------------------------------|&lt;br /&gt;
|       0 | 2*X*Y*Z    | node IDs (param0)                        |&lt;br /&gt;
| 2*X*Y*Z | X*Y*Z      | probability values (param1)              |&lt;br /&gt;
| 3*X*Y*Z | X*Y*Z      | param2                                   |&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get the node ID from &amp;lt;code&amp;gt;param0&amp;lt;/code&amp;gt; for a given coordinate (x,y,z), you should calculate the index &amp;lt;code&amp;gt;param0[(Z-z)*Z*Y + y*X + x]&amp;lt;/code&amp;gt;.&lt;br /&gt;
That's right, the Z axis is mirrored.&lt;br /&gt;
&lt;br /&gt;
Each node ID is stored on a big endian 2 bytes. Orientation is '''not''' defined in any way, there's absolutely no convention.&lt;br /&gt;
&lt;br /&gt;
Probability values in &amp;lt;code&amp;gt;param1&amp;lt;/code&amp;gt; are encoded in unsigned 8 bits. They are indexed the same way as node IDs. Probability ranges from 0 (0%) to 127 (100%). Bit 7 means force node placement, i.e. the node will be able to replace non-air nodes as well.&lt;br /&gt;
(In legacy version 3, &amp;lt;code&amp;gt;param1&amp;lt;/code&amp;gt;'s probability range was from 0 to 0xFF, there's no force placement.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;param2&amp;lt;/code&amp;gt; is an 8-bit value (0-255), the meaning depends on the node definition. See &amp;lt;code&amp;gt;lua_api.md&amp;lt;/code&amp;gt; to learn more about &amp;lt;code&amp;gt;param2&amp;lt;/code&amp;gt; (keywords: “param2”, “paramtype2”).&lt;br /&gt;
&lt;br /&gt;
== Official definition ==&lt;br /&gt;
The official definition of version 4 of this file format follows and has been copied from [https://github.com/minetest/minetest/blob/5.1.0/src/mapgen/mg_schematic.h /src/mapgen/mg_schematic.h] in the Minetest 5.1.0 source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
All values are stored in big-endian byte order.&lt;br /&gt;
[u32] signature: 'MTSM'&lt;br /&gt;
[u16] version: 4&lt;br /&gt;
[u16] size X&lt;br /&gt;
[u16] size Y&lt;br /&gt;
[u16] size Z&lt;br /&gt;
For each Y:&lt;br /&gt;
	[u8] slice probability value&lt;br /&gt;
[Name-ID table] Name ID Mapping Table&lt;br /&gt;
	[u16] name-id count&lt;br /&gt;
	For each name-id mapping:&lt;br /&gt;
		[u16] name length&lt;br /&gt;
		[u8[]] name&lt;br /&gt;
ZLib deflated {&lt;br /&gt;
For each node in schematic:  (for z, y, x)&lt;br /&gt;
	[u16] content&lt;br /&gt;
For each node in schematic:&lt;br /&gt;
	[u8] param1&lt;br /&gt;
	  bit 0-6: probability&lt;br /&gt;
	  bit 7:   specific node force placement&lt;br /&gt;
For each node in schematic:&lt;br /&gt;
	[u8] param2&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Source code 5.1.0: [https://github.com/minetest/minetest/blob/5.1.0/src/mapgen/mg_schematic.h /src/mapgen/mg_schematic.h]&lt;br /&gt;
* Source code bleeding edge: [https://github.com/minetest/minetest/blob/master/src/mapgen/mg_schematic.h /src/mapgen/mg_schematic.h]&lt;br /&gt;
&lt;br /&gt;
== Version changes ==&lt;br /&gt;
As of Minetest 5.1.0, the current version of the MTS file format is 4.&lt;br /&gt;
&lt;br /&gt;
* 1—Initial version&lt;br /&gt;
* 2—Fixed messy never/always place; the probability of &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; is now never, and &amp;lt;code&amp;gt;0xFF&amp;lt;/code&amp;gt; is always&lt;br /&gt;
* 3—Added y-slice probabilities; this allows for variable height structures&lt;br /&gt;
* 4—Compressed range of node occurence probability, added per-node force placement bit (used since 0.4.16 or earlier)&lt;br /&gt;
&lt;br /&gt;
[[Category:Core Engine]]&lt;/div&gt;</summary>
		<author><name>&gt;Rubenwardy</name></author>
	</entry>
</feed>