Optional dependencies and properly handle mod name conflicts again
[oweals/minetest.git] / doc / lua_api.txt
1 Minetest Lua Modding API Reference 0.4.6
2 ========================================
3 More information at http://c55.me/minetest/
4
5 Introduction
6 -------------
7 Content and functionality can be added to Minetest 0.4 by using Lua
8 scripting in run-time loaded mods.
9
10 A mod is a self-contained bunch of scripts, textures and other related
11 things that is loaded by and interfaces with Minetest.
12
13 Mods are contained and ran solely on the server side. Definitions and media
14 files are automatically transferred to the client.
15
16 If you see a deficiency in the API, feel free to attempt to add the
17 functionality in the engine and API. You can send such improvements as
18 source code patches to <celeron55@gmail.com>.
19
20 Programming in Lua
21 -------------------
22 If you have any difficulty in understanding this, please read:
23   http://www.lua.org/pil/
24
25 Startup
26 --------
27 Mods are loaded during server startup from the mod load paths by running
28 the init.lua scripts in a shared environment.
29
30 Paths
31 -----
32 RUN_IN_PLACE=1: (Windows release, local build)
33  $path_user:  Linux:    <build directory>
34               Windows:  <build directory>
35  $path_share: Linux:    <build directory>
36               Windows:  <build directory>
37
38 RUN_IN_PLACE=0: (Linux release)
39  $path_share: Linux:    /usr/share/minetest
40               Windows:  <install directory>/minetest-0.4.x
41  $path_user:  Linux:    ~/.minetest
42               Windows:  C:/users/<user>/AppData/minetest (maybe)
43
44 Games
45 -----
46 Games are looked up from:
47   $path_share/games/gameid/
48   $path_user/games/gameid/
49 where gameid is unique to each game.
50
51 The game directory contains the file game.conf, which contains these fields:
52   name = <Human-readable full name of the game>
53   common_mods = <Comma-separated list of common mods>
54 eg.
55   name = Minetest
56   common_mods = bucket, default, doors, fire, stairs
57
58 Common mods are loaded from the pseudo-game "common".
59
60 The game directory can contain the file minetest.conf, which will be used
61 to set default settings when running the particular game.
62
63 Mod load path
64 -------------
65 Generic:
66   $path_share/games/gameid/mods/
67   $path_share/mods/gameid/
68   $path_user/games/gameid/mods/
69   $path_user/mods/gameid/ <-- User-installed mods
70   $worldpath/worldmods/
71
72 In a run-in-place version (eg. the distributed windows version):
73   minetest-0.4.x/games/gameid/mods/
74   minetest-0.4.x/mods/gameid/ <-- User-installed mods
75   minetest-0.4.x/worlds/worldname/worldmods/
76
77 On an installed version on linux:
78   /usr/share/minetest/games/gameid/mods/
79   ~/.minetest/mods/gameid/ <-- User-installed mods
80   ~/.minetest/worlds/worldname/worldmods
81
82 Mod load path for world-specific games
83 --------------------------------------
84 It is possible to include a game in a world; in this case, no mods or
85 games are loaded or checked from anywhere else.
86
87 This is useful for eg. adventure worlds.
88
89 This happens if the following directory exists:
90   $world/game/
91
92 Mods should be then be placed in:
93   $world/game/mods/
94
95 Modpack support
96 ----------------
97 Mods can be put in a subdirectory, if the parent directory, which otherwise
98 should be a mod, contains a file named modpack.txt. This file shall be
99 empty, except for lines starting with #, which are comments.
100
101 Mod directory structure
102 ------------------------
103 mods
104 |-- modname
105 |   |-- depends.txt
106 |   |-- init.lua
107 |   |-- textures
108 |   |   |-- modname_stuff.png
109 |   |   `-- modname_something_else.png
110 |   |-- sounds
111 |   |-- media
112 |   `-- <custom data>
113 `-- another
114
115 modname:
116   The location of this directory can be fetched by using
117   minetest.get_modpath(modname)
118
119 depends.txt:
120   List of mods that have to be loaded before loading this mod.
121   A single line contains a single modname.
122
123   Optional dependencies can be defined by appending a question mark
124   to a single modname. Their meaning is that if the specified mod
125   is missing, that does not prevent this mod from being loaded.
126
127 optdepends.txt:
128   An alternative way of specifying optional dependencies.
129   Like depends.txt, a single line contains a single modname.
130
131   NOTE: This file exists for compatibility purposes only and
132   support for it will be removed from the engine by the end of 2013.
133
134 init.lua:
135   The main Lua script. Running this script should register everything it
136   wants to register. Subsequent execution depends on minetest calling the
137   registered callbacks.
138
139   minetest.setting_get(name) and minetest.setting_getbool(name) can be used
140   to read custom or existing settings at load time, if necessary.
141
142 textures, sounds, media:
143   Media files (textures, sounds, whatever) that will be transferred to the
144   client and will be available for use by the mod.
145
146 Naming convention for registered textual names
147 ----------------------------------------------
148 Registered names should generally be in this format:
149   "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
150
151 This is to prevent conflicting names from corrupting maps and is
152 enforced by the mod loader.
153
154 Example: mod "experimental", ideal item/node/entity name "tnt":
155          -> the name should be "experimental:tnt".
156
157 Enforcement can be overridden by prefixing the name with ":". This can
158 be used for overriding the registrations of some other mod.
159
160 Example: Any mod can redefine experimental:tnt by using the name
161          ":experimental:tnt" when registering it.
162 (also that mod is required to have "experimental" as a dependency)
163
164 The ":" prefix can also be used for maintaining backwards compatibility.
165
166 Aliases
167 -------
168 Aliases can be added by using minetest.register_alias(name, convert_to)
169
170 This will make Minetest to convert things called name to things called
171 convert_to.
172
173 This can be used for maintaining backwards compatibility.
174
175 This can be also used for setting quick access names for things, eg. if
176 you have an item called epiclylongmodname:stuff, you could do
177   minetest.register_alias("stuff", "epiclylongmodname:stuff")
178 and be able to use "/giveme stuff".
179
180 Textures
181 --------
182 Mods should generally prefix their textures with modname_, eg. given
183 the mod name "foomod", a texture could be called
184   "foomod_foothing.png"
185
186 Textures are referred to by their complete name, or alternatively by
187 stripping out the file extension:
188   eg. foomod_foothing.png
189   eg. foomod_foothing
190
191 Sounds
192 -------
193 Only OGG files are supported.
194
195 For positional playing of sounds, only single-channel (mono) files are
196 supported. Otherwise OpenAL will play them non-positionally.
197
198 Mods should generally prefix their sounds with modname_, eg. given
199 the mod name "foomod", a sound could be called
200   "foomod_foosound.ogg"
201
202 Sounds are referred to by their name with a dot, a single digit and the
203 file extension stripped out.  When a sound is played, the actual sound file
204 is chosen randomly from the matching sounds.
205
206 When playing the sound "foomod_foosound", the sound is chosen randomly
207 from the available ones of the following files:
208   foomod_foosound.ogg
209   foomod_foosound.0.ogg
210   foomod_foosound.1.ogg
211   ...
212   foomod_foosound.9.ogg
213
214 Examples of sound parameter tables:
215 -- Play locationless on all clients
216 {
217     gain = 1.0, -- default
218 }
219 -- Play locationless to a player
220 {
221     to_player = name,
222     gain = 1.0, -- default
223 }
224 -- Play in a location
225 {
226     pos = {x=1,y=2,z=3},
227     gain = 1.0, -- default
228     max_hear_distance = 32, -- default
229 }
230 -- Play connected to an object, looped
231 {
232     object = <an ObjectRef>,
233     gain = 1.0, -- default
234     max_hear_distance = 32, -- default
235     loop = true, -- only sounds connected to objects can be looped
236 }
237
238 SimpleSoundSpec:
239 eg. ""
240 eg. "default_place_node"
241 eg. {}
242 eg. {name="default_place_node"}
243 eg. {name="default_place_node", gain=1.0}
244
245 Registered definitions of stuff
246 --------------------------------
247 Anything added using certain minetest.register_* functions get added to
248 the global minetest.registered_* tables.
249
250 minetest.register_entity(name, prototype table)
251  -> minetest.registered_entities[name]
252
253 minetest.register_node(name, node definition)
254  -> minetest.registered_items[name]
255  -> minetest.registered_nodes[name]
256
257 minetest.register_tool(name, item definition)
258  -> minetest.registered_items[name]
259
260 minetest.register_craftitem(name, item definition)
261  -> minetest.registered_items[name]
262
263 Note that in some cases you will stumble upon things that are not contained
264 in these tables (eg. when a mod has been removed). Always check for
265 existence before trying to access the fields.
266
267 Example: If you want to check the drawtype of a node, you could do:
268
269 local function get_nodedef_field(nodename, fieldname)
270     if not minetest.registered_nodes[nodename] then
271         return nil
272     end
273     return minetest.registered_nodes[nodename][fieldname]
274 end
275 local drawtype = get_nodedef_field(nodename, "drawtype")
276
277 Example: minetest.get_item_group(name, group) has been implemented as:
278
279 function minetest.get_item_group(name, group)
280     if not minetest.registered_items[name] or not
281             minetest.registered_items[name].groups[group] then
282         return 0
283     end
284     return minetest.registered_items[name].groups[group]
285 end
286
287 Nodes
288 ------
289 Nodes are the bulk data of the world: cubes and other things that take the
290 space of a cube. Huge amounts of them are handled efficiently, but they
291 are quite static.
292
293 The definition of a node is stored and can be accessed by name in
294   minetest.registered_nodes[node.name]
295 See "Registered definitions of stuff".
296
297 Nodes are passed by value between Lua and the engine.
298 They are represented by a table:
299   {name="name", param1=num, param2=num}
300
301 param1 and param2 are 8 bit integers. The engine uses them for certain
302 automated functions. If you don't use these functions, you can use them to
303 store arbitrary values.
304
305 The functions of param1 and param2 are determined by certain fields in the
306 node definition:
307 param1 is reserved for the engine when paramtype != "none":
308   paramtype = "light"
309   ^ The value stores light with and without sun in it's
310     upper and lower 4 bits.
311 param2 is reserved for the engine when any of these are used:
312   liquidtype == "flowing"
313   ^ The level and some flags of the liquid is stored in param2
314   drawtype == "flowingliquid"
315   ^ The drawn liquid level is read from param2
316   drawtype == "torchlike"
317   drawtype == "signlike"
318   paramtype2 == "wallmounted"
319   ^ The rotation of the node is stored in param2. You can make this value
320     by using minetest.dir_to_wallmounted().
321   paramtype2 == "facedir"
322   ^ The rotation of the node is stored in param2. Furnaces and chests are
323     rotated this way. Can be made by using minetest.dir_to_facedir().
324     Values range 0 - 23
325     facedir modulo 4 = axisdir
326     0 = y+    1 = z+    2 = z-    3 = x+    4 = x-    5 = y-
327     facedir's two less significant bits are rotation around the axis
328
329 Nodes can also contain extra data. See "Node Metadata".
330
331 Node drawtypes
332 ---------------
333 There are a bunch of different looking node types. These are mostly just
334 copied from Minetest 0.3; more may be made in the future.
335
336 Look for examples in games/minimal or games/minetest_game.
337
338 - normal
339 - airlike
340 - liquid
341 - flowingliquid
342 - glasslike
343 - glasslike_framed
344 - allfaces
345 - allfaces_optional
346 - torchlike
347 - signlike
348 - plantlike
349 - fencelike
350 - raillike
351 - nodebox -- See below. EXPERIMENTAL
352
353 Node boxes
354 -----------
355 Node selection boxes are defined using "node boxes"
356
357 The "nodebox" node drawtype allows defining visual of nodes consisting of
358 arbitrary number of boxes. It allows defining stuff like stairs. Only the
359 "fixed" box type is supported for these.
360 ^ Please note that this is still experimental, and may be incompatibly
361   changed in the future.
362
363 A nodebox is defined as any of:
364 {
365     -- A normal cube; the default in most things
366     type = "regular"
367 }
368 {
369     -- A fixed box (facedir param2 is used, if applicable)
370     type = "fixed",
371     fixed = box OR {box1, box2, ...}
372 }
373 {
374     -- A box like the selection box for torches
375     -- (wallmounted param2 is used, if applicable)
376     type = "wallmounted",
377     wall_top = box,
378     wall_bottom = box,
379     wall_side = box
380 }
381
382 A box is defined as:
383   {x1, y1, z1, x2, y2, z2}
384 A box of a regular node would look like:
385   {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
386
387 Ore types
388 ---------------
389 These tell in what manner the ore is generated.
390 All default ores are of the uniformly-distributed scatter type.
391
392 - scatter
393     Randomly chooses a location and generates a cluster of ore.
394     If noise_params is specified, the ore will be placed if the 3d perlin noise at 
395     that point is greater than the noise_threshhold, giving the ability to create a non-equal
396     distribution of ore.
397 - sheet
398     Creates a sheet of ore in a blob shape according to the 2d perlin noise described by noise_params.
399     The relative height of the sheet can be controlled by the same perlin noise as well, by specifying
400     a non-zero 'scale' parameter in noise_params.  IMPORTANT: The noise is not transformed by offset or
401     scale when comparing against the noise threshhold, but scale is used to determine relative height.
402     The height of the blob is randomly scattered, with a maximum height of clust_size.
403     clust_scarcity and clust_num_ores are ignored.
404     This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
405 - claylike - NOT YET IMPLEMENTED
406     Places ore if there are no more than clust_scarcity number of specified nodes within a Von Neumann
407     neighborhood of clust_size radius.
408
409 Ore attributes
410 -------------------
411 Currently supported flags:  absheight
412  - absheight
413     Also produce this same ore between the height range of -height_max and -height_min.
414     Useful for having ore in sky realms without having to duplicate ore entries.
415
416 HUD element types
417 -------------------
418 The position field is used for all element types.
419 To account for differing resolutions, the position coordinates are the percentage of the screen,
420 ranging in value from 0 to 1.
421 The name field is not yet used, but should contain a description of what the HUD element represents.
422 The direction field is the direction in which something is drawn.
423 0 draws from left to right, 1 draws from right to left, 2 draws from top to bottom, and 3 draws from bottom to top.
424 The alignment field specifies how the item will be aligned. It ranges from -1 to 1,
425 with 0 being the center, -1 is moved to the left/up, and 1 is to the right/down. Fractional
426 values can be used.
427 The offset field specifies a pixel offset from the position. Contrary to position,
428 the offset is not scaled to screen size. This allows for some precisely-positioned
429 items in the HUD.
430 Below are the specific uses for fields in each type; fields not listed for that type are ignored.
431
432 Note: Future revisions to the HUD API may be incompatible; the HUD API is still in the experimental stages.
433
434 - image
435     Displays an image on the HUD.
436         - scale: The scale of the image, with 1 being the original texture size.
437              Only the X coordinate scale is used.
438     - text: The name of the texture that is displayed.
439     - alignment: The alignment of the image.
440     - offset: offset in pixels from position.
441 - text
442     Displays text on the HUD.
443     - scale: Defines the bounding rectangle of the text.
444              A value such as {x=100, y=100} should work.
445     - text: The text to be displayed in the HUD element.
446     - number: An integer containing the RGB value of the color used to draw the text.
447               Specify 0xFFFFFF for white text, 0xFF0000 for red, and so on.
448     - alignment: The alignment of the text.
449     - offset: offset in pixels from position.
450 - statbar
451     Displays a horizontal bar made up of half-images.
452     - text: The name of the texture that is used.
453     - number: The number of half-textures that are displayed.
454               If odd, will end with a vertically center-split texture.
455     - direction
456     - offset: offset in pixels from position.
457 - inventory
458     - text: The name of the inventory list to be displayed.
459     - number: Number of items in the inventory to be displayed.
460     - item: Position of item that is selected.
461     - direction
462
463 Representations of simple things
464 --------------------------------
465 Position/vector:
466   {x=num, y=num, z=num}
467 Currently the API does not provide any helper functions for addition,
468 subtraction and whatever; you can define those that you need yourself.
469
470 pointed_thing:
471   {type="nothing"}
472   {type="node", under=pos, above=pos}
473   {type="object", ref=ObjectRef}
474
475 Items
476 ------
477 Node (register_node):
478   A node from the world
479 Tool (register_tool):
480   A tool/weapon that can dig and damage things according to tool_capabilities
481 Craftitem (register_craftitem):
482   A miscellaneous item
483
484 Items and item stacks can exist in three formats:
485
486 Serialized; This is called stackstring or itemstring:
487 eg. 'default:dirt 5'
488 eg. 'default:pick_wood 21323'
489 eg. 'default:apple'
490
491 Table format:
492 eg. {name="default:dirt", count=5, wear=0, metadata=""} 
493     ^ 5 dirt nodes
494 eg. {name="default:pick_wood", count=1, wear=21323, metadata=""}
495     ^ a wooden pick about 1/3 weared out
496 eg. {name="default:apple", count=1, wear=0, metadata=""}
497     ^ an apple.
498
499 ItemStack:
500 C++ native format with many helper methods. Useful for converting between
501 formats. See the Class reference section for details.
502
503 When an item must be passed to a function, it can usually be in any of
504 these formats.
505
506 Groups
507 -------
508 In a number of places, there is a group table. Groups define the
509 properties of a thing (item, node, armor of entity, capabilities of
510 tool) in such a way that the engine and other mods can can interact with
511 the thing without actually knowing what the thing is.
512
513 Usage:
514 - Groups are stored in a table, having the group names with keys and the
515   group ratings as values. For example:
516     groups = {crumbly=3, soil=1}
517     ^ Default dirt (soil group actually currently not defined; TODO)
518     groups = {crumbly=2, soil=1, level=2, outerspace=1}
519     ^ A more special dirt-kind of thing
520 - Groups always have a rating associated with them. If there is no
521   useful meaning for a rating for an enabled group, it shall be 1.
522 - When not defined, the rating of a group defaults to 0. Thus when you
523   read groups, you must interpret nil and 0 as the same value, 0.
524
525 You can read the rating of a group for an item or a node by using
526   minetest.get_item_group(itemname, groupname)
527
528 Groups of items
529 ----------------
530 Groups of items can define what kind of an item it is (eg. wool).
531
532 Groups of nodes
533 ----------------
534 In addition to the general item things, groups are used to define whether
535 a node is destroyable and how long it takes to destroy by a tool.
536
537 Groups of entities
538 -------------------
539 For entities, groups are, as of now, used only for calculating damage.
540 The rating is the percentage of damage caused by tools with this damage group.
541 See "Entity damage mechanism".
542
543 object.get_armor_groups() -> a group-rating table (eg. {fleshy=100})
544 object.set_armor_groups({fleshy=30, cracky=80})
545
546 Groups of tools
547 ----------------
548 Groups in tools define which groups of nodes and entities they are
549 effective towards.
550
551 Groups in crafting recipes
552 ---------------------------
553 An example: Make meat soup from any meat, any water and any bowl
554 {
555     output = 'food:meat_soup_raw',
556     recipe = {
557         {'group:meat'},
558         {'group:water'},
559         {'group:bowl'},
560     },
561     -- preserve = {'group:bowl'}, -- Not implemented yet (TODO)
562 }
563 An another example: Make red wool from white wool and red dye
564 {
565     type = 'shapeless',
566     output = 'wool:red',
567     recipe = {'wool:white', 'group:dye,basecolor_red'},
568 }
569
570 Special groups
571 ---------------
572 - immortal: Disables the group damage system for an entity
573 - level: Can be used to give an additional sense of progression in the game.
574   - A larger level will cause eg. a weapon of a lower level make much less
575     damage, and get weared out much faster, or not be able to get drops
576     from destroyed nodes.
577   - 0 is something that is directly accessible at the start of gameplay
578   - There is no upper limit
579 - dig_immediate: (player can always pick up node without tool wear)
580   - 2: node is removed without tool wear after 0.5 seconds or so
581        (rail, sign)
582   - 3: node is removed without tool wear immediately (torch)
583 - disable_jump: Player (and possibly other things) cannot jump from node
584 - fall_damage_add_percent: damage speed = speed * (1 + value/100)
585 - bouncy: value is bounce speed in percent
586 - falling_node: if there is no walkable block under the node it will fall
587 - attached_node: if the node under it is not a walkable block the node will be
588                   dropped as an item. If the node is wallmounted the
589                   wallmounted direction is checked.
590
591 Known damage and digging time defining groups
592 ----------------------------------------------
593 - crumbly: dirt, sand
594 - cracky: tough but crackable stuff like stone.
595 - snappy: something that can be cut using fine tools; eg. leaves, small
596           plants, wire, sheets of metal
597 - choppy: something that can be cut using force; eg. trees, wooden planks
598 - fleshy: Living things like animals and the player. This could imply
599           some blood effects when hitting.
600 - explody: Especially prone to explosions
601 - oddly_breakable_by_hand:
602    Can be added to nodes that shouldn't logically be breakable by the
603    hand but are. Somewhat similar to dig_immediate, but times are more
604    like {[1]=3.50,[2]=2.00,[3]=0.70} and this does not override the
605    speed of a tool if the tool can dig at a faster speed than this
606    suggests for the hand.
607
608 Examples of custom groups
609 --------------------------
610 Item groups are often used for defining, well, //groups of items//.
611 - meat: any meat-kind of a thing (rating might define the size or healing
612   ability or be irrelevant - it is not defined as of yet)
613 - eatable: anything that can be eaten. Rating might define HP gain in half
614   hearts.
615 - flammable: can be set on fire. Rating might define the intensity of the
616   fire, affecting eg. the speed of the spreading of an open fire.
617 - wool: any wool (any origin, any color)
618 - metal: any metal
619 - weapon: any weapon
620 - heavy: anything considerably heavy
621
622 Digging time calculation specifics
623 -----------------------------------
624 Groups such as **crumbly**, **cracky** and **snappy** are used for this
625 purpose. Rating is 1, 2 or 3. A higher rating for such a group implies
626 faster digging time.
627
628 The **level** group is used to limit the toughness of nodes a tool can dig
629 and to scale the digging times / damage to a greater extent.
630
631 ^ PLEASE DO UNDERSTAND THIS, otherwise you cannot use the system to it's
632   full potential.
633
634 Tools define their properties by a list of parameters for groups. They
635 cannot dig other groups; thus it is important to use a standard bunch of
636 groups to enable interaction with tools.
637
638 **Tools define:**
639   * Full punch interval
640   * Maximum drop level
641   * For an arbitrary list of groups:
642     * Uses (until the tool breaks)
643     * Maximum level (usually 0, 1, 2 or 3)
644     * Digging times
645     * Damage groups
646
647 **Full punch interval**:
648 When used as a weapon, the tool will do full damage if this time is spent
649 between punches. If eg. half the time is spent, the tool will do half
650 damage.
651
652 **Maximum drop level**
653 Suggests the maximum level of node, when dug with the tool, that will drop
654 it's useful item. (eg. iron ore to drop a lump of iron).
655 - This is not automated; it is the responsibility of the node definition
656   to implement this
657
658 **Uses**
659 Determines how many uses the tool has when it is used for digging a node,
660 of this group, of the maximum level. For lower leveled nodes, the use count
661 is multiplied by 3^leveldiff.
662 - uses=10, leveldiff=0 -> actual uses: 10
663 - uses=10, leveldiff=1 -> actual uses: 30
664 - uses=10, leveldiff=2 -> actual uses: 90
665
666 **Maximum level**
667 Tells what is the maximum level of a node of this group that the tool will
668 be able to dig.
669
670 **Digging times**
671 List of digging times for different ratings of the group, for nodes of the
672 maximum level.
673   * For example, as a lua table, ''times={2=2.00, 3=0.70}''. This would
674     result in the tool to be able to dig nodes that have a rating of 2 or 3
675     for this group, and unable to dig the rating 1, which is the toughest.
676     Unless there is a matching group that enables digging otherwise.
677
678 **Damage groups**
679 List of damage for groups of entities. See "Entity damage mechanism".
680
681 Example definition of the capabilities of a tool
682 -------------------------------------------------
683 tool_capabilities = {
684     full_punch_interval=1.5,
685     max_drop_level=1,
686     groupcaps={
687         crumbly={maxlevel=2, uses=20, times={[1]=1.60, [2]=1.20, [3]=0.80}}
688     }
689     damage_groups = {fleshy=2},
690 }
691
692 This makes the tool be able to dig nodes that fullfill both of these:
693 - Have the **crumbly** group
694 - Have a **level** group less or equal to 2
695
696 Table of resulting digging times:
697 crumbly        0     1     2     3     4  <- level
698      ->  0     -     -     -     -     -
699          1  0.80  1.60  1.60     -     -
700          2  0.60  1.20  1.20     -     -
701          3  0.40  0.80  0.80     -     -
702
703 level diff:    2     1     0    -1    -2
704
705 Table of resulting tool uses:
706      ->  0     -     -     -     -     -
707          1   180    60    20     -     -
708          2   180    60    20     -     -
709          3   180    60    20     -     -
710
711 Notes:
712 - At crumbly=0, the node is not diggable.
713 - At crumbly=3, the level difference digging time divider kicks in and makes
714   easy nodes to be quickly breakable.
715 - At level > 2, the node is not diggable, because it's level > maxlevel
716
717 Entity damage mechanism
718 ------------------------
719 Damage calculation:
720 damage = 0
721 foreach group in cap.damage_groups:
722     damage += cap.damage_groups[group] * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0)
723         * (object.armor_groups[group] / 100.0)
724         -- Where object.armor_groups[group] is 0 for inexisting values
725 return damage
726
727 Client predicts damage based on damage groups. Because of this, it is able to
728 give an immediate response when an entity is damaged or dies; the response is
729 pre-defined somehow (eg. by defining a sprite animation) (not implemented;
730 TODO).
731 - Currently a smoke puff will appear when an entity dies.
732
733 The group **immortal** completely disables normal damage.
734
735 Entities can define a special armor group, which is **punch_operable**. This
736 group disables the regular damage mechanism for players punching it by hand or
737 a non-tool item, so that it can do something else than take damage.
738
739 On the Lua side, every punch calls ''entity:on_punch(puncher,
740 time_from_last_punch, tool_capabilities, direction)''. This should never be
741 called directly, because damage is usually not handled by the entity itself.
742   * ''puncher'' is the object performing the punch. Can be nil. Should never be
743     accessed unless absolutely required, to encourage interoperability.
744   * ''time_from_last_punch'' is time from last punch (by puncher) or nil.
745   * ''tool_capabilities'' can be nil.
746   * ''direction'' is a unit vector, pointing from the source of the punch to
747     the punched object.
748
749 To punch an entity/object in Lua, call ''object:punch(puncher,
750 time_from_last_punch, tool_capabilities, direction)''.
751   * Return value is tool wear.
752   * Parameters are equal to the above callback.
753   * If ''direction'' is nil and ''puncher'' is not nil, ''direction'' will be
754     automatically filled in based on the location of ''puncher''.
755
756 Node Metadata
757 -------------
758 The instance of a node in the world normally only contains the three values
759 mentioned in "Nodes". However, it is possible to insert extra data into a
760 node. It is called "node metadata"; See "NodeMetaRef".
761
762 Metadata contains two things:
763 - A key-value store
764 - An inventory
765
766 Some of the values in the key-value store are handled specially:
767 - formspec: Defines a right-click inventory menu. See "Formspec".
768 - infotext: Text shown on the screen when the node is pointed at
769
770 Example stuff:
771
772 local meta = minetest.env:get_meta(pos)
773 meta:set_string("formspec",
774         "invsize[8,9;]"..
775         "list[context;main;0,0;8,4;]"..
776         "list[current_player;main;0,5;8,4;]")
777 meta:set_string("infotext", "Chest");
778 local inv = meta:get_inventory()
779 inv:set_size("main", 8*4)
780 print(dump(meta:to_table()))
781 meta:from_table({
782     inventory = {
783         main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", [10] = "", [11] = "", [12] = "", [13] = "", [14] = "default:cobble", [15] = "", [16] = "", [17] = "", [18] = "", [19] = "", [20] = "default:cobble", [21] = "", [22] = "", [23] = "", [24] = "", [25] = "", [26] = "", [27] = "", [28] = "", [29] = "", [30] = "", [31] = "", [32] = ""}
784     },
785     fields = {
786         formspec = "invsize[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
787         infotext = "Chest"
788     }
789 })
790
791 Formspec
792 --------
793 Formspec defines a menu. Currently not much else than inventories are
794 supported. It is a string, with a somewhat strange format.
795
796 Spaces and newlines can be inserted between the blocks, as is used in the
797 examples.
798
799 Examples:
800 - Chest:
801     invsize[8,9;]
802     list[context;main;0,0;8,4;]
803     list[current_player;main;0,5;8,4;]
804 - Furnace:
805     invsize[8,9;]
806     list[context;fuel;2,3;1,1;]
807     list[context;src;2,1;1,1;]
808     list[context;dst;5,1;2,2;]
809     list[current_player;main;0,5;8,4;]
810 - Minecraft-like player inventory
811     invsize[8,7.5;]
812     image[1,0.6;1,2;player.png]
813     list[current_player;main;0,3.5;8,4;]
814     list[current_player;craft;3,0;3,3;]
815     list[current_player;craftpreview;7,1;1,1;]
816
817 Elements:
818
819 size[<W>,<H>]
820 ^ Define the size of the menu in inventory slots
821 ^ deprecated: invsize[<W>,<H>;]
822
823 list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]
824 list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]
825 ^ Show an inventory list
826
827 image[<X>,<Y>;<W>,<H>;<texture name>]
828 ^ Show an image
829 ^ Position and size units are inventory slots
830
831 item_image[<X>,<Y>;<W>,<H>;<item name>]
832 ^ Show an inventory image of registered item/node
833 ^ Position and size units are inventory slots
834
835 background[<X>,<Y>;<W>,<H>;<texture name>]
836 ^ Use a background. Inventory rectangles are not drawn then.
837 ^ Position and size units are inventory slots
838 ^ Example for formspec 8x4 in 16x resolution: image shall be sized 8*16px x 4*16px
839
840 field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
841 ^ Textual field; will be sent to server when a button is clicked
842 ^ x and y position the field relative to the top left of the menu
843 ^ w and h are the size of the field
844 ^ fields are a set height, but will be vertically centred on h
845 ^ Position and size units are inventory slots
846 ^ name is the name of the field as returned in fields to on_receive_fields
847 ^ label, if not blank, will be text printed on the top left above the field
848 ^ default is the default value of the field
849   ^ default may contain variable references such as '${text}' which
850     will fill the value from the metadata value 'text'
851     ^ Note: no extra text or more than a single variable is supported ATM.
852
853 field[<name>;<label>;<default>]
854 ^ as above but without position/size units
855 ^ special field for creating simple forms, such as sign text input
856 ^ must be used without a size[] element
857 ^ a 'Proceed' button will be added automatically
858
859 textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
860 ^ same as fields above, but with multi-line input
861
862 label[<X>,<Y>;<label>]
863 ^ x and y work as per field
864 ^ label is the text on the label
865 ^ Position and size units are inventory slots
866
867 button[<X>,<Y>;<W>,<H>;<name>;<label>]
868 ^ Clickable button. When clicked, fields will be sent.
869 ^ x, y and name work as per field
870 ^ w and h are the size of the button
871 ^ label is the text on the button
872 ^ Position and size units are inventory slots
873
874 image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
875 ^ x, y, w, h, and name work as per button
876 ^ image is the filename of an image
877 ^ Position and size units are inventory slots
878
879 item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]
880 ^ x, y, w, h, name and label work as per button
881 ^ item name is the registered name of an item/node,
882   tooltip will be made out of its descritption
883 ^ Position and size units are inventory slots
884
885 button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]
886 ^ When clicked, fields will be sent and the form will quit.
887
888 image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
889 ^ When clicked, fields will be sent and the form will quit.
890
891 Inventory location:
892
893 - "context": Selected node metadata (deprecated: "current_name")
894 - "current_player": Player to whom the menu is shown
895 - "player:<name>": Any player
896 - "nodemeta:<X>,<Y>,<Z>": Any node metadata
897 - "detached:<name>": A detached inventory
898
899 Helper functions
900 -----------------
901 dump2(obj, name="_", dumped={})
902 ^ Return object serialized as a string, handles reference loops
903 dump(obj, dumped={})
904 ^ Return object serialized as a string
905 string:split(separator)
906 ^ eg. string:split("a,b", ",") == {"a","b"}
907 string:trim()
908 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
909 minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)"
910 ^ Convert position to a printable string
911 minetest.string_to_pos(string) -> position
912 ^ Same but in reverse
913 minetest.formspec_escape(string) -> string
914 ^ escapes characters like [, ], and \ that can not be used in formspecs
915
916 minetest namespace reference
917 -----------------------------
918 minetest.get_current_modname() -> string
919 minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
920 ^ Useful for loading additional .lua modules or static data from mod
921 minetest.get_modnames() -> list of installed mods
922 ^ Return a list of installed mods, sorted alphabetically
923 minetest.get_worldpath() -> eg. "/home/user/.minetest/world"
924 ^ Useful for storing custom data
925 minetest.is_singleplayer()
926 minetest.features
927 ^ table containing API feature flags: {foo=true, bar=true}
928 minetest.has_feature(arg) -> bool, missing_features
929 ^ arg: string or table in format {foo=true, bar=true}
930 ^ missing_features: {foo=true, bar=true}
931
932 minetest.debug(line)
933 ^ Always printed to stderr and logfile (print() is redirected here)
934 minetest.log(line)
935 minetest.log(loglevel, line)
936 ^ loglevel one of "error", "action", "info", "verbose"
937
938 Registration functions: (Call these only at load time)
939 minetest.register_entity(name, prototype table)
940 minetest.register_abm(abm definition)
941 minetest.register_node(name, node definition)
942 minetest.register_tool(name, item definition)
943 minetest.register_craftitem(name, item definition)
944 minetest.register_alias(name, convert_to)
945 minetest.register_craft(recipe)
946 minetest.register_ore(ore definition)
947
948 Global callback registration functions: (Call these only at load time)
949 minetest.register_globalstep(func(dtime))
950 ^ Called every server step, usually interval of 0.05s
951 minetest.register_on_shutdown(func())
952 ^ Called before server shutdown
953 ^ WARNING: If the server terminates abnormally (i.e. crashes), the registered
954            callbacks WILL LIKELY NOT BE RUN.  Data should be saved at
955            semi-frequent intervals as well as on server shutdown.
956 minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack))
957 ^ Called when a node has been placed
958 ^ If return true no item is taken from itemstack
959 ^ Deprecated: Use on_construct or after_place_node in node definition instead
960 minetest.register_on_dignode(func(pos, oldnode, digger))
961 ^ Called when a node has been dug.
962 ^ Deprecated: Use on_destruct or after_dig_node in node definition instead
963 minetest.register_on_punchnode(func(pos, node, puncher))
964 ^ Called when a node is punched
965 minetest.register_on_generated(func(minp, maxp, blockseed))
966 ^ Called after generating a piece of world. Modifying nodes inside the area
967   is a bit faster than usually.
968 minetest.register_on_newplayer(func(ObjectRef))
969 ^ Called after a new player has been created
970 minetest.register_on_dieplayer(func(ObjectRef))
971 ^ Called when a player dies
972 minetest.register_on_respawnplayer(func(ObjectRef))
973 ^ Called when player is to be respawned
974 ^ Called _before_ repositioning of player occurs
975 ^ return true in func to disable regular player placement
976 minetest.register_on_joinplayer(func(ObjectRef))
977 ^ Called when a player joins the game
978 minetest.register_on_leaveplayer(func(ObjectRef))
979 ^ Called when a player leaves the game
980 minetest.register_on_chat_message(func(name, message))
981 ^ Called always when a player says something
982 minetest.register_on_player_receive_fields(func(player, formname, fields))
983 ^ Called when a button is pressed in player's inventory form
984 ^ Newest functions are called first
985 ^ If function returns true, remaining functions are not called
986
987 Other registration functions:
988 minetest.register_chatcommand(cmd, chatcommand definition)
989 minetest.register_privilege(name, definition)
990 ^ definition: "description text"
991 ^ definition: {
992       description = "description text",
993       give_to_singleplayer = boolean, -- default: true
994   }
995 minetest.register_authentication_handler(handler)
996 ^ See minetest.builtin_auth_handler in builtin.lua for reference
997
998 Setting-related:
999 minetest.setting_set(name, value)
1000 minetest.setting_get(name) -> string or nil
1001 minetest.setting_getbool(name) -> boolean value or nil
1002 minetest.setting_get_pos(name) -> position or nil
1003 minetest.setting_save() -> nil, save all settings to config file
1004 minetest.add_to_creative_inventory(itemstring)
1005
1006 Authentication:
1007 minetest.notify_authentication_modified(name)
1008 ^ Should be called by the authentication handler if privileges change.
1009 ^ To report everybody, set name=nil.
1010 minetest.get_password_hash(name, raw_password)
1011 ^ Convert a name-password pair to a password hash that minetest can use
1012 minetest.string_to_privs(str) -> {priv1=true,...}
1013 minetest.privs_to_string(privs) -> "priv1,priv2,..."
1014 ^ Convert between two privilege representations
1015 minetest.set_player_password(name, password_hash)
1016 minetest.set_player_privs(name, {priv1=true,...})
1017 minetest.get_player_privs(name) -> {priv1=true,...}
1018 minetest.auth_reload()
1019 ^ These call the authentication handler
1020 minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
1021 ^ A quickhand for checking privileges
1022 minetest.get_player_ip(name) -> IP address string
1023
1024 Chat:
1025 minetest.chat_send_all(text)
1026 minetest.chat_send_player(name, text, prepend)
1027 ^ prepend: optional, if it is set to false "Server -!- " will not be prepended to the message
1028
1029 Inventory:
1030 minetest.get_inventory(location) -> InvRef
1031 ^ location = eg. {type="player", name="celeron55"}
1032                  {type="node", pos={x=, y=, z=}}
1033                  {type="detached", name="creative"}
1034 minetest.create_detached_inventory(name, callbacks) -> InvRef
1035 ^ callbacks: See "Detached inventory callbacks"
1036 ^ Creates a detached inventory. If it already exists, it is cleared.
1037 minetest.show_formspec(playername, formname, formspec)
1038 ^ playername: name of player to show formspec
1039 ^ formname: name passed to on_player_receive_fields callbacks
1040 ^           should follow "modname:<whatever>" naming convention
1041 ^ formspec: formspec to display
1042
1043 Item handling:
1044 minetest.inventorycube(img1, img2, img3)
1045 ^ Returns a string for making an image of a cube (useful as an item image)
1046 minetest.get_pointed_thing_position(pointed_thing, above)
1047 ^ Get position of a pointed_thing (that you can get from somewhere)
1048 minetest.dir_to_facedir(dir)
1049 ^ Convert a vector to a facedir value, used in param2 for paramtype2="facedir"
1050 minetest.dir_to_wallmounted(dir)
1051 ^ Convert a vector to a wallmounted value, used for paramtype2="wallmounted"
1052 minetest.get_node_drops(nodename, toolname)
1053 ^ Returns list of item names.
1054 ^ Note: This will be removed or modified in a future version.
1055 minetest.get_craft_result(input) -> output, decremented_input
1056 ^ input.method = 'normal' or 'cooking' or 'fuel'
1057 ^ input.width = for example 3
1058 ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
1059                               stack 5, stack 6, stack 7, stack 8, stack 9 }
1060 ^ output.item = ItemStack, if unsuccessful: empty ItemStack
1061 ^ output.time = number, if unsuccessful: 0
1062 ^ decremented_input = like input
1063 minetest.get_craft_recipe(output) -> input
1064 ^ returns last registered recipe for output item (node)
1065 ^ output is a node or item type such as 'default:torch'
1066 ^ input.method = 'normal' or 'cooking' or 'fuel'
1067 ^ input.width = for example 3
1068 ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
1069                               stack 5, stack 6, stack 7, stack 8, stack 9 }
1070 ^ input.items = nil if no recipe found
1071 minetest.get_all_craft_recipes(query item) -> table or nil
1072 ^ returns indexed table with all registered recipes for query item (node)
1073   or nil if no recipe was found
1074   recipe entry table:
1075   { 
1076    method = 'normal' or 'cooking' or 'fuel'
1077    width = 0-3, 0 means shapeless recipe
1078    items = indexed [1-9] table with recipe items
1079    output = string with item name and quantity
1080   }
1081   Example query for default:gold_ingot will return table:
1082   {
1083    1={type = "cooking", width = 3, output = "default:gold_ingot",
1084     items = {1 = "default:gold_lump"}},
1085    2={type = "normal", width = 1, output = "default:gold_ingot 9",
1086     items = {1 = "default:goldblock"}}
1087   }
1088 minetest.handle_node_drops(pos, drops, digger)
1089 ^ drops: list of itemstrings
1090 ^ Handles drops from nodes after digging: Default action is to put them into
1091   digger's inventory
1092 ^ Can be overridden to get different functionality (eg. dropping items on
1093   ground)
1094
1095 Rollbacks:
1096 minetest.rollback_get_last_node_actor(p, range, seconds) -> actor, p, seconds
1097 ^ Find who has done something to a node, or near a node
1098 ^ actor: "player:<name>", also "liquid".
1099 minetest.rollback_revert_actions_by(actor, seconds) -> bool, log messages
1100 ^ Revert latest actions of someone
1101 ^ actor: "player:<name>", also "liquid".
1102
1103 Defaults for the on_* item definition functions:
1104 (These return the leftover itemstack)
1105 minetest.item_place_node(itemstack, placer, pointed_thing)
1106 ^ Place item as a node
1107 minetest.item_place_object(itemstack, placer, pointed_thing)
1108 ^ Place item as-is
1109 minetest.item_place(itemstack, placer, pointed_thing)
1110 ^ Use one of the above based on what the item is.
1111 ^ Calls on_rightclick of pointed_thing.under if defined instead
1112 ^ Note: is not called when wielded item overrides on_place
1113 minetest.item_drop(itemstack, dropper, pos)
1114 ^ Drop the item
1115 minetest.item_eat(hp_change, replace_with_item)
1116 ^ Eat the item. replace_with_item can be nil.
1117
1118 Defaults for the on_punch and on_dig node definition callbacks:
1119 minetest.node_punch(pos, node, puncher)
1120 ^ Calls functions registered by minetest.register_on_punchnode()
1121 minetest.node_dig(pos, node, digger)
1122 ^ Checks if node can be dug, puts item into inventory, removes node
1123 ^ Calls functions registered by minetest.registered_on_dignodes()
1124
1125 Sounds:
1126 minetest.sound_play(spec, parameters) -> handle
1127 ^ spec = SimpleSoundSpec
1128 ^ parameters = sound parameter table
1129 minetest.sound_stop(handle)
1130
1131 Timing:
1132 minetest.after(time, func, ...)
1133 ^ Call function after time seconds
1134 ^ Optional: Variable number of arguments that are passed to func
1135
1136 Server:
1137 minetest.request_shutdown() -> request for server shutdown
1138 minetest.get_server_status() -> server status string
1139
1140 Bans:
1141 minetest.get_ban_list() -> ban list (same as minetest.get_ban_description(""))
1142 minetest.get_ban_description(ip_or_name) -> ban description (string)
1143 minetest.ban_player(name) -> ban a player
1144 minetest.unban_player_or_ip(name) -> unban player or IP address
1145
1146 Particles:
1147 minetest.add_particle(pos, velocity, acceleration, expirationtime,
1148     size, collisiondetection, texture, playername)
1149 ^ Spawn particle at pos with velocity and acceleration
1150 ^ Disappears after expirationtime seconds
1151 ^ collisiondetection: if true collides with physical objects
1152 ^ Uses texture (string)
1153 ^ Playername is optional, if specified spawns particle only on the player's client
1154
1155 minetest.add_particlespawner(amount, time,
1156     minpos, maxpos,
1157     minvel, maxvel,
1158     minacc, maxacc,
1159     minexptime, maxexptime,
1160     minsize, maxsize,
1161     collisiondetection, texture, playername)
1162 ^ Add a particlespawner, an object that spawns an amount of particles over time seconds
1163 ^ The particle's properties are random values in between the boundings:
1164 ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
1165 ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
1166 ^ collisiondetection: if true uses collisiondetection
1167 ^ Uses texture (string)
1168 ^ Playername is optional, if specified spawns particle only on the player's client
1169 ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
1170 ^ Returns and id
1171
1172 minetest.delete_particlespawner(id, player)
1173 ^ Delete ParticleSpawner with id (return value from add_particlespawner)
1174 ^ If playername is specified, only deletes on the player's client,
1175 ^ otherwise on all clients
1176
1177 Random:
1178 minetest.get_connected_players() -> list of ObjectRefs
1179 minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer
1180 ^ Gives a unique hash number for a node position (16+16+16=48bit)
1181 minetest.get_item_group(name, group) -> rating
1182 ^ Get rating of a group of an item. (0 = not in group)
1183 minetest.get_node_group(name, group) -> rating
1184 ^ Deprecated: An alias for the former.
1185 minetest.serialize(table) -> string
1186 ^ Convert a table containing tables, strings, numbers, booleans and nils
1187   into string form readable by minetest.deserialize
1188 ^ Example: serialize({foo='bar'}) -> 'return { ["foo"] = "bar" }'
1189 minetest.deserialize(string) -> table
1190 ^ Convert a string returned by minetest.deserialize into a table
1191 ^ String is loaded in an empty sandbox environment.
1192 ^ Will load functions, but they cannot access the global environment.
1193 ^ Example: deserialize('return { ["foo"] = "bar" }') -> {foo='bar'}
1194 ^ Example: deserialize('print("foo")') -> nil (function call fails)
1195   ^ error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)
1196
1197 Global objects:
1198 minetest.env - EnvRef of the server environment and world.
1199 ^ Using this you can access nodes and entities
1200
1201 Global tables:
1202 minetest.registered_items
1203 ^ List of registered items, indexed by name
1204 minetest.registered_nodes
1205 ^ List of registered node definitions, indexed by name
1206 minetest.registered_craftitems
1207 ^ List of registered craft item definitions, indexed by name
1208 minetest.registered_tools
1209 ^ List of registered tool definitions, indexed by name
1210 minetest.registered_entities
1211 ^ List of registered entity prototypes, indexed by name
1212 minetest.object_refs
1213 ^ List of object references, indexed by active object id
1214 minetest.luaentities
1215 ^ List of lua entities, indexed by active object id
1216
1217 Deprecated but defined for backwards compatibility:
1218 minetest.digprop_constanttime(time)
1219 minetest.digprop_stonelike(toughness)
1220 minetest.digprop_dirtlike(toughness)
1221 minetest.digprop_gravellike(toughness)
1222 minetest.digprop_woodlike(toughness)
1223 minetest.digprop_leaveslike(toughness)
1224 minetest.digprop_glasslike(toughness)
1225
1226 Class reference
1227 ----------------
1228 EnvRef: basically ServerEnvironment and ServerMap combined.
1229 methods:
1230 - set_node(pos, node)
1231 - add_node(pos, node): alias set_node(pos, node)
1232  ^ Set node at position (node = {name="foo", param1=0, param2=0})
1233 - remove_node(pos)
1234   ^ Equivalent to set_node(pos, "air")
1235 - get_node(pos)
1236   ^ Returns {name="ignore", ...} for unloaded area
1237 - get_node_or_nil(pos)
1238   ^ Returns nil for unloaded area
1239 - get_node_light(pos, timeofday) -> 0...15 or nil
1240   ^ timeofday: nil = current time, 0 = night, 0.5 = day
1241
1242 - place_node(pos, node)
1243   ^ Place node with the same effects that a player would cause
1244 - dig_node(pos)
1245   ^ Dig node with the same effects that a player would cause
1246 - punch_node(pos)
1247   ^ Punch node with the same effects that a player would cause
1248   
1249 - get_meta(pos) -- Get a NodeMetaRef at that position
1250 - get_node_timer(pos) -- Get NodeTimerRef
1251
1252 - add_entity(pos, name): Spawn Lua-defined entity at position
1253   ^ Returns ObjectRef, or nil if failed
1254 - add_item(pos, item): Spawn item
1255   ^ Returns ObjectRef, or nil if failed
1256 - get_player_by_name(name) -- Get an ObjectRef to a player
1257 - get_objects_inside_radius(pos, radius)
1258 - set_timeofday(val): val: 0...1; 0 = midnight, 0.5 = midday
1259 - get_timeofday()
1260 - find_node_near(pos, radius, nodenames) -> pos or nil
1261   ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
1262 - find_nodes_in_area(minp, maxp, nodenames) -> list of positions
1263   ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
1264 - get_perlin(seeddiff, octaves, persistence, scale)
1265   ^ Return world-specific perlin noise (int(worldseed)+seeddiff)
1266 - clear_objects()
1267   ^ clear all objects in the environments
1268 - line_of_sight(pos1,pos2,stepsize) ->true/false
1269   ^ checkif there is a direct line of sight between pos1 and pos2
1270   ^ pos1 First position
1271   ^ pos2 Second position
1272   ^ stepsize smaller gives more accurate results but requires more computing
1273              time. Default is 1.
1274 -find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm) -> table containing path
1275   ^ returns a table of 3d points representing a path from pos1 to pos2 or nil
1276   ^ pos1: start position
1277   ^ pos2: end position
1278   ^ searchdistance: number of blocks to search in each direction
1279   ^ max_jump: maximum height difference to consider walkable
1280   ^ max_drop: maximum height difference to consider droppable
1281   ^ algorithm: A*_noprefetch(default), A*, Dijkstra
1282 - spawn_tree (pos, {treedef})
1283   ^ spawns L-System tree at given pos with definition in treedef table
1284 treedef={
1285   axiom,         - string  initial tree axiom
1286   rules_a,       - string  rules set A
1287   rules_b,       - string  rules set B
1288   rules_c,       - string  rules set C
1289   rules_d,       - string  rules set D
1290   trunk,         - string  trunk node name
1291   leaves,        - string  leaves node name
1292   leaves2,       - string  secondary leaves node name
1293   leaves2_chance,- num     chance (0-100) to replace leaves with leaves2
1294   angle,         - num     angle in deg
1295   iterations,    - num     max # of iterations, usually 2 -5
1296   random_level,  - num     factor to lower nr of iterations, usually 0 - 3
1297   trunk_type,    - string  single/double/crossed) type of trunk: 1 node, 2x2 nodes or 3x3 in cross shape
1298   thin_branches, - boolean true -> use thin (1 node) branches
1299   fruit,         - string  fruit node name
1300   fruit_chance,  - num     chance (0-100) to replace leaves with fruit node
1301   seed,          - num     random seed
1302   }
1303
1304 Key for Special L-System Symbols used in Axioms
1305   G  - move forward one unit with the pen up
1306   F  - move forward one unit with the pen down drawing trunks and branches
1307   f  - move forward one unit with the pen down drawing leaves (100% chance)
1308   T  - move forward one unit with the pen down drawing trunks only
1309   R  - move forward one unit with the pen down placing fruit
1310   A  - replace with rules set A
1311   B  - replace with rules set B
1312   C  - replace with rules set C
1313   D  - replace with rules set D
1314   a  - replace with rules set A, chance 90%
1315   b  - replace with rules set B, chance 80%
1316   c  - replace with rules set C, chance 70%
1317   d  - replace with rules set D, chance 60%
1318   +  - yaw the turtle right by angle parameter
1319   -  - yaw the turtle left by angle parameter
1320   &  - pitch the turtle down by angle parameter
1321   ^  - pitch the turtle up by angle parameter
1322   /  - roll the turtle to the right by angle parameter
1323   *  - roll the turtle to the left by angle parameter
1324   [  - save in stack current state info
1325   ]  - recover from stack state info
1326
1327 Example usage: spawn small apple tree
1328 apple_tree={
1329   axiom="FFFFFAFFBF",
1330   rules_a="[&&&FFFFF&&FFFF][&&&++++FFFFF&&FFFF][&&&----FFFFF&&FFFF]",
1331   rules_b="[&&&++FFFFF&&FFFF][&&&--FFFFF&&FFFF][&&&------FFFFF&&FFFF]",
1332   trunk="default:tree",
1333   leaves="default:leaves",
1334   angle=30,
1335   iterations=2,
1336   random_level=0,
1337   trunk_type="single",
1338   thin_branches=true,
1339   fruit_chance=10,
1340   fruit="default:apple"
1341   }
1342 minetest.env:spawn_tree(pos,apple_tree)
1343
1344 Deprecated:
1345 - add_rat(pos): Add C++ rat object (no-op)
1346 - add_firefly(pos): Add C++ firefly object (no-op)
1347
1348 NodeMetaRef: Node metadata - reference extra data and functionality stored
1349              in a node
1350 - Can be gotten via minetest.env:get_nodemeta(pos)
1351 methods:
1352 - set_string(name, value)
1353 - get_string(name)
1354 - set_int(name, value)
1355 - get_int(name)
1356 - set_float(name, value)
1357 - get_float(name)
1358 - get_inventory() -> InvRef
1359 - to_table() -> nil or {fields = {...}, inventory = {list1 = {}, ...}}
1360 - from_table(nil or {})
1361   ^ See "Node Metadata"
1362   
1363 NodeTimerRef: Node Timers - a high resolution persistent per-node timer
1364 - Can be gotten via minetest.env:get_node_timer(pos)
1365 methods:
1366 - set(timeout,elapsed)
1367   ^ set a timer's state
1368   ^ timeout is in seconds, and supports fractional values (0.1 etc)
1369   ^ elapsed is in seconds, and supports fractional values (0.1 etc)
1370   ^ will trigger the node's on_timer function after timeout-elapsed seconds
1371 - start(timeout)
1372   ^ start a timer
1373   ^ equivelent to set(timeout,0)
1374 - stop()
1375   ^ stops the timer
1376 - get_timeout() -> current timeout in seconds
1377   ^ if timeout is 0, timer is inactive
1378 - get_elapsed() -> current elapsed time in seconds
1379   ^ the node's on_timer function will be called after timeout-elapsed seconds
1380 - is_started() -> boolean state of timer
1381   ^ returns true if timer is started, otherwise false
1382
1383 ObjectRef: Moving things in the game are generally these
1384 (basically reference to a C++ ServerActiveObject)
1385 methods:
1386 - remove(): remove object (after returning from Lua)
1387 - getpos() -> {x=num, y=num, z=num}
1388 - setpos(pos); pos={x=num, y=num, z=num}
1389 - moveto(pos, continuous=false): interpolated move
1390 - punch(puncher, time_from_last_punch, tool_capabilities, direction)
1391   ^ puncher = an another ObjectRef,
1392   ^ time_from_last_punch = time since last punch action of the puncher
1393   ^ direction: can be nil
1394 - right_click(clicker); clicker = an another ObjectRef
1395 - get_hp(): returns number of hitpoints (2 * number of hearts)
1396 - set_hp(hp): set number of hitpoints (2 * number of hearts)
1397 - get_inventory() -> InvRef
1398 - get_wield_list(): returns the name of the inventory list the wielded item is in
1399 - get_wield_index(): returns the index of the wielded item
1400 - get_wielded_item() -> ItemStack
1401 - set_wielded_item(item): replaces the wielded item, returns true if successful
1402 - set_armor_groups({group1=rating, group2=rating, ...})
1403 - set_animation({x=1,y=1}, frame_speed=15, frame_blend=0)
1404 - set_attach(parent, bone, position, rotation)
1405   ^ bone = string
1406   ^ position = {x=num, y=num, z=num} (relative)
1407   ^ rotation = {x=num, y=num, z=num}
1408 - set_detach()
1409 - set_bone_position(bone, position, rotation)
1410   ^ bone = string
1411   ^ position = {x=num, y=num, z=num} (relative)
1412   ^ rotation = {x=num, y=num, z=num}
1413 - set_properties(object property table)
1414 LuaEntitySAO-only: (no-op for other objects)
1415 - setvelocity({x=num, y=num, z=num})
1416 - getvelocity() -> {x=num, y=num, z=num}
1417 - setacceleration({x=num, y=num, z=num})
1418 - getacceleration() -> {x=num, y=num, z=num}
1419 - setyaw(radians)
1420 - getyaw() -> radians
1421 - settexturemod(mod)
1422 - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
1423 -           select_horiz_by_yawpitch=false)
1424   ^ Select sprite from spritesheet with optional animation and DM-style
1425     texture selection based on yaw relative to camera
1426 - get_entity_name() (DEPRECATED: Will be removed in a future version)
1427 - get_luaentity()
1428 Player-only: (no-op for other objects)
1429 - is_player(): true for players, false for others
1430 - get_player_name(): returns "" if is not a player
1431 - get_look_dir(): get camera direction as a unit vector
1432 - get_look_pitch(): pitch in radians
1433 - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
1434 - set_look_pitch(radians): sets look pitch
1435 - set_look_yaw(radians): sets look yaw
1436 - set_inventory_formspec(formspec)
1437   ^ Redefine player's inventory form
1438   ^ Should usually be called in on_joinplayer
1439 - get_inventory_formspec() -> formspec string
1440 - get_player_control(): returns table with player pressed keys
1441     {jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
1442 - get_player_control_bits(): returns integer with bit packed player pressed keys
1443     bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
1444 - set_physics_override(speed, jump, gravity)
1445     modifies per-player walking speed, jump height, and gravity.
1446     Values default to 1 and act as offsets to the physics settings 
1447     in minetest.conf. nil will keep the current setting.
1448 - hud_add(hud definition): add a HUD element described by HUD def, returns ID number on success
1449 - hud_remove(id): remove the HUD element of the specified id
1450 - hud_change(id, stat, value): change a value of a previously added HUD element
1451   ^ element stat values: position, name, scale, text, number, item, dir
1452 - hud_get(id): gets the HUD element definition structure of the specified ID
1453 - hud_set_flags(flags): sets specified HUD flags to true/false
1454   ^ flags: (is visible) hotbar, healthbar, crosshair, wielditem
1455   ^ pass a table containing a true/false value of each flag to be set or unset
1456   ^ if a flag is nil, the flag is not modified
1457
1458 InvRef: Reference to an inventory
1459 methods:
1460 - is_empty(listname): return true if list is empty
1461 - get_size(listname): get size of a list
1462 - set_size(listname, size): set size of a list
1463 - get_width(listname): get width of a list
1464 - set_width(listname, width): set width of list; currently used for crafting
1465 - get_stack(listname, i): get a copy of stack index i in list
1466 - set_stack(listname, i, stack): copy stack to index i in list
1467 - get_list(listname): return full list
1468 - set_list(listname, list): set full list (size will not change)
1469 - add_item(listname, stack): add item somewhere in list, returns leftover ItemStack
1470 - room_for_item(listname, stack): returns true if the stack of items
1471     can be fully added to the list
1472 - contains_item(listname, stack): returns true if the stack of items
1473     can be fully taken from the list
1474   remove_item(listname, stack): take as many items as specified from the list,
1475     returns the items that were actually removed (as an ItemStack)
1476 - get_location() -> location compatible to minetest.get_inventory(location)
1477                  -> {type="undefined"} in case location is not known
1478
1479 ItemStack: A stack of items.
1480 - Can be created via ItemStack(itemstack or itemstring or table or nil)
1481 methods:
1482 - is_empty(): return true if stack is empty
1483 - get_name(): returns item name (e.g. "default:stone")
1484 - get_count(): returns number of items on the stack
1485 - get_wear(): returns tool wear (0-65535), 0 for non-tools
1486 - get_metadata(): returns metadata (a string attached to an item stack)
1487 - clear(): removes all items from the stack, making it empty
1488 - replace(item): replace the contents of this stack (item can also
1489     be an itemstring or table)
1490 - to_string(): returns the stack in itemstring form
1491 - to_table(): returns the stack in Lua table form
1492 - get_stack_max(): returns the maximum size of the stack (depends on the item)
1493 - get_free_space(): returns get_stack_max() - get_count()
1494 - is_known(): returns true if the item name refers to a defined item type
1495 - get_definition(): returns the item definition table
1496 - get_tool_capabilities(): returns the digging properties of the item,
1497   ^ or those of the hand if none are defined for this item type
1498 - add_wear(amount): increases wear by amount if the item is a tool
1499 - add_item(item): put some item or stack onto this stack,
1500   ^ returns leftover ItemStack
1501 - item_fits(item): returns true if item or stack can be fully added to this one
1502 - take_item(n): take (and remove) up to n items from this stack
1503   ^ returns taken ItemStack
1504   ^ if n is omitted, n=1 is used
1505 - peek_item(n): copy (don't remove) up to n items from this stack
1506   ^ returns copied ItemStack
1507   ^ if n is omitted, n=1 is used
1508
1509 PseudoRandom: A pseudorandom number generator
1510 - Can be created via PseudoRandom(seed)
1511 methods:
1512 - next(): return next integer random number [0...32767]
1513 - next(min, max): return next integer random number [min...max]
1514                   (max - min) must be 32767 or <= 6553 due to the simple
1515                   implementation making bad distribution otherwise.
1516
1517 PerlinNoise: A perlin noise generator
1518 - Can be created via PerlinNoise(seed, octaves, persistence, scale)
1519 - Also minetest.env:get_perlin(seeddiff, octaves, persistence, scale)
1520 methods:
1521 - get2d(pos) -> 2d noise value at pos={x=,y=}
1522 - get3d(pos) -> 3d noise value at pos={x=,y=,z=}
1523
1524 Registered entities
1525 --------------------
1526 - Functions receive a "luaentity" as self:
1527   - It has the member .name, which is the registered name ("mod:thing")
1528   - It has the member .object, which is an ObjectRef pointing to the object
1529   - The original prototype stuff is visible directly via a metatable
1530 - Callbacks:
1531   - on_activate(self, staticdata)
1532     ^ Called when the object is instantiated.
1533   - on_step(self, dtime)
1534     ^ Called on every server tick (dtime is usually 0.05 seconds)
1535   - on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
1536     ^ Called when somebody punches the object.
1537     ^ Note that you probably want to handle most punches using the
1538       automatic armor group system.
1539     ^ puncher: ObjectRef (can be nil)
1540     ^ time_from_last_punch: Meant for disallowing spamming of clicks (can be nil)
1541     ^ tool_capabilities: capability table of used tool (can be nil)
1542     ^ dir: unit vector of direction of punch. Always defined. Points from
1543            the puncher to the punched.
1544   - on_rightclick(self, clicker)
1545   - get_staticdata(self)
1546     ^ Should return a string that will be passed to on_activate when
1547       the object is instantiated the next time.
1548
1549 Definition tables
1550 ------------------
1551
1552 Object Properties
1553 {
1554     hp_max = 1,
1555     physical = true,
1556     weight = 5,
1557     collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1558     visual = "cube"/"sprite"/"upright_sprite"/"mesh",
1559     visual_size = {x=1, y=1},
1560     mesh = "model",
1561     textures = {}, -- number of required textures depends on visual
1562     colors = {}, -- number of required colors depends on visual
1563     spritediv = {x=1, y=1},
1564     initial_sprite_basepos = {x=0, y=0},
1565     is_visible = true,
1566     makes_footstep_sound = false,
1567     automatic_rotate = false,
1568 }
1569
1570 Entity definition (register_entity)
1571 {
1572     (Deprecated: Everything in object properties is read directly from here)
1573     
1574     initial_properties = <initial object properties>,
1575
1576     on_activate = function(self, staticdata, dtime_s),
1577     on_step = function(self, dtime),
1578     on_punch = function(self, hitter),
1579     on_rightclick = function(self, clicker),
1580     get_staticdata = function(self),
1581     ^ Called sometimes; the string returned is passed to on_activate when
1582       the entity is re-activated from static state
1583     
1584     # Also you can define arbitrary member variables here
1585     myvariable = whatever,
1586 }
1587
1588 ABM (ActiveBlockModifier) definition (register_abm)
1589 {
1590     -- In the following two fields, also group:groupname will work.
1591     nodenames = {"default:lava_source"},
1592     neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
1593      ^ If left out or empty, any neighbor will do
1594     interval = 1.0, -- (operation interval)
1595     chance = 1, -- (chance of trigger is 1.0/this)
1596     action = func(pos, node, active_object_count, active_object_count_wider),
1597 }
1598
1599 Item definition (register_node, register_craftitem, register_tool)
1600 {
1601     description = "Steel Axe",
1602     groups = {}, -- key=name, value=rating; rating=1..3.
1603                     if rating not applicable, use 1.
1604                     eg. {wool=1, fluffy=3}
1605                         {soil=2, outerspace=1, crumbly=1}
1606                         {bendy=2, snappy=1},
1607                         {hard=1, metal=1, spikes=1}
1608     inventory_image = "default_tool_steelaxe.png",
1609     wield_image = "",
1610     wield_scale = {x=1,y=1,z=1},
1611     stack_max = 99,
1612     liquids_pointable = false,
1613     tool_capabilities = {
1614         full_punch_interval = 1.0,
1615         max_drop_level=0,
1616         groupcaps={
1617             -- For example:
1618             snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
1619             choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0}
1620         },
1621         damage_groups = {groupname=damage},
1622     }
1623     node_placement_prediction = nil,
1624     ^ If nil and item is node, prediction is made automatically
1625     ^ If nil and item is not a node, no prediction is made
1626     ^ If "" and item is anything, no prediction is made
1627     ^ Otherwise should be name of node which the client immediately places
1628       on ground when the player places the item. Server will always update
1629       actual result to client in a short moment.
1630     sound = {
1631         place = <SimpleSoundSpec>,
1632     }
1633
1634     on_place = func(itemstack, placer, pointed_thing),
1635     ^ Shall place item and return the leftover itemstack
1636     ^ default: minetest.item_place
1637     on_drop = func(itemstack, dropper, pos),
1638     ^ Shall drop item and return the leftover itemstack
1639     ^ default: minetest.item_drop
1640     on_use = func(itemstack, user, pointed_thing),
1641     ^  default: nil
1642     ^ Function must return either nil if no item shall be removed from
1643       inventory, or an itemstack to replace the original itemstack.
1644         eg. itemstack:take_item(); return itemstack
1645     ^ Otherwise, the function is free to do what it wants.
1646     ^ The default functions handle regular use cases.
1647 }
1648
1649 Tile definition:
1650 - "image.png"
1651 - {name="image.png", animation={Tile Animation definition}}
1652 - {name="image.png", backface_culling=bool}
1653   ^ backface culling only supported in special tiles
1654 - deprecated still supported field names:
1655   - image -> name
1656
1657 Tile animation definition:
1658 - {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}
1659
1660 Node definition (register_node)
1661 {
1662     <all fields allowed in item definitions>,
1663
1664     drawtype = "normal", -- See "Node drawtypes"
1665     visual_scale = 1.0,
1666     tiles = {tile definition 1, def2, def3, def4, def5, def6},
1667     ^ Textures of node; +Y, -Y, +X, -X, +Z, -Z (old field name: tile_images)
1668     ^ List can be shortened to needed length
1669     special_tiles = {tile definition 1, Tile definition 2},
1670     ^ Special textures of node; used rarely (old field name: special_materials)
1671     ^ List can be shortened to needed length
1672     alpha = 255,
1673     use_texture_alpha = false, -- Use texture's alpha channel
1674     post_effect_color = {a=0, r=0, g=0, b=0}, -- If player is inside node
1675     paramtype = "none", -- See "Nodes"
1676     paramtype2 = "none", -- See "Nodes"
1677     is_ground_content = false, -- Currently not used for anything
1678     sunlight_propagates = false, -- If true, sunlight will go infinitely through this
1679     walkable = true, -- If true, objects collide with node
1680     pointable = true, -- If true, can be pointed at
1681     diggable = true, -- If false, can never be dug
1682     climbable = false, -- If true, can be climbed on (ladder)
1683     buildable_to = false, -- If true, placed nodes can replace this node
1684     drop = "", -- alternatively drop = { max_items = ..., items = { ... } }
1685     liquidtype = "none", -- "none"/"source"/"flowing"
1686     liquid_alternative_flowing = "", -- Flowing version of source liquid
1687     liquid_alternative_source = "", -- Source version of flowing liquid
1688     liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
1689     liquid_renewable = true, -- Can new liquid source be created by placing
1690     two or more sources nearly?
1691     light_source = 0, -- Amount of light emitted by node
1692     damage_per_second = 0, -- If player is inside node, this damage is caused
1693     node_box = {type="regular"}, -- See "Node boxes"
1694     selection_box = {type="regular"}, -- See "Node boxes"
1695     ^ If drawtype "nodebox" is used and selection_box is nil, then node_box is used
1696     legacy_facedir_simple = false, -- Support maps made in and before January 2012
1697     legacy_wallmounted = false, -- Support maps made in and before January 2012
1698     sounds = {
1699         footstep = <SimpleSoundSpec>,
1700         dig = <SimpleSoundSpec>, -- "__group" = group-based sound (default)
1701         dug = <SimpleSoundSpec>,
1702         place = <SimpleSoundSpec>,
1703     },
1704
1705     on_construct = func(pos),
1706     ^ Node constructor; always called after adding node
1707     ^ Can set up metadata and stuff like that
1708     ^ default: nil
1709     on_destruct = func(pos),
1710     ^ Node destructor; always called before removing node
1711     ^ default: nil
1712     after_destruct = func(pos, oldnode),
1713     ^ Node destructor; always called after removing node
1714     ^ default: nil
1715
1716     after_place_node = func(pos, placer, itemstack),
1717     ^ Called after constructing node when node was placed using
1718       minetest.item_place_node / minetest.env:place_node
1719     ^ If return true no item is taken from itemstack
1720     ^ default: nil
1721     after_dig_node = func(pos, oldnode, oldmetadata, digger),
1722     ^ oldmetadata is in table format
1723     ^ Called after destructing node when node was dug using
1724       minetest.node_dig / minetest.env:dig_node
1725     ^ default: nil
1726     can_dig = function(pos,player)
1727     ^ returns true if node can be dug, or false if not
1728     ^ default: nil
1729     
1730     on_punch = func(pos, node, puncher),
1731     ^ default: minetest.node_punch
1732     ^ By default: does nothing
1733     on_rightclick = func(pos, node, clicker, itemstack),
1734     ^ default: nil
1735     ^ if defined, itemstack will hold clicker's wielded item
1736       Shall return the leftover itemstack
1737     on_dig = func(pos, node, digger),
1738     ^ default: minetest.node_dig
1739     ^ By default: checks privileges, wears out tool and removes node
1740     
1741     on_timer = function(pos,elapsed),
1742     ^ default: nil
1743     ^ called by NodeTimers, see EnvRef and NodeTimerRef
1744     ^ elapsed is the total time passed since the timer was started
1745     ^ return true to run the timer for another cycle with the same timeout value
1746
1747     on_receive_fields = func(pos, formname, fields, sender),
1748     ^ fields = {name1 = value1, name2 = value2, ...}
1749     ^ Called when an UI form (eg. sign text input) returns data
1750     ^ default: nil
1751
1752     allow_metadata_inventory_move = func(pos, from_list, from_index,
1753             to_list, to_index, count, player),
1754     ^ Called when a player wants to move items inside the inventory
1755     ^ Return value: number of items allowed to move
1756     
1757     allow_metadata_inventory_put = func(pos, listname, index, stack, player),
1758     ^ Called when a player wants to put something into the inventory
1759     ^ Return value: number of items allowed to put
1760     ^ Return value: -1: Allow and don't modify item count in inventory
1761   
1762     allow_metadata_inventory_take = func(pos, listname, index, stack, player),
1763     ^ Called when a player wants to take something out of the inventory
1764     ^ Return value: number of items allowed to take
1765     ^ Return value: -1: Allow and don't modify item count in inventory
1766
1767     on_metadata_inventory_move = func(pos, from_list, from_index,
1768             to_list, to_index, count, player),
1769     on_metadata_inventory_put = func(pos, listname, index, stack, player),
1770     on_metadata_inventory_take = func(pos, listname, index, stack, player),
1771     ^ Called after the actual action has happened, according to what was allowed.
1772     ^ No return value
1773     
1774     on_blast = func(pos, intensity),
1775     ^ intensity: 1.0 = mid range of regular TNT
1776     ^ If defined, called when an explosion touches the node, instead of
1777       removing the node
1778 }
1779
1780 Recipe for register_craft: (shaped)
1781 {
1782     output = 'default:pick_stone',
1783     recipe = {
1784         {'default:cobble', 'default:cobble', 'default:cobble'},
1785         {'', 'default:stick', ''},
1786         {'', 'default:stick', ''}, -- Also groups; eg. 'group:crumbly'
1787     },
1788     replacements = <optional list of item pairs,
1789                     replace one input item with another item on crafting>
1790 }
1791
1792 Recipe for register_craft (shapeless)
1793 {
1794     type = "shapeless",
1795     output = 'mushrooms:mushroom_stew',
1796     recipe = {
1797         "mushrooms:bowl",
1798         "mushrooms:mushroom_brown",
1799         "mushrooms:mushroom_red",
1800     },
1801     replacements = <optional list of item pairs,
1802                     replace one input item with another item on crafting>
1803 }
1804
1805 Recipe for register_craft (tool repair)
1806 {
1807     type = "toolrepair",
1808     additional_wear = -0.02,
1809 }
1810
1811 Recipe for register_craft (cooking)
1812 {
1813     type = "cooking",
1814     output = "default:glass",
1815     recipe = "default:sand",
1816     cooktime = 3,
1817 }
1818
1819 Recipe for register_craft (furnace fuel)
1820 {
1821     type = "fuel",
1822     recipe = "default:leaves",
1823     burntime = 1,
1824 }
1825
1826 Ore definition (register_ore)
1827 {
1828     ore_type = "scatter" -- See "Ore types"
1829     ore = "default:stone_with_coal",
1830     wherein = "default:stone",
1831     clust_scarcity = 8*8*8,
1832     ^ Ore has a 1 out of clust_scarcity chance of spawning in a node
1833     ^ This value should be *MUCH* higher than your intuition might tell you!
1834     clust_num_ores = 8,
1835     ^ Number of ores in a cluster
1836     clust_size = 3,
1837     ^ Size of the bounding box of the cluster
1838     ^ In this example, there is a 3x3x3 cluster where 8 out of the 27 nodes are coal ore
1839     height_min = -31000,
1840     height_max = 64,
1841     flags = "",
1842     ^ Attributes for this ore generation
1843     noise_threshhold = 0.5,
1844     ^ If noise is above this threshhold, ore is placed.  Not needed for a uniform distribution
1845     noise_params = {offset=0, scale=1, spread={x=100, y=100, z=100}, seed=23, octaves=3, persist=0.70}
1846     ^ NoiseParams structure describing the perlin noise used for ore distribution.
1847     ^ Needed for sheet ore_type.  Omit from scatter ore_type for a uniform ore distribution
1848 }
1849
1850 Chatcommand definition (register_chatcommand)
1851 {
1852     params = "<name> <privilege>", -- short parameter description
1853     description = "Remove privilege from player", -- full description
1854     privs = {privs=true}, -- require the "privs" privilege to run
1855     func = function(name, param), -- called when command is run
1856 }
1857
1858 Detached inventory callbacks
1859 {
1860     allow_move = func(inv, from_list, from_index, to_list, to_index, count, player),
1861     ^ Called when a player wants to move items inside the inventory
1862     ^ Return value: number of items allowed to move
1863     
1864     allow_put = func(inv, listname, index, stack, player),
1865     ^ Called when a player wants to put something into the inventory
1866     ^ Return value: number of items allowed to put
1867     ^ Return value: -1: Allow and don't modify item count in inventory
1868    
1869     allow_take = func(inv, listname, index, stack, player),
1870     ^ Called when a player wants to take something out of the inventory
1871     ^ Return value: number of items allowed to take
1872     ^ Return value: -1: Allow and don't modify item count in inventory
1873     
1874     on_move = func(inv, from_list, from_index, to_list, to_index, count, player),
1875     on_put = func(inv, listname, index, stack, player),
1876     on_take = func(inv, listname, index, stack, player),
1877     ^ Called after the actual action has happened, according to what was allowed.
1878     ^ No return value
1879 }
1880
1881 HUD Definition (hud_add, hud_get)
1882 {
1883     hud_elem_type = "image", -- see HUD element types
1884     ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
1885     position = {x=0.5, y=0.5},
1886     ^ Left corner position of element
1887     name = "<name>",
1888     scale = {x=2, y=2},
1889     text = "<text>",
1890     number = 2,
1891     item = 3,
1892     ^ Selected item in inventory.  0 for no item selected.
1893     direction = 0,
1894     ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
1895     alignment = {x=0, y=0},
1896     ^ See "HUD Element Types"
1897     offset = {x=0, y=0},
1898     ^ See "HUD Element Types"
1899 }