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