game_api.txt 20 KB

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