Add loot to dungeons (#1921)
[oweals/minetest_game.git] / game_api.txt
1 Minetest Game API
2 =================
3 GitHub Repo: https://github.com/minetest/minetest_game
4
5 Introduction
6 ------------
7
8 The Minetest Game subgame offers multiple new possibilities in addition to the Minetest engine's built-in API,
9 allowing you to add new plants to farming mod, buckets for new liquids, new stairs and custom panes.
10 For information on the Minetest API, visit https://github.com/minetest/minetest/blob/master/doc/lua_api.txt
11 Please note:
12
13  * [XYZ] refers to a section the Minetest API
14  * [#ABC] refers to a section in this document
15  * [pos] refers to a position table `{x = -5, y = 0, z = 200}`
16
17 Bucket API
18 ----------
19
20 The bucket API allows registering new types of buckets for non-default liquids.
21
22         bucket.register_liquid(
23                 "default:lava_source",   -- name of the source node
24                 "default:lava_flowing",  -- name of the flowing node
25                 "bucket:bucket_lava",    -- name of the new bucket item (or nil if liquid is not takeable)
26                 "bucket_lava.png",       -- texture of the new bucket item (ignored if itemname == nil)
27                 "Lava Bucket",           -- text description of the bucket item
28                 {lava_bucket = 1},       -- groups of the bucket item, OPTIONAL
29                 false                    -- force-renew, OPTIONAL. Force the liquid source to renew if it has
30                                          -- a source neighbour, even if defined as 'liquid_renewable = false'.
31                                          -- Needed to avoid creating holes in sloping rivers.
32         )
33
34 The filled bucket item is returned to the player that uses an empty bucket pointing to the given liquid source.
35 When punching with an empty bucket pointing to an entity or a non-liquid node, the on_punch of the entity or node will be triggered.
36
37 Beds API
38 --------
39
40         beds.register_bed(
41                 "beds:bed",    -- Bed name
42                 def            -- See [#Bed definition]
43         )
44
45  * `beds.read_spawns() `   Returns a table containing players respawn positions
46  * `beds.kick_players()`  Forces all players to leave bed
47  * `beds.skip_night()`   Sets world time to morning and saves respawn position of all players currently sleeping
48
49 ### Bed definition
50
51         {
52                 description = "Simple Bed",
53                 inventory_image = "beds_bed.png",
54                 wield_image = "beds_bed.png",
55                 tiles = {
56                         bottom = {'Tile definition'}, -- the tiles of the bottom part of the bed.
57                         top = {Tile definition} -- the tiles of the bottom part of the bed.
58                 },
59                 nodebox = {
60                         bottom = 'regular nodebox',     -- bottom part of bed (see [Node boxes])
61                         top = 'regular nodebox',        -- top part of bed (see [Node boxes])
62                 },
63                 selectionbox = 'regular nodebox',  -- for both nodeboxes (see [Node boxes])
64                 recipe = {                                         -- Craft recipe
65                         {"group:wool", "group:wool", "group:wool"},
66                         {"group:wood", "group:wood", "group:wood"}
67                 }
68         }
69
70 Creative API
71 ------------
72
73 Use `creative.register_tab(name, title, items)` to add a tab with filtered items.
74 For example,
75
76         creative.register_tab("tools", "Tools", minetest.registered_tools)
77
78 is used to show all tools. Name is used in the sfinv page name, title is the
79 human readable title.
80
81 `is_enabled_for` is used to check whether a player is in creative mode:
82
83     creative.is_enabled_for(name)
84
85 Override this to allow per-player game modes.
86
87 The contents of `creative.formspec_add` is appended to every creative inventory
88 page. Mods can use it to add additional formspec elements onto the default
89 creative inventory formspec to be drawn after each update.
90
91 Doors API
92 ---------
93
94 The doors mod allows modders to register custom doors and trapdoors.
95
96 `doors.register_door(name, def)`
97
98  * Registers new door
99  * `name` Name for door
100  * `def`  See [#Door definition]
101
102 `doors.register_trapdoor(name, def)`
103
104  * Registers new trapdoor
105  * `name` Name for trapdoor
106  * `def`  See [#Trapdoor definition]
107
108 `doors.register_fencegate(name, def)`
109
110  * Registers new fence gate
111  * `name` Name for fence gate
112  * `def`  See [#Fence gate definition]
113
114 `doors.get(pos)`
115
116  * `pos` A position as a table, e.g `{x = 1, y = 1, z = 1}`
117  * Returns an ObjectRef to a door, or nil if the position does not contain a door
118
119     ### Methods
120
121         :open(player)   -- Open the door object, returns if door was opened
122         :close(player)  -- Close the door object, returns if door was closed
123         :toggle(player) -- Toggle the door state, returns if state was toggled
124         :state()        -- returns the door state, true = open, false = closed
125
126     the "player" parameter can be omitted in all methods. If passed then
127     the usual permission checks will be performed to make sure the player
128     has the permissions needed to open this door. If omitted then no
129     permission checks are performed.
130
131 ### Door definition
132
133         description = "Door description",
134         inventory_image = "mod_door_inv.png",
135         groups = {choppy = 2},
136         tiles = {"mod_door.png"}, -- UV map.
137         recipe = craftrecipe,
138         sounds = default.node_sound_wood_defaults(), -- optional
139         sound_open = sound play for open door, -- optional
140         sound_close = sound play for close door, -- optional
141         protected = false, -- If true, only placer can open the door (locked for others)
142
143 ### Trapdoor definition
144
145         description = "Trapdoor description",
146         inventory_image = "mod_trapdoor_inv.png",
147         groups = {choppy = 2},
148         tile_front = "doors_trapdoor.png", -- the texture for the front and back of the trapdoor
149         tile_side = "doors_trapdoor_side.png", -- the tiles of the four side parts of the trapdoor
150         sounds = default.node_sound_wood_defaults(), -- optional
151         sound_open = sound play for open door, -- optional
152         sound_close = sound play for close door, -- optional
153         protected = false, -- If true, only placer can open the door (locked for others)
154
155 ### Fence gate definition
156
157         description = "Wooden Fence Gate",
158         texture = "default_wood.png", -- `backface_culling` will automatically be
159                                       -- set to `true` if not specified.
160         material = "default:wood",
161         groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
162         sounds = default.node_sound_wood_defaults(), -- optional
163
164 Dungeon Loot API
165 ----------------
166
167 The mod that places chests with loot in dungeons provides an API to register additional loot.
168
169 `dungeon_loot.register(def)`
170
171  * Registers one or more loot items
172  * `def` Can be a single [#Loot definition] or a list of them
173
174 `dungeon_loot.registered_loot`
175
176  * Table of all registered loot, not to be modified manually
177
178 ### Loot definition
179
180         name = "item:name",
181         chance = 0.5,
182         -- ^ chance value from 0.0 to 1.0 that the item will appear in the chest when chosen
183         --   due to an extra step in the selection process, 0.5 does not(!) mean that
184         --   on average every second chest will have this item
185         count = {1, 4},
186         -- ^ table with minimum and maximum amounts of this item
187         --   optional, defaults to always single item
188         y = {-32768, -512},
189         -- ^ table with minimum and maximum heights this item can be found at
190         --   optional, defaults to no height restrictions
191         types = {"desert"},
192         -- ^ table with types of dungeons this item can be found in
193         --   supported types: "normal" (the cobble/mossycobble one), "sandstone", "desert"
194         --   optional, defaults to no type restrictions
195
196 Fence API
197 ---------
198
199 Allows creation of new fences with "fencelike" drawtype.
200
201 `default.register_fence(name, item definition)`
202
203  Registers a new fence. Custom fields texture and material are required, as
204  are name and description. The rest is optional. You can pass most normal
205  nodedef fields here except drawtype. The fence group will always be added
206  for this node.
207
208 ### fence definition
209
210         name = "default:fence_wood",
211         description = "Wooden Fence",
212         texture = "default_wood.png",
213         material = "default:wood",
214         groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
215         sounds = default.node_sound_wood_defaults(),
216
217 Walls API
218 ---------
219
220 The walls API allows easy addition of stone auto-connecting wall nodes.
221
222 walls.register(name, desc, texture, mat, sounds)
223 ^ name = "walls:stone_wall". Node name.
224 ^ desc = "A Stone wall"
225 ^ texture = "default_stone.png"
226 ^ mat = "default:stone". Used to auto-generate crafting recipe.
227 ^ sounds = sounds: see [#Default sounds]
228
229 Farming API
230 -----------
231
232 The farming API allows you to easily register plants and hoes.
233
234 `farming.register_hoe(name, hoe definition)`
235  * Register a new hoe, see [#hoe definition]
236
237 `farming.register_plant(name, Plant definition)`
238  * Register a new growing plant, see [#Plant definition]
239
240 `farming.registered_plants[name] = definition`
241  * Table of registered plants, indexed by plant name
242
243 ### Hoe Definition
244
245
246         {
247                 description = "",                      -- Description for tooltip
248                 inventory_image = "unknown_item.png",  -- Image to be used as wield- and inventory image
249                 max_uses = 30,                         -- Uses until destroyed
250                 material = "",                         -- Material for recipes
251                 recipe = {                             -- Craft recipe, if material isn't used
252                         {"air", "air", "air"},
253                         {"", "group:stick"},
254                         {"", "group:stick"},
255                 }
256         }
257
258 ### Plant definition
259
260         {
261                 description = "",                      -- Description of seed item
262                 inventory_image = "unknown_item.png",  -- Image to be used as seed's wield- and inventory image
263                 steps = 8,                             -- How many steps the plant has to grow, until it can be harvested
264                 -- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
265                 minlight = 13,                         -- Minimum light to grow
266                 maxlight = default.LIGHT_MAX           -- Maximum light to grow
267         }
268
269 Fire API
270 --------
271
272 New node def property:
273
274 `on_burn(pos)`
275
276  * Called when fire attempts to remove a burning node.
277  * `pos` Position of the burning node.
278
279  `on_ignite(pos, igniter)`
280
281   * Called when Flint and steel (or a mod defined ignitor) is used on a node.
282     Defining it may prevent the default action (spawning flames) from triggering.
283   * `pos` Position of the ignited node.
284   * `igniter` Player that used the tool, when available.
285
286
287 Give Initial Stuff API
288 ----------------------
289
290 `give_initial_stuff.give(player)`
291
292 ^ Give initial stuff to "player"
293
294 `give_initial_stuff.add(stack)`
295
296 ^ Add item to the initial stuff
297 ^ Stack can be an ItemStack or a item name eg: "default:dirt 99"
298 ^ Can be called after the game has loaded
299
300 `give_initial_stuff.clear()`
301
302 ^ Removes all items from the initial stuff
303 ^ Can be called after the game has loaded
304
305 `give_initial_stuff.get_list()`
306
307 ^ returns list of item stacks
308
309 `give_initial_stuff.set_list(list)`
310
311 ^ List of initial items with numeric indices.
312
313 `give_initial_stuff.add_from_csv(str)`
314
315 ^ str is a comma separated list of initial stuff
316 ^ Adds items to the list of items to be given
317
318
319 Players API
320 -----------
321
322 The player API can register player models and update the player's appearence
323
324 * `player_api.register_model(name, def)`
325         * Register a new model to be used by players
326         * name: model filename such as "character.x", "foo.b3d", etc.
327         * def: See [#Model definition]
328     * saved to player_api.registered_models
329
330 * `player_api.registered_player_models[name]`
331          * Get a model's definition
332          * see [#Model definition]
333
334 * `player_api.set_model(player, model_name)`
335         * Change a player's model
336         * `player`: PlayerRef
337         * `model_name`: model registered with player_api.register_model()
338
339 * `player_api.set_animation(player, anim_name [, speed])`
340         * Applies an animation to a player
341         * anim_name: name of the animation.
342         * speed: frames per second. If nil, default from the model is used
343
344 * `player_api.set_textures(player, textures)`
345         * Sets player textures
346         * `player`: PlayerRef
347         * `textures`: array of textures, If `textures` is nil the default
348           textures from the model def are used
349
350 * `player_api.get_animation(player)`
351         * Returns a table containing fields `model`, `textures` and `animation`.
352         * Any of the fields of the returned table may be nil.
353         * player: PlayerRef
354
355 ### Model Definition
356
357         {
358                 animation_speed = 30,            -- Default animation speed, in FPS.
359                 textures = {"character.png", },  -- Default array of textures.
360                 visual_size = {x = 1, y = 1},    -- Used to scale the model.
361                 animations = {
362                         -- <anim_name> = {x = <start_frame>, y = <end_frame>},
363                         foo = {x = 0, y = 19},
364                         bar = {x = 20, y = 39},
365                 -- ...
366                 },
367                 collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3}, -- In nodes from feet position
368                 stepheight = 0.6, -- In nodes
369         }
370
371
372 TNT API
373 -------
374
375 `tnt.register_tnt(definition)`
376
377 ^ Register a new type of tnt.
378
379  * `name` The name of the node. If no prefix is given `tnt` is used.
380  * `description` A description for your TNT.
381  * `radius` The radius within which the TNT can destroy nodes. The default is 3.
382  * `damage_radius` The radius within which the TNT can damage players and mobs. By default it is twice the `radius`.
383  * `sound` The sound played when explosion occurs. By default it is `tnt_explode`.
384  * `disable_drops` Disable drops. By default it is set to false.
385  * `ignore_protection` Don't check `minetest.is_protected` before removing a node.
386  * `ignore_on_blast` Don't call `on_blast` even if a node has one.
387  * `tiles` Textures for node
388   * `side`  Side tiles. By default the name of the tnt with a suffix of `_side.png`.
389   * `top`  Top tile. By default the name of the tnt with a suffix of `_top.png`.
390   * `bottom` Bottom tile. By default the name of the tnt with a suffix of `_bottom.png`.
391   * `burning` Top tile when lit. By default the name of the tnt with a suffix of `_top_burning_animated.png".
392
393 `tnt.boom(position[, definition])`
394
395 ^ Create an explosion.
396
397 * `position` The center of explosion.
398 * `definition` The TNT definion as passed to `tnt.register` with the following addition:
399  * `explode_center` false by default which removes TNT node on blast, when true will explode center node.
400
401 `tnt.burn(position, [nodename])`
402
403 ^ Ignite node at position, triggering its `on_ignite` callback (see fire mod).
404 If no such callback exists, fallback to turn tnt group nodes to their
405 "_burning" variant.
406   nodename isn't required unless already known.
407
408 To make dropping items from node inventories easier, you can use the
409 following helper function from 'default':
410
411 default.get_inventory_drops(pos, inventory, drops)
412
413 ^ Return drops from node inventory "inventory" in drops.
414
415 * `pos` - the node position
416 * `inventory` - the name of the inventory (string)
417 * `drops` - an initialized list
418
419 The function returns no values. The drops are returned in the `drops`
420 parameter, and drops is not reinitialized so you can call it several
421 times in a row to add more inventory items to it.
422
423
424 `on_blast` callbacks:
425
426 Both nodedefs and entitydefs can provide an `on_blast()` callback
427
428 `nodedef.on_blast(pos, intensity)`
429 ^ Allow drop and node removal overriding
430 * `pos` - node position
431 * `intensity` - TNT explosion measure. larger or equal to 1.0
432 ^ Should return a list of drops (e.g. {"default:stone"})
433 ^ Should perform node removal itself. If callback exists in the nodedef
434 ^ then the TNT code will not destroy this node.
435
436 `entitydef.on_blast(luaobj, damage)`
437 ^ Allow TNT effects on entities to be overridden
438 * `luaobj` - LuaEntityRef of the entity
439 * `damage` - suggested HP damage value
440 ^ Should return a list of (bool do_damage, bool do_knockback, table drops)
441 * `do_damage` - if true then TNT mod wil damage the entity
442 * `do_knockback` - if true then TNT mod will knock the entity away
443 * `drops` - a list of drops, e.g. {"wool:red"}
444
445
446 Screwdriver API
447 ---------------
448
449 The screwdriver API allows you to control a node's behaviour when a screwdriver is used on it.
450 To use it, add the `on_screwdriver` function to the node definition.
451
452 `on_rotate(pos, node, user, mode, new_param2)`
453
454  * `pos` Position of the node that the screwdriver is being used on
455  * `node` that node
456  * `user` The player who used the screwdriver
457  * `mode` screwdriver.ROTATE_FACE or screwdriver.ROTATE_AXIS
458  * `new_param2` the new value of param2 that would have been set if on_rotate wasn't there
459  * return value: false to disallow rotation, nil to keep default behaviour, true to allow
460         it but to indicate that changed have already been made (so the screwdriver will wear out)
461  * use `on_rotate = false` to always disallow rotation
462  * use `on_rotate = screwdriver.rotate_simple` to allow only face rotation
463
464
465 Sethome API
466 -----------
467
468 The sethome API adds three global functions to allow mods to read a players home position,
469 set a players home position and teleport a player to home position.
470
471 `sethome.get(name)`
472
473  * `name` Player who's home position you wish to get
474  * return value: false if no player home coords exist, position table if true
475
476 `sethome.set(name, pos)`
477
478  * `name` Player who's home position you wish to set
479  * `pos` Position table containing coords of home position
480  * return value: false if unable to set and save new home position, otherwise true
481
482 `sethome.go(name)`
483
484  * `name` Player you wish to teleport to their home position
485  * return value: false if player cannot be sent home, otherwise true
486
487
488 Sfinv API
489 ---------
490
491 ### sfinv Methods
492
493 **Pages**
494
495 * sfinv.set_page(player, pagename) - changes the page
496 * sfinv.get_homepage_name(player) - get the page name of the first page to show to a player
497 * sfinv.register_page(name, def) - register a page, see section below
498 * sfinv.override_page(name, def) - overrides fields of an page registered with register_page.
499     * Note: Page must already be defined, (opt)depend on the mod defining it.
500 * sfinv.set_player_inventory_formspec(player) - (re)builds page formspec
501              and calls set_inventory_formspec().
502 * sfinv.get_formspec(player, context) - builds current page's formspec
503
504 **Contexts**
505
506 * sfinv.get_or_create_context(player) - gets the player's context
507 * sfinv.set_context(player, context)
508
509 **Theming**
510
511 * sfinv.make_formspec(player, context, content, show_inv, size) - adds a theme to a formspec
512     * show_inv, defaults to false. Whether to show the player's main inventory
513     * size, defaults to `size[8,8.6]` if not specified
514 * sfinv.get_nav_fs(player, context, nav, current_idx) - creates tabheader or ""
515
516 ### sfinv Members
517
518 * pages - table of pages[pagename] = def
519 * pages_unordered - array table of pages in order of addition (used to build navigation tabs).
520 * contexts - contexts[playername] = player_context
521 * enabled - set to false to disable. Good for inventory rehaul mods like unified inventory
522
523 ### Context
524
525 A table with these keys:
526
527 * page - current page name
528 * nav - a list of page names
529 * nav_titles - a list of page titles
530 * nav_idx - current nav index (in nav and nav_titles)
531 * any thing you want to store
532     * sfinv will clear the stored data on log out / log in
533
534 ### sfinv.register_page
535
536 sfinv.register_page(name, def)
537
538 def is a table containing:
539
540 * `title` - human readable page name (required)
541 * `get(self, player, context)` - returns a formspec string. See formspec variables. (required)
542 * `is_in_nav(self, player, context)` - return true to show in the navigation (the tab header, by default)
543 * `on_player_receive_fields(self, player, context, fields)` - on formspec submit.
544 * `on_enter(self, player, context)` - called when the player changes pages, usually using the tabs.
545 * `on_leave(self, player, context)` - when leaving this page to go to another, called before other's on_enter
546
547 ### get formspec
548
549 Use sfinv.make_formspec to apply a layout:
550
551         return sfinv.make_formspec(player, context, [[
552                 list[current_player;craft;1.75,0.5;3,3;]
553                 list[current_player;craftpreview;5.75,1.5;1,1;]
554                 image[4.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]
555                 listring[current_player;main]
556                 listring[current_player;craft]
557                 image[0,4.25;1,1;gui_hb_bg.png]
558                 image[1,4.25;1,1;gui_hb_bg.png]
559                 image[2,4.25;1,1;gui_hb_bg.png]
560                 image[3,4.25;1,1;gui_hb_bg.png]
561                 image[4,4.25;1,1;gui_hb_bg.png]
562                 image[5,4.25;1,1;gui_hb_bg.png]
563                 image[6,4.25;1,1;gui_hb_bg.png]
564                 image[7,4.25;1,1;gui_hb_bg.png]
565         ]], true)
566
567 See above (methods section) for more options.
568
569 ### Customising themes
570
571 Simply override this function to change the navigation:
572
573         function sfinv.get_nav_fs(player, context, nav, current_idx)
574                 return "navformspec"
575         end
576
577 And override this function to change the layout:
578
579         function sfinv.make_formspec(player, context, content, show_inv, size)
580                 local tmp = {
581                         size or "size[8,8.6]",
582                         theme_main,
583                         sfinv.get_nav_fs(player, context, context.nav_titles, context.nav_idx),
584                         content
585                 }
586                 if show_inv then
587                         tmp[4] = theme_inv
588                 end
589                 return table.concat(tmp, "")
590         end
591
592 Stairs API
593 ----------
594
595 The stairs API lets you register stairs and slabs and ensures that they are registered the same way as those
596 delivered with Minetest Game, to keep them compatible with other mods.
597
598 `stairs.register_stair(subname, recipeitem, groups, images, description, sounds)`
599
600  * Registers a stair.
601  * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
602  * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil`
603  * `groups`: see [Known damage and digging time defining groups]
604  * `images`: see [Tile definition]
605  * `description`: used for the description field in the stair's definition
606  * `sounds`: see [#Default sounds]
607
608 `stairs.register_slab(subname, recipeitem, groups, images, description, sounds)`
609
610  * Registers a slabs
611  * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
612  * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble"
613  * `groups`: see [Known damage and digging time defining groups]
614  * `images`: see [Tile definition]
615  * `description`: used for the description field in the stair's definition
616  * `sounds`: see [#Default sounds]
617
618 `stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)`
619
620  * A wrapper for stairs.register_stair and stairs.register_slab
621  * Uses almost the same arguments as stairs.register_stair
622  * `desc_stair`: Description for stair node
623  * `desc_slab`: Description for slab node
624
625 Xpanes API
626 ----------
627
628 Creates panes that automatically connect to each other
629
630 `xpanes.register_pane(subname, def)`
631
632  * `subname`: used for nodename. Result: "xpanes:subname" and "xpanes:subname_{2..15}"
633  * `def`: See [#Pane definition]
634
635 ### Pane definition
636
637         {
638                 textures = {"texture for sides", (unused), "texture for top and bottom"}, -- More tiles aren't supported
639                 groups = {group = rating}, -- Uses the known node groups, see [Known damage and digging time defining groups]
640                 sounds = SoundSpec,        -- See [#Default sounds]
641                 recipe = {{"","","","","","","","",""}}, -- Recipe field only
642         }
643
644 Raillike definitions
645 --------------------
646
647 The following nodes use the group `connect_to_raillike` and will only connect to
648 raillike nodes within this group and the same group value.
649 Use `minetest.raillike_group(<Name>)` to get the group value.
650
651 | Node type             | Raillike group name
652 |-----------------------|---------------------
653 | default:rail          | "rail"
654 | tnt:gunpowder         | "gunpowder"
655 | tnt:gunpowder_burning | "gunpowder"
656
657 Example:
658 If you want to add a new rail type and want it to connect with default:rail,
659 add `connect_to_raillike=minetest.raillike_group("rail")` into the `groups` table
660 of your node.
661
662
663 Default sounds
664 --------------
665
666 Sounds inside the default table can be used within the sounds field of node definitions.
667
668  * `default.node_sound_defaults()`
669  * `default.node_sound_stone_defaults()`
670  * `default.node_sound_dirt_defaults()`
671  * `default.node_sound_sand_defaults()`
672  * `default.node_sound_wood_defaults()`
673  * `default.node_sound_leaves_defaults()`
674  * `default.node_sound_glass_defaults()`
675  * `default.node_sound_metal_defaults()`
676
677 Default constants
678 -----------------
679
680 `default.LIGHT_MAX`  The maximum light level (see [Node definition] light_source)
681
682
683 GUI and formspecs
684 -----------------
685
686 `default.get_hotbar_bg(x, y)`
687
688  * Get the hotbar background as string, containing the formspec elements
689  * x: Horizontal position in the formspec
690  * y: Vertical position in the formspec
691
692 `default.gui_bg`
693
694  * Background color formspec element
695
696 `default.gui_bg_img`
697
698  * Image overlay formspec element for the background to use in formspecs
699
700 `default.gui_slots`
701
702  * `listcolors` formspec element that is used to format the slots in formspecs
703
704 `default.gui_survival_form`
705
706  * Entire formspec for the survival inventory
707
708 `default.get_chest_formspec(pos)`
709
710  * Get the chest formspec using the defined GUI elements
711  * pos: Location of the node
712
713 `default.get_furnace_active_formspec(fuel_percent, item_percent)`
714
715  * Get the active furnace formspec using the defined GUI elements
716  * fuel_percent: Percent of how much the fuel is used
717  * item_percent: Percent of how much the item is cooked
718
719 `default.get_furnace_inactive_formspec()`
720
721  * Get the inactive furnace formspec using the defined GUI elements
722
723
724 Leafdecay
725 ---------
726
727 To enable leaf decay for leaves when a tree is cut down by a player,
728 register the tree with the default.register_leafdecay(leafdecaydef)
729 function.
730
731 If `param2` of any registered node is ~= 0, the node will always be
732 preserved. Thus, if the player places a node of that kind, you will
733 want to set `param2 = 1` or so.
734
735 The function `default.after_place_leaves` can be set as
736 `after_place_node of a node` to set param2 to 1 if the player places
737 the node (should not be used for nodes that use param2 otherwise
738 (e.g. facedir)).
739
740 If the node is in the `leafdecay_drop` group then it will always be
741 dropped as an item.
742
743 `default.register_leafdecay(leafdecaydef)`
744
745 `leafdecaydef` is a table, with following members:
746         {
747                 trunks = {"default:tree"}, -- nodes considered trunks
748                 leaves = {"default:leaves", "default:apple"},
749                         -- nodes considered for removal
750                 radius = 3, -- radius to consider for searching
751         }
752
753 Note: all the listed nodes in `trunks` have their `on_after_destruct`
754 callback overridden. All the nodes listed in `leaves` have their
755 `on_timer` callback overridden.
756
757
758 Dyes
759 ----
760
761 To make recipes that will work with any dye ever made by anybody, define
762 them based on groups. You can select any group of groups, based on your need for
763 amount of colors.
764
765 ### Color groups
766
767 Base color groups:
768
769  * `basecolor_white`
770  * `basecolor_grey`
771  * `basecolor_black`
772  * `basecolor_red`
773  * `basecolor_yellow`
774  * `basecolor_green`
775  * `basecolor_cyan`
776  * `basecolor_blue`
777  * `basecolor_magenta`
778
779 Extended color groups ( * means also base color )
780
781  * `excolor_white` *
782  * `excolor_lightgrey`
783  * `excolor_grey` *
784  * `excolor_darkgrey`
785  * `excolor_black` *
786  * `excolor_red` *
787  * `excolor_orange`
788  * `excolor_yellow` *
789  * `excolor_lime`
790  * `excolor_green` *
791  * `excolor_aqua`
792  * `excolor_cyan` *
793  * `excolor_sky_blue`
794  * `excolor_blue` *
795  * `excolor_violet`
796  * `excolor_magenta` *
797  * `excolor_red_violet`
798
799 The whole unifieddyes palette as groups:
800
801  * `unicolor_<excolor>`
802
803 For the following, no white/grey/black is allowed:
804
805  * `unicolor_medium_<excolor>`
806  * `unicolor_dark_<excolor>`
807  * `unicolor_light_<excolor>`
808  * `unicolor_<excolor>_s50`
809  * `unicolor_medium_<excolor>_s50`
810  * `unicolor_dark_<excolor>_s50`
811
812 Example of one shapeless recipe using a color group:
813
814         minetest.register_craft({
815                 type = "shapeless",
816                 output = '<mod>:item_yellow',
817                 recipe = {'<mod>:item_no_color', 'group:basecolor_yellow'},
818         })
819
820 ### Color lists
821
822  * `dye.basecolors` are an array containing the names of available base colors
823
824  * `dye.excolors` are an array containing the names of the available extended colors
825
826 Trees
827 -----
828
829  * `default.grow_tree(pos, is_apple_tree)`
830   * Grows a mgv6 tree or apple tree at pos
831
832  * `default.grow_jungle_tree(pos)`
833   * Grows a mgv6 jungletree at pos
834
835  * `default.grow_pine_tree(pos)`
836   * Grows a mgv6 pinetree at pos
837
838  * `default.grow_new_apple_tree(pos)`
839   * Grows a new design apple tree at pos
840
841  * `default.grow_new_jungle_tree(pos)`
842   * Grows a new design jungle tree at pos
843
844  * `default.grow_new_pine_tree(pos)`
845   * Grows a new design pine tree at pos
846
847  * `default.grow_new_snowy_pine_tree(pos)`
848   * Grows a new design snowy pine tree at pos
849
850  * `default.grow_new_acacia_tree(pos)`
851   * Grows a new design acacia tree at pos
852
853  * `default.grow_new_aspen_tree(pos)`
854   * Grows a new design aspen tree at pos
855
856  * `default.grow_bush(pos)`
857   * Grows a bush at pos
858
859  * `default.grow_acacia_bush(pos)`
860   * Grows an acaia bush at pos
861
862 Carts
863 -----
864
865         carts.register_rail(
866                 "mycarts:myrail", -- Rail name
867                 nodedef,          -- standard nodedef
868                 railparams        -- rail parameter struct (optional)
869         )
870
871         railparams = {
872                 on_step(obj, dtime), -- Event handler called when
873                                      -- cart is on rail
874                 acceleration, -- integer acceleration factor (negative
875                               -- values to brake)
876         }
877
878         The event handler is called after all default calculations
879         are made, so the custom on_step handler can override things
880         like speed, acceleration, player attachment. The handler will
881         likely be called many times per second, so the function needs
882         to make sure that the event is handled properly.
883
884 Key API
885 -------
886
887 The key API allows mods to add key functionality to nodes that have
888 ownership or specific permissions. Using the API will make it so
889 that a node owner can use skeleton keys on their nodes to create keys
890 for that node in that location, and give that key to other players,
891 allowing them some sort of access that they otherwise would not have
892 due to node protection.
893
894 To make your new nodes work with the key API, you need to register
895 two callback functions in each nodedef:
896
897
898 `on_key_use(pos, player)`
899  * Is called when a player right-clicks (uses) a normal key on your
900  * node.
901  * `pos` - position of the node
902  * `player` - PlayerRef
903  * return value: none, ignored
904
905 The `on_key_use` callback should validate that the player is wielding
906 a key item with the right key meta secret. If needed the code should
907 deny access to the node functionality.
908
909 If formspecs are used, the formspec callbacks should duplicate these
910 checks in the metadata callback functions.
911
912
913 `on_skeleton_key_use(pos, player, newsecret)`
914
915  * Is called when a player right-clicks (uses) a skeleton key on your
916  * node.
917  * `pos` - position of the node
918  * `player` - PlayerRef
919  * `newsecret` - a secret value(string)
920  * return values:
921  * `secret` - `nil` or the secret value that unlocks the door
922  * `name` - a string description of the node ("a locked chest")
923  * `owner` - name of the node owner
924
925 The `on_skeleton_key_use` function should validate that the player has
926 the right permissions to make a new key for the item. The newsecret
927 value is useful if the node has no secret value. The function should
928 store this secret value somewhere so that in the future it may compare
929 key secrets and match them to allow access. If a node already has a
930 secret value, the function should return that secret value instead
931 of the newsecret value. The secret value stored for the node should
932 not be overwritten, as this would invalidate existing keys.
933
934 Aside from the secret value, the function should retun a descriptive
935 name for the node and the owner name. The return values are all
936 encoded in the key that will be given to the player in replacement
937 for the wielded skeleton key.
938
939 if `nil` is returned, it is assumed that the wielder did not have
940 permissions to create a key for this node, and no key is created.