]> git.lizzy.rs Git - dragonfireclient.git/blob - doc/client_lua_api.txt
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / doc / client_lua_api.txt
1 Minetest Lua Client Modding API Reference 5.6.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, 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`: `<build directory>`
47     * `$path_share`: `<build directory>`
48 * `RUN_IN_PLACE=0`: (Linux release)
49     * `$path_share`:
50         * Linux: `/usr/share/minetest`
51         * Windows: `<install directory>/minetest-0.4.x`
52     * `$path_user`:
53         * Linux: `$HOME/.minetest`
54         * Windows: `C:/users/<user>/AppData/minetest` (maybe)
55
56 Mod load path
57 -------------
58 Generic:
59
60 * `$path_share/clientmods/`
61 * `$path_user/clientmods/` (User-installed mods)
62
63 In a run-in-place version (e.g. the distributed windows version):
64
65 * `minetest-0.4.x/clientmods/` (User-installed mods)
66
67 On an installed version on Linux:
68
69 * `/usr/share/minetest/clientmods/`
70 * `$HOME/.minetest/clientmods/` (User-installed mods)
71
72 Modpack support
73 ----------------
74
75 Mods can be put in a subdirectory, if the parent directory, which otherwise
76 should be a mod, contains a file named `modpack.conf`.
77 The file is a key-value store of modpack details.
78
79 * `name`: The modpack name.
80 * `description`: Description of mod to be shown in the Mods tab of the main
81                  menu.
82
83 Mod directory structure
84 ------------------------
85
86     clientmods
87     ├── modname
88     │   ├── mod.conf
89     |   ├── settingtypes.txt
90     │   ├── init.lua
91     └── another
92
93 ### `settingtypes.txt`
94
95 The format is documented in `builtin/settingtypes.txt`.
96 It is parsed by the main menu settings dialogue to list mod-specific
97 settings in the "Clientmods" category.
98
99 ### modname
100
101 The location of this directory.
102
103 ### mod.conf
104
105 An (optional) settings file that provides meta information about the mod.
106
107 * `name`: The mod name. Allows Minetest to determine the mod name even if the
108           folder is wrongly named.
109 * `description`: Description of mod to be shown in the Mods tab of the main
110                  menu.
111 * `depends`: A comma separated list of dependencies. These are mods that must be
112              loaded before this mod.
113 * `optional_depends`: A comma separated list of optional dependencies.
114                       Like a dependency, but no error if the mod doesn't exist.
115
116 ### `init.lua`
117
118 The main Lua script. Running this script should register everything it
119 wants to register. Subsequent execution depends on minetest calling the
120 registered callbacks.
121
122 **NOTE**: Client mods currently can't provide textures, sounds, or models by
123 themselves. Any media referenced in function calls must already be loaded
124 (provided by mods that exist on the server).
125
126 Naming convention for registered textual names
127 ----------------------------------------------
128 Registered names should generally be in this format:
129
130     "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
131
132 This is to prevent conflicting names from corrupting maps and is
133 enforced by the mod loader.
134
135 ### Example
136 In the mod `experimental`, there is the ideal item/node/entity name `tnt`.
137 So the name should be `experimental:tnt`.
138
139 Enforcement can be overridden by prefixing the name with `:`. This can
140 be used for overriding the registrations of some other mod.
141
142 Example: Any mod can redefine `experimental:tnt` by using the name
143
144     :experimental:tnt
145
146 when registering it.
147 (also that mod is required to have `experimental` as a dependency)
148
149 The `:` prefix can also be used for maintaining backwards compatibility.
150
151 Sounds
152 ------
153 **NOTE: Connecting sounds to objects is not implemented.**
154
155 Only Ogg Vorbis files are supported.
156
157 For positional playing of sounds, only single-channel (mono) files are
158 supported. Otherwise OpenAL will play them non-positionally.
159
160 Mods should generally prefix their sounds with `modname_`, e.g. given
161 the mod name "`foomod`", a sound could be called:
162
163     foomod_foosound.ogg
164
165 Sounds are referred to by their name with a dot, a single digit and the
166 file extension stripped out. When a sound is played, the actual sound file
167 is chosen randomly from the matching sounds.
168
169 When playing the sound `foomod_foosound`, the sound is chosen randomly
170 from the available ones of the following files:
171
172 * `foomod_foosound.ogg`
173 * `foomod_foosound.0.ogg`
174 * `foomod_foosound.1.ogg`
175 * (...)
176 * `foomod_foosound.9.ogg`
177
178 Examples of sound parameter tables:
179
180     -- Play locationless
181     {
182         gain = 1.0, -- default
183     }
184     -- Play locationless, looped
185     {
186         gain = 1.0, -- default
187         loop = true,
188     }
189     -- Play in a location
190     {
191         pos = {x = 1, y = 2, z = 3},
192         gain = 1.0, -- default
193     }
194     -- Play connected to an object, looped
195     {
196         object = <an ObjectRef>,
197         gain = 1.0, -- default
198         loop = true,
199     }
200
201 Looped sounds must either be connected to an object or played locationless.
202
203 ### SimpleSoundSpec
204 * e.g. `""`
205 * e.g. `"default_place_node"`
206 * e.g. `{}`
207 * e.g. `{name = "default_place_node"}`
208 * e.g. `{name = "default_place_node", gain = 1.0}`
209
210 Representations of simple things
211 --------------------------------
212
213 ### Position/vector
214
215     {x=num, y=num, z=num}
216
217 For helper functions see "Vector helpers".
218
219 ### pointed_thing
220 * `{type="nothing"}`
221 * `{type="node", under=pos, above=pos}`
222 * `{type="object", ref=ClientObjectRef}`
223
224 Flag Specifier Format
225 ---------------------
226 Flags using the standardized flag specifier format can be specified in either of
227 two ways, by string or table.
228
229 The string format is a comma-delimited set of flag names; whitespace and
230 unrecognized flag fields are ignored. Specifying a flag in the string sets the
231 flag, and specifying a flag prefixed by the string `"no"` explicitly
232 clears the flag from whatever the default may be.
233
234 In addition to the standard string flag format, the schematic flags field can
235 also be a table of flag names to boolean values representing whether or not the
236 flag is set. Additionally, if a field with the flag name prefixed with `"no"`
237 is present, mapped to a boolean of any value, the specified flag is unset.
238
239 E.g. A flag field of value
240
241     {place_center_x = true, place_center_y=false, place_center_z=true}
242
243 is equivalent to
244
245     {place_center_x = true, noplace_center_y=true, place_center_z=true}
246
247 which is equivalent to
248
249     "place_center_x, noplace_center_y, place_center_z"
250
251 or even
252
253     "place_center_x, place_center_z"
254
255 since, by default, no schematic attributes are set.
256
257 Formspec
258 --------
259 Formspec defines a menu. It is a string, with a somewhat strange format.
260
261 Spaces and newlines can be inserted between the blocks, as is used in the
262 examples.
263
264 ### Examples
265
266 #### Chest
267
268     size[8,9]
269     list[context;main;0,0;8,4;]
270     list[current_player;main;0,5;8,4;]
271
272 #### Furnace
273
274     size[8,9]
275     list[context;fuel;2,3;1,1;]
276     list[context;src;2,1;1,1;]
277     list[context;dst;5,1;2,2;]
278     list[current_player;main;0,5;8,4;]
279
280 #### Minecraft-like player inventory
281
282     size[8,7.5]
283     image[1,0.6;1,2;player.png]
284     list[current_player;main;0,3.5;8,4;]
285     list[current_player;craft;3,0;3,3;]
286     list[current_player;craftpreview;7,1;1,1;]
287
288 ### Elements
289
290 #### `size[<W>,<H>,<fixed_size>]`
291 * Define the size of the menu in inventory slots
292 * `fixed_size`: `true`/`false` (optional)
293 * deprecated: `invsize[<W>,<H>;]`
294
295 #### `container[<X>,<Y>]`
296 * Start of a container block, moves all physical elements in the container by (X, Y)
297 * Must have matching container_end
298 * Containers can be nested, in which case the offsets are added
299   (child containers are relative to parent containers)
300
301 #### `container_end[]`
302 * End of a container, following elements are no longer relative to this container
303
304 #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]`
305 * Show an inventory list
306
307 #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
308 * Show an inventory list
309
310 #### `listring[<inventory location>;<list name>]`
311 * Allows to create a ring of inventory lists
312 * Shift-clicking on items in one element of the ring
313   will send them to the next inventory list inside the ring
314 * The first occurrence of an element inside the ring will
315   determine the inventory where items will be sent to
316
317 #### `listring[]`
318 * Shorthand for doing `listring[<inventory location>;<list name>]`
319   for the last two inventory lists added by list[...]
320
321 #### `listcolors[<slot_bg_normal>;<slot_bg_hover>]`
322 * Sets background color of slots as `ColorString`
323 * Sets background color of slots on mouse hovering
324
325 #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>]`
326 * Sets background color of slots as `ColorString`
327 * Sets background color of slots on mouse hovering
328 * Sets color of slots border
329
330 #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<tooltip_fontcolor>]`
331 * Sets background color of slots as `ColorString`
332 * Sets background color of slots on mouse hovering
333 * Sets color of slots border
334 * Sets default background color of tooltips
335 * Sets default font color of tooltips
336
337 #### `tooltip[<gui_element_name>;<tooltip_text>;<bgcolor>,<fontcolor>]`
338 * Adds tooltip for an element
339 * `<bgcolor>` tooltip background color as `ColorString` (optional)
340 * `<fontcolor>` tooltip font color as `ColorString` (optional)
341
342 #### `image[<X>,<Y>;<W>,<H>;<texture name>]`
343 * Show an image
344 * Position and size units are inventory slots
345
346 #### `item_image[<X>,<Y>;<W>,<H>;<item name>]`
347 * Show an inventory image of registered item/node
348 * Position and size units are inventory slots
349
350 #### `bgcolor[<color>;<fullscreen>]`
351 * Sets background color of formspec as `ColorString`
352 * If `true`, the background color is drawn fullscreen (does not effect the size of the formspec)
353
354 #### `background[<X>,<Y>;<W>,<H>;<texture name>]`
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: image shall be sized
358   8 times 16px  times  4 times 16px.
359
360 #### `background[<X>,<Y>;<W>,<H>;<texture name>;<auto_clip>]`
361 * Use a background. Inventory rectangles are not drawn then.
362 * Position and size units are inventory slots
363 * Example for formspec 8x4 in 16x resolution:
364   image shall be sized 8 times 16px  times  4 times 16px
365 * If `true` the background is clipped to formspec size
366   (`x` and `y` are used as offset values, `w` and `h` are ignored)
367
368 #### `pwdfield[<X>,<Y>;<W>,<H>;<name>;<label>]`
369 * Textual password style field; will be sent to server when a button is clicked
370 * When enter is pressed in field, fields.key_enter_field will be sent with the name
371   of this field.
372 * `x` and `y` position the field relative to the top left of the menu
373 * `w` and `h` are the size of the field
374 * Fields are a set height, but will be vertically centred on `h`
375 * Position and size units are inventory slots
376 * `name` is the name of the field as returned in fields to `on_receive_fields`
377 * `label`, if not blank, will be text printed on the top left above the field
378 * See field_close_on_enter to stop enter closing the formspec
379
380 #### `field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
381 * Textual field; will be sent to server when a button is clicked
382 * When enter is pressed in field, fields.key_enter_field will be sent with the name
383   of this field.
384 * `x` and `y` position the field relative to the top left of the menu
385 * `w` and `h` are the size of the field
386 * Fields are a set height, but will be vertically centred on `h`
387 * Position and size units are inventory slots
388 * `name` is the name of the field as returned in fields to `on_receive_fields`
389 * `label`, if not blank, will be text printed on the top left above the field
390 * `default` is the default value of the field
391     * `default` may contain variable references such as `${text}'` which
392       will fill the value from the metadata value `text`
393     * **Note**: no extra text or more than a single variable is supported ATM.
394 * See field_close_on_enter to stop enter closing the formspec
395
396 #### `field[<name>;<label>;<default>]`
397 * As above, but without position/size units
398 * When enter is pressed in field, fields.key_enter_field will be sent with the name
399   of this field.
400 * Special field for creating simple forms, such as sign text input
401 * Must be used without a `size[]` element
402 * A "Proceed" button will be added automatically
403 * See field_close_on_enter to stop enter closing the formspec
404
405 #### `field_close_on_enter[<name>;<close_on_enter>]`
406 * <name> is the name of the field
407 * if <close_on_enter> is false, pressing enter in the field will submit the form but not close it
408 * defaults to true when not specified (ie: no tag for a field)
409
410 #### `textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
411 * Same as fields above, but with multi-line input
412
413 #### `label[<X>,<Y>;<label>]`
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 #### `vertlabel[<X>,<Y>;<label>]`
419 * Textual label drawn vertically
420 * `x` and `y` work as per field
421 * `label` is the text on the label
422 * Position and size units are inventory slots
423
424 #### `button[<X>,<Y>;<W>,<H>;<name>;<label>]`
425 * Clickable button. When clicked, fields will be sent.
426 * `x`, `y` and `name` work as per field
427 * `w` and `h` are the size of the button
428 * Fixed button height. It will be vertically centred on `h`
429 * `label` is the text on the button
430 * Position and size units are inventory slots
431
432 #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
433 * `x`, `y`, `w`, `h`, and `name` work as per button
434 * `texture name` is the filename of an image
435 * Position and size units are inventory slots
436
437 #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]`
438 * `x`, `y`, `w`, `h`, and `name` work as per button
439 * `texture name` is the filename of an image
440 * Position and size units are inventory slots
441 * `noclip=true` means the image button doesn't need to be within specified formsize
442 * `drawborder`: draw button border or not
443 * `pressed texture name` is the filename of an image on pressed state
444
445 #### `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
446 * `x`, `y`, `w`, `h`, `name` and `label` work as per button
447 * `item name` is the registered name of an item/node,
448    tooltip will be made out of its description
449    to override it use tooltip element
450 * Position and size units are inventory slots
451
452 #### `button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]`
453 * When clicked, fields will be sent and the form will quit.
454
455 #### `image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
456 * When clicked, fields will be sent and the form will quit.
457
458 #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>]`
459 * Scrollable item list showing arbitrary text elements
460 * `x` and `y` position the itemlist relative to the top left of the menu
461 * `w` and `h` are the size of the itemlist
462 * `name` fieldname sent to server on doubleclick value is current selected element
463 * `listelements` can be prepended by #color in hexadecimal format RRGGBB (only),
464      * if you want a listelement to start with "#" write "##".
465
466 #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>;<selected idx>;<transparent>]`
467 * Scrollable itemlist showing arbitrary text elements
468 * `x` and `y` position the item list relative to the top left of the menu
469 * `w` and `h` are the size of the item list
470 * `name` fieldname sent to server on doubleclick value is current selected element
471 * `listelements` can be prepended by #RRGGBB (only) in hexadecimal format
472      * if you want a listelement to start with "#" write "##"
473 * Index to be selected within textlist
474 * `true`/`false`: draw transparent background
475 * See also `minetest.explode_textlist_event` (main menu: `engine.explode_textlist_event`)
476
477 #### `tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
478 * Show a tab**header** at specific position (ignores formsize)
479 * `x` and `y` position the itemlist relative to the top left of the menu
480 * `name` fieldname data is transferred to Lua
481 * `caption 1`...: name shown on top of tab
482 * `current_tab`: index of selected tab 1...
483 * `transparent` (optional): show transparent
484 * `draw_border` (optional): draw border
485
486 #### `box[<X>,<Y>;<W>,<H>;<color>]`
487 * Simple colored semitransparent box
488 * `x` and `y` position the box relative to the top left of the menu
489 * `w` and `h` are the size of box
490 * `color` is color specified as a `ColorString`
491
492 #### `dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]`
493 * Show a dropdown field
494 * **Important note**: There are two different operation modes:
495      1. handle directly on change (only changed dropdown is submitted)
496      2. read the value on pressing a button (all dropdown values are available)
497 * `x` and `y` position of dropdown
498 * Width of dropdown
499 * Fieldname data is transferred to Lua
500 * Items to be shown in dropdown
501 * Index of currently selected dropdown item
502
503 #### `checkbox[<X>,<Y>;<name>;<label>;<selected>]`
504 * Show a checkbox
505 * `x` and `y`: position of checkbox
506 * `name` fieldname data is transferred to Lua
507 * `label` to be shown left of checkbox
508 * `selected` (optional): `true`/`false`
509
510 #### `scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]`
511 * Show a scrollbar
512 * There are two ways to use it:
513      1. handle the changed event (only changed scrollbar is available)
514      2. read the value on pressing a button (all scrollbars are available)
515 * `x` and `y`: position of trackbar
516 * `w` and `h`: width and height
517 * `orientation`:  `vertical`/`horizontal`
518 * Fieldname data is transferred to Lua
519 * Value this trackbar is set to (`0`-`1000`)
520 * See also `minetest.explode_scrollbar_event` (main menu: `engine.explode_scrollbar_event`)
521
522 #### `table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]`
523 * Show scrollable table using options defined by the previous `tableoptions[]`
524 * Displays cells as defined by the previous `tablecolumns[]`
525 * `x` and `y`: position the itemlist relative to the top left of the menu
526 * `w` and `h` are the size of the itemlist
527 * `name`: fieldname sent to server on row select or doubleclick
528 * `cell 1`...`cell n`: cell contents given in row-major order
529 * `selected idx`: index of row to be selected within table (first row = `1`)
530 * See also `minetest.explode_table_event` (main menu: `engine.explode_table_event`)
531
532 #### `tableoptions[<opt 1>;<opt 2>;...]`
533 * Sets options for `table[]`
534 * `color=#RRGGBB`
535      * default text color (`ColorString`), defaults to `#FFFFFF`
536 * `background=#RRGGBB`
537      * table background color (`ColorString`), defaults to `#000000`
538 * `border=<true/false>`
539      * should the table be drawn with a border? (default: `true`)
540 * `highlight=#RRGGBB`
541      * highlight background color (`ColorString`), defaults to `#466432`
542 * `highlight_text=#RRGGBB`
543      * highlight text color (`ColorString`), defaults to `#FFFFFF`
544 * `opendepth=<value>`
545      * all subtrees up to `depth < value` are open (default value = `0`)
546      * only useful when there is a column of type "tree"
547
548 #### `tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]`
549 * Sets columns for `table[]`
550 * Types: `text`, `image`, `color`, `indent`, `tree`
551     * `text`:   show cell contents as text
552     * `image`:  cell contents are an image index, use column options to define images
553     * `color`:   cell contents are a ColorString and define color of following cell
554     * `indent`: cell contents are a number and define indentation of following cell
555     * `tree`:   same as indent, but user can open and close subtrees (treeview-like)
556 * Column options:
557     * `align=<value>`
558         * for `text` and `image`: content alignment within cells.
559           Available values: `left` (default), `center`, `right`, `inline`
560     * `width=<value>`
561         * for `text` and `image`: minimum width in em (default: `0`)
562         * for `indent` and `tree`: indent width in em (default: `1.5`)
563     * `padding=<value>`: padding left of the column, in em (default `0.5`).
564       Exception: defaults to 0 for indent columns
565     * `tooltip=<value>`: tooltip text (default: empty)
566     * `image` column options:
567         * `0=<value>` sets image for image index 0
568         * `1=<value>` sets image for image index 1
569         * `2=<value>` sets image for image index 2
570         * and so on; defined indices need not be contiguous empty or
571           non-numeric cells are treated as `0`.
572     * `color` column options:
573         * `span=<value>`: number of following columns to affect (default: infinite)
574
575 **Note**: do _not_ use a element name starting with `key_`; those names are reserved to
576 pass key press events to formspec!
577
578 Spatial Vectors
579 ---------------
580 * `vector.new(a[, b, c])`: returns a vector:
581     * A copy of `a` if `a` is a vector.
582     * `{x = a, y = b, z = c}`, if all `a, b, c` are defined
583 * `vector.direction(p1, p2)`: returns a vector
584 * `vector.distance(p1, p2)`: returns a number
585 * `vector.length(v)`: returns a number
586 * `vector.normalize(v)`: returns a vector
587 * `vector.floor(v)`: returns a vector, each dimension rounded down
588 * `vector.round(v)`: returns a vector, each dimension rounded to nearest int
589 * `vector.apply(v, func)`: returns a vector
590 * `vector.combine(v, w, func)`: returns a vector
591 * `vector.equals(v1, v2)`: returns a boolean
592
593 For the following functions `x` can be either a vector or a number:
594
595 * `vector.add(v, x)`: returns a vector
596 * `vector.subtract(v, x)`: returns a vector
597 * `vector.multiply(v, x)`: returns a scaled vector or Schur product
598 * `vector.divide(v, x)`: returns a scaled vector or Schur quotient
599
600 Helper functions
601 ----------------
602 * `dump2(obj, name="_", dumped={})`
603      * Return object serialized as a string, handles reference loops
604 * `dump(obj, dumped={})`
605     * Return object serialized as a string
606 * `math.hypot(x, y)`
607     * Get the hypotenuse of a triangle with legs x and y.
608       Useful for distance calculation.
609 * `math.sign(x, tolerance)`
610     * Get the sign of a number.
611       Optional: Also returns `0` when the absolute value is within the tolerance (default: `0`)
612 * `string.split(str, separator=",", include_empty=false, max_splits=-1, sep_is_pattern=false)`
613     * If `max_splits` is negative, do not limit splits.
614     * `sep_is_pattern` specifies if separator is a plain string or a pattern (regex).
615     * e.g. `string:split("a,b", ",") == {"a","b"}`
616 * `string:trim()`
617     * e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"`
618 * `minetest.wrap_text(str, limit)`: returns a string
619     * Adds new lines to the string to keep it within the specified character limit
620     * limit: Maximal amount of characters in one line
621 * `minetest.pos_to_string({x=X,y=Y,z=Z}, decimal_places))`: returns string `"(X,Y,Z)"`
622     * Convert position to a printable string
623       Optional: 'decimal_places' will round the x, y and z of the pos to the given decimal place.
624 * `minetest.string_to_pos(string)`: returns a position
625     * Same but in reverse. Returns `nil` if the string can't be parsed to a position.
626 * `minetest.string_to_area("(X1, Y1, Z1) (X2, Y2, Z2)")`: returns two positions
627     * Converts a string representing an area box into two positions
628 * `minetest.is_yes(arg)`
629     * returns whether `arg` can be interpreted as yes
630 * `minetest.is_nan(arg)`
631     * returns true when the passed number represents NaN.
632 * `table.copy(table)`: returns a table
633     * returns a deep copy of `table`
634
635 Minetest namespace reference
636 ------------------------------
637
638 ### Utilities
639
640 * `minetest.get_current_modname()`: returns the currently loading mod's name, when we are loading a mod
641 * `minetest.get_modpath(modname)`: returns virtual path of given mod including
642    the trailing separator. This is useful to load additional Lua files
643    contained in your mod:
644    e.g. `dofile(minetest.get_modpath(minetest.get_current_modname()) .. "stuff.lua")`
645 * `minetest.get_language()`: returns two strings
646    * the current gettext locale
647    * the current language code (the same as used for client-side translations)
648 * `minetest.get_version()`: returns a table containing components of the
649    engine version.  Components:
650     * `project`: Name of the project, eg, "Minetest"
651     * `string`: Simple version, eg, "1.2.3-dev"
652     * `hash`: Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty"
653   Use this for informational purposes only. The information in the returned
654   table does not represent the capabilities of the engine, nor is it
655   reliable or verifiable. Compatible forks will have a different name and
656   version entirely. To check for the presence of engine features, test
657   whether the functions exported by the wanted features exist. For example:
658   `if minetest.check_for_falling then ... end`.
659 * `minetest.sha1(data, [raw])`: returns the sha1 hash of data
660     * `data`: string of data to hash
661     * `raw`: return raw bytes instead of hex digits, default: false
662 * `minetest.colorspec_to_colorstring(colorspec)`: Converts a ColorSpec to a
663   ColorString. If the ColorSpec is invalid, returns `nil`.
664     * `colorspec`: The ColorSpec to convert
665 * `minetest.get_csm_restrictions()`: returns a table of `Flags` indicating the
666    restrictions applied to the current mod.
667    * If a flag in this table is set to true, the feature is RESTRICTED.
668    * Possible flags: `load_client_mods`, `chat_messages`, `read_itemdefs`,
669                    `read_nodedefs`, `lookup_nodes`, `read_playerinfo`
670
671 ### Logging
672 * `minetest.debug(...)`
673     * Equivalent to `minetest.log(table.concat({...}, "\t"))`
674 * `minetest.log([level,] text)`
675     * `level` is one of `"none"`, `"error"`, `"warning"`, `"action"`,
676       `"info"`, or `"verbose"`.  Default is `"none"`.
677
678 ### Global callback registration functions
679 Call these functions only at load time!
680
681 * `minetest.get_send_speed(speed)`
682         * This function is called every time the player's speed is sent to server
683         * The `speed` argument is the actual speed of the player
684         * If you define it, you can return a modified `speed`. This speed will be
685                 sent to server instead.
686 * `minetest.open_enderchest()`
687     * This function is called if the client uses the Keybind for it (by default "O")
688     * You can override it
689 * `minetest.register_globalstep(function(dtime))`
690     * Called every client environment step, usually interval of 0.1s
691 * `minetest.register_on_mods_loaded(function())`
692     * Called just after mods have finished loading.
693 * `minetest.register_on_shutdown(function())`
694     * Called before client shutdown
695     * **Warning**: If the client terminates abnormally (i.e. crashes), the registered
696       callbacks **will likely not be run**. Data should be saved at
697       semi-frequent intervals as well as on server shutdown.
698 * `minetest.register_on_receiving_chat_message(function(message))`
699     * Called always when a client receive a message
700     * Return `true` to mark the message as handled, which means that it will not be shown to chat
701 * `minetest.register_on_sending_chat_message(function(message))`
702     * Called always when a client send a message from chat
703     * Return `true` to mark the message as handled, which means that it will not be sent to server
704 * `minetest.register_chatcommand(cmd, chatcommand definition)`
705     * Adds definition to minetest.registered_chatcommands
706 * `minetest.unregister_chatcommand(name)`
707     * Unregisters a chatcommands registered with register_chatcommand.
708 * `minetest.register_list_command(command, desc, setting)`
709     * Registers a chatcommand `command` to manage a list that takes the args `del | add | list <param>`
710     * The list is stored comma-seperated in `setting`
711     * `desc` is the description
712     * `add` adds something to the list
713     * `del` del removes something from the list
714     * `list` lists all items on the list
715 * `minetest.register_on_chatcommand(function(command, params))`
716     * Called always when a chatcommand is triggered, before `minetest.registered_chatcommands`
717       is checked to see if that the command exists, but after the input is parsed.
718     * Return `true` to mark the command as handled, which means that the default
719       handlers will be prevented.
720 * `minetest.register_on_death(function())`
721     * Called when the local player dies
722 * `minetest.register_on_hp_modification(function(hp))`
723     * Called when server modified player's HP
724 * `minetest.register_on_damage_taken(function(hp))`
725     * Called when the local player take damages
726 * `minetest.register_on_formspec_input(function(formname, fields))`
727     * Called when a button is pressed in the local player's inventory form
728     * Newest functions are called first
729     * If function returns `true`, remaining functions are not called
730 * `minetest.register_on_dignode(function(pos, node))`
731     * Called when the local player digs a node
732     * Newest functions are called first
733     * If any function returns true, the node isn't dug
734 * `minetest.register_on_punchnode(function(pos, node))`
735     * Called when the local player punches a node
736     * Newest functions are called first
737     * If any function returns true, the punch is ignored
738 * `minetest.register_on_placenode(function(pointed_thing, node))`
739     * Called when a node has been placed
740 * `minetest.register_on_item_use(function(item, pointed_thing))`
741     * Called when the local player uses an item.
742     * Newest functions are called first.
743     * If any function returns true, the item use is not sent to server.
744 * `minetest.register_on_modchannel_message(function(channel_name, sender, message))`
745     * Called when an incoming mod channel message is received
746     * You must have joined some channels before, and server must acknowledge the
747       join request.
748     * If message comes from a server mod, `sender` field is an empty string.
749 * `minetest.register_on_modchannel_signal(function(channel_name, signal))`
750     * Called when a valid incoming mod channel signal is received
751     * Signal id permit to react to server mod channel events
752     * Possible values are:
753       0: join_ok
754       1: join_failed
755       2: leave_ok
756       3: leave_failed
757       4: event_on_not_joined_channel
758       5: state_changed
759 * `minetest.register_on_inventory_open(function(inventory))`
760     * Called when the local player open inventory
761     * Newest functions are called first
762     * If any function returns true, inventory doesn't open
763 * `minetest.register_on_recieve_physics_override(function(override))`
764     * Called when recieving physics_override from server
765     * Newest functions are called first
766     * If any function returns true, the physics override does not change
767 * `minetest.register_on_play_sound(function(SimpleSoundSpec))`
768     * Called when recieving a play sound command from server
769     * Newest functions are called first
770     * If any function returns true, the sound does not play
771 * `minetest.register_on_spawn_partice(function(particle definition))`
772     * Called when recieving a spawn particle command from server
773     * Newest functions are called first
774     * If any function returns true, the particle does not spawn
775 * `minetest.register_on_object_add(function(obj))`
776         * Called every time an object is added
777 * `minetest.register_on_object_properties_change(function(obj))`
778     * Called every time the properties of an object are changed server-side
779     * May modify the object's properties without the fear of infinite recursion
780 * `minetest.register_on_object_hp_change(function(obj))`
781     * Called every time the hp of an object are changes server-side
782
783 ### Setting-related
784 * `minetest.settings`: Settings object containing all of the settings from the
785   main config file (`minetest.conf`).
786 * `minetest.setting_get_pos(name)`: Loads a setting from the main settings and
787   parses it as a position (in the format `(1,2,3)`). Returns a position or nil.
788
789 ### Sounds
790 * `minetest.sound_play(spec, parameters)`: returns a handle
791     * `spec` is a `SimpleSoundSpec`
792     * `parameters` is a sound parameter table
793 * `minetest.sound_stop(handle)`
794     * `handle` is a handle returned by `minetest.sound_play`
795 * `minetest.sound_fade(handle, step, gain)`
796     * `handle` is a handle returned by `minetest.sound_play`
797     * `step` determines how fast a sound will fade.
798       Negative step will lower the sound volume, positive step will increase
799       the sound volume.
800     * `gain` the target gain for the fade.
801
802 ### Timing
803 * `minetest.after(time, func, ...)`
804     * Call the function `func` after `time` seconds, may be fractional
805     * Optional: Variable number of arguments that are passed to `func`
806 * `minetest.get_us_time()`
807     * Returns time with microsecond precision. May not return wall time.
808 * `minetest.get_timeofday()`
809     * Returns the time of day: `0` for midnight, `0.5` for midday
810
811 ### Map
812 * `minetest.interact(action, pointed_thing)`
813     * Sends an interaction to the server
814     * `pointed_thing` is a pointed_thing
815     * `action` is one of
816         * "start_digging": Use to punch nodes / objects
817         * "stop_digging": Use to abort digging a "start_digging" command
818         * "digging_completed": Use to finish a "start_digging" command or dig a node instantly
819         * "place": Use to rightclick nodes and objects
820         * "use": Use to leftclick an item in air (pointed_thing.type is usually "nothing")
821         * "activate": Same as "use", but rightclick
822 * `minetest.place_node(pos)`
823     * Places the wielded node/item of the player at pos.
824 * `minetest.dig_node(pos)`
825     * Instantly digs the node at pos. This may fuck up with anticheat.
826 * `minetest.get_node_or_nil(pos)`
827     * Returns the node at the given position as table in the format
828       `{name="node_name", param1=0, param2=0}`, returns `nil`
829       for unloaded areas or flavor limited areas.
830 * `minetest.get_node_light(pos, timeofday)`
831     * Gets the light value at the given position. Note that the light value
832       "inside" the node at the given position is returned, so you usually want
833       to get the light value of a neighbor.
834     * `pos`: The position where to measure the light.
835     * `timeofday`: `nil` for current time, `0` for night, `0.5` for day
836     * Returns a number between `0` and `15` or `nil`
837 * `minetest.find_node_near(pos, radius, nodenames, [search_center])`: returns pos or `nil`
838     * `radius`: using a maximum metric
839     * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
840     * `search_center` is an optional boolean (default: `false`)
841       If true `pos` is also checked for the nodes
842 * `minetest.find_nodes_near(pos, radius, nodenames, [search_center])`: returns a
843   list of positions.
844     * `radius`: using a maximum metric
845     * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
846     * `search_center` is an optional boolean (default: `false`)
847       If true `pos` is also checked for the nodes
848 * `minetest.find_nodes_near_under_air(pos, radius, nodenames, [search_center])`: returns a
849   list of positions.
850     * `radius`: using a maximum metric
851     * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
852     * `search_center` is an optional boolean (default: `false`)
853       If true `pos` is also checked for the nodes
854     * Return value: Table with all node positions with a node air above
855 * `minetest.find_nodes_near_under_air_except(pos, radius, nodenames, [search_center])`: returns a
856   list of positions.
857     * `radius`: using a maximum metric
858     * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`, specifies the nodes to be ignored
859     * `search_center` is an optional boolean (default: `false`)
860       If true `pos` is also checked for the nodes
861     * Return value: Table with all node positions with a node air above
862 * `minetest.find_nodes_in_area(pos1, pos2, nodenames, [grouped])`
863     * `pos1` and `pos2` are the min and max positions of the area to search.
864     * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
865     * If `grouped` is true the return value is a table indexed by node name
866       which contains lists of positions.
867     * If `grouped` is false or absent the return values are as follows:
868       first value: Table with all node positions
869       second value: Table with the count of each node with the node name
870       as index
871     * Area volume is limited to 4,096,000 nodes
872 * `minetest.find_nodes_in_area_under_air(pos1, pos2, nodenames)`: returns a
873   list of positions.
874     * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
875     * Return value: Table with all node positions with a node air above
876     * Area volume is limited to 4,096,000 nodes
877 * `minetest.line_of_sight(pos1, pos2)`: returns `boolean, pos`
878     * Checks if there is anything other than air between pos1 and pos2.
879     * Returns false if something is blocking the sight.
880     * Returns the position of the blocking node when `false`
881     * `pos1`: First position
882     * `pos2`: Second position
883 * `minetest.raycast(pos1, pos2, objects, liquids)`: returns `Raycast`
884     * Creates a `Raycast` object.
885     * `pos1`: start of the ray
886     * `pos2`: end of the ray
887     * `objects`: if false, only nodes will be returned. Default is `true`.
888     * `liquids`: if false, liquid nodes won't be returned. Default is `false`.
889 * `minetest.get_pointed_thing()` returns `PointedThing`
890     * Returns the thing currently pointed by player
891 * `minetest.get_pointed_thing_position(pointed_thing, above)`
892     * Returns the position of a `pointed_thing` or `nil` if the `pointed_thing`
893       does not refer to a node or entity.
894     * If the optional `above` parameter is true and the `pointed_thing` refers
895       to a node, then it will return the `above` position of the `pointed_thing`.
896 * `minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)`
897     * returns table containing path that can be walked on
898     * returns a table of 3D points representing a path from `pos1` to `pos2` or
899       `nil` on failure.
900     * Reasons for failure:
901         * No path exists at all
902         * No path exists within `searchdistance` (see below)
903         * Start or end pos is buried in land
904     * `pos1`: start position
905     * `pos2`: end position
906     * `searchdistance`: maximum distance from the search positions to search in.
907       In detail: Path must be completely inside a cuboid. The minimum
908       `searchdistance` of 1 will confine search between `pos1` and `pos2`.
909       Larger values will increase the size of this cuboid in all directions
910     * `max_jump`: maximum height difference to consider walkable
911     * `max_drop`: maximum height difference to consider droppable
912     * `algorithm`: One of `"A*_noprefetch"` (default), `"A*"`, `"Dijkstra"`.
913       Difference between `"A*"` and `"A*_noprefetch"` is that
914       `"A*"` will pre-calculate the cost-data, the other will calculate it
915       on-the-fly
916 * `minetest.find_nodes_with_meta(pos1, pos2)`
917     * Get a table of positions of nodes that have metadata within a region
918       {pos1, pos2}.
919 * `minetest.get_meta(pos)`
920     * Get a `NodeMetaRef` at that position
921 * `minetest.get_node_level(pos)`
922     * get level of leveled node (water, snow)
923 * `minetest.get_node_max_level(pos)`
924     * get max available level for leveled node
925
926 ### Player
927 * `minetest.send_damage(hp)`
928     * Sends fall damage to server
929 * `minetest.send_chat_message(message)`
930     * Act as if `message` was typed by the player into the terminal.
931 * `minetest.run_server_chatcommand(cmd, param)`
932     * Alias for `minetest.send_chat_message("/" .. cmd .. " " .. param)`
933 * `minetest.clear_out_chat_queue()`
934     * Clears the out chat queue
935 * `minetest.drop_selected_item()`
936     * Drops the selected item
937 * `minetest.localplayer`
938     * Reference to the LocalPlayer object. See [`LocalPlayer`](#localplayer) class reference for methods.
939
940 ### Privileges
941 * `minetest.get_privilege_list()`
942     * Returns a list of privileges the current player has in the format `{priv1=true,...}`
943 * `minetest.string_to_privs(str)`: returns `{priv1=true,...}`
944 * `minetest.privs_to_string(privs)`: returns `"priv1,priv2,..."`
945     * Convert between two privilege representations
946
947 ### Client Environment
948 * `minetest.object_refs`
949     * Map of object references, indexed by active object id
950 * `minetest.get_player_names()`
951     * Returns list of player names on server (nil if CSM_RF_READ_PLAYERINFO is enabled by server)
952 * `minetest.get_objects_inside_radius(pos, radius)`: returns a list of
953   ClientObjectRefs.
954     * `radius`: using an euclidean metric
955 * `minetest.get_nearby_objects(radius)`
956     * alias for minetest.get_objects_inside_radius(minetest.localplayer:get_pos(), radius)
957 * `minetest.disconnect()`
958     * Disconnect from the server and exit to main menu.
959     * Returns `false` if the client is already disconnecting otherwise returns `true`.
960 * `minetest.get_server_info()`
961     * Returns [server info](#server-info).
962 * `minetest.send_respawn()`
963     * Sends a respawn request to the server.
964
965 ### HTTP Requests
966
967 * `minetest.request_http_api()`:
968     * returns `HTTPApiTable` containing http functions if the calling mod has
969       been granted access by being listed in the `secure.http_mods` or
970       `secure.trusted_mods` setting, otherwise returns `nil`.
971     * The returned table contains the functions `fetch`, `fetch_async` and
972       `fetch_async_get` described below.
973     * Only works at init time and must be called from the mod's main scope
974       (not from a function).
975     * Function only exists if minetest server was built with cURL support.
976     * **DO NOT ALLOW ANY OTHER MODS TO ACCESS THE RETURNED TABLE, STORE IT IN
977       A LOCAL VARIABLE!**
978 * `HTTPApiTable.fetch(HTTPRequest req, callback)`
979     * Performs given request asynchronously and calls callback upon completion
980     * callback: `function(HTTPRequestResult res)`
981     * Use this HTTP function if you are unsure, the others are for advanced use
982 * `HTTPApiTable.fetch_async(HTTPRequest req)`: returns handle
983     * Performs given request asynchronously and returns handle for
984       `HTTPApiTable.fetch_async_get`
985 * `HTTPApiTable.fetch_async_get(handle)`: returns HTTPRequestResult
986     * Return response data for given asynchronous HTTP request
987
988 ### `HTTPRequest` definition
989
990 Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
991
992     {
993         url = "http://example.org",
994
995         timeout = 10,
996         -- Timeout for connection in seconds. Default is 3 seconds.
997
998         post_data = "Raw POST request data string" OR {field1 = "data1", field2 = "data2"},
999         -- Optional, if specified a POST request with post_data is performed.
1000         -- Accepts both a string and a table. If a table is specified, encodes
1001         -- table as x-www-form-urlencoded key-value pairs.
1002         -- If post_data is not specified, a GET request is performed instead.
1003
1004         user_agent = "ExampleUserAgent",
1005         -- Optional, if specified replaces the default minetest user agent with
1006         -- given string
1007
1008         extra_headers = { "Accept-Language: en-us", "Accept-Charset: utf-8" },
1009         -- Optional, if specified adds additional headers to the HTTP request.
1010         -- You must make sure that the header strings follow HTTP specification
1011         -- ("Key: Value").
1012
1013         multipart = boolean
1014         -- Optional, if true performs a multipart HTTP request.
1015         -- Default is false.
1016     }
1017
1018 ### `HTTPRequestResult` definition
1019
1020 Passed to `HTTPApiTable.fetch` callback. Returned by
1021 `HTTPApiTable.fetch_async_get`.
1022
1023     {
1024         completed = true,
1025         -- If true, the request has finished (either succeeded, failed or timed
1026         -- out)
1027
1028         succeeded = true,
1029         -- If true, the request was successful
1030
1031         timeout = false,
1032         -- If true, the request timed out
1033
1034         code = 200,
1035         -- HTTP status code
1036
1037         data = "response"
1038     }
1039
1040 ### Storage API
1041 * `minetest.get_mod_storage()`:
1042     * returns reference to mod private `StorageRef`
1043     * must be called during mod load time
1044
1045 ### Mod channels
1046 ![Mod channels communication scheme](docs/mod channels.png)
1047
1048 * `minetest.mod_channel_join(channel_name)`
1049     * Client joins channel `channel_name`, and creates it, if necessary. You
1050       should listen from incoming messages with `minetest.register_on_modchannel_message`
1051       call to receive incoming messages. Warning, this function is asynchronous.
1052
1053 ### Particles
1054 * `minetest.add_particle(particle definition)`
1055
1056 * `minetest.add_particlespawner(particlespawner definition)`
1057     * Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds
1058     * Returns an `id`, and -1 if adding didn't succeed
1059
1060 * `minetest.delete_particlespawner(id)`
1061     * Delete `ParticleSpawner` with `id` (return value from `minetest.add_particlespawner`)
1062
1063 ### Misc
1064 * `minetest.set_keypress(key, value)`
1065     * Act as if a key was pressed (value = true) / released (value = false)
1066     * The key must be an keymap_* setting
1067     * e.g. minetest.set_keypress("jump", true) will cause te player to jump until minetest.set_keypress("jump", false) is called or the player presses & releases the space bar himself
1068 * `minetest.get_inventory(location)`
1069     * Returns the inventory at location
1070 * `minetest.find_item(item)`
1071     * finds and an item in the inventory
1072     * returns index on success or nil if item is not found
1073 * `minetest.switch_to_item(item)`
1074     * `item` is an Itemstring
1075     * searches to item in inventory, sets the wield index to it if found
1076     * returns true on success, false if item was not found
1077 * `minetest.register_cheat(name, category, setting | function)`
1078     * Register an entry for the cheat menu
1079     * If the Category is nonexistant, it will be created
1080     * If the 3rd argument is a string it will be interpreted as a setting and toggled
1081         when the player selects the entry in the cheat menu
1082     * If the 3rd argument is a function it will be called
1083         when the player selects the entry in the cheat menu
1084 * `minetest.parse_json(string[, nullvalue])`: returns something
1085     * Convert a string containing JSON data into the Lua equivalent
1086     * `nullvalue`: returned in place of the JSON null; defaults to `nil`
1087     * On success returns a table, a string, a number, a boolean or `nullvalue`
1088     * On failure outputs an error message and returns `nil`
1089     * Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}`
1090 * `minetest.write_json(data[, styled])`: returns a string or `nil` and an error message
1091     * Convert a Lua table into a JSON string
1092     * styled: Outputs in a human-readable format if this is set, defaults to false
1093     * Unserializable things like functions and userdata are saved as null.
1094     * **Warning**: JSON is more strict than the Lua table format.
1095         1. You can only use strings and positive integers of at least one as keys.
1096         2. You can not mix string and integer keys.
1097            This is due to the fact that JSON has two distinct array and object values.
1098     * Example: `write_json({10, {a = false}})`, returns `"[10, {\"a\": false}]"`
1099 * `minetest.serialize(table)`: returns a string
1100     * Convert a table containing tables, strings, numbers, booleans and `nil`s
1101       into string form readable by `minetest.deserialize`
1102     * Example: `serialize({foo='bar'})`, returns `'return { ["foo"] = "bar" }'`
1103 * `minetest.deserialize(string)`: returns a table
1104     * Convert a string returned by `minetest.deserialize` into a table
1105     * `string` is loaded in an empty sandbox environment.
1106     * Will load functions, but they cannot access the global environment.
1107     * Example: `deserialize('return { ["foo"] = "bar" }')`, returns `{foo='bar'}`
1108     * Example: `deserialize('print("foo")')`, returns `nil` (function call fails)
1109         * `error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)`
1110 * `minetest.compress(data, method, ...)`: returns `compressed_data`
1111     * Compress a string of data.
1112     * `method` is a string identifying the compression method to be used.
1113     * Supported compression methods:
1114     *     Deflate (zlib): `"deflate"`
1115     * `...` indicates method-specific arguments.  Currently defined arguments are:
1116     *     Deflate: `level` - Compression level, `0`-`9` or `nil`.
1117 * `minetest.decompress(compressed_data, method, ...)`: returns data
1118     * Decompress a string of data (using ZLib).
1119     * See documentation on `minetest.compress()` for supported compression methods.
1120     * currently supported.
1121     * `...` indicates method-specific arguments. Currently, no methods use this.
1122 * `minetest.rgba(red, green, blue[, alpha])`: returns a string
1123     * Each argument is a 8 Bit unsigned integer
1124     * Returns the ColorString from rgb or rgba values
1125     * Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
1126 * `minetest.encode_base64(string)`: returns string encoded in base64
1127     * Encodes a string in base64.
1128 * `minetest.decode_base64(string)`: returns string or nil on failure
1129     * Padding characters are only supported starting at version 5.4.0, where
1130       5.5.0 and newer perform proper checks.
1131     * Decodes a string encoded in base64.
1132 * `minetest.gettext(string)` : returns string
1133     * look up the translation of a string in the gettext message catalog
1134 * `fgettext_ne(string, ...)`
1135     * call minetest.gettext(string), replace "$1"..."$9" with the given
1136       extra arguments and return the result
1137 * `fgettext(string, ...)` : returns string
1138     * same as fgettext_ne(), but calls minetest.formspec_escape before returning result
1139 * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
1140     * returns the exact position on the surface of a pointed node
1141 * `minetest.global_exists(name)`
1142     * Checks if a global variable has been set, without triggering a warning.
1143 * `minetest.make_screenshot()`
1144     * Triggers the MT makeScreenshot functionality
1145 * `minetest.request_insecure_environment()`: returns an environment containing
1146   insecure functions if the calling mod has been listed as trusted in the
1147   `secure.trusted_mods` setting or security is disabled, otherwise returns
1148   `nil`.
1149     * Only works at init time and must be called from the mod's main scope
1150       (ie: the init.lua of the mod, not from another Lua file or within a function).
1151     * **DO NOT ALLOW ANY OTHER MODS TO ACCESS THE RETURNED ENVIRONMENT, STORE
1152       IT IN A LOCAL VARIABLE!**
1153
1154 ### UI
1155 * `minetest.ui.minimap`
1156     * Reference to the minimap object. See [`Minimap`](#minimap) class reference for methods.
1157     * If client disabled minimap (using enable_minimap setting) this reference will be nil.
1158 * `minetest.camera`
1159     * Reference to the camera object. See [`Camera`](#camera) class reference for methods.
1160 * `minetest.show_formspec(formname, formspec)` : returns true on success
1161         * Shows a formspec to the player
1162 * `minetest.close_formspec(formname)`
1163     * `formname`: has to exactly match the one given in `show_formspec`, or the
1164       formspec will not close.
1165     * calling `show_formspec(formname, "")` is equal to this
1166       expression.
1167     * to close a formspec regardless of the formname, call
1168       `minetest.close_formspec("")`.
1169       **USE THIS ONLY WHEN ABSOLUTELY NECESSARY!**
1170 * `minetest.display_chat_message(message)` returns true on success
1171         * Shows a chat message to the current player.
1172
1173 Class reference
1174 ---------------
1175
1176 ### ModChannel
1177
1178 An interface to use mod channels on client and server
1179
1180 #### Methods
1181 * `leave()`: leave the mod channel.
1182     * Client leaves channel `channel_name`.
1183     * No more incoming or outgoing messages can be sent to this channel from client mods.
1184     * This invalidate all future object usage
1185     * Ensure your set mod_channel to nil after that to free Lua resources
1186 * `is_writeable()`: returns true if channel is writable and mod can send over it.
1187 * `send_all(message)`: Send `message` though the mod channel.
1188     * If mod channel is not writable or invalid, message will be dropped.
1189     * Message size is limited to 65535 characters by protocol.
1190
1191 ### Minimap
1192 An interface to manipulate minimap on client UI
1193
1194 #### Methods
1195 * `show()`: shows the minimap (if not disabled by server)
1196 * `hide()`: hides the minimap
1197 * `set_pos(pos)`: sets the minimap position on screen
1198 * `get_pos()`: returns the minimap current position
1199 * `set_angle(deg)`: sets the minimap angle in degrees
1200 * `get_angle()`: returns the current minimap angle in degrees
1201 * `set_mode(mode)`: sets the minimap mode (0 to 6)
1202 * `get_mode()`: returns the current minimap mode
1203 * `set_shape(shape)`: Sets the minimap shape. (0 = square, 1 = round)
1204 * `get_shape()`: Gets the minimap shape. (0 = square, 1 = round)
1205
1206 ### Camera
1207 An interface to get or set information about the camera and camera-node.
1208 Please do not try to access the reference until the camera is initialized, otherwise the reference will be nil.
1209
1210 #### Methods
1211 * `set_camera_mode(mode)`
1212     * Pass `0` for first-person, `1` for third person, and `2` for third person front
1213 * `get_camera_mode()`
1214     * Returns 0, 1, or 2 as described above
1215 * `get_fov()`
1216     * Returns a table with X, Y, maximum and actual FOV in degrees:
1217
1218 ```lua
1219      {
1220          x = number,
1221          y = number,
1222          max = number,
1223          actual = number
1224      }
1225 ```
1226
1227 * `get_pos()`
1228     * Returns position of camera with view bobbing
1229 * `get_offset()`
1230     * Returns eye offset vector
1231 * `get_look_dir()`
1232     * Returns eye direction unit vector
1233 * `get_look_vertical()`
1234     * Returns pitch in radians
1235 * `get_look_horizontal()`
1236     * Returns yaw in radians
1237 * `get_aspect_ratio()`
1238     * Returns aspect ratio of screen
1239
1240 ### LocalPlayer
1241 An interface to retrieve information about the player.
1242 This object will only be available after the client is initialized. Earlier accesses will yield a `nil` value.
1243
1244 Methods:
1245
1246 * `get_pos()`
1247     * returns current player current position
1248 * `set_pos(pos)`
1249     * sets the position (anticheat may not like this)
1250 * `get_yaw()`
1251     * returns the yaw (degrees)
1252 * `set_yaw(yaw)`
1253     * sets the yaw (degrees)
1254 * `get_pitch()`
1255     * returns the pitch (degrees)
1256 * `set_pitch(pitch)`
1257     * sets the pitch (degrees)
1258 * `get_velocity()`
1259     * returns player speed vector
1260 * `set_velocity(vel)`
1261     * sets player speed vector
1262 * `get_hp()`
1263     * returns player HP
1264 * `get_name()`
1265     * returns player name
1266 * `get_wield_index()`
1267     * returns the index of the wielded item (starts at 1)
1268 * `set_wield_index()`
1269     * sets the index (starts at 1)
1270 * `get_wielded_item()`
1271     * returns the itemstack the player is holding
1272 * `is_attached()`
1273     * returns true if player is attached
1274 * `is_touching_ground()`
1275     * returns true if player touching ground
1276 * `is_in_liquid()`
1277     * returns true if player is in a liquid (This oscillates so that the player jumps a bit above the surface)
1278 * `is_in_liquid_stable()`
1279     * returns true if player is in a stable liquid (This is more stable and defines the maximum speed of the player)
1280 * `get_move_resistance()`
1281     * returns move resistance of current node, the higher the slower the player moves
1282 * `is_climbing()`
1283     * returns true if player is climbing
1284 * `swimming_vertical()`
1285     * returns true if player is swimming in vertical
1286 * `get_physics_override()`
1287     * returns:
1288
1289 ```lua
1290     {
1291         speed = float,
1292         jump = float,
1293         gravity = float,
1294         sneak = boolean,
1295         sneak_glitch = boolean,
1296         new_move = boolean,
1297     }
1298 ```
1299
1300 * `set_physics_override(override_table)`
1301     * `override_table` is a table with the following fields:
1302         * `speed`: multiplier to default walking speed value (default: `1`)
1303         * `jump`: multiplier to default jump value (default: `1`)
1304         * `gravity`: multiplier to default gravity value (default: `1`)
1305         * `sneak`: whether player can sneak (default: `true`)
1306         * `sneak_glitch`: whether player can use the new move code replications
1307           of the old sneak side-effects: sneak ladders and 2 node sneak jump
1308           (default: `false`)
1309         * `new_move`: use new move/sneak code. When `false` the exact old code
1310           is used for the specific old sneak behaviour (default: `true`)
1311 * `get_override_pos()`
1312     * returns override position
1313 * `get_last_pos()`
1314     * returns last player position before the current client step
1315 * `get_last_velocity()`
1316     * returns last player speed
1317 * `get_breath()`
1318     * returns the player's breath
1319 * `get_movement_acceleration()`
1320     * returns acceleration of the player in different environments:
1321
1322 ```lua
1323     {
1324        fast = float,
1325        air = float,
1326        default = float,
1327     }
1328 ```
1329
1330 * `get_movement_speed()`
1331     * returns player's speed in different environments:
1332
1333 ```lua
1334     {
1335        walk = float,
1336        jump = float,
1337        crouch = float,
1338        fast = float,
1339        climb = float,
1340     }
1341 ```
1342
1343 * `get_movement()`
1344     * returns player's movement in different environments:
1345
1346 ```lua
1347     {
1348        liquid_fluidity = float,
1349        liquid_sink = float,
1350        liquid_fluidity_smooth = float,
1351        gravity = float,
1352     }
1353 ```
1354
1355 * `get_last_look_horizontal()`:
1356     * returns last look horizontal angle
1357 * `get_last_look_vertical()`:
1358     * returns last look vertical angle
1359 * `get_control()`:
1360     * returns pressed player controls
1361
1362 ```lua
1363     {
1364        up = boolean,
1365        down = boolean,
1366        left = boolean,
1367        right = boolean,
1368        jump = boolean,
1369        aux1 = boolean,
1370        sneak = boolean,
1371        zoom = boolean,
1372        dig = boolean,
1373        place = boolean,
1374     }
1375 ```
1376
1377 * `get_armor_groups()`
1378     * returns a table with the armor group ratings
1379 * `hud_add(definition)`
1380     * add a HUD element described by HUD def, returns ID number on success and `nil` on failure.
1381     * See [`HUD definition`](#hud-definition-hud_add-hud_get)
1382 * `hud_get(id)`
1383     * returns the [`definition`](#hud-definition-hud_add-hud_get) of the HUD with that ID number or `nil`, if non-existent.
1384 * `hud_remove(id)`
1385     * remove the HUD element of the specified id, returns `true` on success
1386 * `hud_change(id, stat, value)`
1387     * change a value of a previously added HUD element
1388     * element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir`
1389     * Returns `true` on success, otherwise returns `nil`
1390 * `get_object()`
1391     * Returns the ClientObjectRef for the player
1392
1393 ### Settings
1394 An interface to read config files in the format of `minetest.conf`.
1395
1396 It can be created via `Settings(filename)`.
1397
1398 #### Methods
1399 * `get(key)`: returns a value
1400 * `get_bool(key)`: returns a boolean
1401 * `set(key, value)`
1402 * `remove(key)`: returns a boolean (`true` for success)
1403 * `get_names()`: returns `{key1,...}`
1404 * `write()`: returns a boolean (`true` for success)
1405     * write changes to file
1406 * `to_table()`: returns `{[key1]=value1,...}`
1407
1408 ### NodeMetaRef
1409 Node metadata: reference extra data and functionality stored in a node.
1410 Can be obtained via `minetest.get_meta(pos)`.
1411
1412 #### Methods
1413 * `get_string(name)`
1414 * `get_int(name)`
1415 * `get_float(name)`
1416 * `to_table()`: returns `nil` or a table with keys:
1417     * `fields`: key-value storage
1418     * `inventory`: `{list1 = {}, ...}}`
1419
1420 ### ClientObjectRef
1421
1422 Moving things in the game are generally these.
1423 This is basically a reference to a C++ `GenericCAO`.
1424
1425 #### Methods
1426
1427 * `get_pos()`: returns `{x=num, y=num, z=num}`
1428 * `get_velocity()`: returns the velocity, a vector
1429 * `get_acceleration()`: returns the acceleration, a vector
1430 * `get_rotation()`: returns the rotation, a vector (radians)
1431 * `is_player()`: returns true if the object is a player
1432 * `is_local_player()`: returns true if the object is the local player
1433 * `get_attach()`: returns parent or nil if it isn't attached.
1434 * `get_nametag()`: returns the nametag (deprecated, use get_properties().nametag instead)
1435 * `get_item_textures()`: returns the textures (deprecated, use get_properties().textures instead)
1436 * `get_max_hp()`: returns the maximum heath (deprecated, use get_properties().hp_max instead)
1437 * `set_properties(object property table)`
1438 * `get_properties()`: returns object property table
1439 * `punch()`: punches the object
1440 * `rightclick()`: rightclicks the object
1441 * `remove()`: removes the object permanently
1442 * `set_nametag_images(images)`: Provides a list of images to be drawn below the nametag
1443
1444 ### `Raycast`
1445
1446 A raycast on the map. It works with selection boxes.
1447 Can be used as an iterator in a for loop as:
1448
1449     local ray = Raycast(...)
1450     for pointed_thing in ray do
1451         ...
1452     end
1453
1454 The map is loaded as the ray advances. If the map is modified after the
1455 `Raycast` is created, the changes may or may not have an effect on the object.
1456
1457 It can be created via `Raycast(pos1, pos2, objects, liquids)` or
1458 `minetest.raycast(pos1, pos2, objects, liquids)` where:
1459
1460 * `pos1`: start of the ray
1461 * `pos2`: end of the ray
1462 * `objects`: if false, only nodes will be returned. Default is true.
1463 * `liquids`: if false, liquid nodes won't be returned. Default is false.
1464
1465 #### Methods
1466
1467 * `next()`: returns a `pointed_thing` with exact pointing location
1468     * Returns the next thing pointed by the ray or nil.
1469
1470 -----------------
1471 ### Definitions
1472 * `minetest.inventorycube(img1, img2, img3)`
1473     * Returns a string for making an image of a cube (useful as an item image)
1474 * `minetest.get_node_def(nodename)`
1475         * Returns [node definition](#node-definition) table of `nodename`
1476 * `minetest.get_item_def(itemstring)`
1477         * Returns item definition table of `itemstring`
1478 * `minetest.override_item(itemstring, redefinition)`
1479     * Overrides fields of an item registered with register_node/tool/craftitem.
1480     * Note: Item must already be defined by the server
1481     * Example: `minetest.override_item("default:mese",
1482       {light_source=minetest.LIGHT_MAX})`
1483     * Doesnt really work yet an causes strange bugs, I'm working to make is better
1484
1485
1486 #### Tile definition
1487
1488 * `"image.png"`
1489 * `{name="image.png", animation={Tile Animation definition}}`
1490 * `{name="image.png", backface_culling=bool, align_style="node"/"world"/"user", scale=int}`
1491     * backface culling enabled by default for most nodes
1492     * align style determines whether the texture will be rotated with the node
1493       or kept aligned with its surroundings. "user" means that client
1494       setting will be used, similar to `glasslike_framed_optional`.
1495       Note: supported by solid nodes and nodeboxes only.
1496     * scale is used to make texture span several (exactly `scale`) nodes,
1497       instead of just one, in each direction. Works for world-aligned
1498       textures only.
1499       Note that as the effect is applied on per-mapblock basis, `16` should
1500       be equally divisible by `scale` or you may get wrong results.
1501 * `{name="image.png", color=ColorSpec}`
1502     * the texture's color will be multiplied with this color.
1503     * the tile's color overrides the owning node's color in all cases.
1504
1505 ##### Tile definition
1506
1507     {
1508         type = "vertical_frames",
1509
1510         aspect_w = 16,
1511         -- Width of a frame in pixels
1512
1513         aspect_h = 16,
1514         -- Height of a frame in pixels
1515
1516         length = 3.0,
1517         -- Full loop length
1518     }
1519
1520     {
1521         type = "sheet_2d",
1522
1523         frames_w = 5,
1524         -- Width in number of frames
1525
1526         frames_h = 3,
1527         -- Height in number of frames
1528
1529         frame_length = 0.5,
1530         -- Length of a single frame
1531     }
1532
1533 #### Node Definition
1534
1535 ```lua
1536         {
1537         tiles = {tile definition 1, def2, def3, def4, def5, def6},
1538         -- Textures of node; +Y, -Y, +X, -X, +Z, -Z
1539         overlay_tiles = {tile definition 1, def2, def3, def4, def5, def6},
1540         -- Same as `tiles`, but these textures are drawn on top of the base
1541         -- tiles. This is used to colorize only specific parts of the
1542         -- texture. If the texture name is an empty string, that overlay is not
1543         -- drawn
1544         special_tiles = {tile definition 1, Tile definition 2},
1545         -- Special textures of node; used rarely.
1546                 has_on_construct = bool,        -- Whether the node has the on_construct callback defined
1547                 has_on_destruct = bool,         -- Whether the node has the on_destruct callback defined
1548                 has_after_destruct = bool,      -- Whether the node has the after_destruct callback defined
1549                 name = string,                  -- The name of the node e.g. "air", "default:dirt"
1550                 groups = table,                 -- The groups of the node
1551                 paramtype = string,             -- Paramtype of the node
1552                 paramtype2 = string,            -- ParamType2 of the node
1553                 drawtype = string,              -- Drawtype of the node
1554                 mesh = <string>,                -- Mesh name if existant
1555                 minimap_color = <Color>,        -- Color of node on minimap *May not exist*
1556                 visual_scale = number,          -- Visual scale of node
1557                 alpha = number,                 -- Alpha of the node. Only used for liquids
1558                 color = <Color>,                -- Color of node *May not exist*
1559                 palette_name = <string>,        -- Filename of palette *May not exist*
1560                 palette = <{                    -- List of colors
1561                         Color,
1562                         Color
1563                 }>,
1564                 waving = number,                -- 0 of not waving, 1 if waving
1565                 connect_sides = number,         -- Used for connected nodes
1566                 connects_to = {                 -- List of nodes to connect to
1567                         "node1",
1568                         "node2"
1569                 },
1570                 post_effect_color = Color,      -- Color overlayed on the screen when the player is in the node
1571                 leveled = number,               -- Max level for node
1572                 sunlight_propogates = bool,     -- Whether light passes through the block
1573                 light_source = number,          -- Light emitted by the block
1574                 is_ground_content = bool,       -- Whether caves should cut through the node
1575                 walkable = bool,                -- Whether the player collides with the node
1576                 pointable = bool,               -- Whether the player can select the node
1577                 diggable = bool,                -- Whether the player can dig the node
1578                 climbable = bool,               -- Whether the player can climb up the node
1579                 buildable_to = bool,            -- Whether the player can replace the node by placing a node on it
1580                 rightclickable = bool,          -- Whether the player can place nodes pointing at this node
1581                 damage_per_second = number,     -- HP of damage per second when the player is in the node
1582                 liquid_type = <string>,         -- A string containing "none", "flowing", or "source" *May not exist*
1583                 liquid_alternative_flowing = <string>, -- Alternative node for liquid *May not exist*
1584                 liquid_alternative_source = <string>, -- Alternative node for liquid *May not exist*
1585                 liquid_viscosity = <number>,    -- How slow the liquid flows *May not exist*
1586                 liquid_renewable = <boolean>,   -- Whether the liquid makes an infinite source *May not exist*
1587                 liquid_range = <number>,        -- How far the liquid flows *May not exist*
1588                 drowning = bool,                -- Whether the player will drown in the node
1589                 floodable = bool,               -- Whether nodes will be replaced by liquids (flooded)
1590                 node_box = table,               -- Nodebox to draw the node with
1591                 collision_box = table,          -- Nodebox to set the collision area
1592                 selection_box = table,          -- Nodebox to set the area selected by the player
1593                 sounds = {                      -- Table of sounds that the block makes
1594                         sound_footstep = SimpleSoundSpec,
1595                         sound_dig = SimpleSoundSpec,
1596                         sound_dug = SimpleSoundSpec
1597                 },
1598                 legacy_facedir_simple = bool,   -- Whether to use old facedir
1599                 legacy_wallmounted = bool       -- Whether to use old wallmounted
1600                 move_resistance = <number>,     -- How slow players can move through the node *May not exist*
1601         }
1602 ```
1603
1604 #### Item Definition
1605
1606 ```lua
1607         {
1608                 name = string,                  -- Name of the item e.g. "default:stone"
1609                 description = string,           -- Description of the item e.g. "Stone"
1610                 type = string,                  -- Item type: "none", "node", "craftitem", "tool"
1611                 inventory_image = string,       -- Image in the inventory
1612                 wield_image = string,           -- Image in wieldmesh
1613                 palette_image = string,         -- Image for palette
1614                 color = Color,                  -- Color for item
1615                 wield_scale = Vector,           -- Wieldmesh scale
1616                 stack_max = number,             -- Number of items stackable together
1617                 usable = bool,                  -- Has on_use callback defined
1618                 liquids_pointable = bool,       -- Whether you can point at liquids with the item
1619                 tool_capabilities = <table>,    -- If the item is a tool, tool capabilities of the item
1620                 groups = table,                 -- Groups of the item
1621                 sound_place = SimpleSoundSpec,  -- Sound played when placed
1622                 sound_place_failed = SimpleSoundSpec, -- Sound played when placement failed
1623                 node_placement_prediction = string -- Node placed in client until server catches up
1624         }
1625 ```
1626 -----------------
1627
1628 ### Chat command definition (`register_chatcommand`)
1629
1630     {
1631         params = "<name> <privilege>", -- Short parameter description
1632         description = "Remove privilege from player", -- Full description
1633         func = function(param),        -- Called when command is run.
1634                                        -- Returns boolean success and text output.
1635     }
1636 ### Server info
1637 ```lua
1638 {
1639         address = "minetest.example.org", -- The domain name/IP address of a remote server or "" for a local server.
1640         ip = "203.0.113.156",             -- The IP address of the server.
1641         port = 30000,                     -- The port the client is connected to.
1642         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.
1643 }
1644 ```
1645
1646 ### HUD Definition (`hud_add`, `hud_get`)
1647 ```lua
1648     {
1649         hud_elem_type = "image", -- see HUD element types, default "text"
1650     --  ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
1651         position = {x=0.5, y=0.5},
1652     --  ^ Left corner position of element, default `{x=0,y=0}`.
1653         name = "<name>",    -- default ""
1654         scale = {x=2, y=2}, -- default {x=0,y=0}
1655         text = "<text>",    -- default ""
1656         number = 2,         -- default 0
1657         item = 3,           -- default 0
1658     --  ^ Selected item in inventory.  0 for no item selected.
1659         direction = 0,      -- default 0
1660     --  ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
1661         alignment = {x=0, y=0},   -- default {x=0, y=0}
1662     --  ^ See "HUD Element Types"
1663         offset = {x=0, y=0},      -- default {x=0, y=0}
1664     --  ^ See "HUD Element Types"
1665         size = { x=100, y=100 },  -- default {x=0, y=0}
1666     --  ^ Size of element in pixels
1667         style = 0,
1668     --  ^ For "text" elements sets font style: bitfield with 1 = bold, 2 = italic, 4 = monospace
1669     }
1670 ```
1671
1672 Escape sequences
1673 ----------------
1674 Most text can contain escape sequences, that can for example color the text.
1675 There are a few exceptions: tab headers, dropdowns and vertical labels can't.
1676 The following functions provide escape sequences:
1677 * `minetest.get_color_escape_sequence(color)`:
1678     * `color` is a [ColorString](#colorstring)
1679     * The escape sequence sets the text color to `color`
1680 * `minetest.colorize(color, message)`:
1681     * Equivalent to:
1682       `minetest.get_color_escape_sequence(color) ..
1683        message ..
1684        minetest.get_color_escape_sequence("#ffffff")`
1685 * `minetest.rainbow(message)`:
1686     * Rainbow colorizes the message.
1687 * `minetest.get_background_escape_sequence(color)`
1688     * `color` is a [ColorString](#colorstring)
1689     * The escape sequence sets the background of the whole text element to
1690       `color`. Only defined for item descriptions and tooltips.
1691 * `minetest.strip_foreground_colors(str)`
1692     * Removes foreground colors added by `get_color_escape_sequence`.
1693 * `minetest.strip_background_colors(str)`
1694     * Removes background colors added by `get_background_escape_sequence`.
1695 * `minetest.strip_colors(str)`
1696     * Removes all color escape sequences.
1697
1698 `ColorString`
1699 -------------
1700 `#RGB` defines a color in hexadecimal format.
1701
1702 `#RGBA` defines a color in hexadecimal format and alpha channel.
1703
1704 `#RRGGBB` defines a color in hexadecimal format.
1705
1706 `#RRGGBBAA` defines a color in hexadecimal format and alpha channel.
1707
1708 Named colors are also supported and are equivalent to
1709 [CSS Color Module Level 4](http://dev.w3.org/csswg/css-color/#named-colors).
1710 To specify the value of the alpha channel, append `#A` or `#AA` to the end of
1711 the color name (e.g. `colorname#08`).
1712
1713 `Color`
1714 -------------
1715 `{a = alpha, r = red, g = green, b = blue}` defines an ARGB8 color.
1716
1717 HUD element types
1718 -----------------
1719 The position field is used for all element types.
1720
1721 To account for differing resolutions, the position coordinates are the percentage
1722 of the screen, ranging in value from `0` to `1`.
1723
1724 The name field is not yet used, but should contain a description of what the
1725 HUD element represents. The direction field is the direction in which something
1726 is drawn.
1727
1728 `0` draws from left to right, `1` draws from right to left, `2` draws from
1729 top to bottom, and `3` draws from bottom to top.
1730
1731 The `alignment` field specifies how the item will be aligned. It ranges from `-1` to `1`,
1732 with `0` being the center, `-1` is moved to the left/up, and `1` is to the right/down.
1733 Fractional values can be used.
1734
1735 The `offset` field specifies a pixel offset from the position. Contrary to position,
1736 the offset is not scaled to screen size. This allows for some precisely-positioned
1737 items in the HUD.
1738
1739 **Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling factor!
1740
1741 Below are the specific uses for fields in each type; fields not listed for that type are ignored.
1742
1743 **Note**: Future revisions to the HUD API may be incompatible; the HUD API is still
1744 in the experimental stages.
1745
1746 ### `image`
1747 Displays an image on the HUD.
1748
1749 * `scale`: The scale of the image, with 1 being the original texture size.
1750   Only the X coordinate scale is used (positive values).
1751   Negative values represent that percentage of the screen it
1752   should take; e.g. `x=-100` means 100% (width).
1753 * `text`: The name of the texture that is displayed.
1754 * `alignment`: The alignment of the image.
1755 * `offset`: offset in pixels from position.
1756
1757 ### `text`
1758 Displays text on the HUD.
1759
1760 * `scale`: Defines the bounding rectangle of the text.
1761   A value such as `{x=100, y=100}` should work.
1762 * `text`: The text to be displayed in the HUD element.
1763 * `number`: An integer containing the RGB value of the color used to draw the text.
1764   Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
1765 * `alignment`: The alignment of the text.
1766 * `offset`: offset in pixels from position.
1767
1768 ### `statbar`
1769 Displays a horizontal bar made up of half-images.
1770
1771 * `text`: The name of the texture that is used.
1772 * `number`: The number of half-textures that are displayed.
1773   If odd, will end with a vertically center-split texture.
1774 * `direction`
1775 * `offset`: offset in pixels from position.
1776 * `size`: If used, will force full-image size to this value (override texture pack image size)
1777
1778 ### `inventory`
1779 * `text`: The name of the inventory list to be displayed.
1780 * `number`: Number of items in the inventory to be displayed.
1781 * `item`: Position of item that is selected.
1782 * `direction`
1783 * `offset`: offset in pixels from position.
1784
1785 ### `waypoint`
1786
1787 Displays distance to selected world position.
1788
1789 * `name`: The name of the waypoint.
1790 * `text`: Distance suffix. Can be blank.
1791 * `precision`: Waypoint precision, integer >= 0. Defaults to 10.
1792   If set to 0, distance is not shown. Shown value is `floor(distance*precision)/precision`.
1793   When the precision is an integer multiple of 10, there will be `log_10(precision)` digits after the decimal point.
1794   `precision = 1000`, for example, will show 3 decimal places (eg: `0.999`).
1795   `precision = 2` will show multiples of `0.5`; precision = 5 will show multiples of `0.2` and so on:
1796   `precision = n` will show multiples of `1/n`
1797 * `number:` An integer containing the RGB value of the color used to draw the
1798   text.
1799 * `world_pos`: World position of the waypoint.
1800 * `offset`: offset in pixels from position.
1801 * `alignment`: The alignment of the waypoint.
1802
1803 ### `image_waypoint`
1804
1805 Same as `image`, but does not accept a `position`; the position is instead determined by `world_pos`, the world position of the waypoint.
1806
1807 * `scale`: The scale of the image, with 1 being the original texture size.
1808   Only the X coordinate scale is used (positive values).
1809   Negative values represent that percentage of the screen it
1810   should take; e.g. `x=-100` means 100% (width).
1811 * `text`: The name of the texture that is displayed.
1812 * `alignment`: The alignment of the image.
1813 * `world_pos`: World position of the waypoint.
1814 * `offset`: offset in pixels from position.
1815
1816 ### Particle definition (`add_particle`)
1817
1818     {
1819         pos = {x=0, y=0, z=0},
1820         velocity = {x=0, y=0, z=0},
1821         acceleration = {x=0, y=0, z=0},
1822     --  ^ Spawn particle at pos with velocity and acceleration
1823         expirationtime = 1,
1824     --  ^ Disappears after expirationtime seconds
1825         size = 1,
1826         collisiondetection = false,
1827     --  ^ collisiondetection: if true collides with physical objects
1828         collision_removal = false,
1829     --  ^ collision_removal: if true then particle is removed when it collides,
1830     --  ^ requires collisiondetection = true to have any effect
1831         vertical = false,
1832     --  ^ vertical: if true faces player using y axis only
1833         texture = "image.png",
1834     --  ^ Uses texture (string)
1835         animation = {Tile Animation definition},
1836     --  ^ optional, specifies how to animate the particle texture
1837         glow = 0
1838     --  ^ optional, specify particle self-luminescence in darkness
1839     }
1840
1841 ### `ParticleSpawner` definition (`add_particlespawner`)
1842
1843     {
1844         amount = 1,
1845         time = 1,
1846     --  ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
1847         minpos = {x=0, y=0, z=0},
1848         maxpos = {x=0, y=0, z=0},
1849         minvel = {x=0, y=0, z=0},
1850         maxvel = {x=0, y=0, z=0},
1851         minacc = {x=0, y=0, z=0},
1852         maxacc = {x=0, y=0, z=0},
1853         minexptime = 1,
1854         maxexptime = 1,
1855         minsize = 1,
1856         maxsize = 1,
1857     --  ^ The particle's properties are random values in between the bounds:
1858     --  ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
1859     --  ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
1860         collisiondetection = false,
1861     --  ^ collisiondetection: if true uses collision detection
1862         collision_removal = false,
1863     --  ^ collision_removal: if true then particle is removed when it collides,
1864     --  ^ requires collisiondetection = true to have any effect
1865         vertical = false,
1866     --  ^ vertical: if true faces player using y axis only
1867         texture = "image.png",
1868     --  ^ Uses texture (string)
1869     }
1870
1871 ### InventoryAction
1872 A reference to a C++ InventoryAction. You can move, drop and craft items in all accessible inventories using InventoryActions.
1873
1874 #### methods
1875
1876 * `InventoryAction(type)`:
1877     * creates a new InventoryAction
1878     * type is on of "move", "drop", or "craft", else returns nil
1879     * indexing starts at 1
1880 * `apply()`:
1881     * applies the InventoryAction (InventoryActions can be applied multible times)
1882 * `from(inventorylocation, listname, stack)`
1883     * this is valid for move or drop actions
1884     * when `apply()` is called items are moved / dropped from `listname` `inventorylocation` in` at `stack`
1885 * `to(inventorylocation, listname, stack)`
1886     * this is valid for move actions
1887     * when `apply()` is called items are moved to `listname` in`inventorylocation` at `stack`
1888 * `craft(inventoryaction)`
1889     * this is valid for craft actions
1890     * when `apply()` is called a craft event for this inventory will be triggered
1891 * `set_count(count)`
1892     * this is valid for all actions
1893     * it specifies how many items to drop / craft / move
1894     * `0` means move all items
1895     * default count: `0`
1896
1897 #### example
1898     `local move_act = InventoryAction("move")
1899     move_act:from("current_player", "main", 1)
1900     move_act:to("current_player", "craft", 1)
1901     move_act:set_count(1)
1902     local craft_act = InventoryAction("craft")
1903     craft_act:craft("current_player")
1904     local drop_act = InventoryAction("drop")
1905     drop_act:from("current_player", "craft_result",10)
1906     move_act:apply()
1907     craft_act:apply()
1908     drop_act:apply()
1909     `
1910     * e.g. In first hotbar slot there are tree logs: Move one to craft field, then craft wood out of it and immediately drop it
1911
1912
1913
1914