2
0

init.lua 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898
  1. -- default (Minetest 0.4 mod)
  2. -- Most default stuff
  3. -- The API documentation in here was moved into doc/lua_api.txt
  4. WATER_ALPHA = 160
  5. WATER_VISC = 1
  6. LAVA_VISC = 7
  7. LIGHT_MAX = 14
  8. -- Definitions made by this mod that other mods can use too
  9. default = {}
  10. -- Load other files
  11. dofile(minetest.get_modpath("default").."/mapgen.lua")
  12. -- Set a noticeable inventory formspec for players
  13. minetest.register_on_joinplayer(function(player)
  14. local cb = function(player)
  15. minetest.chat_send_player(player:get_player_name(), "This is the [minimal] \"Minimal Development Test\" game. Use [minetest_game] for the real thing.")
  16. player:set_attribute("test_attribute", "test_me")
  17. player:set_attribute("remove_this", nil)
  18. end
  19. minetest.after(2.0, cb, player)
  20. end)
  21. --
  22. -- Tool definition
  23. --
  24. -- The hand
  25. minetest.register_item(":", {
  26. type = "none",
  27. wield_image = "wieldhand.png",
  28. wield_scale = {x=1,y=1,z=2.5},
  29. tool_capabilities = {
  30. full_punch_interval = 1.0,
  31. max_drop_level = 0,
  32. groupcaps = {
  33. fleshy = {times={[2]=2.00, [3]=1.00}, uses=0, maxlevel=1},
  34. crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
  35. snappy = {times={[3]=0.40}, uses=0, maxlevel=1},
  36. oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=1.40}, uses=0, maxlevel=3},
  37. },
  38. damage_groups = {fleshy=1},
  39. }
  40. })
  41. --
  42. -- Picks
  43. --
  44. minetest.register_tool("default:pick_wood", {
  45. description = "Wooden Pickaxe",
  46. inventory_image = "default_tool_woodpick.png",
  47. tool_capabilities = {
  48. max_drop_level=0,
  49. groupcaps={
  50. cracky={times={[2]=2.00, [3]=1.20}, uses=10, maxlevel=1}
  51. },
  52. damage_groups = {fleshy=2},
  53. },
  54. })
  55. minetest.register_tool("default:pick_stone", {
  56. description = "Stone Pickaxe",
  57. inventory_image = "default_tool_stonepick.png",
  58. tool_capabilities = {
  59. max_drop_level=0,
  60. groupcaps={
  61. cracky={times={[1]=2.00, [2]=1.20, [3]=0.80}, uses=20, maxlevel=1}
  62. },
  63. damage_groups = {fleshy=3},
  64. },
  65. })
  66. minetest.register_tool("default:pick_steel", {
  67. description = "Steel Pickaxe",
  68. inventory_image = "default_tool_steelpick.png",
  69. tool_capabilities = {
  70. max_drop_level=1,
  71. groupcaps={
  72. cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=10, maxlevel=2}
  73. },
  74. damage_groups = {fleshy=4},
  75. },
  76. })
  77. minetest.register_tool("default:pick_mese", {
  78. description = "Mese Pickaxe",
  79. inventory_image = "default_tool_mesepick.png",
  80. tool_capabilities = {
  81. full_punch_interval = 1.0,
  82. max_drop_level=3,
  83. groupcaps={
  84. cracky={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
  85. crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
  86. snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3}
  87. },
  88. damage_groups = {fleshy=4},
  89. },
  90. })
  91. --
  92. -- Shovels
  93. --
  94. minetest.register_tool("default:shovel_wood", {
  95. description = "Wooden Shovel",
  96. inventory_image = "default_tool_woodshovel.png",
  97. tool_capabilities = {
  98. max_drop_level=0,
  99. groupcaps={
  100. crumbly={times={[1]=2.00, [2]=0.80, [3]=0.50}, uses=10, maxlevel=1}
  101. },
  102. damage_groups = {fleshy=2},
  103. },
  104. })
  105. minetest.register_tool("default:shovel_stone", {
  106. description = "Stone Shovel",
  107. inventory_image = "default_tool_stoneshovel.png",
  108. tool_capabilities = {
  109. max_drop_level=0,
  110. groupcaps={
  111. crumbly={times={[1]=1.20, [2]=0.50, [3]=0.30}, uses=20, maxlevel=1}
  112. },
  113. damage_groups = {fleshy=3},
  114. },
  115. })
  116. minetest.register_tool("default:shovel_steel", {
  117. description = "Steel Shovel",
  118. inventory_image = "default_tool_steelshovel.png",
  119. tool_capabilities = {
  120. max_drop_level=1,
  121. groupcaps={
  122. crumbly={times={[1]=1.00, [2]=0.70, [3]=0.60}, uses=10, maxlevel=2}
  123. },
  124. damage_groups = {fleshy=4},
  125. },
  126. })
  127. --
  128. -- Axes
  129. --
  130. minetest.register_tool("default:axe_wood", {
  131. description = "Wooden Axe",
  132. inventory_image = "default_tool_woodaxe.png",
  133. tool_capabilities = {
  134. max_drop_level=0,
  135. groupcaps={
  136. choppy={times={[2]=1.40, [3]=0.80}, uses=10, maxlevel=1},
  137. fleshy={times={[2]=1.50, [3]=0.80}, uses=10, maxlevel=1}
  138. },
  139. damage_groups = {fleshy=2},
  140. },
  141. })
  142. minetest.register_tool("default:axe_stone", {
  143. description = "Stone Axe",
  144. inventory_image = "default_tool_stoneaxe.png",
  145. tool_capabilities = {
  146. max_drop_level=0,
  147. groupcaps={
  148. choppy={times={[1]=1.50, [2]=1.00, [3]=0.60}, uses=20, maxlevel=1},
  149. fleshy={times={[2]=1.30, [3]=0.70}, uses=20, maxlevel=1}
  150. },
  151. damage_groups = {fleshy=3},
  152. },
  153. })
  154. minetest.register_tool("default:axe_steel", {
  155. description = "Steel Axe",
  156. inventory_image = "default_tool_steelaxe.png",
  157. tool_capabilities = {
  158. max_drop_level=1,
  159. groupcaps={
  160. choppy={times={[1]=2.00, [2]=1.60, [3]=1.00}, uses=10, maxlevel=2},
  161. fleshy={times={[2]=1.10, [3]=0.60}, uses=40, maxlevel=1}
  162. },
  163. damage_groups = {fleshy=3},
  164. },
  165. })
  166. --
  167. -- Swords
  168. --
  169. minetest.register_tool("default:sword_wood", {
  170. description = "Wooden Sword",
  171. inventory_image = "default_tool_woodsword.png",
  172. tool_capabilities = {
  173. full_punch_interval = 1.0,
  174. max_drop_level=0,
  175. groupcaps={
  176. fleshy={times={[2]=1.10, [3]=0.60}, uses=10, maxlevel=1},
  177. snappy={times={[2]=1.00, [3]=0.50}, uses=10, maxlevel=1},
  178. choppy={times={[3]=1.00}, uses=20, maxlevel=0}
  179. },
  180. damage_groups = {fleshy=2},
  181. }
  182. })
  183. minetest.register_tool("default:sword_stone", {
  184. description = "Stone Sword",
  185. inventory_image = "default_tool_stonesword.png",
  186. tool_capabilities = {
  187. full_punch_interval = 1.0,
  188. max_drop_level=0,
  189. groupcaps={
  190. fleshy={times={[2]=0.80, [3]=0.40}, uses=20, maxlevel=1},
  191. snappy={times={[2]=0.80, [3]=0.40}, uses=20, maxlevel=1},
  192. choppy={times={[3]=0.90}, uses=20, maxlevel=0}
  193. },
  194. damage_groups = {fleshy=4},
  195. }
  196. })
  197. minetest.register_tool("default:sword_steel", {
  198. description = "Steel Sword",
  199. inventory_image = "default_tool_steelsword.png",
  200. tool_capabilities = {
  201. full_punch_interval = 1.0,
  202. max_drop_level=1,
  203. groupcaps={
  204. fleshy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=10, maxlevel=2},
  205. snappy={times={[2]=0.70, [3]=0.30}, uses=40, maxlevel=1},
  206. choppy={times={[3]=0.70}, uses=40, maxlevel=0}
  207. },
  208. damage_groups = {fleshy=6},
  209. }
  210. })
  211. --
  212. -- Crafting definition
  213. --
  214. minetest.register_craft({
  215. output = 'default:wood 4',
  216. recipe = {
  217. {'default:tree'},
  218. }
  219. })
  220. minetest.register_craft({
  221. output = 'default:stick 4',
  222. recipe = {
  223. {'default:wood'},
  224. }
  225. })
  226. minetest.register_craft({
  227. output = 'default:fence_wood 2',
  228. recipe = {
  229. {'default:stick', 'default:stick', 'default:stick'},
  230. {'default:stick', 'default:stick', 'default:stick'},
  231. }
  232. })
  233. minetest.register_craft({
  234. output = 'default:sign_wall',
  235. recipe = {
  236. {'default:wood', 'default:wood', 'default:wood'},
  237. {'default:wood', 'default:wood', 'default:wood'},
  238. {'', 'default:stick', ''},
  239. }
  240. })
  241. minetest.register_craft({
  242. output = 'default:torch 4',
  243. recipe = {
  244. {'default:coal_lump'},
  245. {'default:stick'},
  246. }
  247. })
  248. minetest.register_craft({
  249. output = 'default:pick_wood',
  250. recipe = {
  251. {'default:wood', 'default:wood', 'default:wood'},
  252. {'', 'default:stick', ''},
  253. {'', 'default:stick', ''},
  254. }
  255. })
  256. minetest.register_craft({
  257. output = 'default:pick_stone',
  258. recipe = {
  259. {'default:cobble', 'default:cobble', 'default:cobble'},
  260. {'', 'default:stick', ''},
  261. {'', 'default:stick', ''},
  262. }
  263. })
  264. minetest.register_craft({
  265. output = 'default:pick_steel',
  266. recipe = {
  267. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  268. {'', 'default:stick', ''},
  269. {'', 'default:stick', ''},
  270. }
  271. })
  272. minetest.register_craft({
  273. output = 'default:pick_mese',
  274. recipe = {
  275. {'default:mese', 'default:mese', 'default:mese'},
  276. {'', 'default:stick', ''},
  277. {'', 'default:stick', ''},
  278. }
  279. })
  280. minetest.register_craft({
  281. output = 'default:shovel_wood',
  282. recipe = {
  283. {'default:wood'},
  284. {'default:stick'},
  285. {'default:stick'},
  286. }
  287. })
  288. minetest.register_craft({
  289. output = 'default:shovel_stone',
  290. recipe = {
  291. {'default:cobble'},
  292. {'default:stick'},
  293. {'default:stick'},
  294. }
  295. })
  296. minetest.register_craft({
  297. output = 'default:shovel_steel',
  298. recipe = {
  299. {'default:steel_ingot'},
  300. {'default:stick'},
  301. {'default:stick'},
  302. }
  303. })
  304. minetest.register_craft({
  305. output = 'default:axe_wood',
  306. recipe = {
  307. {'default:wood', 'default:wood'},
  308. {'default:wood', 'default:stick'},
  309. {'', 'default:stick'},
  310. }
  311. })
  312. minetest.register_craft({
  313. output = 'default:axe_stone',
  314. recipe = {
  315. {'default:cobble', 'default:cobble'},
  316. {'default:cobble', 'default:stick'},
  317. {'', 'default:stick'},
  318. }
  319. })
  320. minetest.register_craft({
  321. output = 'default:axe_steel',
  322. recipe = {
  323. {'default:steel_ingot', 'default:steel_ingot'},
  324. {'default:steel_ingot', 'default:stick'},
  325. {'', 'default:stick'},
  326. }
  327. })
  328. minetest.register_craft({
  329. output = 'default:sword_wood',
  330. recipe = {
  331. {'default:wood'},
  332. {'default:wood'},
  333. {'default:stick'},
  334. }
  335. })
  336. minetest.register_craft({
  337. output = 'default:sword_stone',
  338. recipe = {
  339. {'default:cobble'},
  340. {'default:cobble'},
  341. {'default:stick'},
  342. }
  343. })
  344. minetest.register_craft({
  345. output = 'default:sword_steel',
  346. recipe = {
  347. {'default:steel_ingot'},
  348. {'default:steel_ingot'},
  349. {'default:stick'},
  350. }
  351. })
  352. minetest.register_craft({
  353. output = 'default:rail 15',
  354. recipe = {
  355. {'default:steel_ingot', '', 'default:steel_ingot'},
  356. {'default:steel_ingot', 'default:stick', 'default:steel_ingot'},
  357. {'default:steel_ingot', '', 'default:steel_ingot'},
  358. }
  359. })
  360. minetest.register_craft({
  361. output = 'default:chest',
  362. recipe = {
  363. {'default:wood', 'default:wood', 'default:wood'},
  364. {'default:wood', '', 'default:wood'},
  365. {'default:wood', 'default:wood', 'default:wood'},
  366. }
  367. })
  368. minetest.register_craft({
  369. output = 'default:chest_locked',
  370. recipe = {
  371. {'default:wood', 'default:wood', 'default:wood'},
  372. {'default:wood', 'default:steel_ingot', 'default:wood'},
  373. {'default:wood', 'default:wood', 'default:wood'},
  374. }
  375. })
  376. minetest.register_craft({
  377. output = 'default:furnace',
  378. recipe = {
  379. {'default:cobble', 'default:cobble', 'default:cobble'},
  380. {'default:cobble', '', 'default:cobble'},
  381. {'default:cobble', 'default:cobble', 'default:cobble'},
  382. }
  383. })
  384. minetest.register_craft({
  385. output = 'default:steelblock',
  386. recipe = {
  387. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  388. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  389. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  390. }
  391. })
  392. minetest.register_craft({
  393. output = 'default:sandstone',
  394. recipe = {
  395. {'default:sand', 'default:sand'},
  396. {'default:sand', 'default:sand'},
  397. }
  398. })
  399. minetest.register_craft({
  400. output = 'default:clay',
  401. recipe = {
  402. {'default:clay_lump', 'default:clay_lump'},
  403. {'default:clay_lump', 'default:clay_lump'},
  404. }
  405. })
  406. minetest.register_craft({
  407. output = 'default:brick',
  408. recipe = {
  409. {'default:clay_brick', 'default:clay_brick'},
  410. {'default:clay_brick', 'default:clay_brick'},
  411. }
  412. })
  413. minetest.register_craft({
  414. output = 'default:paper',
  415. recipe = {
  416. {'default:papyrus', 'default:papyrus', 'default:papyrus'},
  417. }
  418. })
  419. minetest.register_craft({
  420. output = 'default:book',
  421. recipe = {
  422. {'default:paper'},
  423. {'default:paper'},
  424. {'default:paper'},
  425. }
  426. })
  427. minetest.register_craft({
  428. output = 'default:bookshelf',
  429. recipe = {
  430. {'default:wood', 'default:wood', 'default:wood'},
  431. {'default:book', 'default:book', 'default:book'},
  432. {'default:wood', 'default:wood', 'default:wood'},
  433. }
  434. })
  435. minetest.register_craft({
  436. output = 'default:ladder',
  437. recipe = {
  438. {'default:stick', '', 'default:stick'},
  439. {'default:stick', 'default:stick', 'default:stick'},
  440. {'default:stick', '', 'default:stick'},
  441. }
  442. })
  443. -- Tool repair
  444. minetest.register_craft({
  445. type = "toolrepair",
  446. additional_wear = -0.02,
  447. })
  448. --
  449. -- Cooking recipes
  450. --
  451. minetest.register_craft({
  452. type = "cooking",
  453. output = "default:glass",
  454. recipe = "default:sand",
  455. })
  456. minetest.register_craft({
  457. type = "cooking",
  458. output = "default:coal_lump",
  459. recipe = "default:tree",
  460. })
  461. minetest.register_craft({
  462. type = "cooking",
  463. output = "default:stone",
  464. recipe = "default:cobble",
  465. })
  466. minetest.register_craft({
  467. type = "cooking",
  468. output = "default:steel_ingot",
  469. recipe = "default:iron_lump",
  470. })
  471. minetest.register_craft({
  472. type = "cooking",
  473. output = "default:clay_brick",
  474. recipe = "default:clay_lump",
  475. })
  476. --
  477. -- Fuels
  478. --
  479. minetest.register_craft({
  480. type = "fuel",
  481. recipe = "default:tree",
  482. burntime = 30,
  483. })
  484. minetest.register_craft({
  485. type = "fuel",
  486. recipe = "default:junglegrass",
  487. burntime = 2,
  488. })
  489. minetest.register_craft({
  490. type = "fuel",
  491. recipe = "default:leaves",
  492. burntime = 1,
  493. })
  494. minetest.register_craft({
  495. type = "fuel",
  496. recipe = "default:cactus",
  497. burntime = 15,
  498. })
  499. minetest.register_craft({
  500. type = "fuel",
  501. recipe = "default:papyrus",
  502. burntime = 1,
  503. })
  504. minetest.register_craft({
  505. type = "fuel",
  506. recipe = "default:bookshelf",
  507. burntime = 30,
  508. })
  509. minetest.register_craft({
  510. type = "fuel",
  511. recipe = "default:fence_wood",
  512. burntime = 15,
  513. })
  514. minetest.register_craft({
  515. type = "fuel",
  516. recipe = "default:ladder",
  517. burntime = 5,
  518. })
  519. minetest.register_craft({
  520. type = "fuel",
  521. recipe = "default:wood",
  522. burntime = 7,
  523. })
  524. minetest.register_craft({
  525. type = "fuel",
  526. recipe = "default:mese",
  527. burntime = 30,
  528. })
  529. minetest.register_craft({
  530. type = "fuel",
  531. recipe = "default:lava_source",
  532. burntime = 60,
  533. })
  534. minetest.register_craft({
  535. type = "fuel",
  536. recipe = "default:torch",
  537. burntime = 4,
  538. })
  539. minetest.register_craft({
  540. type = "fuel",
  541. recipe = "default:sign_wall",
  542. burntime = 10,
  543. })
  544. minetest.register_craft({
  545. type = "fuel",
  546. recipe = "default:chest",
  547. burntime = 30,
  548. })
  549. minetest.register_craft({
  550. type = "fuel",
  551. recipe = "default:chest_locked",
  552. burntime = 30,
  553. })
  554. minetest.register_craft({
  555. type = "fuel",
  556. recipe = "default:nyancat",
  557. burntime = 1,
  558. })
  559. minetest.register_craft({
  560. type = "fuel",
  561. recipe = "default:nyancat_rainbow",
  562. burntime = 1,
  563. })
  564. minetest.register_craft({
  565. type = "fuel",
  566. recipe = "default:sapling",
  567. burntime = 10,
  568. })
  569. minetest.register_craft({
  570. type = "fuel",
  571. recipe = "default:apple",
  572. burntime = 3,
  573. })
  574. minetest.register_craft({
  575. type = "fuel",
  576. recipe = "default:coal_lump",
  577. burntime = 40,
  578. })
  579. --
  580. -- Node definitions
  581. --
  582. -- Default node sounds
  583. function default.node_sound_defaults(table)
  584. table = table or {}
  585. table.footstep = table.footstep or
  586. {name="", gain=1.0}
  587. table.dug = table.dug or
  588. {name="default_dug_node", gain=1.0}
  589. return table
  590. end
  591. function default.node_sound_stone_defaults(table)
  592. table = table or {}
  593. table.footstep = table.footstep or
  594. {name="default_hard_footstep", gain=0.2}
  595. default.node_sound_defaults(table)
  596. return table
  597. end
  598. function default.node_sound_dirt_defaults(table)
  599. table = table or {}
  600. table.footstep = table.footstep or
  601. {name="", gain=0.5}
  602. --table.dug = table.dug or
  603. -- {name="default_dirt_break", gain=0.5}
  604. table.place = table.place or
  605. {name="default_grass_footstep", gain=0.5}
  606. default.node_sound_defaults(table)
  607. return table
  608. end
  609. function default.node_sound_sand_defaults(table)
  610. table = table or {}
  611. table.footstep = table.footstep or
  612. {name="default_grass_footstep", gain=0.25}
  613. --table.dug = table.dug or
  614. -- {name="default_dirt_break", gain=0.25}
  615. table.dug = table.dug or
  616. {name="", gain=0.25}
  617. default.node_sound_defaults(table)
  618. return table
  619. end
  620. function default.node_sound_wood_defaults(table)
  621. table = table or {}
  622. table.footstep = table.footstep or
  623. {name="default_hard_footstep", gain=0.3}
  624. default.node_sound_defaults(table)
  625. return table
  626. end
  627. function default.node_sound_leaves_defaults(table)
  628. table = table or {}
  629. table.footstep = table.footstep or
  630. {name="default_grass_footstep", gain=0.25}
  631. table.dig = table.dig or
  632. {name="default_dig_crumbly", gain=0.4}
  633. table.dug = table.dug or
  634. {name="", gain=1.0}
  635. default.node_sound_defaults(table)
  636. return table
  637. end
  638. function default.node_sound_glass_defaults(table)
  639. table = table or {}
  640. table.footstep = table.footstep or
  641. {name="default_stone_footstep", gain=0.25}
  642. table.dug = table.dug or
  643. {name="default_break_glass", gain=1.0}
  644. default.node_sound_defaults(table)
  645. return table
  646. end
  647. -- Register nodes
  648. minetest.register_node("default:stone", {
  649. description = "Stone",
  650. tiles ={"default_stone.png"},
  651. groups = {cracky=3},
  652. drop = 'default:cobble',
  653. legacy_mineral = true,
  654. sounds = default.node_sound_stone_defaults(),
  655. })
  656. minetest.register_node("default:stone_with_coal", {
  657. description = "Stone with coal",
  658. tiles ={"default_stone.png^default_mineral_coal.png"},
  659. groups = {cracky=3},
  660. drop = 'default:coal_lump',
  661. sounds = default.node_sound_stone_defaults(),
  662. })
  663. minetest.register_node("default:stone_with_iron", {
  664. description = "Stone with iron",
  665. tiles ={"default_stone.png^default_mineral_iron.png"},
  666. groups = {cracky=3},
  667. drop = 'default:iron_lump',
  668. sounds = default.node_sound_stone_defaults(),
  669. })
  670. minetest.register_node("default:dirt_with_grass", {
  671. description = "Dirt with grass",
  672. tiles ={"default_grass.png", "default_dirt.png",
  673. {name = "default_dirt.png^default_grass_side.png",
  674. tileable_vertical = false}},
  675. groups = {crumbly=3, soil=1},
  676. drop = 'default:dirt',
  677. sounds = default.node_sound_dirt_defaults({
  678. footstep = {name="default_grass_footstep", gain=0.4},
  679. }),
  680. })
  681. minetest.register_node("default:dirt_with_grass_footsteps", {
  682. description = "Dirt with grass and footsteps",
  683. tiles ={"default_grass_footsteps.png", "default_dirt.png",
  684. {name = "default_dirt.png^default_grass_side.png",
  685. tileable_vertical = false}},
  686. groups = {crumbly=3, soil=1},
  687. drop = 'default:dirt',
  688. sounds = default.node_sound_dirt_defaults({
  689. footstep = {name="default_grass_footstep", gain=0.4},
  690. }),
  691. })
  692. minetest.register_node("default:dirt", {
  693. description = "Dirt",
  694. tiles ={"default_dirt.png"},
  695. groups = {crumbly=3, soil=1},
  696. sounds = default.node_sound_dirt_defaults(),
  697. })
  698. minetest.register_node("default:sand", {
  699. description = "Sand",
  700. tiles ={"default_sand.png"},
  701. groups = {crumbly=3, falling_node=1},
  702. sounds = default.node_sound_sand_defaults(),
  703. })
  704. minetest.register_node("default:gravel", {
  705. description = "Gravel",
  706. tiles ={"default_gravel.png"},
  707. groups = {crumbly=2, falling_node=1},
  708. sounds = default.node_sound_dirt_defaults({
  709. footstep = {name="default_gravel_footstep", gain=0.45},
  710. }),
  711. })
  712. minetest.register_node("default:sandstone", {
  713. description = "Sandstone",
  714. tiles ={"default_sandstone.png"},
  715. groups = {crumbly=2,cracky=2},
  716. drop = 'default:sand',
  717. sounds = default.node_sound_stone_defaults(),
  718. })
  719. minetest.register_node("default:clay", {
  720. description = "Clay",
  721. tiles ={"default_clay.png"},
  722. groups = {crumbly=3},
  723. drop = 'default:clay_lump 4',
  724. sounds = default.node_sound_dirt_defaults({
  725. footstep = "",
  726. }),
  727. })
  728. minetest.register_node("default:brick", {
  729. description = "Brick",
  730. tiles ={"default_brick.png"},
  731. is_ground_content = false,
  732. groups = {cracky=3},
  733. drop = 'default:clay_brick 4',
  734. sounds = default.node_sound_stone_defaults(),
  735. })
  736. minetest.register_node("default:tree", {
  737. description = "Tree",
  738. tiles ={"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
  739. is_ground_content = false,
  740. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1},
  741. sounds = default.node_sound_wood_defaults(),
  742. })
  743. minetest.register_node("default:junglegrass", {
  744. description = "Jungle Grass",
  745. drawtype = "plantlike",
  746. visual_scale = 1.3,
  747. tiles ={"default_junglegrass.png"},
  748. inventory_image = "default_junglegrass.png",
  749. wield_image = "default_junglegrass.png",
  750. paramtype = "light",
  751. walkable = false,
  752. groups = {snappy=3,attached_node=1},
  753. sounds = default.node_sound_leaves_defaults(),
  754. })
  755. minetest.register_node("default:leaves", {
  756. description = "Leaves",
  757. drawtype = "allfaces_optional",
  758. visual_scale = 1.3,
  759. tiles ={"default_leaves.png"},
  760. paramtype = "light",
  761. is_ground_content = false,
  762. groups = {snappy=3},
  763. drop = {
  764. max_items = 1,
  765. items = {
  766. {
  767. -- player will get sapling with 1/20 chance
  768. items = {'default:sapling'},
  769. rarity = 20,
  770. },
  771. {
  772. -- player will get leaves only if he get no saplings,
  773. -- this is because max_items is 1
  774. items = {'default:leaves'},
  775. }
  776. }
  777. },
  778. sounds = default.node_sound_leaves_defaults(),
  779. })
  780. minetest.register_node("default:cactus", {
  781. description = "Cactus",
  782. tiles ={"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
  783. groups = {snappy=2,choppy=3},
  784. sounds = default.node_sound_wood_defaults(),
  785. })
  786. minetest.register_node("default:papyrus", {
  787. description = "Papyrus",
  788. drawtype = "plantlike",
  789. tiles ={"default_papyrus.png"},
  790. inventory_image = "default_papyrus.png",
  791. wield_image = "default_papyrus.png",
  792. paramtype = "light",
  793. walkable = false,
  794. groups = {snappy=3},
  795. sounds = default.node_sound_leaves_defaults(),
  796. })
  797. minetest.register_node("default:bookshelf", {
  798. description = "Bookshelf",
  799. tiles ={"default_wood.png", "default_wood.png", "default_bookshelf.png"},
  800. is_ground_content = false,
  801. groups = {snappy=2,choppy=3,oddly_breakable_by_hand=2},
  802. sounds = default.node_sound_wood_defaults(),
  803. })
  804. minetest.register_node("default:glass", {
  805. description = "Glass",
  806. drawtype = "glasslike",
  807. tiles ={"default_glass.png"},
  808. paramtype = "light",
  809. is_ground_content = false,
  810. sunlight_propagates = true,
  811. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
  812. sounds = default.node_sound_glass_defaults(),
  813. })
  814. minetest.register_node("default:fence_wood", {
  815. description = "Wooden Fence",
  816. drawtype = "fencelike",
  817. tiles ={"default_wood.png"},
  818. inventory_image = "default_fence.png",
  819. wield_image = "default_fence.png",
  820. paramtype = "light",
  821. is_ground_content = false,
  822. selection_box = {
  823. type = "fixed",
  824. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  825. },
  826. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  827. sounds = default.node_sound_wood_defaults(),
  828. })
  829. minetest.register_node("default:rail", {
  830. description = "Rail",
  831. drawtype = "raillike",
  832. tiles ={"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
  833. inventory_image = "default_rail.png",
  834. wield_image = "default_rail.png",
  835. paramtype = "light",
  836. is_ground_content = false,
  837. walkable = false,
  838. selection_box = {
  839. type = "fixed",
  840. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  841. },
  842. groups = {bendy=2,snappy=1,dig_immediate=2},
  843. })
  844. minetest.register_node("default:ladder", {
  845. description = "Ladder",
  846. drawtype = "signlike",
  847. tiles ={"default_ladder.png"},
  848. inventory_image = "default_ladder.png",
  849. wield_image = "default_ladder.png",
  850. paramtype = "light",
  851. paramtype2 = "wallmounted",
  852. is_ground_content = false,
  853. walkable = false,
  854. climbable = true,
  855. selection_box = {
  856. type = "wallmounted",
  857. --wall_top = = <default>
  858. --wall_bottom = = <default>
  859. --wall_side = = <default>
  860. },
  861. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
  862. legacy_wallmounted = true,
  863. sounds = default.node_sound_wood_defaults(),
  864. })
  865. minetest.register_node("default:wood", {
  866. description = "Wood",
  867. tiles ={"default_wood.png"},
  868. is_ground_content = false,
  869. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  870. sounds = default.node_sound_wood_defaults(),
  871. })
  872. minetest.register_node("default:mese", {
  873. description = "Mese",
  874. tiles ={"default_mese.png"},
  875. groups = {cracky=1,level=2},
  876. sounds = default.node_sound_defaults(),
  877. })
  878. minetest.register_node("default:cloud", {
  879. description = "Cloud",
  880. tiles ={"default_cloud.png"},
  881. is_ground_content = false,
  882. sounds = default.node_sound_defaults(),
  883. })
  884. minetest.register_node("default:water_flowing", {
  885. description = "Water (flowing)",
  886. drawtype = "flowingliquid",
  887. tiles = {"default_water.png"},
  888. special_tiles = {
  889. {name = "default_water.png", backface_culling = false},
  890. {name = "default_water.png", backface_culling = true},
  891. },
  892. alpha = WATER_ALPHA,
  893. paramtype = "light",
  894. paramtype2 = "flowingliquid",
  895. walkable = false,
  896. pointable = false,
  897. diggable = false,
  898. buildable_to = true,
  899. is_ground_content = false,
  900. drop = "",
  901. drowning = 1,
  902. liquidtype = "flowing",
  903. liquid_alternative_flowing = "default:water_flowing",
  904. liquid_alternative_source = "default:water_source",
  905. liquid_viscosity = WATER_VISC,
  906. post_effect_color = {a = 64, r = 100, g = 100, b = 200},
  907. groups = {water = 3, liquid = 3},
  908. })
  909. minetest.register_node("default:water_source", {
  910. description = "Water",
  911. drawtype = "liquid",
  912. tiles = {"default_water.png"},
  913. special_tiles = {
  914. -- New-style water source material (mostly unused)
  915. {name = "default_water.png", backface_culling = false},
  916. },
  917. alpha = WATER_ALPHA,
  918. paramtype = "light",
  919. walkable = false,
  920. pointable = false,
  921. diggable = false,
  922. buildable_to = true,
  923. is_ground_content = false,
  924. drop = "",
  925. drowning = 1,
  926. liquidtype = "source",
  927. liquid_alternative_flowing = "default:water_flowing",
  928. liquid_alternative_source = "default:water_source",
  929. liquid_viscosity = WATER_VISC,
  930. post_effect_color = {a = 64, r = 100, g = 100, b = 200},
  931. groups = {water = 3, liquid = 3},
  932. })
  933. minetest.register_node("default:river_water_source", {
  934. description = "River Water Source",
  935. drawtype = "liquid",
  936. tiles = {"default_river_water.png"},
  937. special_tiles = {
  938. -- New-style water source material (mostly unused)
  939. {name = "default_river_water.png", backface_culling = false},
  940. },
  941. alpha = 160,
  942. paramtype = "light",
  943. walkable = false,
  944. pointable = false,
  945. diggable = false,
  946. buildable_to = true,
  947. is_ground_content = false,
  948. drop = "",
  949. drowning = 1,
  950. liquidtype = "source",
  951. liquid_alternative_flowing = "default:river_water_flowing",
  952. liquid_alternative_source = "default:river_water_source",
  953. liquid_viscosity = 1,
  954. liquid_renewable = false,
  955. liquid_range = 2,
  956. post_effect_color = {a = 103, r = 30, g = 76, b = 90},
  957. groups = {water = 3, liquid = 3, puts_out_fire = 1, cools_lava = 1},
  958. })
  959. minetest.register_node("default:river_water_flowing", {
  960. description = "Flowing River Water",
  961. drawtype = "flowingliquid",
  962. tiles = {"default_river_water.png"},
  963. special_tiles = {
  964. {name = "default_river_water.png", backface_culling = false},
  965. {name = "default_river_water.png", backface_culling = true},
  966. },
  967. alpha = 160,
  968. paramtype = "light",
  969. paramtype2 = "flowingliquid",
  970. walkable = false,
  971. pointable = false,
  972. diggable = false,
  973. buildable_to = true,
  974. is_ground_content = false,
  975. drop = "",
  976. drowning = 1,
  977. liquidtype = "flowing",
  978. liquid_alternative_flowing = "default:river_water_flowing",
  979. liquid_alternative_source = "default:river_water_source",
  980. liquid_viscosity = 1,
  981. liquid_renewable = false,
  982. liquid_range = 2,
  983. post_effect_color = {a = 103, r = 30, g = 76, b = 90},
  984. groups = {water = 3, liquid = 3, puts_out_fire = 1,
  985. not_in_creative_inventory = 1, cools_lava = 1},
  986. })
  987. minetest.register_node("default:lava_flowing", {
  988. description = "Lava (flowing)",
  989. inventory_image = minetest.inventorycube("default_lava.png"),
  990. drawtype = "flowingliquid",
  991. tiles ={"default_lava.png"},
  992. special_tiles = {
  993. {
  994. image="default_lava_flowing_animated.png",
  995. backface_culling=false,
  996. animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.3}
  997. },
  998. {
  999. image="default_lava_flowing_animated.png",
  1000. backface_culling=true,
  1001. animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.3}
  1002. },
  1003. },
  1004. paramtype = "light",
  1005. light_source = LIGHT_MAX - 1,
  1006. walkable = false,
  1007. pointable = false,
  1008. diggable = false,
  1009. buildable_to = true,
  1010. is_ground_content = false,
  1011. drowning = 1,
  1012. liquidtype = "flowing",
  1013. liquid_alternative_flowing = "default:lava_flowing",
  1014. liquid_alternative_source = "default:lava_source",
  1015. liquid_viscosity = LAVA_VISC,
  1016. damage_per_second = 4*2,
  1017. post_effect_color = {a=192, r=255, g=64, b=0},
  1018. groups = {lava=3, liquid=2, hot=3},
  1019. })
  1020. minetest.register_node("default:lava_source", {
  1021. description = "Lava",
  1022. inventory_image = minetest.inventorycube("default_lava.png"),
  1023. drawtype = "liquid",
  1024. --tiles ={"default_lava.png"},
  1025. tiles = {
  1026. {
  1027. name = "default_lava_source_animated.png",
  1028. animation = {type="sheet_2d", frames_w=3, frames_h=2, frame_length=0.5}
  1029. }
  1030. },
  1031. special_tiles = {
  1032. -- New-style lava source material (mostly unused)
  1033. {name="default_lava.png", backface_culling=false},
  1034. },
  1035. paramtype = "light",
  1036. light_source = LIGHT_MAX - 1,
  1037. walkable = false,
  1038. pointable = false,
  1039. diggable = false,
  1040. buildable_to = true,
  1041. is_ground_content = false,
  1042. drowning = 1,
  1043. liquidtype = "source",
  1044. liquid_alternative_flowing = "default:lava_flowing",
  1045. liquid_alternative_source = "default:lava_source",
  1046. liquid_viscosity = LAVA_VISC,
  1047. damage_per_second = 4*2,
  1048. post_effect_color = {a=192, r=255, g=64, b=0},
  1049. groups = {lava=3, liquid=2, hot=3},
  1050. })
  1051. minetest.register_node("default:torch", {
  1052. description = "Torch",
  1053. drawtype = "torchlike",
  1054. tiles ={"default_torch_on_floor.png", "default_torch_on_ceiling.png", "default_torch.png"},
  1055. inventory_image = "default_torch_on_floor.png",
  1056. wield_image = "default_torch_on_floor.png",
  1057. paramtype = "light",
  1058. paramtype2 = "wallmounted",
  1059. sunlight_propagates = true,
  1060. is_ground_content = false,
  1061. walkable = false,
  1062. light_source = LIGHT_MAX-1,
  1063. selection_box = {
  1064. type = "wallmounted",
  1065. wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
  1066. wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
  1067. wall_side = {-0.5, -0.3, -0.1, -0.5+0.3, 0.3, 0.1},
  1068. },
  1069. groups = {choppy=2,dig_immediate=3,attached_node=1},
  1070. legacy_wallmounted = true,
  1071. sounds = default.node_sound_defaults(),
  1072. })
  1073. minetest.register_node("default:sign_wall", {
  1074. description = "Sign",
  1075. drawtype = "signlike",
  1076. tiles ={"default_sign_wall.png"},
  1077. inventory_image = "default_sign_wall.png",
  1078. wield_image = "default_sign_wall.png",
  1079. paramtype = "light",
  1080. paramtype2 = "wallmounted",
  1081. sunlight_propagates = true,
  1082. is_ground_content = false,
  1083. walkable = false,
  1084. selection_box = {
  1085. type = "wallmounted",
  1086. --wall_top = <default>
  1087. --wall_bottom = <default>
  1088. --wall_side = <default>
  1089. },
  1090. groups = {choppy=2,dig_immediate=2,attached_node=1},
  1091. legacy_wallmounted = true,
  1092. sounds = default.node_sound_defaults(),
  1093. on_construct = function(pos)
  1094. --local n = minetest.get_node(pos)
  1095. local meta = minetest.get_meta(pos)
  1096. meta:set_string("formspec", "field[text;;${text}]")
  1097. meta:set_string("infotext", "\"\"")
  1098. end,
  1099. on_receive_fields = function(pos, formname, fields, sender)
  1100. --print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields))
  1101. local meta = minetest.get_meta(pos)
  1102. fields.text = fields.text or ""
  1103. print((sender:get_player_name() or "").." wrote \""..fields.text..
  1104. "\" to sign at "..minetest.pos_to_string(pos))
  1105. meta:set_string("text", fields.text)
  1106. meta:set_string("infotext", '"'..fields.text..'"')
  1107. end,
  1108. })
  1109. minetest.register_node("default:chest", {
  1110. description = "Chest",
  1111. tiles ={"default_chest.png^[sheet:2x2:0,0", "default_chest.png^[sheet:2x2:0,0",
  1112. "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,0",
  1113. "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:0,1"},
  1114. paramtype2 = "facedir",
  1115. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  1116. legacy_facedir_simple = true,
  1117. is_ground_content = false,
  1118. sounds = default.node_sound_wood_defaults(),
  1119. on_construct = function(pos)
  1120. local meta = minetest.get_meta(pos)
  1121. meta:set_string("formspec",
  1122. "size[8,9]"..
  1123. "list[current_name;main;0,0;8,4;]"..
  1124. "list[current_player;main;0,5;8,4;]" ..
  1125. "listring[]")
  1126. meta:set_string("infotext", "Chest")
  1127. local inv = meta:get_inventory()
  1128. inv:set_size("main", 8*4)
  1129. end,
  1130. can_dig = function(pos,player)
  1131. local meta = minetest.get_meta(pos);
  1132. local inv = meta:get_inventory()
  1133. return inv:is_empty("main")
  1134. end,
  1135. })
  1136. local function has_locked_chest_privilege(meta, player)
  1137. if player:get_player_name() ~= meta:get_string("owner") then
  1138. return false
  1139. end
  1140. return true
  1141. end
  1142. minetest.register_node("default:chest_locked", {
  1143. description = "Locked Chest",
  1144. tiles ={"default_chest.png^[sheet:2x2:0,0", "default_chest.png^[sheet:2x2:0,0",
  1145. "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,0",
  1146. "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,1"},
  1147. paramtype2 = "facedir",
  1148. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  1149. legacy_facedir_simple = true,
  1150. is_ground_content = false,
  1151. sounds = default.node_sound_wood_defaults(),
  1152. after_place_node = function(pos, placer)
  1153. local meta = minetest.get_meta(pos)
  1154. local pname =
  1155. placer and placer:get_player_name() or ""
  1156. meta:set_string("owner", pname)
  1157. meta:set_string("infotext", "Locked Chest (owned by "..
  1158. meta:get_string("owner")..")")
  1159. end,
  1160. on_construct = function(pos)
  1161. local meta = minetest.get_meta(pos)
  1162. meta:set_string("formspec",
  1163. "size[8,9]"..
  1164. "list[current_name;main;0,0;8,4;]"..
  1165. "list[current_player;main;0,5;8,4;]" ..
  1166. "listring[]")
  1167. meta:set_string("infotext", "Locked Chest")
  1168. meta:set_string("owner", "")
  1169. local inv = meta:get_inventory()
  1170. inv:set_size("main", 8*4)
  1171. -- this is not really the intended usage but works for testing purposes:
  1172. meta:mark_as_private("owner")
  1173. end,
  1174. can_dig = function(pos,player)
  1175. local meta = minetest.get_meta(pos);
  1176. local inv = meta:get_inventory()
  1177. return inv:is_empty("main")
  1178. end,
  1179. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  1180. local meta = minetest.get_meta(pos)
  1181. if not has_locked_chest_privilege(meta, player) then
  1182. minetest.log("action", player:get_player_name()..
  1183. " tried to access a locked chest belonging to "..
  1184. meta:get_string("owner").." at "..
  1185. minetest.pos_to_string(pos))
  1186. return 0
  1187. end
  1188. return count
  1189. end,
  1190. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  1191. local meta = minetest.get_meta(pos)
  1192. if not has_locked_chest_privilege(meta, player) then
  1193. minetest.log("action", player:get_player_name()..
  1194. " tried to access a locked chest belonging to "..
  1195. meta:get_string("owner").." at "..
  1196. minetest.pos_to_string(pos))
  1197. return 0
  1198. end
  1199. return stack:get_count()
  1200. end,
  1201. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  1202. local meta = minetest.get_meta(pos)
  1203. if not has_locked_chest_privilege(meta, player) then
  1204. minetest.log("action", player:get_player_name()..
  1205. " tried to access a locked chest belonging to "..
  1206. meta:get_string("owner").." at "..
  1207. minetest.pos_to_string(pos))
  1208. return 0
  1209. end
  1210. return stack:get_count()
  1211. end,
  1212. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  1213. minetest.log("action", player:get_player_name()..
  1214. " moves stuff in locked chest at "..minetest.pos_to_string(pos))
  1215. end,
  1216. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  1217. minetest.log("action", player:get_player_name()..
  1218. " moves stuff to locked chest at "..minetest.pos_to_string(pos))
  1219. end,
  1220. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  1221. minetest.log("action", player:get_player_name()..
  1222. " takes stuff from locked chest at "..minetest.pos_to_string(pos))
  1223. end,
  1224. })
  1225. default.furnace_inactive_formspec =
  1226. "size[8,9]"..
  1227. "image[2,2;1,1;default_furnace_fire_bg.png]"..
  1228. "list[current_name;fuel;2,3;1,1;]"..
  1229. "list[current_name;src;2,1;1,1;]"..
  1230. "list[current_name;dst;5,1;2,2;]"..
  1231. "list[current_player;main;0,5;8,4;]" ..
  1232. "listring[current_name;dst]" ..
  1233. "listring[current_player;main]" ..
  1234. "listring[current_name;src]" ..
  1235. "listring[current_player;main]"
  1236. minetest.register_node("default:furnace", {
  1237. description = "Furnace",
  1238. tiles ={"default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png",
  1239. "default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"},
  1240. paramtype2 = "facedir",
  1241. groups = {cracky=2},
  1242. legacy_facedir_simple = true,
  1243. is_ground_content = false,
  1244. sounds = default.node_sound_stone_defaults(),
  1245. on_construct = function(pos)
  1246. local meta = minetest.get_meta(pos)
  1247. meta:set_string("formspec", default.furnace_inactive_formspec)
  1248. meta:set_string("infotext", "Furnace")
  1249. local inv = meta:get_inventory()
  1250. inv:set_size("fuel", 1)
  1251. inv:set_size("src", 1)
  1252. inv:set_size("dst", 4)
  1253. end,
  1254. can_dig = function(pos,player)
  1255. local meta = minetest.get_meta(pos);
  1256. local inv = meta:get_inventory()
  1257. if not inv:is_empty("fuel") then
  1258. return false
  1259. elseif not inv:is_empty("dst") then
  1260. return false
  1261. elseif not inv:is_empty("src") then
  1262. return false
  1263. end
  1264. return true
  1265. end,
  1266. })
  1267. minetest.register_node("default:furnace_active", {
  1268. description = "Furnace",
  1269. tiles ={"default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png",
  1270. "default_furnace_side.png", "default_furnace_side.png", "default_furnace_front_active.png"},
  1271. paramtype2 = "facedir",
  1272. light_source = 8,
  1273. drop = "default:furnace",
  1274. groups = {cracky=2},
  1275. legacy_facedir_simple = true,
  1276. is_ground_content = false,
  1277. sounds = default.node_sound_stone_defaults(),
  1278. on_construct = function(pos)
  1279. local meta = minetest.get_meta(pos)
  1280. meta:set_string("formspec", default.furnace_inactive_formspec)
  1281. meta:set_string("infotext", "Furnace");
  1282. local inv = meta:get_inventory()
  1283. inv:set_size("fuel", 1)
  1284. inv:set_size("src", 1)
  1285. inv:set_size("dst", 4)
  1286. end,
  1287. can_dig = function(pos,player)
  1288. local meta = minetest.get_meta(pos);
  1289. local inv = meta:get_inventory()
  1290. if not inv:is_empty("fuel") then
  1291. return false
  1292. elseif not inv:is_empty("dst") then
  1293. return false
  1294. elseif not inv:is_empty("src") then
  1295. return false
  1296. end
  1297. return true
  1298. end,
  1299. })
  1300. function swap_node(pos,name)
  1301. local node = minetest.get_node(pos)
  1302. if node.name == name then
  1303. return
  1304. end
  1305. node.name = name
  1306. minetest.swap_node(pos, node)
  1307. end
  1308. minetest.register_abm({
  1309. nodenames = {"default:furnace","default:furnace_active"},
  1310. interval = 1.0,
  1311. chance = 1,
  1312. action = function(pos, node, active_object_count, active_object_count_wider)
  1313. local meta = minetest.get_meta(pos)
  1314. for i, name in ipairs({
  1315. "fuel_totaltime",
  1316. "fuel_time",
  1317. "src_totaltime",
  1318. "src_time"
  1319. }) do
  1320. if meta:get_string(name) == "" then
  1321. meta:set_float(name, 0.0)
  1322. end
  1323. end
  1324. local inv = meta:get_inventory()
  1325. local srclist = inv:get_list("src")
  1326. local cooked = nil
  1327. if srclist then
  1328. cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  1329. end
  1330. local was_active = false
  1331. if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
  1332. was_active = true
  1333. meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
  1334. meta:set_float("src_time", meta:get_float("src_time") + 1)
  1335. if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
  1336. -- check if there's room for output in "dst" list
  1337. if inv:room_for_item("dst",cooked.item) then
  1338. -- Put result in "dst" list
  1339. inv:add_item("dst", cooked.item)
  1340. -- take stuff from "src" list
  1341. srcstack = inv:get_stack("src", 1)
  1342. srcstack:take_item()
  1343. inv:set_stack("src", 1, srcstack)
  1344. else
  1345. print("Could not insert '"..cooked.item:to_string().."'")
  1346. end
  1347. meta:set_string("src_time", 0)
  1348. end
  1349. end
  1350. if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
  1351. local percent = math.floor(meta:get_float("fuel_time") /
  1352. meta:get_float("fuel_totaltime") * 100)
  1353. meta:set_string("infotext","Furnace active: "..percent.."%")
  1354. swap_node(pos,"default:furnace_active")
  1355. meta:set_string("formspec",
  1356. "size[8,9]"..
  1357. "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
  1358. (100-percent)..":default_furnace_fire_fg.png]"..
  1359. "list[current_name;fuel;2,3;1,1;]"..
  1360. "list[current_name;src;2,1;1,1;]"..
  1361. "list[current_name;dst;5,1;2,2;]"..
  1362. "list[current_player;main;0,5;8,4;]" ..
  1363. "listring[current_name;dst]" ..
  1364. "listring[current_player;main]" ..
  1365. "listring[current_name;src]" ..
  1366. "listring[current_player;main]")
  1367. return
  1368. end
  1369. local fuel = nil
  1370. local cooked = nil
  1371. local fuellist = inv:get_list("fuel")
  1372. local srclist = inv:get_list("src")
  1373. if srclist then
  1374. cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  1375. end
  1376. if fuellist then
  1377. fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
  1378. end
  1379. if fuel.time <= 0 then
  1380. meta:set_string("infotext","Furnace out of fuel")
  1381. swap_node(pos,"default:furnace")
  1382. meta:set_string("formspec", default.furnace_inactive_formspec)
  1383. return
  1384. end
  1385. if cooked.item:is_empty() then
  1386. if was_active then
  1387. meta:set_string("infotext","Furnace is empty")
  1388. swap_node(pos,"default:furnace")
  1389. meta:set_string("formspec", default.furnace_inactive_formspec)
  1390. end
  1391. return
  1392. end
  1393. meta:set_string("fuel_totaltime", fuel.time)
  1394. meta:set_string("fuel_time", 0)
  1395. local stack = inv:get_stack("fuel", 1)
  1396. stack:take_item()
  1397. inv:set_stack("fuel", 1, stack)
  1398. end,
  1399. })
  1400. minetest.register_node("default:cobble", {
  1401. description = "Cobble",
  1402. tiles ={"default_cobble.png"},
  1403. is_ground_content = false,
  1404. groups = {cracky=3},
  1405. sounds = default.node_sound_stone_defaults(),
  1406. })
  1407. minetest.register_node("default:mossycobble", {
  1408. description = "Mossy Cobble",
  1409. tiles ={"default_mossycobble.png"},
  1410. is_ground_content = false,
  1411. groups = {cracky=3},
  1412. sounds = default.node_sound_stone_defaults(),
  1413. })
  1414. minetest.register_node("default:steelblock", {
  1415. description = "Steel Block",
  1416. tiles ={"default_steel_block.png"},
  1417. is_ground_content = false,
  1418. groups = {snappy=1,bendy=2},
  1419. sounds = default.node_sound_stone_defaults(),
  1420. })
  1421. minetest.register_node("default:nyancat", {
  1422. description = "Nyancat",
  1423. tiles ={"default_nc_side.png", "default_nc_side.png", "default_nc_side.png",
  1424. "default_nc_side.png", "default_nc_back.png", "default_nc_front.png"},
  1425. inventory_image = "default_nc_front.png",
  1426. paramtype2 = "facedir",
  1427. groups = {cracky=2},
  1428. legacy_facedir_simple = true,
  1429. is_ground_content = false,
  1430. sounds = default.node_sound_defaults(),
  1431. })
  1432. minetest.register_node("default:nyancat_rainbow", {
  1433. description = "Nyancat Rainbow",
  1434. tiles ={"default_nc_rb.png"},
  1435. inventory_image = "default_nc_rb.png",
  1436. is_ground_content = false,
  1437. groups = {cracky=2},
  1438. sounds = default.node_sound_defaults(),
  1439. })
  1440. minetest.register_node("default:sapling", {
  1441. description = "Sapling",
  1442. drawtype = "plantlike",
  1443. visual_scale = 1.0,
  1444. tiles ={"default_sapling.png"},
  1445. inventory_image = "default_sapling.png",
  1446. wield_image = "default_sapling.png",
  1447. paramtype = "light",
  1448. walkable = false,
  1449. groups = {snappy=2,dig_immediate=3,attached_node=1},
  1450. sounds = default.node_sound_defaults(),
  1451. })
  1452. minetest.register_node("default:apple", {
  1453. description = "Apple",
  1454. drawtype = "plantlike",
  1455. visual_scale = 1.0,
  1456. tiles ={"default_apple.png"},
  1457. inventory_image = "default_apple.png",
  1458. paramtype = "light",
  1459. is_ground_content = false,
  1460. sunlight_propagates = true,
  1461. walkable = false,
  1462. groups = {fleshy=3,dig_immediate=3},
  1463. on_use = minetest.item_eat(4),
  1464. sounds = default.node_sound_defaults(),
  1465. })
  1466. --
  1467. -- Grow tree function
  1468. --
  1469. local c_air = minetest.get_content_id("air")
  1470. local c_ignore = minetest.get_content_id("ignore")
  1471. local c_tree = minetest.get_content_id("default:tree")
  1472. local c_leaves = minetest.get_content_id("default:leaves")
  1473. local c_apple = minetest.get_content_id("default:apple")
  1474. function default.grow_tree(data, a, pos, is_apple_tree, seed)
  1475. --[[
  1476. NOTE: Tree-placing code is currently duplicated in the engine
  1477. and in games that have saplings; both are deprecated but not
  1478. replaced yet
  1479. ]]--
  1480. local pr = PseudoRandom(seed)
  1481. local th = pr:next(4, 5)
  1482. local x, y, z = pos.x, pos.y, pos.z
  1483. for yy = y, y+th-1 do
  1484. local vi = a:index(x, yy, z)
  1485. if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then
  1486. data[vi] = c_tree
  1487. end
  1488. end
  1489. y = y+th-1 -- (x, y, z) is now last piece of trunk
  1490. local leaves_a = VoxelArea:new{MinEdge={x=-2, y=-1, z=-2}, MaxEdge={x=2, y=2, z=2}}
  1491. local leaves_buffer = {}
  1492. -- Force leaves near the trunk
  1493. local d = 1
  1494. for xi = -d, d do
  1495. for yi = -d, d do
  1496. for zi = -d, d do
  1497. leaves_buffer[leaves_a:index(xi, yi, zi)] = true
  1498. end
  1499. end
  1500. end
  1501. -- Add leaves randomly
  1502. for iii = 1, 8 do
  1503. local d = 1
  1504. local xx = pr:next(leaves_a.MinEdge.x, leaves_a.MaxEdge.x - d)
  1505. local yy = pr:next(leaves_a.MinEdge.y, leaves_a.MaxEdge.y - d)
  1506. local zz = pr:next(leaves_a.MinEdge.z, leaves_a.MaxEdge.z - d)
  1507. for xi = 0, d do
  1508. for yi = 0, d do
  1509. for zi = 0, d do
  1510. leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true
  1511. end
  1512. end
  1513. end
  1514. end
  1515. -- Add the leaves
  1516. for xi = leaves_a.MinEdge.x, leaves_a.MaxEdge.x do
  1517. for yi = leaves_a.MinEdge.y, leaves_a.MaxEdge.y do
  1518. for zi = leaves_a.MinEdge.z, leaves_a.MaxEdge.z do
  1519. if a:contains(x+xi, y+yi, z+zi) then
  1520. local vi = a:index(x+xi, y+yi, z+zi)
  1521. if data[vi] == c_air or data[vi] == c_ignore then
  1522. if leaves_buffer[leaves_a:index(xi, yi, zi)] then
  1523. if is_apple_tree and pr:next(1, 100) <= 10 then
  1524. data[vi] = c_apple
  1525. else
  1526. data[vi] = c_leaves
  1527. end
  1528. end
  1529. end
  1530. end
  1531. end
  1532. end
  1533. end
  1534. end
  1535. --
  1536. -- ABMs
  1537. --
  1538. minetest.register_abm({
  1539. nodenames = {"default:sapling"},
  1540. interval = 10,
  1541. chance = 50,
  1542. action = function(pos, node)
  1543. if minetest.get_item_group(minetest.get_node(
  1544. {x = pos.x, y = pos.y - 1, z = pos.z}).name, "soil") == 0 then
  1545. return
  1546. end
  1547. print("A sapling grows into a tree at "..minetest.pos_to_string(pos))
  1548. local vm = minetest.get_voxel_manip()
  1549. local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16})
  1550. local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
  1551. local data = vm:get_data()
  1552. default.grow_tree(data, a, pos, math.random(1, 4) == 1, math.random(1,100000))
  1553. vm:set_data(data)
  1554. vm:write_to_map(data)
  1555. vm:update_map()
  1556. end
  1557. })
  1558. minetest.register_abm({
  1559. nodenames = {"default:dirt"},
  1560. interval = 2,
  1561. chance = 200,
  1562. action = function(pos, node)
  1563. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  1564. local name = minetest.get_node(above).name
  1565. local nodedef = minetest.registered_nodes[name]
  1566. if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light")
  1567. and nodedef.liquidtype == "none"
  1568. and (minetest.get_node_light(above) or 0) >= 13 then
  1569. if name == "default:snow" or name == "default:snowblock" then
  1570. minetest.set_node(pos, {name = "default:dirt_with_snow"})
  1571. else
  1572. minetest.set_node(pos, {name = "default:dirt_with_grass"})
  1573. end
  1574. end
  1575. end
  1576. })
  1577. minetest.register_abm({
  1578. nodenames = {"default:dirt_with_grass"},
  1579. interval = 2,
  1580. chance = 20,
  1581. action = function(pos, node)
  1582. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  1583. local name = minetest.get_node(above).name
  1584. local nodedef = minetest.registered_nodes[name]
  1585. if name ~= "ignore" and nodedef
  1586. and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
  1587. and nodedef.liquidtype == "none") then
  1588. minetest.set_node(pos, {name = "default:dirt"})
  1589. end
  1590. end
  1591. })
  1592. --
  1593. -- Crafting items
  1594. --
  1595. minetest.register_craftitem("default:stick", {
  1596. description = "Stick",
  1597. inventory_image = "default_stick.png",
  1598. })
  1599. minetest.register_craftitem("default:paper", {
  1600. description = "Paper",
  1601. inventory_image = "default_paper.png",
  1602. })
  1603. minetest.register_craftitem("default:book", {
  1604. description = "Book",
  1605. inventory_image = "default_book.png",
  1606. })
  1607. minetest.register_craftitem("default:coal_lump", {
  1608. description = "Lump of coal",
  1609. inventory_image = "default_coal_lump.png",
  1610. })
  1611. minetest.register_craftitem("default:iron_lump", {
  1612. description = "Lump of iron",
  1613. inventory_image = "default_iron_lump.png",
  1614. })
  1615. minetest.register_craftitem("default:clay_lump", {
  1616. description = "Lump of clay",
  1617. inventory_image = "default_clay_lump.png",
  1618. })
  1619. minetest.register_craftitem("default:steel_ingot", {
  1620. description = "Steel ingot",
  1621. inventory_image = "default_steel_ingot.png",
  1622. })
  1623. minetest.register_craftitem("default:clay_brick", {
  1624. description = "Clay brick",
  1625. inventory_image = "default_steel_ingot.png",
  1626. inventory_image = "default_clay_brick.png",
  1627. })
  1628. minetest.register_craftitem("default:scorched_stuff", {
  1629. description = "Scorched stuff",
  1630. inventory_image = "default_scorched_stuff.png",
  1631. })
  1632. --
  1633. -- Support old code
  1634. --
  1635. function default.spawn_falling_node(p, nodename)
  1636. spawn_falling_node(p, nodename)
  1637. end
  1638. -- Horrible crap to support old code
  1639. -- Don't use this and never do what this does, it's completely wrong!
  1640. -- (More specifically, the client and the C++ code doesn't get the group)
  1641. function default.register_falling_node(nodename, texture)
  1642. minetest.log("error", debug.traceback())
  1643. minetest.log('error', "WARNING: default.register_falling_node is deprecated")
  1644. if minetest.registered_nodes[nodename] then
  1645. minetest.registered_nodes[nodename].groups.falling_node = 1
  1646. end
  1647. end
  1648. --
  1649. -- Global callbacks
  1650. --
  1651. -- Global environment step function
  1652. function on_step(dtime)
  1653. -- print("on_step")
  1654. end
  1655. minetest.register_globalstep(on_step)
  1656. function on_placenode(p, node)
  1657. --print("on_placenode")
  1658. end
  1659. minetest.register_on_placenode(on_placenode)
  1660. function on_dignode(p, node)
  1661. --print("on_dignode")
  1662. end
  1663. minetest.register_on_dignode(on_dignode)
  1664. function on_punchnode(p, node)
  1665. end
  1666. minetest.register_on_punchnode(on_punchnode)
  1667. --
  1668. -- Test some things
  1669. --
  1670. local function test_get_craft_result()
  1671. minetest.log("info", "test_get_craft_result()")
  1672. -- normal
  1673. local input = {
  1674. method = "normal",
  1675. width = 2,
  1676. items = {"", "default:coal_lump", "", "default:stick"}
  1677. }
  1678. minetest.log("info", "torch crafting input: "..dump(input))
  1679. local output, decremented_input = minetest.get_craft_result(input)
  1680. minetest.log("info", "torch crafting output: "..dump(output))
  1681. minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
  1682. assert(output.item)
  1683. minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
  1684. assert(output.item:get_name() == "default:torch")
  1685. assert(output.item:get_count() == 4)
  1686. -- fuel
  1687. local input = {
  1688. method = "fuel",
  1689. width = 1,
  1690. items = {"default:coal_lump"}
  1691. }
  1692. minetest.log("info", "coal fuel input: "..dump(input))
  1693. local output, decremented_input = minetest.get_craft_result(input)
  1694. minetest.log("info", "coal fuel output: "..dump(output))
  1695. minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
  1696. assert(output.time)
  1697. assert(output.time > 0)
  1698. -- cook
  1699. local input = {
  1700. method = "cooking",
  1701. width = 1,
  1702. items = {"default:cobble"}
  1703. }
  1704. minetest.log("info", "cobble cooking input: "..dump(output))
  1705. local output, decremented_input = minetest.get_craft_result(input)
  1706. minetest.log("info", "cobble cooking output: "..dump(output))
  1707. minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
  1708. assert(output.time)
  1709. assert(output.time > 0)
  1710. assert(output.item)
  1711. minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
  1712. assert(output.item:get_name() == "default:stone")
  1713. assert(output.item:get_count() == 1)
  1714. end
  1715. test_get_craft_result()
  1716. --
  1717. -- Done, print some random stuff
  1718. --
  1719. --print("minetest.registered_entities:")
  1720. --dump2(minetest.registered_entities)
  1721. -- END