lua_api.txt 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. Minetest Lua Modding API Reference 0.4.dev
  2. ==========================================
  3. More information at http://c55.me/minetest/
  4. Introduction
  5. -------------
  6. Content and functionality can be added to Minetest 0.4 by using Lua
  7. scripting in run-time loaded mods.
  8. A mod is a self-contained bunch of scripts, textures and other related
  9. things that is loaded by and interfaces with Minetest.
  10. Mods are contained and ran solely on the server side. Definitions and media
  11. files are automatically transferred to the client.
  12. If you see a deficiency in the API, feel free to attempt to add the
  13. functionality in the engine and API. You can send such improvements as
  14. source code patches to <celeron55@gmail.com>.
  15. Programming in Lua
  16. -------------------
  17. If you have any difficulty in understanding this, please read:
  18. http://www.lua.org/pil/
  19. Startup
  20. --------
  21. Mods are loaded during server startup from the mod load paths by running
  22. the init.lua scripts in a shared environment.
  23. Mod load path
  24. -------------
  25. Generic:
  26. $path_share/games/gameid/mods/
  27. $path_share/mods/gameid/
  28. $path_user/games/gameid/mods/
  29. $path_user/mods/gameid/ <-- User-installed mods
  30. $worldpath/worldmods/
  31. In a run-in-place version (eg. the distributed windows version):
  32. minetest-0.4.x/games/gameid/mods/
  33. minetest-0.4.x/mods/gameid/ <-- User-installed mods
  34. minetest-0.4.x/worlds/worldname/worldmods/
  35. On an installed version on linux:
  36. /usr/share/minetest/games/gameid/mods/
  37. ~/.minetest/mods/gameid/ <-- User-installed mods
  38. ~/.minetest/worlds/worldname/worldmods
  39. Mod load path for world-specific games
  40. --------------------------------------
  41. It is possible to include a game in a world; in this case, no mods or
  42. games are loaded or checked from anywhere else.
  43. This is useful for eg. adventure worlds.
  44. This happens if the following directory exists:
  45. $world/game/
  46. Mods should be then be placed in:
  47. $world/game/mods/
  48. Modpack support
  49. ----------------
  50. Mods can be put in a subdirectory, if the parent directory, which otherwise
  51. should be a mod, contains a file named modpack.txt. This file shall be
  52. empty, except for lines starting with #, which are comments.
  53. Mod directory structure
  54. ------------------------
  55. mods
  56. |-- modname
  57. | |-- depends.txt
  58. | |-- init.lua
  59. | |-- textures
  60. | | |-- modname_stuff.png
  61. | | `-- modname_something_else.png
  62. | |-- sounds
  63. | |-- media
  64. | `-- <custom data>
  65. `-- another
  66. modname:
  67. The location of this directory can be fetched by using
  68. minetest.get_modpath(modname)
  69. depends.txt:
  70. List of mods that have to be loaded before loading this mod.
  71. A single line contains a single modname.
  72. init.lua:
  73. The main Lua script. Running this script should register everything it
  74. wants to register. Subsequent execution depends on minetest calling the
  75. registered callbacks.
  76. minetest.setting_get(name) and minetest.setting_getbool(name) can be used
  77. to read custom or existing settings at load time, if necessary.
  78. textures, sounds, media:
  79. Media files (textures, sounds, whatever) that will be transferred to the
  80. client and will be available for use by the mod.
  81. Naming convention for registered textual names
  82. ----------------------------------------------
  83. Registered names should generally be in this format:
  84. "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
  85. This is to prevent conflicting names from corrupting maps and is
  86. enforced by the mod loader.
  87. Example: mod "experimental", ideal item/node/entity name "tnt":
  88. -> the name should be "experimental:tnt".
  89. Enforcement can be overridden by prefixing the name with ":". This can
  90. be used for overriding the registrations of some other mod.
  91. Example: Any mod can redefine experimental:tnt by using the name
  92. ":experimental:tnt" when registering it.
  93. (also that mod is required to have "experimental" as a dependency)
  94. The ":" prefix can also be used for maintaining backwards compatibility.
  95. Aliases
  96. -------
  97. Aliases can be added by using minetest.register_alias(name, convert_to)
  98. This will make Minetest to convert things called name to things called
  99. convert_to.
  100. This can be used for maintaining backwards compatibility.
  101. This can be also used for setting quick access names for things, eg. if
  102. you have an item called epiclylongmodname:stuff, you could do
  103. minetest.register_alias("stuff", "epiclylongmodname:stuff")
  104. and be able to use "/giveme stuff".
  105. Textures
  106. --------
  107. Mods should generally prefix their textures with modname_, eg. given
  108. the mod name "foomod", a texture could be called
  109. "foomod_foothing.png"
  110. Textures are referred to by their complete name, or alternatively by
  111. stripping out the file extension:
  112. eg. foomod_foothing.png
  113. eg. foomod_foothing
  114. Sounds
  115. -------
  116. Only OGG files are supported.
  117. For positional playing of sounds, only single-channel (mono) files are
  118. supported. Otherwise OpenAL will play them non-positionally.
  119. Mods should generally prefix their sounds with modname_, eg. given
  120. the mod name "foomod", a sound could be called
  121. "foomod_foosound.ogg"
  122. Sounds are referred to by their name with a dot, a single digit and the
  123. file extension stripped out. When a sound is played, the actual sound file
  124. is chosen randomly from the matching sounds.
  125. When playing the sound "foomod_foosound", the sound is chosen randomly
  126. from the available ones of the following files:
  127. foomod_foosound.ogg
  128. foomod_foosound.0.ogg
  129. foomod_foosound.1.ogg
  130. ...
  131. foomod_foosound.9.ogg
  132. Examples of sound parameter tables:
  133. -- Play locationless on all clients
  134. {
  135. gain = 1.0, -- default
  136. }
  137. -- Play locationless to a player
  138. {
  139. to_player = name,
  140. gain = 1.0, -- default
  141. }
  142. -- Play in a location
  143. {
  144. pos = {x=1,y=2,z=3},
  145. gain = 1.0, -- default
  146. max_hear_distance = 32, -- default
  147. }
  148. -- Play connected to an object, looped
  149. {
  150. object = <an ObjectRef>,
  151. gain = 1.0, -- default
  152. max_hear_distance = 32, -- default
  153. loop = true, -- only sounds connected to objects can be looped
  154. }
  155. SimpleSoundSpec:
  156. eg. ""
  157. eg. "default_place_node"
  158. eg. {}
  159. eg. {name="default_place_node"}
  160. eg. {name="default_place_node", gain=1.0}
  161. Registered definitions of stuff
  162. --------------------------------
  163. Anything added using certain minetest.register_* functions get added to
  164. the global minetest.registered_* tables.
  165. minetest.register_entity(name, prototype table)
  166. -> minetest.registered_entities[name]
  167. minetest.register_node(name, node definition)
  168. -> minetest.registered_items[name]
  169. -> minetest.registered_nodes[name]
  170. minetest.register_tool(name, item definition)
  171. -> minetest.registered_items[name]
  172. minetest.register_craftitem(name, item definition)
  173. -> minetest.registered_items[name]
  174. Note that in some cases you will stumble upon things that are not contained
  175. in these tables (eg. when a mod has been removed). Always check for
  176. existence before trying to access the fields.
  177. Example: If you want to check the drawtype of a node, you could do:
  178. local function get_nodedef_field(nodename, fieldname)
  179. if not minetest.registered_nodes[nodename] then
  180. return nil
  181. end
  182. return minetest.registered_nodes[nodename][fieldname]
  183. end
  184. local drawtype = get_nodedef_field(nodename, "drawtype")
  185. Example: minetest.get_item_group(name, group) has been implemented as:
  186. function minetest.get_item_group(name, group)
  187. if not minetest.registered_items[name] or not
  188. minetest.registered_items[name].groups[group] then
  189. return 0
  190. end
  191. return minetest.registered_items[name].groups[group]
  192. end
  193. Nodes
  194. ------
  195. Nodes are the bulk data of the world: cubes and other things that take the
  196. space of a cube. Huge amounts of them are handled efficiently, but they
  197. are quite static.
  198. The definition of a node is stored and can be accessed by name in
  199. minetest.registered_nodes[node.name]
  200. See "Registered definitions of stuff".
  201. Nodes are passed by value between Lua and the engine.
  202. They are represented by a table:
  203. {name="name", param1=num, param2=num}
  204. param1 and param2 are 8 bit and 4 bit integers, respectively. The engine
  205. uses them for certain automated functions. If you don't use these
  206. functions, you can use them to store arbitrary values.
  207. The functions of param1 and param2 are determined by certain fields in the
  208. node definition:
  209. param1 is reserved for the engine when paramtype != "none":
  210. paramtype = "light"
  211. ^ The value stores light with and without sun in it's
  212. upper and lower 4 bits.
  213. param2 is reserved for the engine when any of these are used:
  214. liquidtype == "flowing"
  215. ^ The level and some flags of the liquid is stored in param2
  216. drawtype == "flowingliquid"
  217. ^ The drawn liquid level is read from param2
  218. drawtype == "torchlike"
  219. drawtype == "signlike"
  220. paramtype2 == "wallmounted"
  221. ^ The rotation of the node is stored in param2. You can make this value
  222. by using minetest.dir_to_wallmounted().
  223. paramtype2 == "facedir"
  224. ^ The rotation of the node is stored in param2. Furnaces and chests are
  225. rotated this way. Can be made by using minetest.dir_to_facedir().
  226. Nodes can also contain extra data. See "Node Metadata".
  227. Representations of simple things
  228. --------------------------------
  229. Position/vector:
  230. {x=num, y=num, z=num}
  231. Currently the API does not provide any helper functions for addition,
  232. subtraction and whatever; you can define those that you need yourself.
  233. Items
  234. ------
  235. Node (register_node):
  236. A node from the world
  237. Tool (register_tool):
  238. A tool/weapon that can dig and damage things according to tool_capabilities
  239. Craftitem (register_craftitem):
  240. A miscellaneous item
  241. Items and item stacks can exist in three formats:
  242. Serialized; This is called stackstring or itemstring:
  243. eg. 'default:dirt 5'
  244. eg. 'default:pick_wood 21323'
  245. eg. 'default:apple'
  246. Table format:
  247. eg. {name="default:dirt", count=5, wear=0, metadata=""}
  248. ^ 5 dirt nodes
  249. eg. {name="default:pick_wood", count=1, wear=21323, metadata=""}
  250. ^ a wooden pick about 1/3 weared out
  251. eg. {name="default:apple", count=1, wear=0, metadata=""}
  252. ^ an apple.
  253. ItemStack:
  254. C++ native format with many helper methods. Useful for converting between
  255. formats. See the Class reference section for details.
  256. When an item must be passed to a function, it can usually be in any of
  257. these formats.
  258. Groups
  259. -------
  260. In a number of places, there is a group table. Groups define the
  261. properties of a thing (item, node, armor of entity, capabilities of
  262. tool) in such a way that the engine and other mods can can interact with
  263. the thing without actually knowing what the thing is.
  264. Usage:
  265. - Groups are stored in a table, having the group names with keys and the
  266. group ratings as values. For example:
  267. groups = {crumbly=3, soil=1}
  268. ^ Default dirt (soil group actually currently not defined; TODO)
  269. groups = {crumbly=2, soil=1, level=2, outerspace=1}
  270. ^ A more special dirt-kind of thing
  271. - Groups always have a rating associated with them. If there is no
  272. useful meaning for a rating for an enabled group, it shall be 1.
  273. - When not defined, the rating of a group defaults to 0. Thus when you
  274. read groups, you must interpret nil and 0 as the same value, 0.
  275. You can read the rating of a group for an item or a node by using
  276. minetest.get_item_group(itemname, groupname)
  277. Groups of items
  278. ----------------
  279. Groups of items can define what kind of an item it is (eg. wool).
  280. Groups of nodes
  281. ----------------
  282. In addition to the general item things, groups are used to define whether
  283. a node is destroyable and how long it takes to destroy by a tool.
  284. Groups of entities
  285. -------------------
  286. For entities, groups are, as of now, used only for calculating damage.
  287. object.get_armor_groups() -> a group-rating table (eg. {fleshy=3})
  288. object.set_armor_groups({level=2, fleshy=2, cracky=2})
  289. Groups of tools
  290. ----------------
  291. Groups in tools define which groups of nodes and entities they are
  292. effective towards.
  293. Groups in crafting recipes
  294. ---------------------------
  295. An example:
  296. {
  297. output = 'food:meat_soup_raw',
  298. recipe = {
  299. {'group:meat'},
  300. {'group:water'},
  301. {'group:bowl'},
  302. },
  303. preserve = {'group:bowl'}, -- Not implemented yet (TODO)
  304. }
  305. Special groups
  306. ---------------
  307. - immortal: Disables the group damage system for an entity
  308. - level: Can be used to give an additional sense of progression in the game.
  309. - A larger level will cause eg. a weapon of a lower level make much less
  310. damage, and get weared out much faster, or not be able to get drops
  311. from destroyed nodes.
  312. - 0 is something that is directly accessible at the start of gameplay
  313. - There is no upper limit
  314. - dig_immediate: (player can always pick up node without tool wear)
  315. - 2: node is removed without tool wear after 0.5 seconds or so
  316. (rail, sign)
  317. - 3: node is removed without tool wear immediately (torch)
  318. Known damage and digging time defining groups
  319. ----------------------------------------------
  320. Valid ratings for these are 0, 1, 2 and 3, unless otherwise stated.
  321. - crumbly: dirt, sand
  322. - cracky: tough but crackable stuff like stone.
  323. - snappy: something that can be cut using fine tools; eg. leaves, small
  324. plants, wire, sheets of metal
  325. - choppy: something that can be cut using force; eg. trees, wooden planks
  326. - fleshy: Living things like animals and the player. This could imply
  327. some blood effects when hitting.
  328. - explody: Especially prone to explosions
  329. - oddly_breakable_by_hand:
  330. Can be added to nodes that shouldn't logically be breakable by the
  331. hand but are. Somewhat similar to dig_immediate, but times are more
  332. like {[1]=3.50,[2]=2.00,[3]=0.70} and this does not override the
  333. speed of a tool if the tool can dig at a faster speed than this
  334. suggests for the hand.
  335. Examples of custom groups
  336. --------------------------
  337. Item groups are often used for defining, well, //groups of items//.
  338. - meat: any meat-kind of a thing (rating might define the size or healing
  339. ability or be irrelevant - it is not defined as of yet)
  340. - eatable: anything that can be eaten. Rating might define HP gain in half
  341. hearts.
  342. - flammable: can be set on fire. Rating might define the intensity of the
  343. fire, affecting eg. the speed of the spreading of an open fire.
  344. - wool: any wool (any origin, any color)
  345. - metal: any metal
  346. - weapon: any weapon
  347. - heavy: anything considerably heavy
  348. Digging time calculation specifics
  349. -----------------------------------
  350. Groups such as **crumbly**, **cracky** and **snappy** are used for this
  351. purpose. Rating is 1, 2 or 3. A higher rating for such a group implies
  352. faster digging time.
  353. The **level** group is used to limit the toughness of nodes a tool can dig
  354. and to scale the digging times / damage to a greater extent.
  355. ^ PLEASE DO UNDERSTAND THIS, otherwise you cannot use the system to it's
  356. full potential.
  357. Tools define their properties by a list of parameters for groups. They
  358. cannot dig other groups; thus it is important to use a standard bunch of
  359. groups to enable interaction with tools.
  360. **Tools define:**
  361. * Full punch interval
  362. * Maximum drop level
  363. * For an arbitrary list of groups:
  364. * Uses (until the tool breaks)
  365. * Maximum level (usually 0, 1, 2 or 3)
  366. * Digging times
  367. **Full punch interval**:
  368. When used as a weapon, the tool will do full damage if this time is spent
  369. between punches. If eg. half the time is spent, the tool will do half
  370. damage.
  371. **Maximum drop level**
  372. Suggests the maximum level of node, when dug with the tool, that will drop
  373. it's useful item. (eg. iron ore to drop a lump of iron).
  374. - This is not automated; it is the responsibility of the node definition
  375. to implement this
  376. **Uses**
  377. Determines how many uses the tool has when it is used for digging a node,
  378. of this group, of the maximum level. For lower leveled nodes, the use count
  379. is multiplied by 3^leveldiff.
  380. - uses=10, leveldiff=0 -> actual uses: 10
  381. - uses=10, leveldiff=1 -> actual uses: 30
  382. - uses=10, leveldiff=2 -> actual uses: 90
  383. **Maximum level**
  384. Tells what is the maximum level of a node of this group that the tool will
  385. be able to dig.
  386. **Digging times**
  387. List of digging times for different ratings of the group, for nodes of the
  388. maximum level.
  389. * For example, as a lua table, ''times={2=2.00, 3=0.70}''. This would
  390. result in the tool to be able to dig nodes that have a rating of 2 or 3
  391. for this group, and unable to dig the rating 1, which is the toughest.
  392. Unless there is a matching group that enables digging otherwise.
  393. * For entities, damage equals the amount of nodes dug in the time spent
  394. between hits, with a maximum time of ''full_punch_interval''.
  395. Example definition of the capabilities of a tool
  396. -------------------------------------------------
  397. tool_capabilities = {
  398. full_punch_interval=1.5,
  399. max_drop_level=1,
  400. groupcaps={
  401. crumbly={maxlevel=2, uses=20, times={[1]=1.60, [2]=1.20, [3]=0.80}}
  402. }
  403. }
  404. This makes the tool be able to dig nodes that fullfill both of these:
  405. - Have the **crumbly** group
  406. - Have a **level** group less or equal to 2
  407. Table of resulting digging times:
  408. crumbly 0 1 2 3 4 <- level
  409. -> 0 - - - - -
  410. 1 0.80 1.60 1.60 - -
  411. 2 0.60 1.20 1.20 - -
  412. 3 0.40 0.80 0.80 - -
  413. level diff: 2 1 0 -1 -2
  414. Table of resulting tool uses:
  415. -> 0 - - - - -
  416. 1 180 60 20 - -
  417. 2 180 60 20 - -
  418. 3 180 60 20 - -
  419. Notes:
  420. - At crumbly=0, the node is not diggable.
  421. - At crumbly=3, the level difference digging time divider kicks in and makes
  422. easy nodes to be quickly breakable.
  423. - At level > 2, the node is not diggable, because it's level > maxlevel
  424. Entity damage mechanism
  425. ------------------------
  426. Damage calculation:
  427. - Take the time spent after the last hit
  428. - Limit time to full_punch_interval
  429. - Take the damage groups and imagine a bunch of nodes that have them
  430. - Damage in HP is the amount of nodes destroyed in this time.
  431. Client predicts damage based on damage groups. Because of this, it is able to
  432. give an immediate response when an entity is damaged or dies; the response is
  433. pre-defined somehow (eg. by defining a sprite animation) (not implemented;
  434. TODO).
  435. - Currently a smoke puff will appear when an entity dies.
  436. The group **immortal** completely disables normal damage.
  437. Entities can define a special armor group, which is **punch_operable**. This
  438. group disables the regular damage mechanism for players punching it by hand or
  439. a non-tool item, so that it can do something else than take damage.
  440. On the Lua side, every punch calls ''entity:on_punch(puncher,
  441. time_from_last_punch, tool_capabilities, direction)''. This should never be
  442. called directly, because damage is usually not handled by the entity itself.
  443. * ''puncher'' is the object performing the punch. Can be nil. Should never be
  444. accessed unless absolutely required, to encourage interoperability.
  445. * ''time_from_last_punch'' is time from last punch (by puncher) or nil.
  446. * ''tool_capabilities'' can be nil.
  447. * ''direction'' is a unit vector, pointing from the source of the punch to
  448. the punched object.
  449. To punch an entity/object in Lua, call ''object:punch(puncher,
  450. time_from_last_punch, tool_capabilities, direction)''.
  451. * Return value is tool wear.
  452. * Parameters are equal to the above callback.
  453. * If ''direction'' is nil and ''puncher'' is not nil, ''direction'' will be
  454. automatically filled in based on the location of ''puncher''.
  455. Node Metadata
  456. -------------
  457. The instance of a node in the world normally only contains the three values
  458. mentioned in "Nodes". However, it is possible to insert extra data into a
  459. node. It is called "node metadata"; See "NodeMetaRef".
  460. Metadata contains two things:
  461. - A key-value store
  462. - An inventory
  463. Some of the values in the key-value store are handled specially:
  464. - formspec: Defines a right-click inventory menu. See "Formspec".
  465. - infotext: Text shown on the screen when the node is pointed at
  466. Example stuff:
  467. local meta = minetest.env:get_meta(pos)
  468. meta:set_string("formspec",
  469. "invsize[8,9;]"..
  470. "list[context;main;0,0;8,4;]"..
  471. "list[current_player;main;0,5;8,4;]")
  472. meta:set_string("infotext", "Chest");
  473. local inv = meta:get_inventory()
  474. inv:set_size("main", 8*4)
  475. print(dump(meta:to_table()))
  476. meta:from_table({
  477. inventory = {
  478. main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", [10] = "", [11] = "", [12] = "", [13] = "", [14] = "default:cobble", [15] = "", [16] = "", [17] = "", [18] = "", [19] = "", [20] = "default:cobble", [21] = "", [22] = "", [23] = "", [24] = "", [25] = "", [26] = "", [27] = "", [28] = "", [29] = "", [30] = "", [31] = "", [32] = ""}
  479. },
  480. fields = {
  481. formspec = "invsize[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
  482. infotext = "Chest"
  483. }
  484. })
  485. Formspec
  486. --------
  487. Formspec defines a menu. Currently not much else than inventories are
  488. supported. It is a string, with a somewhat strange format.
  489. Spaces and newlines can be inserted between the blocks, as is used in the
  490. examples.
  491. Examples:
  492. - Chest:
  493. invsize[8,9;]
  494. list[context;main;0,0;8,4;]
  495. list[current_player;main;0,5;8,4;]
  496. - Furnace:
  497. invsize[8,9;]
  498. list[context;fuel;2,3;1,1;]
  499. list[context;src;2,1;1,1;]
  500. list[context;dst;5,1;2,2;]
  501. list[current_player;main;0,5;8,4;]
  502. - Minecraft-like player inventory
  503. invsize[8,7.5;]
  504. image[1,0.6;1,2;player.png]
  505. list[current_player;main;0,3.5;8,4;]
  506. list[current_player;craft;3,0;3,3;]
  507. list[current_player;craftpreview;7,1;1,1;]
  508. Elements:
  509. invsize[<W>,<H>;]
  510. ^ Define the size of the menu in inventory slots
  511. list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]
  512. ^ Show an inventory list
  513. image[<X>,<Y>;<W>,<H>;<texture name>]
  514. ^ Show an image
  515. ^ Position and size units are inventory slots
  516. field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
  517. ^ Textual field; will be sent to server when a button is clicked
  518. ^ Position and size units are inventory slots
  519. ^ Not implemented
  520. button[<X>,<Y>;<W>,<H>;<name>;<label>]
  521. ^ Clickable button. When clicked, fields will be sent.
  522. ^ Button will be visible as a field, with the value "active".
  523. ^ Position and size units are inventory slots
  524. ^ Not implemented
  525. Inventory location:
  526. - "context": Selected node metadata (deprecated: "current_name")
  527. - "current_player": Player to whom the menu is shown
  528. - "player:<name>": Any player
  529. - "nodemeta:<X>,<Y>,<Z>": Any node metadata
  530. Helper functions
  531. -----------------
  532. dump2(obj, name="_", dumped={})
  533. ^ Return object serialized as a string, handles reference loops
  534. dump(obj, dumped={})
  535. ^ Return object serialized as a string
  536. string:split(separator)
  537. ^ eg. string:split("a,b", ",") == {"a","b"}
  538. string:trim()
  539. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  540. minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)"
  541. ^ Convert position to a printable string
  542. minetest.string_to_pos(string) -> position
  543. minetest namespace reference
  544. -----------------------------
  545. minetest.get_current_modname() -> string
  546. minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
  547. ^ Useful for loading additional .lua modules or static data from mod
  548. minetest.get_worldpath() -> eg. "/home/user/.minetest/world"
  549. ^ Useful for storing custom data
  550. minetest.is_singleplayer()
  551. minetest.debug(line)
  552. ^ Always printed to stderr and logfile (print() is redirected here)
  553. minetest.log(line)
  554. minetest.log(loglevel, line)
  555. ^ loglevel one of "error", "action", "info", "verbose"
  556. Registration functions: (Call these only at load time)
  557. minetest.register_entity(name, prototype table)
  558. minetest.register_abm(abm definition)
  559. minetest.register_node(name, node definition)
  560. minetest.register_tool(name, item definition)
  561. minetest.register_craftitem(name, item definition)
  562. minetest.register_alias(name, convert_to)
  563. minetest.register_craft(recipe)
  564. Global callback registration functions: (Call these only at load time)
  565. minetest.register_globalstep(func(dtime))
  566. ^ Called every server step, usually interval of 0.05s
  567. minetest.register_on_placenode(func(pos, newnode, placer))
  568. ^ Called when a node has been placed
  569. ^ Deprecated: Use on_construct or after_place_node in node definition instead
  570. minetest.register_on_dignode(func(pos, oldnode, digger))
  571. ^ Called when a node has been dug. digger can be nil.
  572. ^ Deprecated: Use on_destruct or after_dig_node in node definition instead
  573. minetest.register_on_punchnode(func(pos, node, puncher))
  574. ^ Called when a node is punched
  575. minetest.register_on_generated(func(minp, maxp, blockseed))
  576. ^ Called after generating a piece of world. Modifying nodes inside the area
  577. is a bit faster than usually.
  578. minetest.register_on_newplayer(func(ObjectRef))
  579. ^ Called after a new player has been created
  580. minetest.register_on_dieplayer(func(ObjectRef))
  581. ^ Called when a player dies
  582. minetest.register_on_respawnplayer(func(ObjectRef))
  583. ^ Called when player is to be respawned
  584. ^ Called _before_ repositioning of player occurs
  585. ^ return true in func to disable regular player placement
  586. minetest.register_on_chat_message(func(name, message))
  587. Other registration functions:
  588. minetest.register_chatcommand(cmd, chatcommand definition)
  589. minetest.register_privilege(name, definition)
  590. ^ definition: "description text"
  591. ^ definition: {
  592. description = "description text",
  593. give_to_singleplayer = boolean, -- default: true
  594. }
  595. minetest.register_authentication_handler(handler)
  596. ^ See minetest.builtin_auth_handler in builtin.lua for reference
  597. Setting-related:
  598. minetest.setting_set(name, value)
  599. minetest.setting_get(name) -> string or nil
  600. minetest.setting_getbool(name) -> boolean value or nil
  601. minetest.setting_get_pos(name) -> position or nil
  602. minetest.add_to_creative_inventory(itemstring)
  603. Authentication:
  604. minetest.notify_authentication_modified(name)
  605. ^ Should be called by the authentication handler if privileges change.
  606. ^ To report everybody, set name=nil.
  607. minetest.get_password_hash(name, raw_password)
  608. ^ Convert a name-password pair to a password hash that minetest can use
  609. minetest.string_to_privs(str) -> {priv1=true,...}
  610. minetest.privs_to_string(privs) -> "priv1,priv2,..."
  611. ^ Convert between two privilege representations
  612. minetest.set_player_password(name, password_hash)
  613. minetest.set_player_privs(name, {priv1=true,...})
  614. minetest.get_player_privs(name) -> {priv1=true,...}
  615. minetest.auth_reload()
  616. ^ These call the authentication handler
  617. minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
  618. ^ A quickhand for checking privileges
  619. Chat:
  620. minetest.chat_send_all(text)
  621. minetest.chat_send_player(name, text)
  622. Inventory:
  623. minetest.get_inventory(location) -> InvRef
  624. ^ location = eg. {type="player", name="celeron55"}
  625. {type="node", pos={x=, y=, z=}}
  626. Item handling:
  627. minetest.inventorycube(img1, img2, img3)
  628. ^ Returns a string for making an image of a cube (useful as an item image)
  629. minetest.get_pointed_thing_position(pointed_thing, above)
  630. ^ Get position of a pointed_thing (that you can get from somewhere)
  631. minetest.dir_to_facedir(dir)
  632. ^ Convert a vector to a facedir value, used in param2 for paramtype2="facedir"
  633. minetest.dir_to_wallmounted(dir)
  634. ^ Convert a vector to a wallmounted value, used for paramtype2="wallmounted"
  635. minetest.get_node_drops(nodename, toolname)
  636. ^ Returns list of item names.
  637. ^ Note: This will be removed or modified in a future version.
  638. minetest.get_craft_result(input) -> output, decremented_input
  639. ^ input.method = 'normal' or 'cooking' or 'fuel'
  640. ^ input.width = for example 3
  641. ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
  642. stack 5, stack 6, stack 7, stack 8, stack 9 }
  643. ^ output.item = ItemStack, if unsuccessful: empty ItemStack
  644. ^ output.time = number, if unsuccessful: 0
  645. ^ decremented_input = like input
  646. Defaults for the on_* item definition functions:
  647. (These return the leftover itemstack)
  648. minetest.item_place_node(itemstack, placer, pointed_thing)
  649. ^ Place item as a node
  650. minetest.item_place_object(itemstack, placer, pointed_thing)
  651. ^ Place item as-is
  652. minetest.item_place(itemstack, placer, pointed_thing)
  653. ^ Use one of the above based on what the item is.
  654. minetest.item_drop(itemstack, dropper, pos)
  655. ^ Drop the item
  656. minetest.item_eat(hp_change, replace_with_item)
  657. ^ Eat the item. replace_with_item can be nil.
  658. Defaults for the on_punch and on_dig node definition callbacks:
  659. minetest.node_punch(pos, node, puncher)
  660. ^ Calls functions registered by minetest.register_on_punchnode()
  661. minetest.node_dig(pos, node, digger)
  662. ^ Checks if node can be dug, puts item into inventory, removes node
  663. ^ Calls functions registered by minetest.registered_on_dignodes()
  664. Sounds:
  665. minetest.sound_play(spec, parameters) -> handle
  666. ^ spec = SimpleSoundSpec
  667. ^ parameters = sound parameter table
  668. minetest.sound_stop(handle)
  669. Timing:
  670. minetest.after(time, func, param)
  671. ^ Call function after time seconds
  672. ^ param is optional; to pass multiple parameters, pass a table.
  673. Random:
  674. minetest.get_connected_players() -> list of ObjectRefs
  675. minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer
  676. ^ Gives a unique hash number for a node position (16+16+16=48bit)
  677. minetest.get_item_group(name, group) -> rating
  678. ^ Get rating of a group of an item. (0 = not in group)
  679. minetest.get_node_group(name, group) -> rating
  680. ^ Deprecated: An alias for the former.
  681. minetest.serialize(table) -> string
  682. ^ Convert a table containing tables, strings, numbers, booleans and nils
  683. into string form readable by minetest.deserialize
  684. ^ Example: serialize({foo='bar'}) -> 'return { ["foo"] = "bar" }'
  685. minetest.deserialize(string) -> table
  686. ^ Convert a string returned by minetest.deserialize into a table
  687. ^ String is loaded in an empty sandbox environment.
  688. ^ Will load functions, but they cannot access the global environment.
  689. ^ Example: deserialize('return { ["foo"] = "bar" }') -> {foo='bar'}
  690. ^ Example: deserialize('print("foo")') -> nil (function call fails)
  691. ^ error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)
  692. Global objects:
  693. minetest.env - EnvRef of the server environment and world.
  694. ^ Using this you can access nodes and entities
  695. Global tables:
  696. minetest.registered_items
  697. ^ List of registered items, indexed by name
  698. minetest.registered_nodes
  699. ^ List of registered node definitions, indexed by name
  700. minetest.registered_craftitems
  701. ^ List of registered craft item definitions, indexed by name
  702. minetest.registered_tools
  703. ^ List of registered tool definitions, indexed by name
  704. minetest.registered_entities
  705. ^ List of registered entity prototypes, indexed by name
  706. minetest.object_refs
  707. ^ List of object references, indexed by active object id
  708. minetest.luaentities
  709. ^ List of lua entities, indexed by active object id
  710. Deprecated but defined for backwards compatibility:
  711. minetest.digprop_constanttime(time)
  712. minetest.digprop_stonelike(toughness)
  713. minetest.digprop_dirtlike(toughness)
  714. minetest.digprop_gravellike(toughness)
  715. minetest.digprop_woodlike(toughness)
  716. minetest.digprop_leaveslike(toughness)
  717. minetest.digprop_glasslike(toughness)
  718. Class reference
  719. ----------------
  720. EnvRef: basically ServerEnvironment and ServerMap combined.
  721. methods:
  722. - set_node(pos, node)
  723. - add_node(pos, node): alias set_node(pos, node)
  724. ^ Set node at position (node = {name="foo", param1=0, param2=0})
  725. - remove_node(pos)
  726. ^ Equivalent to set_node(pos, "air")
  727. - get_node(pos)
  728. ^ Returns {name="ignore", ...} for unloaded area
  729. - get_node_or_nil(pos)
  730. ^ Returns nil for unloaded area
  731. - get_node_light(pos, timeofday) -> 0...15 or nil
  732. ^ timeofday: nil = current time, 0 = night, 0.5 = day
  733. - place_node(pos, node)
  734. ^ Place node with the same effects that a player would cause
  735. - dig_node(pos)
  736. ^ Dig node with the same effects that a player would cause
  737. - punch_node(pos)
  738. ^ Punch node with the same effects that a player would cause
  739. - add_entity(pos, name): Spawn Lua-defined entity at position
  740. ^ Returns ObjectRef, or nil if failed
  741. - add_item(pos, item): Spawn item
  742. ^ Returns ObjectRef, or nil if failed
  743. - get_meta(pos) -- Get a NodeMetaRef at that position
  744. - get_player_by_name(name) -- Get an ObjectRef to a player
  745. - get_objects_inside_radius(pos, radius)
  746. - set_timeofday(val): val: 0...1; 0 = midnight, 0.5 = midday
  747. - get_timeofday()
  748. - find_node_near(pos, radius, nodenames) -> pos or nil
  749. ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
  750. - find_nodes_in_area(minp, maxp, nodenames) -> list of positions
  751. ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
  752. - get_perlin(seeddiff, octaves, persistence, scale)
  753. ^ Return world-specific perlin noise (int(worldseed)+seeddiff)
  754. Deprecated:
  755. - add_rat(pos): Add C++ rat object (no-op)
  756. - add_firefly(pos): Add C++ firefly object (no-op)
  757. NodeMetaRef: Node metadata - reference extra data and functionality stored
  758. in a node
  759. - Can be gotten via minetest.env:get_nodemeta(pos)
  760. methods:
  761. - set_string(name, value)
  762. - get_string(name)
  763. - set_int(name, value)
  764. - get_int(name)
  765. - set_float(name, value)
  766. - get_float(name)
  767. - get_inventory() -> InvRef
  768. - to_table() -> nil or {fields = {...}, inventory = {list1 = {}, ...}}
  769. - from_table(nil or {})
  770. ^ See "Node Metadata"
  771. ObjectRef: Moving things in the game are generally these
  772. (basically reference to a C++ ServerActiveObject)
  773. methods:
  774. - remove(): remove object (after returning from Lua)
  775. - getpos() -> {x=num, y=num, z=num}
  776. - setpos(pos); pos={x=num, y=num, z=num}
  777. - moveto(pos, continuous=false): interpolated move
  778. - punch(puncher, time_from_last_punch, tool_capabilities, direction)
  779. ^ puncher = an another ObjectRef,
  780. ^ time_from_last_punch = time since last punch action of the puncher
  781. - right_click(clicker); clicker = an another ObjectRef
  782. - get_hp(): returns number of hitpoints (2 * number of hearts)
  783. - set_hp(hp): set number of hitpoints (2 * number of hearts)
  784. - get_inventory() -> InvRef
  785. - get_wield_list(): returns the name of the inventory list the wielded item is in
  786. - get_wield_index(): returns the index of the wielded item
  787. - get_wielded_item() -> ItemStack
  788. - set_wielded_item(item): replaces the wielded item, returns true if successful
  789. - set_armor_groups({group1=rating, group2=rating, ...})
  790. - set_properties(object property table)
  791. LuaEntitySAO-only: (no-op for other objects)
  792. - setvelocity({x=num, y=num, z=num})
  793. - getvelocity() -> {x=num, y=num, z=num}
  794. - setacceleration({x=num, y=num, z=num})
  795. - getacceleration() -> {x=num, y=num, z=num}
  796. - setyaw(radians)
  797. - getyaw() -> radians
  798. - settexturemod(mod)
  799. - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
  800. - select_horiz_by_yawpitch=false)
  801. - ^ Select sprite from spritesheet with optional animation and DM-style
  802. - texture selection based on yaw relative to camera
  803. - get_entity_name() (DEPRECATED: Will be removed in a future version)
  804. - get_luaentity()
  805. Player-only: (no-op for other objects)
  806. - is_player(): true for players, false for others
  807. - get_player_name(): returns "" if is not a player
  808. - get_look_dir(): get camera direction as a unit vector
  809. - get_look_pitch(): pitch in radians
  810. - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
  811. InvRef: Reference to an inventory
  812. methods:
  813. - is_empty(listname): return true if list is empty
  814. - get_size(listname): get size of a list
  815. - set_size(listname, size): set size of a list
  816. - get_stack(listname, i): get a copy of stack index i in list
  817. - set_stack(listname, i, stack): copy stack to index i in list
  818. - get_list(listname): return full list
  819. - set_list(listname, list): set full list (size will not change)
  820. - add_item(listname, stack): add item somewhere in list, returns leftover ItemStack
  821. - room_for_item(listname, stack): returns true if the stack of items
  822. can be fully added to the list
  823. - contains_item(listname, stack): returns true if the stack of items
  824. can be fully taken from the list
  825. remove_item(listname, stack): take as many items as specified from the list,
  826. returns the items that were actually removed (as an ItemStack)
  827. ItemStack: A stack of items.
  828. - Can be created via ItemStack(itemstack or itemstring or table or nil)
  829. methods:
  830. - is_empty(): return true if stack is empty
  831. - get_name(): returns item name (e.g. "default:stone")
  832. - get_count(): returns number of items on the stack
  833. - get_wear(): returns tool wear (0-65535), 0 for non-tools
  834. - get_metadata(): returns metadata (a string attached to an item stack)
  835. - clear(): removes all items from the stack, making it empty
  836. - replace(item): replace the contents of this stack (item can also
  837. be an itemstring or table)
  838. - to_string(): returns the stack in itemstring form
  839. - to_table(): returns the stack in Lua table form
  840. - get_stack_max(): returns the maximum size of the stack (depends on the item)
  841. - get_free_space(): returns get_stack_max() - get_count()
  842. - is_known(): returns true if the item name refers to a defined item type
  843. - get_definition(): returns the item definition table
  844. - get_tool_capabilities(): returns the digging properties of the item,
  845. ^ or those of the hand if none are defined for this item type
  846. - add_wear(amount): increases wear by amount if the item is a tool
  847. - add_item(item): put some item or stack onto this stack,
  848. ^ returns leftover ItemStack
  849. - item_fits(item): returns true if item or stack can be fully added to this one
  850. - take_item(n): take (and remove) up to n items from this stack
  851. ^ returns taken ItemStack
  852. ^ if n is omitted, n=1 is used
  853. - peek_item(n): copy (don't remove) up to n items from this stack
  854. ^ returns copied ItemStack
  855. ^ if n is omitted, n=1 is used
  856. PseudoRandom: A pseudorandom number generator
  857. - Can be created via PseudoRandom(seed)
  858. methods:
  859. - next(): return next integer random number [0...32767]
  860. - next(min, max): return next integer random number [min...max]
  861. (max - min) must be 32767 or <= 6553 due to the simple
  862. implementation making bad distribution otherwise.
  863. PerlinNoise: A perlin noise generator
  864. - Can be created via PerlinNoise(seed, octaves, persistence, scale)
  865. - Also minetest.env:get_perlin(seeddiff, octaves, persistence, scale)
  866. methods:
  867. - get2d(pos) -> 2d noise value at pos={x=,y=}
  868. - get3d(pos) -> 3d noise value at pos={x=,y=,z=}
  869. Registered entities
  870. --------------------
  871. - Functions receive a "luaentity" as self:
  872. - It has the member .name, which is the registered name ("mod:thing")
  873. - It has the member .object, which is an ObjectRef pointing to the object
  874. - The original prototype stuff is visible directly via a metatable
  875. - Callbacks:
  876. - on_activate(self, staticdata)
  877. ^ Called when the object is instantiated.
  878. - on_step(self, dtime)
  879. ^ Called on every server tick (dtime is usually 0.05 seconds)
  880. - on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
  881. ^ Called when somebody punches the object.
  882. ^ Note that you probably want to handle most punches using the
  883. automatic armor group system.
  884. ^ puncher: ObjectRef (can be nil)
  885. ^ time_from_last_punch: Meant for disallowing spamming of clicks (can be nil)
  886. ^ tool_capabilities: capability table of used tool (can be nil)
  887. ^ dir: unit vector of direction of punch. Always defined. Points from
  888. the puncher to the punched.
  889. - on_rightclick(self, clicker)
  890. - get_staticdata(self)
  891. ^ Should return a string that will be passed to on_activate when
  892. the object is instantiated the next time.
  893. Definition tables
  894. ------------------
  895. Object Properties
  896. {
  897. physical = true,
  898. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  899. visual = "cube"/"sprite"/"upright_sprite",
  900. visual_size = {x=1, y=1},
  901. textures = {}, -- number of required textures depends on visual
  902. spritediv = {x=1, y=1},
  903. initial_sprite_basepos = {x=0, y=0},
  904. is_visible = true,
  905. makes_footstep_sound = false,
  906. }
  907. Entity definition (register_entity)
  908. {
  909. (Deprecated: Everything in object properties is read directly from here)
  910. initial_properties = <initial object properties>,
  911. on_activate = function(self, staticdata),
  912. on_step = function(self, dtime),
  913. on_punch = function(self, hitter),
  914. on_rightclick = function(self, clicker),
  915. get_staticdata = function(self),
  916. ^ Called sometimes; the string returned is passed to on_activate when
  917. the entity is re-activated from static state
  918. # Also you can define arbitrary member variables here
  919. myvariable = whatever,
  920. }
  921. ABM (ActiveBlockModifier) definition (register_abm)
  922. {
  923. -- In the following two fields, also group:groupname will work.
  924. nodenames = {"default:lava_source"},
  925. neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
  926. ^ If left out or empty, any neighbor will do
  927. interval = 1.0, -- (operation interval)
  928. chance = 1, -- (chance of trigger is 1.0/this)
  929. action = func(pos, node, active_object_count, active_object_count_wider),
  930. }
  931. Item definition (register_node, register_craftitem, register_tool)
  932. {
  933. description = "Steel Axe",
  934. groups = {}, -- key=name, value=rating; rating=1..3.
  935. if rating not applicable, use 1.
  936. eg. {wool=1, fluffy=3}
  937. {soil=2, outerspace=1, crumbly=1}
  938. {bendy=2, snappy=1},
  939. {hard=1, metal=1, spikes=1}
  940. inventory_image = "default_tool_steelaxe.png",
  941. wield_image = "",
  942. wield_scale = {x=1,y=1,z=1},
  943. stack_max = 99,
  944. liquids_pointable = false,
  945. tool_capabilities = {
  946. full_punch_interval = 1.0,
  947. max_drop_level=0,
  948. groupcaps={
  949. -- For example:
  950. fleshy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
  951. snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
  952. choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0}
  953. }
  954. }
  955. on_place = func(itemstack, placer, pointed_thing),
  956. ^ default: minetest.item_place
  957. on_drop = func(itemstack, dropper, pos),
  958. ^ default: minetest.item_drop
  959. on_use = func(itemstack, user, pointed_thing),
  960. ^ default: nil
  961. ^ Function must return either nil if no item shall be removed from
  962. inventory, or an itemstack to replace the original itemstack.
  963. eg. itemstack:take_item(); return itemstack
  964. ^ Otherwise, the function is free to do what it wants.
  965. ^ The default functions handle regular use cases.
  966. }
  967. Node definition (register_node)
  968. {
  969. <all fields allowed in item definitions>,
  970. drawtype = "normal",
  971. visual_scale = 1.0,
  972. tile_images = {"default_unknown_block.png"},
  973. special_materials = {
  974. {image="", backface_culling=true},
  975. {image="", backface_culling=true},
  976. },
  977. alpha = 255,
  978. post_effect_color = {a=0, r=0, g=0, b=0},
  979. paramtype = "none",
  980. paramtype2 = "none",
  981. is_ground_content = false,
  982. sunlight_propagates = false,
  983. walkable = true,
  984. pointable = true,
  985. diggable = true,
  986. climbable = false,
  987. buildable_to = false,
  988. drop = "",
  989. -- alternatively drop = { max_items = ..., items = { ... } }
  990. liquidtype = "none",
  991. liquid_alternative_flowing = "",
  992. liquid_alternative_source = "",
  993. liquid_viscosity = 0,
  994. light_source = 0,
  995. damage_per_second = 0,
  996. selection_box = {type="regular"},
  997. legacy_facedir_simple = false, -- Support maps made in and before January 2012
  998. legacy_wallmounted = false, -- Support maps made in and before January 2012
  999. sounds = {
  1000. footstep = <SimpleSoundSpec>,
  1001. dig = <SimpleSoundSpec>, -- "__group" = group-based sound (default)
  1002. dug = <SimpleSoundSpec>,
  1003. },
  1004. on_construct = func(pos),
  1005. ^ Node constructor; always called after adding node
  1006. ^ Can set up metadata and stuff like that
  1007. ^ default: nil
  1008. on_destruct = func(pos),
  1009. ^ Node destructor; always called before removing node
  1010. ^ default: nil
  1011. after_destruct = func(pos, oldnode),
  1012. ^ Node destructor; always called after removing node
  1013. ^ default: nil
  1014. after_place_node = func(pos, placer),
  1015. ^ Called after constructing node when node was placed using
  1016. minetest.item_place_node / minetest.env:place_node
  1017. ^ default: nil
  1018. after_dig_node = func(pos, oldnode, oldmetadata, digger),
  1019. ^ oldmetadata is in table format
  1020. ^ Called after destructing node when node was dug using
  1021. minetest.node_dig / minetest.env:dig_node
  1022. ^ default: nil
  1023. can_dig = function(pos,player)
  1024. ^ returns true if node can be dug, or false if not
  1025. ^ default: nil
  1026. on_punch = func(pos, node, puncher),
  1027. ^ default: minetest.node_punch
  1028. ^ By default: does nothing
  1029. on_dig = func(pos, node, digger),
  1030. ^ default: minetest.node_dig
  1031. ^ By default: checks privileges, wears out tool and removes node
  1032. on_receive_fields = func(pos, formname, fields, sender),
  1033. ^ fields = {name1 = value1, name2 = value2, ...}
  1034. ^ Called when an UI form (eg. sign text input) returns data
  1035. ^ default: nil
  1036. on_metadata_inventory_move = func(pos, from_list, from_index,
  1037. to_list, to_index, count, player),
  1038. ^ Called when a player wants to move items inside the metadata
  1039. ^ Should move items, or some items, if permitted. If not, should do
  1040. nothing.
  1041. ^ The engine ensures the action is valid, i.e. the stack fits at the
  1042. given position
  1043. ^ default: minetest.node_metadata_inventory_move_allow_all
  1044. on_metadata_inventory_offer = func(pos, listname, index, stack, player),
  1045. ^ Called when a player wants to put something into the metadata
  1046. inventory
  1047. ^ Should check if the action is permitted (the engine ensures the
  1048. action is valid, i.e. the stack fits at the given position)
  1049. ^ If permitted, modify the metadata inventory and return the
  1050. "leftover" stack (normally nil).
  1051. ^ If not permitted, return itemstack.
  1052. ^ default: minetest.node_metadata_inventory_offer_allow_all
  1053. on_metadata_inventory_take = func(pos, listname, index, count, player),
  1054. ^ Called when a player wants to take something out of the metadata
  1055. inventory
  1056. ^ Should check if the action is permitted (the engine ensures the
  1057. action is valid, i.e. there's a stack of at least “count” items at
  1058. that position)
  1059. ^ If permitted, modify the metadata inventory and return the
  1060. stack of items
  1061. ^ If not permitted, return nil.
  1062. ^ default: minetest.node_metadata_inventory_take_allow_all
  1063. }
  1064. Recipe for register_craft: (shaped)
  1065. {
  1066. output = 'default:pick_stone',
  1067. recipe = {
  1068. {'default:cobble', 'default:cobble', 'default:cobble'},
  1069. {'', 'default:stick', ''},
  1070. {'', 'default:stick', ''}, -- Also groups; eg. 'group:crumbly'
  1071. },
  1072. replacements = <optional list of item pairs,
  1073. replace one input item with another item on crafting>
  1074. }
  1075. Recipe for register_craft (shapeless)
  1076. {
  1077. type = "shapeless",
  1078. output = 'mushrooms:mushroom_stew',
  1079. recipe = {
  1080. "mushrooms:bowl",
  1081. "mushrooms:mushroom_brown",
  1082. "mushrooms:mushroom_red",
  1083. },
  1084. replacements = <optional list of item pairs,
  1085. replace one input item with another item on crafting>
  1086. }
  1087. Recipe for register_craft (tool repair)
  1088. {
  1089. type = "toolrepair",
  1090. additional_wear = -0.02,
  1091. }
  1092. Recipe for register_craft (cooking)
  1093. {
  1094. type = "cooking",
  1095. output = "default:glass",
  1096. recipe = "default:sand",
  1097. cooktime = 3,
  1098. }
  1099. Recipe for register_craft (furnace fuel)
  1100. {
  1101. type = "fuel",
  1102. recipe = "default:leaves",
  1103. burntime = 1,
  1104. }
  1105. Chatcommand definition (register_chatcommand)
  1106. {
  1107. params = "<name> <privilege>", -- short parameter description
  1108. description = "Remove privilege from player", -- full description
  1109. privs = {privs=true}, -- require the "privs" privilege to run
  1110. func = function(name, param), -- called when command is run
  1111. }