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