api.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. local S=minerdream.intllib
  2. local agroup={helmet="armor_head",chestplate="armor_torso",leggings="armor_legs",boots="armor_feet",shield="armor_shield"}
  3. --local orelump={ore="lump",poorore="nugget"}
  4. local orelump={lump="ore",nugget="poorore",gem="ore"}
  5. local tier_definition = basic_functions.import_csv(minerdream.path.."/tiers.txt",{col_num={"name"},})
  6. local local_item_insert=function(name,ttype,def)
  7. if minerdream.items[name] == nil then
  8. minerdream.items[name] = {}
  9. end
  10. minerdream.items[name][ttype]=def
  11. end
  12. local local_create_def=function(name,type,cracky,tdef)
  13. local temp_def={description=S(name:gsub("^%l", string.upper)).." "..S(type:gsub("^%l", string.upper)),
  14. tiles={minerdream.modname.."_"..name.."_"..type..".png"},
  15. groups={cracky=cracky},
  16. sounds = default.node_sound_stone_defaults(),
  17. }
  18. if tdef.tier then
  19. temp_def.description=core.colorize("#00FF00", temp_def.description.."\n")..tdef.tier_string
  20. end
  21. return temp_def
  22. end
  23. local local_craft_block=function(input,output)
  24. minetest.register_craft({
  25. output = output,
  26. recipe = {
  27. {input, input, input},
  28. {input, input, input},
  29. {input, input, input},
  30. } })
  31. minetest.register_craft({
  32. output = input.." 9",
  33. recipe = {{output}} })
  34. end
  35. -- register craft recipes for creating stacks
  36. local local_craft_stack=function(input,output)
  37. minetest.register_craft({
  38. output = output,
  39. recipe = {
  40. {input, input },
  41. {input, input },
  42. } })
  43. minetest.register_craft({
  44. output = input.." 4",
  45. recipe = {{output}} })
  46. end
  47. -- register craft recipes for creating bricks
  48. local local_craft_brick = function(input,output)
  49. minetest.register_craft( {type = "shapeless",
  50. output = output,
  51. recipe = {input, "default:cobble"},})
  52. end
  53. -- return recipes for different tools
  54. local local_get_recipe=function(tool,material,stick)
  55. if stick == nil then
  56. stick="group:stick"
  57. end
  58. local out_recipe={}
  59. if tool == "spear" then
  60. out_recipe={
  61. {'', material, material},
  62. {'', stick, material},
  63. {stick, '', ''},}
  64. elseif tool == "bow" then
  65. out_recipe = {
  66. {'', material, material},
  67. {material, '', stick},
  68. {material, stick, ''},}
  69. elseif tool == "pick" then
  70. out_recipe = {
  71. {material, material, material},
  72. {'', stick, ''},
  73. {'', stick, ''},}
  74. elseif tool == "axe" then
  75. out_recipe = {
  76. {material, material, ''},
  77. {material, stick, ''},
  78. {'', stick, ''},}
  79. elseif tool == "shovel" then
  80. out_recipe = {
  81. {'', material, ''},
  82. {'', stick, ''},
  83. {'', stick, ''},}
  84. elseif tool == "sword" then
  85. out_recipe = {
  86. {'', material, ''},
  87. {'', material, ''},
  88. {'', stick, ''},}
  89. elseif tool == "helmet" then
  90. out_recipe = {
  91. {material, material, material},
  92. {material, '', material},}
  93. elseif tool == "chestplate" then
  94. out_recipe = {
  95. {material, '', material},
  96. {material, material, material},
  97. {material, material, material},}
  98. elseif tool == "leggings" then
  99. out_recipe = {
  100. {material, material, material},
  101. {material, '', material},
  102. {material, '', material},}
  103. elseif tool == "boots" then
  104. out_recipe = {
  105. {material, '', material},
  106. {material, '', material},}
  107. elseif tool == "shield" then
  108. out_recipe = {
  109. {material, material, material},
  110. {material, material, material},
  111. {'', material, ''},}
  112. else
  113. out_recipe={}
  114. end
  115. return out_recipe
  116. end
  117. minerdream.register_ore=function(i,tdef)
  118. -- only register, if not already defined
  119. if minerdream.items[i] == nil then
  120. -- generate ore name if not already given
  121. local ore_name=tdef.name or i
  122. tdef.ore_name=ore_name
  123. tdef.ore_modname=minerdream.modname
  124. if tdef.name == nil then tdef.name = i end
  125. -- generate tier description
  126. tdef.tier_string=""
  127. tdef.tierd={}
  128. if tdef.tier then
  129. tdef.tierd=tier_definition[tostring(tdef.tier)]
  130. tdef.tier_string=core.colorize("#A0A0A0", "tier: "..tdef.tier.." ("..tdef.tierd.desc..")")
  131. tdef.tierdef=table.copy(tier_definition[tostring(tdef.tier)])
  132. end
  133. -- generate ore and lump for pairs given in orelump (e.g. ore <-> lump and poorore <-> nugget)
  134. for l,o in pairs(orelump) do
  135. -- register if ore and lump is defined
  136. if tdef[o] ~= nil and tdef[l] ~= nil then
  137. -- register ore
  138. if tdef[o] ~= nil then
  139. tdef[o].ore_name=ore_name.."_"..o
  140. tdef[o].lump_name=tdef[o].ore_name
  141. if tdef[l] ~= nil then
  142. tdef[o].lump_name=tdef[l].lump_name or ore.."_"..l
  143. tdef[l].lump_name=tdef[o].lump_name
  144. end
  145. minerdream.register_node_ore(tdef,tdef[o],l)
  146. minerdream.register_node_mapgen(tdef,tdef[o])
  147. end
  148. --register lump, if needed
  149. if (tdef[o].lump_name ~= tdef[o].ore_name) and (tdef[l] ~= nil) then
  150. if tdef[l].lump_name == nil then
  151. tdef[l].lump_name=tdef[o].lump_name
  152. else
  153. if tdef[l].lump_name ~= tdef[o].lump_name then
  154. tdef[l].lump_name = tdef[o].lump_name
  155. end
  156. end
  157. if tdef[l].lump_node_name == nil then
  158. tdef[l].lump_node_name=tdef[o].lump_node_name
  159. end
  160. tdef[l].ore_name=tdef[o].ore_name
  161. minerdream.register_node_lump(tdef,tdef[l])
  162. end
  163. end
  164. end
  165. -- if lump and nugget defined, register craft recipe between them
  166. if tdef.nugget ~= nil and tdef.lump ~= nil then
  167. local_craft_stack(tdef.nugget.lump_node_name,tdef.lump.lump_node_name)
  168. end
  169. -- define ingot
  170. if tdef.ingot ~= nil then
  171. minerdream.register_ingot(tdef,tdef.ingot)
  172. end
  173. -- register block (9 ingot)
  174. if tdef.block ~= nil then
  175. minerdream.register_block(tdef)
  176. end
  177. -- define ore dust
  178. -- only makes sense if it can be grinded
  179. if tdef.dust~= nil and minetest.get_modpath("technic") and technic ~=nil then
  180. minerdream.register_dust(tdef,tdef.dust)
  181. end
  182. -- register tools like shovel
  183. if tdef.tools ~= nil then
  184. minerdream.register_tools(tdef,tdef.tools)
  185. end
  186. -- register armor
  187. if tdef["3d_armor"] ~= nil then
  188. minerdream.register_3d_armor(tdef,tdef["3d_armor"])
  189. end
  190. -- register additional crafts if given in json file
  191. if tdef.crafts ~= nil then
  192. minerdream.register_crafts(tdef,tdef.crafts)
  193. end
  194. -- register additional crafts if given in json file
  195. if tdef.craftitems ~= nil then
  196. minerdream.register_craftitems(tdef,tdef.craftitems)
  197. end
  198. -- save definition to minerdream.items
  199. minerdream.items[ore_name]=tdef
  200. end
  201. end
  202. minerdream.register_node_lump=function(tdef,ldef)
  203. if ldef.lump_name ~= nil then
  204. local node_name=ldef.node_name or tdef.ore_modname..":"..ldef.lump_name
  205. ldef.node_name=node_name
  206. local lump_def={description=S(ldef.lump_name:gsub("^%l", string.upper):gsub("_"," ")),
  207. name=node_name,
  208. inventory_image=ldef.inventory_image or node_name:gsub(":","_")..".png"
  209. }
  210. for _,def_item in pairs({"mesh"}) do
  211. if ldef[def_item] ~= nil and lump_def[def_item] == nil then
  212. lump_def[def_item]=ldef[def_item]
  213. end
  214. end
  215. if lump_def.mesh ~= nil then
  216. lump_def.drawtype = "mesh"
  217. end
  218. if ldef.is_lump_gemstone ~= nil then
  219. lump_def.paramtype="light"
  220. lump_def.walkable = true
  221. lump_def.tiles = {lump_def.inventory_image}
  222. lump_def.is_ground_content = true
  223. lump_def.groups={snappy=3,dig_immidiate=3}
  224. lump_def.selection_box = {type = "fixed",
  225. fixed = {{-0.2, -0.5, -0.2, 0.2, -0.25, 0.2},},}
  226. lump_def.node_box = {type = "fixed",
  227. fixed = {{-0.2, -0.5, -0.2, 0.2, -0.25, 0.2},},}
  228. end
  229. minetest.register_craftitem(lump_def.name,lump_def)
  230. if ldef.burntime ~= nil then
  231. minetest.register_craft({
  232. type = "fuel",
  233. recipe = lump_def.name,
  234. burntime = ldef.burntime})
  235. end
  236. end
  237. end
  238. minerdream.register_node_ore=function(tdef,odef,ltype)
  239. -- register node for ore/poorore
  240. -- check, which node should be dropped: node itself or specific lump
  241. if odef.lump_name == nil then
  242. odef.lump_name=tdef.ore_name.."_"..ltype
  243. end
  244. if odef.lump_node_name == nil then
  245. odef.lump_node_name=tdef.ore_modname..":"..odef.lump_name
  246. end
  247. -- check, if some kind of stone is defined, where the ore can appear
  248. if odef.wherein == nil then
  249. odef.wherein="stone"
  250. end
  251. -- check, if inventory image is given
  252. if odef.inventory_image == nil then
  253. odef.inventory_image=minerdream.modname.."_"..odef.ore_name..".png"
  254. end
  255. -- check, if name of node is defined
  256. if odef.node_name == nil then
  257. odef.node_name=tdef.ore_modname..":"..odef.ore_name
  258. end
  259. local ore_def={description=S(odef.ore_name:gsub("^%l", string.upper):gsub("_"," ")),
  260. groups={cracky=odef.crack},
  261. sound=default.node_sound_stone_defaults()
  262. }
  263. if odef.lump_name ~= odef.ore_name then
  264. ore_def.drop=odef.lump_node_name
  265. end
  266. if tdef.groups.is_metall then
  267. ore_def.groups["metall"]=tdef.groups.is_metall
  268. end
  269. if tdef.groups.is_mineral then
  270. ore_def.groups["mineral"]=tdef.groups.is_mineral
  271. end
  272. if odef.stackmax then
  273. ore_def.stack_max=odef.stackmax
  274. end
  275. if tdef.tier then
  276. ore_def.description=core.colorize("#00FF00", ore_def.description.."\n")..tdef.tier_string
  277. end
  278. if tdef.groups.is_gemstone ~= nil then
  279. ore_def.paramtype="light"
  280. ore_def.drawtype = "mesh"
  281. ore_def.mesh = "gemstone_cubic_pillars.obj"
  282. ore_def.walkable = true
  283. ore_def.tiles = {"minerdream_"..tdef.ore_name.."_rock.png"}
  284. ore_def.selection_box = {type = "fixed",
  285. fixed = {{-0.4, -0.5, -0.4, 0.4, 0.0, 0.4},},}
  286. ore_def.node_box = {type = "fixed",
  287. fixed = {{-0.4, -0.5, -0.4, 0.4, 0.0, 0.4},},}
  288. end
  289. -- for each stone, where the node can appear, add the name
  290. odef.node_name={}
  291. if odef.wherein==nil then
  292. odef.wherein={"stone"}
  293. end
  294. -- for each stone create definition table and register node
  295. for _,wi in ipairs(odef.wherein) do
  296. local oredef=table.copy(ore_def)
  297. oredef.name=minerdream.modname..":"..wi.."_with_"..odef.ore_name
  298. oredef.tiles={"default_"..wi..".png^"..odef.inventory_image}
  299. odef.node_name[wi]=oredef.name
  300. -- print(oredef.name)
  301. -- print(dump2(oredef))
  302. -- print(dump(oredef))
  303. minetest.register_node(oredef.name,oredef)
  304. end
  305. end
  306. minerdream.register_craftitems=function(tdef,cdef)
  307. if cdef ~= nil then
  308. for item_name,item_def in pairs(cdef) do
  309. local idef=cdef[item_name]
  310. if idef.name == nil then idef.name = item_name end
  311. if idef.inventory_image == nil then
  312. idef.inventory_image=minerdream.modname.."_"..item_name..".png"
  313. end
  314. if idef.description == nil then
  315. idef.description=S(item_name:gsub("_"," "))
  316. else
  317. idef.description=S(idef.description)
  318. end
  319. local iname=tdef.ore_modname..":"..item_name or minerdream.modname..":"..item_name
  320. minetest.register_craftitem(iname,idef)
  321. end
  322. end
  323. end
  324. local parse_recipe_element=function(tdef,recipe_item)
  325. local out=nil
  326. local found=true
  327. if recipe_item ~= nil then
  328. if recipe_item ~= "" then
  329. if tdef[recipe_item] ~= nil then
  330. out = tdef[recipe_item].node_name or tdef[recipe_item].item_name
  331. end
  332. if string.match(recipe_item,"@") then
  333. local sw=string.split(recipe_item,"@")
  334. if minerdream.items[sw[1]] ~= nil then
  335. local ti=minerdream.items[sw[1]]
  336. if ti[sw[2]] ~= nil then
  337. out=ti[sw[2]].node_name or ti[sw[2]].item_name
  338. end
  339. if out == nil then
  340. found = false
  341. end
  342. end
  343. end
  344. end
  345. end
  346. return out,found
  347. end
  348. minerdream.register_crafts=function(tdef,cdef)
  349. if cdef ~= nil then
  350. for _,ccdef in pairs(cdef) do
  351. if ccdef.output ~= nil and ccdef.recipe ~= nil then
  352. local bcraft=true
  353. -- analyse, if recipe refers to items in definition
  354. if type(ccdef.recipe)=="table" then
  355. for k,v in pairs(ccdef.recipe) do
  356. if type(v) == "table" then
  357. for l,w in pairs(v) do
  358. local pre,pref=parse_recipe_element(tdef,w)
  359. if pref then
  360. if pre~=nil then
  361. ccdef.recipe[k][l]=pre
  362. end
  363. else
  364. bcraft = false
  365. end
  366. end
  367. end
  368. if type(v) == "string" then
  369. local pre,pref=parse_recipe_element(tdef,v)
  370. if pref then
  371. if pre~=nil then
  372. ccdef.recipe[k]=pre
  373. end
  374. else
  375. bcraft = false
  376. end
  377. end
  378. end
  379. end
  380. if type(ccdef.recipe)=="string" then
  381. local pre,pref=parse_recipe_element(tdef,ccdef.recipe)
  382. if pref then
  383. if pre ~= nil then
  384. ccdef.recipe={pre}
  385. end
  386. else bcraft=false end
  387. end
  388. local pre,pref=parse_recipe_element(tdef,ccdef.output)
  389. if pref then
  390. if pre ~= nil then ccdef.output=pre end
  391. else bcraft = false end
  392. if bcraft then
  393. minetest.register_craft(ccdef)
  394. else
  395. print("craft not yet defined",dump(ccdef))
  396. end
  397. end
  398. end
  399. end
  400. end
  401. minerdream.register_ore_lump=function(ore_name,tdef)
  402. -- base config of ore found in normal stone
  403. local tore=tdef.ore
  404. local tlump=tdef.lump
  405. local lump_name=tlump.name or tdef.ore_modname..":"..ore_name
  406. if tdef.groups.drop_as_lump ~= nil then
  407. lump_name=lump_name.."_lump"
  408. end
  409. local torename=tore.inventory_image or minerdream.modname.."_"..ore_name.."_ore.png"
  410. local ore_def={description=S(ore_name:gsub("^%l", string.upper)).." "..S("ore"),
  411. name=minerdream.modname..":stone_with_"..ore_name,
  412. groups={cracky=tore.crack},
  413. tiles={"default_stone.png^"..torename},
  414. sound=default.node_sound_stone_defaults(),
  415. }
  416. -- group definitions for awards
  417. if tdef.groups.is_metall then
  418. ore_def.groups["metall"..tdef.groups.is_metall]=tdef.groups.is_metall
  419. end
  420. if tdef.groups.is_mineral then
  421. ore_def.groups["mineral"..tdef.groups.is_mineral]=tdef.groups.is_mineral
  422. end
  423. -- drops item
  424. if tdef.groups.has_no_drop == nil then
  425. ore_def.drop=lump_name
  426. end
  427. if tore.stackmax then
  428. ore_def.stack_max = tore.stackmax
  429. end
  430. if tdef.groups.is_gemstone ~= nil then
  431. ore_def.description=ore_name:gsub("^%l", string.upper)
  432. ore_def.paramtype="light"
  433. ore_def.drawtype = "mesh"
  434. ore_def.mesh = "gemstone_cubic_pillars.obj"
  435. ore_def.walkable = true
  436. ore_def.inventory_image = "minerdream_"..ore_name.."_gem.png"
  437. ore_def.tiles = {"minerdream_"..ore_name.."_rock.png"}
  438. ore_def.selection_box = {type = "fixed",
  439. fixed = {{-0.4, -0.5, -0.4, 0.4, 0.0, 0.4},},}
  440. ore_def.node_box = {type = "fixed",
  441. fixed = {{-0.4, -0.5, -0.4, 0.4, 0.0, 0.4},},}
  442. end
  443. local lump_def={description=S(ore_name:gsub("^%l", string.upper)).." "..S("lump"),
  444. name=lump_name,
  445. inventory_image=tdef.lump.inventory_image or lump_name:gsub(":","_")..".png"
  446. }
  447. if tlump.stackmax ~= nil then
  448. tlump_def.stack_max=tlump.stackmax
  449. end
  450. if tdef.groups.is_lump_gemstone ~= nil then
  451. lump_def.drawtype="mesh"
  452. lump_def.mesh = ore_name..".obj"
  453. lump_def.walkable = true
  454. lump_def.inventory_image = "minerdream_"..ore_name.."_gem.png"
  455. lump_def.tiles = {"minerdream_"..ore_name..".png"}
  456. lump_def.paramtype = "light"
  457. lump_def.is_ground_content = true
  458. lump_def.groups={snappy=3,dig_immidiate=3}
  459. lump_def.selection_box = {type = "fixed",
  460. fixed = {{-0.2, -0.5, -0.2, 0.2, -0.25, 0.2},},}
  461. lump_def.node_box = {type = "fixed",
  462. fixed = {{-0.2, -0.5, -0.2, 0.2, -0.25, 0.2},},}
  463. end
  464. -- override existing ore?
  465. local to_override = false
  466. if tdef.overrides ~= nil then
  467. if minetest.registered_nodes[tdef.overrides] ~= nil then
  468. -- get drop item of defined ore
  469. local temp_def=minetest.registered_nodes[tdef.overrides]
  470. ore_def.name=tdef.overrides
  471. ore_def.drop=temp_def.drop
  472. lump_def.name=temp_def.drop
  473. local override_mod=tdef.overrides:split(":")[1]
  474. if override_mod ~=nil then
  475. ore_def.override_mod=override_mod
  476. lump_def.override_mod=override_mod
  477. end
  478. to_override = true
  479. end
  480. end
  481. if tdef.tier then
  482. ore_def.description=core.colorize("#00FF00", ore_def.description.."\n")..tdef.tier_string
  483. lump_def.description=core.colorize("#00FF00", lump_def.description.."\n")..tdef.tier_string
  484. end
  485. local orename=ore_def.name
  486. local lump_name=lump_def.name
  487. local needs_mapgen=false
  488. local mapgen_name=""
  489. if to_override then
  490. ore_def.name=nil
  491. lump_def.name=nil
  492. -- get cooking output of already defined lump
  493. local output, decremented_input = minetest.get_craft_result({ method = "cooking", width = 1, items = { ItemStack(lump_name) }})
  494. local override_ingot=output.item:get_name()
  495. if override_ingot ~= nil then
  496. lump_def.ingot_name=output.item:get_name()
  497. tdef.ingot_name=output.item:get_name()
  498. minerdream.items[ore_name].ingot_name=output.item:get_name()
  499. end
  500. minetest.override_item(orename,ore_def)
  501. if tdef.groups.has_no_lump == nil then
  502. minetest.override_item(lump_name,lump_def)
  503. end
  504. lump_def.name=lump_name
  505. ore_def.name=orename
  506. else
  507. minetest.register_node(ore_def.name,ore_def)
  508. -- if tdef.groups.has_no_lump == nil then
  509. minetest.register_craftitem(lump_def.name,lump_def)
  510. -- end
  511. -- if not already defined, then add mapgen parameter
  512. if tdef.scarcity ~= nil then
  513. needs_mapgen = true
  514. mapgen_name=ore_def.name
  515. end
  516. end
  517. local_item_insert(ore_name,"ore_def",ore_def)
  518. -- if tdef.groups.has_no_lump == nil then
  519. local_item_insert(ore_name,"lump_def",lump_def)
  520. -- end
  521. -- define desert ores
  522. if tdef.groups.in_desert then
  523. local desertore_def=table.copy(ore_def)
  524. desertore_def.name=minerdream.modname..":desertstone_with_"..ore_name
  525. desertore_def.tiles={"default_desert_stone.png^"..torename}
  526. local_item_insert(ore_name,"desertore_def",desertore_def)
  527. minetest.register_node(desertore_def.name,desertore_def)
  528. end
  529. if tdef.nugget ~= nil then
  530. local poor_def=table.copy(ore_def)
  531. local nugget_def=table.copy(lump_def)
  532. local poorimg=tdef.nugget.inventory_image or minerdream.modname.."_"..ore_name.."_poorore.png"
  533. poor_def.description=S("Poor").." "..S(ore_name:gsub("^%l", string.upper))
  534. -- poor_def.name=poor_def.name.."_poor"
  535. poor_def.name=minerdream.modname..":stone_with_"..ore_name.."_poor"
  536. poor_def.tiles={"default_stone.png^"..poorimg}
  537. poor_def.groups.cracky= tdef.nugget.cracky or math.max(1,math.floor(tdef.crack/2)) -- poor ore should be easier to dig
  538. nugget_def.description=ore_name:gsub("^%l", string.upper).." Nugget"
  539. nugget_def.name=minerdream.modname..":"..ore_name.."_nugget"
  540. nugget_def.inventory_image=tdef.nugget.inventory_image or nugget_def.name:gsub(":","_")..".png"
  541. poor_def.drop=nugget_def.name
  542. minetest.register_node(poor_def.name,poor_def)
  543. minetest.register_craftitem(nugget_def.name,nugget_def)
  544. local_craft_stack(nugget_def.name,lump_def.name)
  545. end
  546. end
  547. minerdream.register_node_mapgen=function(tdef,odef)
  548. -- register map generation of ore based on config
  549. local wherein={"default:stone"}
  550. if odef.wherein ~= nil then
  551. wherein={}
  552. for _,wi in pairs(odef.wherein) do
  553. local tscar=odef.scarcity or 13
  554. local map_def={ore_type = "scatter",
  555. ore = odef.node_name[wi],
  556. wherein = wi,
  557. clust_scarcity = tscar * tscar * tscar,
  558. clust_num_ores = odef.num_ores or 1,
  559. clust_size = odef.clust_size or 1,
  560. y_min = odef.y_min or (-31000),
  561. y_max = odef.y_max or 0,
  562. }
  563. minetest.register_ore(map_def)
  564. end
  565. end
  566. end
  567. minerdream.register_ingot=function(tdef,idef)
  568. if idef ~= nil then
  569. if idef.node_name == nil then
  570. idef.node_name=minerdream.modname..":"..tdef.name.."_ingot"
  571. end
  572. local ingot_def=local_create_def(tdef.name,"ingot",idef.crack or (tdef.ore.crack+1),tdef)
  573. ingot_def.groups["metal"]=tdef.tier or 1 -- setting metal group
  574. ingot_def.inventory_image=idef.inventory_image or idef.node_name:gsub(":","_") or minerdream.modname.."_"..tdef.name.."_ingot.png"
  575. ingot_def.stack_max = idef.maxstack or minerdream.ingot_max_stack
  576. minetest.register_craftitem(idef.node_name,ingot_def)
  577. -- if lump is defined and cooking time is given then register cooking recipe
  578. if tdef.lump then
  579. if tdef.lump.cooking_time == nil then
  580. tdef.lump.cooking_time = 2^tdef.tier
  581. end
  582. -- check, if cooking recipe already registered
  583. local output, decremented_input = minetest.get_craft_result({ method = "cooking", width = 1, items = { ItemStack(tdef.lump.node_name) }})
  584. if output.item:get_name() ~= idef.node_name then
  585. minetest.register_craft({type="cooking",
  586. cooktime=tdef.lump.cooking_time,
  587. output=idef.node_name,
  588. recipe=tdef.lump.node_name,
  589. })
  590. end
  591. end
  592. end
  593. end
  594. minerdream.register_block=function(tdef)
  595. local block_def=local_create_def(tdef.ore.ore_name,"block",1,tdef)
  596. if tdef.block.node_name == nil then
  597. tdef.block.node_name = minerdream.modname..":"..tdef.name.."_block"
  598. block_def.name=tdef.block.node_name
  599. end
  600. if tdef.block.inventory_image then
  601. block_def.tiles={tdef.block.inventory_image}
  602. block_def.inventory_image=tdef.block.inventory_image
  603. end
  604. -- print(dump(block_def))
  605. minetest.register_craftitem(tdef.block.node_name,block_def)
  606. local_craft_block(tdef.ingot.node_name,tdef.block.node_name)
  607. end
  608. minerdream.register_weapons=function(ore_name,tdef)
  609. local ingot_name=minerdream.items[ore_name].ingot_def.name
  610. for _,tool in ipairs(minerdream.tools_to_register) do
  611. if tdef[tool] ~= nil then
  612. local stick = "group:stick"
  613. if tool == "bow" then -- for bows use stick for cotton or steel-wire
  614. stick = "farming:cotton"
  615. if tdef.tool_cotton ~= nil then
  616. if tdef.tool_cotton == "steel_wire" then
  617. stick = minerdream.steel_wire
  618. else
  619. stick=tdef.tool_cotton
  620. end
  621. end
  622. else
  623. if tdef[tool].tool_stick ~= nil then
  624. stick=tdef.tool_stick
  625. end
  626. end
  627. minetest.register_craft({
  628. output=minerdream.modname..":"..tool.."_"..ore_name,
  629. recipe=local_get_recipe(tool,ingot_name,stick)
  630. })
  631. end
  632. end
  633. end
  634. minerdream.register_dust=function(tdef,ddef)
  635. if ddef~=nil and minetest.get_modpath("technic") and technic ~= nil then
  636. if ddef.node_name == nil then
  637. ddef.node_name = minerdream.modname..":"..tdef.name.."_dust"
  638. end
  639. local dust_def=local_create_def(tdef.name,"dust",ddef.crack or (tdef.ore.crack-1),tdef)
  640. dust_def.name=ddef.node_name
  641. local dustimg=ddef.inventory_image or ddef.node_name:gsub(":","_") or minerdream.modname.."_"..ore_name.."_dust.png"
  642. dust_def.tiles={dustimg}
  643. dust_def.inventory_image=dustimg
  644. minetest.register_node(ddef.node_name,dust_def)
  645. if tdef.lump.grind_time == nil then
  646. tdef.lump.grind_time=(tdef.lump.cooking_time or 64)/minerdream.dust_cooking_time_reduce
  647. end
  648. if ddef.cooking_time == nil then
  649. ddef.cooking_time = tdef.lump.grind_time
  650. end
  651. -- grind lump into dust
  652. technic.register_grinder_recipe({input = {tdef.lump.node_name}, output = ddef.node_name.." 2",time=tdef.lump.grind_time})
  653. -- grind ingot into dust
  654. if tdef.ingot ~= nil then
  655. if tdef.ingot.grind_time == nil then
  656. tdef.ingot.grind_time = tdef.lump.grind_time
  657. technic.register_grinder_recipe({input = {tdef.ingot.node_name}, output = ddef.node_name.." 2",time=tdef.ingot.grind_time})
  658. end
  659. end
  660. if tdef.ingot ~= nil then
  661. minetest.register_craft({type="cooking",
  662. cooktime=tdef.dust.cooking_time,
  663. output=tdef.ingot.node_name,
  664. recipe=tdef.dust.node_name,
  665. })
  666. end
  667. end
  668. end
  669. minerdream.register_tools=function(tdef,adef)
  670. if adef ~= nil then
  671. for _,tool in pairs({"pick","axe","sword","shovel","spear"}) do
  672. if adef[tool] ~= nil then
  673. local ttv=tdef.tools[tool]
  674. ttv.item_name=minerdream.modname..":"..tdef.name.."_"..tool
  675. for _,it in pairs({"range","maxlevel","tool_stick","fleshy","level","cracky","crumbly","choppy","snappy","use"}) do
  676. if ttv[it] == nil and adef[it] ~= nil then
  677. ttv[it] = adef[it]
  678. end
  679. end
  680. local fleshy=ttv.fleshy or tdef.tools.fleshy or 4
  681. local uses=ttv.use or tdef.tools.use
  682. local tdesc=core.colorize("#"..tdef.tierd.color, S(tdef.name:gsub("^%l", string.upper)).." "..S(tool:gsub("^%l", string.upper)).."\n")..
  683. core.colorize("#A0A0A0", "tier: "..tdef.tierd.name.." ("..tdef.tierd.desc..")")
  684. -- check special attributes of tool definition and use fallback definitions
  685. if uses then
  686. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Uses")..": "..uses)
  687. end
  688. if ttv.maxlevel then
  689. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Max. Level")..": "..ttv.maxlevel)
  690. end
  691. if ttv.fleshy then
  692. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Damage")..": "..fleshy)
  693. end
  694. local tt_def={description=tdesc,uses=uses,
  695. inventory_image=ttv.inventory_image or minerdream.modname.."_"..tool.."_"..tdef.name..".png",
  696. range=ttv.range or tdef.tools.range or 2,
  697. groups={weapon=1},
  698. tool_capabilities={max_drop_level = 1,groupcaps={},
  699. damage_groups = {fleshy = fleshy},},
  700. }
  701. -- check if values for capabitlites exist
  702. for _,gc in pairs({"cracky","crumbly","choppy","snappy"}) do
  703. if ttv[gc] ~= nil then
  704. local ml = ttv.maxlevel or tdef.tools.maxlevel or 1
  705. tt_def.tool_capabilities.groupcaps[gc]={times=table.copy(ttv[gc]),
  706. uses=tdef.uses,maxlevel=ml}
  707. end
  708. end
  709. minetest.register_tool(ttv.item_name,tt_def)
  710. local stick = ttv.tool_stick or "group:stick"
  711. minetest.register_craft({
  712. output=ttv.item_name,
  713. recipe=local_get_recipe(tool,tdef.ingot.node_name,stick)
  714. })
  715. end
  716. end
  717. end
  718. end
  719. minerdream.register_3d_armor=function(tdef,adef)
  720. if adef ~= nil then
  721. for _,tool in pairs({"helmet","chestplate","boots","leggings","shield"}) do
  722. if adef[tool] ~= nil then
  723. local ttv=adef[tool]
  724. ttv.item_name=minerdream.modname..":"..tdef.name.."_"..tool
  725. for _,it in pairs({"fleshy","heal","speed","gravity","jump","level","cracky","crumbly","choppy","snappy","use"}) do
  726. if ttv[it] == nil and adef[it] ~= nil then
  727. ttv[it] = adef[it]
  728. end
  729. end
  730. local tdesc=core.colorize("#"..tdef.tierd.color, S(tdef.name:gsub("^%l", string.upper)).." "..S(tool:gsub("^%l", string.upper)).."\n")..
  731. core.colorize("#A0A0A0", "tier: "..tdef.tierd.name.." ("..tdef.tierd.desc..")")
  732. if ttv.fleshy then
  733. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Defense")..": "..ttv.fleshy)
  734. end
  735. if ttv.heal then
  736. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Heal")..": "..ttv.heal)
  737. end
  738. if ttv.speed then
  739. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Walking speed")..": "..(ttv.speed*100).."%")
  740. end
  741. if ttv.gravity then
  742. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Gravity")..": "..(ttv.gravity*100).."%")
  743. end
  744. if ttv.jump then
  745. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Jump force")..": "..(ttv.jump*100).."%")
  746. end
  747. local tt_def={description=tdesc,
  748. inventory_image=ttv.inventory_image or minerdream.modname.."_inv_"..tool.."_"..tdef.name..".png",
  749. damage_groups = {level = ttv.level or 2},
  750. armor_groups={fleshy=ttv.fleshy or 10},
  751. groups={armor_heal=ttv.heal,armor_use=ttv.use,
  752. physics_jump=ttv.jump,physics_speed=ttv.speed,physics_gravity=ttv.gravity}
  753. }
  754. for _,gc in pairs({"cracky","crumbly","choppy","snappy"}) do
  755. tt_def.damage_groups[gc]=ttv[gc]
  756. end
  757. -- print(tool)
  758. -- print(agroup[tool])
  759. tt_def.groups[agroup[tool]]=1
  760. armor:register_armor(ttv.item_name,tt_def)
  761. local stick = ttv.tool_stick or "group:stick"
  762. local arm_rec = {output=ttv.item_name}
  763. if tdef.ingot ~= nil then if tdef.ingot.node_name ~= nil then
  764. arm_rec.recipe=local_get_recipe(tool,tdef.ingot.node_name,stick)
  765. end end
  766. if ttv.recipe ~= nil then
  767. arm_rec.recipe=ttv.recipe
  768. end
  769. if arm_rec.recipe ~= nil then
  770. minetest.register_craft(arm_rec)
  771. end
  772. end
  773. end
  774. end
  775. end