You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1245 lines
50 KiB

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