Doors: Allow arbitrary recipe to be passed, even nil
[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 The Minetest Game subgame offers multiple new possibilities in addition to the Minetest engine's built-in API,
8 allowing you to add new plants to farming mod, buckets for new liquids, new stairs and custom panes.
9 For information on the Minetest API, visit https://github.com/minetest/minetest/blob/master/doc/lua_api.txt
10 Please note:
11         [XYZ] refers to a section the Minetest API
12         [#ABC] refers to a section in this document
13         ^ Explanation for line above
14
15 Bucket API
16 ----------
17 The bucket API allows registering new types of buckets for non-default liquids.
18
19         bucket.register_liquid(
20                 "default:lava_source",   -- name of the source node
21                 "default:lava_flowing",  -- name of the flowing node
22                 "bucket:bucket_lava",    -- name of the new bucket item (or nil if liquid is not takeable)
23                 "bucket_lava.png",       -- texture of the new bucket item (ignored if itemname == nil)
24                 "Lava Bucket",           -- text description of the bucket item
25                 {lava_bucket = 1}        -- groups of the bucket item, OPTIONAL
26         )
27
28 Beds API
29 --------
30         beds.register_bed(
31                 "beds:bed",                 -- Bed name
32                 def: See [#Bed definition]  -- Bed definition
33         )
34
35         beds.read_spawns()   -- returns a table containing players respawn positions
36         beds.kick_players()  -- forces all players to leave bed
37         beds.skip_night()    -- sets world time to morning and saves respawn position of all players currently sleeping
38
39 #Bed definition
40 ---------------
41 {
42         description = "Simple Bed",
43         inventory_image = "beds_bed.png",
44         wield_image = "beds_bed.png",
45         tiles = {
46             bottom = {[Tile definition],
47                 ^ the tiles of the bottom part of the bed
48             },
49             top = {[Tile definition],
50                 ^ the tiles of the bottom part of the bed
51             }
52         },
53         nodebox = {
54             bottom = regular nodebox, see [Node boxes],    -- bottm part of bed
55             top = regular nodebox, see [Node boxes],       -- top part of bed
56         },
57         selectionbox = regular nodebox, see [Node boxes],  -- for both nodeboxes
58         recipe = {                                         -- Craft recipe
59                 {"group:wool", "group:wool", "group:wool"},
60                 {"group:wood", "group:wood", "group:wood"}
61         }
62 }
63
64 Doors API
65 ---------
66 The doors mod allows modders to register custom doors and trapdoors.
67
68 doors.register_door(name, def)
69 ^ name: "Door name"
70 ^ def: See [#Door definition]
71  -> Registers new door
72
73 doors.register_trapdoor(name, def)
74 ^ name: "mod_door"
75 ^ def: See [#Trapdoor definition]
76  -> Registers new trapdoor
77
78 doors.get(pos)
79 ^ pos = { x = .., y = .., z = ..}
80  -> Returns an ObjecRef to a door, or nil if the pos did not contain a door
81
82     Methods:
83         :open(player)   -- Open the door object, returns if door was opened
84         :close(player)  -- Close the door object, returns if door was closed
85         :toggle(player) -- Toggle the door state, returns if state was toggled
86         :state()        -- returns the door state, true = open, false = closed
87
88     the "player" parameter can be omitted in all methods. If passed then
89     the usual permission checks will be performed to make sure the player
90     has the permissions needed to open this door. If omitted then no
91     permission checks are performed.
92
93 #Door definition
94 ----------------
95 {
96         description = "Door description",
97         inventory_image = "mod_door_inv.png",
98         groups = {choppy = 1},
99         tiles = { "mod_door.png" },
100         recipe = craftrecipe,
101         sounds = default.node_sound_wood_defaults(), -- optional
102         sound_open = sound play for open door, -- optional
103         sound_close = sound play for close door, -- optional
104         protected = false,
105         ^ If true, only placer can open the door (locked for others)
106 }
107
108 #Trapdoor definition
109 ----------------
110 {
111         description = "Trapdoor description",
112         inventory_image = "mod_trapdoor_inv.png",
113         groups = {choppy = 1},
114         tile_front = "doors_trapdoor.png",
115         ^ the texture for the front and back of the trapdoor
116         tile_side: "doors_trapdoor_side.png",
117         ^ the tiles of the four side parts of the trapdoor
118         sounds = default.node_sound_wood_defaults(), -- optional
119         sound_open = sound play for open door, -- optional
120         sound_close = sound play for close door, -- optional
121         protected = false,
122         ^ If true, only placer can open the door (locked for others)
123 }
124
125 Fence API
126 ---------
127 Allows creation of new fences with "fencelike" drawtype.
128
129 default.register_fence(name, item definition)
130  ^ Registers a new fence. Custom fields texture and material are required, as
131  ^ are name and description. The rest is optional. You can pass most normal
132  ^ nodedef fields here except drawtype. The fence group will always be added
133  ^ for this node.
134
135 #fence definition
136         name = "default:fence_wood",
137         description = "Wooden Fence",
138         texture = "default_wood.png",
139         material = "default:wood",
140         groups = {choppy=2, oddly_breakable_by_hand = 2, flammable = 2},
141         sounds = default.node_sound_wood_defaults(),
142
143 Farming API
144 -----------
145 The farming API allows you to easily register plants and hoes.
146
147 farming.register_hoe(name, hoe definition)
148  -> Register a new hoe, see [#hoe definition]
149
150 farming.register_plant(name, Plant definition)
151  -> Register a new growing plant, see [#Plant definition]
152
153 #Hoe Definition
154 ---------------
155 {
156         description = "",                      -- Description for tooltip
157         inventory_image = "unknown_item.png",  -- Image to be used as wield- and inventory image
158         max_uses = 30,                         -- Uses until destroyed
159         material = "",                         -- Material for recipes
160         recipe = {                             -- Craft recipe, if material isn't used
161                 {"air", "air", "air"},
162                 {"", "group:stick"},
163                 {"", "group:stick"},
164         }
165 }
166
167 #Plant definition
168 -----------------
169 {
170         description = "",                      -- Description of seed item
171         inventory_image = "unknown_item.png",  -- Image to be used as seed's wield- and inventory image
172         steps = 8,                             -- How many steps the plant has to grow, until it can be harvested
173         ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
174         minlight = 13,                         -- Minimum light to grow
175         maxlight = default.LIGHT_MAX           -- Maximum light to grow
176 }
177
178 Screwdriver API
179 ---------------
180 The screwdriver API allows you to control a node's behaviour when a screwdriver is used on it.
181 To use it, add the on_screwdriver function to the node definition.
182 on_rotate(pos, node, user, mode, new_param2)
183 ^ pos: position of the node that the screwdriver is being used on
184 ^ node: that node
185 ^ user: the player who used the screwdriver
186 ^ mode: screwdriver.ROTATE_FACE or screwdriver.ROTATE_AXIS
187 ^ new_param2: the new value of param2 that would have been set if on_rotate wasn't there
188 ^ return value: false to disallow rotation, nil to keep default behaviour, true to allow
189         it but to indicate that changed have already been made (so the screwdriver will wear out)
190 ^ use on_rotate = screwdriver.disallow to always disallow rotation
191 ^ use on_rotate = screwdriver.rotate_simple to allow only face rotation
192
193 Stairs API
194 ----------
195 The stairs API lets you register stairs and slabs and ensures that they are registered the same way as those
196 delivered with Minetest Game, to keep them compatible with other mods.
197
198 stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
199  -> Registers a stair.
200  -> subname: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
201  -> recipeitem: Item used in the craft recipe, e.g. "default:cobble"
202  -> groups: see [Known damage and digging time defining groups]
203  -> images: see [Tile definition]
204  -> description: used for the description field in the stair's definition
205  -> sounds: see [#Default sounds]
206
207 stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
208  -> Registers a slabs
209  -> subname: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname"
210  -> recipeitem: Item used in the craft recipe, e.g. "default:cobble"
211  -> groups: see [Known damage and digging time defining groups]
212  -> images: see [Tile definition]
213  -> description: used for the description field in the stair's definition
214  -> sounds: see [#Default sounds]
215
216 stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
217  -> A wrapper for stairs.register_stair and stairs.register_slab
218  -> Uses almost the same arguments as stairs.register_stair
219  -> desc_stair: Description for stair node
220  -> desc_slab: Description for slab node
221
222 Xpanes API
223 ----------
224 Creates panes that automatically connect to each other
225
226 xpanes.register_pane(subname, def)
227  -> subname: used for nodename. Result: "xpanes:subname" and "xpanes:subname_{2..15}"
228  -> def: See [#Pane definition]
229
230 #Pane definition
231 ----------------
232 {
233         textures = {"texture_Bottom_top", "texture_left_right", "texture_front_back"},
234         ^ More tiles aren't supported
235         groups = {group = rating},
236         ^ Uses the known node groups, see [Known damage and digging time defining groups]
237         sounds = SoundSpec,
238         ^ See [#Default sounds]
239         recipe = {{"","","","","","","","",""}},
240         ^ Recipe field only
241 }
242
243 Raillike definitions
244 --------------------
245 The following nodes use the group `connect_to_raillike` and will only connect to
246 raillike nodes within this group and the same group value.
247 Use `minetest.raillike_group(<Name>)` to get the group value.
248
249 | Node type             | Raillike group name
250 +-----------------------+--------------------
251 | default:rail          | "rail"
252 | tnt:gunpowder         | "gunpowder"
253 | tnt:gunpowder_burning | "gunpowder"
254
255 Example:
256 If you want to add a new rail type and want it to connect with default:rail,
257 add `connect_to_raillike=minetest.raillike_group("rail")` into the `groups` table
258 of your node.
259
260
261 Default sounds
262 --------------
263 Sounds inside the default table can be used within the sounds field of node definitions.
264
265 default.node_sound_defaults()
266 default.node_sound_stone_defaults()
267 default.node_sound_dirt_defaults()
268 default.node_sound_sand_defaults()
269 default.node_sound_wood_defaults()
270 default.node_sound_leaves_defaults()
271 default.node_sound_glass_defaults()
272
273 Default constants
274 -----------------
275 default.LIGHT_MAX
276 ^ The maximum light level (see [Node definition] light_source)
277
278 Player API
279 ----------
280 The player API can register player models and update the player's appearence
281
282 default.player_register_model(name, def)
283 ^ Register a new model to be used by players.
284  -> name: model filename such as "character.x", "foo.b3d", etc.
285  -> def: See [#Model definition]
286
287 default.registered_player_models[name]
288 ^ Get a model's definition
289  -> see [#Model definition]
290
291 default.player_set_model(player, model_name)
292 ^ Change a player's model
293  -> player: PlayerRef
294  -> model_name: model registered with player_register_model()
295
296 default.player_set_animation(player, anim_name [, speed])
297 ^ Applies an animation to a player
298  -> anim_name: name of the animation.
299  -> speed: frames per second. If nil, default from the model is used
300
301 default.player_set_textures(player, textures)
302 ^ Sets player textures
303  -> player: PlayerRef
304  -> textures: array of textures
305  ^ If <textures> is nil, the default textures from the model def are used
306
307 default.player_get_animation(player)
308 ^ Returns a table containing fields "model", "textures" and "animation".
309 ^ Any of the fields of the returned table may be nil.
310  -> player: PlayerRef
311
312 Model Definition
313 ----------------
314 {
315         animation_speed = 30,            -- Default animation speed, in FPS.
316         textures = {"character.png", },  -- Default array of textures.
317         visual_size = {x = 1, y = 1},    -- Used to scale the model.
318         animations = {
319                 -- <anim_name> = {x = <start_frame>, y = <end_frame>},
320                 foo = {x = 0, y = 19},
321                 bar = {x = 20, y = 39},
322                 -- ...
323         },
324 }
325
326 Leafdecay
327 ---------
328 To enable leaf decay for a node, add it to the "leafdecay" group.
329
330 The rating of the group determines how far from a node in the group "tree"
331 the node can be without decaying.
332
333 If param2 of the node is ~= 0, the node will always be preserved. Thus, if
334 the player places a node of that kind, you will want to set param2=1 or so.
335
336 The function default.after_place_leaves can be set as after_place_node of a node
337 to set param2 to 1 if the player places the node (should not be used for nodes
338 that use param2 otherwise (e.g. facedir)).
339
340 If the node is in the leafdecay_drop group then it will always be dropped as an
341 item.
342
343 Dyes
344 ----
345 To make recipes that will work with any dye ever made by anybody, define
346 them based on groups. You can select any group of groups, based on your need for
347 amount of colors.
348
349 #Color groups
350 -------------
351 Base color groups:
352 - basecolor_white
353 - basecolor_grey
354 - basecolor_black
355 - basecolor_red
356 - basecolor_yellow
357 - basecolor_green
358 - basecolor_cyan
359 - basecolor_blue
360 - basecolor_magenta
361
362 Extended color groups (* = equal to a base color):
363 * excolor_white
364 - excolor_lightgrey
365 * excolor_grey
366 - excolor_darkgrey
367 * excolor_black
368 * excolor_red
369 - excolor_orange
370 * excolor_yellow
371 - excolor_lime
372 * excolor_green
373 - excolor_aqua
374 * excolor_cyan
375 - excolor_sky_blue
376 * excolor_blue
377 - excolor_violet
378 * excolor_magenta
379 - excolor_red_violet
380
381 The whole unifieddyes palette as groups:
382 - unicolor_<excolor>
383 For the following, no white/grey/black is allowed:
384 - unicolor_medium_<excolor>
385 - unicolor_dark_<excolor>
386 - unicolor_light_<excolor>
387 - unicolor_<excolor>_s50
388 - unicolor_medium_<excolor>_s50
389 - unicolor_dark_<excolor>_s50
390
391 Example of one shapeless recipe using a color group:
392 minetest.register_craft({
393         type = "shapeless",
394         output = '<mod>:item_yellow',
395         recipe = {'<mod>:item_no_color', 'group:basecolor_yellow'},
396 })
397
398 #Color lists
399 ------------
400 dye.basecolors
401 ^ Array containing the names of available base colors
402
403 dye.excolors
404 ^ Array containing the names of the available extended colors
405
406 Trees
407 -----
408 default.grow_tree(pos, is_apple_tree)
409 ^ Grows a mgv6 tree or apple tree at pos
410
411 default.grow_jungle_tree(pos)
412 ^ Grows a mgv6 jungletree at pos
413
414 default.grow_pine_tree(pos)
415 ^ Grows a mgv6 pinetree at pos
416
417 default.grow_new_apple_tree(pos)
418 ^ Grows a new design apple tree at pos
419
420 default.grow_new_jungle_tree(pos)
421 ^ Grows a new design jungle tree at pos
422
423 default.grow_new_pine_tree(pos)
424 ^ Grows a new design pine tree at pos
425
426 default.grow_new_acacia_tree(pos)
427 ^ Grows a new design acacia tree at pos