client_lua_api.txt 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. Minetest Lua Client Modding API Reference 5.2.0
  2. ================================================
  3. * More information at <http://www.minetest.net/>
  4. * Developer Wiki: <http://dev.minetest.net/>
  5. Introduction
  6. ------------
  7. ** WARNING: The client API is currently unstable, and may break/change without warning. **
  8. Content and functionality can be added to Minetest 0.4.15-dev+ by using Lua
  9. scripting in run-time loaded mods.
  10. A mod is a self-contained bunch of scripts, textures and other related
  11. things that is loaded by and interfaces with Minetest.
  12. Transferring client-sided mods from the server to the client is planned, but not implemented yet.
  13. If you see a deficiency in the API, feel free to attempt to add the
  14. functionality in the engine and API. You can send such improvements as
  15. source code patches on GitHub (https://github.com/minetest/minetest).
  16. Programming in Lua
  17. ------------------
  18. If you have any difficulty in understanding this, please read
  19. [Programming in Lua](http://www.lua.org/pil/).
  20. Startup
  21. -------
  22. Mods are loaded during client startup from the mod load paths by running
  23. the `init.lua` scripts in a shared environment.
  24. In order to load client-side mods, the following conditions need to be satisfied:
  25. 1) `$path_user/minetest.conf` contains the setting `enable_client_modding = true`
  26. 2) The client-side mod located in `$path_user/clientmods/<modname>` is added to
  27. `$path_user/clientmods/mods.conf` as `load_mod_<modname> = true`.
  28. Note: Depending on the remote server's settings, client-side mods might not
  29. be loaded or have limited functionality. See setting `csm_restriction_flags` for reference.
  30. Paths
  31. -----
  32. * `RUN_IN_PLACE=1` (Windows release, local build)
  33. * `$path_user`: `<build directory>`
  34. * `$path_share`: `<build directory>`
  35. * `RUN_IN_PLACE=0`: (Linux release)
  36. * `$path_share`:
  37. * Linux: `/usr/share/minetest`
  38. * Windows: `<install directory>/minetest-0.4.x`
  39. * `$path_user`:
  40. * Linux: `$HOME/.minetest`
  41. * Windows: `C:/users/<user>/AppData/minetest` (maybe)
  42. Mod load path
  43. -------------
  44. Generic:
  45. * `$path_share/clientmods/`
  46. * `$path_user/clientmods/` (User-installed mods)
  47. In a run-in-place version (e.g. the distributed windows version):
  48. * `minetest-0.4.x/clientmods/` (User-installed mods)
  49. On an installed version on Linux:
  50. * `/usr/share/minetest/clientmods/`
  51. * `$HOME/.minetest/clientmods/` (User-installed mods)
  52. Modpack support
  53. ----------------
  54. Mods can be put in a subdirectory, if the parent directory, which otherwise
  55. should be a mod, contains a file named `modpack.conf`.
  56. The file is a key-value store of modpack details.
  57. * `name`: The modpack name.
  58. * `description`: Description of mod to be shown in the Mods tab of the main
  59. menu.
  60. Mod directory structure
  61. ------------------------
  62. clientmods
  63. ├── modname
  64. │   ├── mod.conf
  65. │   ├── init.lua
  66. └── another
  67. ### modname
  68. The location of this directory.
  69. ### mod.conf
  70. An (optional) settings file that provides meta information about the mod.
  71. * `name`: The mod name. Allows Minetest to determine the mod name even if the
  72. folder is wrongly named.
  73. * `description`: Description of mod to be shown in the Mods tab of the main
  74. menu.
  75. * `depends`: A comma separated list of dependencies. These are mods that must be
  76. loaded before this mod.
  77. * `optional_depends`: A comma separated list of optional dependencies.
  78. Like a dependency, but no error if the mod doesn't exist.
  79. ### `init.lua`
  80. The main Lua script. Running this script should register everything it
  81. wants to register. Subsequent execution depends on minetest calling the
  82. registered callbacks.
  83. **NOTE**: Client mods currently can't provide and textures, sounds or models by
  84. themselves. Any media referenced in function calls must already be loaded
  85. (provided by mods that exist on the server).
  86. Naming convention for registered textual names
  87. ----------------------------------------------
  88. Registered names should generally be in this format:
  89. "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
  90. This is to prevent conflicting names from corrupting maps and is
  91. enforced by the mod loader.
  92. ### Example
  93. In the mod `experimental`, there is the ideal item/node/entity name `tnt`.
  94. So the name should be `experimental:tnt`.
  95. Enforcement can be overridden by prefixing the name with `:`. This can
  96. be used for overriding the registrations of some other mod.
  97. Example: Any mod can redefine `experimental:tnt` by using the name
  98. :experimental:tnt
  99. when registering it.
  100. (also that mod is required to have `experimental` as a dependency)
  101. The `:` prefix can also be used for maintaining backwards compatibility.
  102. Sounds
  103. ------
  104. **NOTE: Connecting sounds to objects is not implemented.**
  105. Only Ogg Vorbis files are supported.
  106. For positional playing of sounds, only single-channel (mono) files are
  107. supported. Otherwise OpenAL will play them non-positionally.
  108. Mods should generally prefix their sounds with `modname_`, e.g. given
  109. the mod name "`foomod`", a sound could be called:
  110. foomod_foosound.ogg
  111. Sounds are referred to by their name with a dot, a single digit and the
  112. file extension stripped out. When a sound is played, the actual sound file
  113. is chosen randomly from the matching sounds.
  114. When playing the sound `foomod_foosound`, the sound is chosen randomly
  115. from the available ones of the following files:
  116. * `foomod_foosound.ogg`
  117. * `foomod_foosound.0.ogg`
  118. * `foomod_foosound.1.ogg`
  119. * (...)
  120. * `foomod_foosound.9.ogg`
  121. Examples of sound parameter tables:
  122. -- Play locationless
  123. {
  124. gain = 1.0, -- default
  125. }
  126. -- Play locationless, looped
  127. {
  128. gain = 1.0, -- default
  129. loop = true,
  130. }
  131. -- Play in a location
  132. {
  133. pos = {x = 1, y = 2, z = 3},
  134. gain = 1.0, -- default
  135. }
  136. -- Play connected to an object, looped
  137. {
  138. object = <an ObjectRef>,
  139. gain = 1.0, -- default
  140. loop = true,
  141. }
  142. Looped sounds must either be connected to an object or played locationless.
  143. ### SimpleSoundSpec
  144. * e.g. `""`
  145. * e.g. `"default_place_node"`
  146. * e.g. `{}`
  147. * e.g. `{name = "default_place_node"}`
  148. * e.g. `{name = "default_place_node", gain = 1.0}`
  149. Representations of simple things
  150. --------------------------------
  151. ### Position/vector
  152. {x=num, y=num, z=num}
  153. For helper functions see "Vector helpers".
  154. ### pointed_thing
  155. * `{type="nothing"}`
  156. * `{type="node", under=pos, above=pos}`
  157. * `{type="object", id=ObjectID}`
  158. Flag Specifier Format
  159. ---------------------
  160. Flags using the standardized flag specifier format can be specified in either of
  161. two ways, by string or table.
  162. The string format is a comma-delimited set of flag names; whitespace and
  163. unrecognized flag fields are ignored. Specifying a flag in the string sets the
  164. flag, and specifying a flag prefixed by the string `"no"` explicitly
  165. clears the flag from whatever the default may be.
  166. In addition to the standard string flag format, the schematic flags field can
  167. also be a table of flag names to boolean values representing whether or not the
  168. flag is set. Additionally, if a field with the flag name prefixed with `"no"`
  169. is present, mapped to a boolean of any value, the specified flag is unset.
  170. E.g. A flag field of value
  171. {place_center_x = true, place_center_y=false, place_center_z=true}
  172. is equivalent to
  173. {place_center_x = true, noplace_center_y=true, place_center_z=true}
  174. which is equivalent to
  175. "place_center_x, noplace_center_y, place_center_z"
  176. or even
  177. "place_center_x, place_center_z"
  178. since, by default, no schematic attributes are set.
  179. Formspec
  180. --------
  181. Formspec defines a menu. It is a string, with a somewhat strange format.
  182. Spaces and newlines can be inserted between the blocks, as is used in the
  183. examples.
  184. ### Examples
  185. #### Chest
  186. size[8,9]
  187. list[context;main;0,0;8,4;]
  188. list[current_player;main;0,5;8,4;]
  189. #### Furnace
  190. size[8,9]
  191. list[context;fuel;2,3;1,1;]
  192. list[context;src;2,1;1,1;]
  193. list[context;dst;5,1;2,2;]
  194. list[current_player;main;0,5;8,4;]
  195. #### Minecraft-like player inventory
  196. size[8,7.5]
  197. image[1,0.6;1,2;player.png]
  198. list[current_player;main;0,3.5;8,4;]
  199. list[current_player;craft;3,0;3,3;]
  200. list[current_player;craftpreview;7,1;1,1;]
  201. ### Elements
  202. #### `size[<W>,<H>,<fixed_size>]`
  203. * Define the size of the menu in inventory slots
  204. * `fixed_size`: `true`/`false` (optional)
  205. * deprecated: `invsize[<W>,<H>;]`
  206. #### `container[<X>,<Y>]`
  207. * Start of a container block, moves all physical elements in the container by (X, Y)
  208. * Must have matching container_end
  209. * Containers can be nested, in which case the offsets are added
  210. (child containers are relative to parent containers)
  211. #### `container_end[]`
  212. * End of a container, following elements are no longer relative to this container
  213. #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]`
  214. * Show an inventory list
  215. #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
  216. * Show an inventory list
  217. #### `listring[<inventory location>;<list name>]`
  218. * Allows to create a ring of inventory lists
  219. * Shift-clicking on items in one element of the ring
  220. will send them to the next inventory list inside the ring
  221. * The first occurrence of an element inside the ring will
  222. determine the inventory where items will be sent to
  223. #### `listring[]`
  224. * Shorthand for doing `listring[<inventory location>;<list name>]`
  225. for the last two inventory lists added by list[...]
  226. #### `listcolors[<slot_bg_normal>;<slot_bg_hover>]`
  227. * Sets background color of slots as `ColorString`
  228. * Sets background color of slots on mouse hovering
  229. #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>]`
  230. * Sets background color of slots as `ColorString`
  231. * Sets background color of slots on mouse hovering
  232. * Sets color of slots border
  233. #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<tooltip_fontcolor>]`
  234. * Sets background color of slots as `ColorString`
  235. * Sets background color of slots on mouse hovering
  236. * Sets color of slots border
  237. * Sets default background color of tooltips
  238. * Sets default font color of tooltips
  239. #### `tooltip[<gui_element_name>;<tooltip_text>;<bgcolor>,<fontcolor>]`
  240. * Adds tooltip for an element
  241. * `<bgcolor>` tooltip background color as `ColorString` (optional)
  242. * `<fontcolor>` tooltip font color as `ColorString` (optional)
  243. #### `image[<X>,<Y>;<W>,<H>;<texture name>]`
  244. * Show an image
  245. * Position and size units are inventory slots
  246. #### `item_image[<X>,<Y>;<W>,<H>;<item name>]`
  247. * Show an inventory image of registered item/node
  248. * Position and size units are inventory slots
  249. #### `bgcolor[<color>;<fullscreen>]`
  250. * Sets background color of formspec as `ColorString`
  251. * If `true`, the background color is drawn fullscreen (does not effect the size of the formspec)
  252. #### `background[<X>,<Y>;<W>,<H>;<texture name>]`
  253. * Use a background. Inventory rectangles are not drawn then.
  254. * Position and size units are inventory slots
  255. * Example for formspec 8x4 in 16x resolution: image shall be sized
  256. 8 times 16px times 4 times 16px.
  257. #### `background[<X>,<Y>;<W>,<H>;<texture name>;<auto_clip>]`
  258. * Use a background. Inventory rectangles are not drawn then.
  259. * Position and size units are inventory slots
  260. * Example for formspec 8x4 in 16x resolution:
  261. image shall be sized 8 times 16px times 4 times 16px
  262. * If `true` the background is clipped to formspec size
  263. (`x` and `y` are used as offset values, `w` and `h` are ignored)
  264. #### `pwdfield[<X>,<Y>;<W>,<H>;<name>;<label>]`
  265. * Textual password style field; will be sent to server when a button is clicked
  266. * When enter is pressed in field, fields.key_enter_field will be sent with the name
  267. of this field.
  268. * `x` and `y` position the field relative to the top left of the menu
  269. * `w` and `h` are the size of the field
  270. * Fields are a set height, but will be vertically centred on `h`
  271. * Position and size units are inventory slots
  272. * `name` is the name of the field as returned in fields to `on_receive_fields`
  273. * `label`, if not blank, will be text printed on the top left above the field
  274. * See field_close_on_enter to stop enter closing the formspec
  275. #### `field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
  276. * Textual field; will be sent to server when a button is clicked
  277. * When enter is pressed in field, fields.key_enter_field will be sent with the name
  278. of this field.
  279. * `x` and `y` position the field relative to the top left of the menu
  280. * `w` and `h` are the size of the field
  281. * Fields are a set height, but will be vertically centred on `h`
  282. * Position and size units are inventory slots
  283. * `name` is the name of the field as returned in fields to `on_receive_fields`
  284. * `label`, if not blank, will be text printed on the top left above the field
  285. * `default` is the default value of the field
  286. * `default` may contain variable references such as `${text}'` which
  287. will fill the value from the metadata value `text`
  288. * **Note**: no extra text or more than a single variable is supported ATM.
  289. * See field_close_on_enter to stop enter closing the formspec
  290. #### `field[<name>;<label>;<default>]`
  291. * As above, but without position/size units
  292. * When enter is pressed in field, fields.key_enter_field will be sent with the name
  293. of this field.
  294. * Special field for creating simple forms, such as sign text input
  295. * Must be used without a `size[]` element
  296. * A "Proceed" button will be added automatically
  297. * See field_close_on_enter to stop enter closing the formspec
  298. #### `field_close_on_enter[<name>;<close_on_enter>]`
  299. * <name> is the name of the field
  300. * if <close_on_enter> is false, pressing enter in the field will submit the form but not close it
  301. * defaults to true when not specified (ie: no tag for a field)
  302. #### `textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
  303. * Same as fields above, but with multi-line input
  304. #### `label[<X>,<Y>;<label>]`
  305. * `x` and `y` work as per field
  306. * `label` is the text on the label
  307. * Position and size units are inventory slots
  308. #### `vertlabel[<X>,<Y>;<label>]`
  309. * Textual label drawn vertically
  310. * `x` and `y` work as per field
  311. * `label` is the text on the label
  312. * Position and size units are inventory slots
  313. #### `button[<X>,<Y>;<W>,<H>;<name>;<label>]`
  314. * Clickable button. When clicked, fields will be sent.
  315. * `x`, `y` and `name` work as per field
  316. * `w` and `h` are the size of the button
  317. * Fixed button height. It will be vertically centred on `h`
  318. * `label` is the text on the button
  319. * Position and size units are inventory slots
  320. #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
  321. * `x`, `y`, `w`, `h`, and `name` work as per button
  322. * `texture name` is the filename of an image
  323. * Position and size units are inventory slots
  324. #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]`
  325. * `x`, `y`, `w`, `h`, and `name` work as per button
  326. * `texture name` is the filename of an image
  327. * Position and size units are inventory slots
  328. * `noclip=true` means the image button doesn't need to be within specified formsize
  329. * `drawborder`: draw button border or not
  330. * `pressed texture name` is the filename of an image on pressed state
  331. #### `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
  332. * `x`, `y`, `w`, `h`, `name` and `label` work as per button
  333. * `item name` is the registered name of an item/node,
  334. tooltip will be made out of its description
  335. to override it use tooltip element
  336. * Position and size units are inventory slots
  337. #### `button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]`
  338. * When clicked, fields will be sent and the form will quit.
  339. #### `image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
  340. * When clicked, fields will be sent and the form will quit.
  341. #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>]`
  342. * Scrollable item list showing arbitrary text elements
  343. * `x` and `y` position the itemlist relative to the top left of the menu
  344. * `w` and `h` are the size of the itemlist
  345. * `name` fieldname sent to server on doubleclick value is current selected element
  346. * `listelements` can be prepended by #color in hexadecimal format RRGGBB (only),
  347. * if you want a listelement to start with "#" write "##".
  348. #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>;<selected idx>;<transparent>]`
  349. * Scrollable itemlist showing arbitrary text elements
  350. * `x` and `y` position the item list relative to the top left of the menu
  351. * `w` and `h` are the size of the item list
  352. * `name` fieldname sent to server on doubleclick value is current selected element
  353. * `listelements` can be prepended by #RRGGBB (only) in hexadecimal format
  354. * if you want a listelement to start with "#" write "##"
  355. * Index to be selected within textlist
  356. * `true`/`false`: draw transparent background
  357. * See also `minetest.explode_textlist_event` (main menu: `engine.explode_textlist_event`)
  358. #### `tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
  359. * Show a tab**header** at specific position (ignores formsize)
  360. * `x` and `y` position the itemlist relative to the top left of the menu
  361. * `name` fieldname data is transferred to Lua
  362. * `caption 1`...: name shown on top of tab
  363. * `current_tab`: index of selected tab 1...
  364. * `transparent` (optional): show transparent
  365. * `draw_border` (optional): draw border
  366. #### `box[<X>,<Y>;<W>,<H>;<color>]`
  367. * Simple colored semitransparent box
  368. * `x` and `y` position the box relative to the top left of the menu
  369. * `w` and `h` are the size of box
  370. * `color` is color specified as a `ColorString`
  371. #### `dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]`
  372. * Show a dropdown field
  373. * **Important note**: There are two different operation modes:
  374. 1. handle directly on change (only changed dropdown is submitted)
  375. 2. read the value on pressing a button (all dropdown values are available)
  376. * `x` and `y` position of dropdown
  377. * Width of dropdown
  378. * Fieldname data is transferred to Lua
  379. * Items to be shown in dropdown
  380. * Index of currently selected dropdown item
  381. #### `checkbox[<X>,<Y>;<name>;<label>;<selected>]`
  382. * Show a checkbox
  383. * `x` and `y`: position of checkbox
  384. * `name` fieldname data is transferred to Lua
  385. * `label` to be shown left of checkbox
  386. * `selected` (optional): `true`/`false`
  387. #### `scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]`
  388. * Show a scrollbar
  389. * There are two ways to use it:
  390. 1. handle the changed event (only changed scrollbar is available)
  391. 2. read the value on pressing a button (all scrollbars are available)
  392. * `x` and `y`: position of trackbar
  393. * `w` and `h`: width and height
  394. * `orientation`: `vertical`/`horizontal`
  395. * Fieldname data is transferred to Lua
  396. * Value this trackbar is set to (`0`-`1000`)
  397. * See also `minetest.explode_scrollbar_event` (main menu: `engine.explode_scrollbar_event`)
  398. #### `table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]`
  399. * Show scrollable table using options defined by the previous `tableoptions[]`
  400. * Displays cells as defined by the previous `tablecolumns[]`
  401. * `x` and `y`: position the itemlist relative to the top left of the menu
  402. * `w` and `h` are the size of the itemlist
  403. * `name`: fieldname sent to server on row select or doubleclick
  404. * `cell 1`...`cell n`: cell contents given in row-major order
  405. * `selected idx`: index of row to be selected within table (first row = `1`)
  406. * See also `minetest.explode_table_event` (main menu: `engine.explode_table_event`)
  407. #### `tableoptions[<opt 1>;<opt 2>;...]`
  408. * Sets options for `table[]`
  409. * `color=#RRGGBB`
  410. * default text color (`ColorString`), defaults to `#FFFFFF`
  411. * `background=#RRGGBB`
  412. * table background color (`ColorString`), defaults to `#000000`
  413. * `border=<true/false>`
  414. * should the table be drawn with a border? (default: `true`)
  415. * `highlight=#RRGGBB`
  416. * highlight background color (`ColorString`), defaults to `#466432`
  417. * `highlight_text=#RRGGBB`
  418. * highlight text color (`ColorString`), defaults to `#FFFFFF`
  419. * `opendepth=<value>`
  420. * all subtrees up to `depth < value` are open (default value = `0`)
  421. * only useful when there is a column of type "tree"
  422. #### `tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]`
  423. * Sets columns for `table[]`
  424. * Types: `text`, `image`, `color`, `indent`, `tree`
  425. * `text`: show cell contents as text
  426. * `image`: cell contents are an image index, use column options to define images
  427. * `color`: cell contents are a ColorString and define color of following cell
  428. * `indent`: cell contents are a number and define indentation of following cell
  429. * `tree`: same as indent, but user can open and close subtrees (treeview-like)
  430. * Column options:
  431. * `align=<value>`
  432. * for `text` and `image`: content alignment within cells.
  433. Available values: `left` (default), `center`, `right`, `inline`
  434. * `width=<value>`
  435. * for `text` and `image`: minimum width in em (default: `0`)
  436. * for `indent` and `tree`: indent width in em (default: `1.5`)
  437. * `padding=<value>`: padding left of the column, in em (default `0.5`).
  438. Exception: defaults to 0 for indent columns
  439. * `tooltip=<value>`: tooltip text (default: empty)
  440. * `image` column options:
  441. * `0=<value>` sets image for image index 0
  442. * `1=<value>` sets image for image index 1
  443. * `2=<value>` sets image for image index 2
  444. * and so on; defined indices need not be contiguous empty or
  445. non-numeric cells are treated as `0`.
  446. * `color` column options:
  447. * `span=<value>`: number of following columns to affect (default: infinite)
  448. **Note**: do _not_ use a element name starting with `key_`; those names are reserved to
  449. pass key press events to formspec!
  450. Spatial Vectors
  451. ---------------
  452. * `vector.new(a[, b, c])`: returns a vector:
  453. * A copy of `a` if `a` is a vector.
  454. * `{x = a, y = b, z = c}`, if all `a, b, c` are defined
  455. * `vector.direction(p1, p2)`: returns a vector
  456. * `vector.distance(p1, p2)`: returns a number
  457. * `vector.length(v)`: returns a number
  458. * `vector.normalize(v)`: returns a vector
  459. * `vector.floor(v)`: returns a vector, each dimension rounded down
  460. * `vector.round(v)`: returns a vector, each dimension rounded to nearest int
  461. * `vector.apply(v, func)`: returns a vector
  462. * `vector.equals(v1, v2)`: returns a boolean
  463. For the following functions `x` can be either a vector or a number:
  464. * `vector.add(v, x)`: returns a vector
  465. * `vector.subtract(v, x)`: returns a vector
  466. * `vector.multiply(v, x)`: returns a scaled vector or Schur product
  467. * `vector.divide(v, x)`: returns a scaled vector or Schur quotient
  468. Helper functions
  469. ----------------
  470. * `dump2(obj, name="_", dumped={})`
  471. * Return object serialized as a string, handles reference loops
  472. * `dump(obj, dumped={})`
  473. * Return object serialized as a string
  474. * `math.hypot(x, y)`
  475. * Get the hypotenuse of a triangle with legs x and y.
  476. Useful for distance calculation.
  477. * `math.sign(x, tolerance)`
  478. * Get the sign of a number.
  479. Optional: Also returns `0` when the absolute value is within the tolerance (default: `0`)
  480. * `string.split(str, separator=",", include_empty=false, max_splits=-1, sep_is_pattern=false)`
  481. * If `max_splits` is negative, do not limit splits.
  482. * `sep_is_pattern` specifies if separator is a plain string or a pattern (regex).
  483. * e.g. `string:split("a,b", ",") == {"a","b"}`
  484. * `string:trim()`
  485. * e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"`
  486. * `minetest.wrap_text(str, limit)`: returns a string
  487. * Adds new lines to the string to keep it within the specified character limit
  488. * limit: Maximal amount of characters in one line
  489. * `minetest.pos_to_string({x=X,y=Y,z=Z}, decimal_places))`: returns string `"(X,Y,Z)"`
  490. * Convert position to a printable string
  491. Optional: 'decimal_places' will round the x, y and z of the pos to the given decimal place.
  492. * `minetest.string_to_pos(string)`: returns a position
  493. * Same but in reverse. Returns `nil` if the string can't be parsed to a position.
  494. * `minetest.string_to_area("(X1, Y1, Z1) (X2, Y2, Z2)")`: returns two positions
  495. * Converts a string representing an area box into two positions
  496. * `minetest.is_yes(arg)`
  497. * returns whether `arg` can be interpreted as yes
  498. * `minetest.is_nan(arg)`
  499. * returns true true when the passed number represents NaN.
  500. * `table.copy(table)`: returns a table
  501. * returns a deep copy of `table`
  502. Minetest namespace reference
  503. ------------------------------
  504. ### Utilities
  505. * `minetest.get_current_modname()`: returns the currently loading mod's name, when we are loading a mod
  506. * `minetest.get_modpath(modname)`: returns virtual path of given mod including
  507. the trailing separator. This is useful to load additional Lua files
  508. contained in your mod:
  509. e.g. `dofile(minetest.get_modpath(minetest.get_current_modname()) .. "stuff.lua")`
  510. * `minetest.get_language()`: returns two strings
  511. * the current gettext locale
  512. * the current language code (the same as used for client-side translations)
  513. * `minetest.get_version()`: returns a table containing components of the
  514. engine version. Components:
  515. * `project`: Name of the project, eg, "Minetest"
  516. * `string`: Simple version, eg, "1.2.3-dev"
  517. * `hash`: Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty"
  518. Use this for informational purposes only. The information in the returned
  519. table does not represent the capabilities of the engine, nor is it
  520. reliable or verifiable. Compatible forks will have a different name and
  521. version entirely. To check for the presence of engine features, test
  522. whether the functions exported by the wanted features exist. For example:
  523. `if minetest.check_for_falling then ... end`.
  524. * `minetest.sha1(data, [raw])`: returns the sha1 hash of data
  525. * `data`: string of data to hash
  526. * `raw`: return raw bytes instead of hex digits, default: false
  527. * `minetest.get_csm_restrictions()`: returns a table of `Flags` indicating the
  528. restrictions applied to the current mod.
  529. * If a flag in this table is set to true, the feature is RESTRICTED.
  530. * Possible flags: `load_client_mods`, `chat_messages`, `read_itemdefs`,
  531. `read_nodedefs`, `lookup_nodes`, `read_playerinfo`
  532. ### Logging
  533. * `minetest.debug(...)`
  534. * Equivalent to `minetest.log(table.concat({...}, "\t"))`
  535. * `minetest.log([level,] text)`
  536. * `level` is one of `"none"`, `"error"`, `"warning"`, `"action"`,
  537. `"info"`, or `"verbose"`. Default is `"none"`.
  538. ### Global callback registration functions
  539. Call these functions only at load time!
  540. * `minetest.register_globalstep(function(dtime))`
  541. * Called every client environment step, usually interval of 0.1s
  542. * `minetest.register_on_mods_loaded(function())`
  543. * Called just after mods have finished loading.
  544. * `minetest.register_on_shutdown(function())`
  545. * Called before client shutdown
  546. * **Warning**: If the client terminates abnormally (i.e. crashes), the registered
  547. callbacks **will likely not be run**. Data should be saved at
  548. semi-frequent intervals as well as on server shutdown.
  549. * `minetest.register_on_receiving_chat_message(function(message))`
  550. * Called always when a client receive a message
  551. * Return `true` to mark the message as handled, which means that it will not be shown to chat
  552. * `minetest.register_on_sending_chat_message(function(message))`
  553. * Called always when a client send a message from chat
  554. * Return `true` to mark the message as handled, which means that it will not be sent to server
  555. * `minetest.register_chatcommand(cmd, chatcommand definition)`
  556. * Adds definition to minetest.registered_chatcommands
  557. * `minetest.unregister_chatcommand(name)`
  558. * Unregisters a chatcommands registered with register_chatcommand.
  559. * `minetest.register_on_death(function())`
  560. * Called when the local player dies
  561. * `minetest.register_on_hp_modification(function(hp))`
  562. * Called when server modified player's HP
  563. * `minetest.register_on_damage_taken(function(hp))`
  564. * Called when the local player take damages
  565. * `minetest.register_on_formspec_input(function(formname, fields))`
  566. * Called when a button is pressed in the local player's inventory form
  567. * Newest functions are called first
  568. * If function returns `true`, remaining functions are not called
  569. * `minetest.register_on_dignode(function(pos, node))`
  570. * Called when the local player digs a node
  571. * Newest functions are called first
  572. * If any function returns true, the node isn't dug
  573. * `minetest.register_on_punchnode(function(pos, node))`
  574. * Called when the local player punches a node
  575. * Newest functions are called first
  576. * If any function returns true, the punch is ignored
  577. * `minetest.register_on_placenode(function(pointed_thing, node))`
  578. * Called when a node has been placed
  579. * `minetest.register_on_item_use(function(item, pointed_thing))`
  580. * Called when the local player uses an item.
  581. * Newest functions are called first.
  582. * If any function returns true, the item use is not sent to server.
  583. * `minetest.register_on_modchannel_message(function(channel_name, sender, message))`
  584. * Called when an incoming mod channel message is received
  585. * You must have joined some channels before, and server must acknowledge the
  586. join request.
  587. * If message comes from a server mod, `sender` field is an empty string.
  588. * `minetest.register_on_modchannel_signal(function(channel_name, signal))`
  589. * Called when a valid incoming mod channel signal is received
  590. * Signal id permit to react to server mod channel events
  591. * Possible values are:
  592. 0: join_ok
  593. 1: join_failed
  594. 2: leave_ok
  595. 3: leave_failed
  596. 4: event_on_not_joined_channel
  597. 5: state_changed
  598. * `minetest.register_on_inventory_open(function(inventory))`
  599. * Called when the local player open inventory
  600. * Newest functions are called first
  601. * If any function returns true, inventory doesn't open
  602. ### Sounds
  603. * `minetest.sound_play(spec, parameters)`: returns a handle
  604. * `spec` is a `SimpleSoundSpec`
  605. * `parameters` is a sound parameter table
  606. * `minetest.sound_stop(handle)`
  607. ### Timing
  608. * `minetest.after(time, func, ...)`
  609. * Call the function `func` after `time` seconds, may be fractional
  610. * Optional: Variable number of arguments that are passed to `func`
  611. * `minetest.get_us_time()`
  612. * Returns time with microsecond precision. May not return wall time.
  613. * `minetest.get_timeofday()`
  614. * Returns the time of day: `0` for midnight, `0.5` for midday
  615. ### Map
  616. * `minetest.get_node_or_nil(pos)`
  617. * Returns the node at the given position as table in the format
  618. `{name="node_name", param1=0, param2=0}`, returns `nil`
  619. for unloaded areas or flavor limited areas.
  620. * `minetest.get_node_light(pos, timeofday)`
  621. * Gets the light value at the given position. Note that the light value
  622. "inside" the node at the given position is returned, so you usually want
  623. to get the light value of a neighbor.
  624. * `pos`: The position where to measure the light.
  625. * `timeofday`: `nil` for current time, `0` for night, `0.5` for day
  626. * Returns a number between `0` and `15` or `nil`
  627. * `minetest.find_node_near(pos, radius, nodenames, [search_center])`: returns pos or `nil`
  628. * `radius`: using a maximum metric
  629. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
  630. * `search_center` is an optional boolean (default: `false`)
  631. If true `pos` is also checked for the nodes
  632. * `minetest.find_nodes_in_area(pos1, pos2, nodenames)`: returns a list of
  633. positions.
  634. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
  635. * First return value: Table with all node positions
  636. * Second return value: Table with the count of each node with the node name
  637. as index.
  638. * Area volume is limited to 4,096,000 nodes
  639. * `minetest.find_nodes_in_area_under_air(pos1, pos2, nodenames)`: returns a
  640. list of positions.
  641. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
  642. * Return value: Table with all node positions with a node air above
  643. * Area volume is limited to 4,096,000 nodes
  644. * `minetest.line_of_sight(pos1, pos2)`: returns `boolean, pos`
  645. * Checks if there is anything other than air between pos1 and pos2.
  646. * Returns false if something is blocking the sight.
  647. * Returns the position of the blocking node when `false`
  648. * `pos1`: First position
  649. * `pos2`: Second position
  650. * `minetest.raycast(pos1, pos2, objects, liquids)`: returns `Raycast`
  651. * Creates a `Raycast` object.
  652. * `pos1`: start of the ray
  653. * `pos2`: end of the ray
  654. * `objects`: if false, only nodes will be returned. Default is `true`.
  655. * `liquids`: if false, liquid nodes won't be returned. Default is `false`.
  656. * `minetest.find_nodes_with_meta(pos1, pos2)`
  657. * Get a table of positions of nodes that have metadata within a region
  658. {pos1, pos2}.
  659. * `minetest.get_meta(pos)`
  660. * Get a `NodeMetaRef` at that position
  661. * `minetest.get_node_level(pos)`
  662. * get level of leveled node (water, snow)
  663. * `minetest.get_node_max_level(pos)`
  664. * get max available level for leveled node
  665. ### Player
  666. * `minetest.get_wielded_item()`
  667. * Returns the itemstack the local player is holding
  668. * `minetest.send_chat_message(message)`
  669. * Act as if `message` was typed by the player into the terminal.
  670. * `minetest.run_server_chatcommand(cmd, param)`
  671. * Alias for `minetest.send_chat_message("/" .. cmd .. " " .. param)`
  672. * `minetest.clear_out_chat_queue()`
  673. * Clears the out chat queue
  674. * `minetest.localplayer`
  675. * Reference to the LocalPlayer object. See [`LocalPlayer`](#localplayer) class reference for methods.
  676. ### Privileges
  677. * `minetest.get_privilege_list()`
  678. * Returns a list of privileges the current player has in the format `{priv1=true,...}`
  679. * `minetest.string_to_privs(str)`: returns `{priv1=true,...}`
  680. * `minetest.privs_to_string(privs)`: returns `"priv1,priv2,..."`
  681. * Convert between two privilege representations
  682. ### Client Environment
  683. * `minetest.get_player_names()`
  684. * Returns list of player names on server (nil if CSM_RF_READ_PLAYERINFO is enabled by server)
  685. * `minetest.disconnect()`
  686. * Disconnect from the server and exit to main menu.
  687. * Returns `false` if the client is already disconnecting otherwise returns `true`.
  688. * `minetest.get_server_info()`
  689. * Returns [server info](#server-info).
  690. * `minetest.send_respawn()`
  691. * Sends a respawn request to the server.
  692. ### Storage API
  693. * `minetest.get_mod_storage()`:
  694. * returns reference to mod private `StorageRef`
  695. * must be called during mod load time
  696. ### Mod channels
  697. ![Mod channels communication scheme](docs/mod channels.png)
  698. * `minetest.mod_channel_join(channel_name)`
  699. * Client joins channel `channel_name`, and creates it, if necessary. You
  700. should listen from incoming messages with `minetest.register_on_modchannel_message`
  701. call to receive incoming messages. Warning, this function is asynchronous.
  702. ### Particles
  703. * `minetest.add_particle(particle definition)`
  704. * `minetest.add_particlespawner(particlespawner definition)`
  705. * Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds
  706. * Returns an `id`, and -1 if adding didn't succeed
  707. * `minetest.delete_particlespawner(id)`
  708. * Delete `ParticleSpawner` with `id` (return value from `minetest.add_particlespawner`)
  709. ### Misc.
  710. * `minetest.parse_json(string[, nullvalue])`: returns something
  711. * Convert a string containing JSON data into the Lua equivalent
  712. * `nullvalue`: returned in place of the JSON null; defaults to `nil`
  713. * On success returns a table, a string, a number, a boolean or `nullvalue`
  714. * On failure outputs an error message and returns `nil`
  715. * Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}`
  716. * `minetest.write_json(data[, styled])`: returns a string or `nil` and an error message
  717. * Convert a Lua table into a JSON string
  718. * styled: Outputs in a human-readable format if this is set, defaults to false
  719. * Unserializable things like functions and userdata are saved as null.
  720. * **Warning**: JSON is more strict than the Lua table format.
  721. 1. You can only use strings and positive integers of at least one as keys.
  722. 2. You can not mix string and integer keys.
  723. This is due to the fact that JSON has two distinct array and object values.
  724. * Example: `write_json({10, {a = false}})`, returns `"[10, {\"a\": false}]"`
  725. * `minetest.serialize(table)`: returns a string
  726. * Convert a table containing tables, strings, numbers, booleans and `nil`s
  727. into string form readable by `minetest.deserialize`
  728. * Example: `serialize({foo='bar'})`, returns `'return { ["foo"] = "bar" }'`
  729. * `minetest.deserialize(string)`: returns a table
  730. * Convert a string returned by `minetest.deserialize` into a table
  731. * `string` is loaded in an empty sandbox environment.
  732. * Will load functions, but they cannot access the global environment.
  733. * Example: `deserialize('return { ["foo"] = "bar" }')`, returns `{foo='bar'}`
  734. * Example: `deserialize('print("foo")')`, returns `nil` (function call fails)
  735. * `error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)`
  736. * `minetest.compress(data, method, ...)`: returns `compressed_data`
  737. * Compress a string of data.
  738. * `method` is a string identifying the compression method to be used.
  739. * Supported compression methods:
  740. * Deflate (zlib): `"deflate"`
  741. * `...` indicates method-specific arguments. Currently defined arguments are:
  742. * Deflate: `level` - Compression level, `0`-`9` or `nil`.
  743. * `minetest.decompress(compressed_data, method, ...)`: returns data
  744. * Decompress a string of data (using ZLib).
  745. * See documentation on `minetest.compress()` for supported compression methods.
  746. * currently supported.
  747. * `...` indicates method-specific arguments. Currently, no methods use this.
  748. * `minetest.rgba(red, green, blue[, alpha])`: returns a string
  749. * Each argument is a 8 Bit unsigned integer
  750. * Returns the ColorString from rgb or rgba values
  751. * Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
  752. * `minetest.encode_base64(string)`: returns string encoded in base64
  753. * Encodes a string in base64.
  754. * `minetest.decode_base64(string)`: returns string
  755. * Decodes a string encoded in base64.
  756. * `minetest.gettext(string)` : returns string
  757. * look up the translation of a string in the gettext message catalog
  758. * `fgettext_ne(string, ...)`
  759. * call minetest.gettext(string), replace "$1"..."$9" with the given
  760. extra arguments and return the result
  761. * `fgettext(string, ...)` : returns string
  762. * same as fgettext_ne(), but calls minetest.formspec_escape before returning result
  763. * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
  764. * returns the exact position on the surface of a pointed node
  765. * `minetest.global_exists(name)`
  766. * Checks if a global variable has been set, without triggering a warning.
  767. ### UI
  768. * `minetest.ui.minimap`
  769. * Reference to the minimap object. See [`Minimap`](#minimap) class reference for methods.
  770. * If client disabled minimap (using enable_minimap setting) this reference will be nil.
  771. * `minetest.camera`
  772. * Reference to the camera object. See [`Camera`](#camera) class reference for methods.
  773. * `minetest.show_formspec(formname, formspec)` : returns true on success
  774. * Shows a formspec to the player
  775. * `minetest.display_chat_message(message)` returns true on success
  776. * Shows a chat message to the current player.
  777. Class reference
  778. ---------------
  779. ### ModChannel
  780. An interface to use mod channels on client and server
  781. #### Methods
  782. * `leave()`: leave the mod channel.
  783. * Client leaves channel `channel_name`.
  784. * No more incoming or outgoing messages can be sent to this channel from client mods.
  785. * This invalidate all future object usage
  786. * Ensure your set mod_channel to nil after that to free Lua resources
  787. * `is_writeable()`: returns true if channel is writable and mod can send over it.
  788. * `send_all(message)`: Send `message` though the mod channel.
  789. * If mod channel is not writable or invalid, message will be dropped.
  790. * Message size is limited to 65535 characters by protocol.
  791. ### Minimap
  792. An interface to manipulate minimap on client UI
  793. #### Methods
  794. * `show()`: shows the minimap (if not disabled by server)
  795. * `hide()`: hides the minimap
  796. * `set_pos(pos)`: sets the minimap position on screen
  797. * `get_pos()`: returns the minimap current position
  798. * `set_angle(deg)`: sets the minimap angle in degrees
  799. * `get_angle()`: returns the current minimap angle in degrees
  800. * `set_mode(mode)`: sets the minimap mode (0 to 6)
  801. * `get_mode()`: returns the current minimap mode
  802. * `set_shape(shape)`: Sets the minimap shape. (0 = square, 1 = round)
  803. * `get_shape()`: Gets the minimap shape. (0 = square, 1 = round)
  804. ### Camera
  805. An interface to get or set information about the camera and camera-node.
  806. Please do not try to access the reference until the camera is initialized, otherwise the reference will be nil.
  807. #### Methods
  808. * `set_camera_mode(mode)`
  809. * Pass `0` for first-person, `1` for third person, and `2` for third person front
  810. * `get_camera_mode()`
  811. * Returns 0, 1, or 2 as described above
  812. * `get_fov()`
  813. * Returns:
  814. ```lua
  815. {
  816. x = number,
  817. y = number,
  818. max = number,
  819. actual = number
  820. }
  821. ```
  822. * `get_pos()`
  823. * Returns position of camera with view bobbing
  824. * `get_offset()`
  825. * Returns eye offset vector
  826. * `get_look_dir()`
  827. * Returns eye direction unit vector
  828. * `get_look_vertical()`
  829. * Returns pitch in radians
  830. * `get_look_horizontal()`
  831. * Returns yaw in radians
  832. * `get_aspect_ratio()`
  833. * Returns aspect ratio of screen
  834. ### LocalPlayer
  835. An interface to retrieve information about the player.
  836. Methods:
  837. * `get_pos()`
  838. * returns current player current position
  839. * `get_velocity()`
  840. * returns player speed vector
  841. * `get_hp()`
  842. * returns player HP
  843. * `get_name()`
  844. * returns player name
  845. * `is_attached()`
  846. * returns true if player is attached
  847. * `is_touching_ground()`
  848. * returns true if player touching ground
  849. * `is_in_liquid()`
  850. * returns true if player is in a liquid (This oscillates so that the player jumps a bit above the surface)
  851. * `is_in_liquid_stable()`
  852. * returns true if player is in a stable liquid (This is more stable and defines the maximum speed of the player)
  853. * `get_liquid_viscosity()`
  854. * returns liquid viscosity (Gets the viscosity of liquid to calculate friction)
  855. * `is_climbing()`
  856. * returns true if player is climbing
  857. * `swimming_vertical()`
  858. * returns true if player is swimming in vertical
  859. * `get_physics_override()`
  860. * returns:
  861. ```lua
  862. {
  863. speed = float,
  864. jump = float,
  865. gravity = float,
  866. sneak = boolean,
  867. sneak_glitch = boolean
  868. }
  869. ```
  870. * `get_override_pos()`
  871. * returns override position
  872. * `get_last_pos()`
  873. * returns last player position before the current client step
  874. * `get_last_velocity()`
  875. * returns last player speed
  876. * `get_breath()`
  877. * returns the player's breath
  878. * `get_movement_acceleration()`
  879. * returns acceleration of the player in different environments:
  880. ```lua
  881. {
  882. fast = float,
  883. air = float,
  884. default = float,
  885. }
  886. ```
  887. * `get_movement_speed()`
  888. * returns player's speed in different environments:
  889. ```lua
  890. {
  891. walk = float,
  892. jump = float,
  893. crouch = float,
  894. fast = float,
  895. climb = float,
  896. }
  897. ```
  898. * `get_movement()`
  899. * returns player's movement in different environments:
  900. ```lua
  901. {
  902. liquid_fluidity = float,
  903. liquid_sink = float,
  904. liquid_fluidity_smooth = float,
  905. gravity = float,
  906. }
  907. ```
  908. * `get_last_look_horizontal()`:
  909. * returns last look horizontal angle
  910. * `get_last_look_vertical()`:
  911. * returns last look vertical angle
  912. * `get_key_pressed()`:
  913. * returns last key typed by the player
  914. * `hud_add(definition)`
  915. * add a HUD element described by HUD def, returns ID number on success and `nil` on failure.
  916. * See [`HUD definition`](#hud-definition-hud_add-hud_get)
  917. * `hud_get(id)`
  918. * returns the [`definition`](#hud-definition-hud_add-hud_get) of the HUD with that ID number or `nil`, if non-existent.
  919. * `hud_remove(id)`
  920. * remove the HUD element of the specified id, returns `true` on success
  921. * `hud_change(id, stat, value)`
  922. * change a value of a previously added HUD element
  923. * element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir`
  924. * Returns `true` on success, otherwise returns `nil`
  925. ### Settings
  926. An interface to read config files in the format of `minetest.conf`.
  927. It can be created via `Settings(filename)`.
  928. #### Methods
  929. * `get(key)`: returns a value
  930. * `get_bool(key)`: returns a boolean
  931. * `set(key, value)`
  932. * `remove(key)`: returns a boolean (`true` for success)
  933. * `get_names()`: returns `{key1,...}`
  934. * `write()`: returns a boolean (`true` for success)
  935. * write changes to file
  936. * `to_table()`: returns `{[key1]=value1,...}`
  937. ### NodeMetaRef
  938. Node metadata: reference extra data and functionality stored in a node.
  939. Can be obtained via `minetest.get_meta(pos)`.
  940. #### Methods
  941. * `get_string(name)`
  942. * `get_int(name)`
  943. * `get_float(name)`
  944. * `to_table()`: returns `nil` or a table with keys:
  945. * `fields`: key-value storage
  946. * `inventory`: `{list1 = {}, ...}}`
  947. ### `Raycast`
  948. A raycast on the map. It works with selection boxes.
  949. Can be used as an iterator in a for loop as:
  950. local ray = Raycast(...)
  951. for pointed_thing in ray do
  952. ...
  953. end
  954. The map is loaded as the ray advances. If the map is modified after the
  955. `Raycast` is created, the changes may or may not have an effect on the object.
  956. It can be created via `Raycast(pos1, pos2, objects, liquids)` or
  957. `minetest.raycast(pos1, pos2, objects, liquids)` where:
  958. * `pos1`: start of the ray
  959. * `pos2`: end of the ray
  960. * `objects`: if false, only nodes will be returned. Default is true.
  961. * `liquids`: if false, liquid nodes won't be returned. Default is false.
  962. #### Methods
  963. * `next()`: returns a `pointed_thing` with exact pointing location
  964. * Returns the next thing pointed by the ray or nil.
  965. -----------------
  966. ### Definitions
  967. * `minetest.get_node_def(nodename)`
  968. * Returns [node definition](#node-definition) table of `nodename`
  969. * `minetest.get_item_def(itemstring)`
  970. * Returns item definition table of `itemstring`
  971. #### Node Definition
  972. ```lua
  973. {
  974. has_on_construct = bool, -- Whether the node has the on_construct callback defined
  975. has_on_destruct = bool, -- Whether the node has the on_destruct callback defined
  976. has_after_destruct = bool, -- Whether the node has the after_destruct callback defined
  977. name = string, -- The name of the node e.g. "air", "default:dirt"
  978. groups = table, -- The groups of the node
  979. paramtype = string, -- Paramtype of the node
  980. paramtype2 = string, -- ParamType2 of the node
  981. drawtype = string, -- Drawtype of the node
  982. mesh = <string>, -- Mesh name if existant
  983. minimap_color = <Color>, -- Color of node on minimap *May not exist*
  984. visual_scale = number, -- Visual scale of node
  985. alpha = number, -- Alpha of the node. Only used for liquids
  986. color = <Color>, -- Color of node *May not exist*
  987. palette_name = <string>, -- Filename of palette *May not exist*
  988. palette = <{ -- List of colors
  989. Color,
  990. Color
  991. }>,
  992. waving = number, -- 0 of not waving, 1 if waving
  993. connect_sides = number, -- Used for connected nodes
  994. connects_to = { -- List of nodes to connect to
  995. "node1",
  996. "node2"
  997. },
  998. post_effect_color = Color, -- Color overlayed on the screen when the player is in the node
  999. leveled = number, -- Max level for node
  1000. sunlight_propogates = bool, -- Whether light passes through the block
  1001. light_source = number, -- Light emitted by the block
  1002. is_ground_content = bool, -- Whether caves should cut through the node
  1003. walkable = bool, -- Whether the player collides with the node
  1004. pointable = bool, -- Whether the player can select the node
  1005. diggable = bool, -- Whether the player can dig the node
  1006. climbable = bool, -- Whether the player can climb up the node
  1007. buildable_to = bool, -- Whether the player can replace the node by placing a node on it
  1008. rightclickable = bool, -- Whether the player can place nodes pointing at this node
  1009. damage_per_second = number, -- HP of damage per second when the player is in the node
  1010. liquid_type = <string>, -- A string containing "none", "flowing", or "source" *May not exist*
  1011. liquid_alternative_flowing = <string>, -- Alternative node for liquid *May not exist*
  1012. liquid_alternative_source = <string>, -- Alternative node for liquid *May not exist*
  1013. liquid_viscosity = <number>, -- How fast the liquid flows *May not exist*
  1014. liquid_renewable = <boolean>, -- Whether the liquid makes an infinite source *May not exist*
  1015. liquid_range = <number>, -- How far the liquid flows *May not exist*
  1016. drowning = bool, -- Whether the player will drown in the node
  1017. floodable = bool, -- Whether nodes will be replaced by liquids (flooded)
  1018. node_box = table, -- Nodebox to draw the node with
  1019. collision_box = table, -- Nodebox to set the collision area
  1020. selection_box = table, -- Nodebox to set the area selected by the player
  1021. sounds = { -- Table of sounds that the block makes
  1022. sound_footstep = SimpleSoundSpec,
  1023. sound_dig = SimpleSoundSpec,
  1024. sound_dug = SimpleSoundSpec
  1025. },
  1026. legacy_facedir_simple = bool, -- Whether to use old facedir
  1027. legacy_wallmounted = bool -- Whether to use old wallmounted
  1028. }
  1029. ```
  1030. #### Item Definition
  1031. ```lua
  1032. {
  1033. name = string, -- Name of the item e.g. "default:stone"
  1034. description = string, -- Description of the item e.g. "Stone"
  1035. type = string, -- Item type: "none", "node", "craftitem", "tool"
  1036. inventory_image = string, -- Image in the inventory
  1037. wield_image = string, -- Image in wieldmesh
  1038. palette_image = string, -- Image for palette
  1039. color = Color, -- Color for item
  1040. wield_scale = Vector, -- Wieldmesh scale
  1041. stack_max = number, -- Number of items stackable together
  1042. usable = bool, -- Has on_use callback defined
  1043. liquids_pointable = bool, -- Whether you can point at liquids with the item
  1044. tool_capabilities = <table>, -- If the item is a tool, tool capabilities of the item
  1045. groups = table, -- Groups of the item
  1046. sound_place = SimpleSoundSpec, -- Sound played when placed
  1047. sound_place_failed = SimpleSoundSpec, -- Sound played when placement failed
  1048. node_placement_prediction = string -- Node placed in client until server catches up
  1049. }
  1050. ```
  1051. -----------------
  1052. ### Chat command definition (`register_chatcommand`)
  1053. {
  1054. params = "<name> <privilege>", -- Short parameter description
  1055. description = "Remove privilege from player", -- Full description
  1056. func = function(param), -- Called when command is run.
  1057. -- Returns boolean success and text output.
  1058. }
  1059. ### Server info
  1060. ```lua
  1061. {
  1062. address = "minetest.example.org", -- The domain name/IP address of a remote server or "" for a local server.
  1063. ip = "203.0.113.156", -- The IP address of the server.
  1064. port = 30000, -- The port the client is connected to.
  1065. protocol_version = 30 -- Will not be accurate at start up as the client might not be connected to the server yet, in that case it will be 0.
  1066. }
  1067. ```
  1068. ### HUD Definition (`hud_add`, `hud_get`)
  1069. ```lua
  1070. {
  1071. hud_elem_type = "image", -- see HUD element types, default "text"
  1072. -- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
  1073. position = {x=0.5, y=0.5},
  1074. -- ^ Left corner position of element, default `{x=0,y=0}`.
  1075. name = "<name>", -- default ""
  1076. scale = {x=2, y=2}, -- default {x=0,y=0}
  1077. text = "<text>", -- default ""
  1078. number = 2, -- default 0
  1079. item = 3, -- default 0
  1080. -- ^ Selected item in inventory. 0 for no item selected.
  1081. direction = 0, -- default 0
  1082. -- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
  1083. alignment = {x=0, y=0}, -- default {x=0, y=0}
  1084. -- ^ See "HUD Element Types"
  1085. offset = {x=0, y=0}, -- default {x=0, y=0}
  1086. -- ^ See "HUD Element Types"
  1087. size = { x=100, y=100 }, -- default {x=0, y=0}
  1088. -- ^ Size of element in pixels
  1089. }
  1090. ```
  1091. Escape sequences
  1092. ----------------
  1093. Most text can contain escape sequences, that can for example color the text.
  1094. There are a few exceptions: tab headers, dropdowns and vertical labels can't.
  1095. The following functions provide escape sequences:
  1096. * `minetest.get_color_escape_sequence(color)`:
  1097. * `color` is a [ColorString](#colorstring)
  1098. * The escape sequence sets the text color to `color`
  1099. * `minetest.colorize(color, message)`:
  1100. * Equivalent to:
  1101. `minetest.get_color_escape_sequence(color) ..
  1102. message ..
  1103. minetest.get_color_escape_sequence("#ffffff")`
  1104. * `minetest.get_background_escape_sequence(color)`
  1105. * `color` is a [ColorString](#colorstring)
  1106. * The escape sequence sets the background of the whole text element to
  1107. `color`. Only defined for item descriptions and tooltips.
  1108. * `minetest.strip_foreground_colors(str)`
  1109. * Removes foreground colors added by `get_color_escape_sequence`.
  1110. * `minetest.strip_background_colors(str)`
  1111. * Removes background colors added by `get_background_escape_sequence`.
  1112. * `minetest.strip_colors(str)`
  1113. * Removes all color escape sequences.
  1114. `ColorString`
  1115. -------------
  1116. `#RGB` defines a color in hexadecimal format.
  1117. `#RGBA` defines a color in hexadecimal format and alpha channel.
  1118. `#RRGGBB` defines a color in hexadecimal format.
  1119. `#RRGGBBAA` defines a color in hexadecimal format and alpha channel.
  1120. Named colors are also supported and are equivalent to
  1121. [CSS Color Module Level 4](http://dev.w3.org/csswg/css-color/#named-colors).
  1122. To specify the value of the alpha channel, append `#AA` to the end of the color name
  1123. (e.g. `colorname#08`). For named colors the hexadecimal string representing the alpha
  1124. value must (always) be two hexadecimal digits.
  1125. `Color`
  1126. -------------
  1127. `{a = alpha, r = red, g = green, b = blue}` defines an ARGB8 color.
  1128. HUD element types
  1129. -----------------
  1130. The position field is used for all element types.
  1131. To account for differing resolutions, the position coordinates are the percentage
  1132. of the screen, ranging in value from `0` to `1`.
  1133. The name field is not yet used, but should contain a description of what the
  1134. HUD element represents. The direction field is the direction in which something
  1135. is drawn.
  1136. `0` draws from left to right, `1` draws from right to left, `2` draws from
  1137. top to bottom, and `3` draws from bottom to top.
  1138. The `alignment` field specifies how the item will be aligned. It ranges from `-1` to `1`,
  1139. with `0` being the center, `-1` is moved to the left/up, and `1` is to the right/down.
  1140. Fractional values can be used.
  1141. The `offset` field specifies a pixel offset from the position. Contrary to position,
  1142. the offset is not scaled to screen size. This allows for some precisely-positioned
  1143. items in the HUD.
  1144. **Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling factor!
  1145. Below are the specific uses for fields in each type; fields not listed for that type are ignored.
  1146. **Note**: Future revisions to the HUD API may be incompatible; the HUD API is still
  1147. in the experimental stages.
  1148. ### `image`
  1149. Displays an image on the HUD.
  1150. * `scale`: The scale of the image, with 1 being the original texture size.
  1151. Only the X coordinate scale is used (positive values).
  1152. Negative values represent that percentage of the screen it
  1153. should take; e.g. `x=-100` means 100% (width).
  1154. * `text`: The name of the texture that is displayed.
  1155. * `alignment`: The alignment of the image.
  1156. * `offset`: offset in pixels from position.
  1157. ### `text`
  1158. Displays text on the HUD.
  1159. * `scale`: Defines the bounding rectangle of the text.
  1160. A value such as `{x=100, y=100}` should work.
  1161. * `text`: The text to be displayed in the HUD element.
  1162. * `number`: An integer containing the RGB value of the color used to draw the text.
  1163. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
  1164. * `alignment`: The alignment of the text.
  1165. * `offset`: offset in pixels from position.
  1166. ### `statbar`
  1167. Displays a horizontal bar made up of half-images.
  1168. * `text`: The name of the texture that is used.
  1169. * `number`: The number of half-textures that are displayed.
  1170. If odd, will end with a vertically center-split texture.
  1171. * `direction`
  1172. * `offset`: offset in pixels from position.
  1173. * `size`: If used, will force full-image size to this value (override texture pack image size)
  1174. ### `inventory`
  1175. * `text`: The name of the inventory list to be displayed.
  1176. * `number`: Number of items in the inventory to be displayed.
  1177. * `item`: Position of item that is selected.
  1178. * `direction`
  1179. * `offset`: offset in pixels from position.
  1180. ### `waypoint`
  1181. Displays distance to selected world position.
  1182. * `name`: The name of the waypoint.
  1183. * `text`: Distance suffix. Can be blank.
  1184. * `number:` An integer containing the RGB value of the color used to draw the text.
  1185. * `world_pos`: World position of the waypoint.
  1186. ### Particle definition (`add_particle`)
  1187. {
  1188. pos = {x=0, y=0, z=0},
  1189. velocity = {x=0, y=0, z=0},
  1190. acceleration = {x=0, y=0, z=0},
  1191. -- ^ Spawn particle at pos with velocity and acceleration
  1192. expirationtime = 1,
  1193. -- ^ Disappears after expirationtime seconds
  1194. size = 1,
  1195. collisiondetection = false,
  1196. -- ^ collisiondetection: if true collides with physical objects
  1197. collision_removal = false,
  1198. -- ^ collision_removal: if true then particle is removed when it collides,
  1199. -- ^ requires collisiondetection = true to have any effect
  1200. vertical = false,
  1201. -- ^ vertical: if true faces player using y axis only
  1202. texture = "image.png",
  1203. -- ^ Uses texture (string)
  1204. animation = {Tile Animation definition},
  1205. -- ^ optional, specifies how to animate the particle texture
  1206. glow = 0
  1207. -- ^ optional, specify particle self-luminescence in darkness
  1208. }
  1209. ### `ParticleSpawner` definition (`add_particlespawner`)
  1210. {
  1211. amount = 1,
  1212. time = 1,
  1213. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  1214. minpos = {x=0, y=0, z=0},
  1215. maxpos = {x=0, y=0, z=0},
  1216. minvel = {x=0, y=0, z=0},
  1217. maxvel = {x=0, y=0, z=0},
  1218. minacc = {x=0, y=0, z=0},
  1219. maxacc = {x=0, y=0, z=0},
  1220. minexptime = 1,
  1221. maxexptime = 1,
  1222. minsize = 1,
  1223. maxsize = 1,
  1224. -- ^ The particle's properties are random values in between the bounds:
  1225. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  1226. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  1227. collisiondetection = false,
  1228. -- ^ collisiondetection: if true uses collision detection
  1229. collision_removal = false,
  1230. -- ^ collision_removal: if true then particle is removed when it collides,
  1231. -- ^ requires collisiondetection = true to have any effect
  1232. vertical = false,
  1233. -- ^ vertical: if true faces player using y axis only
  1234. texture = "image.png",
  1235. -- ^ Uses texture (string)
  1236. }