lua_api.txt 92 KB

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