lua_api.txt 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  1. Minetest Lua Modding API Reference 0.4.6
  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. Paths
  24. -----
  25. RUN_IN_PLACE=1: (Windows release, local build)
  26. $path_user: Linux: <build directory>
  27. Windows: <build directory>
  28. $path_share: Linux: <build directory>
  29. Windows: <build directory>
  30. RUN_IN_PLACE=0: (Linux release)
  31. $path_share: Linux: /usr/share/minetest
  32. Windows: <install directory>/minetest-0.4.x
  33. $path_user: Linux: ~/.minetest
  34. Windows: C:/users/<user>/AppData/minetest (maybe)
  35. Games
  36. -----
  37. Games are looked up from:
  38. $path_share/games/gameid/
  39. $path_user/games/gameid/
  40. where gameid is unique to each game.
  41. The game directory contains the file game.conf, which contains these fields:
  42. name = <Human-readable full name of the game>
  43. eg.
  44. name = Minetest
  45. The game directory can contain the file minetest.conf, which will be used
  46. to set default settings when running the particular game.
  47. Mod load path
  48. -------------
  49. Generic:
  50. $path_share/games/gameid/mods/
  51. $path_share/mods/
  52. $path_user/games/gameid/mods/
  53. $path_user/mods/ <-- User-installed mods
  54. $worldpath/worldmods/
  55. In a run-in-place version (eg. the distributed windows version):
  56. minetest-0.4.x/games/gameid/mods/
  57. minetest-0.4.x/mods/gameid/ <-- User-installed mods
  58. minetest-0.4.x/worlds/worldname/worldmods/
  59. On an installed version on linux:
  60. /usr/share/minetest/games/gameid/mods/
  61. ~/.minetest/mods/gameid/ <-- User-installed mods
  62. ~/.minetest/worlds/worldname/worldmods
  63. Mod load path for world-specific games
  64. --------------------------------------
  65. It is possible to include a game in a world; in this case, no mods or
  66. games are loaded or checked from anywhere else.
  67. This is useful for eg. adventure worlds.
  68. This happens if the following directory exists:
  69. $world/game/
  70. Mods should be then be placed in:
  71. $world/game/mods/
  72. Modpack support
  73. ----------------
  74. Mods can be put in a subdirectory, if the parent directory, which otherwise
  75. should be a mod, contains a file named modpack.txt. This file shall be
  76. empty, except for lines starting with #, which are comments.
  77. Mod directory structure
  78. ------------------------
  79. mods
  80. |-- modname
  81. | |-- depends.txt
  82. | |-- init.lua
  83. | |-- textures
  84. | | |-- modname_stuff.png
  85. | | `-- modname_something_else.png
  86. | |-- sounds
  87. | |-- media
  88. | `-- <custom data>
  89. `-- another
  90. modname:
  91. The location of this directory can be fetched by using
  92. minetest.get_modpath(modname)
  93. depends.txt:
  94. List of mods that have to be loaded before loading this mod.
  95. A single line contains a single modname.
  96. Optional dependencies can be defined by appending a question mark
  97. to a single modname. Their meaning is that if the specified mod
  98. is missing, that does not prevent this mod from being loaded.
  99. optdepends.txt:
  100. An alternative way of specifying optional dependencies.
  101. Like depends.txt, a single line contains a single modname.
  102. NOTE: This file exists for compatibility purposes only and
  103. support for it will be removed from the engine by the end of 2013.
  104. init.lua:
  105. The main Lua script. Running this script should register everything it
  106. wants to register. Subsequent execution depends on minetest calling the
  107. registered callbacks.
  108. minetest.setting_get(name) and minetest.setting_getbool(name) can be used
  109. to read custom or existing settings at load time, if necessary.
  110. textures, sounds, media:
  111. Media files (textures, sounds, whatever) that will be transferred to the
  112. client and will be available for use by the mod.
  113. Naming convention for registered textual names
  114. ----------------------------------------------
  115. Registered names should generally be in this format:
  116. "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
  117. This is to prevent conflicting names from corrupting maps and is
  118. enforced by the mod loader.
  119. Example: mod "experimental", ideal item/node/entity name "tnt":
  120. -> the name should be "experimental:tnt".
  121. Enforcement can be overridden by prefixing the name with ":". This can
  122. be used for overriding the registrations of some other mod.
  123. Example: Any mod can redefine experimental:tnt by using the name
  124. ":experimental:tnt" when registering it.
  125. (also that mod is required to have "experimental" as a dependency)
  126. The ":" prefix can also be used for maintaining backwards compatibility.
  127. Aliases
  128. -------
  129. Aliases can be added by using minetest.register_alias(name, convert_to)
  130. This will make Minetest to convert things called name to things called
  131. convert_to.
  132. This can be used for maintaining backwards compatibility.
  133. This can be also used for setting quick access names for things, eg. if
  134. you have an item called epiclylongmodname:stuff, you could do
  135. minetest.register_alias("stuff", "epiclylongmodname:stuff")
  136. and be able to use "/giveme stuff".
  137. Textures
  138. --------
  139. Mods should generally prefix their textures with modname_, eg. given
  140. the mod name "foomod", a texture could be called
  141. "foomod_foothing.png"
  142. Textures are referred to by their complete name, or alternatively by
  143. stripping out the file extension:
  144. eg. foomod_foothing.png
  145. eg. foomod_foothing
  146. Sounds
  147. -------
  148. Only OGG files are supported.
  149. For positional playing of sounds, only single-channel (mono) files are
  150. supported. Otherwise OpenAL will play them non-positionally.
  151. Mods should generally prefix their sounds with modname_, eg. given
  152. the mod name "foomod", a sound could be called
  153. "foomod_foosound.ogg"
  154. Sounds are referred to by their name with a dot, a single digit and the
  155. file extension stripped out. When a sound is played, the actual sound file
  156. is chosen randomly from the matching sounds.
  157. When playing the sound "foomod_foosound", the sound is chosen randomly
  158. from the available ones of the following files:
  159. foomod_foosound.ogg
  160. foomod_foosound.0.ogg
  161. foomod_foosound.1.ogg
  162. ...
  163. foomod_foosound.9.ogg
  164. Examples of sound parameter tables:
  165. -- Play locationless on all clients
  166. {
  167. gain = 1.0, -- default
  168. }
  169. -- Play locationless to a player
  170. {
  171. to_player = name,
  172. gain = 1.0, -- default
  173. }
  174. -- Play in a location
  175. {
  176. pos = {x=1,y=2,z=3},
  177. gain = 1.0, -- default
  178. max_hear_distance = 32, -- default
  179. }
  180. -- Play connected to an object, looped
  181. {
  182. object = <an ObjectRef>,
  183. gain = 1.0, -- default
  184. max_hear_distance = 32, -- default
  185. loop = true, -- only sounds connected to objects can be looped
  186. }
  187. SimpleSoundSpec:
  188. eg. ""
  189. eg. "default_place_node"
  190. eg. {}
  191. eg. {name="default_place_node"}
  192. eg. {name="default_place_node", gain=1.0}
  193. Registered definitions of stuff
  194. --------------------------------
  195. Anything added using certain minetest.register_* functions get added to
  196. the global minetest.registered_* tables.
  197. minetest.register_entity(name, prototype table)
  198. -> minetest.registered_entities[name]
  199. minetest.register_node(name, node definition)
  200. -> minetest.registered_items[name]
  201. -> minetest.registered_nodes[name]
  202. minetest.register_tool(name, item definition)
  203. -> minetest.registered_items[name]
  204. minetest.register_craftitem(name, item definition)
  205. -> minetest.registered_items[name]
  206. Note that in some cases you will stumble upon things that are not contained
  207. in these tables (eg. when a mod has been removed). Always check for
  208. existence before trying to access the fields.
  209. Example: If you want to check the drawtype of a node, you could do:
  210. local function get_nodedef_field(nodename, fieldname)
  211. if not minetest.registered_nodes[nodename] then
  212. return nil
  213. end
  214. return minetest.registered_nodes[nodename][fieldname]
  215. end
  216. local drawtype = get_nodedef_field(nodename, "drawtype")
  217. Example: minetest.get_item_group(name, group) has been implemented as:
  218. function minetest.get_item_group(name, group)
  219. if not minetest.registered_items[name] or not
  220. minetest.registered_items[name].groups[group] then
  221. return 0
  222. end
  223. return minetest.registered_items[name].groups[group]
  224. end
  225. Nodes
  226. ------
  227. Nodes are the bulk data of the world: cubes and other things that take the
  228. space of a cube. Huge amounts of them are handled efficiently, but they
  229. are quite static.
  230. The definition of a node is stored and can be accessed by name in
  231. minetest.registered_nodes[node.name]
  232. See "Registered definitions of stuff".
  233. Nodes are passed by value between Lua and the engine.
  234. They are represented by a table:
  235. {name="name", param1=num, param2=num}
  236. param1 and param2 are 8 bit integers. The engine uses them for certain
  237. automated functions. If you don't use these functions, you can use them to
  238. store arbitrary values.
  239. The functions of param1 and param2 are determined by certain fields in the
  240. node definition:
  241. param1 is reserved for the engine when paramtype != "none":
  242. paramtype = "light"
  243. ^ The value stores light with and without sun in it's
  244. upper and lower 4 bits.
  245. param2 is reserved for the engine when any of these are used:
  246. liquidtype == "flowing"
  247. ^ The level and some flags of the liquid is stored in param2
  248. drawtype == "flowingliquid"
  249. ^ The drawn liquid level is read from param2
  250. drawtype == "torchlike"
  251. drawtype == "signlike"
  252. paramtype2 == "wallmounted"
  253. ^ The rotation of the node is stored in param2. You can make this value
  254. by using minetest.dir_to_wallmounted().
  255. paramtype2 == "facedir"
  256. ^ The rotation of the node is stored in param2. Furnaces and chests are
  257. rotated this way. Can be made by using minetest.dir_to_facedir().
  258. Values range 0 - 23
  259. facedir modulo 4 = axisdir
  260. 0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
  261. facedir's two less significant bits are rotation around the axis
  262. Nodes can also contain extra data. See "Node Metadata".
  263. Node drawtypes
  264. ---------------
  265. There are a bunch of different looking node types. These are mostly just
  266. copied from Minetest 0.3; more may be made in the future.
  267. Look for examples in games/minimal or games/minetest_game.
  268. - normal
  269. - airlike
  270. - liquid
  271. - flowingliquid
  272. - glasslike
  273. - glasslike_framed
  274. - allfaces
  275. - allfaces_optional
  276. - torchlike
  277. - signlike
  278. - plantlike
  279. - fencelike
  280. - raillike
  281. - nodebox -- See below. EXPERIMENTAL
  282. Node boxes
  283. -----------
  284. Node selection boxes are defined using "node boxes"
  285. The "nodebox" node drawtype allows defining visual of nodes consisting of
  286. arbitrary number of boxes. It allows defining stuff like stairs. Only the
  287. "fixed" box type is supported for these.
  288. ^ Please note that this is still experimental, and may be incompatibly
  289. changed in the future.
  290. A nodebox is defined as any of:
  291. {
  292. -- A normal cube; the default in most things
  293. type = "regular"
  294. }
  295. {
  296. -- A fixed box (facedir param2 is used, if applicable)
  297. type = "fixed",
  298. fixed = box OR {box1, box2, ...}
  299. }
  300. {
  301. -- A box like the selection box for torches
  302. -- (wallmounted param2 is used, if applicable)
  303. type = "wallmounted",
  304. wall_top = box,
  305. wall_bottom = box,
  306. wall_side = box
  307. }
  308. A box is defined as:
  309. {x1, y1, z1, x2, y2, z2}
  310. A box of a regular node would look like:
  311. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  312. Ore types
  313. ---------------
  314. These tell in what manner the ore is generated.
  315. All default ores are of the uniformly-distributed scatter type.
  316. - scatter
  317. Randomly chooses a location and generates a cluster of ore.
  318. If noise_params is specified, the ore will be placed if the 3d perlin noise at
  319. that point is greater than the noise_threshhold, giving the ability to create a non-equal
  320. distribution of ore.
  321. - sheet
  322. Creates a sheet of ore in a blob shape according to the 2d perlin noise described by noise_params.
  323. The relative height of the sheet can be controlled by the same perlin noise as well, by specifying
  324. a non-zero 'scale' parameter in noise_params. IMPORTANT: The noise is not transformed by offset or
  325. scale when comparing against the noise threshhold, but scale is used to determine relative height.
  326. The height of the blob is randomly scattered, with a maximum height of clust_size.
  327. clust_scarcity and clust_num_ores are ignored.
  328. This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
  329. - claylike - NOT YET IMPLEMENTED
  330. Places ore if there are no more than clust_scarcity number of specified nodes within a Von Neumann
  331. neighborhood of clust_size radius.
  332. Ore attributes
  333. -------------------
  334. Currently supported flags: absheight
  335. - absheight
  336. Also produce this same ore between the height range of -height_max and -height_min.
  337. Useful for having ore in sky realms without having to duplicate ore entries.
  338. HUD element types
  339. -------------------
  340. The position field is used for all element types.
  341. To account for differing resolutions, the position coordinates are the percentage of the screen,
  342. ranging in value from 0 to 1.
  343. The name field is not yet used, but should contain a description of what the HUD element represents.
  344. The direction field is the direction in which something is drawn.
  345. 0 draws from left to right, 1 draws from right to left, 2 draws from top to bottom, and 3 draws from bottom to top.
  346. The alignment field specifies how the item will be aligned. It ranges from -1 to 1,
  347. with 0 being the center, -1 is moved to the left/up, and 1 is to the right/down. Fractional
  348. values can be used.
  349. The offset field specifies a pixel offset from the position. Contrary to position,
  350. the offset is not scaled to screen size. This allows for some precisely-positioned
  351. items in the HUD.
  352. Below are the specific uses for fields in each type; fields not listed for that type are ignored.
  353. Note: Future revisions to the HUD API may be incompatible; the HUD API is still in the experimental stages.
  354. - image
  355. Displays an image on the HUD.
  356. - scale: The scale of the image, with 1 being the original texture size.
  357. Only the X coordinate scale is used.
  358. - text: The name of the texture that is displayed.
  359. - alignment: The alignment of the image.
  360. - offset: offset in pixels from position.
  361. - text
  362. Displays text on the HUD.
  363. - scale: Defines the bounding rectangle of the text.
  364. A value such as {x=100, y=100} should work.
  365. - text: The text to be displayed in the HUD element.
  366. - number: An integer containing the RGB value of the color used to draw the text.
  367. Specify 0xFFFFFF for white text, 0xFF0000 for red, and so on.
  368. - alignment: The alignment of the text.
  369. - offset: offset in pixels from position.
  370. - statbar
  371. Displays a horizontal bar made up of half-images.
  372. - text: The name of the texture that is used.
  373. - number: The number of half-textures that are displayed.
  374. If odd, will end with a vertically center-split texture.
  375. - direction
  376. - offset: offset in pixels from position.
  377. - inventory
  378. - text: The name of the inventory list to be displayed.
  379. - number: Number of items in the inventory to be displayed.
  380. - item: Position of item that is selected.
  381. - direction
  382. Representations of simple things
  383. --------------------------------
  384. Position/vector:
  385. {x=num, y=num, z=num}
  386. Currently the API does not provide any helper functions for addition,
  387. subtraction and whatever; you can define those that you need yourself.
  388. pointed_thing:
  389. {type="nothing"}
  390. {type="node", under=pos, above=pos}
  391. {type="object", ref=ObjectRef}
  392. Items
  393. ------
  394. Node (register_node):
  395. A node from the world
  396. Tool (register_tool):
  397. A tool/weapon that can dig and damage things according to tool_capabilities
  398. Craftitem (register_craftitem):
  399. A miscellaneous item
  400. Items and item stacks can exist in three formats:
  401. Serialized; This is called stackstring or itemstring:
  402. eg. 'default:dirt 5'
  403. eg. 'default:pick_wood 21323'
  404. eg. 'default:apple'
  405. Table format:
  406. eg. {name="default:dirt", count=5, wear=0, metadata=""}
  407. ^ 5 dirt nodes
  408. eg. {name="default:pick_wood", count=1, wear=21323, metadata=""}
  409. ^ a wooden pick about 1/3 weared out
  410. eg. {name="default:apple", count=1, wear=0, metadata=""}
  411. ^ an apple.
  412. ItemStack:
  413. C++ native format with many helper methods. Useful for converting between
  414. formats. See the Class reference section for details.
  415. When an item must be passed to a function, it can usually be in any of
  416. these formats.
  417. Groups
  418. -------
  419. In a number of places, there is a group table. Groups define the
  420. properties of a thing (item, node, armor of entity, capabilities of
  421. tool) in such a way that the engine and other mods can can interact with
  422. the thing without actually knowing what the thing is.
  423. Usage:
  424. - Groups are stored in a table, having the group names with keys and the
  425. group ratings as values. For example:
  426. groups = {crumbly=3, soil=1}
  427. ^ Default dirt (soil group actually currently not defined; TODO)
  428. groups = {crumbly=2, soil=1, level=2, outerspace=1}
  429. ^ A more special dirt-kind of thing
  430. - Groups always have a rating associated with them. If there is no
  431. useful meaning for a rating for an enabled group, it shall be 1.
  432. - When not defined, the rating of a group defaults to 0. Thus when you
  433. read groups, you must interpret nil and 0 as the same value, 0.
  434. You can read the rating of a group for an item or a node by using
  435. minetest.get_item_group(itemname, groupname)
  436. Groups of items
  437. ----------------
  438. Groups of items can define what kind of an item it is (eg. wool).
  439. Groups of nodes
  440. ----------------
  441. In addition to the general item things, groups are used to define whether
  442. a node is destroyable and how long it takes to destroy by a tool.
  443. Groups of entities
  444. -------------------
  445. For entities, groups are, as of now, used only for calculating damage.
  446. The rating is the percentage of damage caused by tools with this damage group.
  447. See "Entity damage mechanism".
  448. object.get_armor_groups() -> a group-rating table (eg. {fleshy=100})
  449. object.set_armor_groups({fleshy=30, cracky=80})
  450. Groups of tools
  451. ----------------
  452. Groups in tools define which groups of nodes and entities they are
  453. effective towards.
  454. Groups in crafting recipes
  455. ---------------------------
  456. An example: Make meat soup from any meat, any water and any bowl
  457. {
  458. output = 'food:meat_soup_raw',
  459. recipe = {
  460. {'group:meat'},
  461. {'group:water'},
  462. {'group:bowl'},
  463. },
  464. -- preserve = {'group:bowl'}, -- Not implemented yet (TODO)
  465. }
  466. An another example: Make red wool from white wool and red dye
  467. {
  468. type = 'shapeless',
  469. output = 'wool:red',
  470. recipe = {'wool:white', 'group:dye,basecolor_red'},
  471. }
  472. Special groups
  473. ---------------
  474. - immortal: Disables the group damage system for an entity
  475. - level: Can be used to give an additional sense of progression in the game.
  476. - A larger level will cause eg. a weapon of a lower level make much less
  477. damage, and get weared out much faster, or not be able to get drops
  478. from destroyed nodes.
  479. - 0 is something that is directly accessible at the start of gameplay
  480. - There is no upper limit
  481. - dig_immediate: (player can always pick up node without tool wear)
  482. - 2: node is removed without tool wear after 0.5 seconds or so
  483. (rail, sign)
  484. - 3: node is removed without tool wear immediately (torch)
  485. - disable_jump: Player (and possibly other things) cannot jump from node
  486. - fall_damage_add_percent: damage speed = speed * (1 + value/100)
  487. - bouncy: value is bounce speed in percent
  488. - falling_node: if there is no walkable block under the node it will fall
  489. - attached_node: if the node under it is not a walkable block the node will be
  490. dropped as an item. If the node is wallmounted the
  491. wallmounted direction is checked.
  492. Known damage and digging time defining groups
  493. ----------------------------------------------
  494. - crumbly: dirt, sand
  495. - cracky: tough but crackable stuff like stone.
  496. - snappy: something that can be cut using fine tools; eg. leaves, small
  497. plants, wire, sheets of metal
  498. - choppy: something that can be cut using force; eg. trees, wooden planks
  499. - fleshy: Living things like animals and the player. This could imply
  500. some blood effects when hitting.
  501. - explody: Especially prone to explosions
  502. - oddly_breakable_by_hand:
  503. Can be added to nodes that shouldn't logically be breakable by the
  504. hand but are. Somewhat similar to dig_immediate, but times are more
  505. like {[1]=3.50,[2]=2.00,[3]=0.70} and this does not override the
  506. speed of a tool if the tool can dig at a faster speed than this
  507. suggests for the hand.
  508. Examples of custom groups
  509. --------------------------
  510. Item groups are often used for defining, well, //groups of items//.
  511. - meat: any meat-kind of a thing (rating might define the size or healing
  512. ability or be irrelevant - it is not defined as of yet)
  513. - eatable: anything that can be eaten. Rating might define HP gain in half
  514. hearts.
  515. - flammable: can be set on fire. Rating might define the intensity of the
  516. fire, affecting eg. the speed of the spreading of an open fire.
  517. - wool: any wool (any origin, any color)
  518. - metal: any metal
  519. - weapon: any weapon
  520. - heavy: anything considerably heavy
  521. Digging time calculation specifics
  522. -----------------------------------
  523. Groups such as **crumbly**, **cracky** and **snappy** are used for this
  524. purpose. Rating is 1, 2 or 3. A higher rating for such a group implies
  525. faster digging time.
  526. The **level** group is used to limit the toughness of nodes a tool can dig
  527. and to scale the digging times / damage to a greater extent.
  528. ^ PLEASE DO UNDERSTAND THIS, otherwise you cannot use the system to it's
  529. full potential.
  530. Tools define their properties by a list of parameters for groups. They
  531. cannot dig other groups; thus it is important to use a standard bunch of
  532. groups to enable interaction with tools.
  533. **Tools define:**
  534. * Full punch interval
  535. * Maximum drop level
  536. * For an arbitrary list of groups:
  537. * Uses (until the tool breaks)
  538. * Maximum level (usually 0, 1, 2 or 3)
  539. * Digging times
  540. * Damage groups
  541. **Full punch interval**:
  542. When used as a weapon, the tool will do full damage if this time is spent
  543. between punches. If eg. half the time is spent, the tool will do half
  544. damage.
  545. **Maximum drop level**
  546. Suggests the maximum level of node, when dug with the tool, that will drop
  547. it's useful item. (eg. iron ore to drop a lump of iron).
  548. - This is not automated; it is the responsibility of the node definition
  549. to implement this
  550. **Uses**
  551. Determines how many uses the tool has when it is used for digging a node,
  552. of this group, of the maximum level. For lower leveled nodes, the use count
  553. is multiplied by 3^leveldiff.
  554. - uses=10, leveldiff=0 -> actual uses: 10
  555. - uses=10, leveldiff=1 -> actual uses: 30
  556. - uses=10, leveldiff=2 -> actual uses: 90
  557. **Maximum level**
  558. Tells what is the maximum level of a node of this group that the tool will
  559. be able to dig.
  560. **Digging times**
  561. List of digging times for different ratings of the group, for nodes of the
  562. maximum level.
  563. * For example, as a lua table, ''times={2=2.00, 3=0.70}''. This would
  564. result in the tool to be able to dig nodes that have a rating of 2 or 3
  565. for this group, and unable to dig the rating 1, which is the toughest.
  566. Unless there is a matching group that enables digging otherwise.
  567. **Damage groups**
  568. List of damage for groups of entities. See "Entity damage mechanism".
  569. Example definition of the capabilities of a tool
  570. -------------------------------------------------
  571. tool_capabilities = {
  572. full_punch_interval=1.5,
  573. max_drop_level=1,
  574. groupcaps={
  575. crumbly={maxlevel=2, uses=20, times={[1]=1.60, [2]=1.20, [3]=0.80}}
  576. }
  577. damage_groups = {fleshy=2},
  578. }
  579. This makes the tool be able to dig nodes that fullfill both of these:
  580. - Have the **crumbly** group
  581. - Have a **level** group less or equal to 2
  582. Table of resulting digging times:
  583. crumbly 0 1 2 3 4 <- level
  584. -> 0 - - - - -
  585. 1 0.80 1.60 1.60 - -
  586. 2 0.60 1.20 1.20 - -
  587. 3 0.40 0.80 0.80 - -
  588. level diff: 2 1 0 -1 -2
  589. Table of resulting tool uses:
  590. -> 0 - - - - -
  591. 1 180 60 20 - -
  592. 2 180 60 20 - -
  593. 3 180 60 20 - -
  594. Notes:
  595. - At crumbly=0, the node is not diggable.
  596. - At crumbly=3, the level difference digging time divider kicks in and makes
  597. easy nodes to be quickly breakable.
  598. - At level > 2, the node is not diggable, because it's level > maxlevel
  599. Entity damage mechanism
  600. ------------------------
  601. Damage calculation:
  602. damage = 0
  603. foreach group in cap.damage_groups:
  604. damage += cap.damage_groups[group] * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0)
  605. * (object.armor_groups[group] / 100.0)
  606. -- Where object.armor_groups[group] is 0 for inexisting values
  607. return damage
  608. Client predicts damage based on damage groups. Because of this, it is able to
  609. give an immediate response when an entity is damaged or dies; the response is
  610. pre-defined somehow (eg. by defining a sprite animation) (not implemented;
  611. TODO).
  612. - Currently a smoke puff will appear when an entity dies.
  613. The group **immortal** completely disables normal damage.
  614. Entities can define a special armor group, which is **punch_operable**. This
  615. group disables the regular damage mechanism for players punching it by hand or
  616. a non-tool item, so that it can do something else than take damage.
  617. On the Lua side, every punch calls ''entity:on_punch(puncher,
  618. time_from_last_punch, tool_capabilities, direction)''. This should never be
  619. called directly, because damage is usually not handled by the entity itself.
  620. * ''puncher'' is the object performing the punch. Can be nil. Should never be
  621. accessed unless absolutely required, to encourage interoperability.
  622. * ''time_from_last_punch'' is time from last punch (by puncher) or nil.
  623. * ''tool_capabilities'' can be nil.
  624. * ''direction'' is a unit vector, pointing from the source of the punch to
  625. the punched object.
  626. To punch an entity/object in Lua, call ''object:punch(puncher,
  627. time_from_last_punch, tool_capabilities, direction)''.
  628. * Return value is tool wear.
  629. * Parameters are equal to the above callback.
  630. * If ''direction'' is nil and ''puncher'' is not nil, ''direction'' will be
  631. automatically filled in based on the location of ''puncher''.
  632. Node Metadata
  633. -------------
  634. The instance of a node in the world normally only contains the three values
  635. mentioned in "Nodes". However, it is possible to insert extra data into a
  636. node. It is called "node metadata"; See "NodeMetaRef".
  637. Metadata contains two things:
  638. - A key-value store
  639. - An inventory
  640. Some of the values in the key-value store are handled specially:
  641. - formspec: Defines a right-click inventory menu. See "Formspec".
  642. - infotext: Text shown on the screen when the node is pointed at
  643. Example stuff:
  644. local meta = minetest.env:get_meta(pos)
  645. meta:set_string("formspec",
  646. "invsize[8,9;]"..
  647. "list[context;main;0,0;8,4;]"..
  648. "list[current_player;main;0,5;8,4;]")
  649. meta:set_string("infotext", "Chest");
  650. local inv = meta:get_inventory()
  651. inv:set_size("main", 8*4)
  652. print(dump(meta:to_table()))
  653. meta:from_table({
  654. inventory = {
  655. 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] = ""}
  656. },
  657. fields = {
  658. formspec = "invsize[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
  659. infotext = "Chest"
  660. }
  661. })
  662. Formspec
  663. --------
  664. Formspec defines a menu. Currently not much else than inventories are
  665. supported. It is a string, with a somewhat strange format.
  666. Spaces and newlines can be inserted between the blocks, as is used in the
  667. examples.
  668. Examples:
  669. - Chest:
  670. invsize[8,9;]
  671. list[context;main;0,0;8,4;]
  672. list[current_player;main;0,5;8,4;]
  673. - Furnace:
  674. invsize[8,9;]
  675. list[context;fuel;2,3;1,1;]
  676. list[context;src;2,1;1,1;]
  677. list[context;dst;5,1;2,2;]
  678. list[current_player;main;0,5;8,4;]
  679. - Minecraft-like player inventory
  680. invsize[8,7.5;]
  681. image[1,0.6;1,2;player.png]
  682. list[current_player;main;0,3.5;8,4;]
  683. list[current_player;craft;3,0;3,3;]
  684. list[current_player;craftpreview;7,1;1,1;]
  685. Elements:
  686. size[<W>,<H>]
  687. ^ Define the size of the menu in inventory slots
  688. ^ deprecated: invsize[<W>,<H>;]
  689. list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]
  690. list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]
  691. ^ Show an inventory list
  692. image[<X>,<Y>;<W>,<H>;<texture name>]
  693. ^ Show an image
  694. ^ Position and size units are inventory slots
  695. item_image[<X>,<Y>;<W>,<H>;<item name>]
  696. ^ Show an inventory image of registered item/node
  697. ^ Position and size units are inventory slots
  698. background[<X>,<Y>;<W>,<H>;<texture name>]
  699. ^ Use a background. Inventory rectangles are not drawn then.
  700. ^ Position and size units are inventory slots
  701. ^ Example for formspec 8x4 in 16x resolution: image shall be sized 8*16px x 4*16px
  702. field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
  703. ^ Textual field; will be sent to server when a button is clicked
  704. ^ x and y position the field relative to the top left of the menu
  705. ^ w and h are the size of the field
  706. ^ fields are a set height, but will be vertically centred on h
  707. ^ Position and size units are inventory slots
  708. ^ name is the name of the field as returned in fields to on_receive_fields
  709. ^ label, if not blank, will be text printed on the top left above the field
  710. ^ default is the default value of the field
  711. ^ default may contain variable references such as '${text}' which
  712. will fill the value from the metadata value 'text'
  713. ^ Note: no extra text or more than a single variable is supported ATM.
  714. field[<name>;<label>;<default>]
  715. ^ as above but without position/size units
  716. ^ special field for creating simple forms, such as sign text input
  717. ^ must be used without a size[] element
  718. ^ a 'Proceed' button will be added automatically
  719. textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
  720. ^ same as fields above, but with multi-line input
  721. label[<X>,<Y>;<label>]
  722. ^ x and y work as per field
  723. ^ label is the text on the label
  724. ^ Position and size units are inventory slots
  725. button[<X>,<Y>;<W>,<H>;<name>;<label>]
  726. ^ Clickable button. When clicked, fields will be sent.
  727. ^ x, y and name work as per field
  728. ^ w and h are the size of the button
  729. ^ label is the text on the button
  730. ^ Position and size units are inventory slots
  731. image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
  732. ^ x, y, w, h, and name work as per button
  733. ^ image is the filename of an image
  734. ^ Position and size units are inventory slots
  735. item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]
  736. ^ x, y, w, h, name and label work as per button
  737. ^ item name is the registered name of an item/node,
  738. tooltip will be made out of its descritption
  739. ^ Position and size units are inventory slots
  740. button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]
  741. ^ When clicked, fields will be sent and the form will quit.
  742. image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
  743. ^ When clicked, fields will be sent and the form will quit.
  744. Inventory location:
  745. - "context": Selected node metadata (deprecated: "current_name")
  746. - "current_player": Player to whom the menu is shown
  747. - "player:<name>": Any player
  748. - "nodemeta:<X>,<Y>,<Z>": Any node metadata
  749. - "detached:<name>": A detached inventory
  750. Helper functions
  751. -----------------
  752. dump2(obj, name="_", dumped={})
  753. ^ Return object serialized as a string, handles reference loops
  754. dump(obj, dumped={})
  755. ^ Return object serialized as a string
  756. string:split(separator)
  757. ^ eg. string:split("a,b", ",") == {"a","b"}
  758. string:trim()
  759. ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
  760. minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)"
  761. ^ Convert position to a printable string
  762. minetest.string_to_pos(string) -> position
  763. ^ Same but in reverse
  764. minetest.formspec_escape(string) -> string
  765. ^ escapes characters like [, ], and \ that can not be used in formspecs
  766. minetest namespace reference
  767. -----------------------------
  768. minetest.get_current_modname() -> string
  769. minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
  770. ^ Useful for loading additional .lua modules or static data from mod
  771. minetest.get_modnames() -> list of installed mods
  772. ^ Return a list of installed mods, sorted alphabetically
  773. minetest.get_worldpath() -> eg. "/home/user/.minetest/world"
  774. ^ Useful for storing custom data
  775. minetest.is_singleplayer()
  776. minetest.features
  777. ^ table containing API feature flags: {foo=true, bar=true}
  778. minetest.has_feature(arg) -> bool, missing_features
  779. ^ arg: string or table in format {foo=true, bar=true}
  780. ^ missing_features: {foo=true, bar=true}
  781. minetest.debug(line)
  782. ^ Always printed to stderr and logfile (print() is redirected here)
  783. minetest.log(line)
  784. minetest.log(loglevel, line)
  785. ^ loglevel one of "error", "action", "info", "verbose"
  786. Registration functions: (Call these only at load time)
  787. minetest.register_entity(name, prototype table)
  788. minetest.register_abm(abm definition)
  789. minetest.register_node(name, node definition)
  790. minetest.register_tool(name, item definition)
  791. minetest.register_craftitem(name, item definition)
  792. minetest.register_alias(name, convert_to)
  793. minetest.register_craft(recipe)
  794. minetest.register_ore(ore definition)
  795. Global callback registration functions: (Call these only at load time)
  796. minetest.register_globalstep(func(dtime))
  797. ^ Called every server step, usually interval of 0.05s
  798. minetest.register_on_shutdown(func())
  799. ^ Called before server shutdown
  800. ^ WARNING: If the server terminates abnormally (i.e. crashes), the registered
  801. callbacks WILL LIKELY NOT BE RUN. Data should be saved at
  802. semi-frequent intervals as well as on server shutdown.
  803. minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack))
  804. ^ Called when a node has been placed
  805. ^ If return true no item is taken from itemstack
  806. ^ Deprecated: Use on_construct or after_place_node in node definition instead
  807. minetest.register_on_dignode(func(pos, oldnode, digger))
  808. ^ Called when a node has been dug.
  809. ^ Deprecated: Use on_destruct or after_dig_node in node definition instead
  810. minetest.register_on_punchnode(func(pos, node, puncher))
  811. ^ Called when a node is punched
  812. minetest.register_on_generated(func(minp, maxp, blockseed))
  813. ^ Called after generating a piece of world. Modifying nodes inside the area
  814. is a bit faster than usually.
  815. minetest.register_on_newplayer(func(ObjectRef))
  816. ^ Called after a new player has been created
  817. minetest.register_on_dieplayer(func(ObjectRef))
  818. ^ Called when a player dies
  819. minetest.register_on_respawnplayer(func(ObjectRef))
  820. ^ Called when player is to be respawned
  821. ^ Called _before_ repositioning of player occurs
  822. ^ return true in func to disable regular player placement
  823. minetest.register_on_joinplayer(func(ObjectRef))
  824. ^ Called when a player joins the game
  825. minetest.register_on_leaveplayer(func(ObjectRef))
  826. ^ Called when a player leaves the game
  827. minetest.register_on_chat_message(func(name, message))
  828. ^ Called always when a player says something
  829. minetest.register_on_player_receive_fields(func(player, formname, fields))
  830. ^ Called when a button is pressed in player's inventory form
  831. ^ Newest functions are called first
  832. ^ If function returns true, remaining functions are not called
  833. Other registration functions:
  834. minetest.register_chatcommand(cmd, chatcommand definition)
  835. minetest.register_privilege(name, definition)
  836. ^ definition: "description text"
  837. ^ definition: {
  838. description = "description text",
  839. give_to_singleplayer = boolean, -- default: true
  840. }
  841. minetest.register_authentication_handler(handler)
  842. ^ See minetest.builtin_auth_handler in builtin.lua for reference
  843. Setting-related:
  844. minetest.setting_set(name, value)
  845. minetest.setting_get(name) -> string or nil
  846. minetest.setting_getbool(name) -> boolean value or nil
  847. minetest.setting_get_pos(name) -> position or nil
  848. minetest.setting_save() -> nil, save all settings to config file
  849. minetest.add_to_creative_inventory(itemstring)
  850. Authentication:
  851. minetest.notify_authentication_modified(name)
  852. ^ Should be called by the authentication handler if privileges change.
  853. ^ To report everybody, set name=nil.
  854. minetest.get_password_hash(name, raw_password)
  855. ^ Convert a name-password pair to a password hash that minetest can use
  856. minetest.string_to_privs(str) -> {priv1=true,...}
  857. minetest.privs_to_string(privs) -> "priv1,priv2,..."
  858. ^ Convert between two privilege representations
  859. minetest.set_player_password(name, password_hash)
  860. minetest.set_player_privs(name, {priv1=true,...})
  861. minetest.get_player_privs(name) -> {priv1=true,...}
  862. minetest.auth_reload()
  863. ^ These call the authentication handler
  864. minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
  865. ^ A quickhand for checking privileges
  866. minetest.get_player_ip(name) -> IP address string
  867. Chat:
  868. minetest.chat_send_all(text)
  869. minetest.chat_send_player(name, text, prepend)
  870. ^ prepend: optional, if it is set to false "Server -!- " will not be prepended to the message
  871. Inventory:
  872. minetest.get_inventory(location) -> InvRef
  873. ^ location = eg. {type="player", name="celeron55"}
  874. {type="node", pos={x=, y=, z=}}
  875. {type="detached", name="creative"}
  876. minetest.create_detached_inventory(name, callbacks) -> InvRef
  877. ^ callbacks: See "Detached inventory callbacks"
  878. ^ Creates a detached inventory. If it already exists, it is cleared.
  879. minetest.show_formspec(playername, formname, formspec)
  880. ^ playername: name of player to show formspec
  881. ^ formname: name passed to on_player_receive_fields callbacks
  882. ^ should follow "modname:<whatever>" naming convention
  883. ^ formspec: formspec to display
  884. Item handling:
  885. minetest.inventorycube(img1, img2, img3)
  886. ^ Returns a string for making an image of a cube (useful as an item image)
  887. minetest.get_pointed_thing_position(pointed_thing, above)
  888. ^ Get position of a pointed_thing (that you can get from somewhere)
  889. minetest.dir_to_facedir(dir)
  890. ^ Convert a vector to a facedir value, used in param2 for paramtype2="facedir"
  891. minetest.dir_to_wallmounted(dir)
  892. ^ Convert a vector to a wallmounted value, used for paramtype2="wallmounted"
  893. minetest.get_node_drops(nodename, toolname)
  894. ^ Returns list of item names.
  895. ^ Note: This will be removed or modified in a future version.
  896. minetest.get_craft_result(input) -> output, decremented_input
  897. ^ input.method = 'normal' or 'cooking' or 'fuel'
  898. ^ input.width = for example 3
  899. ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
  900. stack 5, stack 6, stack 7, stack 8, stack 9 }
  901. ^ output.item = ItemStack, if unsuccessful: empty ItemStack
  902. ^ output.time = number, if unsuccessful: 0
  903. ^ decremented_input = like input
  904. minetest.get_craft_recipe(output) -> input
  905. ^ returns last registered recipe for output item (node)
  906. ^ output is a node or item type such as 'default:torch'
  907. ^ input.method = 'normal' or 'cooking' or 'fuel'
  908. ^ input.width = for example 3
  909. ^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
  910. stack 5, stack 6, stack 7, stack 8, stack 9 }
  911. ^ input.items = nil if no recipe found
  912. minetest.get_all_craft_recipes(query item) -> table or nil
  913. ^ returns indexed table with all registered recipes for query item (node)
  914. or nil if no recipe was found
  915. recipe entry table:
  916. {
  917. method = 'normal' or 'cooking' or 'fuel'
  918. width = 0-3, 0 means shapeless recipe
  919. items = indexed [1-9] table with recipe items
  920. output = string with item name and quantity
  921. }
  922. Example query for default:gold_ingot will return table:
  923. {
  924. 1={type = "cooking", width = 3, output = "default:gold_ingot",
  925. items = {1 = "default:gold_lump"}},
  926. 2={type = "normal", width = 1, output = "default:gold_ingot 9",
  927. items = {1 = "default:goldblock"}}
  928. }
  929. minetest.handle_node_drops(pos, drops, digger)
  930. ^ drops: list of itemstrings
  931. ^ Handles drops from nodes after digging: Default action is to put them into
  932. digger's inventory
  933. ^ Can be overridden to get different functionality (eg. dropping items on
  934. ground)
  935. Rollbacks:
  936. minetest.rollback_get_last_node_actor(p, range, seconds) -> actor, p, seconds
  937. ^ Find who has done something to a node, or near a node
  938. ^ actor: "player:<name>", also "liquid".
  939. minetest.rollback_revert_actions_by(actor, seconds) -> bool, log messages
  940. ^ Revert latest actions of someone
  941. ^ actor: "player:<name>", also "liquid".
  942. Defaults for the on_* item definition functions:
  943. (These return the leftover itemstack)
  944. minetest.item_place_node(itemstack, placer, pointed_thing)
  945. ^ Place item as a node
  946. minetest.item_place_object(itemstack, placer, pointed_thing)
  947. ^ Place item as-is
  948. minetest.item_place(itemstack, placer, pointed_thing)
  949. ^ Use one of the above based on what the item is.
  950. ^ Calls on_rightclick of pointed_thing.under if defined instead
  951. ^ Note: is not called when wielded item overrides on_place
  952. minetest.item_drop(itemstack, dropper, pos)
  953. ^ Drop the item
  954. minetest.item_eat(hp_change, replace_with_item)
  955. ^ Eat the item. replace_with_item can be nil.
  956. Defaults for the on_punch and on_dig node definition callbacks:
  957. minetest.node_punch(pos, node, puncher)
  958. ^ Calls functions registered by minetest.register_on_punchnode()
  959. minetest.node_dig(pos, node, digger)
  960. ^ Checks if node can be dug, puts item into inventory, removes node
  961. ^ Calls functions registered by minetest.registered_on_dignodes()
  962. Sounds:
  963. minetest.sound_play(spec, parameters) -> handle
  964. ^ spec = SimpleSoundSpec
  965. ^ parameters = sound parameter table
  966. minetest.sound_stop(handle)
  967. Timing:
  968. minetest.after(time, func, ...)
  969. ^ Call function after time seconds
  970. ^ Optional: Variable number of arguments that are passed to func
  971. Server:
  972. minetest.request_shutdown() -> request for server shutdown
  973. minetest.get_server_status() -> server status string
  974. Bans:
  975. minetest.get_ban_list() -> ban list (same as minetest.get_ban_description(""))
  976. minetest.get_ban_description(ip_or_name) -> ban description (string)
  977. minetest.ban_player(name) -> ban a player
  978. minetest.unban_player_or_ip(name) -> unban player or IP address
  979. Particles:
  980. minetest.add_particle(pos, velocity, acceleration, expirationtime,
  981. size, collisiondetection, texture, playername)
  982. ^ Spawn particle at pos with velocity and acceleration
  983. ^ Disappears after expirationtime seconds
  984. ^ collisiondetection: if true collides with physical objects
  985. ^ Uses texture (string)
  986. ^ Playername is optional, if specified spawns particle only on the player's client
  987. minetest.add_particlespawner(amount, time,
  988. minpos, maxpos,
  989. minvel, maxvel,
  990. minacc, maxacc,
  991. minexptime, maxexptime,
  992. minsize, maxsize,
  993. collisiondetection, texture, playername)
  994. ^ Add a particlespawner, an object that spawns an amount of particles over time seconds
  995. ^ The particle's properties are random values in between the boundings:
  996. ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  997. ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  998. ^ collisiondetection: if true uses collisiondetection
  999. ^ Uses texture (string)
  1000. ^ Playername is optional, if specified spawns particle only on the player's client
  1001. ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  1002. ^ Returns and id
  1003. minetest.delete_particlespawner(id, player)
  1004. ^ Delete ParticleSpawner with id (return value from add_particlespawner)
  1005. ^ If playername is specified, only deletes on the player's client,
  1006. ^ otherwise on all clients
  1007. Random:
  1008. minetest.get_connected_players() -> list of ObjectRefs
  1009. minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer
  1010. ^ Gives a unique hash number for a node position (16+16+16=48bit)
  1011. minetest.get_item_group(name, group) -> rating
  1012. ^ Get rating of a group of an item. (0 = not in group)
  1013. minetest.get_node_group(name, group) -> rating
  1014. ^ Deprecated: An alias for the former.
  1015. minetest.serialize(table) -> string
  1016. ^ Convert a table containing tables, strings, numbers, booleans and nils
  1017. into string form readable by minetest.deserialize
  1018. ^ Example: serialize({foo='bar'}) -> 'return { ["foo"] = "bar" }'
  1019. minetest.deserialize(string) -> table
  1020. ^ Convert a string returned by minetest.deserialize into a table
  1021. ^ String is loaded in an empty sandbox environment.
  1022. ^ Will load functions, but they cannot access the global environment.
  1023. ^ Example: deserialize('return { ["foo"] = "bar" }') -> {foo='bar'}
  1024. ^ Example: deserialize('print("foo")') -> nil (function call fails)
  1025. ^ error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)
  1026. Global objects:
  1027. minetest.env - EnvRef of the server environment and world.
  1028. ^ Using this you can access nodes and entities
  1029. Global tables:
  1030. minetest.registered_items
  1031. ^ List of registered items, indexed by name
  1032. minetest.registered_nodes
  1033. ^ List of registered node definitions, indexed by name
  1034. minetest.registered_craftitems
  1035. ^ List of registered craft item definitions, indexed by name
  1036. minetest.registered_tools
  1037. ^ List of registered tool definitions, indexed by name
  1038. minetest.registered_entities
  1039. ^ List of registered entity prototypes, indexed by name
  1040. minetest.object_refs
  1041. ^ List of object references, indexed by active object id
  1042. minetest.luaentities
  1043. ^ List of lua entities, indexed by active object id
  1044. Deprecated but defined for backwards compatibility:
  1045. minetest.digprop_constanttime(time)
  1046. minetest.digprop_stonelike(toughness)
  1047. minetest.digprop_dirtlike(toughness)
  1048. minetest.digprop_gravellike(toughness)
  1049. minetest.digprop_woodlike(toughness)
  1050. minetest.digprop_leaveslike(toughness)
  1051. minetest.digprop_glasslike(toughness)
  1052. Class reference
  1053. ----------------
  1054. EnvRef: basically ServerEnvironment and ServerMap combined.
  1055. methods:
  1056. - set_node(pos, node)
  1057. - add_node(pos, node): alias set_node(pos, node)
  1058. ^ Set node at position (node = {name="foo", param1=0, param2=0})
  1059. - remove_node(pos)
  1060. ^ Equivalent to set_node(pos, "air")
  1061. - get_node(pos)
  1062. ^ Returns {name="ignore", ...} for unloaded area
  1063. - get_node_or_nil(pos)
  1064. ^ Returns nil for unloaded area
  1065. - get_node_light(pos, timeofday) -> 0...15 or nil
  1066. ^ timeofday: nil = current time, 0 = night, 0.5 = day
  1067. - place_node(pos, node)
  1068. ^ Place node with the same effects that a player would cause
  1069. - dig_node(pos)
  1070. ^ Dig node with the same effects that a player would cause
  1071. - punch_node(pos)
  1072. ^ Punch node with the same effects that a player would cause
  1073. - get_meta(pos) -- Get a NodeMetaRef at that position
  1074. - get_node_timer(pos) -- Get NodeTimerRef
  1075. - add_entity(pos, name): Spawn Lua-defined entity at position
  1076. ^ Returns ObjectRef, or nil if failed
  1077. - add_item(pos, item): Spawn item
  1078. ^ Returns ObjectRef, or nil if failed
  1079. - get_player_by_name(name) -- Get an ObjectRef to a player
  1080. - get_objects_inside_radius(pos, radius)
  1081. - set_timeofday(val): val: 0...1; 0 = midnight, 0.5 = midday
  1082. - get_timeofday()
  1083. - find_node_near(pos, radius, nodenames) -> pos or nil
  1084. ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
  1085. - find_nodes_in_area(minp, maxp, nodenames) -> list of positions
  1086. ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
  1087. - get_perlin(seeddiff, octaves, persistence, scale)
  1088. ^ Return world-specific perlin noise (int(worldseed)+seeddiff)
  1089. - clear_objects()
  1090. ^ clear all objects in the environments
  1091. - line_of_sight(pos1,pos2,stepsize) ->true/false
  1092. ^ checkif there is a direct line of sight between pos1 and pos2
  1093. ^ pos1 First position
  1094. ^ pos2 Second position
  1095. ^ stepsize smaller gives more accurate results but requires more computing
  1096. time. Default is 1.
  1097. -find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm) -> table containing path
  1098. ^ returns a table of 3d points representing a path from pos1 to pos2 or nil
  1099. ^ pos1: start position
  1100. ^ pos2: end position
  1101. ^ searchdistance: number of blocks to search in each direction
  1102. ^ max_jump: maximum height difference to consider walkable
  1103. ^ max_drop: maximum height difference to consider droppable
  1104. ^ algorithm: A*_noprefetch(default), A*, Dijkstra
  1105. - spawn_tree (pos, {treedef})
  1106. ^ spawns L-System tree at given pos with definition in treedef table
  1107. treedef={
  1108. axiom, - string initial tree axiom
  1109. rules_a, - string rules set A
  1110. rules_b, - string rules set B
  1111. rules_c, - string rules set C
  1112. rules_d, - string rules set D
  1113. trunk, - string trunk node name
  1114. leaves, - string leaves node name
  1115. leaves2, - string secondary leaves node name
  1116. leaves2_chance,- num chance (0-100) to replace leaves with leaves2
  1117. angle, - num angle in deg
  1118. iterations, - num max # of iterations, usually 2 -5
  1119. random_level, - num factor to lower nr of iterations, usually 0 - 3
  1120. trunk_type, - string single/double/crossed) type of trunk: 1 node, 2x2 nodes or 3x3 in cross shape
  1121. thin_branches, - boolean true -> use thin (1 node) branches
  1122. fruit, - string fruit node name
  1123. fruit_chance, - num chance (0-100) to replace leaves with fruit node
  1124. seed, - num random seed
  1125. }
  1126. Key for Special L-System Symbols used in Axioms
  1127. G - move forward one unit with the pen up
  1128. F - move forward one unit with the pen down drawing trunks and branches
  1129. f - move forward one unit with the pen down drawing leaves (100% chance)
  1130. T - move forward one unit with the pen down drawing trunks only
  1131. R - move forward one unit with the pen down placing fruit
  1132. A - replace with rules set A
  1133. B - replace with rules set B
  1134. C - replace with rules set C
  1135. D - replace with rules set D
  1136. a - replace with rules set A, chance 90%
  1137. b - replace with rules set B, chance 80%
  1138. c - replace with rules set C, chance 70%
  1139. d - replace with rules set D, chance 60%
  1140. + - yaw the turtle right by angle parameter
  1141. - - yaw the turtle left by angle parameter
  1142. & - pitch the turtle down by angle parameter
  1143. ^ - pitch the turtle up by angle parameter
  1144. / - roll the turtle to the right by angle parameter
  1145. * - roll the turtle to the left by angle parameter
  1146. [ - save in stack current state info
  1147. ] - recover from stack state info
  1148. Example usage: spawn small apple tree
  1149. apple_tree={
  1150. axiom="FFFFFAFFBF",
  1151. rules_a="[&&&FFFFF&&FFFF][&&&++++FFFFF&&FFFF][&&&----FFFFF&&FFFF]",
  1152. rules_b="[&&&++FFFFF&&FFFF][&&&--FFFFF&&FFFF][&&&------FFFFF&&FFFF]",
  1153. trunk="default:tree",
  1154. leaves="default:leaves",
  1155. angle=30,
  1156. iterations=2,
  1157. random_level=0,
  1158. trunk_type="single",
  1159. thin_branches=true,
  1160. fruit_chance=10,
  1161. fruit="default:apple"
  1162. }
  1163. minetest.env:spawn_tree(pos,apple_tree)
  1164. Deprecated:
  1165. - add_rat(pos): Add C++ rat object (no-op)
  1166. - add_firefly(pos): Add C++ firefly object (no-op)
  1167. NodeMetaRef: Node metadata - reference extra data and functionality stored
  1168. in a node
  1169. - Can be gotten via minetest.env:get_nodemeta(pos)
  1170. methods:
  1171. - set_string(name, value)
  1172. - get_string(name)
  1173. - set_int(name, value)
  1174. - get_int(name)
  1175. - set_float(name, value)
  1176. - get_float(name)
  1177. - get_inventory() -> InvRef
  1178. - to_table() -> nil or {fields = {...}, inventory = {list1 = {}, ...}}
  1179. - from_table(nil or {})
  1180. ^ See "Node Metadata"
  1181. NodeTimerRef: Node Timers - a high resolution persistent per-node timer
  1182. - Can be gotten via minetest.env:get_node_timer(pos)
  1183. methods:
  1184. - set(timeout,elapsed)
  1185. ^ set a timer's state
  1186. ^ timeout is in seconds, and supports fractional values (0.1 etc)
  1187. ^ elapsed is in seconds, and supports fractional values (0.1 etc)
  1188. ^ will trigger the node's on_timer function after timeout-elapsed seconds
  1189. - start(timeout)
  1190. ^ start a timer
  1191. ^ equivelent to set(timeout,0)
  1192. - stop()
  1193. ^ stops the timer
  1194. - get_timeout() -> current timeout in seconds
  1195. ^ if timeout is 0, timer is inactive
  1196. - get_elapsed() -> current elapsed time in seconds
  1197. ^ the node's on_timer function will be called after timeout-elapsed seconds
  1198. - is_started() -> boolean state of timer
  1199. ^ returns true if timer is started, otherwise false
  1200. ObjectRef: Moving things in the game are generally these
  1201. (basically reference to a C++ ServerActiveObject)
  1202. methods:
  1203. - remove(): remove object (after returning from Lua)
  1204. - getpos() -> {x=num, y=num, z=num}
  1205. - setpos(pos); pos={x=num, y=num, z=num}
  1206. - moveto(pos, continuous=false): interpolated move
  1207. - punch(puncher, time_from_last_punch, tool_capabilities, direction)
  1208. ^ puncher = an another ObjectRef,
  1209. ^ time_from_last_punch = time since last punch action of the puncher
  1210. ^ direction: can be nil
  1211. - right_click(clicker); clicker = an another ObjectRef
  1212. - get_hp(): returns number of hitpoints (2 * number of hearts)
  1213. - set_hp(hp): set number of hitpoints (2 * number of hearts)
  1214. - get_inventory() -> InvRef
  1215. - get_wield_list(): returns the name of the inventory list the wielded item is in
  1216. - get_wield_index(): returns the index of the wielded item
  1217. - get_wielded_item() -> ItemStack
  1218. - set_wielded_item(item): replaces the wielded item, returns true if successful
  1219. - set_armor_groups({group1=rating, group2=rating, ...})
  1220. - set_animation({x=1,y=1}, frame_speed=15, frame_blend=0)
  1221. - set_attach(parent, bone, position, rotation)
  1222. ^ bone = string
  1223. ^ position = {x=num, y=num, z=num} (relative)
  1224. ^ rotation = {x=num, y=num, z=num}
  1225. - set_detach()
  1226. - set_bone_position(bone, position, rotation)
  1227. ^ bone = string
  1228. ^ position = {x=num, y=num, z=num} (relative)
  1229. ^ rotation = {x=num, y=num, z=num}
  1230. - set_properties(object property table)
  1231. LuaEntitySAO-only: (no-op for other objects)
  1232. - setvelocity({x=num, y=num, z=num})
  1233. - getvelocity() -> {x=num, y=num, z=num}
  1234. - setacceleration({x=num, y=num, z=num})
  1235. - getacceleration() -> {x=num, y=num, z=num}
  1236. - setyaw(radians)
  1237. - getyaw() -> radians
  1238. - settexturemod(mod)
  1239. - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
  1240. - select_horiz_by_yawpitch=false)
  1241. ^ Select sprite from spritesheet with optional animation and DM-style
  1242. texture selection based on yaw relative to camera
  1243. - get_entity_name() (DEPRECATED: Will be removed in a future version)
  1244. - get_luaentity()
  1245. Player-only: (no-op for other objects)
  1246. - is_player(): true for players, false for others
  1247. - get_player_name(): returns "" if is not a player
  1248. - get_look_dir(): get camera direction as a unit vector
  1249. - get_look_pitch(): pitch in radians
  1250. - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
  1251. - set_look_pitch(radians): sets look pitch
  1252. - set_look_yaw(radians): sets look yaw
  1253. - set_inventory_formspec(formspec)
  1254. ^ Redefine player's inventory form
  1255. ^ Should usually be called in on_joinplayer
  1256. - get_inventory_formspec() -> formspec string
  1257. - get_player_control(): returns table with player pressed keys
  1258. {jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
  1259. - get_player_control_bits(): returns integer with bit packed player pressed keys
  1260. bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
  1261. - set_physics_override(speed, jump, gravity)
  1262. modifies per-player walking speed, jump height, and gravity.
  1263. Values default to 1 and act as offsets to the physics settings
  1264. in minetest.conf. nil will keep the current setting.
  1265. - hud_add(hud definition): add a HUD element described by HUD def, returns ID number on success
  1266. - hud_remove(id): remove the HUD element of the specified id
  1267. - hud_change(id, stat, value): change a value of a previously added HUD element
  1268. ^ element stat values: position, name, scale, text, number, item, dir
  1269. - hud_get(id): gets the HUD element definition structure of the specified ID
  1270. - hud_set_flags(flags): sets specified HUD flags to true/false
  1271. ^ flags: (is visible) hotbar, healthbar, crosshair, wielditem
  1272. ^ pass a table containing a true/false value of each flag to be set or unset
  1273. ^ if a flag is nil, the flag is not modified
  1274. InvRef: Reference to an inventory
  1275. methods:
  1276. - is_empty(listname): return true if list is empty
  1277. - get_size(listname): get size of a list
  1278. - set_size(listname, size): set size of a list
  1279. - get_width(listname): get width of a list
  1280. - set_width(listname, width): set width of list; currently used for crafting
  1281. - get_stack(listname, i): get a copy of stack index i in list
  1282. - set_stack(listname, i, stack): copy stack to index i in list
  1283. - get_list(listname): return full list
  1284. - set_list(listname, list): set full list (size will not change)
  1285. - add_item(listname, stack): add item somewhere in list, returns leftover ItemStack
  1286. - room_for_item(listname, stack): returns true if the stack of items
  1287. can be fully added to the list
  1288. - contains_item(listname, stack): returns true if the stack of items
  1289. can be fully taken from the list
  1290. remove_item(listname, stack): take as many items as specified from the list,
  1291. returns the items that were actually removed (as an ItemStack)
  1292. - get_location() -> location compatible to minetest.get_inventory(location)
  1293. -> {type="undefined"} in case location is not known
  1294. ItemStack: A stack of items.
  1295. - Can be created via ItemStack(itemstack or itemstring or table or nil)
  1296. methods:
  1297. - is_empty(): return true if stack is empty
  1298. - get_name(): returns item name (e.g. "default:stone")
  1299. - get_count(): returns number of items on the stack
  1300. - get_wear(): returns tool wear (0-65535), 0 for non-tools
  1301. - get_metadata(): returns metadata (a string attached to an item stack)
  1302. - clear(): removes all items from the stack, making it empty
  1303. - replace(item): replace the contents of this stack (item can also
  1304. be an itemstring or table)
  1305. - to_string(): returns the stack in itemstring form
  1306. - to_table(): returns the stack in Lua table form
  1307. - get_stack_max(): returns the maximum size of the stack (depends on the item)
  1308. - get_free_space(): returns get_stack_max() - get_count()
  1309. - is_known(): returns true if the item name refers to a defined item type
  1310. - get_definition(): returns the item definition table
  1311. - get_tool_capabilities(): returns the digging properties of the item,
  1312. ^ or those of the hand if none are defined for this item type
  1313. - add_wear(amount): increases wear by amount if the item is a tool
  1314. - add_item(item): put some item or stack onto this stack,
  1315. ^ returns leftover ItemStack
  1316. - item_fits(item): returns true if item or stack can be fully added to this one
  1317. - take_item(n): take (and remove) up to n items from this stack
  1318. ^ returns taken ItemStack
  1319. ^ if n is omitted, n=1 is used
  1320. - peek_item(n): copy (don't remove) up to n items from this stack
  1321. ^ returns copied ItemStack
  1322. ^ if n is omitted, n=1 is used
  1323. PseudoRandom: A pseudorandom number generator
  1324. - Can be created via PseudoRandom(seed)
  1325. methods:
  1326. - next(): return next integer random number [0...32767]
  1327. - next(min, max): return next integer random number [min...max]
  1328. (max - min) must be 32767 or <= 6553 due to the simple
  1329. implementation making bad distribution otherwise.
  1330. PerlinNoise: A perlin noise generator
  1331. - Can be created via PerlinNoise(seed, octaves, persistence, scale)
  1332. - Also minetest.env:get_perlin(seeddiff, octaves, persistence, scale)
  1333. methods:
  1334. - get2d(pos) -> 2d noise value at pos={x=,y=}
  1335. - get3d(pos) -> 3d noise value at pos={x=,y=,z=}
  1336. Registered entities
  1337. --------------------
  1338. - Functions receive a "luaentity" as self:
  1339. - It has the member .name, which is the registered name ("mod:thing")
  1340. - It has the member .object, which is an ObjectRef pointing to the object
  1341. - The original prototype stuff is visible directly via a metatable
  1342. - Callbacks:
  1343. - on_activate(self, staticdata)
  1344. ^ Called when the object is instantiated.
  1345. - on_step(self, dtime)
  1346. ^ Called on every server tick (dtime is usually 0.05 seconds)
  1347. - on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
  1348. ^ Called when somebody punches the object.
  1349. ^ Note that you probably want to handle most punches using the
  1350. automatic armor group system.
  1351. ^ puncher: ObjectRef (can be nil)
  1352. ^ time_from_last_punch: Meant for disallowing spamming of clicks (can be nil)
  1353. ^ tool_capabilities: capability table of used tool (can be nil)
  1354. ^ dir: unit vector of direction of punch. Always defined. Points from
  1355. the puncher to the punched.
  1356. - on_rightclick(self, clicker)
  1357. - get_staticdata(self)
  1358. ^ Should return a string that will be passed to on_activate when
  1359. the object is instantiated the next time.
  1360. Definition tables
  1361. ------------------
  1362. Object Properties
  1363. {
  1364. hp_max = 1,
  1365. physical = true,
  1366. weight = 5,
  1367. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  1368. visual = "cube"/"sprite"/"upright_sprite"/"mesh",
  1369. visual_size = {x=1, y=1},
  1370. mesh = "model",
  1371. textures = {}, -- number of required textures depends on visual
  1372. colors = {}, -- number of required colors depends on visual
  1373. spritediv = {x=1, y=1},
  1374. initial_sprite_basepos = {x=0, y=0},
  1375. is_visible = true,
  1376. makes_footstep_sound = false,
  1377. automatic_rotate = false,
  1378. }
  1379. Entity definition (register_entity)
  1380. {
  1381. (Deprecated: Everything in object properties is read directly from here)
  1382. initial_properties = <initial object properties>,
  1383. on_activate = function(self, staticdata, dtime_s),
  1384. on_step = function(self, dtime),
  1385. on_punch = function(self, hitter),
  1386. on_rightclick = function(self, clicker),
  1387. get_staticdata = function(self),
  1388. ^ Called sometimes; the string returned is passed to on_activate when
  1389. the entity is re-activated from static state
  1390. # Also you can define arbitrary member variables here
  1391. myvariable = whatever,
  1392. }
  1393. ABM (ActiveBlockModifier) definition (register_abm)
  1394. {
  1395. -- In the following two fields, also group:groupname will work.
  1396. nodenames = {"default:lava_source"},
  1397. neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
  1398. ^ If left out or empty, any neighbor will do
  1399. interval = 1.0, -- (operation interval)
  1400. chance = 1, -- (chance of trigger is 1.0/this)
  1401. action = func(pos, node, active_object_count, active_object_count_wider),
  1402. }
  1403. Item definition (register_node, register_craftitem, register_tool)
  1404. {
  1405. description = "Steel Axe",
  1406. groups = {}, -- key=name, value=rating; rating=1..3.
  1407. if rating not applicable, use 1.
  1408. eg. {wool=1, fluffy=3}
  1409. {soil=2, outerspace=1, crumbly=1}
  1410. {bendy=2, snappy=1},
  1411. {hard=1, metal=1, spikes=1}
  1412. inventory_image = "default_tool_steelaxe.png",
  1413. wield_image = "",
  1414. wield_scale = {x=1,y=1,z=1},
  1415. stack_max = 99,
  1416. liquids_pointable = false,
  1417. tool_capabilities = {
  1418. full_punch_interval = 1.0,
  1419. max_drop_level=0,
  1420. groupcaps={
  1421. -- For example:
  1422. snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
  1423. choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0}
  1424. },
  1425. damage_groups = {groupname=damage},
  1426. }
  1427. node_placement_prediction = nil,
  1428. ^ If nil and item is node, prediction is made automatically
  1429. ^ If nil and item is not a node, no prediction is made
  1430. ^ If "" and item is anything, no prediction is made
  1431. ^ Otherwise should be name of node which the client immediately places
  1432. on ground when the player places the item. Server will always update
  1433. actual result to client in a short moment.
  1434. sound = {
  1435. place = <SimpleSoundSpec>,
  1436. }
  1437. on_place = func(itemstack, placer, pointed_thing),
  1438. ^ Shall place item and return the leftover itemstack
  1439. ^ default: minetest.item_place
  1440. on_drop = func(itemstack, dropper, pos),
  1441. ^ Shall drop item and return the leftover itemstack
  1442. ^ default: minetest.item_drop
  1443. on_use = func(itemstack, user, pointed_thing),
  1444. ^ default: nil
  1445. ^ Function must return either nil if no item shall be removed from
  1446. inventory, or an itemstack to replace the original itemstack.
  1447. eg. itemstack:take_item(); return itemstack
  1448. ^ Otherwise, the function is free to do what it wants.
  1449. ^ The default functions handle regular use cases.
  1450. }
  1451. Tile definition:
  1452. - "image.png"
  1453. - {name="image.png", animation={Tile Animation definition}}
  1454. - {name="image.png", backface_culling=bool}
  1455. ^ backface culling only supported in special tiles
  1456. - deprecated still supported field names:
  1457. - image -> name
  1458. Tile animation definition:
  1459. - {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}
  1460. Node definition (register_node)
  1461. {
  1462. <all fields allowed in item definitions>,
  1463. drawtype = "normal", -- See "Node drawtypes"
  1464. visual_scale = 1.0,
  1465. tiles = {tile definition 1, def2, def3, def4, def5, def6},
  1466. ^ Textures of node; +Y, -Y, +X, -X, +Z, -Z (old field name: tile_images)
  1467. ^ List can be shortened to needed length
  1468. special_tiles = {tile definition 1, Tile definition 2},
  1469. ^ Special textures of node; used rarely (old field name: special_materials)
  1470. ^ List can be shortened to needed length
  1471. alpha = 255,
  1472. use_texture_alpha = false, -- Use texture's alpha channel
  1473. post_effect_color = {a=0, r=0, g=0, b=0}, -- If player is inside node
  1474. paramtype = "none", -- See "Nodes"
  1475. paramtype2 = "none", -- See "Nodes"
  1476. is_ground_content = false, -- Currently not used for anything
  1477. sunlight_propagates = false, -- If true, sunlight will go infinitely through this
  1478. walkable = true, -- If true, objects collide with node
  1479. pointable = true, -- If true, can be pointed at
  1480. diggable = true, -- If false, can never be dug
  1481. climbable = false, -- If true, can be climbed on (ladder)
  1482. buildable_to = false, -- If true, placed nodes can replace this node
  1483. drop = "", -- alternatively drop = { max_items = ..., items = { ... } }
  1484. liquidtype = "none", -- "none"/"source"/"flowing"
  1485. liquid_alternative_flowing = "", -- Flowing version of source liquid
  1486. liquid_alternative_source = "", -- Source version of flowing liquid
  1487. liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
  1488. liquid_renewable = true, -- Can new liquid source be created by placing
  1489. two or more sources nearly?
  1490. light_source = 0, -- Amount of light emitted by node
  1491. damage_per_second = 0, -- If player is inside node, this damage is caused
  1492. node_box = {type="regular"}, -- See "Node boxes"
  1493. selection_box = {type="regular"}, -- See "Node boxes"
  1494. ^ If drawtype "nodebox" is used and selection_box is nil, then node_box is used
  1495. legacy_facedir_simple = false, -- Support maps made in and before January 2012
  1496. legacy_wallmounted = false, -- Support maps made in and before January 2012
  1497. sounds = {
  1498. footstep = <SimpleSoundSpec>,
  1499. dig = <SimpleSoundSpec>, -- "__group" = group-based sound (default)
  1500. dug = <SimpleSoundSpec>,
  1501. place = <SimpleSoundSpec>,
  1502. },
  1503. on_construct = func(pos),
  1504. ^ Node constructor; always called after adding node
  1505. ^ Can set up metadata and stuff like that
  1506. ^ default: nil
  1507. on_destruct = func(pos),
  1508. ^ Node destructor; always called before removing node
  1509. ^ default: nil
  1510. after_destruct = func(pos, oldnode),
  1511. ^ Node destructor; always called after removing node
  1512. ^ default: nil
  1513. after_place_node = func(pos, placer, itemstack),
  1514. ^ Called after constructing node when node was placed using
  1515. minetest.item_place_node / minetest.env:place_node
  1516. ^ If return true no item is taken from itemstack
  1517. ^ default: nil
  1518. after_dig_node = func(pos, oldnode, oldmetadata, digger),
  1519. ^ oldmetadata is in table format
  1520. ^ Called after destructing node when node was dug using
  1521. minetest.node_dig / minetest.env:dig_node
  1522. ^ default: nil
  1523. can_dig = function(pos,player)
  1524. ^ returns true if node can be dug, or false if not
  1525. ^ default: nil
  1526. on_punch = func(pos, node, puncher),
  1527. ^ default: minetest.node_punch
  1528. ^ By default: does nothing
  1529. on_rightclick = func(pos, node, clicker, itemstack),
  1530. ^ default: nil
  1531. ^ if defined, itemstack will hold clicker's wielded item
  1532. Shall return the leftover itemstack
  1533. on_dig = func(pos, node, digger),
  1534. ^ default: minetest.node_dig
  1535. ^ By default: checks privileges, wears out tool and removes node
  1536. on_timer = function(pos,elapsed),
  1537. ^ default: nil
  1538. ^ called by NodeTimers, see EnvRef and NodeTimerRef
  1539. ^ elapsed is the total time passed since the timer was started
  1540. ^ return true to run the timer for another cycle with the same timeout value
  1541. on_receive_fields = func(pos, formname, fields, sender),
  1542. ^ fields = {name1 = value1, name2 = value2, ...}
  1543. ^ Called when an UI form (eg. sign text input) returns data
  1544. ^ default: nil
  1545. allow_metadata_inventory_move = func(pos, from_list, from_index,
  1546. to_list, to_index, count, player),
  1547. ^ Called when a player wants to move items inside the inventory
  1548. ^ Return value: number of items allowed to move
  1549. allow_metadata_inventory_put = func(pos, listname, index, stack, player),
  1550. ^ Called when a player wants to put something into the inventory
  1551. ^ Return value: number of items allowed to put
  1552. ^ Return value: -1: Allow and don't modify item count in inventory
  1553. allow_metadata_inventory_take = func(pos, listname, index, stack, player),
  1554. ^ Called when a player wants to take something out of the inventory
  1555. ^ Return value: number of items allowed to take
  1556. ^ Return value: -1: Allow and don't modify item count in inventory
  1557. on_metadata_inventory_move = func(pos, from_list, from_index,
  1558. to_list, to_index, count, player),
  1559. on_metadata_inventory_put = func(pos, listname, index, stack, player),
  1560. on_metadata_inventory_take = func(pos, listname, index, stack, player),
  1561. ^ Called after the actual action has happened, according to what was allowed.
  1562. ^ No return value
  1563. on_blast = func(pos, intensity),
  1564. ^ intensity: 1.0 = mid range of regular TNT
  1565. ^ If defined, called when an explosion touches the node, instead of
  1566. removing the node
  1567. }
  1568. Recipe for register_craft: (shaped)
  1569. {
  1570. output = 'default:pick_stone',
  1571. recipe = {
  1572. {'default:cobble', 'default:cobble', 'default:cobble'},
  1573. {'', 'default:stick', ''},
  1574. {'', 'default:stick', ''}, -- Also groups; eg. 'group:crumbly'
  1575. },
  1576. replacements = <optional list of item pairs,
  1577. replace one input item with another item on crafting>
  1578. }
  1579. Recipe for register_craft (shapeless)
  1580. {
  1581. type = "shapeless",
  1582. output = 'mushrooms:mushroom_stew',
  1583. recipe = {
  1584. "mushrooms:bowl",
  1585. "mushrooms:mushroom_brown",
  1586. "mushrooms:mushroom_red",
  1587. },
  1588. replacements = <optional list of item pairs,
  1589. replace one input item with another item on crafting>
  1590. }
  1591. Recipe for register_craft (tool repair)
  1592. {
  1593. type = "toolrepair",
  1594. additional_wear = -0.02,
  1595. }
  1596. Recipe for register_craft (cooking)
  1597. {
  1598. type = "cooking",
  1599. output = "default:glass",
  1600. recipe = "default:sand",
  1601. cooktime = 3,
  1602. }
  1603. Recipe for register_craft (furnace fuel)
  1604. {
  1605. type = "fuel",
  1606. recipe = "default:leaves",
  1607. burntime = 1,
  1608. }
  1609. Ore definition (register_ore)
  1610. {
  1611. ore_type = "scatter" -- See "Ore types"
  1612. ore = "default:stone_with_coal",
  1613. wherein = "default:stone",
  1614. clust_scarcity = 8*8*8,
  1615. ^ Ore has a 1 out of clust_scarcity chance of spawning in a node
  1616. ^ This value should be *MUCH* higher than your intuition might tell you!
  1617. clust_num_ores = 8,
  1618. ^ Number of ores in a cluster
  1619. clust_size = 3,
  1620. ^ Size of the bounding box of the cluster
  1621. ^ In this example, there is a 3x3x3 cluster where 8 out of the 27 nodes are coal ore
  1622. height_min = -31000,
  1623. height_max = 64,
  1624. flags = "",
  1625. ^ Attributes for this ore generation
  1626. noise_threshhold = 0.5,
  1627. ^ If noise is above this threshhold, ore is placed. Not needed for a uniform distribution
  1628. noise_params = {offset=0, scale=1, spread={x=100, y=100, z=100}, seed=23, octaves=3, persist=0.70}
  1629. ^ NoiseParams structure describing the perlin noise used for ore distribution.
  1630. ^ Needed for sheet ore_type. Omit from scatter ore_type for a uniform ore distribution
  1631. }
  1632. Chatcommand definition (register_chatcommand)
  1633. {
  1634. params = "<name> <privilege>", -- short parameter description
  1635. description = "Remove privilege from player", -- full description
  1636. privs = {privs=true}, -- require the "privs" privilege to run
  1637. func = function(name, param), -- called when command is run
  1638. }
  1639. Detached inventory callbacks
  1640. {
  1641. allow_move = func(inv, from_list, from_index, to_list, to_index, count, player),
  1642. ^ Called when a player wants to move items inside the inventory
  1643. ^ Return value: number of items allowed to move
  1644. allow_put = func(inv, listname, index, stack, player),
  1645. ^ Called when a player wants to put something into the inventory
  1646. ^ Return value: number of items allowed to put
  1647. ^ Return value: -1: Allow and don't modify item count in inventory
  1648. allow_take = func(inv, listname, index, stack, player),
  1649. ^ Called when a player wants to take something out of the inventory
  1650. ^ Return value: number of items allowed to take
  1651. ^ Return value: -1: Allow and don't modify item count in inventory
  1652. on_move = func(inv, from_list, from_index, to_list, to_index, count, player),
  1653. on_put = func(inv, listname, index, stack, player),
  1654. on_take = func(inv, listname, index, stack, player),
  1655. ^ Called after the actual action has happened, according to what was allowed.
  1656. ^ No return value
  1657. }
  1658. HUD Definition (hud_add, hud_get)
  1659. {
  1660. hud_elem_type = "image", -- see HUD element types
  1661. ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
  1662. position = {x=0.5, y=0.5},
  1663. ^ Left corner position of element
  1664. name = "<name>",
  1665. scale = {x=2, y=2},
  1666. text = "<text>",
  1667. number = 2,
  1668. item = 3,
  1669. ^ Selected item in inventory. 0 for no item selected.
  1670. direction = 0,
  1671. ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
  1672. alignment = {x=0, y=0},
  1673. ^ See "HUD Element Types"
  1674. offset = {x=0, y=0},
  1675. ^ See "HUD Element Types"
  1676. }