]> git.lizzy.rs Git - minetest.git/blob - doc/client_lua_api.txt
[CSM] Add `on_punchnode` callback
[minetest.git] / doc / client_lua_api.txt
1 Minetest Lua Modding API Reference 0.4.15
2 =========================================
3 * More information at <http://www.minetest.net/>
4 * Developer Wiki: <http://dev.minetest.net/>
5
6 Introduction
7 ------------
8 Content and functionality can be added to Minetest 0.4 by using Lua
9 scripting in run-time loaded mods.
10
11 A mod is a self-contained bunch of scripts, textures and other related
12 things that is loaded by and interfaces with Minetest.
13
14 Mods are contained and ran solely on the server side. Definitions and media
15 files are automatically transferred to the client.
16
17 If you see a deficiency in the API, feel free to attempt to add the
18 functionality in the engine and API. You can send such improvements as
19 source code patches on GitHub (https://github.com/minetest/minetest).
20
21 Programming in Lua
22 ------------------
23 If you have any difficulty in understanding this, please read
24 [Programming in Lua](http://www.lua.org/pil/).
25
26 Startup
27 -------
28 Mods are loaded during client startup from the mod load paths by running
29 the `init.lua` scripts in a shared environment.
30
31 Paths
32 -----
33 * `RUN_IN_PLACE=1` (Windows release, local build)
34     *  `$path_user`:
35         * Linux: `<build directory>`
36         * Windows: `<build directory>`
37     * `$path_share`
38         * Linux: `<build directory>`
39         * Windows:  `<build directory>`
40 * `RUN_IN_PLACE=0`: (Linux release)
41     * `$path_share`
42         * Linux: `/usr/share/minetest`
43         * Windows: `<install directory>/minetest-0.4.x`
44     * `$path_user`:
45         * Linux: `$HOME/.minetest`
46         * Windows: `C:/users/<user>/AppData/minetest` (maybe)
47
48 Mod load path
49 -------------
50 Generic:
51
52 * `$path_share/clientmods/`
53 * `$path_user/clientmods/` (User-installed mods)
54
55 In a run-in-place version (e.g. the distributed windows version):
56
57 * `minetest-0.4.x/clientmods/` (User-installed mods)
58
59 On an installed version on Linux:
60
61 * `/usr/share/minetest/clientmods/`
62 * `$HOME/.minetest/clientmods/` (User-installed mods)
63
64 Modpack support
65 ----------------
66 Mods can be put in a subdirectory, if the parent directory, which otherwise
67 should be a mod, contains a file named `modpack.txt`. This file shall be
68 empty, except for lines starting with `#`, which are comments.
69
70 Mod directory structure
71 ------------------------
72
73     mods
74     |-- modname
75     |   |-- depends.txt
76     |   |-- screenshot.png
77     |   |-- description.txt
78     |   |-- settingtypes.txt
79     |   |-- init.lua
80     |   |-- models
81     |   |-- textures
82     |   |   |-- modname_stuff.png
83     |   |   `-- modname_something_else.png
84     |   |-- sounds
85     |   |-- media
86     |   `-- <custom data>
87     `-- another
88
89
90 ### modname
91 The location of this directory can be fetched by using
92 `minetest.get_modpath(modname)`.
93
94 ### `depends.txt`
95 List of mods that have to be loaded before loading this mod.
96
97 A single line contains a single modname.
98
99 Optional dependencies can be defined by appending a question mark
100 to a single modname. Their meaning is that if the specified mod
101 is missing, that does not prevent this mod from being loaded.
102
103 ### `screenshot.png`
104 A screenshot shown in the mod manager within the main menu. It should
105 have an aspect ratio of 3:2 and a minimum size of 300×200 pixels.
106
107 ### `description.txt`
108 A File containing description to be shown within mainmenu.
109
110 ### `settingtypes.txt`
111 A file in the same format as the one in builtin. It will be parsed by the
112 settings menu and the settings will be displayed in the "Mods" category.
113
114 ### `init.lua`
115 The main Lua script. Running this script should register everything it
116 wants to register. Subsequent execution depends on minetest calling the
117 registered callbacks.
118
119 `minetest.setting_get(name)` and `minetest.setting_getbool(name)` can be used
120 to read custom or existing settings at load time, if necessary.
121
122 ### `sounds`
123 Media files (sounds) that will be transferred to the
124 client and will be available for use by the mod.
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 ### Aliases
152 Aliases can be added by using `minetest.register_alias(name, convert_to)` or
153 `minetest.register_alias_force(name, convert_to).
154
155 This will make Minetest to convert things called name to things called
156 `convert_to`.
157
158 The only difference between `minetest.register_alias` and
159 `minetest.register_alias_force` is that if an item called `name` exists,
160 `minetest.register_alias` will do nothing while
161 `minetest.register_alias_force` will unregister it.
162
163 This can be used for maintaining backwards compatibility.
164
165 This can be also used for setting quick access names for things, e.g. if
166 you have an item called `epiclylongmodname:stuff`, you could do
167
168     minetest.register_alias("stuff", "epiclylongmodname:stuff")
169
170 and be able to use `/giveme stuff`.
171
172 Sounds
173 ------
174 Only Ogg Vorbis files are supported.
175
176 For positional playing of sounds, only single-channel (mono) files are
177 supported. Otherwise OpenAL will play them non-positionally.
178
179 Mods should generally prefix their sounds with `modname_`, e.g. given
180 the mod name "`foomod`", a sound could be called:
181
182     foomod_foosound.ogg
183
184 Sounds are referred to by their name with a dot, a single digit and the
185 file extension stripped out. When a sound is played, the actual sound file
186 is chosen randomly from the matching sounds.
187
188 When playing the sound `foomod_foosound`, the sound is chosen randomly
189 from the available ones of the following files:
190
191 * `foomod_foosound.ogg`
192 * `foomod_foosound.0.ogg`
193 * `foomod_foosound.1.ogg`
194 * (...)
195 * `foomod_foosound.9.ogg`
196
197 Examples of sound parameter tables:
198
199     -- Play locationless on all clients
200     {
201         gain = 1.0, -- default
202     }
203     -- Play locationless to one player
204     {
205         to_player = name,
206         gain = 1.0, -- default
207     }
208     -- Play locationless to one player, looped
209     {
210         to_player = name,
211         gain = 1.0, -- default
212         loop = true,
213     }
214     -- Play in a location
215     {
216         pos = {x = 1, y = 2, z = 3},
217         gain = 1.0, -- default
218         max_hear_distance = 32, -- default, uses an euclidean metric
219     }
220     -- Play connected to an object, looped
221     {
222         object = <an ObjectRef>,
223         gain = 1.0, -- default
224         max_hear_distance = 32, -- default, uses an euclidean metric
225         loop = true,
226     }
227
228 Looped sounds must either be connected to an object or played locationless to
229 one player using `to_player = name,`
230
231 ### `SimpleSoundSpec`
232 * e.g. `""`
233 * e.g. `"default_place_node"`
234 * e.g. `{}`
235 * e.g. `{name = "default_place_node"}`
236 * e.g. `{name = "default_place_node", gain = 1.0}`
237
238 Representations of simple things
239 --------------------------------
240
241 ### Position/vector
242
243     {x=num, y=num, z=num}
244
245 For helper functions see "Vector helpers".
246
247 ### `pointed_thing`
248 * `{type="nothing"}`
249 * `{type="node", under=pos, above=pos}`
250 * `{type="object", ref=ObjectRef}`
251
252 Flag Specifier Format
253 ---------------------
254 Flags using the standardized flag specifier format can be specified in either of
255 two ways, by string or table.
256
257 The string format is a comma-delimited set of flag names; whitespace and
258 unrecognized flag fields are ignored. Specifying a flag in the string sets the
259 flag, and specifying a flag prefixed by the string `"no"` explicitly
260 clears the flag from whatever the default may be.
261
262 In addition to the standard string flag format, the schematic flags field can
263 also be a table of flag names to boolean values representing whether or not the
264 flag is set. Additionally, if a field with the flag name prefixed with `"no"`
265 is present, mapped to a boolean of any value, the specified flag is unset.
266
267 E.g. A flag field of value
268
269     {place_center_x = true, place_center_y=false, place_center_z=true}
270
271 is equivalent to
272
273     {place_center_x = true, noplace_center_y=true, place_center_z=true}
274
275 which is equivalent to
276
277     "place_center_x, noplace_center_y, place_center_z"
278
279 or even
280
281     "place_center_x, place_center_z"
282
283 since, by default, no schematic attributes are set.
284
285 Formspec
286 --------
287 Formspec defines a menu. Currently not much else than inventories are
288 supported. It is a string, with a somewhat strange format.
289
290 Spaces and newlines can be inserted between the blocks, as is used in the
291 examples.
292
293 ### Examples
294
295 #### Chest
296
297     size[8,9]
298     list[context;main;0,0;8,4;]
299     list[current_player;main;0,5;8,4;]
300
301 #### Furnace
302
303     size[8,9]
304     list[context;fuel;2,3;1,1;]
305     list[context;src;2,1;1,1;]
306     list[context;dst;5,1;2,2;]
307     list[current_player;main;0,5;8,4;]
308
309 #### Minecraft-like player inventory
310
311     size[8,7.5]
312     image[1,0.6;1,2;player.png]
313     list[current_player;main;0,3.5;8,4;]
314     list[current_player;craft;3,0;3,3;]
315     list[current_player;craftpreview;7,1;1,1;]
316
317 ### Elements
318
319 #### `size[<W>,<H>,<fixed_size>]`
320 * Define the size of the menu in inventory slots
321 * `fixed_size`: `true`/`false` (optional)
322 * deprecated: `invsize[<W>,<H>;]`
323
324 #### `container[<X>,<Y>]`
325 * Start of a container block, moves all physical elements in the container by (X, Y)
326 * Must have matching container_end
327 * Containers can be nested, in which case the offsets are added
328   (child containers are relative to parent containers)
329
330 #### `container_end[]`
331 * End of a container, following elements are no longer relative to this container
332
333 #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]`
334 * Show an inventory list
335
336 #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
337 * Show an inventory list
338
339 #### `listring[<inventory location>;<list name>]`
340 * Allows to create a ring of inventory lists
341 * Shift-clicking on items in one element of the ring
342   will send them to the next inventory list inside the ring
343 * The first occurrence of an element inside the ring will
344   determine the inventory where items will be sent to
345
346 #### `listring[]`
347 * Shorthand for doing `listring[<inventory location>;<list name>]`
348   for the last two inventory lists added by list[...]
349
350 #### `listcolors[<slot_bg_normal>;<slot_bg_hover>]`
351 * Sets background color of slots as `ColorString`
352 * Sets background color of slots on mouse hovering
353
354 #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>]`
355 * Sets background color of slots as `ColorString`
356 * Sets background color of slots on mouse hovering
357 * Sets color of slots border
358
359 #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<tooltip_fontcolor>]`
360 * Sets background color of slots as `ColorString`
361 * Sets background color of slots on mouse hovering
362 * Sets color of slots border
363 * Sets default background color of tooltips
364 * Sets default font color of tooltips
365
366 #### `tooltip[<gui_element_name>;<tooltip_text>;<bgcolor>,<fontcolor>]`
367 * Adds tooltip for an element
368 * `<bgcolor>` tooltip background color as `ColorString` (optional)
369 * `<fontcolor>` tooltip font color as `ColorString` (optional)
370
371 #### `image[<X>,<Y>;<W>,<H>;<texture name>]`
372 * Show an image
373 * Position and size units are inventory slots
374
375 #### `item_image[<X>,<Y>;<W>,<H>;<item name>]`
376 * Show an inventory image of registered item/node
377 * Position and size units are inventory slots
378
379 #### `bgcolor[<color>;<fullscreen>]`
380 * Sets background color of formspec as `ColorString`
381 * If `true`, the background color is drawn fullscreen (does not effect the size of the formspec)
382
383 #### `background[<X>,<Y>;<W>,<H>;<texture name>]`
384 * Use a background. Inventory rectangles are not drawn then.
385 * Position and size units are inventory slots
386 * Example for formspec 8x4 in 16x resolution: image shall be sized
387   8 times 16px  times  4 times 16px.
388
389 #### `background[<X>,<Y>;<W>,<H>;<texture name>;<auto_clip>]`
390 * Use a background. Inventory rectangles are not drawn then.
391 * Position and size units are inventory slots
392 * Example for formspec 8x4 in 16x resolution:
393   image shall be sized 8 times 16px  times  4 times 16px
394 * If `true` the background is clipped to formspec size
395   (`x` and `y` are used as offset values, `w` and `h` are ignored)
396
397 #### `pwdfield[<X>,<Y>;<W>,<H>;<name>;<label>]`
398 * Textual password style field; will be sent to server when a button is clicked
399 * When enter is pressed in field, fields.key_enter_field will be sent with the name
400   of this field.
401 * `x` and `y` position the field relative to the top left of the menu
402 * `w` and `h` are the size of the field
403 * Fields are a set height, but will be vertically centred on `h`
404 * Position and size units are inventory slots
405 * `name` is the name of the field as returned in fields to `on_receive_fields`
406 * `label`, if not blank, will be text printed on the top left above the field
407 * See field_close_on_enter to stop enter closing the formspec
408
409 #### `field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
410 * Textual field; will be sent to server when a button is clicked
411 * When enter is pressed in field, fields.key_enter_field will be sent with the name
412   of this field.
413 * `x` and `y` position the field relative to the top left of the menu
414 * `w` and `h` are the size of the field
415 * Fields are a set height, but will be vertically centred on `h`
416 * Position and size units are inventory slots
417 * `name` is the name of the field as returned in fields to `on_receive_fields`
418 * `label`, if not blank, will be text printed on the top left above the field
419 * `default` is the default value of the field
420     * `default` may contain variable references such as `${text}'` which
421       will fill the value from the metadata value `text`
422     * **Note**: no extra text or more than a single variable is supported ATM.
423 * See field_close_on_enter to stop enter closing the formspec
424
425 #### `field[<name>;<label>;<default>]`
426 * As above, but without position/size units
427 * When enter is pressed in field, fields.key_enter_field will be sent with the name
428   of this field.
429 * Special field for creating simple forms, such as sign text input
430 * Must be used without a `size[]` element
431 * A "Proceed" button will be added automatically
432 * See field_close_on_enter to stop enter closing the formspec
433
434 #### `field_close_on_enter[<name>;<close_on_enter>]`
435 * <name> is the name of the field
436 * if <close_on_enter> is false, pressing enter in the field will submit the form but not close it
437 * defaults to true when not specified (ie: no tag for a field)
438
439 #### `textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
440 * Same as fields above, but with multi-line input
441
442 #### `label[<X>,<Y>;<label>]`
443 * `x` and `y` work as per field
444 * `label` is the text on the label
445 * Position and size units are inventory slots
446
447 #### `vertlabel[<X>,<Y>;<label>]`
448 * Textual label drawn vertically
449 * `x` and `y` work as per field
450 * `label` is the text on the label
451 * Position and size units are inventory slots
452
453 #### `button[<X>,<Y>;<W>,<H>;<name>;<label>]`
454 * Clickable button. When clicked, fields will be sent.
455 * `x`, `y` and `name` work as per field
456 * `w` and `h` are the size of the button
457 * `label` is the text on the button
458 * Position and size units are inventory slots
459
460 #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
461 * `x`, `y`, `w`, `h`, and `name` work as per button
462 * `texture name` is the filename of an image
463 * Position and size units are inventory slots
464
465 #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]`
466 * `x`, `y`, `w`, `h`, and `name` work as per button
467 * `texture name` is the filename of an image
468 * Position and size units are inventory slots
469 * `noclip=true` means the image button doesn't need to be within specified formsize
470 * `drawborder`: draw button border or not
471 * `pressed texture name` is the filename of an image on pressed state
472
473 #### `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
474 * `x`, `y`, `w`, `h`, `name` and `label` work as per button
475 * `item name` is the registered name of an item/node,
476    tooltip will be made out of its description
477    to override it use tooltip element
478 * Position and size units are inventory slots
479
480 #### `button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]`
481 * When clicked, fields will be sent and the form will quit.
482
483 #### `image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
484 * When clicked, fields will be sent and the form will quit.
485
486 #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>]`
487 * Scrollable item list showing arbitrary text elements
488 * `x` and `y` position the itemlist relative to the top left of the menu
489 * `w` and `h` are the size of the itemlist
490 * `name` fieldname sent to server on doubleclick value is current selected element
491 * `listelements` can be prepended by #color in hexadecimal format RRGGBB (only),
492      * if you want a listelement to start with "#" write "##".
493
494 #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>;<selected idx>;<transparent>]`
495 * Scrollable itemlist showing arbitrary text elements
496 * `x` and `y` position the item list relative to the top left of the menu
497 * `w` and `h` are the size of the item list
498 * `name` fieldname sent to server on doubleclick value is current selected element
499 * `listelements` can be prepended by #RRGGBB (only) in hexadecimal format
500      * if you want a listelement to start with "#" write "##"
501 * Index to be selected within textlist
502 * `true`/`false`: draw transparent background
503 * See also `minetest.explode_textlist_event` (main menu: `engine.explode_textlist_event`)
504
505 #### `tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
506 * Show a tab**header** at specific position (ignores formsize)
507 * `x` and `y` position the itemlist relative to the top left of the menu
508 * `name` fieldname data is transferred to Lua
509 * `caption 1`...: name shown on top of tab
510 * `current_tab`: index of selected tab 1...
511 * `transparent` (optional): show transparent
512 * `draw_border` (optional): draw border
513
514 #### `box[<X>,<Y>;<W>,<H>;<color>]`
515 * Simple colored semitransparent box
516 * `x` and `y` position the box relative to the top left of the menu
517 * `w` and `h` are the size of box
518 * `color` is color specified as a `ColorString`
519
520 #### `dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]`
521 * Show a dropdown field
522 * **Important note**: There are two different operation modes:
523      1. handle directly on change (only changed dropdown is submitted)
524      2. read the value on pressing a button (all dropdown values are available)
525 * `x` and `y` position of dropdown
526 * Width of dropdown
527 * Fieldname data is transferred to Lua
528 * Items to be shown in dropdown
529 * Index of currently selected dropdown item
530
531 #### `checkbox[<X>,<Y>;<name>;<label>;<selected>]`
532 * Show a checkbox
533 * `x` and `y`: position of checkbox
534 * `name` fieldname data is transferred to Lua
535 * `label` to be shown left of checkbox
536 * `selected` (optional): `true`/`false`
537
538 #### `scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]`
539 * Show a scrollbar
540 * There are two ways to use it:
541      1. handle the changed event (only changed scrollbar is available)
542      2. read the value on pressing a button (all scrollbars are available)
543 * `x` and `y`: position of trackbar
544 * `w` and `h`: width and height
545 * `orientation`:  `vertical`/`horizontal`
546 * Fieldname data is transferred to Lua
547 * Value this trackbar is set to (`0`-`1000`)
548 * See also `minetest.explode_scrollbar_event` (main menu: `engine.explode_scrollbar_event`)
549
550 #### `table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]`
551 * Show scrollable table using options defined by the previous `tableoptions[]`
552 * Displays cells as defined by the previous `tablecolumns[]`
553 * `x` and `y`: position the itemlist relative to the top left of the menu
554 * `w` and `h` are the size of the itemlist
555 * `name`: fieldname sent to server on row select or doubleclick
556 * `cell 1`...`cell n`: cell contents given in row-major order
557 * `selected idx`: index of row to be selected within table (first row = `1`)
558 * See also `minetest.explode_table_event` (main menu: `engine.explode_table_event`)
559
560 #### `tableoptions[<opt 1>;<opt 2>;...]`
561 * Sets options for `table[]`
562 * `color=#RRGGBB`
563      * default text color (`ColorString`), defaults to `#FFFFFF`
564 * `background=#RRGGBB`
565      * table background color (`ColorString`), defaults to `#000000`
566 * `border=<true/false>`
567      * should the table be drawn with a border? (default: `true`)
568 * `highlight=#RRGGBB`
569      * highlight background color (`ColorString`), defaults to `#466432`
570 * `highlight_text=#RRGGBB`
571      * highlight text color (`ColorString`), defaults to `#FFFFFF`
572 * `opendepth=<value>`
573      * all subtrees up to `depth < value` are open (default value = `0`)
574      * only useful when there is a column of type "tree"
575
576 #### `tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]`
577 * Sets columns for `table[]`
578 * Types: `text`, `image`, `color`, `indent`, `tree`
579     * `text`:   show cell contents as text
580     * `image`:  cell contents are an image index, use column options to define images
581     * `color`:   cell contents are a ColorString and define color of following cell
582     * `indent`: cell contents are a number and define indentation of following cell
583     * `tree`:   same as indent, but user can open and close subtrees (treeview-like)
584 * Column options:
585     * `align=<value>`
586         * for `text` and `image`: content alignment within cells.
587           Available values: `left` (default), `center`, `right`, `inline`
588     * `width=<value>`
589         * for `text` and `image`: minimum width in em (default: `0`)
590         * for `indent` and `tree`: indent width in em (default: `1.5`)
591     * `padding=<value>`: padding left of the column, in em (default `0.5`).
592       Exception: defaults to 0 for indent columns
593     * `tooltip=<value>`: tooltip text (default: empty)
594     * `image` column options:
595         * `0=<value>` sets image for image index 0
596         * `1=<value>` sets image for image index 1
597         * `2=<value>` sets image for image index 2
598         * and so on; defined indices need not be contiguous empty or
599           non-numeric cells are treated as `0`.
600     * `color` column options:
601         * `span=<value>`: number of following columns to affect (default: infinite)
602
603 **Note**: do _not_ use a element name starting with `key_`; those names are reserved to
604 pass key press events to formspec!
605
606 Spatial Vectors
607 ---------------
608 * `vector.new(a[, b, c])`: returns a vector:
609     * A copy of `a` if `a` is a vector.
610     * `{x = a, y = b, z = c}`, if all `a, b, c` are defined
611 * `vector.direction(p1, p2)`: returns a vector
612 * `vector.distance(p1, p2)`: returns a number
613 * `vector.length(v)`: returns a number
614 * `vector.normalize(v)`: returns a vector
615 * `vector.floor(v)`: returns a vector, each dimension rounded down
616 * `vector.round(v)`: returns a vector, each dimension rounded to nearest int
617 * `vector.apply(v, func)`: returns a vector
618 * `vector.equals(v1, v2)`: returns a boolean
619
620 For the following functions `x` can be either a vector or a number:
621
622 * `vector.add(v, x)`: returns a vector
623 * `vector.subtract(v, x)`: returns a vector
624 * `vector.multiply(v, x)`: returns a scaled vector or Schur product
625 * `vector.divide(v, x)`: returns a scaled vector or Schur quotient
626
627 Helper functions
628 ----------------
629 * `dump2(obj, name="_", dumped={})`
630      * Return object serialized as a string, handles reference loops
631 * `dump(obj, dumped={})`
632     * Return object serialized as a string
633 * `math.hypot(x, y)`
634     * Get the hypotenuse of a triangle with legs x and y.
635       Useful for distance calculation.
636 * `math.sign(x, tolerance)`
637     * Get the sign of a number.
638       Optional: Also returns `0` when the absolute value is within the tolerance (default: `0`)
639 * `string.split(str, separator=",", include_empty=false, max_splits=-1,
640 * sep_is_pattern=false)`
641     * If `max_splits` is negative, do not limit splits.
642     * `sep_is_pattern` specifies if separator is a plain string or a pattern (regex).
643     * e.g. `string:split("a,b", ",") == {"a","b"}`
644 * `string:trim()`
645     * e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"`
646 * `minetest.is_yes(arg)`
647     * returns whether `arg` can be interpreted as yes
648 * `minetest.get_us_time()`
649     * returns time with microsecond precision. May not return wall time.
650 * `table.copy(table)`: returns a table
651     * returns a deep copy of `table`
652
653 `minetest` namespace reference
654 ------------------------------
655
656 ### Utilities
657
658 * `minetest.get_current_modname()`: returns the currently loading mod's name, when we are loading a mod
659 * `minetest.get_version()`: returns a table containing components of the
660    engine version.  Components:
661     * `project`: Name of the project, eg, "Minetest"
662     * `string`: Simple version, eg, "1.2.3-dev"
663     * `hash`: Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty"
664   Use this for informational purposes only. The information in the returned
665   table does not represent the capabilities of the engine, nor is it
666   reliable or verifyable. Compatible forks will have a different name and
667   version entirely. To check for the presence of engine features, test
668   whether the functions exported by the wanted features exist. For example:
669   `if core.nodeupdate then ... end`.
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.register_globalstep(func(dtime))`
682     * Called every client environment step, usually interval of 0.1s
683 * `minetest.register_on_shutdown(func())`
684     * Called before client shutdown
685     * **Warning**: If the client terminates abnormally (i.e. crashes), the registered
686       callbacks **will likely not be run**. Data should be saved at
687       semi-frequent intervals as well as on server shutdown.
688 * `minetest.register_on_receiving_chat_message(func(name, message))`
689     * Called always when a client receive a message
690     * Return `true` to mark the message as handled, which means that it will not be shown to chat
691 * `minetest.register_on_sending_chat_message(func(name, message))`
692     * Called always when a client send a message from chat
693     * Return `true` to mark the message as handled, which means that it will not be sent to server
694 * `minetest.register_chatcommand(cmd, chatcommand definition)`
695     * Adds definition to minetest.registered_chatcommands
696 * `minetest.register_on_death(func())`
697     * Called when the local player dies
698 * `minetest.register_on_hp_modification(func(hp))`
699     * Called when server modified player's HP
700 * `minetest.register_on_damage_taken(func(hp))`
701     * Called when the local player take damages
702 * `minetest.register_on_formspec_input(func(formname, fields))`
703     * Called when a button is pressed in the local player's inventory form
704     * Newest functions are called first
705     * If function returns `true`, remaining functions are not called
706 * `minetest.register_on_dignode(func(pos, node))`
707     * Called when the local player digs a node
708     * Newest functions are called first
709     * If any function returns true, the node isn't dug
710 * `minetest.register_on_punchnode(func(pos, node))`
711     * Called when the local player punches a node
712     * Newest functions are called first
713     * If any function returns true, the punch is ignored
714 ### Sounds
715 * `minetest.sound_play(spec, parameters)`: returns a handle
716     * `spec` is a `SimpleSoundSpec`
717     * `parameters` is a sound parameter table
718 * `minetest.sound_stop(handle)`
719
720 ### Timing
721 * `minetest.after(time, func, ...)`
722     * Call the function `func` after `time` seconds, may be fractional
723     * Optional: Variable number of arguments that are passed to `func`
724 ### Map
725 * `minetest.get_node(pos)`
726     * Returns the node at the given position as table in the format
727       `{name="node_name", param1=0, param2=0}`, returns `{name="ignore", param1=0, param2=0}`
728       for unloaded areas.
729 * `minetest.get_node_or_nil(pos)`
730     * Same as `get_node` but returns `nil` for unloaded areas.
731 ### Misc.
732 * `minetest.parse_json(string[, nullvalue])`: returns something
733     * Convert a string containing JSON data into the Lua equivalent
734     * `nullvalue`: returned in place of the JSON null; defaults to `nil`
735     * On success returns a table, a string, a number, a boolean or `nullvalue`
736     * On failure outputs an error message and returns `nil`
737     * Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}`
738 * `minetest.write_json(data[, styled])`: returns a string or `nil` and an error message
739     * Convert a Lua table into a JSON string
740     * styled: Outputs in a human-readable format if this is set, defaults to false
741     * Unserializable things like functions and userdata are saved as null.
742     * **Warning**: JSON is more strict than the Lua table format.
743         1. You can only use strings and positive integers of at least one as keys.
744         2. You can not mix string and integer keys.
745            This is due to the fact that JSON has two distinct array and object values.
746     * Example: `write_json({10, {a = false}})`, returns `"[10, {\"a\": false}]"`
747 * `minetest.serialize(table)`: returns a string
748     * Convert a table containing tables, strings, numbers, booleans and `nil`s
749       into string form readable by `minetest.deserialize`
750     * Example: `serialize({foo='bar'})`, returns `'return { ["foo"] = "bar" }'`
751 * `minetest.deserialize(string)`: returns a table
752     * Convert a string returned by `minetest.deserialize` into a table
753     * `string` is loaded in an empty sandbox environment.
754     * Will load functions, but they cannot access the global environment.
755     * Example: `deserialize('return { ["foo"] = "bar" }')`, returns `{foo='bar'}`
756     * Example: `deserialize('print("foo")')`, returns `nil` (function call fails)
757         * `error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)`
758 * `minetest.compress(data, method, ...)`: returns `compressed_data`
759     * Compress a string of data.
760     * `method` is a string identifying the compression method to be used.
761     * Supported compression methods:
762     *     Deflate (zlib): `"deflate"`
763     * `...` indicates method-specific arguments.  Currently defined arguments are:
764     *     Deflate: `level` - Compression level, `0`-`9` or `nil`.
765 * `minetest.decompress(compressed_data, method, ...)`: returns data
766     * Decompress a string of data (using ZLib).
767     * See documentation on `minetest.compress()` for supported compression methods.
768     * currently supported.
769     * `...` indicates method-specific arguments. Currently, no methods use this.
770 * `minetest.encode_base64(string)`: returns string encoded in base64
771     * Encodes a string in base64.
772 * `minetest.decode_base64(string)`: returns string
773     * Decodes a string encoded in base64.
774 * `core.gettext(string) : returns string
775     * look up the translation of a string in the gettext message catalog
776 * `fgettext_ne(string, ...)`
777     * call core.gettext(string), replace "$1"..."$9" with the given
778       extra arguments and return the result
779 * `fgettext(string, ...)` : returns string
780     * same as fgettext_ne(), but calls core.formspec_escape before returning result
781 * `show_formspec(formname, formspec)` : returns true on success
782         * Shows a formspec to the player
783 Class reference
784 ---------------
785
786 ### `Settings`
787 An interface to read config files in the format of `minetest.conf`.
788
789 It can be created via `Settings(filename)`.
790
791 #### Methods
792 * `get(key)`: returns a value
793 * `get_bool(key)`: returns a boolean
794 * `set(key, value)`
795 * `remove(key)`: returns a boolean (`true` for success)
796 * `get_names()`: returns `{key1,...}`
797 * `write()`: returns a boolean (`true` for success)
798     * write changes to file
799 * `to_table()`: returns `{[key1]=value1,...}`
800
801 Definition tables
802 -----------------
803
804 ### Chat command definition (`register_chatcommand`)
805
806     {
807         params = "<name> <privilege>", -- Short parameter description
808         description = "Remove privilege from player", -- Full description
809         privs = {privs=true}, -- Require the "privs" privilege to run
810         func = function(name, param), -- Called when command is run.
811                                       -- Returns boolean success and text output.
812     }