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