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