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