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