3 GitHub Repo: https://github.com/minetest/minetest_game
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
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}`
20 The bucket API allows registering new types of buckets for non-default liquids.
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
36 "beds:bed", -- Bed name
37 def -- See [#Bed definition]
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
47 description = "Simple Bed",
48 inventory_image = "beds_bed.png",
49 wield_image = "beds_bed.png",
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.
55 bottom = 'regular nodebox', -- bottom part of bed (see [Node boxes])
56 top = 'regular nodebox', -- top part of bed (see [Node boxes])
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"}
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.
73 The doors mod allows modders to register custom doors and trapdoors.
75 `doors.register_door(name, def)`
78 * `name` Name for door
79 * `def` See [#Door definition]
81 `doors.register_trapdoor(name, def)`
83 * Registers new trapdoor
84 * `name` Name for trapdoor
85 * `def` See [#Trapdoor definition]
87 `doors.register_fencegate(name, def)`
89 * Registers new fence gate
90 * `name` Name for fence gate
91 * `def` See [#Fence gate definition]
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
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
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.
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)
122 ### Trapdoor definition
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)
134 ### Fence gate definition
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
145 Allows creation of new fences with "fencelike" drawtype.
147 `default.register_fence(name, item definition)`
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
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(),
166 The walls API allows easy addition of stone auto-connecting wall nodes.
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]
178 The farming API allows you to easily register plants and hoes.
180 `farming.register_hoe(name, hoe definition)`
181 * Register a new hoe, see [#hoe definition]
183 `farming.register_plant(name, Plant definition)`
184 * Register a new growing plant, see [#Plant definition]
186 `farming.registered_plants[name] = definition`
187 * Table of registered plants, indexed by plant name
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"},
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
218 New node def property:
222 * Called when fire attempts to remove a burning node.
223 * `pos` Position of the burning node.
225 Give Initial Stuff API
226 ----------------------
228 `give_initial_stuff.give(player)`
230 ^ Give initial stuff to "player"
232 `give_initial_stuff.add(stack)`
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
238 `give_initial_stuff.clear()`
240 ^ Removes all items from the initial stuff
241 ^ Can be called after the game has loaded
243 `give_initial_stuff.get_list()`
245 ^ returns list of item stacks
247 `give_initial_stuff.set_list(list)`
249 ^ List of initial items with numeric indices.
251 `give_initial_stuff.add_from_csv(str)`
253 ^ str is a comma separated list of initial stuff
254 ^ Adds items to the list of items to be given
259 `nyancat.place(pos, facedir, length)`
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
264 `nyancat.generate(minp, maxp, seed)`
266 ^ Called by `minetest.register_on_generated`. To disable nyancat generation,
267 you can redefine nyancat.generate() to be an empty function
272 `tnt.register_tnt(definition)`
274 ^ Register a new type of tnt.
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".
289 `tnt.boom(position, definition)`
291 ^ Create an explosion.
293 * `position` The center of explosion.
294 * `definition` The TNT definion as passed to `tnt.register`
296 `tnt.burn(position, [nodename])`
298 ^ Ignite TNT at position, nodename isn't required unless already known.
301 To make dropping items from node inventories easier, you can use the
302 following helper function from 'default':
304 default.get_inventory_drops(pos, inventory, drops)
306 ^ Return drops from node inventory "inventory" in drops.
308 * `pos` - the node position
309 * `inventory` - the name of the inventory (string)
310 * `drops` - an initialized list
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.
317 `on_blast` callbacks:
319 Both nodedefs and entitydefs can provide an `on_blast()` callback
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.
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"}
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.
345 `on_rotate(pos, node, user, mode, new_param2)`
347 * `pos` Position of the node that the screwdriver is being used on
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
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.
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
369 `sethome.set(name, pos)`
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
377 * `name` Player you wish to teleport to their home position
378 * return value: false if player cannot be sent home, otherwise true
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.
387 `stairs.register_stair(subname, recipeitem, groups, images, description, sounds)`
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]
397 `stairs.register_slab(subname, recipeitem, groups, images, description, sounds)`
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]
407 `stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)`
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
417 Creates panes that automatically connect to each other
419 `xpanes.register_pane(subname, def)`
421 * `subname`: used for nodename. Result: "xpanes:subname" and "xpanes:subname_{2..15}"
422 * `def`: See [#Pane definition]
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
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.
440 | Node type | Raillike group name
441 |-----------------------|---------------------
442 | default:rail | "rail"
443 | tnt:gunpowder | "gunpowder"
444 | tnt:gunpowder_burning | "gunpowder"
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
455 Sounds inside the default table can be used within the sounds field of node definitions.
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()`
468 `default.LIGHT_MAX` The maximum light level (see [Node definition] light_source)
473 The player API can register player models and update the player's appearence
475 `default.player_register_model(name, def)`
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]
481 `default.registered_player_models[name]`
483 * Get a model's definition
484 * see [#Model definition]
486 `default.player_set_model(player, model_name)`
488 * Change a player's model
489 * `player`: PlayerRef
490 * `model_name`: model registered with player_register_model()
492 `default.player_set_animation(player, anim_name [, speed])`
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
498 `default.player_set_textures(player, textures)`
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
504 default.player_get_animation(player)
506 * Returns a table containing fields `model`, `textures` and `animation`.
507 * Any of the fields of the returned table may be nil.
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.
517 -- <anim_name> = {x = <start_frame>, y = <end_frame>},
518 foo = {x = 0, y = 19},
519 bar = {x = 20, y = 39},
527 To enable leaf decay for a node, add it to the `leafdecay` group.
529 The rating of the group determines how far from a node in the group `tree`
530 the node can be without decaying.
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.
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)).
539 If the node is in the `leafdecay_drop` group then it will always be dropped as an
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
561 * `basecolor_magenta`
563 Extended color groups ( * means also base color )
566 * `excolor_lightgrey`
580 * `excolor_magenta` *
581 * `excolor_red_violet`
583 The whole unifieddyes palette as groups:
585 * `unicolor_<excolor>`
587 For the following, no white/grey/black is allowed:
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`
596 Example of one shapeless recipe using a color group:
598 minetest.register_craft({
600 output = '<mod>:item_yellow',
601 recipe = {'<mod>:item_no_color', 'group:basecolor_yellow'},
606 * `dye.basecolors` are an array containing the names of available base colors
608 * `dye.excolors` are an array containing the names of the available extended colors
613 * `default.grow_tree(pos, is_apple_tree)`
614 * Grows a mgv6 tree or apple tree at pos
616 * `default.grow_jungle_tree(pos)`
617 * Grows a mgv6 jungletree at pos
619 * `default.grow_pine_tree(pos)`
620 * Grows a mgv6 pinetree at pos
622 * `default.grow_new_apple_tree(pos)`
623 * Grows a new design apple tree at pos
625 * `default.grow_new_jungle_tree(pos)`
626 * Grows a new design jungle tree at pos
628 * `default.grow_new_pine_tree(pos)`
629 * Grows a new design pine tree at pos
631 * `default.grow_new_acacia_tree(pos)`
632 * Grows a new design acacia tree at pos
634 * `default.grow_new_aspen_tree(pos)`
635 * Grows a new design aspen tree at pos
637 * `default.grow_new_snowy_pine_tree(pos)`
638 * Grows a new design snowy pine tree at pos