Store registered plant on namespace
[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
23         bucket.register_liquid(
24                 "default:lava_source",   -- name of the source node
25                 "default:lava_flowing",  -- name of the flowing node
26                 "bucket:bucket_lava",    -- name of the new bucket item (or nil if liquid is not takeable)
27                 "bucket_lava.png",       -- texture of the new bucket item (ignored if itemname == nil)
28                 "Lava Bucket",           -- text description of the bucket item
29                 {lava_bucket = 1}        -- groups of the bucket item, OPTIONAL
30         )
31
32 Beds API
33 --------
34
35         beds.register_bed(
36                 "beds:bed",    -- Bed name
37                 def            -- See [#Bed definition]
38         )
39
40  * `beds.read_spawns() `   Returns a table containing players respawn positions
41  * `beds.kick_players()`  Forces all players to leave bed
42  * `beds.skip_night()`   Sets world time to morning and saves respawn position of all players currently sleeping
43
44 ### Bed definition
45
46         {
47                 description = "Simple Bed",
48                 inventory_image = "beds_bed.png",
49                 wield_image = "beds_bed.png",
50                 tiles = {
51                         bottom = {'Tile definition'}, -- the tiles of the bottom part of the bed.
52                         top = {Tile definition} -- the tiles of the bottom part of the bed.
53                 },
54                 nodebox = {
55                         bottom = 'regular nodebox',     -- bottom part of bed (see [Node boxes])
56                         top = 'regular nodebox',        -- top part of bed (see [Node boxes])
57                 },
58                 selectionbox = 'regular nodebox',  -- for both nodeboxes (see [Node boxes])
59                 recipe = {                                         -- Craft recipe
60                         {"group:wool", "group:wool", "group:wool"},
61                         {"group:wood", "group:wood", "group:wood"}
62                 }
63         }
64
65 Creative API
66 ------------
67
68 A global string called `creative.formspec_add` was added which allows mods to add additional formspec elements onto the default creative inventory formspec to be drawn after each update.
69
70 Doors API
71 ---------
72
73 The doors mod allows modders to register custom doors and trapdoors.
74
75 `doors.register_door(name, def)`
76
77  * Registers new door
78  * `name` Name for door
79  * `def`  See [#Door definition]
80
81 `doors.register_trapdoor(name, def)`
82
83  * Registers new trapdoor
84  * `name` Name for trapdoor
85  * `def`  See [#Trapdoor definition]
86
87 `doors.register_fencegate(name, def)`
88
89  * Registers new fence gate
90  * `name` Name for fence gate
91  * `def`  See [#Fence gate definition]
92
93 `doors.get(pos)`
94
95  * `pos` A position as a table, e.g `{x = 1, y = 1, z = 1}`
96  * Returns an ObjectRef to a door, or nil if the position does not contain a door
97
98     ### Methods
99
100         :open(player)   -- Open the door object, returns if door was opened
101         :close(player)  -- Close the door object, returns if door was closed
102         :toggle(player) -- Toggle the door state, returns if state was toggled
103         :state()        -- returns the door state, true = open, false = closed
104
105     the "player" parameter can be omitted in all methods. If passed then
106     the usual permission checks will be performed to make sure the player
107     has the permissions needed to open this door. If omitted then no
108     permission checks are performed.
109
110 ### Door definition
111
112         description = "Door description",
113         inventory_image = "mod_door_inv.png",
114         groups = {choppy = 2},
115         tiles = {"mod_door.png"}, -- UV map.
116         recipe = craftrecipe,
117         sounds = default.node_sound_wood_defaults(), -- optional
118         sound_open = sound play for open door, -- optional
119         sound_close = sound play for close door, -- optional
120         protected = false, -- If true, only placer can open the door (locked for others)
121
122 ### Trapdoor definition
123
124         description = "Trapdoor description",
125         inventory_image = "mod_trapdoor_inv.png",
126         groups = {choppy = 2},
127         tile_front = "doors_trapdoor.png", -- the texture for the front and back of the trapdoor
128         tile_side = "doors_trapdoor_side.png", -- the tiles of the four side parts of the trapdoor
129         sounds = default.node_sound_wood_defaults(), -- optional
130         sound_open = sound play for open door, -- optional
131         sound_close = sound play for close door, -- optional
132         protected = false, -- If true, only placer can open the door (locked for others)
133
134 ### Fence gate definition
135
136         description = "Wooden Fence Gate",
137         texture = "default_wood.png",
138         material = "default:wood",
139         groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
140         sounds = default.node_sound_wood_defaults(), -- optional
141
142 Fence API
143 ---------
144
145 Allows creation of new fences with "fencelike" drawtype.
146
147 `default.register_fence(name, item definition)`
148
149  Registers a new fence. Custom fields texture and material are required, as
150  are name and description. The rest is optional. You can pass most normal
151  nodedef fields here except drawtype. The fence group will always be added
152  for this node.
153
154 ### fence definition
155
156         name = "default:fence_wood",
157         description = "Wooden Fence",
158         texture = "default_wood.png",
159         material = "default:wood",
160         groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
161         sounds = default.node_sound_wood_defaults(),
162
163 Walls API
164 ---------
165
166 The walls API allows easy addition of stone auto-connecting wall nodes.
167
168 walls.register(name, desc, texture, mat, sounds)
169 ^ name = "walls:stone_wall". Node name.
170 ^ desc = "A Stone wall"
171 ^ texture = "default_stone.png"
172 ^ mat = "default:stone". Used to auto-generate crafting recipe.
173 ^ sounds = sounds: see [#Default sounds]
174
175 Farming API
176 -----------
177
178 The farming API allows you to easily register plants and hoes.
179
180 `farming.register_hoe(name, hoe definition)`
181  * Register a new hoe, see [#hoe definition]
182
183 `farming.register_plant(name, Plant definition)`
184  * Register a new growing plant, see [#Plant definition]
185
186 `farming.registered_plants[name] = definition`
187  * Table of registered plants, indexed by plant name
188
189 ### Hoe Definition
190
191
192         {
193                 description = "",                      -- Description for tooltip
194                 inventory_image = "unknown_item.png",  -- Image to be used as wield- and inventory image
195                 max_uses = 30,                         -- Uses until destroyed
196                 material = "",                         -- Material for recipes
197                 recipe = {                             -- Craft recipe, if material isn't used
198                         {"air", "air", "air"},
199                         {"", "group:stick"},
200                         {"", "group:stick"},
201                 }
202         }
203
204 ### Plant definition
205
206         {
207                 description = "",                      -- Description of seed item
208                 inventory_image = "unknown_item.png",  -- Image to be used as seed's wield- and inventory image
209                 steps = 8,                             -- How many steps the plant has to grow, until it can be harvested
210                 -- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
211                 minlight = 13,                         -- Minimum light to grow
212                 maxlight = default.LIGHT_MAX           -- Maximum light to grow
213         }
214
215 Fire API
216 --------
217
218 New node def property:
219
220 `on_burn(pos)`
221
222  * Called when fire attempts to remove a burning node.
223  * `pos` Position of the burning node.
224
225 Give Initial Stuff API
226 ----------------------
227
228 `give_initial_stuff.give(player)`
229
230 ^ Give initial stuff to "player"
231
232 `give_initial_stuff.add(stack)`
233
234 ^ Add item to the initial stuff
235 ^ Stack can be an ItemStack or a item name eg: "default:dirt 99"
236 ^ Can be called after the game has loaded
237
238 `give_initial_stuff.clear()`
239
240 ^ Removes all items from the initial stuff
241 ^ Can be called after the game has loaded
242
243 `give_initial_stuff.get_list()`
244
245 ^ returns list of item stacks
246
247 `give_initial_stuff.set_list(list)`
248
249 ^ List of initial items with numeric indices.
250
251 `give_initial_stuff.add_from_csv(str)`
252
253 ^ str is a comma separated list of initial stuff
254 ^ Adds items to the list of items to be given
255
256 Nyancat API
257 -----------
258
259 `nyancat.place(pos, facedir, length)`
260
261 ^ Place a cat at `pos` facing `facedir` with tail length `length`
262   Only accepts facedir 0-3, if facedir > 3 then it will be interpreted as facedir = 0
263
264 `nyancat.generate(minp, maxp, seed)`
265
266 ^ Called by `minetest.register_on_generated`. To disable nyancat generation,
267   you can redefine nyancat.generate() to be an empty function
268
269 TNT API
270 ----------
271
272 `tnt.register_tnt(definition)`
273
274 ^ Register a new type of tnt.
275
276  * `name` The name of the node. If no prefix is given `tnt` is used.
277  * `description` A description for your TNT.
278  * `radius` The radius within which the TNT can destroy nodes. The default is 3.
279  * `damage_radius` The radius within which the TNT can damage players and mobs. By default it is twice the `radius`.
280  * `disable_drops` Disable drops. By default it is set to false.
281  * `ignore_protection` Don't check `minetest.is_protected` before removing a node.
282  * `ignore_on_blast` Don't call `on_blast` even if a node has one.
283  * `tiles` Textures for node
284   * `side`  Side tiles. By default the name of the tnt with a suffix of `_side.png`.
285   * `top`  Top tile. By default the name of the tnt with a suffix of `_top.png`.
286   * `bottom` Bottom tile. By default the name of the tnt with a suffix of `_bottom.png`.
287   * `burning` Top tile when lit. By default the name of the tnt with a suffix of `_top_burning_animated.png".
288
289 `tnt.boom(position, definition)`
290
291 ^ Create an explosion.
292
293 * `position` The center of explosion.
294 * `definition` The TNT definion as passed to `tnt.register`
295
296 `tnt.burn(position, [nodename])`
297
298 ^ Ignite TNT at position, nodename isn't required unless already known.
299
300
301 To make dropping items from node inventories easier, you can use the
302 following helper function from 'default':
303
304 default.get_inventory_drops(pos, inventory, drops)
305
306 ^ Return drops from node inventory "inventory" in drops.
307
308 * `pos` - the node position
309 * `inventory` - the name of the inventory (string)
310 * `drops` - an initialized list
311
312 The function returns no values. The drops are returned in the `drops`
313 parameter, and drops is not reinitialized so you can call it several
314 times in a row to add more inventory items to it.
315
316
317 `on_blast` callbacks:
318
319 Both nodedefs and entitydefs can provide an `on_blast()` callback
320
321 `nodedef.on_blast(pos, intensity)`
322 ^ Allow drop and node removal overriding
323 * `pos` - node position
324 * `intensity` - TNT explosion measure. larger or equal to 1.0
325 ^ Should return a list of drops (e.g. {"default:stone"})
326 ^ Should perform node removal itself. If callback exists in the nodedef
327 ^ then the TNT code will not destroy this node.
328
329 `entitydef.on_blast(luaobj, damage)`
330 ^ Allow TNT effects on entities to be overridden
331 * `luaobj` - LuaEntityRef of the entity
332 * `damage` - suggested HP damage value
333 ^ Should return a list of (bool do_damage, bool do_knockback, table drops)
334 * `do_damage` - if true then TNT mod wil damage the entity
335 * `do_knockback` - if true then TNT mod will knock the entity away
336 * `drops` - a list of drops, e.g. {"wool:red"}
337
338
339 Screwdriver API
340 ---------------
341
342 The screwdriver API allows you to control a node's behaviour when a screwdriver is used on it.
343 To use it, add the `on_screwdriver` function to the node definition.
344
345 `on_rotate(pos, node, user, mode, new_param2)`
346
347  * `pos` Position of the node that the screwdriver is being used on
348  * `node` that node
349  * `user` The player who used the screwdriver
350  * `mode` screwdriver.ROTATE_FACE or screwdriver.ROTATE_AXIS
351  * `new_param2` the new value of param2 that would have been set if on_rotate wasn't there
352  * return value: false to disallow rotation, nil to keep default behaviour, true to allow
353         it but to indicate that changed have already been made (so the screwdriver will wear out)
354  * use `on_rotate = false` to always disallow rotation
355  * use `on_rotate = screwdriver.rotate_simple` to allow only face rotation
356
357
358 Sethome API
359 -----------
360
361 The sethome API adds three global functions to allow mods to read a players home position,
362 set a players home position and teleport a player to home position.
363
364 `sethome.get(name)`
365
366  * `name` Player who's home position you wish to get
367  * return value: false if no player home coords exist, position table if true
368
369 `sethome.set(name, pos)`
370
371  * `name` Player who's home position you wish to set
372  * `pos` Position table containing coords of home position
373  * return value: false if unable to set and save new home position, otherwise true
374
375 `sethome.go(name)`
376
377  * `name` Player you wish to teleport to their home position
378  * return value: false if player cannot be sent home, otherwise true
379
380
381 Stairs API
382 ----------
383
384 The stairs API lets you register stairs and slabs and ensures that they are registered the same way as those
385 delivered with Minetest Game, to keep them compatible with other mods.
386
387 `stairs.register_stair(subname, recipeitem, groups, images, description, sounds)`
388
389  * Registers a stair.
390  * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
391  * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil`
392  * `groups`: see [Known damage and digging time defining groups]
393  * `images`: see [Tile definition]
394  * `description`: used for the description field in the stair's definition
395  * `sounds`: see [#Default sounds]
396
397 `stairs.register_slab(subname, recipeitem, groups, images, description, sounds)`
398
399  * Registers a slabs
400  * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
401  * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble"
402  * `groups`: see [Known damage and digging time defining groups]
403  * `images`: see [Tile definition]
404  * `description`: used for the description field in the stair's definition
405  * `sounds`: see [#Default sounds]
406
407 `stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)`
408
409  * A wrapper for stairs.register_stair and stairs.register_slab
410  * Uses almost the same arguments as stairs.register_stair
411  * `desc_stair`: Description for stair node
412  * `desc_slab`: Description for slab node
413
414 Xpanes API
415 ----------
416
417 Creates panes that automatically connect to each other
418
419 `xpanes.register_pane(subname, def)`
420
421  * `subname`: used for nodename. Result: "xpanes:subname" and "xpanes:subname_{2..15}"
422  * `def`: See [#Pane definition]
423
424 ### Pane definition
425
426         {
427                 textures = {"texture for sides", (unused), "texture for top and bottom"}, -- More tiles aren't supported
428                 groups = {group = rating}, -- Uses the known node groups, see [Known damage and digging time defining groups]
429                 sounds = SoundSpec,        -- See [#Default sounds]
430                 recipe = {{"","","","","","","","",""}}, -- Recipe field only
431         }
432
433 Raillike definitions
434 --------------------
435
436 The following nodes use the group `connect_to_raillike` and will only connect to
437 raillike nodes within this group and the same group value.
438 Use `minetest.raillike_group(<Name>)` to get the group value.
439
440 | Node type             | Raillike group name
441 |-----------------------|---------------------
442 | default:rail          | "rail"
443 | tnt:gunpowder         | "gunpowder"
444 | tnt:gunpowder_burning | "gunpowder"
445
446 Example:
447 If you want to add a new rail type and want it to connect with default:rail,
448 add `connect_to_raillike=minetest.raillike_group("rail")` into the `groups` table
449 of your node.
450
451
452 Default sounds
453 --------------
454
455 Sounds inside the default table can be used within the sounds field of node definitions.
456
457  * `default.node_sound_defaults()`
458  * `default.node_sound_stone_defaults()`
459  * `default.node_sound_dirt_defaults()`
460  * `default.node_sound_sand_defaults()`
461  * `default.node_sound_wood_defaults()`
462  * `default.node_sound_leaves_defaults()`
463  * `default.node_sound_glass_defaults()`
464
465 Default constants
466 -----------------
467
468 `default.LIGHT_MAX`  The maximum light level (see [Node definition] light_source)
469
470 Player API
471 ----------
472
473 The player API can register player models and update the player's appearence
474
475 `default.player_register_model(name, def)`
476
477  * Register a new model to be used by players.
478  * name: model filename such as "character.x", "foo.b3d", etc.
479  * def: See [#Model definition]
480
481 `default.registered_player_models[name]`
482
483  * Get a model's definition
484  * see [#Model definition]
485
486 `default.player_set_model(player, model_name)`
487
488  * Change a player's model
489  * `player`: PlayerRef
490  * `model_name`: model registered with player_register_model()
491
492 `default.player_set_animation(player, anim_name [, speed])`
493
494  * Applies an animation to a player
495  * anim_name: name of the animation.
496  * speed: frames per second. If nil, default from the model is used
497
498 `default.player_set_textures(player, textures)`
499
500  * Sets player textures
501  * `player`: PlayerRef
502  * `textures`: array of textures, If `textures` is nil, the default textures from the model def are used
503
504 default.player_get_animation(player)
505
506  * Returns a table containing fields `model`, `textures` and `animation`.
507  * Any of the fields of the returned table may be nil.
508  * player: PlayerRef
509
510 ### Model Definition
511
512         {
513                 animation_speed = 30,            -- Default animation speed, in FPS.
514                 textures = {"character.png", },  -- Default array of textures.
515                 visual_size = {x = 1, y = 1},    -- Used to scale the model.
516                 animations = {
517                         -- <anim_name> = {x = <start_frame>, y = <end_frame>},
518                         foo = {x = 0, y = 19},
519                         bar = {x = 20, y = 39},
520                 -- ...
521                 },
522         }
523
524 Leafdecay
525 ---------
526
527 To enable leaf decay for a node, add it to the `leafdecay` group.
528
529 The rating of the group determines how far from a node in the group `tree`
530 the node can be without decaying.
531
532 If `param2` of the node is ~= 0, the node will always be preserved. Thus, if
533 the player places a node of that kind, you will want to set `param2 = 1` or so.
534
535 The function `default.after_place_leaves` can be set as `after_place_node of a node`
536 to set param2 to 1 if the player places the node (should not be used for nodes
537 that use param2 otherwise (e.g. facedir)).
538
539 If the node is in the `leafdecay_drop` group then it will always be dropped as an
540 item.
541
542 Dyes
543 ----
544
545 To make recipes that will work with any dye ever made by anybody, define
546 them based on groups. You can select any group of groups, based on your need for
547 amount of colors.
548
549 ### Color groups
550
551 Base color groups:
552
553  * `basecolor_white`
554  * `basecolor_grey`
555  * `basecolor_black`
556  * `basecolor_red`
557  * `basecolor_yellow`
558  * `basecolor_green`
559  * `basecolor_cyan`
560  * `basecolor_blue`
561  * `basecolor_magenta`
562
563 Extended color groups ( * means also base color )
564
565  * `excolor_white` *
566  * `excolor_lightgrey`
567  * `excolor_grey` *
568  * `excolor_darkgrey`
569  * `excolor_black` *
570  * `excolor_red` *
571  * `excolor_orange`
572  * `excolor_yellow` *
573  * `excolor_lime`
574  * `excolor_green` *
575  * `excolor_aqua`
576  * `excolor_cyan` *
577  * `excolor_sky_blue`
578  * `excolor_blue` *
579  * `excolor_violet`
580  * `excolor_magenta` *
581  * `excolor_red_violet`
582
583 The whole unifieddyes palette as groups:
584
585  * `unicolor_<excolor>`
586
587 For the following, no white/grey/black is allowed:
588
589  * `unicolor_medium_<excolor>`
590  * `unicolor_dark_<excolor>`
591  * `unicolor_light_<excolor>`
592  * `unicolor_<excolor>_s50`
593  * `unicolor_medium_<excolor>_s50`
594  * `unicolor_dark_<excolor>_s50`
595
596 Example of one shapeless recipe using a color group:
597
598         minetest.register_craft({
599                 type = "shapeless",
600                 output = '<mod>:item_yellow',
601                 recipe = {'<mod>:item_no_color', 'group:basecolor_yellow'},
602         })
603
604 ### Color lists
605
606  * `dye.basecolors` are an array containing the names of available base colors
607
608  * `dye.excolors` are an array containing the names of the available extended colors
609
610 Trees
611 -----
612
613  * `default.grow_tree(pos, is_apple_tree)`
614   * Grows a mgv6 tree or apple tree at pos
615
616  * `default.grow_jungle_tree(pos)`
617   * Grows a mgv6 jungletree at pos
618
619  * `default.grow_pine_tree(pos)`
620   * Grows a mgv6 pinetree at pos
621
622  * `default.grow_new_apple_tree(pos)`
623   * Grows a new design apple tree at pos
624
625  * `default.grow_new_jungle_tree(pos)`
626   * Grows a new design jungle tree at pos
627
628  * `default.grow_new_pine_tree(pos)`
629   * Grows a new design pine tree at pos
630
631  * `default.grow_new_acacia_tree(pos)`
632   * Grows a new design acacia tree at pos
633
634  * `default.grow_new_aspen_tree(pos)`
635   * Grows a new design aspen tree at pos
636
637  * `default.grow_new_snowy_pine_tree(pos)`
638   * Grows a new design snowy pine tree at pos