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