lua_api.txt 210 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835
  1. Minetest Lua Modding API Reference 0.4.17
  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. [Programming in Lua](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`:
  28. * Linux: `<build directory>`
  29. * Windows: `<build directory>`
  30. * `$path_share`
  31. * Linux: `<build directory>`
  32. * Windows: `<build directory>`
  33. * `RUN_IN_PLACE=0`: (Linux release)
  34. * `$path_share`
  35. * Linux: `/usr/share/minetest`
  36. * Windows: `<install directory>/minetest-0.4.x`
  37. * `$path_user`:
  38. * Linux: `$HOME/.minetest`
  39. * Windows: `C:/users/<user>/AppData/minetest` (maybe)
  40. Games
  41. -----
  42. Games are looked up from:
  43. * `$path_share/games/gameid/`
  44. * `$path_user/games/gameid/`
  45. where `gameid` is unique to each game.
  46. The game directory contains the file `game.conf`, which contains these fields:
  47. name = <Human-readable full name of the game>
  48. e.g.
  49. name = Minetest
  50. The game directory can contain the file minetest.conf, which will be used
  51. to set default settings when running the particular game.
  52. It can also contain a settingtypes.txt in the same format as the one in builtin.
  53. This settingtypes.txt will be parsed by the menu and the settings will be displayed
  54. in the "Games" category in the settings tab.
  55. ### Menu images
  56. Games can provide custom main menu images. They are put inside a `menu` directory
  57. inside the game directory.
  58. The images are named `$identifier.png`, where `$identifier` is
  59. one of `overlay,background,footer,header`.
  60. If you want to specify multiple images for one identifier, add additional images named
  61. like `$identifier.$n.png`, with an ascending number $n starting with 1, and a random
  62. image will be chosen from the provided ones.
  63. Mod load path
  64. -------------
  65. Generic:
  66. * `$path_share/games/gameid/mods/`
  67. * `$path_share/mods/`
  68. * `$path_user/games/gameid/mods/`
  69. * `$path_user/mods/` (User-installed mods)
  70. * `$worldpath/worldmods/`
  71. In a run-in-place version (e.g. the distributed windows version):
  72. * `minetest-0.4.x/games/gameid/mods/`
  73. * `minetest-0.4.x/mods/` (User-installed mods)
  74. * `minetest-0.4.x/worlds/worldname/worldmods/`
  75. On an installed version on Linux:
  76. * `/usr/share/minetest/games/gameid/mods/`
  77. * `$HOME/.minetest/mods/` (User-installed mods)
  78. * `$HOME/.minetest/worlds/worldname/worldmods`
  79. Mod load path for world-specific games
  80. --------------------------------------
  81. It is possible to include a game in a world; in this case, no mods or
  82. games are loaded or checked from anywhere else.
  83. This is useful for e.g. adventure worlds.
  84. This happens if the following directory exists:
  85. $world/game/
  86. Mods should be then be placed in:
  87. $world/game/mods/
  88. Modpack support
  89. ----------------
  90. Mods can be put in a subdirectory, if the parent directory, which otherwise
  91. should be a mod, contains a file named `modpack.txt`. This file shall be
  92. empty, except for lines starting with `#`, which are comments.
  93. Mod directory structure
  94. ------------------------
  95. mods
  96. |-- modname
  97. | |-- depends.txt
  98. | |-- screenshot.png
  99. | |-- description.txt
  100. | |-- settingtypes.txt
  101. | |-- init.lua
  102. | |-- models
  103. | |-- textures
  104. | | |-- modname_stuff.png
  105. | | `-- modname_something_else.png
  106. | |-- sounds
  107. | |-- media
  108. | `-- <custom data>
  109. `-- another
  110. ### modname
  111. The location of this directory can be fetched by using
  112. `minetest.get_modpath(modname)`.
  113. ### `depends.txt`
  114. List of mods that have to be loaded before loading this mod.
  115. A single line contains a single modname.
  116. Optional dependencies can be defined by appending a question mark
  117. to a single modname. Their meaning is that if the specified mod
  118. is missing, that does not prevent this mod from being loaded.
  119. ### `screenshot.png`
  120. A screenshot shown in the mod manager within the main menu. It should
  121. have an aspect ratio of 3:2 and a minimum size of 300×200 pixels.
  122. ### `description.txt`
  123. A File containing description to be shown within mainmenu.
  124. ### `settingtypes.txt`
  125. A file in the same format as the one in builtin. It will be parsed by the
  126. settings menu and the settings will be displayed in the "Mods" category.
  127. ### `init.lua`
  128. The main Lua script. Running this script should register everything it
  129. wants to register. Subsequent execution depends on minetest calling the
  130. registered callbacks.
  131. `minetest.settings` can be used to read custom or existing settings at load
  132. time, if necessary. (See `Settings`)
  133. ### `models`
  134. Models for entities or meshnodes.
  135. ### `textures`, `sounds`, `media`
  136. Media files (textures, sounds, whatever) that will be transferred to the
  137. client and will be available for use by the mod.
  138. Naming convention for registered textual names
  139. ----------------------------------------------
  140. Registered names should generally be in this format:
  141. `modname:<whatever>`
  142. `<whatever>` can have these characters:
  143. a-zA-Z0-9_
  144. This is to prevent conflicting names from corrupting maps and is
  145. enforced by the mod loader.
  146. ### Example
  147. In the mod `experimental`, there is the ideal item/node/entity name `tnt`.
  148. So the name should be `experimental:tnt`.
  149. Enforcement can be overridden by prefixing the name with `:`. This can
  150. be used for overriding the registrations of some other mod.
  151. Example: Any mod can redefine `experimental:tnt` by using the name
  152. :experimental:tnt
  153. when registering it.
  154. (also that mod is required to have `experimental` as a dependency)
  155. The `:` prefix can also be used for maintaining backwards compatibility.
  156. Aliases
  157. -------
  158. Aliases can be added by using `minetest.register_alias(name, convert_to)` or
  159. `minetest.register_alias_force(name, convert_to)`.
  160. This will make Minetest to convert things called name to things called
  161. `convert_to`.
  162. The only difference between `minetest.register_alias` and
  163. `minetest.register_alias_force` is that if an item called `name` exists,
  164. `minetest.register_alias` will do nothing while
  165. `minetest.register_alias_force` will unregister it.
  166. This can be used for maintaining backwards compatibility.
  167. This can be also used for setting quick access names for things, e.g. if
  168. you have an item called `epiclylongmodname:stuff`, you could do
  169. minetest.register_alias("stuff", "epiclylongmodname:stuff")
  170. and be able to use `/giveme stuff`.
  171. Mapgen aliases
  172. --------------
  173. In a game, a certain number of these must be set to tell core mapgens which
  174. of the game's nodes are to be used by the core mapgens. For example:
  175. minetest.register_alias("mapgen_stone", "default:stone")
  176. ### Aliases needed for all mapgens except Mapgen v6
  177. Base terrain:
  178. "mapgen_stone"
  179. "mapgen_water_source"
  180. "mapgen_river_water_source"
  181. Caves:
  182. "mapgen_lava_source"
  183. Dungeons:
  184. Only needed for registered biomes where 'node_stone' is stone:
  185. "mapgen_cobble"
  186. "mapgen_stair_cobble"
  187. "mapgen_mossycobble"
  188. Only needed for registered biomes where 'node_stone' is desert stone:
  189. "mapgen_desert_stone"
  190. "mapgen_stair_desert_stone"
  191. Only needed for registered biomes where 'node_stone' is sandstone:
  192. "mapgen_sandstone"
  193. "mapgen_sandstonebrick"
  194. "mapgen_stair_sandstone_block"
  195. ### Aliases needed for Mapgen v6
  196. Terrain and biomes:
  197. "mapgen_stone"
  198. "mapgen_water_source"
  199. "mapgen_lava_source"
  200. "mapgen_dirt"
  201. "mapgen_dirt_with_grass"
  202. "mapgen_sand"
  203. "mapgen_gravel"
  204. "mapgen_desert_stone"
  205. "mapgen_desert_sand"
  206. "mapgen_dirt_with_snow"
  207. "mapgen_snowblock"
  208. "mapgen_snow"
  209. "mapgen_ice"
  210. Flora:
  211. "mapgen_tree"
  212. "mapgen_leaves"
  213. "mapgen_apple"
  214. "mapgen_jungletree"
  215. "mapgen_jungleleaves"
  216. "mapgen_junglegrass"
  217. "mapgen_pine_tree"
  218. "mapgen_pine_needles"
  219. Dungeons:
  220. "mapgen_cobble"
  221. "mapgen_stair_cobble"
  222. "mapgen_mossycobble"
  223. "mapgen_stair_desert_stone"
  224. Textures
  225. --------
  226. Mods should generally prefix their textures with `modname_`, e.g. given
  227. the mod name `foomod`, a texture could be called:
  228. foomod_foothing.png
  229. Textures are referred to by their complete name, or alternatively by
  230. stripping out the file extension:
  231. * e.g. `foomod_foothing.png`
  232. * e.g. `foomod_foothing`
  233. Texture modifiers
  234. -----------------
  235. There are various texture modifiers that can be used
  236. to generate textures on-the-fly.
  237. ### Texture overlaying
  238. Textures can be overlaid by putting a `^` between them.
  239. Example:
  240. default_dirt.png^default_grass_side.png
  241. `default_grass_side.png` is overlayed over `default_dirt.png`.
  242. The texture with the lower resolution will be automatically upscaled to
  243. the higher resolution texture.
  244. ### Texture grouping
  245. Textures can be grouped together by enclosing them in `(` and `)`.
  246. Example: `cobble.png^(thing1.png^thing2.png)`
  247. A texture for `thing1.png^thing2.png` is created and the resulting
  248. texture is overlaid on top of `cobble.png`.
  249. ### Escaping
  250. Modifiers that accept texture names (e.g. `[combine`) accept escaping to allow
  251. passing complex texture names as arguments. Escaping is done with backslash and
  252. is required for `^` and `:`.
  253. Example: `cobble.png^[lowpart:50:color.png\^[mask\:trans.png`
  254. The lower 50 percent of `color.png^[mask:trans.png` are overlaid
  255. on top of `cobble.png`.
  256. ### Advanced texture modifiers
  257. #### `[crack:<n>:<p>`
  258. * `<n>` = animation frame count
  259. * `<p>` = current animation frame
  260. Draw a step of the crack animation on the texture.
  261. Example:
  262. default_cobble.png^[crack:10:1
  263. #### `[combine:<w>x<h>:<x1>,<y1>=<file1>:<x2>,<y2>=<file2>:...`
  264. * `<w>` = width
  265. * `<h>` = height
  266. * `<x>` = x position
  267. * `<y>` = y position
  268. * `<file>` = texture to combine
  269. Creates a texture of size `<w>` times `<h>` and blits the listed files to their
  270. specified coordinates.
  271. Example:
  272. [combine:16x32:0,0=default_cobble.png:0,16=default_wood.png
  273. #### `[resize:<w>x<h>`
  274. Resizes the texture to the given dimensions.
  275. Example:
  276. default_sandstone.png^[resize:16x16
  277. #### `[opacity:<r>`
  278. Makes the base image transparent according to the given ratio.
  279. `r` must be between 0 and 255.
  280. 0 means totally transparent. 255 means totally opaque.
  281. Example:
  282. default_sandstone.png^[opacity:127
  283. #### `[invert:<mode>`
  284. Inverts the given channels of the base image.
  285. Mode may contain the characters "r", "g", "b", "a".
  286. Only the channels that are mentioned in the mode string will be inverted.
  287. Example:
  288. default_apple.png^[invert:rgb
  289. #### `[brighten`
  290. Brightens the texture.
  291. Example:
  292. tnt_tnt_side.png^[brighten
  293. #### `[noalpha`
  294. Makes the texture completely opaque.
  295. Example:
  296. default_leaves.png^[noalpha
  297. #### `[makealpha:<r>,<g>,<b>`
  298. Convert one color to transparency.
  299. Example:
  300. default_cobble.png^[makealpha:128,128,128
  301. #### `[transform<t>`
  302. * `<t>` = transformation(s) to apply
  303. Rotates and/or flips the image.
  304. `<t>` can be a number (between 0 and 7) or a transform name.
  305. Rotations are counter-clockwise.
  306. 0 I identity
  307. 1 R90 rotate by 90 degrees
  308. 2 R180 rotate by 180 degrees
  309. 3 R270 rotate by 270 degrees
  310. 4 FX flip X
  311. 5 FXR90 flip X then rotate by 90 degrees
  312. 6 FY flip Y
  313. 7 FYR90 flip Y then rotate by 90 degrees
  314. Example:
  315. default_stone.png^[transformFXR90
  316. #### `[inventorycube{<top>{<left>{<right>`
  317. Escaping does not apply here and `^` is replaced by `&` in texture names instead.
  318. Create an inventory cube texture using the side textures.
  319. Example:
  320. [inventorycube{grass.png{dirt.png&grass_side.png{dirt.png&grass_side.png
  321. Creates an inventorycube with `grass.png`, `dirt.png^grass_side.png` and
  322. `dirt.png^grass_side.png` textures
  323. #### `[lowpart:<percent>:<file>`
  324. Blit the lower `<percent>`% part of `<file>` on the texture.
  325. Example:
  326. base.png^[lowpart:25:overlay.png
  327. #### `[verticalframe:<t>:<n>`
  328. * `<t>` = animation frame count
  329. * `<n>` = current animation frame
  330. Crops the texture to a frame of a vertical animation.
  331. Example:
  332. default_torch_animated.png^[verticalframe:16:8
  333. #### `[mask:<file>`
  334. Apply a mask to the base image.
  335. The mask is applied using binary AND.
  336. #### `[sheet:<w>x<h>:<x>,<y>`
  337. Retrieves a tile at position x,y from the base image
  338. which it assumes to be a tilesheet with dimensions w,h.
  339. #### `[colorize:<color>:<ratio>`
  340. Colorize the textures with the given color.
  341. `<color>` is specified as a `ColorString`.
  342. `<ratio>` is an int ranging from 0 to 255 or the word "`alpha`". If
  343. it is an int, then it specifies how far to interpolate between the
  344. colors where 0 is only the texture color and 255 is only `<color>`. If
  345. omitted, the alpha of `<color>` will be used as the ratio. If it is
  346. the word "`alpha`", then each texture pixel will contain the RGB of
  347. `<color>` and the alpha of `<color>` multiplied by the alpha of the
  348. texture pixel.
  349. #### `[multiply:<color>`
  350. Multiplies texture colors with the given color.
  351. `<color>` is specified as a `ColorString`.
  352. Result is more like what you'd expect if you put a color on top of another
  353. color. Meaning white surfaces get a lot of your new color while black parts don't
  354. change very much.
  355. Hardware coloring
  356. -----------------
  357. The goal of hardware coloring is to simplify the creation of
  358. colorful nodes. If your textures use the same pattern, and they only
  359. differ in their color (like colored wool blocks), you can use hardware
  360. coloring instead of creating and managing many texture files.
  361. All of these methods use color multiplication (so a white-black texture
  362. with red coloring will result in red-black color).
  363. ### Static coloring
  364. This method is useful if you wish to create nodes/items with
  365. the same texture, in different colors, each in a new node/item definition.
  366. #### Global color
  367. When you register an item or node, set its `color` field (which accepts a
  368. `ColorSpec`) to the desired color.
  369. An `ItemStack`s static color can be overwritten by the `color` metadata
  370. field. If you set that field to a `ColorString`, that color will be used.
  371. #### Tile color
  372. Each tile may have an individual static color, which overwrites every
  373. other coloring methods. To disable the coloring of a face,
  374. set its color to white (because multiplying with white does nothing).
  375. You can set the `color` property of the tiles in the node's definition
  376. if the tile is in table format.
  377. ### Palettes
  378. For nodes and items which can have many colors, a palette is more
  379. suitable. A palette is a texture, which can contain up to 256 pixels.
  380. Each pixel is one possible color for the node/item.
  381. You can register one node/item, which can have up to 256 colors.
  382. #### Palette indexing
  383. When using palettes, you always provide a pixel index for the given
  384. node or `ItemStack`. The palette is read from left to right and from
  385. top to bottom. If the palette has less than 256 pixels, then it is
  386. stretched to contain exactly 256 pixels (after arranging the pixels
  387. to one line). The indexing starts from 0.
  388. Examples:
  389. * 16x16 palette, index = 0: the top left corner
  390. * 16x16 palette, index = 4: the fifth pixel in the first row
  391. * 16x16 palette, index = 16: the pixel below the top left corner
  392. * 16x16 palette, index = 255: the bottom right corner
  393. * 2 (width)x4 (height) palette, index=31: the top left corner.
  394. The palette has 8 pixels, so each pixel is stretched to 32 pixels,
  395. to ensure the total 256 pixels.
  396. * 2x4 palette, index=32: the top right corner
  397. * 2x4 palette, index=63: the top right corner
  398. * 2x4 palette, index=64: the pixel below the top left corner
  399. #### Using palettes with items
  400. When registering an item, set the item definition's `palette` field to
  401. a texture. You can also use texture modifiers.
  402. The `ItemStack`'s color depends on the `palette_index` field of the
  403. stack's metadata. `palette_index` is an integer, which specifies the
  404. index of the pixel to use.
  405. #### Linking palettes with nodes
  406. When registering a node, set the item definition's `palette` field to
  407. a texture. You can also use texture modifiers.
  408. The node's color depends on its `param2`, so you also must set an
  409. appropriate `drawtype`:
  410. * `drawtype = "color"` for nodes which use their full `param2` for
  411. palette indexing. These nodes can have 256 different colors.
  412. The palette should contain 256 pixels.
  413. * `drawtype = "colorwallmounted"` for nodes which use the first
  414. five bits (most significant) of `param2` for palette indexing.
  415. The remaining three bits are describing rotation, as in `wallmounted`
  416. draw type. Division by 8 yields the palette index (without stretching the
  417. palette). These nodes can have 32 different colors, and the palette
  418. should contain 32 pixels.
  419. Examples:
  420. * `param2 = 17` is 2 * 8 + 1, so the rotation is 1 and the third (= 2 + 1)
  421. pixel will be picked from the palette.
  422. * `param2 = 35` is 4 * 8 + 3, so the rotation is 3 and the fifth (= 4 + 1)
  423. pixel will be picked from the palette.
  424. * `drawtype = "colorfacedir"` for nodes which use the first
  425. three bits of `param2` for palette indexing. The remaining
  426. five bits are describing rotation, as in `facedir` draw type.
  427. Division by 32 yields the palette index (without stretching the
  428. palette). These nodes can have 8 different colors, and the
  429. palette should contain 8 pixels.
  430. Examples:
  431. * `param2 = 17` is 0 * 32 + 17, so the rotation is 17 and the
  432. first (= 0 + 1) pixel will be picked from the palette.
  433. * `param2 = 35` is 1 * 32 + 3, so the rotation is 3 and the
  434. second (= 1 + 1) pixel will be picked from the palette.
  435. To colorize a node on the map, set its `param2` value (according
  436. to the node's draw type).
  437. ### Conversion between nodes in the inventory and the on the map
  438. Static coloring is the same for both cases, there is no need
  439. for conversion.
  440. If the `ItemStack`'s metadata contains the `color` field, it will be
  441. lost on placement, because nodes on the map can only use palettes.
  442. If the `ItemStack`'s metadata contains the `palette_index` field, it is
  443. automatically transferred between node and item forms by the engine,
  444. when a player digs or places a colored node.
  445. You can disable this feature by setting the `drop` field of the node
  446. to itself (without metadata).
  447. To transfer the color to a special drop, you need a drop table.
  448. Example:
  449. minetest.register_node("mod:stone", {
  450. description = "Stone",
  451. tiles = {"default_stone.png"},
  452. paramtype2 = "color",
  453. palette = "palette.png",
  454. drop = {
  455. items = {
  456. -- assume that mod:cobblestone also has the same palette
  457. {items = {"mod:cobblestone"}, inherit_color = true },
  458. }
  459. }
  460. })
  461. ### Colored items in craft recipes
  462. Craft recipes only support item strings, but fortunately item strings
  463. can also contain metadata. Example craft recipe registration:
  464. local stack = ItemStack("wool:block")
  465. dyed:get_meta():set_int("palette_index", 3) -- add index
  466. minetest.register_craft({
  467. output = dyed:to_string(), -- convert to string
  468. type = "shapeless",
  469. recipe = {
  470. "wool:block",
  471. "dye:red",
  472. },
  473. })
  474. Metadata field filtering in the `recipe` field are not supported yet,
  475. so the craft output is independent of the color of the ingredients.
  476. Soft texture overlay
  477. --------------------
  478. Sometimes hardware coloring is not enough, because it affects the
  479. whole tile. Soft texture overlays were added to Minetest to allow
  480. the dynamic coloring of only specific parts of the node's texture.
  481. For example a grass block may have colored grass, while keeping the
  482. dirt brown.
  483. These overlays are 'soft', because unlike texture modifiers, the layers
  484. are not merged in the memory, but they are simply drawn on top of each
  485. other. This allows different hardware coloring, but also means that
  486. tiles with overlays are drawn slower. Using too much overlays might
  487. cause FPS loss.
  488. To define an overlay, simply set the `overlay_tiles` field of the node
  489. definition. These tiles are defined in the same way as plain tiles:
  490. they can have a texture name, color etc.
  491. To skip one face, set that overlay tile to an empty string.
  492. Example (colored grass block):
  493. minetest.register_node("default:dirt_with_grass", {
  494. description = "Dirt with Grass",
  495. -- Regular tiles, as usual
  496. -- The dirt tile disables palette coloring
  497. tiles = {{name = "default_grass.png"},
  498. {name = "default_dirt.png", color = "white"}},
  499. -- Overlay tiles: define them in the same style
  500. -- The top and bottom tile does not have overlay
  501. overlay_tiles = {"", "",
  502. {name = "default_grass_side.png", tileable_vertical = false}},
  503. -- Global color, used in inventory
  504. color = "green",
  505. -- Palette in the world
  506. paramtype2 = "color",
  507. palette = "default_foilage.png",
  508. })
  509. Sounds
  510. ------
  511. Only Ogg Vorbis files are supported.
  512. For positional playing of sounds, only single-channel (mono) files are
  513. supported. Otherwise OpenAL will play them non-positionally.
  514. Mods should generally prefix their sounds with `modname_`, e.g. given
  515. the mod name "`foomod`", a sound could be called:
  516. foomod_foosound.ogg
  517. Sounds are referred to by their name with a dot, a single digit and the
  518. file extension stripped out. When a sound is played, the actual sound file
  519. is chosen randomly from the matching sounds.
  520. When playing the sound `foomod_foosound`, the sound is chosen randomly
  521. from the available ones of the following files:
  522. * `foomod_foosound.ogg`
  523. * `foomod_foosound.0.ogg`
  524. * `foomod_foosound.1.ogg`
  525. * (...)
  526. * `foomod_foosound.9.ogg`
  527. Examples of sound parameter tables:
  528. -- Play locationless on all clients
  529. {
  530. gain = 1.0, -- default
  531. fade = 0.0, -- default, change to a value > 0 to fade the sound in
  532. }
  533. -- Play locationless to one player
  534. {
  535. to_player = name,
  536. gain = 1.0, -- default
  537. fade = 0.0, -- default, change to a value > 0 to fade the sound in
  538. }
  539. -- Play locationless to one player, looped
  540. {
  541. to_player = name,
  542. gain = 1.0, -- default
  543. loop = true,
  544. }
  545. -- Play in a location
  546. {
  547. pos = {x = 1, y = 2, z = 3},
  548. gain = 1.0, -- default
  549. max_hear_distance = 32, -- default, uses an euclidean metric
  550. }
  551. -- Play connected to an object, looped
  552. {
  553. object = <an ObjectRef>,
  554. gain = 1.0, -- default
  555. max_hear_distance = 32, -- default, uses an euclidean metric
  556. loop = true,
  557. }
  558. Looped sounds must either be connected to an object or played locationless to
  559. one player using `to_player = name,`
  560. ### `SimpleSoundSpec`
  561. * e.g. `""`
  562. * e.g. `"default_place_node"`
  563. * e.g. `{}`
  564. * e.g. `{name = "default_place_node"}`
  565. * e.g. `{name = "default_place_node", gain = 1.0}`
  566. Registered definitions of stuff
  567. -------------------------------
  568. Anything added using certain `minetest.register_*` functions get added to
  569. the global `minetest.registered_*` tables.
  570. * `minetest.register_entity(name, prototype table)`
  571. * added to `minetest.registered_entities[name]`
  572. * `minetest.register_node(name, node definition)`
  573. * added to `minetest.registered_items[name]`
  574. * added to `minetest.registered_nodes[name]`
  575. * `minetest.register_tool(name, item definition)`
  576. * added to `minetest.registered_items[name]`
  577. * `minetest.register_craftitem(name, item definition)`
  578. * added to `minetest.registered_items[name]`
  579. * `minetest.unregister_item(name)`
  580. * Unregisters the item name from engine, and deletes the entry with key
  581. * `name` from `minetest.registered_items` and from the associated item
  582. * table according to its nature: `minetest.registered_nodes[]` etc
  583. * `minetest.register_biome(biome definition)`
  584. * returns an integer uniquely identifying the registered biome
  585. * added to `minetest.registered_biome` with the key of `biome.name`
  586. * if `biome.name` is nil, the key is the returned ID
  587. * `minetest.register_ore(ore definition)`
  588. * returns an integer uniquely identifying the registered ore
  589. * added to `minetest.registered_ores` with the key of `ore.name`
  590. * if `ore.name` is nil, the key is the returned ID
  591. * `minetest.register_decoration(decoration definition)`
  592. * returns an integer uniquely identifying the registered decoration
  593. * added to `minetest.registered_decorations` with the key of `decoration.name`
  594. * if `decoration.name` is nil, the key is the returned ID
  595. * `minetest.register_schematic(schematic definition)`
  596. * returns an integer uniquely identifying the registered schematic
  597. * added to `minetest.registered_schematic` with the key of `schematic.name`
  598. * if `schematic.name` is nil, the key is the returned ID
  599. * if the schematic is loaded from a file, schematic.name is set to the filename
  600. * if the function is called when loading the mod, and schematic.name is a relative
  601. path, then the current mod path will be prepended to the schematic filename
  602. * `minetest.clear_registered_biomes()`
  603. * clears all biomes currently registered
  604. * `minetest.clear_registered_ores()`
  605. * clears all ores currently registered
  606. * `minetest.clear_registered_decorations()`
  607. * clears all decorations currently registered
  608. * `minetest.clear_registered_schematics()`
  609. * clears all schematics currently registered
  610. Note that in some cases you will stumble upon things that are not contained
  611. in these tables (e.g. when a mod has been removed). Always check for
  612. existence before trying to access the fields.
  613. Example: If you want to check the drawtype of a node, you could do:
  614. local function get_nodedef_field(nodename, fieldname)
  615. if not minetest.registered_nodes[nodename] then
  616. return nil
  617. end
  618. return minetest.registered_nodes[nodename][fieldname]
  619. end
  620. local drawtype = get_nodedef_field(nodename, "drawtype")
  621. Example: `minetest.get_item_group(name, group)` has been implemented as:
  622. function minetest.get_item_group(name, group)
  623. if not minetest.registered_items[name] or not
  624. minetest.registered_items[name].groups[group] then
  625. return 0
  626. end
  627. return minetest.registered_items[name].groups[group]
  628. end
  629. Nodes
  630. -----
  631. Nodes are the bulk data of the world: cubes and other things that take the
  632. space of a cube. Huge amounts of them are handled efficiently, but they
  633. are quite static.
  634. The definition of a node is stored and can be accessed by name in
  635. minetest.registered_nodes[node.name]
  636. See "Registered definitions of stuff".
  637. Nodes are passed by value between Lua and the engine.
  638. They are represented by a table:
  639. {name="name", param1=num, param2=num}
  640. `param1` and `param2` are 8-bit integers ranging from 0 to 255. The engine uses
  641. them for certain automated functions. If you don't use these functions, you can
  642. use them to store arbitrary values.
  643. The functions of `param1` and `param2` are determined by certain fields in the
  644. node definition:
  645. `param1` is reserved for the engine when `paramtype != "none"`:
  646. paramtype = "light"
  647. ^ The value stores light with and without sun in its upper and lower 4 bits
  648. respectively. Allows light to propagate from or through the node with
  649. light value falling by 1 per node. This is essential for a light source
  650. node to spread its light.
  651. `param2` is reserved for the engine when any of these are used:
  652. liquidtype == "flowing"
  653. ^ The level and some flags of the liquid is stored in param2
  654. drawtype == "flowingliquid"
  655. ^ The drawn liquid level is read from param2
  656. drawtype == "torchlike"
  657. drawtype == "signlike"
  658. paramtype2 == "wallmounted"
  659. ^ The rotation of the node is stored in param2. You can make this value
  660. by using minetest.dir_to_wallmounted().
  661. paramtype2 == "facedir"
  662. ^ The rotation of the node is stored in param2. Furnaces and chests are
  663. rotated this way. Can be made by using minetest.dir_to_facedir().
  664. Values range 0 - 23
  665. facedir / 4 = axis direction:
  666. 0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
  667. facedir modulo 4 = rotation around that axis
  668. paramtype2 == "leveled"
  669. ^ Only valid for "nodebox" with type = "leveled".
  670. The level of the top face of the nodebox is stored in param2.
  671. The other faces are defined by 'fixed = {}' like 'type = "fixed"' nodeboxes.
  672. The nodebox height is param2 / 64 nodes.
  673. The maximum accepted value of param2 is 127.
  674. paramtype2 == "degrotate"
  675. ^ The rotation of this node is stored in param2. Plants are rotated this way.
  676. Values range 0 - 179. The value stored in param2 is multiplied by two to
  677. get the actual rotation of the node.
  678. paramtype2 == "meshoptions"
  679. ^ Only valid for "plantlike". The value of param2 becomes a bitfield which can
  680. be used to change how the client draws plantlike nodes. Bits 0, 1 and 2 form
  681. a mesh selector. Currently the following meshes are choosable:
  682. 0 = a "x" shaped plant (ordinary plant)
  683. 1 = a "+" shaped plant (just rotated 45 degrees)
  684. 2 = a "*" shaped plant with 3 faces instead of 2
  685. 3 = a "#" shaped plant with 4 faces instead of 2
  686. 4 = a "#" shaped plant with 4 faces that lean outwards
  687. 5-7 are unused and reserved for future meshes.
  688. Bits 3 through 7 are optional flags that can be combined and give these
  689. effects:
  690. bit 3 (0x08) - Makes the plant slightly vary placement horizontally
  691. bit 4 (0x10) - Makes the plant mesh 1.4x larger
  692. bit 5 (0x20) - Moves each face randomly a small bit down (1/8 max)
  693. bits 6-7 are reserved for future use.
  694. paramtype2 == "color"
  695. ^ `param2` tells which color is picked from the palette.
  696. The palette should have 256 pixels.
  697. paramtype2 == "colorfacedir"
  698. ^ Same as `facedir`, but with colors.
  699. The first three bits of `param2` tells which color
  700. is picked from the palette.
  701. The palette should have 8 pixels.
  702. paramtype2 == "colorwallmounted"
  703. ^ Same as `wallmounted`, but with colors.
  704. The first five bits of `param2` tells which color
  705. is picked from the palette.
  706. The palette should have 32 pixels.
  707. paramtype2 == "glasslikeliquidlevel"
  708. ^ Only valid for "glasslike_framed" or "glasslike_framed_optional" drawtypes.
  709. param2 defines 64 levels of internal liquid.
  710. Liquid texture is defined using `special_tiles = {"modname_tilename.png"},`
  711. Nodes can also contain extra data. See "Node Metadata".
  712. Node drawtypes
  713. ---------------
  714. There are a bunch of different looking node types.
  715. Look for examples in `games/minimal` or `games/minetest_game`.
  716. * `normal`
  717. * `airlike`
  718. * `liquid`
  719. * `flowingliquid`
  720. * `glasslike`
  721. * `glasslike_framed`
  722. * `glasslike_framed_optional`
  723. * `allfaces`
  724. * `allfaces_optional`
  725. * `torchlike`
  726. * `signlike`
  727. * `plantlike`
  728. * `firelike`
  729. * `fencelike`
  730. * `raillike`
  731. * `nodebox` -- See below. (**Experimental!**)
  732. * `mesh` -- use models for nodes
  733. `*_optional` drawtypes need less rendering time if deactivated (always client side).
  734. Node boxes
  735. -----------
  736. Node selection boxes are defined using "node boxes"
  737. The `nodebox` node drawtype allows defining visual of nodes consisting of
  738. arbitrary number of boxes. It allows defining stuff like stairs. Only the
  739. `fixed` and `leveled` box type is supported for these.
  740. Please note that this is still experimental, and may be incompatibly
  741. changed in the future.
  742. A nodebox is defined as any of:
  743. {
  744. -- A normal cube; the default in most things
  745. type = "regular"
  746. }
  747. {
  748. -- A fixed box (facedir param2 is used, if applicable)
  749. type = "fixed",
  750. fixed = box OR {box1, box2, ...}
  751. }
  752. {
  753. -- A box like the selection box for torches
  754. -- (wallmounted param2 is used, if applicable)
  755. type = "wallmounted",
  756. wall_top = box,
  757. wall_bottom = box,
  758. wall_side = box
  759. }
  760. {
  761. -- A node that has optional boxes depending on neighbouring nodes'
  762. -- presence and type. See also `connects_to`.
  763. type = "connected",
  764. fixed = box OR {box1, box2, ...}
  765. connect_top = box OR {box1, box2, ...}
  766. connect_bottom = box OR {box1, box2, ...}
  767. connect_front = box OR {box1, box2, ...}
  768. connect_left = box OR {box1, box2, ...}
  769. connect_back = box OR {box1, box2, ...}
  770. connect_right = box OR {box1, box2, ...}
  771. }
  772. A `box` is defined as:
  773. {x1, y1, z1, x2, y2, z2}
  774. A box of a regular node would look like:
  775. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  776. `type = "leveled"` is same as `type = "fixed"`, but `y2` will be automatically
  777. set to level from `param2`.
  778. Meshes
  779. ------
  780. If drawtype `mesh` is used, tiles should hold model materials textures.
  781. Only static meshes are implemented.
  782. For supported model formats see Irrlicht engine documentation.
  783. Noise Parameters
  784. ----------------
  785. Noise Parameters, or commonly called "`NoiseParams`", define the properties of
  786. perlin noise.
  787. ### `offset`
  788. Offset that the noise is translated by (i.e. added) after calculation.
  789. ### `scale`
  790. Factor that the noise is scaled by (i.e. multiplied) after calculation.
  791. ### `spread`
  792. Vector containing values by which each coordinate is divided by before calculation.
  793. Higher spread values result in larger noise features.
  794. A value of `{x=250, y=250, z=250}` is common.
  795. ### `seed`
  796. Random seed for the noise. Add the world seed to a seed offset for world-unique noise.
  797. In the case of `minetest.get_perlin()`, this value has the world seed automatically added.
  798. ### `octaves`
  799. Number of times the noise gradient is accumulated into the noise.
  800. Increase this number to increase the amount of detail in the resulting noise.
  801. A value of `6` is common.
  802. ### `persistence`
  803. Factor by which the effect of the noise gradient function changes with each successive octave.
  804. Values less than `1` make the details of successive octaves' noise diminish, while values
  805. greater than `1` make successive octaves stronger.
  806. A value of `0.6` is common.
  807. ### `lacunarity`
  808. Factor by which the noise feature sizes change with each successive octave.
  809. A value of `2.0` is common.
  810. ### `flags`
  811. Leave this field unset for no special handling.
  812. Currently supported are `defaults`, `eased` and `absvalue`.
  813. #### `defaults`
  814. Specify this if you would like to keep auto-selection of eased/not-eased while specifying
  815. some other flags.
  816. #### `eased`
  817. Maps noise gradient values onto a quintic S-curve before performing interpolation.
  818. This results in smooth, rolling noise. Disable this (`noeased`) for sharp-looking noise.
  819. If no flags are specified (or defaults is), 2D noise is eased and 3D noise is not eased.
  820. #### `absvalue`
  821. Accumulates the absolute value of each noise gradient result.
  822. Noise parameters format example for 2D or 3D perlin noise or perlin noise maps:
  823. np_terrain = {
  824. offset = 0,
  825. scale = 1,
  826. spread = {x=500, y=500, z=500},
  827. seed = 571347,
  828. octaves = 5,
  829. persist = 0.63,
  830. lacunarity = 2.0,
  831. flags = "defaults, absvalue"
  832. }
  833. ^ A single noise parameter table can be used to get 2D or 3D noise,
  834. when getting 2D noise spread.z is ignored.
  835. Ore types
  836. ---------
  837. These tell in what manner the ore is generated.
  838. All default ores are of the uniformly-distributed scatter type.
  839. ### `scatter`
  840. Randomly chooses a location and generates a cluster of ore.
  841. If `noise_params` is specified, the ore will be placed if the 3D perlin noise at
  842. that point is greater than the `noise_threshold`, giving the ability to create
  843. a non-equal distribution of ore.
  844. ### `sheet`
  845. Creates a sheet of ore in a blob shape according to the 2D perlin noise
  846. described by `noise_params` and `noise_threshold`. This is essentially an
  847. improved version of the so-called "stratus" ore seen in some unofficial mods.
  848. This sheet consists of vertical columns of uniform randomly distributed height,
  849. varying between the inclusive range `column_height_min` and `column_height_max`.
  850. If `column_height_min` is not specified, this parameter defaults to 1.
  851. If `column_height_max` is not specified, this parameter defaults to `clust_size`
  852. for reverse compatibility. New code should prefer `column_height_max`.
  853. The `column_midpoint_factor` parameter controls the position of the column at which
  854. ore eminates from. If 1, columns grow upward. If 0, columns grow downward. If 0.5,
  855. columns grow equally starting from each direction. `column_midpoint_factor` is a
  856. decimal number ranging in value from 0 to 1. If this parameter is not specified,
  857. the default is 0.5.
  858. The ore parameters `clust_scarcity` and `clust_num_ores` are ignored for this ore type.
  859. ### `puff`
  860. Creates a sheet of ore in a cloud-like puff shape.
  861. As with the `sheet` ore type, the size and shape of puffs are described by
  862. `noise_params` and `noise_threshold` and are placed at random vertical positions
  863. within the currently generated chunk.
  864. The vertical top and bottom displacement of each puff are determined by the noise
  865. parameters `np_puff_top` and `np_puff_bottom`, respectively.
  866. ### `blob`
  867. Creates a deformed sphere of ore according to 3d perlin noise described by
  868. `noise_params`. The maximum size of the blob is `clust_size`, and
  869. `clust_scarcity` has the same meaning as with the `scatter` type.
  870. ### `vein`
  871. Creates veins of ore varying in density by according to the intersection of two
  872. instances of 3d perlin noise with diffferent seeds, both described by
  873. `noise_params`. `random_factor` varies the influence random chance has on
  874. placement of an ore inside the vein, which is `1` by default. Note that
  875. modifying this parameter may require adjusting `noise_threshold`.
  876. The parameters `clust_scarcity`, `clust_num_ores`, and `clust_size` are ignored
  877. by this ore type. This ore type is difficult to control since it is sensitive
  878. to small changes. The following is a decent set of parameters to work from:
  879. noise_params = {
  880. offset = 0,
  881. scale = 3,
  882. spread = {x=200, y=200, z=200},
  883. seed = 5390,
  884. octaves = 4,
  885. persist = 0.5,
  886. flags = "eased",
  887. },
  888. noise_threshold = 1.6
  889. **WARNING**: Use this ore type *very* sparingly since it is ~200x more
  890. computationally expensive than any other ore.
  891. Ore attributes
  892. --------------
  893. See section "Flag Specifier Format".
  894. Currently supported flags:
  895. `absheight`, `puff_cliffs`, `puff_additive_composition`.
  896. ### `absheight`
  897. Also produce this same ore between the height range of `-y_max` and `-y_min`.
  898. Useful for having ore in sky realms without having to duplicate ore entries.
  899. ### `puff_cliffs`
  900. If set, puff ore generation will not taper down large differences in displacement
  901. when approaching the edge of a puff. This flag has no effect for ore types other
  902. than `puff`.
  903. ### `puff_additive_composition`
  904. By default, when noise described by `np_puff_top` or `np_puff_bottom` results in a
  905. negative displacement, the sub-column at that point is not generated. With this
  906. attribute set, puff ore generation will instead generate the absolute difference in
  907. noise displacement values. This flag has no effect for ore types other than `puff`.
  908. Decoration types
  909. ----------------
  910. The varying types of decorations that can be placed.
  911. ### `simple`
  912. Creates a 1 times `H` times 1 column of a specified node (or a random node from
  913. a list, if a decoration list is specified). Can specify a certain node it must
  914. spawn next to, such as water or lava, for example. Can also generate a
  915. decoration of random height between a specified lower and upper bound.
  916. This type of decoration is intended for placement of grass, flowers, cacti,
  917. papyri, waterlilies and so on.
  918. ### `schematic`
  919. Copies a box of `MapNodes` from a specified schematic file (or raw description).
  920. Can specify a probability of a node randomly appearing when placed.
  921. This decoration type is intended to be used for multi-node sized discrete
  922. structures, such as trees, cave spikes, rocks, and so on.
  923. Schematic specifier
  924. --------------------
  925. A schematic specifier identifies a schematic by either a filename to a
  926. Minetest Schematic file (`.mts`) or through raw data supplied through Lua,
  927. in the form of a table. This table specifies the following fields:
  928. * The `size` field is a 3D vector containing the dimensions of the provided schematic. (required)
  929. * The `yslice_prob` field is a table of {ypos, prob} which sets the `ypos`th vertical slice
  930. of the schematic to have a `prob / 256 * 100` chance of occuring. (default: 255)
  931. * The `data` field is a flat table of MapNode tables making up the schematic,
  932. in the order of `[z [y [x]]]`. (required)
  933. Each MapNode table contains:
  934. * `name`: the name of the map node to place (required)
  935. * `prob` (alias `param1`): the probability of this node being placed (default: 255)
  936. * `param2`: the raw param2 value of the node being placed onto the map (default: 0)
  937. * `force_place`: boolean representing if the node should forcibly overwrite any
  938. previous contents (default: false)
  939. About probability values:
  940. * A probability value of `0` or `1` means that node will never appear (0% chance).
  941. * A probability value of `254` or `255` means the node will always appear (100% chance).
  942. * If the probability value `p` is greater than `1`, then there is a
  943. `(p / 256 * 100)` percent chance that node will appear when the schematic is
  944. placed on the map.
  945. Schematic attributes
  946. --------------------
  947. See section "Flag Specifier Format".
  948. Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`,
  949. `force_placement`.
  950. * `place_center_x`: Placement of this decoration is centered along the X axis.
  951. * `place_center_y`: Placement of this decoration is centered along the Y axis.
  952. * `place_center_z`: Placement of this decoration is centered along the Z axis.
  953. * `force_placement`: Schematic nodes other than "ignore" will replace existing nodes.
  954. HUD element types
  955. -----------------
  956. The position field is used for all element types.
  957. To account for differing resolutions, the position coordinates are the percentage
  958. of the screen, ranging in value from `0` to `1`.
  959. The name field is not yet used, but should contain a description of what the
  960. HUD element represents. The direction field is the direction in which something
  961. is drawn.
  962. `0` draws from left to right, `1` draws from right to left, `2` draws from
  963. top to bottom, and `3` draws from bottom to top.
  964. The `alignment` field specifies how the item will be aligned. It ranges from `-1` to `1`,
  965. with `0` being the center, `-1` is moved to the left/up, and `1` is to the right/down.
  966. Fractional values can be used.
  967. The `offset` field specifies a pixel offset from the position. Contrary to position,
  968. the offset is not scaled to screen size. This allows for some precisely-positioned
  969. items in the HUD.
  970. **Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling factor!
  971. Below are the specific uses for fields in each type; fields not listed for that type are ignored.
  972. **Note**: Future revisions to the HUD API may be incompatible; the HUD API is still
  973. in the experimental stages.
  974. ### `image`
  975. Displays an image on the HUD.
  976. * `scale`: The scale of the image, with 1 being the original texture size.
  977. Only the X coordinate scale is used (positive values).
  978. Negative values represent that percentage of the screen it
  979. should take; e.g. `x=-100` means 100% (width).
  980. * `text`: The name of the texture that is displayed.
  981. * `alignment`: The alignment of the image.
  982. * `offset`: offset in pixels from position.
  983. ### `text`
  984. Displays text on the HUD.
  985. * `scale`: Defines the bounding rectangle of the text.
  986. A value such as `{x=100, y=100}` should work.
  987. * `text`: The text to be displayed in the HUD element.
  988. * `number`: An integer containing the RGB value of the color used to draw the text.
  989. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
  990. * `alignment`: The alignment of the text.
  991. * `offset`: offset in pixels from position.
  992. ### `statbar`
  993. Displays a horizontal bar made up of half-images.
  994. * `text`: The name of the texture that is used.
  995. * `number`: The number of half-textures that are displayed.
  996. If odd, will end with a vertically center-split texture.
  997. * `direction`
  998. * `offset`: offset in pixels from position.
  999. * `size`: If used, will force full-image size to this value (override texture pack image size)
  1000. ### `inventory`
  1001. * `text`: The name of the inventory list to be displayed.
  1002. * `number`: Number of items in the inventory to be displayed.
  1003. * `item`: Position of item that is selected.
  1004. * `direction`
  1005. * `offset`: offset in pixels from position.
  1006. ### `waypoint`
  1007. Displays distance to selected world position.
  1008. * `name`: The name of the waypoint.
  1009. * `text`: Distance suffix. Can be blank.
  1010. * `number:` An integer containing the RGB value of the color used to draw the text.
  1011. * `world_pos`: World position of the waypoint.
  1012. Representations of simple things
  1013. --------------------------------
  1014. ### Position/vector
  1015. {x=num, y=num, z=num}
  1016. For helper functions see "Vector helpers".
  1017. ### `pointed_thing`
  1018. * `{type="nothing"}`
  1019. * `{type="node", under=pos, above=pos}`
  1020. * `{type="object", ref=ObjectRef}`
  1021. Flag Specifier Format
  1022. ---------------------
  1023. Flags using the standardized flag specifier format can be specified in either of
  1024. two ways, by string or table.
  1025. The string format is a comma-delimited set of flag names; whitespace and
  1026. unrecognized flag fields are ignored. Specifying a flag in the string sets the
  1027. flag, and specifying a flag prefixed by the string `"no"` explicitly
  1028. clears the flag from whatever the default may be.
  1029. In addition to the standard string flag format, the schematic flags field can
  1030. also be a table of flag names to boolean values representing whether or not the
  1031. flag is set. Additionally, if a field with the flag name prefixed with `"no"`
  1032. is present, mapped to a boolean of any value, the specified flag is unset.
  1033. E.g. A flag field of value
  1034. {place_center_x = true, place_center_y=false, place_center_z=true}
  1035. is equivalent to
  1036. {place_center_x = true, noplace_center_y=true, place_center_z=true}
  1037. which is equivalent to
  1038. "place_center_x, noplace_center_y, place_center_z"
  1039. or even
  1040. "place_center_x, place_center_z"
  1041. since, by default, no schematic attributes are set.
  1042. Items
  1043. -----
  1044. ### Item types
  1045. There are three kinds of items: nodes, tools and craftitems.
  1046. * Node (`register_node`): A node from the world.
  1047. * Tool (`register_tool`): A tool/weapon that can dig and damage
  1048. things according to `tool_capabilities`.
  1049. * Craftitem (`register_craftitem`): A miscellaneous item.
  1050. ### Amount and wear
  1051. All item stacks have an amount between 0 to 65535. It is 1 by
  1052. default. Tool item stacks can not have an amount greater than 1.
  1053. Tools use a wear (=damage) value ranging from 0 to 65535. The
  1054. value 0 is the default and used is for unworn tools. The values
  1055. 1 to 65535 are used for worn tools, where a higher value stands for
  1056. a higher wear. Non-tools always have a wear value of 0.
  1057. ### Item formats
  1058. Items and item stacks can exist in three formats: Serializes, table format
  1059. and `ItemStack`.
  1060. #### Serialized
  1061. This is called "stackstring" or "itemstring". It is a simple string with
  1062. 1-3 components: the full item identifier, an optional amount and an optional
  1063. wear value. Syntax:
  1064. <identifier> [<amount>[ <wear>]]
  1065. Examples:
  1066. * `'default:apple'`: 1 apple
  1067. * `'default:dirt 5'`: 5 dirt
  1068. * `'default:pick_stone'`: a new stone pickaxe
  1069. * `'default:pick_wood 1 21323'`: a wooden pickaxe, ca. 1/3 worn out
  1070. #### Table format
  1071. Examples:
  1072. 5 dirt nodes:
  1073. {name="default:dirt", count=5, wear=0, metadata=""}
  1074. A wooden pick about 1/3 worn out:
  1075. {name="default:pick_wood", count=1, wear=21323, metadata=""}
  1076. An apple:
  1077. {name="default:apple", count=1, wear=0, metadata=""}
  1078. #### `ItemStack`
  1079. A native C++ format with many helper methods. Useful for converting
  1080. between formats. See the Class reference section for details.
  1081. When an item must be passed to a function, it can usually be in any of
  1082. these formats.
  1083. Groups
  1084. ------
  1085. In a number of places, there is a group table. Groups define the
  1086. properties of a thing (item, node, armor of entity, capabilities of
  1087. tool) in such a way that the engine and other mods can can interact with
  1088. the thing without actually knowing what the thing is.
  1089. ### Usage
  1090. Groups are stored in a table, having the group names with keys and the
  1091. group ratings as values. For example:
  1092. groups = {crumbly=3, soil=1}
  1093. -- ^ Default dirt
  1094. groups = {crumbly=2, soil=1, level=2, outerspace=1}
  1095. -- ^ A more special dirt-kind of thing
  1096. Groups always have a rating associated with them. If there is no
  1097. useful meaning for a rating for an enabled group, it shall be `1`.
  1098. When not defined, the rating of a group defaults to `0`. Thus when you
  1099. read groups, you must interpret `nil` and `0` as the same value, `0`.
  1100. You can read the rating of a group for an item or a node by using
  1101. minetest.get_item_group(itemname, groupname)
  1102. ### Groups of items
  1103. Groups of items can define what kind of an item it is (e.g. wool).
  1104. ### Groups of nodes
  1105. In addition to the general item things, groups are used to define whether
  1106. a node is destroyable and how long it takes to destroy by a tool.
  1107. ### Groups of entities
  1108. For entities, groups are, as of now, used only for calculating damage.
  1109. The rating is the percentage of damage caused by tools with this damage group.
  1110. See "Entity damage mechanism".
  1111. object.get_armor_groups() --> a group-rating table (e.g. {fleshy=100})
  1112. object.set_armor_groups({fleshy=30, cracky=80})
  1113. ### Groups of tools
  1114. Groups in tools define which groups of nodes and entities they are
  1115. effective towards.
  1116. ### Groups in crafting recipes
  1117. An example: Make meat soup from any meat, any water and any bowl:
  1118. {
  1119. output = 'food:meat_soup_raw',
  1120. recipe = {
  1121. {'group:meat'},
  1122. {'group:water'},
  1123. {'group:bowl'},
  1124. },
  1125. -- preserve = {'group:bowl'}, -- Not implemented yet (TODO)
  1126. }
  1127. Another example: Make red wool from white wool and red dye:
  1128. {
  1129. type = 'shapeless',
  1130. output = 'wool:red',
  1131. recipe = {'wool:white', 'group:dye,basecolor_red'},
  1132. }
  1133. ### Special groups
  1134. * `immortal`: Disables the group damage system for an entity
  1135. * `punch_operable`: For entities; disables the regular damage mechanism for
  1136. players punching it by hand or a non-tool item, so that it can do something
  1137. else than take damage.
  1138. * `level`: Can be used to give an additional sense of progression in the game.
  1139. * A larger level will cause e.g. a weapon of a lower level make much less
  1140. damage, and get worn out much faster, or not be able to get drops
  1141. from destroyed nodes.
  1142. * `0` is something that is directly accessible at the start of gameplay
  1143. * There is no upper limit
  1144. * `dig_immediate`: (player can always pick up node without reducing tool wear)
  1145. * `2`: the node always gets the digging time 0.5 seconds (rail, sign)
  1146. * `3`: the node always gets the digging time 0 seconds (torch)
  1147. * `disable_jump`: Player (and possibly other things) cannot jump from node
  1148. * `fall_damage_add_percent`: damage speed = `speed * (1 + value/100)`
  1149. * `bouncy`: value is bounce speed in percent
  1150. * `falling_node`: if there is no walkable block under the node it will fall
  1151. * `attached_node`: if the node under it is not a walkable block the node will be
  1152. dropped as an item. If the node is wallmounted the wallmounted direction is
  1153. checked.
  1154. * `soil`: saplings will grow on nodes in this group
  1155. * `connect_to_raillike`: makes nodes of raillike drawtype with same group value
  1156. connect to each other
  1157. ### Known damage and digging time defining groups
  1158. * `crumbly`: dirt, sand
  1159. * `cracky`: tough but crackable stuff like stone.
  1160. * `snappy`: something that can be cut using fine tools; e.g. leaves, small
  1161. plants, wire, sheets of metal
  1162. * `choppy`: something that can be cut using force; e.g. trees, wooden planks
  1163. * `fleshy`: Living things like animals and the player. This could imply
  1164. some blood effects when hitting.
  1165. * `explody`: Especially prone to explosions
  1166. * `oddly_breakable_by_hand`:
  1167. Can be added to nodes that shouldn't logically be breakable by the
  1168. hand but are. Somewhat similar to `dig_immediate`, but times are more
  1169. like `{[1]=3.50,[2]=2.00,[3]=0.70}` and this does not override the
  1170. speed of a tool if the tool can dig at a faster speed than this
  1171. suggests for the hand.
  1172. ### Examples of custom groups
  1173. Item groups are often used for defining, well, _groups of items_.
  1174. * `meat`: any meat-kind of a thing (rating might define the size or healing
  1175. ability or be irrelevant -- it is not defined as of yet)
  1176. * `eatable`: anything that can be eaten. Rating might define HP gain in half
  1177. hearts.
  1178. * `flammable`: can be set on fire. Rating might define the intensity of the
  1179. fire, affecting e.g. the speed of the spreading of an open fire.
  1180. * `wool`: any wool (any origin, any color)
  1181. * `metal`: any metal
  1182. * `weapon`: any weapon
  1183. * `heavy`: anything considerably heavy
  1184. ### Digging time calculation specifics
  1185. Groups such as `crumbly`, `cracky` and `snappy` are used for this
  1186. purpose. Rating is `1`, `2` or `3`. A higher rating for such a group implies
  1187. faster digging time.
  1188. The `level` group is used to limit the toughness of nodes a tool can dig
  1189. and to scale the digging times / damage to a greater extent.
  1190. **Please do understand this**, otherwise you cannot use the system to it's
  1191. full potential.
  1192. Tools define their properties by a list of parameters for groups. They
  1193. cannot dig other groups; thus it is important to use a standard bunch of
  1194. groups to enable interaction with tools.
  1195. #### Tools definition
  1196. Tools define:
  1197. * Full punch interval
  1198. * Maximum drop level
  1199. * For an arbitrary list of groups:
  1200. * Uses (until the tool breaks)
  1201. * Maximum level (usually `0`, `1`, `2` or `3`)
  1202. * Digging times
  1203. * Damage groups
  1204. #### Full punch interval
  1205. When used as a weapon, the tool will do full damage if this time is spent
  1206. between punches. If e.g. half the time is spent, the tool will do half
  1207. damage.
  1208. #### Maximum drop level
  1209. Suggests the maximum level of node, when dug with the tool, that will drop
  1210. it's useful item. (e.g. iron ore to drop a lump of iron).
  1211. This is not automated; it is the responsibility of the node definition
  1212. to implement this.
  1213. #### Uses
  1214. Determines how many uses the tool has when it is used for digging a node,
  1215. of this group, of the maximum level. For lower leveled nodes, the use count
  1216. is multiplied by `3^leveldiff`.
  1217. * `uses=10, leveldiff=0`: actual uses: 10
  1218. * `uses=10, leveldiff=1`: actual uses: 30
  1219. * `uses=10, leveldiff=2`: actual uses: 90
  1220. #### Maximum level
  1221. Tells what is the maximum level of a node of this group that the tool will
  1222. be able to dig.
  1223. #### Digging times
  1224. List of digging times for different ratings of the group, for nodes of the
  1225. maximum level.
  1226. For example, as a Lua table, `times={2=2.00, 3=0.70}`. This would
  1227. result in the tool to be able to dig nodes that have a rating of `2` or `3`
  1228. for this group, and unable to dig the rating `1`, which is the toughest.
  1229. Unless there is a matching group that enables digging otherwise.
  1230. If the result digging time is 0, a delay of 0.15 seconds is added between
  1231. digging nodes; If the player releases LMB after digging, this delay is set to 0,
  1232. i.e. players can more quickly click the nodes away instead of holding LMB.
  1233. #### Damage groups
  1234. List of damage for groups of entities. See "Entity damage mechanism".
  1235. #### Example definition of the capabilities of a tool
  1236. tool_capabilities = {
  1237. full_punch_interval=1.5,
  1238. max_drop_level=1,
  1239. groupcaps={
  1240. crumbly={maxlevel=2, uses=20, times={[1]=1.60, [2]=1.20, [3]=0.80}}
  1241. }
  1242. damage_groups = {fleshy=2},
  1243. }
  1244. This makes the tool be able to dig nodes that fulfil both of these:
  1245. * Have the `crumbly` group
  1246. * Have a `level` group less or equal to `2`
  1247. Table of resulting digging times:
  1248. crumbly 0 1 2 3 4 <- level
  1249. -> 0 - - - - -
  1250. 1 0.80 1.60 1.60 - -
  1251. 2 0.60 1.20 1.20 - -
  1252. 3 0.40 0.80 0.80 - -
  1253. level diff: 2 1 0 -1 -2
  1254. Table of resulting tool uses:
  1255. -> 0 - - - - -
  1256. 1 180 60 20 - -
  1257. 2 180 60 20 - -
  1258. 3 180 60 20 - -
  1259. **Notes**:
  1260. * At `crumbly==0`, the node is not diggable.
  1261. * At `crumbly==3`, the level difference digging time divider kicks in and makes
  1262. easy nodes to be quickly breakable.
  1263. * At `level > 2`, the node is not diggable, because it's `level > maxlevel`
  1264. Entity damage mechanism
  1265. -----------------------
  1266. Damage calculation:
  1267. damage = 0
  1268. foreach group in cap.damage_groups:
  1269. damage += cap.damage_groups[group] * limit(actual_interval /
  1270. cap.full_punch_interval, 0.0, 1.0)
  1271. * (object.armor_groups[group] / 100.0)
  1272. -- Where object.armor_groups[group] is 0 for inexistent values
  1273. return damage
  1274. Client predicts damage based on damage groups. Because of this, it is able to
  1275. give an immediate response when an entity is damaged or dies; the response is
  1276. pre-defined somehow (e.g. by defining a sprite animation) (not implemented;
  1277. TODO).
  1278. Currently a smoke puff will appear when an entity dies.
  1279. The group `immortal` completely disables normal damage.
  1280. Entities can define a special armor group, which is `punch_operable`. This
  1281. group disables the regular damage mechanism for players punching it by hand or
  1282. a non-tool item, so that it can do something else than take damage.
  1283. On the Lua side, every punch calls:
  1284. entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction, damage)
  1285. This should never be called directly, because damage is usually not handled by
  1286. the entity itself.
  1287. * `puncher` is the object performing the punch. Can be `nil`. Should never be
  1288. accessed unless absolutely required, to encourage interoperability.
  1289. * `time_from_last_punch` is time from last punch (by `puncher`) or `nil`.
  1290. * `tool_capabilities` can be `nil`.
  1291. * `direction` is a unit vector, pointing from the source of the punch to
  1292. the punched object.
  1293. * `damage` damage that will be done to entity
  1294. Return value of this function will determin if damage is done by this function
  1295. (retval true) or shall be done by engine (retval false)
  1296. To punch an entity/object in Lua, call:
  1297. object:punch(puncher, time_from_last_punch, tool_capabilities, direction)
  1298. * Return value is tool wear.
  1299. * Parameters are equal to the above callback.
  1300. * If `direction` equals `nil` and `puncher` does not equal `nil`,
  1301. `direction` will be automatically filled in based on the location of `puncher`.
  1302. Node Metadata
  1303. -------------
  1304. The instance of a node in the world normally only contains the three values
  1305. mentioned in "Nodes". However, it is possible to insert extra data into a
  1306. node. It is called "node metadata"; See `NodeMetaRef`.
  1307. Node metadata contains two things:
  1308. * A key-value store
  1309. * An inventory
  1310. Some of the values in the key-value store are handled specially:
  1311. * `formspec`: Defines a right-click inventory menu. See "Formspec".
  1312. * `infotext`: Text shown on the screen when the node is pointed at
  1313. Example stuff:
  1314. local meta = minetest.get_meta(pos)
  1315. meta:set_string("formspec",
  1316. "size[8,9]"..
  1317. "list[context;main;0,0;8,4;]"..
  1318. "list[current_player;main;0,5;8,4;]")
  1319. meta:set_string("infotext", "Chest");
  1320. local inv = meta:get_inventory()
  1321. inv:set_size("main", 8*4)
  1322. print(dump(meta:to_table()))
  1323. meta:from_table({
  1324. inventory = {
  1325. main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "",
  1326. [5] = "", [6] = "", [7] = "", [8] = "", [9] = "",
  1327. [10] = "", [11] = "", [12] = "", [13] = "",
  1328. [14] = "default:cobble", [15] = "", [16] = "", [17] = "",
  1329. [18] = "", [19] = "", [20] = "default:cobble", [21] = "",
  1330. [22] = "", [23] = "", [24] = "", [25] = "", [26] = "",
  1331. [27] = "", [28] = "", [29] = "", [30] = "", [31] = "",
  1332. [32] = ""}
  1333. },
  1334. fields = {
  1335. formspec = "size[8,9]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
  1336. infotext = "Chest"
  1337. }
  1338. })
  1339. Item Metadata
  1340. -------------
  1341. Item stacks can store metadata too. See `ItemStackMetaRef`.
  1342. Item metadata only contains a key-value store.
  1343. Some of the values in the key-value store are handled specially:
  1344. * `description`: Set the item stack's description. Defaults to `idef.description`
  1345. * `color`: A `ColorString`, which sets the stack's color.
  1346. * `palette_index`: If the item has a palette, this is used to get the
  1347. current color from the palette.
  1348. Example stuff:
  1349. local meta = stack:get_meta()
  1350. meta:set_string("key", "value")
  1351. print(dump(meta:to_table()))
  1352. Formspec
  1353. --------
  1354. Formspec defines a menu. Currently not much else than inventories are
  1355. supported. It is a string, with a somewhat strange format.
  1356. Spaces and newlines can be inserted between the blocks, as is used in the
  1357. examples.
  1358. ### Examples
  1359. #### Chest
  1360. size[8,9]
  1361. list[context;main;0,0;8,4;]
  1362. list[current_player;main;0,5;8,4;]
  1363. #### Furnace
  1364. size[8,9]
  1365. list[context;fuel;2,3;1,1;]
  1366. list[context;src;2,1;1,1;]
  1367. list[context;dst;5,1;2,2;]
  1368. list[current_player;main;0,5;8,4;]
  1369. #### Minecraft-like player inventory
  1370. size[8,7.5]
  1371. image[1,0.6;1,2;player.png]
  1372. list[current_player;main;0,3.5;8,4;]
  1373. list[current_player;craft;3,0;3,3;]
  1374. list[current_player;craftpreview;7,1;1,1;]
  1375. ### Elements
  1376. #### `size[<W>,<H>,<fixed_size>]`
  1377. * Define the size of the menu in inventory slots
  1378. * `fixed_size`: `true`/`false` (optional)
  1379. * deprecated: `invsize[<W>,<H>;]`
  1380. #### `position[<X>,<Y>]`
  1381. * Define the position of the formspec
  1382. * A value between 0.0 and 1.0 represents a position inside the screen
  1383. * The default value is the center of the screen (0.5, 0.5)
  1384. #### `anchor[<X>,<Y>]`
  1385. * Define the anchor of the formspec
  1386. * A value between 0.0 and 1.0 represents an anchor inside the formspec
  1387. * The default value is the center of the formspec (0.5, 0.5)
  1388. #### `container[<X>,<Y>]`
  1389. * Start of a container block, moves all physical elements in the container by (X, Y)
  1390. * Must have matching `container_end`
  1391. * Containers can be nested, in which case the offsets are added
  1392. (child containers are relative to parent containers)
  1393. #### `container_end[]`
  1394. * End of a container, following elements are no longer relative to this container
  1395. #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]`
  1396. * Show an inventory list
  1397. #### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
  1398. * Show an inventory list
  1399. #### `listring[<inventory location>;<list name>]`
  1400. * Allows to create a ring of inventory lists
  1401. * Shift-clicking on items in one element of the ring
  1402. will send them to the next inventory list inside the ring
  1403. * The first occurrence of an element inside the ring will
  1404. determine the inventory where items will be sent to
  1405. #### `listring[]`
  1406. * Shorthand for doing `listring[<inventory location>;<list name>]`
  1407. for the last two inventory lists added by list[...]
  1408. #### `listcolors[<slot_bg_normal>;<slot_bg_hover>]`
  1409. * Sets background color of slots as `ColorString`
  1410. * Sets background color of slots on mouse hovering
  1411. #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>]`
  1412. * Sets background color of slots as `ColorString`
  1413. * Sets background color of slots on mouse hovering
  1414. * Sets color of slots border
  1415. #### `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<tooltip_fontcolor>]`
  1416. * Sets background color of slots as `ColorString`
  1417. * Sets background color of slots on mouse hovering
  1418. * Sets color of slots border
  1419. * Sets default background color of tooltips
  1420. * Sets default font color of tooltips
  1421. #### `tooltip[<gui_element_name>;<tooltip_text>;<bgcolor>;<fontcolor>]`
  1422. * Adds tooltip for an element
  1423. * `<bgcolor>` tooltip background color as `ColorString` (optional)
  1424. * `<fontcolor>` tooltip font color as `ColorString` (optional)
  1425. #### `image[<X>,<Y>;<W>,<H>;<texture name>]`
  1426. * Show an image
  1427. * Position and size units are inventory slots
  1428. #### `item_image[<X>,<Y>;<W>,<H>;<item name>]`
  1429. * Show an inventory image of registered item/node
  1430. * Position and size units are inventory slots
  1431. #### `bgcolor[<color>;<fullscreen>]`
  1432. * Sets background color of formspec as `ColorString`
  1433. * If `true`, the background color is drawn fullscreen (does not effect the size of the formspec)
  1434. #### `background[<X>,<Y>;<W>,<H>;<texture name>]`
  1435. * Use a background. Inventory rectangles are not drawn then.
  1436. * Position and size units are inventory slots
  1437. * Example for formspec 8x4 in 16x resolution: image shall be sized
  1438. 8 times 16px times 4 times 16px.
  1439. #### `background[<X>,<Y>;<W>,<H>;<texture name>;<auto_clip>]`
  1440. * Use a background. Inventory rectangles are not drawn then.
  1441. * Position and size units are inventory slots
  1442. * Example for formspec 8x4 in 16x resolution:
  1443. image shall be sized 8 times 16px times 4 times 16px
  1444. * If `true` the background is clipped to formspec size
  1445. (`x` and `y` are used as offset values, `w` and `h` are ignored)
  1446. #### `pwdfield[<X>,<Y>;<W>,<H>;<name>;<label>]`
  1447. * Textual password style field; will be sent to server when a button is clicked
  1448. * When enter is pressed in field, fields.key_enter_field will be sent with the name
  1449. of this field.
  1450. * `x` and `y` position the field relative to the top left of the menu
  1451. * `w` and `h` are the size of the field
  1452. * Fields are a set height, but will be vertically centred on `h`
  1453. * Position and size units are inventory slots
  1454. * `name` is the name of the field as returned in fields to `on_receive_fields`
  1455. * `label`, if not blank, will be text printed on the top left above the field
  1456. * See field_close_on_enter to stop enter closing the formspec
  1457. #### `field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
  1458. * Textual field; will be sent to server when a button is clicked
  1459. * When enter is pressed in field, `fields.key_enter_field` will be sent with the name
  1460. of this field.
  1461. * `x` and `y` position the field relative to the top left of the menu
  1462. * `w` and `h` are the size of the field
  1463. * Fields are a set height, but will be vertically centred on `h`
  1464. * Position and size units are inventory slots
  1465. * `name` is the name of the field as returned in fields to `on_receive_fields`
  1466. * `label`, if not blank, will be text printed on the top left above the field
  1467. * `default` is the default value of the field
  1468. * `default` may contain variable references such as `${text}'` which
  1469. will fill the value from the metadata value `text`
  1470. * **Note**: no extra text or more than a single variable is supported ATM.
  1471. * See `field_close_on_enter` to stop enter closing the formspec
  1472. #### `field[<name>;<label>;<default>]`
  1473. * As above, but without position/size units
  1474. * When enter is pressed in field, `fields.key_enter_field` will be sent with the name
  1475. of this field.
  1476. * Special field for creating simple forms, such as sign text input
  1477. * Must be used without a `size[]` element
  1478. * A "Proceed" button will be added automatically
  1479. * See `field_close_on_enter` to stop enter closing the formspec
  1480. #### `field_close_on_enter[<name>;<close_on_enter>]`
  1481. * <name> is the name of the field
  1482. * if <close_on_enter> is false, pressing enter in the field will submit the form but not close it
  1483. * defaults to true when not specified (ie: no tag for a field)
  1484. #### `textarea[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]`
  1485. * Same as fields above, but with multi-line input
  1486. #### `label[<X>,<Y>;<label>]`
  1487. * `x` and `y` work as per field
  1488. * `label` is the text on the label
  1489. * Position and size units are inventory slots
  1490. #### `vertlabel[<X>,<Y>;<label>]`
  1491. * Textual label drawn vertically
  1492. * `x` and `y` work as per field
  1493. * `label` is the text on the label
  1494. * Position and size units are inventory slots
  1495. #### `button[<X>,<Y>;<W>,<H>;<name>;<label>]`
  1496. * Clickable button. When clicked, fields will be sent.
  1497. * `x`, `y` and `name` work as per field
  1498. * `w` and `h` are the size of the button
  1499. * `label` is the text on the button
  1500. * Position and size units are inventory slots
  1501. #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
  1502. * `x`, `y`, `w`, `h`, and `name` work as per button
  1503. * `texture name` is the filename of an image
  1504. * Position and size units are inventory slots
  1505. #### `image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]`
  1506. * `x`, `y`, `w`, `h`, and `name` work as per button
  1507. * `texture name` is the filename of an image
  1508. * Position and size units are inventory slots
  1509. * `noclip=true` means the image button doesn't need to be within specified formsize
  1510. * `drawborder`: draw button border or not
  1511. * `pressed texture name` is the filename of an image on pressed state
  1512. #### `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
  1513. * `x`, `y`, `w`, `h`, `name` and `label` work as per button
  1514. * `item name` is the registered name of an item/node,
  1515. tooltip will be made out of its description
  1516. to override it use tooltip element
  1517. * Position and size units are inventory slots
  1518. #### `button_exit[<X>,<Y>;<W>,<H>;<name>;<label>]`
  1519. * When clicked, fields will be sent and the form will quit.
  1520. #### `image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]`
  1521. * When clicked, fields will be sent and the form will quit.
  1522. #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>]`
  1523. * Scrollable item list showing arbitrary text elements
  1524. * `x` and `y` position the itemlist relative to the top left of the menu
  1525. * `w` and `h` are the size of the itemlist
  1526. * `name` fieldname sent to server on doubleclick value is current selected element
  1527. * `listelements` can be prepended by #color in hexadecimal format RRGGBB (only),
  1528. * if you want a listelement to start with "#" write "##".
  1529. #### `textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>;<selected idx>;<transparent>]`
  1530. * Scrollable itemlist showing arbitrary text elements
  1531. * `x` and `y` position the item list relative to the top left of the menu
  1532. * `w` and `h` are the size of the item list
  1533. * `name` fieldname sent to server on doubleclick value is current selected element
  1534. * `listelements` can be prepended by #RRGGBB (only) in hexadecimal format
  1535. * if you want a listelement to start with "#" write "##"
  1536. * Index to be selected within textlist
  1537. * `true`/`false`: draw transparent background
  1538. * See also `minetest.explode_textlist_event` (main menu: `engine.explode_textlist_event`)
  1539. #### `tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]`
  1540. * Show a tab**header** at specific position (ignores formsize)
  1541. * `x` and `y` position the itemlist relative to the top left of the menu
  1542. * `name` fieldname data is transferred to Lua
  1543. * `caption 1`...: name shown on top of tab
  1544. * `current_tab`: index of selected tab 1...
  1545. * `transparent` (optional): show transparent
  1546. * `draw_border` (optional): draw border
  1547. #### `box[<X>,<Y>;<W>,<H>;<color>]`
  1548. * Simple colored semitransparent box
  1549. * `x` and `y` position the box relative to the top left of the menu
  1550. * `w` and `h` are the size of box
  1551. * `color` is color specified as a `ColorString`
  1552. #### `dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]`
  1553. * Show a dropdown field
  1554. * **Important note**: There are two different operation modes:
  1555. 1. handle directly on change (only changed dropdown is submitted)
  1556. 2. read the value on pressing a button (all dropdown values are available)
  1557. * `x` and `y` position of dropdown
  1558. * Width of dropdown
  1559. * Fieldname data is transferred to Lua
  1560. * Items to be shown in dropdown
  1561. * Index of currently selected dropdown item
  1562. #### `checkbox[<X>,<Y>;<name>;<label>;<selected>]`
  1563. * Show a checkbox
  1564. * `x` and `y`: position of checkbox
  1565. * `name` fieldname data is transferred to Lua
  1566. * `label` to be shown left of checkbox
  1567. * `selected` (optional): `true`/`false`
  1568. #### `scrollbar[<X>,<Y>;<W>,<H>;<orientation>;<name>;<value>]`
  1569. * Show a scrollbar
  1570. * There are two ways to use it:
  1571. 1. handle the changed event (only changed scrollbar is available)
  1572. 2. read the value on pressing a button (all scrollbars are available)
  1573. * `x` and `y`: position of trackbar
  1574. * `w` and `h`: width and height
  1575. * `orientation`: `vertical`/`horizontal`
  1576. * Fieldname data is transferred to Lua
  1577. * Value this trackbar is set to (`0`-`1000`)
  1578. * See also `minetest.explode_scrollbar_event` (main menu: `engine.explode_scrollbar_event`)
  1579. #### `table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]`
  1580. * Show scrollable table using options defined by the previous `tableoptions[]`
  1581. * Displays cells as defined by the previous `tablecolumns[]`
  1582. * `x` and `y`: position the itemlist relative to the top left of the menu
  1583. * `w` and `h` are the size of the itemlist
  1584. * `name`: fieldname sent to server on row select or doubleclick
  1585. * `cell 1`...`cell n`: cell contents given in row-major order
  1586. * `selected idx`: index of row to be selected within table (first row = `1`)
  1587. * See also `minetest.explode_table_event` (main menu: `engine.explode_table_event`)
  1588. #### `tableoptions[<opt 1>;<opt 2>;...]`
  1589. * Sets options for `table[]`
  1590. * `color=#RRGGBB`
  1591. * default text color (`ColorString`), defaults to `#FFFFFF`
  1592. * `background=#RRGGBB`
  1593. * table background color (`ColorString`), defaults to `#000000`
  1594. * `border=<true/false>`
  1595. * should the table be drawn with a border? (default: `true`)
  1596. * `highlight=#RRGGBB`
  1597. * highlight background color (`ColorString`), defaults to `#466432`
  1598. * `highlight_text=#RRGGBB`
  1599. * highlight text color (`ColorString`), defaults to `#FFFFFF`
  1600. * `opendepth=<value>`
  1601. * all subtrees up to `depth < value` are open (default value = `0`)
  1602. * only useful when there is a column of type "tree"
  1603. #### `tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]`
  1604. * Sets columns for `table[]`
  1605. * Types: `text`, `image`, `color`, `indent`, `tree`
  1606. * `text`: show cell contents as text
  1607. * `image`: cell contents are an image index, use column options to define images
  1608. * `color`: cell contents are a ColorString and define color of following cell
  1609. * `indent`: cell contents are a number and define indentation of following cell
  1610. * `tree`: same as indent, but user can open and close subtrees (treeview-like)
  1611. * Column options:
  1612. * `align=<value>`
  1613. * for `text` and `image`: content alignment within cells.
  1614. Available values: `left` (default), `center`, `right`, `inline`
  1615. * `width=<value>`
  1616. * for `text` and `image`: minimum width in em (default: `0`)
  1617. * for `indent` and `tree`: indent width in em (default: `1.5`)
  1618. * `padding=<value>`: padding left of the column, in em (default `0.5`).
  1619. Exception: defaults to 0 for indent columns
  1620. * `tooltip=<value>`: tooltip text (default: empty)
  1621. * `image` column options:
  1622. * `0=<value>` sets image for image index 0
  1623. * `1=<value>` sets image for image index 1
  1624. * `2=<value>` sets image for image index 2
  1625. * and so on; defined indices need not be contiguous empty or
  1626. non-numeric cells are treated as `0`.
  1627. * `color` column options:
  1628. * `span=<value>`: number of following columns to affect (default: infinite)
  1629. **Note**: do _not_ use a element name starting with `key_`; those names are reserved to
  1630. pass key press events to formspec!
  1631. Inventory locations
  1632. -------------------
  1633. * `"context"`: Selected node metadata (deprecated: `"current_name"`)
  1634. * `"current_player"`: Player to whom the menu is shown
  1635. * `"player:<name>"`: Any player
  1636. * `"nodemeta:<X>,<Y>,<Z>"`: Any node metadata
  1637. * `"detached:<name>"`: A detached inventory
  1638. Player Inventory lists
  1639. ----------------------
  1640. * `main`: list containing the default inventory
  1641. * `craft`: list containing the craft input
  1642. * `craftpreview`: list containing the craft output
  1643. * `hand`: list containing an override for the empty hand
  1644. `ColorString`
  1645. -------------
  1646. `#RGB` defines a color in hexadecimal format.
  1647. `#RGBA` defines a color in hexadecimal format and alpha channel.
  1648. `#RRGGBB` defines a color in hexadecimal format.
  1649. `#RRGGBBAA` defines a color in hexadecimal format and alpha channel.
  1650. Named colors are also supported and are equivalent to
  1651. [CSS Color Module Level 4](http://dev.w3.org/csswg/css-color/#named-colors).
  1652. To specify the value of the alpha channel, append `#AA` to the end of the color name
  1653. (e.g. `colorname#08`). For named colors the hexadecimal string representing the alpha
  1654. value must (always) be two hexadecimal digits.
  1655. `ColorSpec`
  1656. -----------
  1657. A ColorSpec specifies a 32-bit color. It can be written in either:
  1658. table form, each element ranging from 0..255 (a, if absent, defaults to 255):
  1659. `colorspec = {a=255, r=0, g=255, b=0}`
  1660. numerical form, the raw integer value of an ARGB8 quad:
  1661. `colorspec = 0xFF00FF00`
  1662. or string form, a ColorString (defined above):
  1663. `colorspec = "green"`
  1664. Escape sequences
  1665. ----------------
  1666. Most text can contain escape sequences, that can for example color the text.
  1667. There are a few exceptions: tab headers, dropdowns and vertical labels can't.
  1668. The following functions provide escape sequences:
  1669. * `minetest.get_color_escape_sequence(color)`:
  1670. * `color` is a ColorString
  1671. * The escape sequence sets the text color to `color`
  1672. * `minetest.colorize(color, message)`:
  1673. * Equivalent to:
  1674. `minetest.get_color_escape_sequence(color) ..
  1675. message ..
  1676. minetest.get_color_escape_sequence("#ffffff")`
  1677. * `minetest.get_background_escape_sequence(color)`
  1678. * `color` is a ColorString
  1679. * The escape sequence sets the background of the whole text element to
  1680. `color`. Only defined for item descriptions and tooltips.
  1681. * `minetest.strip_foreground_colors(str)`
  1682. * Removes foreground colors added by `get_color_escape_sequence`.
  1683. * `minetest.strip_background_colors(str)`
  1684. * Removes background colors added by `get_background_escape_sequence`.
  1685. * `minetest.strip_colors(str)`
  1686. * Removes all color escape sequences.
  1687. Spatial Vectors
  1688. ---------------
  1689. * `vector.new(a[, b, c])`: returns a vector:
  1690. * A copy of `a` if `a` is a vector.
  1691. * `{x = a, y = b, z = c}`, if all `a, b, c` are defined
  1692. * `vector.direction(p1, p2)`: returns a vector
  1693. * `vector.distance(p1, p2)`: returns a number
  1694. * `vector.length(v)`: returns a number
  1695. * `vector.normalize(v)`: returns a vector
  1696. * `vector.floor(v)`: returns a vector, each dimension rounded down
  1697. * `vector.round(v)`: returns a vector, each dimension rounded to nearest int
  1698. * `vector.apply(v, func)`: returns a vector
  1699. * `vector.equals(v1, v2)`: returns a boolean
  1700. * `vector.sort(v1, v2)`: returns minp, maxp vectors of the cuboid defined by v1 and v2
  1701. For the following functions `x` can be either a vector or a number:
  1702. * `vector.add(v, x)`: returns a vector
  1703. * `vector.subtract(v, x)`: returns a vector
  1704. * `vector.multiply(v, x)`: returns a scaled vector or Schur product
  1705. * `vector.divide(v, x)`: returns a scaled vector or Schur quotient
  1706. Helper functions
  1707. ----------------
  1708. * `dump2(obj, name="_", dumped={})`
  1709. * Return object serialized as a string, handles reference loops
  1710. * `dump(obj, dumped={})`
  1711. * Return object serialized as a string
  1712. * `math.hypot(x, y)`
  1713. * Get the hypotenuse of a triangle with legs x and y.
  1714. Useful for distance calculation.
  1715. * `math.sign(x, tolerance)`
  1716. * Get the sign of a number.
  1717. Optional: Also returns `0` when the absolute value is within the tolerance (default: `0`)
  1718. * `string.split(str, separator=",", include_empty=false, max_splits=-1, sep_is_pattern=false)`
  1719. * If `max_splits` is negative, do not limit splits.
  1720. * `sep_is_pattern` specifies if separator is a plain string or a pattern (regex).
  1721. * e.g. `string:split("a,b", ",") == {"a","b"}`
  1722. * `string:trim()`
  1723. * e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"`
  1724. * `minetest.wrap_text(str, limit, [as_table])`: returns a string or table
  1725. * Adds newlines to the string to keep it within the specified character limit
  1726. Note that returned lines may be longer than the limit since it only splits at word borders.
  1727. * limit: Maximal amount of characters in one line
  1728. * as_table: optional, if true return table of lines instead of string
  1729. * `minetest.pos_to_string({x=X,y=Y,z=Z}, decimal_places))`: returns string `"(X,Y,Z)"`
  1730. * Convert position to a printable string
  1731. Optional: 'decimal_places' will round the x, y and z of the pos to the given decimal place.
  1732. * `minetest.string_to_pos(string)`: returns a position
  1733. * Same but in reverse. Returns `nil` if the string can't be parsed to a position.
  1734. * `minetest.string_to_area("(X1, Y1, Z1) (X2, Y2, Z2)")`: returns two positions
  1735. * Converts a string representing an area box into two positions
  1736. * `minetest.formspec_escape(string)`: returns a string
  1737. * escapes the characters "[", "]", "\", "," and ";", which can not be used in formspecs
  1738. * `minetest.is_yes(arg)`
  1739. * returns true if passed 'y', 'yes', 'true' or a number that isn't zero.
  1740. * `minetest.get_us_time()`
  1741. * returns time with microsecond precision. May not return wall time.
  1742. * `table.copy(table)`: returns a table
  1743. * returns a deep copy of `table`
  1744. * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
  1745. * returns the exact position on the surface of a pointed node
  1746. `minetest` namespace reference
  1747. ------------------------------
  1748. ### Utilities
  1749. * `minetest.get_current_modname()`: returns the currently loading mod's name, when we are loading a mod
  1750. * `minetest.get_modpath(modname)`: returns e.g. `"/home/user/.minetest/usermods/modname"`
  1751. * Useful for loading additional `.lua` modules or static data from mod
  1752. * `minetest.get_modnames()`: returns a list of installed mods
  1753. * Return a list of installed mods, sorted alphabetically
  1754. * `minetest.get_worldpath()`: returns e.g. `"/home/user/.minetest/world"`
  1755. * Useful for storing custom data
  1756. * `minetest.is_singleplayer()`
  1757. * `minetest.features`: Table containing API feature flags
  1758. {
  1759. glasslike_framed = true,
  1760. nodebox_as_selectionbox = true,
  1761. chat_send_player_param3 = true,
  1762. get_all_craft_recipes_works = true,
  1763. use_texture_alpha = true,
  1764. -- ^ The transparency channel of textures can be used optionally
  1765. no_legacy_abms = true,
  1766. -- ^ Tree and grass ABMs are no longer done from C++
  1767. texture_names_parens = true,
  1768. -- ^ Texture grouping is possible using parentheses
  1769. area_store_custom_ids = true,
  1770. -- ^ Unique Area ID for AreaStore:insert_area
  1771. add_entity_with_staticdata = true,
  1772. -- ^ add_entity supports passing initial staticdata to on_activate
  1773. no_chat_message_prediction = true,
  1774. -- ^ Chat messages are no longer predicted
  1775. }
  1776. * `minetest.has_feature(arg)`: returns `boolean, missing_features`
  1777. * `arg`: string or table in format `{foo=true, bar=true}`
  1778. * `missing_features`: `{foo=true, bar=true}`
  1779. * `minetest.get_player_information(player_name)`:
  1780. * Returns a table containing information about a player. Example return value:
  1781. {
  1782. address = "127.0.0.1", -- IP address of client
  1783. ip_version = 4, -- IPv4 / IPv6
  1784. min_rtt = 0.01, -- minimum round trip time
  1785. max_rtt = 0.2, -- maximum round trip time
  1786. avg_rtt = 0.02, -- average round trip time
  1787. min_jitter = 0.01, -- minimum packet time jitter
  1788. max_jitter = 0.5, -- maximum packet time jitter
  1789. avg_jitter = 0.03, -- average packet time jitter
  1790. connection_uptime = 200, -- seconds since client connected
  1791. protocol_version = 32, -- protocol version used by client
  1792. -- following information is available on debug build only!!!
  1793. -- DO NOT USE IN MODS
  1794. --ser_vers = 26, -- serialization version used by client
  1795. --major = 0, -- major version number
  1796. --minor = 4, -- minor version number
  1797. --patch = 10, -- patch version number
  1798. --vers_string = "0.4.9-git", -- full version string
  1799. --state = "Active" -- current client state
  1800. }
  1801. * `minetest.mkdir(path)`: returns success.
  1802. * Creates a directory specified by `path`, creating parent directories
  1803. if they don't exist.
  1804. * `minetest.get_dir_list(path, [is_dir])`: returns list of entry names
  1805. * is_dir is one of:
  1806. * nil: return all entries,
  1807. * true: return only subdirectory names, or
  1808. * false: return only file names.
  1809. * `minetest.safe_file_write(path, content)`: returns boolean indicating success
  1810. * Replaces contents of file at path with new contents in a safe (atomic) way.
  1811. Use this instead of below code when writing e.g. database files:
  1812. `local f = io.open(path, "wb"); f:write(content); f:close()`
  1813. * `minetest.get_version()`: returns a table containing components of the
  1814. engine version. Components:
  1815. * `project`: Name of the project, eg, "Minetest"
  1816. * `string`: Simple version, eg, "1.2.3-dev"
  1817. * `hash`: Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty"
  1818. Use this for informational purposes only. The information in the returned
  1819. table does not represent the capabilities of the engine, nor is it
  1820. reliable or verifyable. Compatible forks will have a different name and
  1821. version entirely. To check for the presence of engine features, test
  1822. whether the functions exported by the wanted features exist. For example:
  1823. `if minetest.nodeupdate then ... end`.
  1824. * `minetest.sha1(data, [raw])`: returns the sha1 hash of data
  1825. * `data`: string of data to hash
  1826. * `raw`: return raw bytes instead of hex digits, default: false
  1827. ### Logging
  1828. * `minetest.debug(...)`
  1829. * Equivalent to `minetest.log(table.concat({...}, "\t"))`
  1830. * `minetest.log([level,] text)`
  1831. * `level` is one of `"none"`, `"error"`, `"warning"`, `"action"`,
  1832. `"info"`, or `"verbose"`. Default is `"none"`.
  1833. ### Registration functions
  1834. Call these functions only at load time!
  1835. * `minetest.register_entity(name, prototype table)`
  1836. * `minetest.register_abm(abm definition)`
  1837. * `minetest.register_lbm(lbm definition)`
  1838. * `minetest.register_node(name, node definition)`
  1839. * `minetest.register_tool(name, item definition)`
  1840. * `minetest.register_craftitem(name, item definition)`
  1841. * `minetest.unregister_item(name)`
  1842. * `minetest.register_alias(name, convert_to)`
  1843. * Also use this to set the 'mapgen aliases' needed in a game for the core
  1844. * mapgens. See 'Mapgen aliases' section above.
  1845. * `minetest.register_alias_force(name, convert_to)`
  1846. * `minetest.register_craft(recipe)`
  1847. * Check recipe table syntax for different types below.
  1848. * `minetest.clear_craft(recipe)`
  1849. * Will erase existing craft based either on output item or on input recipe.
  1850. * Specify either output or input only. If you specify both, input will be ignored. For input use the same recipe table
  1851. syntax as for `minetest.register_craft(recipe)`. For output specify only the item, without a quantity.
  1852. * If no erase candidate could be found, Lua exception will be thrown.
  1853. * **Warning**! The type field ("shaped","cooking" or any other) will be ignored if the recipe
  1854. contains output. Erasing is then done independently from the crafting method.
  1855. * `minetest.register_ore(ore definition)`
  1856. * `minetest.register_biome(biome definition)`
  1857. * `minetest.register_decoration(decoration definition)`
  1858. * `minetest.override_item(name, redefinition)`
  1859. * Overrides fields of an item registered with register_node/tool/craftitem.
  1860. * Note: Item must already be defined, (opt)depend on the mod defining it.
  1861. * Example: `minetest.override_item("default:mese", {light_source=LIGHT_MAX})`
  1862. * `minetest.clear_registered_ores()`
  1863. * `minetest.clear_registered_biomes()`
  1864. * `minetest.clear_registered_decorations()`
  1865. ### Global callback registration functions
  1866. Call these functions only at load time!
  1867. * `minetest.register_globalstep(func(dtime))`
  1868. * Called every server step, usually interval of 0.1s
  1869. * `minetest.register_on_shutdown(func())`
  1870. * Called before server shutdown
  1871. * **Warning**: If the server terminates abnormally (i.e. crashes), the registered
  1872. callbacks **will likely not be run**. Data should be saved at
  1873. semi-frequent intervals as well as on server shutdown.
  1874. * `minetest.register_on_placenode(func(pos, newnode, placer, oldnode, itemstack, pointed_thing))`
  1875. * Called when a node has been placed
  1876. * If return `true` no item is taken from `itemstack`
  1877. * `placer` may be any valid ObjectRef or nil.
  1878. * **Not recommended**; use `on_construct` or `after_place_node` in node definition
  1879. whenever possible
  1880. * `minetest.register_on_dignode(func(pos, oldnode, digger))`
  1881. * Called when a node has been dug.
  1882. * **Not recommended**; Use `on_destruct` or `after_dig_node` in node definition
  1883. whenever possible
  1884. * `minetest.register_on_punchnode(func(pos, node, puncher, pointed_thing))`
  1885. * Called when a node is punched
  1886. * `minetest.register_on_generated(func(minp, maxp, blockseed))`
  1887. * Called after generating a piece of world. Modifying nodes inside the area
  1888. is a bit faster than usually.
  1889. * `minetest.register_on_newplayer(func(ObjectRef))`
  1890. * Called after a new player has been created
  1891. * `minetest.register_on_dieplayer(func(ObjectRef))`
  1892. * Called when a player dies
  1893. * `minetest.register_on_punchplayer(func(player, hitter, time_from_last_punch, tool_capabilities, dir, damage))`
  1894. * Called when a player is punched
  1895. * `player` - ObjectRef - Player that was punched
  1896. * `hitter` - ObjectRef - Player that hit
  1897. * `time_from_last_punch`: Meant for disallowing spamming of clicks (can be nil)
  1898. * `tool_capabilities`: capability table of used tool (can be nil)
  1899. * `dir`: unit vector of direction of punch. Always defined. Points from
  1900. the puncher to the punched.
  1901. * `damage` - number that represents the damage calculated by the engine
  1902. * should return `true` to prevent the default damage mechanism
  1903. * `minetest.register_on_player_hpchange(func(player, hp_change), modifier)`
  1904. * Called when the player gets damaged or healed
  1905. * `player`: ObjectRef of the player
  1906. * `hp_change`: the amount of change. Negative when it is damage.
  1907. * `modifier`: when true, the function should return the actual `hp_change`.
  1908. Note: modifiers only get a temporary hp_change that can be modified by later modifiers.
  1909. modifiers can return true as a second argument to stop the execution of further functions.
  1910. Non-modifiers receive the final hp change calculated by the modifiers.
  1911. * `minetest.register_on_respawnplayer(func(ObjectRef))`
  1912. * Called when player is to be respawned
  1913. * Called _before_ repositioning of player occurs
  1914. * return true in func to disable regular player placement
  1915. * `minetest.register_on_prejoinplayer(func(name, ip))`
  1916. * Called before a player joins the game
  1917. * If it returns a string, the player is disconnected with that string as reason
  1918. * `minetest.register_on_joinplayer(func(ObjectRef))`
  1919. * Called when a player joins the game
  1920. * `minetest.register_on_leaveplayer(func(ObjectRef, timed_out))`
  1921. * Called when a player leaves the game
  1922. * `timed_out`: True for timeout, false for other reasons.
  1923. * `minetest.register_on_cheat(func(ObjectRef, cheat))`
  1924. * Called when a player cheats
  1925. * `cheat`: `{type=<cheat_type>}`, where `<cheat_type>` is one of:
  1926. * `moved_too_fast`
  1927. * `interacted_too_far`
  1928. * `interacted_while_dead`
  1929. * `finished_unknown_dig`
  1930. * `dug_unbreakable`
  1931. * `dug_too_fast`
  1932. * `minetest.register_on_chat_message(func(name, message))`
  1933. * Called always when a player says something
  1934. * Return `true` to mark the message as handled, which means that it will not be sent to other players
  1935. * `minetest.register_on_player_receive_fields(func(player, formname, fields))`
  1936. * Called when a button is pressed in player's inventory form
  1937. * Newest functions are called first
  1938. * If function returns `true`, remaining functions are not called
  1939. * `minetest.register_on_craft(func(itemstack, player, old_craft_grid, craft_inv))`
  1940. * Called when `player` crafts something
  1941. * `itemstack` is the output
  1942. * `old_craft_grid` contains the recipe (Note: the one in the inventory is cleared)
  1943. * `craft_inv` is the inventory with the crafting grid
  1944. * Return either an `ItemStack`, to replace the output, or `nil`, to not modify it
  1945. * `minetest.register_craft_predict(func(itemstack, player, old_craft_grid, craft_inv))`
  1946. * The same as before, except that it is called before the player crafts, to make
  1947. craft prediction, and it should not change anything.
  1948. * `minetest.register_on_protection_violation(func(pos, name))`
  1949. * Called by `builtin` and mods when a player violates protection at a position
  1950. (eg, digs a node or punches a protected entity).
  1951. * The registered functions can be called using `minetest.record_protection_violation`
  1952. * The provided function should check that the position is protected by the mod
  1953. calling this function before it prints a message, if it does, to allow for
  1954. multiple protection mods.
  1955. * `minetest.register_on_item_eat(func(hp_change, replace_with_item, itemstack, user, pointed_thing))`
  1956. * Called when an item is eaten, by `minetest.item_eat`
  1957. * Return `true` or `itemstack` to cancel the default item eat response (i.e.: hp increase)
  1958. ### Other registration functions
  1959. * `minetest.register_chatcommand(cmd, chatcommand definition)`
  1960. * Adds definition to `minetest.registered_chatcommands`
  1961. * `minetest.override_chatcommand(name, redefinition)`
  1962. * Overrides fields of a chatcommand registered with `register_chatcommand`.
  1963. * `minetest.unregister_chatcommand(name)`
  1964. * Unregisters a chatcommands registered with `register_chatcommand`.
  1965. * `minetest.register_privilege(name, definition)`
  1966. * `definition`: `"description text"`
  1967. * `definition`: `{ description = "description text", give_to_singleplayer = boolean}`
  1968. the default of `give_to_singleplayer` is true
  1969. * To allow players with `basic_privs` to grant, see `basic_privs` minetest.conf setting.
  1970. * `minetest.register_authentication_handler(authentication handler definition)`
  1971. * Registers an auth handler that overrides the builtin one
  1972. * This function can be called by a single mod once only.
  1973. ### Setting-related
  1974. * `minetest.settings`: Settings object containing all of the settings from the
  1975. main config file (`minetest.conf`).
  1976. * `minetest.setting_get_pos(name)`: Loads a setting from the main settings and
  1977. parses it as a position (in the format `(1,2,3)`). Returns a position or nil.
  1978. ### Authentication
  1979. * `minetest.string_to_privs(str)`: returns `{priv1=true,...}`
  1980. * `minetest.privs_to_string(privs)`: returns `"priv1,priv2,..."`
  1981. * Convert between two privilege representations
  1982. * `minetest.get_player_privs(name) -> {priv1=true,...}`
  1983. * `minetest.check_player_privs(player_or_name, ...)`: returns `bool, missing_privs`
  1984. * A quickhand for checking privileges.
  1985. * `player_or_name`: Either a Player object or the name of a player.
  1986. * `...` is either a list of strings, e.g. `"priva", "privb"` or
  1987. a table, e.g. `{ priva = true, privb = true }`.
  1988. * `minetest.check_password_entry(name, entry, password)`
  1989. * Returns true if the "password entry" for a player with name matches given
  1990. password, false otherwise.
  1991. * The "password entry" is the password representation generated by the engine
  1992. as returned as part of a `get_auth()` call on the auth handler.
  1993. * Only use this function for making it possible to log in via password from
  1994. external protocols such as IRC, other uses are frowned upon.
  1995. * `minetest.get_password_hash(name, raw_password)`
  1996. * Convert a name-password pair to a password hash that Minetest can use.
  1997. * The returned value alone is not a good basis for password checks based
  1998. on comparing the password hash in the database with the password hash
  1999. from the function, with an externally provided password, as the hash
  2000. in the db might use the new SRP verifier format.
  2001. * For this purpose, use `minetest.check_password_entry` instead.
  2002. * `minetest.get_player_ip(name)`: returns an IP address string for the player `name`
  2003. * The player needs to be online for this to be successful.
  2004. * `minetest.get_auth_handler()`: Return the currently active auth handler
  2005. * See the `Authentication handler definition`
  2006. * Use this to e.g. get the authentication data for a player:
  2007. `local auth_data = minetest.get_auth_handler().get_auth(playername)`
  2008. * `minetest.notify_authentication_modified(name)`
  2009. * Must be called by the authentication handler for privilege changes.
  2010. * `name`: string; if omitted, all auth data should be considered modified
  2011. * `minetest.set_player_password(name, password_hash)`: Set password hash of player `name`
  2012. * `minetest.set_player_privs(name, {priv1=true,...})`: Set privileges of player `name`
  2013. * `minetest.auth_reload()`
  2014. * See `reload()` in authentication handler definition
  2015. `minetest.set_player_password`, `minetest_set_player_privs`, `minetest_get_player_privs`
  2016. and `minetest.auth_reload` call the authetification handler.
  2017. ### Chat
  2018. * `minetest.chat_send_all(text)`
  2019. * `minetest.chat_send_player(name, text)`
  2020. ### Environment access
  2021. * `minetest.set_node(pos, node)`
  2022. * `minetest.add_node(pos, node): alias set_node(pos, node)`
  2023. * Set node at position (`node = {name="foo", param1=0, param2=0}`)
  2024. * `minetest.swap_node(pos, node)`
  2025. * Set node at position, but don't remove metadata
  2026. * `minetest.remove_node(pos)`
  2027. * Equivalent to `set_node(pos, "air")`
  2028. * `minetest.get_node(pos)`
  2029. * Returns the node at the given position as table in the format
  2030. `{name="node_name", param1=0, param2=0}`, returns `{name="ignore", param1=0, param2=0}`
  2031. for unloaded areas.
  2032. * `minetest.get_node_or_nil(pos)`
  2033. * Same as `get_node` but returns `nil` for unloaded areas.
  2034. * `minetest.get_node_light(pos, timeofday)`
  2035. * Gets the light value at the given position. Note that the light value
  2036. "inside" the node at the given position is returned, so you usually want
  2037. to get the light value of a neighbor.
  2038. * `pos`: The position where to measure the light.
  2039. * `timeofday`: `nil` for current time, `0` for night, `0.5` for day
  2040. * Returns a number between `0` and `15` or `nil`
  2041. * `minetest.place_node(pos, node)`
  2042. * Place node with the same effects that a player would cause
  2043. * `minetest.dig_node(pos)`
  2044. * Dig node with the same effects that a player would cause
  2045. * Returns `true` if successful, `false` on failure (e.g. protected location)
  2046. * `minetest.punch_node(pos)`
  2047. * Punch node with the same effects that a player would cause
  2048. * `minetest.spawn_falling_node(pos)`
  2049. * Change node into falling node
  2050. * Returns `true` if successful, `false` on failure
  2051. * `minetest.find_nodes_with_meta(pos1, pos2)`
  2052. * Get a table of positions of nodes that have metadata within a region {pos1, pos2}
  2053. * `minetest.get_meta(pos)`
  2054. * Get a `NodeMetaRef` at that position
  2055. * `minetest.get_node_timer(pos)`
  2056. * Get `NodeTimerRef`
  2057. * `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at position
  2058. * Returns `ObjectRef`, or `nil` if failed
  2059. * `minetest.add_item(pos, item)`: Spawn item
  2060. * Returns `ObjectRef`, or `nil` if failed
  2061. * `minetest.get_player_by_name(name)`: Get an `ObjectRef` to a player
  2062. * `minetest.get_objects_inside_radius(pos, radius)`
  2063. * `radius`: using an euclidean metric
  2064. * `minetest.set_timeofday(val)`
  2065. * `val` is between `0` and `1`; `0` for midnight, `0.5` for midday
  2066. * `minetest.get_timeofday()`
  2067. * `minetest.get_gametime()`: returns the time, in seconds, since the world was created
  2068. * `minetest.get_day_count()`: returns number days elapsed since world was created,
  2069. * accounting for time changes.
  2070. * `minetest.find_node_near(pos, radius, nodenames, [search_center])`: returns pos or `nil`
  2071. * `radius`: using a maximum metric
  2072. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
  2073. * `search_center` is an optional boolean (default: `false`)
  2074. If true `pos` is also checked for the nodes
  2075. * `minetest.find_nodes_in_area(pos1, pos2, nodenames)`: returns a list of positions
  2076. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
  2077. * First return value: Table with all node positions
  2078. * Second return value: Table with the count of each node with the node name as index
  2079. * Area volume is limited to 4,096,000 nodes
  2080. * `minetest.find_nodes_in_area_under_air(pos1, pos2, nodenames)`: returns a list of positions
  2081. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
  2082. * Return value: Table with all node positions with a node air above
  2083. * Area volume is limited to 4,096,000 nodes
  2084. * `minetest.get_perlin(noiseparams)`
  2085. * `minetest.get_perlin(seeddiff, octaves, persistence, scale)`
  2086. * Return world-specific perlin noise (`int(worldseed)+seeddiff`)
  2087. * `minetest.get_voxel_manip([pos1, pos2])`
  2088. * Return voxel manipulator object.
  2089. * Loads the manipulator from the map if positions are passed.
  2090. * `minetest.set_gen_notify(flags, {deco_ids})`
  2091. * Set the types of on-generate notifications that should be collected
  2092. * `flags` is a flag field with the available flags: `dungeon`, `temple`, `cave_begin`,
  2093. `cave_end`, `large_cave_begin`, `large_cave_end`, `decoration`
  2094. * The second parameter is a list of IDS of decorations which notification is requested for
  2095. * `get_gen_notify()`: returns a flagstring and a table with the `deco_id`s
  2096. * `minetest.get_mapgen_object(objectname)`
  2097. * Return requested mapgen object if available (see "Mapgen objects")
  2098. * `minetest.get_biome_id(biome_name)`
  2099. * Returns the biome id, as used in the biomemap Mapgen object, for a
  2100. given biome_name string.
  2101. * `minetest.get_mapgen_params()` Returns mapgen parameters, a table containing
  2102. `mgname`, `seed`, `chunksize`, `water_level`, and `flags`.
  2103. * Deprecated: use `minetest.get_mapgen_setting(name)` instead
  2104. * `minetest.set_mapgen_params(MapgenParams)`
  2105. * Deprecated: use `minetest.set_mapgen_setting(name, value, override)` instead
  2106. * Set map generation parameters
  2107. * Function cannot be called after the registration period; only initialization
  2108. and `on_mapgen_init`
  2109. * Takes a table as an argument with the fields `mgname`, `seed`, `water_level`,
  2110. and `flags`.
  2111. * Leave field unset to leave that parameter unchanged
  2112. * `flags` contains a comma-delimited string of flags to set,
  2113. or if the prefix `"no"` is attached, clears instead.
  2114. * `flags` is in the same format and has the same options as `mg_flags` in `minetest.conf`
  2115. * `minetest.get_mapgen_setting(name)`
  2116. * Gets the *active* mapgen setting (or nil if none exists) in string format with the following
  2117. order of precedence:
  2118. 1) Settings loaded from map_meta.txt or overrides set during mod execution
  2119. 2) Settings set by mods without a metafile override
  2120. 3) Settings explicitly set in the user config file, minetest.conf
  2121. 4) Settings set as the user config default
  2122. * `minetest.get_mapgen_setting_noiseparams(name)`
  2123. * Same as above, but returns the value as a NoiseParams table if the setting `name` exists
  2124. and is a valid NoiseParams
  2125. * `minetest.set_mapgen_setting(name, value, [override_meta])`
  2126. * Sets a mapgen param to `value`, and will take effect if the corresponding mapgen setting
  2127. is not already present in map_meta.txt.
  2128. * `override_meta` is an optional boolean (default: `false`). If this is set to true,
  2129. the setting will become the active setting regardless of the map metafile contents.
  2130. * Note: to set the seed, use `"seed"`, not `"fixed_map_seed"`
  2131. * `minetest.set_mapgen_setting_noiseparams(name, value, [override_meta])`
  2132. * Same as above, except value is a NoiseParams table.
  2133. * `minetest.set_noiseparams(name, noiseparams, set_default)`
  2134. * Sets the noiseparams setting of `name` to the noiseparams table specified in `noiseparams`.
  2135. * `set_default` is an optional boolean (default: `true`) that specifies whether the setting
  2136. should be applied to the default config or current active config
  2137. * `minetest.get_noiseparams(name)`: returns a table of the noiseparams for name
  2138. * `minetest.generate_ores(vm, pos1, pos2)`
  2139. * Generate all registered ores within the VoxelManip `vm` and in the area from `pos1` to `pos2`.
  2140. * `pos1` and `pos2` are optional and default to mapchunk minp and maxp.
  2141. * `minetest.generate_decorations(vm, pos1, pos2)`
  2142. * Generate all registered decorations within the VoxelManip `vm` and in the area from `pos1` to `pos2`.
  2143. * `pos1` and `pos2` are optional and default to mapchunk minp and maxp.
  2144. * `minetest.clear_objects([options])`
  2145. * Clear all objects in the environment
  2146. * Takes an optional table as an argument with the field `mode`.
  2147. * mode = `"full"`: Load and go through every mapblock, clearing objects (default).
  2148. * mode = `"quick"`: Clear objects immediately in loaded mapblocks;
  2149. clear objects in unloaded mapblocks only when the mapblocks are next activated.
  2150. * `minetest.emerge_area(pos1, pos2, [callback], [param])`
  2151. * Queue all blocks in the area from `pos1` to `pos2`, inclusive, to be asynchronously
  2152. * fetched from memory, loaded from disk, or if inexistent, generates them.
  2153. * If `callback` is a valid Lua function, this will be called for each block emerged.
  2154. * The function signature of callback is:
  2155. * `function EmergeAreaCallback(blockpos, action, calls_remaining, param)`
  2156. * - `blockpos` is the *block* coordinates of the block that had been emerged
  2157. * - `action` could be one of the following constant values:
  2158. * `minetest.EMERGE_CANCELLED`, `minetest.EMERGE_ERRORED`, `minetest.EMERGE_FROM_MEMORY`,
  2159. * `minetest.EMERGE_FROM_DISK`, `minetest.EMERGE_GENERATED`
  2160. * - `calls_remaining` is the number of callbacks to be expected after this one
  2161. * - `param` is the user-defined parameter passed to emerge_area (or nil if the
  2162. * parameter was absent)
  2163. * `minetest.delete_area(pos1, pos2)`
  2164. * delete all mapblocks in the area from pos1 to pos2, inclusive
  2165. * `minetest.line_of_sight(pos1, pos2, stepsize)`: returns `boolean, pos`
  2166. * Check if there is a direct line of sight between `pos1` and `pos2`
  2167. * Returns the position of the blocking node when `false`
  2168. * `pos1`: First position
  2169. * `pos2`: Second position
  2170. * `stepsize`: smaller gives more accurate results but requires more computing
  2171. time. Default is `1`.
  2172. * `minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)`
  2173. * returns table containing path
  2174. * returns a table of 3D points representing a path from `pos1` to `pos2` or `nil`
  2175. * `pos1`: start position
  2176. * `pos2`: end position
  2177. * `searchdistance`: number of blocks to search in each direction using a maximum metric
  2178. * `max_jump`: maximum height difference to consider walkable
  2179. * `max_drop`: maximum height difference to consider droppable
  2180. * `algorithm`: One of `"A*_noprefetch"` (default), `"A*"`, `"Dijkstra"`
  2181. * `minetest.spawn_tree (pos, {treedef})`
  2182. * spawns L-system tree at given `pos` with definition in `treedef` table
  2183. * `minetest.transforming_liquid_add(pos)`
  2184. * add node to liquid update queue
  2185. * `minetest.get_node_max_level(pos)`
  2186. * get max available level for leveled node
  2187. * `minetest.get_node_level(pos)`
  2188. * get level of leveled node (water, snow)
  2189. * `minetest.set_node_level(pos, level)`
  2190. * set level of leveled node, default `level` equals `1`
  2191. * if `totallevel > maxlevel`, returns rest (`total-max`).
  2192. * `minetest.add_node_level(pos, level)`
  2193. * increase level of leveled node by level, default `level` equals `1`
  2194. * if `totallevel > maxlevel`, returns rest (`total-max`)
  2195. * can be negative for decreasing
  2196. * `minetest.fix_light(pos1, pos2)`: returns `true`/`false`
  2197. * resets the light in a cuboid-shaped part of
  2198. the map and removes lighting bugs.
  2199. * Loads the area if it is not loaded.
  2200. * `pos1` is the corner of the cuboid with the least coordinates
  2201. (in node coordinates), inclusive.
  2202. * `pos2` is the opposite corner of the cuboid, inclusive.
  2203. * The actual updated cuboid might be larger than the specified one,
  2204. because only whole map blocks can be updated.
  2205. The actual updated area consists of those map blocks that intersect
  2206. with the given cuboid.
  2207. * However, the neighborhood of the updated area might change
  2208. as well, as light can spread out of the cuboid, also light
  2209. might be removed.
  2210. * returns `false` if the area is not fully generated,
  2211. `true` otherwise
  2212. * `minetest.check_single_for_falling(pos)`
  2213. * causes an unsupported `group:falling_node` node to fall and causes an
  2214. unattached `group:attached_node` node to fall.
  2215. * does not spread these updates to neighbours.
  2216. * `minetest.check_for_falling(pos)`
  2217. * causes an unsupported `group:falling_node` node to fall and causes an
  2218. unattached `group:attached_node` node to fall.
  2219. * spread these updates to neighbours and can cause a cascade
  2220. of nodes to fall.
  2221. ### Inventory
  2222. `minetest.get_inventory(location)`: returns an `InvRef`
  2223. * `location` = e.g.
  2224. * `{type="player", name="celeron55"}`
  2225. * `{type="node", pos={x=, y=, z=}}`
  2226. * `{type="detached", name="creative"}`
  2227. * `minetest.create_detached_inventory(name, callbacks, [player_name])`: returns an `InvRef`
  2228. * callbacks: See "Detached inventory callbacks"
  2229. * `player_name`: Make detached inventory available to one player exclusively,
  2230. by default they will be sent to every player (even if not used).
  2231. Note that this parameter is mostly just a workaround and will be removed in future releases.
  2232. * Creates a detached inventory. If it already exists, it is cleared.
  2233. * `minetest.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)`:
  2234. returns left over ItemStack
  2235. * See `minetest.item_eat` and `minetest.register_on_item_eat`
  2236. ### Formspec
  2237. * `minetest.show_formspec(playername, formname, formspec)`
  2238. * `playername`: name of player to show formspec
  2239. * `formname`: name passed to `on_player_receive_fields` callbacks.
  2240. It should follow the `"modname:<whatever>"` naming convention
  2241. * `formspec`: formspec to display
  2242. * `minetest.close_formspec(playername, formname)`
  2243. * `playername`: name of player to close formspec
  2244. * `formname`: has to exactly match the one given in `show_formspec`, or the formspec will
  2245. not close.
  2246. * calling `show_formspec(playername, formname, "")` is equal to this expression
  2247. * to close a formspec regardless of the formname, call
  2248. `minetest.close_formspec(playername, "")`. **USE THIS ONLY WHEN ABSOLUTELY NECESSARY!**
  2249. * `minetest.formspec_escape(string)`: returns a string
  2250. * escapes the characters "[", "]", "\", "," and ";", which can not be used in formspecs
  2251. * `minetest.explode_table_event(string)`: returns a table
  2252. * returns e.g. `{type="CHG", row=1, column=2}`
  2253. * `type` is one of:
  2254. * `"INV"`: no row selected)
  2255. * `"CHG"`: selected)
  2256. * `"DCL"`: double-click
  2257. * `minetest.explode_textlist_event(string)`: returns a table
  2258. * returns e.g. `{type="CHG", index=1}`
  2259. * `type` is one of:
  2260. * `"INV"`: no row selected)
  2261. * `"CHG"`: selected)
  2262. * `"DCL"`: double-click
  2263. * `minetest.explode_scrollbar_event(string)`: returns a table
  2264. * returns e.g. `{type="CHG", value=500}`
  2265. * `type` is one of:
  2266. * `"INV"`: something failed
  2267. * `"CHG"`: has been changed
  2268. * `"VAL"`: not changed
  2269. ### Item handling
  2270. * `minetest.inventorycube(img1, img2, img3)`
  2271. * Returns a string for making an image of a cube (useful as an item image)
  2272. * `minetest.get_pointed_thing_position(pointed_thing, above)`
  2273. * Get position of a `pointed_thing` (that you can get from somewhere)
  2274. * `minetest.dir_to_facedir(dir, is6d)`
  2275. * Convert a vector to a facedir value, used in `param2` for `paramtype2="facedir"`;
  2276. * passing something non-`nil`/`false` for the optional second parameter causes it to
  2277. take the y component into account
  2278. * `minetest.facedir_to_dir(facedir)`
  2279. * Convert a facedir back into a vector aimed directly out the "back" of a node
  2280. * `minetest.dir_to_wallmounted(dir)`
  2281. * Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`
  2282. * `minetest.wallmounted_to_dir(wallmounted)`
  2283. * Convert a wallmounted value back into a vector aimed directly out the "back" of a node
  2284. * `minetest.dir_to_yaw(dir)`
  2285. * Convert a vector into a yaw (angle)
  2286. * `minetest.yaw_to_dir(yaw)`
  2287. * Convert yaw (angle) to a vector
  2288. * `minetest.is_colored_paramtype(ptype)`
  2289. * Returns a boolean. Returns `true` if the given `paramtype2` contains color
  2290. information (`color`, `colorwallmounted` or `colorfacedir`).
  2291. * `minetest.strip_param2_color(param2, paramtype2)`
  2292. * Removes everything but the color information from the
  2293. given `param2` value.
  2294. * Returns `nil` if the given `paramtype2` does not contain color information
  2295. * `minetest.get_node_drops(nodename, toolname)`
  2296. * Returns list of item names.
  2297. * **Note**: This will be removed or modified in a future version.
  2298. * `minetest.get_craft_result(input)`: returns `output, decremented_input`
  2299. * `input.method` = `"normal"` or `"cooking"` or `"fuel"`
  2300. * `input.width` = for example `3`
  2301. * `input.items` = for example
  2302. `{ stack1, stack2, stack3, stack4, stack 5, stack 6, stack 7, stack 8, stack 9 }`
  2303. * `output.item` = `ItemStack`, if unsuccessful: empty `ItemStack`
  2304. * `output.time` = a number, if unsuccessful: `0`
  2305. * `output.replacements` = list of `ItemStack`s that couldn't be placed in
  2306. `decremented_input.items`
  2307. * `decremented_input` = like `input`
  2308. * `minetest.get_craft_recipe(output)`: returns input
  2309. * returns last registered recipe for output item (node)
  2310. * `output` is a node or item type such as `"default:torch"`
  2311. * `input.method` = `"normal"` or `"cooking"` or `"fuel"`
  2312. * `input.width` = for example `3`
  2313. * `input.items` = for example
  2314. `{ stack1, stack2, stack3, stack4, stack 5, stack 6, stack 7, stack 8, stack 9 }`
  2315. * `input.items` = `nil` if no recipe found
  2316. * `minetest.get_all_craft_recipes(query item)`: returns a table or `nil`
  2317. * returns indexed table with all registered recipes for query item (node)
  2318. or `nil` if no recipe was found
  2319. * recipe entry table:
  2320. {
  2321. method = 'normal' or 'cooking' or 'fuel'
  2322. width = 0-3, 0 means shapeless recipe
  2323. items = indexed [1-9] table with recipe items
  2324. output = string with item name and quantity
  2325. }
  2326. * Example query for `"default:gold_ingot"` will return table:
  2327. {
  2328. [1]={method = "cooking", width = 3, output = "default:gold_ingot",
  2329. items = {1 = "default:gold_lump"}},
  2330. [2]={method = "normal", width = 1, output = "default:gold_ingot 9",
  2331. items = {1 = "default:goldblock"}}
  2332. }
  2333. * `minetest.handle_node_drops(pos, drops, digger)`
  2334. * `drops`: list of itemstrings
  2335. * Handles drops from nodes after digging: Default action is to put them into
  2336. digger's inventory
  2337. * Can be overridden to get different functionality (e.g. dropping items on
  2338. ground)
  2339. ### Rollback
  2340. * `minetest.rollback_get_node_actions(pos, range, seconds, limit)`:
  2341. returns `{{actor, pos, time, oldnode, newnode}, ...}`
  2342. * Find who has done something to a node, or near a node
  2343. * `actor`: `"player:<name>"`, also `"liquid"`.
  2344. * `minetest.rollback_revert_actions_by(actor, seconds)`: returns `boolean, log_messages`
  2345. * Revert latest actions of someone
  2346. * `actor`: `"player:<name>"`, also `"liquid"`.
  2347. ### Defaults for the `on_*` item definition functions
  2348. These functions return the leftover itemstack.
  2349. * `minetest.item_place_node(itemstack, placer, pointed_thing[, param2, prevent_after_place])`
  2350. * Place item as a node
  2351. * `param2` overrides `facedir` and wallmounted `param2`
  2352. * `prevent_after_place`: if set to `true`, `after_place_node` is not called
  2353. for the newly placed node to prevent a callback and placement loop
  2354. * returns `itemstack, success`
  2355. * `minetest.item_place_object(itemstack, placer, pointed_thing)`
  2356. * Place item as-is
  2357. * `minetest.item_place(itemstack, placer, pointed_thing, param2)`
  2358. * Use one of the above based on what the item is.
  2359. * Calls `on_rightclick` of `pointed_thing.under` if defined instead
  2360. * **Note**: is not called when wielded item overrides `on_place`
  2361. * `param2` overrides `facedir` and wallmounted `param2`
  2362. * returns `itemstack, success`
  2363. * `minetest.item_drop(itemstack, dropper, pos)`
  2364. * Drop the item
  2365. * `minetest.item_eat(hp_change, replace_with_item)`
  2366. * Eat the item.
  2367. * `replace_with_item` is the itemstring which is added to the inventory.
  2368. If the player is eating a stack, then replace_with_item goes to a
  2369. different spot. Can be `nil`
  2370. * See `minetest.do_item_eat`
  2371. ### Defaults for the `on_punch` and `on_dig` node definition callbacks
  2372. * `minetest.node_punch(pos, node, puncher, pointed_thing)`
  2373. * Calls functions registered by `minetest.register_on_punchnode()`
  2374. * `minetest.node_dig(pos, node, digger)`
  2375. * Checks if node can be dug, puts item into inventory, removes node
  2376. * Calls functions registered by `minetest.registered_on_dignodes()`
  2377. ### Sounds
  2378. * `minetest.sound_play(spec, parameters)`: returns a handle
  2379. * `spec` is a `SimpleSoundSpec`
  2380. * `parameters` is a sound parameter table
  2381. * `minetest.sound_stop(handle)`
  2382. * `minetest.sound_fade(handle, step, gain)`
  2383. * `handle` is a handle returned by `minetest.sound_play`
  2384. * `step` determines how fast a sound will fade.
  2385. Negative step will lower the sound volume, positive step will increase the sound volume
  2386. * `gain` the target gain for the fade.
  2387. ### Timing
  2388. * `minetest.after(time, func, ...)`
  2389. * Call the function `func` after `time` seconds, may be fractional
  2390. * Optional: Variable number of arguments that are passed to `func`
  2391. ### Server
  2392. * `minetest.request_shutdown([message],[reconnect],[delay])`: request for server shutdown. Will display `message` to clients,
  2393. `reconnect` == true displays a reconnect button,
  2394. `delay` adds an optional delay (in seconds) before shutdown
  2395. negative delay cancels the current active shutdown
  2396. zero delay triggers an immediate shutdown.
  2397. * `minetest.cancel_shutdown_requests()`: cancel current delayed shutdown
  2398. * `minetest.get_server_status()`: returns server status string
  2399. * `minetest.get_server_uptime()`: returns the server uptime in seconds
  2400. * `minetest.remove_player(name)`: remove player from database (if he is not connected).
  2401. * Does not remove player authentication data, minetest.player_exists will continue to return true.
  2402. * Returns a code (0: successful, 1: no such player, 2: player is connected)
  2403. ### Bans
  2404. * `minetest.get_ban_list()`: returns the ban list (same as `minetest.get_ban_description("")`)
  2405. * `minetest.get_ban_description(ip_or_name)`: returns ban description (string)
  2406. * `minetest.ban_player(name)`: ban a player
  2407. * `minetest.unban_player_or_ip(name)`: unban player or IP address
  2408. * `minetest.kick_player(name, [reason])`: disconnect a player with a optional reason
  2409. ### Particles
  2410. * `minetest.add_particle(particle definition)`
  2411. * Deprecated: `minetest.add_particle(pos, velocity, acceleration, expirationtime,
  2412. size, collisiondetection, texture, playername)`
  2413. * `minetest.add_particlespawner(particlespawner definition)`
  2414. * Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds
  2415. * Returns an `id`, and -1 if adding didn't succeed
  2416. * `Deprecated: minetest.add_particlespawner(amount, time,
  2417. minpos, maxpos,
  2418. minvel, maxvel,
  2419. minacc, maxacc,
  2420. minexptime, maxexptime,
  2421. minsize, maxsize,
  2422. collisiondetection, texture, playername)`
  2423. * `minetest.delete_particlespawner(id, player)`
  2424. * Delete `ParticleSpawner` with `id` (return value from `minetest.add_particlespawner`)
  2425. * If playername is specified, only deletes on the player's client,
  2426. * otherwise on all clients
  2427. ### Schematics
  2428. * `minetest.create_schematic(p1, p2, probability_list, filename, slice_prob_list)`
  2429. * Create a schematic from the volume of map specified by the box formed by p1 and p2.
  2430. * Apply the specified probability values to the specified nodes in `probability_list`.
  2431. * `probability_list` is an array of tables containing two fields, `pos` and `prob`.
  2432. * `pos` is the 3D vector specifying the absolute coordinates of the
  2433. node being modified,
  2434. * `prob` is the integer value from `0` to `255` of the probability (see: Schematic specifier).
  2435. * If there are two or more entries with the same pos value, the
  2436. last entry is used.
  2437. * If `pos` is not inside the box formed by `p1` and `p2`, it is ignored.
  2438. * If `probability_list` equals `nil`, no probabilities are applied.
  2439. * Slice probability works in the same manner, except takes a field
  2440. called `ypos` instead which
  2441. indicates the y position of the slice with a probability applied.
  2442. * If slice probability list equals `nil`, no slice probabilities are applied.
  2443. * Saves schematic in the Minetest Schematic format to filename.
  2444. * `minetest.place_schematic(pos, schematic, rotation, replacements, force_placement)`
  2445. * Place the schematic specified by schematic (see: Schematic specifier) at `pos`.
  2446. * `rotation` can equal `"0"`, `"90"`, `"180"`, `"270"`, or `"random"`.
  2447. * If the `rotation` parameter is omitted, the schematic is not rotated.
  2448. * `replacements` = `{["old_name"] = "convert_to", ...}`
  2449. * `force_placement` is a boolean indicating whether nodes other than `air` and
  2450. `ignore` are replaced by the schematic
  2451. * Returns nil if the schematic could not be loaded.
  2452. * `minetest.place_schematic_on_vmanip(vmanip, pos, schematic, rotation, replacement, force_placement)`:
  2453. * This function is analagous to minetest.place_schematic, but places a schematic onto the
  2454. specified VoxelManip object `vmanip` instead of the whole map.
  2455. * Returns false if any part of the schematic was cut-off due to the VoxelManip not
  2456. containing the full area required, and true if the whole schematic was able to fit.
  2457. * Returns nil if the schematic could not be loaded.
  2458. * After execution, any external copies of the VoxelManip contents are invalidated.
  2459. * `minetest.serialize_schematic(schematic, format, options)`
  2460. * Return the serialized schematic specified by schematic (see: Schematic specifier)
  2461. * in the `format` of either "mts" or "lua".
  2462. * "mts" - a string containing the binary MTS data used in the MTS file format
  2463. * "lua" - a string containing Lua code representing the schematic in table format
  2464. * `options` is a table containing the following optional parameters:
  2465. * If `lua_use_comments` is true and `format` is "lua", the Lua code generated will have (X, Z)
  2466. * position comments for every X row generated in the schematic data for easier reading.
  2467. * If `lua_num_indent_spaces` is a nonzero number and `format` is "lua", the Lua code generated
  2468. * will use that number of spaces as indentation instead of a tab character.
  2469. ### HTTP Requests:
  2470. * `minetest.request_http_api()`:
  2471. * returns `HTTPApiTable` containing http functions if the calling mod has been granted
  2472. access by being listed in the `secure.http_mods` or `secure.trusted_mods` setting,
  2473. otherwise returns `nil`.
  2474. * The returned table contains the functions `fetch`, `fetch_async` and `fetch_async_get`
  2475. described below.
  2476. * Only works at init time and must be called from the mod's main scope (not from a function).
  2477. * Function only exists if minetest server was built with cURL support.
  2478. * **DO NOT ALLOW ANY OTHER MODS TO ACCESS THE RETURNED TABLE, STORE IT IN
  2479. A LOCAL VARIABLE!**
  2480. * `HTTPApiTable.fetch(HTTPRequest req, callback)`
  2481. * Performs given request asynchronously and calls callback upon completion
  2482. * callback: `function(HTTPRequestResult res)`
  2483. * Use this HTTP function if you are unsure, the others are for advanced use.
  2484. * `HTTPApiTable.fetch_async(HTTPRequest req)`: returns handle
  2485. * Performs given request asynchronously and returns handle for `HTTPApiTable.fetch_async_get`
  2486. * `HTTPApiTable.fetch_async_get(handle)`: returns HTTPRequestResult
  2487. * Return response data for given asynchronous HTTP request
  2488. ### Storage API:
  2489. * `minetest.get_mod_storage()`:
  2490. * returns reference to mod private `StorageRef`
  2491. * must be called during mod load time
  2492. ### Misc.
  2493. * `minetest.get_connected_players()`: returns list of `ObjectRefs`
  2494. * `minetest.is_player(o)`: boolean, whether `o` is a player
  2495. * `minetest.player_exists(name)`: boolean, whether player exists (regardless of online status)
  2496. * `minetest.hud_replace_builtin(name, hud_definition)`
  2497. * Replaces definition of a builtin hud element
  2498. * `name`: `"breath"` or `"health"`
  2499. * `hud_definition`: definition to replace builtin definition
  2500. * `minetest.hash_node_position({x=,y=,z=})`: returns an 48-bit integer
  2501. * Gives a unique hash number for a node position (16+16+16=48bit)
  2502. * `minetest.get_position_from_hash(hash)`: returns a position
  2503. * Inverse transform of `minetest.hash_node_position`
  2504. * `minetest.get_item_group(name, group)`: returns a rating
  2505. * Get rating of a group of an item. (`0` means: not in group)
  2506. * `minetest.get_node_group(name, group)`: returns a rating
  2507. * Deprecated: An alias for the former.
  2508. * `minetest.raillike_group(name)`: returns a rating
  2509. * Returns rating of the connect_to_raillike group corresponding to name
  2510. * If name is not yet the name of a connect_to_raillike group, a new group id
  2511. * is created, with that name
  2512. * `minetest.get_content_id(name)`: returns an integer
  2513. * Gets the internal content ID of `name`
  2514. * `minetest.get_name_from_content_id(content_id)`: returns a string
  2515. * Gets the name of the content with that content ID
  2516. * `minetest.parse_json(string[, nullvalue])`: returns something
  2517. * Convert a string containing JSON data into the Lua equivalent
  2518. * `nullvalue`: returned in place of the JSON null; defaults to `nil`
  2519. * On success returns a table, a string, a number, a boolean or `nullvalue`
  2520. * On failure outputs an error message and returns `nil`
  2521. * Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}`
  2522. * `minetest.write_json(data[, styled])`: returns a string or `nil` and an error message
  2523. * Convert a Lua table into a JSON string
  2524. * styled: Outputs in a human-readable format if this is set, defaults to false
  2525. * Unserializable things like functions and userdata will cause an error.
  2526. * **Warning**: JSON is more strict than the Lua table format.
  2527. 1. You can only use strings and positive integers of at least one as keys.
  2528. 2. You can not mix string and integer keys.
  2529. This is due to the fact that JSON has two distinct array and object values.
  2530. * Example: `write_json({10, {a = false}})`, returns `"[10, {\"a\": false}]"`
  2531. * `minetest.serialize(table)`: returns a string
  2532. * Convert a table containing tables, strings, numbers, booleans and `nil`s
  2533. into string form readable by `minetest.deserialize`
  2534. * Example: `serialize({foo='bar'})`, returns `'return { ["foo"] = "bar" }'`
  2535. * `minetest.deserialize(string)`: returns a table
  2536. * Convert a string returned by `minetest.deserialize` into a table
  2537. * `string` is loaded in an empty sandbox environment.
  2538. * Will load functions, but they cannot access the global environment.
  2539. * Example: `deserialize('return { ["foo"] = "bar" }')`, returns `{foo='bar'}`
  2540. * Example: `deserialize('print("foo")')`, returns `nil` (function call fails)
  2541. * `error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)`
  2542. * `minetest.compress(data, method, ...)`: returns `compressed_data`
  2543. * Compress a string of data.
  2544. * `method` is a string identifying the compression method to be used.
  2545. * Supported compression methods:
  2546. * Deflate (zlib): `"deflate"`
  2547. * `...` indicates method-specific arguments. Currently defined arguments are:
  2548. * Deflate: `level` - Compression level, `0`-`9` or `nil`.
  2549. * `minetest.decompress(compressed_data, method, ...)`: returns data
  2550. * Decompress a string of data (using ZLib).
  2551. * See documentation on `minetest.compress()` for supported compression methods.
  2552. * currently supported.
  2553. * `...` indicates method-specific arguments. Currently, no methods use this.
  2554. * `minetest.encode_base64(string)`: returns string encoded in base64
  2555. * Encodes a string in base64.
  2556. * `minetest.decode_base64(string)`: returns string
  2557. * Decodes a string encoded in base64.
  2558. * `minetest.is_protected(pos, name)`: returns boolean
  2559. * Returns true, if player `name` shouldn't be abled to dig at `pos` or do other
  2560. actions, defineable by mods, due to some mod-defined ownership-like concept.
  2561. Returns false or nil, if the player is allowed to do such actions.
  2562. * `name` will be "" for non-players or unknown players.
  2563. * This function should be overridden by protection mods and should be used to
  2564. check if a player can interact at a position.
  2565. * This function should call the old version of itself if the position is not
  2566. protected by the mod.
  2567. * Example:
  2568. local old_is_protected = minetest.is_protected
  2569. function minetest.is_protected(pos, name)
  2570. if mymod:position_protected_from(pos, name) then
  2571. return true
  2572. end
  2573. return old_is_protected(pos, name)
  2574. end
  2575. * `minetest.record_protection_violation(pos, name)`
  2576. * This function calls functions registered with
  2577. `minetest.register_on_protection_violation`.
  2578. * `minetest.rotate_and_place(itemstack, placer, pointed_thing[, infinitestacks,
  2579. orient_flags, prevent_after_place])`
  2580. * Attempt to predict the desired orientation of the facedir-capable node
  2581. defined by `itemstack`, and place it accordingly (on-wall, on the floor,
  2582. or hanging from the ceiling).
  2583. * `infinitestacks`: if `true`, the itemstack is not changed. Otherwise the
  2584. stacks are handled normally.
  2585. * `orient_flags`: Optional table containing extra tweaks to the placement code:
  2586. * `invert_wall`: if `true`, place wall-orientation on the ground and
  2587. ground-orientation on the wall.
  2588. * `force_wall` : if `true`, always place the node in wall orientation.
  2589. * `force_ceiling`: if `true`, always place on the ceiling.
  2590. * `force_floor`: if `true`, always place the node on the floor.
  2591. * `force_facedir`: if `true`, forcefully reset the facedir to north
  2592. when placing on the floor or ceiling.
  2593. * The first four options are mutually-exclusive; the last in the list
  2594. takes precedence over the first.
  2595. * `prevent_after_place` is directly passed to `minetest.item_place_node`
  2596. * Returns the new itemstack after placement
  2597. * `minetest.rotate_node(itemstack, placer, pointed_thing)`
  2598. * calls `rotate_and_place()` with `infinitestacks` set according to the state
  2599. of the creative mode setting, checks for "sneak" to set the `invert_wall`
  2600. parameter and `prevent_after_place` set to `true`.
  2601. * `minetest.forceload_block(pos[, transient])`
  2602. * forceloads the position `pos`.
  2603. * returns `true` if area could be forceloaded
  2604. * If `transient` is `false` or absent, the forceload will be persistent
  2605. (saved between server runs). If `true`, the forceload will be transient
  2606. (not saved between server runs).
  2607. * `minetest.forceload_free_block(pos[, transient])`
  2608. * stops forceloading the position `pos`
  2609. * If `transient` is `false` or absent, frees a persistent forceload.
  2610. If `true`, frees a transient forceload.
  2611. * `minetest.request_insecure_environment()`: returns an environment containing
  2612. insecure functions if the calling mod has been listed as trusted in the
  2613. `secure.trusted_mods` setting or security is disabled, otherwise returns `nil`.
  2614. * Only works at init time and must be called from the mod's main scope (not from a function).
  2615. * **DO NOT ALLOW ANY OTHER MODS TO ACCESS THE RETURNED ENVIRONMENT, STORE IT IN
  2616. A LOCAL VARIABLE!**
  2617. * `minetest.global_exists(name)`
  2618. * Checks if a global variable has been set, without triggering a warning.
  2619. ### Global objects
  2620. * `minetest.env`: `EnvRef` of the server environment and world.
  2621. * Any function in the minetest namespace can be called using the syntax
  2622. `minetest.env:somefunction(somearguments)`
  2623. instead of `minetest.somefunction(somearguments)`
  2624. * Deprecated, but support is not to be dropped soon
  2625. ### Global tables
  2626. * `minetest.registered_items`
  2627. * Map of registered items, indexed by name
  2628. * `minetest.registered_nodes`
  2629. * Map of registered node definitions, indexed by name
  2630. * `minetest.registered_craftitems`
  2631. * Map of registered craft item definitions, indexed by name
  2632. * `minetest.registered_tools`
  2633. * Map of registered tool definitions, indexed by name
  2634. * `minetest.registered_entities`
  2635. * Map of registered entity prototypes, indexed by name
  2636. * `minetest.object_refs`
  2637. * Map of object references, indexed by active object id
  2638. * `minetest.luaentities`
  2639. * Map of Lua entities, indexed by active object id
  2640. * `minetest.registered_chatcommands`
  2641. * Map of registered chat command definitions, indexed by name
  2642. * `minetest.registered_ores`
  2643. * List of registered ore definitions.
  2644. * `minetest.registered_biomes`
  2645. * List of registered biome definitions.
  2646. * `minetest.registered_decorations`
  2647. * List of registered decoration definitions.
  2648. Class reference
  2649. ---------------
  2650. ### `MetaDataRef`
  2651. See `StorageRef`, `NodeMetaRef` and `ItemStackMetaRef`.
  2652. #### Methods
  2653. * `set_string(name, value)`
  2654. * `get_string(name)`
  2655. * `set_int(name, value)`
  2656. * `get_int(name)`
  2657. * `set_float(name, value)`
  2658. * `get_float(name)`
  2659. * `to_table()`: returns `nil` or a table with keys:
  2660. * `fields`: key-value storage
  2661. * `inventory`: `{list1 = {}, ...}}` (NodeMetaRef only)
  2662. * `from_table(nil or {})`
  2663. * Any non-table value will clear the metadata
  2664. * See "Node Metadata" for an example
  2665. * returns `true` on success
  2666. * `equals(other)`
  2667. * returns `true` if this metadata has the same key-value pairs as `other`
  2668. ### `NodeMetaRef`
  2669. Node metadata: reference extra data and functionality stored in a node.
  2670. Can be obtained via `minetest.get_meta(pos)`.
  2671. #### Methods
  2672. * All methods in MetaDataRef
  2673. * `get_inventory()`: returns `InvRef`
  2674. * `mark_as_private(name or {name1, name2, ...})`: Mark specific vars as private
  2675. This will prevent them from being sent to the client. Note that the "private"
  2676. status will only be remembered if an associated key-value pair exists, meaning
  2677. it's best to call this when initializing all other meta (e.g. `on_construct`).
  2678. ### `ItemStackMetaRef`
  2679. ItemStack metadata: reference extra data and functionality stored in a stack.
  2680. Can be obtained via `item:get_meta()`.
  2681. #### Methods
  2682. * All methods in MetaDataRef
  2683. ### `StorageRef`
  2684. Mod metadata: per mod metadata, saved automatically.
  2685. Can be obtained via `minetest.get_mod_storage()` during load time.
  2686. #### Methods
  2687. * All methods in MetaDataRef
  2688. ### `NodeTimerRef`
  2689. Node Timers: a high resolution persistent per-node timer.
  2690. Can be gotten via `minetest.get_node_timer(pos)`.
  2691. #### Methods
  2692. * `set(timeout,elapsed)`
  2693. * set a timer's state
  2694. * `timeout` is in seconds, and supports fractional values (0.1 etc)
  2695. * `elapsed` is in seconds, and supports fractional values (0.1 etc)
  2696. * will trigger the node's `on_timer` function after `(timeout - elapsed)` seconds
  2697. * `start(timeout)`
  2698. * start a timer
  2699. * equivalent to `set(timeout,0)`
  2700. * `stop()`
  2701. * stops the timer
  2702. * `get_timeout()`: returns current timeout in seconds
  2703. * if `timeout` equals `0`, timer is inactive
  2704. * `get_elapsed()`: returns current elapsed time in seconds
  2705. * the node's `on_timer` function will be called after `(timeout - elapsed)` seconds
  2706. * `is_started()`: returns boolean state of timer
  2707. * returns `true` if timer is started, otherwise `false`
  2708. ### `ObjectRef`
  2709. Moving things in the game are generally these.
  2710. This is basically a reference to a C++ `ServerActiveObject`
  2711. #### Methods
  2712. * `remove()`: remove object (after returning from Lua)
  2713. * Note: Doesn't work on players, use `minetest.kick_player` instead
  2714. * `get_pos()`: returns `{x=num, y=num, z=num}`
  2715. * `set_pos(pos)`; `pos`=`{x=num, y=num, z=num}`
  2716. * `move_to(pos, continuous=false)`: interpolated move
  2717. * `punch(puncher, time_from_last_punch, tool_capabilities, direction)`
  2718. * `puncher` = another `ObjectRef`,
  2719. * `time_from_last_punch` = time since last punch action of the puncher
  2720. * `direction`: can be `nil`
  2721. * `right_click(clicker)`; `clicker` is another `ObjectRef`
  2722. * `get_hp()`: returns number of hitpoints (2 * number of hearts)
  2723. * `set_hp(hp)`: set number of hitpoints (2 * number of hearts)
  2724. * `get_inventory()`: returns an `InvRef`
  2725. * `get_wield_list()`: returns the name of the inventory list the wielded item is in
  2726. * `get_wield_index()`: returns the index of the wielded item
  2727. * `get_wielded_item()`: returns an `ItemStack`
  2728. * `set_wielded_item(item)`: replaces the wielded item, returns `true` if successful
  2729. * `set_armor_groups({group1=rating, group2=rating, ...})`
  2730. * `get_armor_groups()`: returns a table with the armor group ratings
  2731. * `set_animation({x=1,y=1}, frame_speed=15, frame_blend=0, frame_loop=true)`
  2732. * `get_animation()`: returns `range`, `frame_speed`, `frame_blend` and `frame_loop`
  2733. * `set_attach(parent, bone, position, rotation)`
  2734. * `bone`: string
  2735. * `position`: `{x=num, y=num, z=num}` (relative)
  2736. * `rotation`: `{x=num, y=num, z=num}` = Rotation on each axis, in degrees
  2737. * `get_attach()`: returns parent, bone, position, rotation or nil if it isn't attached
  2738. * `set_detach()`
  2739. * `set_bone_position(bone, position, rotation)`
  2740. * `bone`: string
  2741. * `position`: `{x=num, y=num, z=num}` (relative)
  2742. * `rotation`: `{x=num, y=num, z=num}`
  2743. * `get_bone_position(bone)`: returns position and rotation of the bone
  2744. * `set_properties(object property table)`
  2745. * `get_properties()`: returns object property table
  2746. * `is_player()`: returns true for players, false otherwise
  2747. * `get_nametag_attributes()`
  2748. * returns a table with the attributes of the nametag of an object
  2749. * {
  2750. color = {a=0..255, r=0..255, g=0..255, b=0..255},
  2751. text = "",
  2752. }
  2753. * `set_nametag_attributes(attributes)`
  2754. * sets the attributes of the nametag of an object
  2755. * `attributes`:
  2756. {
  2757. color = ColorSpec,
  2758. text = "My Nametag",
  2759. }
  2760. ##### LuaEntitySAO-only (no-op for other objects)
  2761. * `set_velocity({x=num, y=num, z=num})`
  2762. * `get_velocity()`: returns `{x=num, y=num, z=num}`
  2763. * `set_acceleration({x=num, y=num, z=num})`
  2764. * `get_acceleration()`: returns `{x=num, y=num, z=num}`
  2765. * `set_yaw(radians)`
  2766. * `get_yaw()`: returns number in radians
  2767. * `set_texture_mod(mod)`
  2768. * `get_texture_mod()` returns current texture modifier
  2769. * `set_sprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
  2770. select_horiz_by_yawpitch=false)`
  2771. * Select sprite from spritesheet with optional animation and DM-style
  2772. texture selection based on yaw relative to camera
  2773. * `get_entity_name()` (**Deprecated**: Will be removed in a future version)
  2774. * `get_luaentity()`
  2775. ##### Player-only (no-op for other objects)
  2776. * `get_player_name()`: returns `""` if is not a player
  2777. * `get_player_velocity()`: returns `nil` if is not a player, otherwise a
  2778. table {x, y, z} representing the player's instantaneous velocity in nodes/s
  2779. * `get_look_dir()`: get camera direction as a unit vector
  2780. * `get_look_vertical()`: pitch in radians
  2781. * Angle ranges between -pi/2 and pi/2, which are straight up and down respectively.
  2782. * `get_look_horizontal()`: yaw in radians
  2783. * Angle is counter-clockwise from the +z direction.
  2784. * `set_look_vertical(radians)`: sets look pitch
  2785. * radians - Angle from looking forward, where positive is downwards.
  2786. * `set_look_horizontal(radians)`: sets look yaw
  2787. * radians - Angle from the +z direction, where positive is counter-clockwise.
  2788. * `get_look_pitch()`: pitch in radians - Deprecated as broken. Use `get_look_vertical`.
  2789. * Angle ranges between -pi/2 and pi/2, which are straight down and up respectively.
  2790. * `get_look_yaw()`: yaw in radians - Deprecated as broken. Use `get_look_horizontal`.
  2791. * Angle is counter-clockwise from the +x direction.
  2792. * `set_look_pitch(radians)`: sets look pitch - Deprecated. Use `set_look_vertical`.
  2793. * `set_look_yaw(radians)`: sets look yaw - Deprecated. Use `set_look_horizontal`.
  2794. * `get_breath()`: returns players breath
  2795. * `set_breath(value)`: sets players breath
  2796. * values:
  2797. * `0`: player is drowning,
  2798. * `1`-`10`: remaining number of bubbles
  2799. * `11`: bubbles bar is not shown
  2800. * `set_attribute(attribute, value)`:
  2801. * Sets an extra attribute with value on player.
  2802. * `value` must be a string, or a number which will be converted to a string.
  2803. * If `value` is `nil`, remove attribute from player.
  2804. * `get_attribute(attribute)`:
  2805. * Returns value (a string) for extra attribute.
  2806. * Returns `nil` if no attribute found.
  2807. * `set_inventory_formspec(formspec)`
  2808. * Redefine player's inventory form
  2809. * Should usually be called in `on_joinplayer`
  2810. * `get_inventory_formspec()`: returns a formspec string
  2811. * `get_player_control()`: returns table with player pressed keys
  2812. * `{jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}`
  2813. * `get_player_control_bits()`: returns integer with bit packed player pressed keys
  2814. * bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
  2815. * `set_physics_override(override_table)`
  2816. * `override_table` is a table with the following fields:
  2817. * `speed`: multiplier to default walking speed value (default: `1`)
  2818. * `jump`: multiplier to default jump value (default: `1`)
  2819. * `gravity`: multiplier to default gravity value (default: `1`)
  2820. * `sneak`: whether player can sneak (default: `true`)
  2821. * `sneak_glitch`: whether player can use the new move code replications
  2822. of the old sneak side-effects: sneak ladders and 2 node sneak jump
  2823. (default: `false`)
  2824. * `new_move`: use new move/sneak code. When `false` the exact old code
  2825. is used for the specific old sneak behaviour (default: `true`)
  2826. * `get_physics_override()`: returns the table given to `set_physics_override`
  2827. * `hud_add(hud definition)`: add a HUD element described by HUD def, returns ID
  2828. number on success
  2829. * `hud_remove(id)`: remove the HUD element of the specified id
  2830. * `hud_change(id, stat, value)`: change a value of a previously added HUD element
  2831. * element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir`
  2832. * `hud_get(id)`: gets the HUD element definition structure of the specified ID
  2833. * `hud_set_flags(flags)`: sets specified HUD flags to `true`/`false`
  2834. * `flags`: (is visible) `hotbar`, `healthbar`, `crosshair`, `wielditem`, `minimap`
  2835. * pass a table containing a `true`/`false` value of each flag to be set or unset
  2836. * if a flag equals `nil`, the flag is not modified
  2837. * note that setting `minimap` modifies the client's permission to view the minimap -
  2838. * the client may locally elect to not view the minimap
  2839. * `hud_get_flags()`: returns a table containing status of hud flags
  2840. * returns `{ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true }`
  2841. * `hud_set_hotbar_itemcount(count)`: sets number of items in builtin hotbar
  2842. * `count`: number of items, must be between `1` and `23`
  2843. * `hud_get_hotbar_itemcount`: returns number of visible items
  2844. * `hud_set_hotbar_image(texturename)`
  2845. * sets background image for hotbar
  2846. * `hud_get_hotbar_image`: returns texturename
  2847. * `hud_set_hotbar_selected_image(texturename)`
  2848. * sets image for selected item of hotbar
  2849. * `hud_get_hotbar_selected_image`: returns texturename
  2850. * `set_sky(bgcolor, type, {texture names}, clouds)`
  2851. * `bgcolor`: ColorSpec, defaults to white
  2852. * `type`: Available types:
  2853. * `"regular"`: Uses 0 textures, `bgcolor` ignored
  2854. * `"skybox"`: Uses 6 textures, `bgcolor` used
  2855. * `"plain"`: Uses 0 textures, `bgcolor` used
  2856. * `clouds`: Boolean for whether clouds appear in front of `"skybox"` or
  2857. `"plain"` custom skyboxes (default: `true`)
  2858. * `get_sky()`: returns bgcolor, type, table of textures, clouds
  2859. * `set_clouds(parameters)`: set cloud parameters
  2860. * `parameters` is a table with the following optional fields:
  2861. * `density`: from `0` (no clouds) to `1` (full clouds) (default `0.4`)
  2862. * `color`: basic cloud color, with alpha channel (default `#fff0f0e5`)
  2863. * `ambient`: cloud color lower bound, use for a "glow at night" effect (default `#000000`)
  2864. * `height`: cloud height, i.e. y of cloud base (default per conf, usually `120`)
  2865. * `thickness`: cloud thickness in nodes (default `16`)
  2866. * `speed`: 2D cloud speed + direction in nodes per second (default `{x=0, y=-2}`)
  2867. * `get_clouds()`: returns a table with the current cloud parameters as in `set_clouds`
  2868. * `override_day_night_ratio(ratio or nil)`
  2869. * `0`...`1`: Overrides day-night ratio, controlling sunlight to a specific amount
  2870. * `nil`: Disables override, defaulting to sunlight based on day-night cycle
  2871. * `get_day_night_ratio()`: returns the ratio or nil if it isn't overridden
  2872. * `set_local_animation(stand/idle, walk, dig, walk+dig, frame_speed=frame_speed)`
  2873. set animation for player model in third person view
  2874. set_local_animation({x=0, y=79}, -- < stand/idle animation key frames
  2875. {x=168, y=187}, -- < walk animation key frames
  2876. {x=189, y=198}, -- < dig animation key frames
  2877. {x=200, y=219}, -- < walk+dig animation key frames
  2878. frame_speed=30): -- < animation frame speed
  2879. * `get_local_animation()`: returns stand, walk, dig, dig+walk tables and `frame_speed`
  2880. * `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
  2881. * in first person view
  2882. * in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
  2883. * `get_eye_offset()`: returns `offset_first` and `offset_third`
  2884. ### `InvRef`
  2885. An `InvRef` is a reference to an inventory.
  2886. #### Methods
  2887. * `is_empty(listname)`: return `true` if list is empty
  2888. * `get_size(listname)`: get size of a list
  2889. * `set_size(listname, size)`: set size of a list
  2890. * returns `false` on error (e.g. invalid `listname` or `size`)
  2891. * `get_width(listname)`: get width of a list
  2892. * `set_width(listname, width)`: set width of list; currently used for crafting
  2893. * `get_stack(listname, i)`: get a copy of stack index `i` in list
  2894. * `set_stack(listname, i, stack)`: copy `stack` to index `i` in list
  2895. * `get_list(listname)`: return full list
  2896. * `set_list(listname, list)`: set full list (size will not change)
  2897. * `get_lists()`: returns list of inventory lists
  2898. * `set_lists(lists)`: sets inventory lists (size will not change)
  2899. * `add_item(listname, stack)`: add item somewhere in list, returns leftover `ItemStack`
  2900. * `room_for_item(listname, stack):` returns `true` if the stack of items
  2901. can be fully added to the list
  2902. * `contains_item(listname, stack, [match_meta])`: returns `true` if
  2903. the stack of items can be fully taken from the list.
  2904. If `match_meta` is false, only the items' names are compared (default: `false`).
  2905. * `remove_item(listname, stack)`: take as many items as specified from the list,
  2906. returns the items that were actually removed (as an `ItemStack`) -- note that
  2907. any item metadata is ignored, so attempting to remove a specific unique
  2908. item this way will likely remove the wrong one -- to do that use `set_stack`
  2909. with an empty `ItemStack`
  2910. * `get_location()`: returns a location compatible to `minetest.get_inventory(location)`
  2911. * returns `{type="undefined"}` in case location is not known
  2912. ### `AreaStore`
  2913. A fast access data structure to store areas, and find areas near a given position or area.
  2914. Every area has a `data` string attribute to store additional information.
  2915. You can create an empty `AreaStore` by calling `AreaStore()`, or `AreaStore(type_name)`.
  2916. If you chose the parameter-less constructor, a fast implementation will be automatically
  2917. chosen for you.
  2918. #### Methods
  2919. * `get_area(id, include_borders, include_data)`: returns the area with the id `id`.
  2920. (optional) Boolean values `include_borders` and `include_data` control what's copied.
  2921. Returns nil if specified area id does not exist.
  2922. * `get_areas_for_pos(pos, include_borders, include_data)`: returns all areas that contain
  2923. the position `pos`. (optional) Boolean values `include_borders` and `include_data` control
  2924. what's copied.
  2925. * `get_areas_in_area(edge1, edge2, accept_overlap, include_borders, include_data)`:
  2926. returns all areas that contain all nodes inside the area specified by `edge1` and `edge2` (inclusive).
  2927. If `accept_overlap` is true, also areas are returned that have nodes in common with the specified area.
  2928. (optional) Boolean values `include_borders` and `include_data` control what's copied.
  2929. * `insert_area(edge1, edge2, data, [id])`: inserts an area into the store. Returns the new area's ID,
  2930. or nil if the insertion failed. The (inclusive) positions `edge1` and `edge2` describe the area.
  2931. `data` is a string stored with the area. If passed, `id` will be used as the internal area ID,
  2932. it must be a unique number between 0 and 2^32-2. If you use the `id` parameter you must always use it,
  2933. or insertions are likely to fail due to conflicts.
  2934. * `reserve(count)`: reserves resources for at most `count` many contained areas.
  2935. Only needed for efficiency, and only some implementations profit.
  2936. * `remove_area(id)`: removes the area with the given id from the store, returns success.
  2937. * `set_cache_params(params)`: sets params for the included prefiltering cache.
  2938. Calling invalidates the cache, so that its elements have to be newly generated.
  2939. * `params`:
  2940. {
  2941. enabled = boolean, -- whether to enable, default true
  2942. block_radius = number, -- the radius (in nodes) of the areas the cache generates
  2943. prefiltered lists for, minimum 16, default 64
  2944. limit = number, -- the cache's size, minimum 20, default 1000
  2945. }
  2946. * `to_string()`: Experimental. Returns area store serialized as a (binary) string.
  2947. * `to_file(filename)`: Experimental. Like `to_string()`, but writes the data to a file.
  2948. * `from_string(str)`: Experimental. Deserializes string and loads it into the AreaStore.
  2949. Returns success and, optionally, an error message.
  2950. * `from_file(filename)`: Experimental. Like `from_string()`, but reads the data from a file.
  2951. ### `ItemStack`
  2952. An `ItemStack` is a stack of items.
  2953. It can be created via `ItemStack(x)`, where x is an `ItemStack`,
  2954. an itemstring, a table or `nil`.
  2955. #### Methods
  2956. * `is_empty()`: Returns `true` if stack is empty.
  2957. * `get_name()`: Returns item name (e.g. `"default:stone"`).
  2958. * `set_name(item_name)`: Returns boolean whether item was cleared
  2959. * `get_count()`: Returns number of items on the stack.
  2960. * `set_count(count)`: Returns boolean whether item was cleared
  2961. * `get_wear()`: Returns tool wear (`0`-`65535`), `0` for non-tools.
  2962. * `set_wear(wear)`: Returns boolean whether item was cleared
  2963. * `get_meta()`: Returns ItemStackMetaRef. See section for more details
  2964. * `get_metadata()`: (DEPRECATED) Returns metadata (a string attached to an item stack).
  2965. * `set_metadata(metadata)`: (DEPRECATED) Returns true.
  2966. * `clear()`: removes all items from the stack, making it empty.
  2967. * `replace(item)`: replace the contents of this stack.
  2968. * `item` can also be an itemstring or table.
  2969. * `to_string()`: Returns the stack in itemstring form.
  2970. * `to_table()`: Returns the stack in Lua table form.
  2971. * `get_stack_max()`: Returns the maximum size of the stack (depends on the item).
  2972. * `get_free_space()`: Returns `get_stack_max() - get_count()`.
  2973. * `is_known()`: Returns `true` if the item name refers to a defined item type.
  2974. * `get_definition()`: Returns the item definition table.
  2975. * `get_tool_capabilities()`: Returns the digging properties of the item,
  2976. or those of the hand if none are defined for this item type
  2977. * `add_wear(amount)`: Increases wear by `amount` if the item is a tool.
  2978. * `add_item(item)`: Put some item or stack onto this stack.
  2979. Returns leftover `ItemStack`.
  2980. * `item_fits(item)`: Returns `true` if item or stack can be fully added to
  2981. this one.
  2982. * `take_item(n=1)`: Take (and remove) up to `n` items from this stack.
  2983. Returns taken `ItemStack`.
  2984. * `peek_item(n=1)`: copy (don't remove) up to `n` items from this stack.
  2985. Returns taken `ItemStack`.
  2986. ### `PseudoRandom`
  2987. A 16-bit pseudorandom number generator.
  2988. Uses a well-known LCG algorithm introduced by K&R.
  2989. It can be created via `PseudoRandom(seed)`.
  2990. #### Methods
  2991. * `next()`: return next integer random number [`0`...`32767`]
  2992. * `next(min, max)`: return next integer random number [`min`...`max`]
  2993. * `((max - min) == 32767) or ((max-min) <= 6553))` must be true
  2994. due to the simple implementation making bad distribution otherwise.
  2995. ### `PcgRandom`
  2996. A 32-bit pseudorandom number generator.
  2997. Uses PCG32, an algorithm of the permuted congruential generator family, offering very strong randomness.
  2998. It can be created via `PcgRandom(seed)` or `PcgRandom(seed, sequence)`.
  2999. #### Methods
  3000. * `next()`: return next integer random number [`-2147483648`...`2147483647`]
  3001. * `next(min, max)`: return next integer random number [`min`...`max`]
  3002. * `rand_normal_dist(min, max, num_trials=6)`: return normally distributed random number [`min`...`max`]
  3003. * This is only a rough approximation of a normal distribution with:
  3004. * `mean = (max - min) / 2`, and
  3005. * `variance = (((max - min + 1) ^ 2) - 1) / (12 * num_trials)`
  3006. * Increasing `num_trials` improves accuracy of the approximation
  3007. ### `SecureRandom`
  3008. Interface for the operating system's crypto-secure PRNG.
  3009. It can be created via `SecureRandom()`. The constructor returns nil if a secure random device cannot be
  3010. be found on the system.
  3011. #### Methods
  3012. * `next_bytes([count])`: return next `count` (default 1, capped at 2048) many random bytes, as a string.
  3013. ### `PerlinNoise`
  3014. A perlin noise generator.
  3015. It can be created via `PerlinNoise(seed, octaves, persistence, scale)`
  3016. or `PerlinNoise(noiseparams)`.
  3017. Alternatively with `minetest.get_perlin(seeddiff, octaves, persistence, scale)`
  3018. or `minetest.get_perlin(noiseparams)`.
  3019. #### Methods
  3020. * `get2d(pos)`: returns 2D noise value at `pos={x=,y=}`
  3021. * `get3d(pos)`: returns 3D noise value at `pos={x=,y=,z=}`
  3022. ### `PerlinNoiseMap`
  3023. A fast, bulk perlin noise generator.
  3024. It can be created via `PerlinNoiseMap(noiseparams, size)` or
  3025. `minetest.get_perlin_map(noiseparams, size)`.
  3026. Format of `size` is `{x=dimx, y=dimy, z=dimz}`. The `z` conponent is ommitted
  3027. for 2D noise, and it must be must be larger than 1 for 3D noise (otherwise
  3028. `nil` is returned).
  3029. For each of the functions with an optional `buffer` parameter: If `buffer` is not
  3030. nil, this table will be used to store the result instead of creating a new table.
  3031. #### Methods
  3032. * `get2dMap(pos)`: returns a `<size.x>` times `<size.y>` 2D array of 2D noise
  3033. with values starting at `pos={x=,y=}`
  3034. * `get3dMap(pos)`: returns a `<size.x>` times `<size.y>` times `<size.z>` 3D array
  3035. of 3D noise with values starting at `pos={x=,y=,z=}`
  3036. * `get2dMap_flat(pos, buffer)`: returns a flat `<size.x * size.y>` element array of 2D noise
  3037. with values starting at `pos={x=,y=}`
  3038. * `get3dMap_flat(pos, buffer)`: Same as `get2dMap_flat`, but 3D noise
  3039. * `calc2dMap(pos)`: Calculates the 2d noise map starting at `pos`. The result is stored internally.
  3040. * `calc3dMap(pos)`: Calculates the 3d noise map starting at `pos`. The result is stored internally.
  3041. * `getMapSlice(slice_offset, slice_size, buffer)`: In the form of an array, returns a slice of the
  3042. most recently computed noise results. The result slice begins at coordinates `slice_offset` and
  3043. takes a chunk of `slice_size`.
  3044. E.g. to grab a 2-slice high horizontal 2d plane of noise starting at buffer offset y = 20:
  3045. `noisevals = noise:getMapSlice({y=20}, {y=2})`
  3046. It is important to note that `slice_offset` offset coordinates begin at 1, and are relative to
  3047. the starting position of the most recently calculated noise.
  3048. To grab a single vertical column of noise starting at map coordinates x = 1023, y=1000, z = 1000:
  3049. `noise:calc3dMap({x=1000, y=1000, z=1000})`
  3050. `noisevals = noise:getMapSlice({x=24, z=1}, {x=1, z=1})`
  3051. ### `VoxelManip`
  3052. #### About VoxelManip
  3053. VoxelManip is a scripting interface to the internal 'Map Voxel Manipulator' facility. The purpose of
  3054. this object is for fast, low-level, bulk access to reading and writing Map content. As such, setting
  3055. map nodes through VoxelManip will lack many of the higher level features and concepts you may be used
  3056. to with other methods of setting nodes. For example, nodes will not have their construction and
  3057. destruction callbacks run, and no rollback information is logged.
  3058. It is important to note that VoxelManip is designed for speed, and *not* ease of use or flexibility.
  3059. If your mod requires a map manipulation facility that will handle 100% of all edge cases, or the use
  3060. of high level node placement features, perhaps `minetest.set_node()` is better suited for the job.
  3061. In addition, VoxelManip might not be faster, or could even be slower, for your specific use case.
  3062. VoxelManip is most effective when setting very large areas of map at once - for example, if only
  3063. setting a 5x5x5 node area, a `minetest.set_node()` loop may be more optimal. Always profile code
  3064. using both methods of map manipulation to determine which is most appropriate for your usage.
  3065. #### Using VoxelManip
  3066. A VoxelManip object can be created any time using either:
  3067. `VoxelManip([p1, p2])`, or `minetest.get_voxel_manip([p1, p2])`.
  3068. If the optional position parameters are present for either of these routines, the specified region
  3069. will be pre-loaded into the VoxelManip object on creation. Otherwise, the area of map you wish to
  3070. manipulate must first be loaded into the VoxelManip object using `VoxelManip:read_from_map()`.
  3071. Note that `VoxelManip:read_from_map()` returns two position vectors. The region formed by these
  3072. positions indicate the minimum and maximum (respectively) positions of the area actually loaded in
  3073. the VoxelManip, which may be larger than the area requested. For convenience, the loaded area
  3074. coordinates can also be queried any time after loading map data with `VoxelManip:get_emerged_area()`.
  3075. Now that the VoxelManip object is populated with map data, your mod can fetch a copy of this data
  3076. using either of two methods. `VoxelManip:get_node_at()`, which retrieves an individual node in a
  3077. MapNode formatted table at the position requested is the simplest method to use, but also the slowest.
  3078. Nodes in a VoxelManip object may also be read in bulk to a flat array table using:
  3079. `VoxelManip:get_data()` for node content (in Content ID form, see section 'Content IDs'),
  3080. `VoxelManip:get_light_data()` for node light levels, and
  3081. `VoxelManip:get_param2_data()` for the node type-dependent "param2" values.
  3082. See section 'Flat array format' for more details.
  3083. It is very important to understand that the tables returned by any of the above three functions
  3084. represent a snapshot of the VoxelManip's internal state at the time of the call. This copy of the
  3085. data will *not* magically update itself if another function modifies the internal VoxelManip state.
  3086. Any functions that modify a VoxelManip's contents work on the VoxelManip's internal state unless
  3087. otherwise explicitly stated.
  3088. Once the bulk data has been edited to your liking, the internal VoxelManip state can be set using:
  3089. `VoxelManip:set_data()` for node content (in Content ID form, see section 'Content IDs'),
  3090. `VoxelManip:set_light_data()` for node light levels, and
  3091. `VoxelManip:set_param2_data()` for the node type-dependent `param2` values.
  3092. The parameter to each of the above three functions can use any table at all in the same flat array
  3093. format as produced by `get_data()` et al. and is *not required* to be a table retrieved from `get_data()`.
  3094. Once the internal VoxelManip state has been modified to your liking, the changes can be committed back
  3095. to the map by calling `VoxelManip:write_to_map()`.
  3096. ##### Flat array format
  3097. Let
  3098. `Nx = p2.X - p1.X + 1`,
  3099. `Ny = p2.Y - p1.Y + 1`, and
  3100. `Nz = p2.Z - p1.Z + 1`.
  3101. Then, for a loaded region of p1..p2, this array ranges from `1` up to and including the value of
  3102. the expression `Nx * Ny * Nz`.
  3103. Positions offset from p1 are present in the array with the format of:
  3104. ```
  3105. [
  3106. (0, 0, 0), (1, 0, 0), (2, 0, 0), ... (Nx, 0, 0),
  3107. (0, 1, 0), (1, 1, 0), (2, 1, 0), ... (Nx, 1, 0),
  3108. ...
  3109. (0, Ny, 0), (1, Ny, 0), (2, Ny, 0), ... (Nx, Ny, 0),
  3110. (0, 0, 1), (1, 0, 1), (2, 0, 1), ... (Nx, 0, 1),
  3111. ...
  3112. (0, Ny, 2), (1, Ny, 2), (2, Ny, 2), ... (Nx, Ny, 2),
  3113. ...
  3114. (0, Ny, Nz), (1, Ny, Nz), (2, Ny, Nz), ... (Nx, Ny, Nz)
  3115. ]
  3116. ```
  3117. and the array index for a position p contained completely in p1..p2 is:
  3118. `(p.Z - p1.Z) * Ny * Nx + (p.Y - p1.Y) * Nx + (p.X - p1.X) + 1`
  3119. Note that this is the same "flat 3D array" format as `PerlinNoiseMap:get3dMap_flat()`.
  3120. VoxelArea objects (see section 'VoxelArea') can be used to simplify calculation of the index
  3121. for a single point in a flat VoxelManip array.
  3122. ##### Content IDs
  3123. A Content ID is a unique integer identifier for a specific node type. These IDs are used by VoxelManip
  3124. in place of the node name string for `VoxelManip:get_data()` and `VoxelManip:set_data()`. You can use
  3125. `minetest.get_content_id()` to look up the Content ID for the specified node name, and
  3126. `minetest.get_name_from_content_id()` to look up the node name string for a given Content ID.
  3127. After registration of a node, its Content ID will remain the same throughout execution of the mod.
  3128. Note that the node being queried needs to have already been been registered.
  3129. The following builtin node types have their Content IDs defined as constants:
  3130. * `minetest.CONTENT_UNKNOWN`: ID for "unknown" nodes
  3131. * `minetest.CONTENT_AIR`: ID for "air" nodes
  3132. * `minetest.CONTENT_IGNORE`: ID for "ignore" nodes
  3133. ##### Mapgen VoxelManip objects
  3134. Inside of `on_generated()` callbacks, it is possible to retrieve the same VoxelManip object used by the
  3135. core's Map Generator (commonly abbreviated Mapgen). Most of the rules previously described still apply
  3136. but with a few differences:
  3137. * The Mapgen VoxelManip object is retrieved using: `minetest.get_mapgen_object("voxelmanip")`
  3138. * This VoxelManip object already has the region of map just generated loaded into it; it's not necessary
  3139. to call `VoxelManip:read_from_map()` before using a Mapgen VoxelManip.
  3140. * The `on_generated()` callbacks of some mods may place individual nodes in the generated area using
  3141. non-VoxelManip map modification methods. Because the same Mapgen VoxelManip object is passed through
  3142. each `on_generated()` callback, it becomes necessary for the Mapgen VoxelManip object to maintain
  3143. consistency with the current map state. For this reason, calling any of the following functions:
  3144. `minetest.add_node()`, `minetest.set_node()`, or `minetest.swap_node()`
  3145. will also update the Mapgen VoxelManip object's internal state active on the current thread.
  3146. * After modifying the Mapgen VoxelManip object's internal buffer, it may be necessary to update lighting
  3147. information using either: `VoxelManip:calc_lighting()` or `VoxelManip:set_lighting()`.
  3148. ##### Other API functions operating on a VoxelManip
  3149. If any VoxelManip contents were set to a liquid node, `VoxelManip:update_liquids()` must be called
  3150. for these liquid nodes to begin flowing. It is recommended to call this function only after having
  3151. written all buffered data back to the VoxelManip object, save for special situations where the modder
  3152. desires to only have certain liquid nodes begin flowing.
  3153. The functions `minetest.generate_ores()` and `minetest.generate_decorations()` will generate all
  3154. registered decorations and ores throughout the full area inside of the specified VoxelManip object.
  3155. `minetest.place_schematic_on_vmanip()` is otherwise identical to `minetest.place_schematic()`,
  3156. except instead of placing the specified schematic directly on the map at the specified position, it
  3157. will place the schematic inside of the VoxelManip.
  3158. ##### Notes
  3159. * Attempting to read data from a VoxelManip object before map is read will result in a zero-length
  3160. array table for `VoxelManip:get_data()`, and an "ignore" node at any position for
  3161. `VoxelManip:get_node_at()`.
  3162. * If either a region of map has not yet been generated or is out-of-bounds of the map, that region is
  3163. filled with "ignore" nodes.
  3164. * Other mods, or the core itself, could possibly modify the area of map currently loaded into a VoxelManip
  3165. object. With the exception of Mapgen VoxelManips (see above section), the internal buffers are not
  3166. updated. For this reason, it is strongly encouraged to complete the usage of a particular VoxelManip
  3167. object in the same callback it had been created.
  3168. * If a VoxelManip object will be used often, such as in an `on_generated()` callback, consider passing
  3169. a file-scoped table as the optional parameter to `VoxelManip:get_data()`, which serves as a static
  3170. buffer the function can use to write map data to instead of returning a new table each call. This
  3171. greatly enhances performance by avoiding unnecessary memory allocations.
  3172. #### Methods
  3173. * `read_from_map(p1, p2)`: Loads a chunk of map into the VoxelManip object containing
  3174. the region formed by `p1` and `p2`.
  3175. * returns actual emerged `pmin`, actual emerged `pmax`
  3176. * `write_to_map([light])`: Writes the data loaded from the `VoxelManip` back to the map.
  3177. * **important**: data must be set using `VoxelManip:set_data()` before calling this
  3178. * if `light` is true, then lighting is automatically recalculated.
  3179. The default value is true.
  3180. If `light` is false, no light calculations happen, and you should correct
  3181. all modified blocks with `minetest.fix_light()` as soon as possible.
  3182. Keep in mind that modifying the map where light is incorrect can cause
  3183. more lighting bugs.
  3184. * `get_node_at(pos)`: Returns a `MapNode` table of the node currently loaded in
  3185. the `VoxelManip` at that position
  3186. * `set_node_at(pos, node)`: Sets a specific `MapNode` in the `VoxelManip` at that position
  3187. * `get_data([buffer])`: Retrieves the node content data loaded into the `VoxelManip` object
  3188. * returns raw node data in the form of an array of node content IDs
  3189. * if the param `buffer` is present, this table will be used to store the result instead
  3190. * `set_data(data)`: Sets the data contents of the `VoxelManip` object
  3191. * `update_map()`: Does nothing, kept for compatibility.
  3192. * `set_lighting(light, [p1, p2])`: Set the lighting within the `VoxelManip` to a uniform value
  3193. * `light` is a table, `{day=<0...15>, night=<0...15>}`
  3194. * To be used only by a `VoxelManip` object from `minetest.get_mapgen_object`
  3195. * (`p1`, `p2`) is the area in which lighting is set;
  3196. defaults to the whole area if left out
  3197. * `get_light_data()`: Gets the light data read into the `VoxelManip` object
  3198. * Returns an array (indices 1 to volume) of integers ranging from `0` to `255`
  3199. * Each value is the bitwise combination of day and night light values (`0` to `15` each)
  3200. * `light = day + (night * 16)`
  3201. * `set_light_data(light_data)`: Sets the `param1` (light) contents of each node
  3202. in the `VoxelManip`
  3203. * expects lighting data in the same format that `get_light_data()` returns
  3204. * `get_param2_data([buffer])`: Gets the raw `param2` data read into the `VoxelManip` object
  3205. * Returns an array (indices 1 to volume) of integers ranging from `0` to `255`
  3206. * If the param `buffer` is present, this table will be used to store the result instead
  3207. * `set_param2_data(param2_data)`: Sets the `param2` contents of each node in the `VoxelManip`
  3208. * `calc_lighting([p1, p2], [propagate_shadow])`: Calculate lighting within the `VoxelManip`
  3209. * To be used only by a `VoxelManip` object from `minetest.get_mapgen_object`
  3210. * (`p1`, `p2`) is the area in which lighting is set; defaults to the whole area
  3211. if left out or nil
  3212. * `propagate_shadow` is an optional boolean deciding whether shadows in a generated
  3213. mapchunk above are propagated down into the mapchunk; defaults to `true` if left out
  3214. * `update_liquids()`: Update liquid flow
  3215. * `was_modified()`: Returns `true` or `false` if the data in the voxel manipulator
  3216. had been modified since the last read from map, due to a call to
  3217. `minetest.set_data()` on the loaded area elsewhere
  3218. * `get_emerged_area()`: Returns actual emerged minimum and maximum positions.
  3219. ### `VoxelArea`
  3220. A helper class for voxel areas.
  3221. It can be created via `VoxelArea:new{MinEdge=pmin, MaxEdge=pmax}`.
  3222. The coordinates are *inclusive*, like most other things in Minetest.
  3223. #### Methods
  3224. * `getExtent()`: returns a 3D vector containing the size of the area formed by
  3225. `MinEdge` and `MaxEdge`
  3226. * `getVolume()`: returns the volume of the area formed by `MinEdge` and `MaxEdge`
  3227. * `index(x, y, z)`: returns the index of an absolute position in a flat array starting at `1`
  3228. * useful for things like `VoxelManip`, raw Schematic specifiers,
  3229. `PerlinNoiseMap:get2d`/`3dMap`, and so on
  3230. * `indexp(p)`: same as above, except takes a vector
  3231. * `position(i)`: returns the absolute position vector corresponding to index `i`
  3232. * `contains(x, y, z)`: check if (`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`
  3233. * `containsp(p)`: same as above, except takes a vector
  3234. * `containsi(i)`: same as above, except takes an index `i`
  3235. * `iter(minx, miny, minz, maxx, maxy, maxz)`: returns an iterator that returns indices
  3236. * from (`minx`,`miny`,`minz`) to (`maxx`,`maxy`,`maxz`) in the order of `[z [y [x]]]`
  3237. * `iterp(minp, maxp)`: same as above, except takes a vector
  3238. ### `Settings`
  3239. An interface to read config files in the format of `minetest.conf`.
  3240. It can be created via `Settings(filename)`.
  3241. #### Methods
  3242. * `get(key)`: returns a value
  3243. * `get_bool(key)`: returns a boolean
  3244. * `set(key, value)`
  3245. * Setting names can't contain whitespace or any of `="{}#`.
  3246. * Setting values can't contain the sequence `\n"""`.
  3247. * Setting names starting with "secure." can't be set on the main settings object (`minetest.settings`).
  3248. * `set_bool(key, value)`
  3249. * See documentation for set() above.
  3250. * `remove(key)`: returns a boolean (`true` for success)
  3251. * `get_names()`: returns `{key1,...}`
  3252. * `write()`: returns a boolean (`true` for success)
  3253. * Writes changes to file.
  3254. * `to_table()`: returns `{[key1]=value1,...}`
  3255. Mapgen objects
  3256. --------------
  3257. A mapgen object is a construct used in map generation. Mapgen objects can be used
  3258. by an `on_generate` callback to speed up operations by avoiding unnecessary
  3259. recalculations; these can be retrieved using the `minetest.get_mapgen_object()`
  3260. function. If the requested Mapgen object is unavailable, or `get_mapgen_object()`
  3261. was called outside of an `on_generate()` callback, `nil` is returned.
  3262. The following Mapgen objects are currently available:
  3263. ### `voxelmanip`
  3264. This returns three values; the `VoxelManip` object to be used, minimum and maximum
  3265. emerged position, in that order. All mapgens support this object.
  3266. ### `heightmap`
  3267. Returns an array containing the y coordinates of the ground levels of nodes in
  3268. the most recently generated chunk by the current mapgen.
  3269. ### `biomemap`
  3270. Returns an array containing the biome IDs of nodes in the most recently
  3271. generated chunk by the current mapgen.
  3272. ### `heatmap`
  3273. Returns an array containing the temperature values of nodes in the most
  3274. recently generated chunk by the current mapgen.
  3275. ### `humiditymap`
  3276. Returns an array containing the humidity values of nodes in the most recently
  3277. generated chunk by the current mapgen.
  3278. ### `gennotify`
  3279. Returns a table mapping requested generation notification types to arrays of
  3280. positions at which the corresponding generated structures are located at within
  3281. the current chunk. To set the capture of positions of interest to be recorded
  3282. on generate, use `minetest.set_gen_notify()`.
  3283. Possible fields of the table returned are:
  3284. * `dungeon`
  3285. * `temple`
  3286. * `cave_begin`
  3287. * `cave_end`
  3288. * `large_cave_begin`
  3289. * `large_cave_end`
  3290. * `decoration`
  3291. Decorations have a key in the format of `"decoration#id"`, where `id` is the
  3292. numeric unique decoration ID.
  3293. Registered entities
  3294. -------------------
  3295. * Functions receive a "luaentity" as `self`:
  3296. * It has the member `.name`, which is the registered name `("mod:thing")`
  3297. * It has the member `.object`, which is an `ObjectRef` pointing to the object
  3298. * The original prototype stuff is visible directly via a metatable
  3299. * Callbacks:
  3300. * `on_activate(self, staticdata, dtime_s)`
  3301. * Called when the object is instantiated.
  3302. * `dtime_s` is the time passed since the object was unloaded, which can
  3303. be used for updating the entity state.
  3304. * `on_step(self, dtime)`
  3305. * Called on every server tick, after movement and collision processing.
  3306. `dtime` is usually 0.1 seconds, as per the `dedicated_server_step` setting
  3307. `in minetest.conf`.
  3308. * `on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)`
  3309. * Called when somebody punches the object.
  3310. * Note that you probably want to handle most punches using the
  3311. automatic armor group system.
  3312. * `puncher`: an `ObjectRef` (can be `nil`)
  3313. * `time_from_last_punch`: Meant for disallowing spamming of clicks (can be `nil`)
  3314. * `tool_capabilities`: capability table of used tool (can be `nil`)
  3315. * `dir`: unit vector of direction of punch. Always defined. Points from
  3316. the puncher to the punched.
  3317. * `on_rightclick(self, clicker)`
  3318. * `get_staticdata(self)`
  3319. * Should return a string that will be passed to `on_activate` when
  3320. the object is instantiated the next time.
  3321. L-system trees
  3322. --------------
  3323. **Warning**
  3324. L-system generation currently creates lighting bugs in the form of mapblock-sized shadows.
  3325. Often these bugs appear as subtle shadows in water.
  3326. ### Tree definition
  3327. treedef={
  3328. axiom, --string initial tree axiom
  3329. rules_a, --string rules set A
  3330. rules_b, --string rules set B
  3331. rules_c, --string rules set C
  3332. rules_d, --string rules set D
  3333. trunk, --string trunk node name
  3334. leaves, --string leaves node name
  3335. leaves2, --string secondary leaves node name
  3336. leaves2_chance,--num chance (0-100) to replace leaves with leaves2
  3337. angle, --num angle in deg
  3338. iterations, --num max # of iterations, usually 2 -5
  3339. random_level, --num factor to lower nr of iterations, usually 0 - 3
  3340. trunk_type, --string single/double/crossed) type of trunk: 1 node,
  3341. -- 2x2 nodes or 3x3 in cross shape
  3342. thin_branches, --boolean true -> use thin (1 node) branches
  3343. fruit, --string fruit node name
  3344. fruit_chance, --num chance (0-100) to replace leaves with fruit node
  3345. seed, --num random seed; if no seed is provided, the engine will create one
  3346. }
  3347. ### Key for Special L-System Symbols used in Axioms
  3348. * `G`: move forward one unit with the pen up
  3349. * `F`: move forward one unit with the pen down drawing trunks and branches
  3350. * `f`: move forward one unit with the pen down drawing leaves (100% chance)
  3351. * `T`: move forward one unit with the pen down drawing trunks only
  3352. * `R`: move forward one unit with the pen down placing fruit
  3353. * `A`: replace with rules set A
  3354. * `B`: replace with rules set B
  3355. * `C`: replace with rules set C
  3356. * `D`: replace with rules set D
  3357. * `a`: replace with rules set A, chance 90%
  3358. * `b`: replace with rules set B, chance 80%
  3359. * `c`: replace with rules set C, chance 70%
  3360. * `d`: replace with rules set D, chance 60%
  3361. * `+`: yaw the turtle right by `angle` parameter
  3362. * `-`: yaw the turtle left by `angle` parameter
  3363. * `&`: pitch the turtle down by `angle` parameter
  3364. * `^`: pitch the turtle up by `angle` parameter
  3365. * `/`: roll the turtle to the right by `angle` parameter
  3366. * `*`: roll the turtle to the left by `angle` parameter
  3367. * `[`: save in stack current state info
  3368. * `]`: recover from stack state info
  3369. ### Example
  3370. Spawn a small apple tree:
  3371. pos = {x=230,y=20,z=4}
  3372. apple_tree={
  3373. axiom="FFFFFAFFBF",
  3374. rules_a="[&&&FFFFF&&FFFF][&&&++++FFFFF&&FFFF][&&&----FFFFF&&FFFF]",
  3375. rules_b="[&&&++FFFFF&&FFFF][&&&--FFFFF&&FFFF][&&&------FFFFF&&FFFF]",
  3376. trunk="default:tree",
  3377. leaves="default:leaves",
  3378. angle=30,
  3379. iterations=2,
  3380. random_level=0,
  3381. trunk_type="single",
  3382. thin_branches=true,
  3383. fruit_chance=10,
  3384. fruit="default:apple"
  3385. }
  3386. minetest.spawn_tree(pos,apple_tree)
  3387. Definition tables
  3388. -----------------
  3389. ### Object Properties
  3390. {
  3391. hp_max = 1,
  3392. physical = true,
  3393. collide_with_objects = true, -- collide with other objects if physical = true
  3394. weight = 5,
  3395. collisionbox = {-0.5, 0.0, -0.5, 0.5, 1.0, 0.5},
  3396. visual = "cube" / "sprite" / "upright_sprite" / "mesh" / "wielditem",
  3397. visual_size = {x = 1, y = 1},
  3398. mesh = "model",
  3399. textures = {}, -- number of required textures depends on visual
  3400. colors = {}, -- number of required colors depends on visual
  3401. spritediv = {x = 1, y = 1},
  3402. initial_sprite_basepos = {x = 0, y = 0},
  3403. is_visible = true,
  3404. makes_footstep_sound = false,
  3405. automatic_rotate = false,
  3406. stepheight = 0,
  3407. automatic_face_movement_dir = 0.0,
  3408. -- ^ Automatically set yaw to movement direction, offset in degrees,
  3409. -- 'false' to disable.
  3410. automatic_face_movement_max_rotation_per_sec = -1,
  3411. -- ^ Limit automatic rotation to this value in degrees per second,
  3412. -- value < 0 no limit.
  3413. backface_culling = true, -- false to disable backface_culling for model
  3414. nametag = "", -- by default empty, for players their name is shown if empty
  3415. nametag_color = <color>, -- sets color of nametag as ColorSpec
  3416. infotext = "", -- by default empty, text to be shown when pointed at object
  3417. }
  3418. ### Entity definition (`register_entity`)
  3419. {
  3420. -- Deprecated: Everything in object properties is read directly from here
  3421. initial_properties = --[[<initial object properties>]],
  3422. on_activate = function(self, staticdata, dtime_s),
  3423. on_step = function(self, dtime),
  3424. on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir),
  3425. on_rightclick = function(self, clicker),
  3426. get_staticdata = function(self),
  3427. -- ^ Called sometimes; the string returned is passed to on_activate when
  3428. -- the entity is re-activated from static state
  3429. -- Also you can define arbitrary member variables here (see item definition for
  3430. -- more info)
  3431. _custom_field = whatever,
  3432. }
  3433. ### ABM (ActiveBlockModifier) definition (`register_abm`)
  3434. {
  3435. label = "Lava cooling",
  3436. -- ^ Descriptive label for profiling purposes (optional).
  3437. -- Definitions with identical labels will be listed as one.
  3438. -- In the following two fields, also group:groupname will work.
  3439. nodenames = {"default:lava_source"},
  3440. neighbors = {"default:water_source", "default:water_flowing"}, -- Any of these --[[
  3441. ^ If left out or empty, any neighbor will do ]]
  3442. interval = 1.0, -- Operation interval in seconds
  3443. chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
  3444. catch_up = true, -- If true, catch-up behaviour is enabled --[[
  3445. ^ The chance value is temporarily reduced when returning to
  3446. an area to simulate time lost by the area being unattended.
  3447. ^ Note chance value can often be reduced to 1 ]]
  3448. action = func(pos, node, active_object_count, active_object_count_wider),
  3449. }
  3450. ### LBM (LoadingBlockModifier) definition (`register_lbm`)
  3451. {
  3452. label = "Upgrade legacy doors",
  3453. -- ^ Descriptive label for profiling purposes (optional).
  3454. -- Definitions with identical labels will be listed as one.
  3455. name = "modname:replace_legacy_door",
  3456. nodenames = {"default:lava_source"},
  3457. -- ^ List of node names to trigger the LBM on.
  3458. -- Also non-registered nodes will work.
  3459. -- Groups (as of group:groupname) will work as well.
  3460. run_at_every_load = false,
  3461. -- ^ Whether to run the LBM's action every time a block gets loaded,
  3462. -- and not just for blocks that were saved last time before LBMs were
  3463. -- introduced to the world.
  3464. action = func(pos, node),
  3465. }
  3466. ### Item definition (`register_node`, `register_craftitem`, `register_tool`)
  3467. {
  3468. description = "Steel Axe",
  3469. groups = {}, -- key = name, value = rating; rating = 1..3.
  3470. if rating not applicable, use 1.
  3471. e.g. {wool = 1, fluffy = 3}
  3472. {soil = 2, outerspace = 1, crumbly = 1}
  3473. {bendy = 2, snappy = 1},
  3474. {hard = 1, metal = 1, spikes = 1}
  3475. inventory_image = "default_tool_steelaxe.png",
  3476. wield_image = "",
  3477. palette = "",
  3478. --[[
  3479. ^ An image file containing the palette of a node.
  3480. ^ You can set the currently used color as the
  3481. ^ "palette_index" field of the item stack metadata.
  3482. ^ The palette is always stretched to fit indices
  3483. ^ between 0 and 255, to ensure compatibility with
  3484. ^ "colorfacedir" and "colorwallmounted" nodes.
  3485. ]]
  3486. color = "0xFFFFFFFF",
  3487. --[[
  3488. ^ The color of the item. The palette overrides this.
  3489. ]]
  3490. wield_scale = {x = 1, y = 1, z = 1},
  3491. stack_max = 99,
  3492. range = 4.0,
  3493. liquids_pointable = false,
  3494. tool_capabilities = {
  3495. full_punch_interval = 1.0,
  3496. max_drop_level = 0,
  3497. groupcaps = {
  3498. -- For example:
  3499. choppy = {times = {[1] = 2.50, [2] = 1.40, [3] = 1.00}, uses = 20, maxlevel = 2},
  3500. },
  3501. damage_groups = {groupname = damage},
  3502. },
  3503. node_placement_prediction = nil,
  3504. --[[
  3505. ^ If nil and item is node, prediction is made automatically
  3506. ^ If nil and item is not a node, no prediction is made
  3507. ^ If "" and item is anything, no prediction is made
  3508. ^ Otherwise should be name of node which the client immediately places
  3509. on ground when the player places the item. Server will always update
  3510. actual result to client in a short moment.
  3511. ]]
  3512. sound = {
  3513. breaks = "default_tool_break", -- tools only
  3514. place = --[[<SimpleSoundSpec>]],
  3515. },
  3516. on_place = func(itemstack, placer, pointed_thing),
  3517. --[[
  3518. ^ Shall place item and return the leftover itemstack
  3519. ^ The placer may be any ObjectRef or nil.
  3520. ^ default: minetest.item_place ]]
  3521. on_secondary_use = func(itemstack, user, pointed_thing),
  3522. --[[
  3523. ^ Same as on_place but called when pointing at nothing.
  3524. ^ The user may be any ObjectRef or nil.
  3525. ^ pointed_thing : always { type = "nothing" }
  3526. ]]
  3527. on_drop = func(itemstack, dropper, pos),
  3528. --[[
  3529. ^ Shall drop item and return the leftover itemstack
  3530. ^ The dropper may be any ObjectRef or nil.
  3531. ^ default: minetest.item_drop ]]
  3532. on_use = func(itemstack, user, pointed_thing),
  3533. --[[
  3534. ^ default: nil
  3535. ^ Function must return either nil if no item shall be removed from
  3536. inventory, or an itemstack to replace the original itemstack.
  3537. e.g. itemstack:take_item(); return itemstack
  3538. ^ Otherwise, the function is free to do what it wants.
  3539. ^ The user may be any ObjectRef or nil.
  3540. ^ The default functions handle regular use cases.
  3541. ]]
  3542. after_use = func(itemstack, user, node, digparams),
  3543. --[[
  3544. ^ default: nil
  3545. ^ If defined, should return an itemstack and will be called instead of
  3546. wearing out the tool. If returns nil, does nothing.
  3547. If after_use doesn't exist, it is the same as:
  3548. function(itemstack, user, node, digparams)
  3549. itemstack:add_wear(digparams.wear)
  3550. return itemstack
  3551. end
  3552. ^ The user may be any ObjectRef or nil.
  3553. ]]
  3554. _custom_field = whatever,
  3555. --[[
  3556. ^ Add your own custom fields. By convention, all custom field names
  3557. should start with `_` to avoid naming collisions with future engine
  3558. usage.
  3559. ]]
  3560. }
  3561. ### Tile definition
  3562. * `"image.png"`
  3563. * `{name="image.png", animation={Tile Animation definition}}`
  3564. * `{name="image.png", backface_culling=bool, tileable_vertical=bool,
  3565. tileable_horizontal=bool}`
  3566. * backface culling enabled by default for most nodes
  3567. * tileable flags are info for shaders, how they should treat texture
  3568. when displacement mapping is used
  3569. Directions are from the point of view of the tile texture,
  3570. not the node it's on
  3571. * `{name="image.png", color=ColorSpec}`
  3572. * the texture's color will be multiplied with this color.
  3573. * the tile's color overrides the owning node's color in all cases.
  3574. * deprecated, yet still supported field names:
  3575. * `image` (name)
  3576. ### Tile animation definition
  3577. {
  3578. type = "vertical_frames",
  3579. aspect_w = 16,
  3580. -- ^ specify width of a frame in pixels
  3581. aspect_h = 16,
  3582. -- ^ specify height of a frame in pixels
  3583. length = 3.0,
  3584. -- ^ specify full loop length
  3585. }
  3586. {
  3587. type = "sheet_2d",
  3588. frames_w = 5,
  3589. -- ^ specify width in number of frames
  3590. frames_h = 3,
  3591. -- ^ specify height in number of frames
  3592. frame_length = 0.5,
  3593. -- ^ specify length of a single frame
  3594. }
  3595. ### Node definition (`register_node`)
  3596. {
  3597. -- <all fields allowed in item definitions>,
  3598. drawtype = "normal", -- See "Node drawtypes"
  3599. visual_scale = 1.0, --[[
  3600. ^ Supported for drawtypes "plantlike", "signlike", "torchlike",
  3601. ^ "firelike", "mesh".
  3602. ^ For plantlike and firelike, the image will start at the bottom of the
  3603. ^ node, for the other drawtypes the image will be centered on the node.
  3604. ^ Note that positioning for "torchlike" may still change. ]]
  3605. tiles = {tile definition 1, def2, def3, def4, def5, def6}, --[[
  3606. ^ Textures of node; +Y, -Y, +X, -X, +Z, -Z (old field name: tile_images)
  3607. ^ List can be shortened to needed length ]]
  3608. overlay_tiles = {tile definition 1, def2, def3, def4, def5, def6}, --[[
  3609. ^ Same as `tiles`, but these textures are drawn on top of the
  3610. ^ base tiles. You can use this to colorize only specific parts of
  3611. ^ your texture. If the texture name is an empty string, that
  3612. ^ overlay is not drawn. Since such tiles are drawn twice, it
  3613. ^ is not recommended to use overlays on very common nodes.
  3614. special_tiles = {tile definition 1, Tile definition 2}, --[[
  3615. ^ Special textures of node; used rarely (old field name: special_materials)
  3616. ^ List can be shortened to needed length ]]
  3617. color = ColorSpec, --[[
  3618. ^ The node's original color will be multiplied with this color.
  3619. ^ If the node has a palette, then this setting only has an effect
  3620. ^ in the inventory and on the wield item. ]]
  3621. use_texture_alpha = false, -- Use texture's alpha channel
  3622. palette = "palette.png", --[[
  3623. ^ The node's `param2` is used to select a pixel from the image
  3624. ^ (pixels are arranged from left to right and from top to bottom).
  3625. ^ The node's color will be multiplied with the selected pixel's
  3626. ^ color. Tiles can override this behavior.
  3627. ^ Only when `paramtype2` supports palettes. ]]
  3628. post_effect_color = "green#0F", -- If player is inside node, see "ColorSpec"
  3629. paramtype = "none", -- See "Nodes" --[[
  3630. ^ paramtype = "light" allows light to propagate from or through the node with light value
  3631. ^ falling by 1 per node. This line is essential for a light source node to spread its light. ]]
  3632. paramtype2 = "none", -- See "Nodes"
  3633. place_param2 = nil, -- Force value for param2 when player places node
  3634. is_ground_content = true, -- If false, the cave generator will not carve through this
  3635. sunlight_propagates = false, -- If true, sunlight will go infinitely through this
  3636. walkable = true, -- If true, objects collide with node
  3637. pointable = true, -- If true, can be pointed at
  3638. diggable = true, -- If false, can never be dug
  3639. climbable = false, -- If true, can be climbed on (ladder)
  3640. buildable_to = false, -- If true, placed nodes can replace this node
  3641. floodable = false, --[[
  3642. ^ If true, liquids flow into and replace this node.
  3643. ^ Warning: making a liquid node 'floodable' does not work and may cause problems. ]]
  3644. liquidtype = "none", -- "none"/"source"/"flowing"
  3645. liquid_alternative_flowing = "", -- Flowing version of source liquid
  3646. liquid_alternative_source = "", -- Source version of flowing liquid
  3647. liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
  3648. liquid_renewable = true, --[[
  3649. ^ If true, a new liquid source can be created by placing two or more sources nearby ]]
  3650. leveled = 0, --[[
  3651. ^ Block contains level in param2. Value is default level, used for snow.
  3652. ^ Don't forget to use "leveled" type nodebox. ]]
  3653. liquid_range = 8, -- number of flowing nodes around source (max. 8)
  3654. drowning = 0, -- Player will take this amount of damage if no bubbles are left
  3655. light_source = 0, --[[
  3656. ^ Amount of light emitted by node.
  3657. ^ To set the maximum (currently 14), use the value 'minetest.LIGHT_MAX'.
  3658. ^ A value outside the range 0 to minetest.LIGHT_MAX causes undefined behavior.]]
  3659. damage_per_second = 0, -- If player is inside node, this damage is caused
  3660. node_box = {type="regular"}, -- See "Node boxes"
  3661. connects_to = nodenames, --[[
  3662. * Used for nodebox nodes with the type == "connected"
  3663. * Specifies to what neighboring nodes connections will be drawn
  3664. * e.g. `{"group:fence", "default:wood"}` or `"default:stone"` ]]
  3665. connect_sides = { "top", "bottom", "front", "left", "back", "right" }, --[[
  3666. ^ Tells connected nodebox nodes to connect only to these sides of this node. ]]
  3667. mesh = "model",
  3668. selection_box = {type="regular"}, -- See "Node boxes" --[[
  3669. ^ If drawtype "nodebox" is used and selection_box is nil, then node_box is used. ]]
  3670. legacy_facedir_simple = false, -- Support maps made in and before January 2012
  3671. legacy_wallmounted = false, -- Support maps made in and before January 2012
  3672. waving = 0, --[[ valid for mesh, nodebox, plantlike, allfaces_optional nodes
  3673. ^ 1 - wave node like plants (top of node moves, bottom is fixed)
  3674. ^ 2 - wave node like leaves (whole node moves side-to-side synchronously)
  3675. ^ caveats: not all models will properly wave
  3676. ^ plantlike drawtype nodes can only wave like plants
  3677. ^ allfaces_optional drawtype nodes can only wave like leaves --]]
  3678. sounds = {
  3679. footstep = <SimpleSoundSpec>,
  3680. dig = <SimpleSoundSpec>, -- "__group" = group-based sound (default)
  3681. dug = <SimpleSoundSpec>,
  3682. place = <SimpleSoundSpec>,
  3683. place_failed = <SimpleSoundSpec>,
  3684. },
  3685. drop = "", -- Name of dropped node when dug. Default is the node itself.
  3686. -- Alternatively:
  3687. drop = {
  3688. max_items = 1, -- Maximum number of items to drop.
  3689. items = { -- Choose max_items randomly from this list.
  3690. {
  3691. items = {"foo:bar", "baz:frob"}, -- Items to drop.
  3692. rarity = 1, -- Probability of dropping is 1 / rarity.
  3693. inherit_color = true, -- To inherit palette color from the node
  3694. },
  3695. },
  3696. },
  3697. on_construct = func(pos), --[[
  3698. ^ Node constructor; called after adding node
  3699. ^ Can set up metadata and stuff like that
  3700. ^ Not called for bulk node placement (i.e. schematics and VoxelManip)
  3701. ^ default: nil ]]
  3702. on_destruct = func(pos), --[[
  3703. ^ Node destructor; called before removing node
  3704. ^ Not called for bulk node placement (i.e. schematics and VoxelManip)
  3705. ^ default: nil ]]
  3706. after_destruct = func(pos, oldnode), --[[
  3707. ^ Node destructor; called after removing node
  3708. ^ Not called for bulk node placement (i.e. schematics and VoxelManip)
  3709. ^ default: nil ]]
  3710. on_flood = func(pos, oldnode, newnode), --[[
  3711. ^ Called when a liquid (newnode) is about to flood oldnode, if
  3712. ^ it has `floodable = true` in the nodedef. Not called for bulk
  3713. ^ node placement (i.e. schematics and VoxelManip) or air nodes. If
  3714. ^ return true the node is not flooded, but on_flood callback will
  3715. ^ most likely be called over and over again every liquid update
  3716. ^ interval. Default: nil.
  3717. ^ Warning: making a liquid node 'floodable' does not work and may cause problems. ]]
  3718. after_place_node = func(pos, placer, itemstack, pointed_thing) --[[
  3719. ^ Called after constructing node when node was placed using
  3720. minetest.item_place_node / minetest.place_node
  3721. ^ If return true no item is taken from itemstack
  3722. ^ `placer` may be any valid ObjectRef or nil
  3723. ^ default: nil ]]
  3724. after_dig_node = func(pos, oldnode, oldmetadata, digger), --[[
  3725. ^ oldmetadata is in table format
  3726. ^ Called after destructing node when node was dug using
  3727. minetest.node_dig / minetest.dig_node
  3728. ^ default: nil ]]
  3729. can_dig = function(pos, [player]) --[[
  3730. ^ returns true if node can be dug, or false if not
  3731. ^ default: nil ]]
  3732. on_punch = func(pos, node, puncher, pointed_thing), --[[
  3733. ^ default: minetest.node_punch
  3734. ^ By default: Calls minetest.register_on_punchnode callbacks ]]
  3735. on_rightclick = func(pos, node, clicker, itemstack, pointed_thing), --[[
  3736. ^ default: nil
  3737. ^ itemstack will hold clicker's wielded item
  3738. ^ Shall return the leftover itemstack
  3739. ^ Note: pointed_thing can be nil, if a mod calls this function
  3740. This function does not get triggered by clients <=0.4.16 if the
  3741. "formspec" node metadata field is set ]]
  3742. on_dig = func(pos, node, digger), --[[
  3743. ^ default: minetest.node_dig
  3744. ^ By default: checks privileges, wears out tool and removes node ]]
  3745. on_timer = function(pos,elapsed), --[[
  3746. ^ default: nil
  3747. ^ called by NodeTimers, see minetest.get_node_timer and NodeTimerRef
  3748. ^ elapsed is the total time passed since the timer was started
  3749. ^ return true to run the timer for another cycle with the same timeout value ]]
  3750. on_receive_fields = func(pos, formname, fields, sender), --[[
  3751. ^ fields = {name1 = value1, name2 = value2, ...}
  3752. ^ Called when an UI form (e.g. sign text input) returns data
  3753. ^ default: nil ]]
  3754. allow_metadata_inventory_move = func(pos, from_list, from_index,
  3755. to_list, to_index, count, player), --[[
  3756. ^ Called when a player wants to move items inside the inventory
  3757. ^ Return value: number of items allowed to move ]]
  3758. allow_metadata_inventory_put = func(pos, listname, index, stack, player), --[[
  3759. ^ Called when a player wants to put something into the inventory
  3760. ^ Return value: number of items allowed to put
  3761. ^ Return value: -1: Allow and don't modify item count in inventory ]]
  3762. allow_metadata_inventory_take = func(pos, listname, index, stack, player), --[[
  3763. ^ Called when a player wants to take something out of the inventory
  3764. ^ Return value: number of items allowed to take
  3765. ^ Return value: -1: Allow and don't modify item count in inventory ]]
  3766. on_metadata_inventory_move = func(pos, from_list, from_index,
  3767. to_list, to_index, count, player),
  3768. on_metadata_inventory_put = func(pos, listname, index, stack, player),
  3769. on_metadata_inventory_take = func(pos, listname, index, stack, player), --[[
  3770. ^ Called after the actual action has happened, according to what was allowed.
  3771. ^ No return value ]]
  3772. on_blast = func(pos, intensity), --[[
  3773. ^ intensity: 1.0 = mid range of regular TNT
  3774. ^ If defined, called when an explosion touches the node, instead of
  3775. removing the node ]]
  3776. }
  3777. ### Recipe for `register_craft` (shaped)
  3778. {
  3779. output = 'default:pick_stone',
  3780. recipe = {
  3781. {'default:cobble', 'default:cobble', 'default:cobble'},
  3782. {'', 'default:stick', ''},
  3783. {'', 'default:stick', ''}, -- Also groups; e.g. 'group:crumbly'
  3784. },
  3785. replacements = --[[<optional list of item pairs,
  3786. replace one input item with another item on crafting>]]
  3787. }
  3788. ### Recipe for `register_craft` (shapeless)
  3789. {
  3790. type = "shapeless",
  3791. output = 'mushrooms:mushroom_stew',
  3792. recipe = {
  3793. "mushrooms:bowl",
  3794. "mushrooms:mushroom_brown",
  3795. "mushrooms:mushroom_red",
  3796. },
  3797. replacements = --[[<optional list of item pairs,
  3798. replace one input item with another item on crafting>]]
  3799. }
  3800. ### Recipe for `register_craft` (tool repair)
  3801. {
  3802. type = "toolrepair",
  3803. additional_wear = -0.02,
  3804. }
  3805. ### Recipe for `register_craft` (cooking)
  3806. {
  3807. type = "cooking",
  3808. output = "default:glass",
  3809. recipe = "default:sand",
  3810. cooktime = 3,
  3811. }
  3812. ### Recipe for `register_craft` (furnace fuel)
  3813. {
  3814. type = "fuel",
  3815. recipe = "default:leaves",
  3816. burntime = 1,
  3817. }
  3818. ### Ore definition (`register_ore`)
  3819. {
  3820. ore_type = "scatter", -- See "Ore types"
  3821. ore = "default:stone_with_coal",
  3822. wherein = "default:stone",
  3823. -- ^ a list of nodenames is supported too
  3824. clust_scarcity = 8*8*8,
  3825. -- ^ Ore has a 1 out of clust_scarcity chance of spawning in a node
  3826. -- ^ This value should be *MUCH* higher than your intuition might tell you!
  3827. clust_num_ores = 8,
  3828. -- ^ Number of ores in a cluster
  3829. clust_size = 3,
  3830. -- ^ Size of the bounding box of the cluster
  3831. -- ^ In this example, there is a 3x3x3 cluster where 8 out of the 27 nodes are coal ore
  3832. y_min = -31000,
  3833. y_max = 64,
  3834. flags = "",
  3835. -- ^ Attributes for this ore generation
  3836. noise_threshold = 0.5,
  3837. -- ^ If noise is above this threshold, ore is placed. Not needed for a uniform distribution
  3838. noise_params = {offset=0, scale=1, spread={x=100, y=100, z=100}, seed=23, octaves=3, persist=0.70}
  3839. -- ^ NoiseParams structure describing the perlin noise used for ore distribution.
  3840. -- ^ Needed for sheet ore_type. Omit from scatter ore_type for a uniform ore distribution
  3841. random_factor = 1.0,
  3842. -- ^ Multiplier of the randomness contribution to the noise value at any
  3843. -- given point to decide if ore should be placed. Set to 0 for solid veins.
  3844. -- ^ This parameter is only valid for ore_type == "vein".
  3845. biomes = {"desert", "rainforest"}
  3846. -- ^ List of biomes in which this decoration occurs. Occurs in all biomes if this is omitted,
  3847. -- ^ and ignored if the Mapgen being used does not support biomes.
  3848. -- ^ Can be a list of (or a single) biome names, IDs, or definitions.
  3849. }
  3850. ### Biome definition (`register_biome`)
  3851. **Note**
  3852. The Biome API is still in an experimental phase and subject to change.
  3853. {
  3854. name = "tundra",
  3855. node_dust = "default:snow",
  3856. -- ^ Node dropped onto upper surface after all else is generated.
  3857. node_top = "default:dirt_with_snow",
  3858. depth_top = 1,
  3859. -- ^ Node forming surface layer of biome and thickness of this layer.
  3860. node_filler = "default:permafrost",
  3861. depth_filler = 3,
  3862. -- ^ Node forming lower layer of biome and thickness of this layer.
  3863. node_stone = "default:bluestone",
  3864. -- ^ Node that replaces all stone nodes between roughly y_min and y_max.
  3865. node_water_top = "default:ice",
  3866. depth_water_top = 10,
  3867. -- ^ Node forming a surface layer in seawater with the defined thickness.
  3868. node_water = "",
  3869. -- ^ Node that replaces all seawater nodes not in the defined surface layer.
  3870. node_river_water = "default:ice",
  3871. -- ^ Node that replaces river water in mapgens that use default:river_water.
  3872. node_riverbed = "default:gravel",
  3873. depth_riverbed = 2,
  3874. -- ^ Node placed under river water and thickness of this layer.
  3875. y_min = 1,
  3876. y_max = 31000,
  3877. -- ^ Lower and upper limits for biome.
  3878. -- ^ Because biome is not recalculated for every node in a node column
  3879. -- ^ some biome materials can exceed their limits, especially stone.
  3880. -- ^ For each node column in a mapchunk, biome is only recalculated at column
  3881. -- ^ top and at each of these surfaces:
  3882. -- ^ Ground below air, water below air, ground below water.
  3883. -- ^ The selected biome then stays in effect for all nodes below until
  3884. -- ^ column base or the next biome recalculation.
  3885. heat_point = 0,
  3886. humidity_point = 50,
  3887. -- ^ Characteristic average temperature and humidity for the biome.
  3888. -- ^ These values create 'biome points' on a voronoi diagram that has heat
  3889. -- ^ and humidity as axes. The resulting voronoi cells determine which
  3890. -- ^ heat/humidity points belong to which biome, and therefore determine
  3891. -- ^ the area and location of each biome in the world.
  3892. -- ^ The biome points need to be carefully and evenly spaced on the voronoi
  3893. -- ^ diagram to result in roughly equal size biomes.
  3894. -- ^ Heat and humidity have average values of 50, vary mostly between
  3895. -- ^ 0 and 100 but also often exceed these values.
  3896. -- ^ Heat is not in degrees celcius, both values are abstract.
  3897. }
  3898. ### Decoration definition (`register_decoration`)
  3899. {
  3900. deco_type = "simple", -- See "Decoration types"
  3901. place_on = "default:dirt_with_grass",
  3902. -- ^ Node (or list of nodes) that the decoration can be placed on
  3903. sidelen = 8,
  3904. -- ^ Size of divisions made in the chunk being generated.
  3905. -- ^ If the chunk size is not evenly divisible by sidelen, sidelen is made equal to the chunk size.
  3906. fill_ratio = 0.02,
  3907. -- ^ Ratio of the area to be uniformly filled by the decoration.
  3908. -- ^ Used only if noise_params is not specified.
  3909. noise_params = {offset=0, scale=.45, spread={x=100, y=100, z=100}, seed=354, octaves=3, persist=0.7},
  3910. -- ^ NoiseParams structure describing the perlin noise used for decoration distribution.
  3911. -- ^ The result of this is multiplied by the 2d area of the division being decorated.
  3912. biomes = {"Oceanside", "Hills", "Plains"},
  3913. -- ^ List of biomes in which this decoration occurs. Occurs in all biomes if this is omitted,
  3914. -- ^ and ignored if the Mapgen being used does not support biomes.
  3915. -- ^ Can be a list of (or a single) biome names, IDs, or definitions.
  3916. y_min = -31000
  3917. y_max = 31000
  3918. -- ^ Minimum and maximum `y` positions these decorations can be generated at.
  3919. -- ^ This parameter refers to the `y` position of the decoration base, so
  3920. -- the actual maximum height would be `height_max + size.Y`.
  3921. spawn_by = "default:water",
  3922. -- ^ Node (or list of nodes) that the decoration only spawns next to.
  3923. -- ^ Checks two horizontal planes of neighbouring nodes (including diagonal neighbours),
  3924. -- ^ one plane at Y = surface and one plane at Y = surface = + 1.
  3925. num_spawn_by = 1,
  3926. -- ^ Number of spawn_by nodes that must be surrounding the decoration position to occur.
  3927. -- ^ If absent or -1, decorations occur next to any nodes.
  3928. flags = "liquid_surface, force_placement",
  3929. -- ^ Flags for all decoration types.
  3930. -- ^ "liquid_surface": Instead of placement on the highest solid surface
  3931. -- ^ in a mapchunk column, placement is on the highest liquid surface.
  3932. -- ^ Placement is disabled if solid nodes are found above the liquid surface.
  3933. -- ^ "force_placement": Nodes other than "air" and "ignore" are replaced by the decoration.
  3934. ----- Simple-type parameters
  3935. decoration = "default:grass",
  3936. -- ^ The node name used as the decoration.
  3937. -- ^ If instead a list of strings, a randomly selected node from the list is placed as the decoration.
  3938. height = 1,
  3939. -- ^ Number of nodes high the decoration is made.
  3940. -- ^ If height_max is not 0, this is the lower bound of the randomly selected height.
  3941. height_max = 0,
  3942. -- ^ Number of nodes the decoration can be at maximum.
  3943. -- ^ If absent, the parameter 'height' is used as a constant.
  3944. param2 = 0,
  3945. -- ^ Param2 value of placed decoration node.
  3946. ----- Schematic-type parameters
  3947. schematic = "foobar.mts",
  3948. -- ^ If schematic is a string, it is the filepath relative to the current working directory of the
  3949. -- ^ specified Minetest schematic file.
  3950. -- ^ - OR -, could be the ID of a previously registered schematic
  3951. -- ^ - OR -, could instead be a table containing two mandatory fields, size and data,
  3952. -- ^ and an optional table yslice_prob:
  3953. schematic = {
  3954. size = {x=4, y=6, z=4},
  3955. data = {
  3956. {name="default:cobble", param1=255, param2=0},
  3957. {name="default:dirt_with_grass", param1=255, param2=0},
  3958. {name="ignore", param1=255, param2=0},
  3959. {name="air", param1=255, param2=0},
  3960. ...
  3961. },
  3962. yslice_prob = {
  3963. {ypos=2, prob=128},
  3964. {ypos=5, prob=64},
  3965. ...
  3966. },
  3967. },
  3968. -- ^ See 'Schematic specifier' for details.
  3969. replacements = {["oldname"] = "convert_to", ...},
  3970. flags = "place_center_x, place_center_y, place_center_z",
  3971. -- ^ Flags for schematic decorations. See 'Schematic attributes'.
  3972. rotation = "90" -- rotate schematic 90 degrees on placement
  3973. -- ^ Rotation can be "0", "90", "180", "270", or "random".
  3974. }
  3975. ### Chat command definition (`register_chatcommand`)
  3976. {
  3977. params = "<name> <privilege>", -- Short parameter description
  3978. description = "Remove privilege from player", -- Full description
  3979. privs = {privs=true}, -- Require the "privs" privilege to run
  3980. func = function(name, param), -- Called when command is run.
  3981. -- Returns boolean success and text output.
  3982. }
  3983. ### Detached inventory callbacks
  3984. {
  3985. allow_move = func(inv, from_list, from_index, to_list, to_index, count, player),
  3986. -- ^ Called when a player wants to move items inside the inventory
  3987. -- ^ Return value: number of items allowed to move
  3988. allow_put = func(inv, listname, index, stack, player),
  3989. -- ^ Called when a player wants to put something into the inventory
  3990. -- ^ Return value: number of items allowed to put
  3991. -- ^ Return value: -1: Allow and don't modify item count in inventory
  3992. allow_take = func(inv, listname, index, stack, player),
  3993. -- ^ Called when a player wants to take something out of the inventory
  3994. -- ^ Return value: number of items allowed to take
  3995. -- ^ Return value: -1: Allow and don't modify item count in inventory
  3996. on_move = func(inv, from_list, from_index, to_list, to_index, count, player),
  3997. on_put = func(inv, listname, index, stack, player),
  3998. on_take = func(inv, listname, index, stack, player),
  3999. -- ^ Called after the actual action has happened, according to what was allowed.
  4000. -- ^ No return value
  4001. }
  4002. ### HUD Definition (`hud_add`, `hud_get`)
  4003. {
  4004. hud_elem_type = "image", -- see HUD element types
  4005. -- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
  4006. position = {x=0.5, y=0.5},
  4007. -- ^ Left corner position of element
  4008. name = "<name>",
  4009. scale = {x=2, y=2},
  4010. text = "<text>",
  4011. number = 2,
  4012. item = 3,
  4013. -- ^ Selected item in inventory. 0 for no item selected.
  4014. direction = 0,
  4015. -- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
  4016. alignment = {x=0, y=0},
  4017. -- ^ See "HUD Element Types"
  4018. offset = {x=0, y=0},
  4019. -- ^ See "HUD Element Types"
  4020. size = { x=100, y=100 },
  4021. -- ^ Size of element in pixels
  4022. }
  4023. ### Particle definition (`add_particle`)
  4024. {
  4025. pos = {x=0, y=0, z=0},
  4026. velocity = {x=0, y=0, z=0},
  4027. acceleration = {x=0, y=0, z=0},
  4028. -- ^ Spawn particle at pos with velocity and acceleration
  4029. expirationtime = 1,
  4030. -- ^ Disappears after expirationtime seconds
  4031. size = 1,
  4032. collisiondetection = false,
  4033. -- ^ collisiondetection: if true collides with physical objects
  4034. collision_removal = false,
  4035. -- ^ collision_removal: if true then particle is removed when it collides,
  4036. -- ^ requires collisiondetection = true to have any effect
  4037. vertical = false,
  4038. -- ^ vertical: if true faces player using y axis only
  4039. texture = "image.png",
  4040. -- ^ Uses texture (string)
  4041. playername = "singleplayer",
  4042. -- ^ optional, if specified spawns particle only on the player's client
  4043. animation = {Tile Animation definition},
  4044. -- ^ optional, specifies how to animate the particle texture
  4045. glow = 0
  4046. -- ^ optional, specify particle self-luminescence in darkness
  4047. }
  4048. ### `ParticleSpawner` definition (`add_particlespawner`)
  4049. {
  4050. amount = 1,
  4051. time = 1,
  4052. -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
  4053. minpos = {x=0, y=0, z=0},
  4054. maxpos = {x=0, y=0, z=0},
  4055. minvel = {x=0, y=0, z=0},
  4056. maxvel = {x=0, y=0, z=0},
  4057. minacc = {x=0, y=0, z=0},
  4058. maxacc = {x=0, y=0, z=0},
  4059. minexptime = 1,
  4060. maxexptime = 1,
  4061. minsize = 1,
  4062. maxsize = 1,
  4063. -- ^ The particle's properties are random values in between the bounds:
  4064. -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
  4065. -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
  4066. collisiondetection = false,
  4067. -- ^ collisiondetection: if true uses collision detection
  4068. collision_removal = false,
  4069. -- ^ collision_removal: if true then particle is removed when it collides,
  4070. -- ^ requires collisiondetection = true to have any effect
  4071. attached = ObjectRef,
  4072. -- ^ attached: if defined, particle positions, velocities and accelerations
  4073. -- ^ are relative to this object's position and yaw.
  4074. vertical = false,
  4075. -- ^ vertical: if true faces player using y axis only
  4076. texture = "image.png",
  4077. -- ^ Uses texture (string)
  4078. playername = "singleplayer"
  4079. -- ^ Playername is optional, if specified spawns particle only on the player's client
  4080. }
  4081. ### `HTTPRequest` definition (`HTTPApiTable.fetch_async`, `HTTPApiTable.fetch_async`)
  4082. {
  4083. url = "http://example.org",
  4084. timeout = 10,
  4085. -- ^ Timeout for connection in seconds. Default is 3 seconds.
  4086. post_data = "Raw POST request data string" OR { field1 = "data1", field2 = "data2" },
  4087. -- ^ Optional, if specified a POST request with post_data is performed.
  4088. -- ^ Accepts both a string and a table. If a table is specified, encodes table
  4089. -- ^ as x-www-form-urlencoded key-value pairs.
  4090. -- ^ If post_data ist not specified, a GET request is performed instead.
  4091. user_agent = "ExampleUserAgent",
  4092. -- ^ Optional, if specified replaces the default minetest user agent with given string
  4093. extra_headers = { "Accept-Language: en-us", "Accept-Charset: utf-8" },
  4094. -- ^ Optional, if specified adds additional headers to the HTTP request. You must make sure
  4095. -- ^ that the header strings follow HTTP specification ("Key: Value").
  4096. multipart = boolean
  4097. -- ^ Optional, if true performs a multipart HTTP request. Default is false.
  4098. }
  4099. ### `HTTPRequestResult` definition (`HTTPApiTable.fetch` callback, `HTTPApiTable.fetch_async_get`)
  4100. {
  4101. completed = true,
  4102. -- ^ If true, the request has finished (either succeeded, failed or timed out)
  4103. succeeded = true,
  4104. -- ^ If true, the request was succesful
  4105. timeout = false,
  4106. -- ^ If true, the request timed out
  4107. code = 200,
  4108. -- ^ HTTP status code
  4109. data = "response"
  4110. }
  4111. ### Authentication handler definition
  4112. {
  4113. get_auth = func(name),
  4114. -- ^ Get authentication data for existing player `name` (`nil` if player doesn't exist)
  4115. -- ^ returns following structure `{password=<string>, privileges=<table>, last_login=<number or nil>}`
  4116. create_auth = func(name, password),
  4117. -- ^ Create new auth data for player `name`
  4118. -- ^ Note that `password` is not plain-text but an arbitrary representation decided by the engine
  4119. set_password = func(name, password),
  4120. -- ^ Set password of player `name` to `password`
  4121. Auth data should be created if not present
  4122. set_privileges = func(name, privileges),
  4123. -- ^ Set privileges of player `name`
  4124. -- ^ `privileges` is in table form, auth data should be created if not present
  4125. reload = func(),
  4126. -- ^ Reload authentication data from the storage location
  4127. -- ^ Returns boolean indicating success
  4128. record_login = func(name),
  4129. -- ^ Called when player joins, used for keeping track of last_login
  4130. }