init.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. instant_ores = {}
  2. if minetest.get_modpath("default") then
  3. instant_ores.stone = "default:stone"
  4. instant_ores.stick = "default:stick"
  5. elseif minetest.get_modpath("mcl_core") then
  6. instant_ores.stone = "mcl_core:stone"
  7. instant_ores.stick = "mcl_core:stick"
  8. else
  9. minetest.log("warn","instant_ores only supports default and MineClone2. Sticks and stones could not be found.")
  10. end
  11. if minetest.get_modpath("default") then
  12. instant_ores.node_sound_metal_defaults=default.node_sound_metal_defaults
  13. instant_ores.node_sound_stone_defaults=default.node_sound_stone_defaults
  14. elseif minetest.get_modpath("mcl_sounds") then
  15. instant_ores.node_sound_metal_defaults=mcl_sounds.node_sound_metal_defaults
  16. instant_ores.node_sound_stone_defaults=mcl_sounds.node_sound_stone_defaults
  17. else
  18. instant_ores.node_sound_metal_defaults=function ()
  19. return {}
  20. end
  21. instant_ores.node_sound_stone_defaults=function ()
  22. return {}
  23. end
  24. minetest.log("warn","instant_ores only supports default and MineClone2. Sounds could not be found.")
  25. end
  26. instant_ores.register_gen_ore = function(node, rarity, ymax, ymax_deep)
  27. if rarity < 0 then rarity = 0 end
  28. local count_large = math.ceil(48/rarity) + 1
  29. local count_small = math.ceil(24/rarity) + 1
  30. local dense_rarity = math.ceil(rarity * 3/4)
  31. if not instant_ores.stone then return end
  32. minetest.register_ore({
  33. ore_type = "scatter",
  34. ore = node,
  35. wherein = instant_ores.stone,
  36. clust_scarcity = dense_rarity * dense_rarity * dense_rarity,
  37. clust_num_ores = count_large,
  38. clust_size = 3,
  39. y_min = 1025,
  40. y_max = 31000,
  41. })
  42. minetest.register_ore({
  43. ore_type = "scatter",
  44. ore = node,
  45. wherein = instant_ores.stone,
  46. clust_scarcity = rarity * rarity * rarity,
  47. clust_num_ores = count_small,
  48. clust_size = 3,
  49. y_min = ymax_deep,
  50. y_max = ymax,
  51. })
  52. minetest.register_ore({
  53. ore_type = "scatter",
  54. ore = node,
  55. wherein = instant_ores.stone,
  56. clust_scarcity = dense_rarity * dense_rarity * dense_rarity,
  57. clust_num_ores = count_large,
  58. clust_size = 3,
  59. y_min = -31000,
  60. y_max = ymax_deep,
  61. })
  62. end
  63. instant_ores.register_armorset = function(
  64. mod,
  65. name,
  66. desc,
  67. color,
  68. level,
  69. ingredient,
  70. optional_durability,
  71. infinite_use,
  72. shield_damage_sound,
  73. optional_protection,
  74. hurt_back,
  75. optional_weight)
  76. if not minetest.get_modpath("3d_armor") then return end
  77. local durability = optional_durability or (20*level*level*level)
  78. local uses = infinite_use and 0 or (65536 / durability)
  79. local weight = optional_weight or 1
  80. local default_protection = 24 - 20/((level >= 1) and level*level/2 or 1)
  81. local big_armor = optional_protection or default_protection
  82. local small_armor = (optional_protection or default_protection)*0.66
  83. local sound = shield_damage_sound or "default_dig_metal"
  84. --local sanity = nil
  85. armor:register_armor(":"..mod..":helmet_"..name, {
  86. description = desc.." Helmet",
  87. inventory_image = "armor_inv_helmet.png^[colorize:"..color,
  88. texture = "3d_armor_dummy_image.png^(armor_helmet.png^[colorize:"..color..")^3d_armor_dummy_image",
  89. -- I'm not going to try to explain how this texture hack works. Really, it shouldn't.
  90. preview = "3d_armor_preview_dummy_image.png^(armor_helmet_preview.png^[colorize:"..color..")^3d_armor_preview_dummy_image",
  91. groups = {armor_head=1, armor_heal=0, armor_use=uses,
  92. physics_speed=-0.01*weight, physics_gravity=0.01*weight},
  93. reciprocate_damage = hurt_back,
  94. armor_groups = {fleshy=small_armor},
  95. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=level},
  96. })
  97. armor:register_armor(":"..mod..":chestplate_"..name, {
  98. description = desc.." Chestplate",
  99. inventory_image = "armor_inv_chestplate.png^[colorize:"..color,
  100. texture = "3d_armor_dummy_image.png^(armor_chestplate.png^[colorize:"..color..")^3d_armor_dummy_image",
  101. preview = "3d_armor_preview_dummy_image.png^(armor_chestplate_preview.png^[colorize:"..color..")^3d_armor_preview_dummy_image",
  102. groups = {armor_torso=1, armor_heal=0, armor_use=uses,
  103. physics_speed=-0.04*weight, physics_gravity=0.04*weight},
  104. reciprocate_damage = hurt_back,
  105. armor_groups = {fleshy=big_armor},
  106. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=level},
  107. })
  108. armor:register_armor(":"..mod..":leggings_"..name, {
  109. description = desc.." Leggings",
  110. inventory_image = "armor_inv_leggings.png^[colorize:"..color,
  111. texture = "3d_armor_dummy_image.png^(armor_leggings.png^[colorize:"..color..")^3d_armor_dummy_image",
  112. preview = "3d_armor_preview_dummy_image.png^(armor_leggings_preview.png^[colorize:"..color..")^3d_armor_preview_dummy_image",
  113. groups = {armor_legs=1, armor_heal=0, armor_use=uses,
  114. physics_speed=-0.03*weight, physics_gravity=0.03*weight},
  115. reciprocate_damage = hurt_back,
  116. armor_groups = {fleshy=big_armor},
  117. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=level},
  118. })
  119. armor:register_armor(":"..mod..":boots_"..name, {
  120. description = desc.." Boots",
  121. inventory_image = "armor_inv_boots.png^[colorize:"..color,
  122. texture = "3d_armor_dummy_image.png^(armor_boots.png^[colorize:"..color..")^3d_armor_dummy_image",
  123. preview = "3d_armor_preview_dummy_image.png^(armor_boots_preview.png^[colorize:"..color..")^3d_armor_preview_dummy_image",
  124. groups = {armor_feet=1, armor_heal=0, armor_use=uses,
  125. physics_speed=-0.01*weight, physics_gravity=0.01*weight},
  126. reciprocate_damage = hurt_back,
  127. armor_groups = {fleshy=small_armor},
  128. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=level},
  129. })
  130. minetest.register_craft({
  131. output = mod..":helmet_"..name,
  132. recipe = {
  133. {ingredient, ingredient, ingredient},
  134. {ingredient, "", ingredient},
  135. {"", "", ""},
  136. },
  137. })
  138. minetest.register_craft({
  139. output = mod..":chestplate_"..name,
  140. recipe = {
  141. {ingredient, "", ingredient},
  142. {ingredient, ingredient, ingredient},
  143. {ingredient, ingredient, ingredient},
  144. },
  145. })
  146. minetest.register_craft({
  147. output = mod..":leggings_"..name,
  148. recipe = {
  149. {ingredient, ingredient, ingredient},
  150. {ingredient, "", ingredient},
  151. {ingredient, "", ingredient},
  152. },
  153. })
  154. minetest.register_craft({
  155. output = mod..":boots_"..name,
  156. recipe = {
  157. {ingredient, "", ingredient},
  158. {ingredient, "", ingredient},
  159. },
  160. })
  161. if not minetest.get_modpath("shields") then return end
  162. armor:register_armor(":"..mod..":shield_"..name, {
  163. description = desc.." Shield",
  164. inventory_image = "armor_inv_shield.png^[colorize:"..color,
  165. texture = "3d_armor_dummy_image.png^(armor_shield.png^[colorize:"..color..")^3d_armor_dummy_image.png",
  166. preview = "3d_armor_preview_dummy_image.png^(armor_shield_preview.png^[colorize:"..color..")^3d_armor_preview_dummy_image.png",
  167. groups = {armor_shield=1, armor_heal=0, armor_use=uses,
  168. physics_speed=-0.03*weight, physics_gravity=0.03*weight},
  169. armor_groups = {fleshy=small_armor},
  170. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=level},
  171. reciprocate_damage = hurt_back,
  172. on_damage = function(player)
  173. if not minetest.settings:get_bool("shields_disable_sounds") then
  174. minetest.sound_play(sound, {
  175. pos = player:get_pos(),
  176. max_hear_distance = 10,
  177. gain = 0.5,
  178. })
  179. end
  180. end,
  181. on_destroy = function(player)
  182. if not minetest.settings:get_bool("shields_disable_sounds") then
  183. minetest.sound_play("default_tool_breaks", {
  184. pos = player:get_pos(),
  185. max_hear_distance = 10,
  186. gain = 0.5,
  187. })
  188. end
  189. end,
  190. })
  191. minetest.register_craft({
  192. output = mod..":shield_"..name,
  193. recipe = {
  194. {ingredient, ingredient, ingredient},
  195. {ingredient, ingredient, ingredient},
  196. {"", ingredient, ""},
  197. },
  198. })
  199. end
  200. instant_ores.after_use = function(itemstack, user, node)
  201. -- Use this hack instead of the insane default which is impossible to work with.
  202. local tool = itemstack:get_tool_capabilities()
  203. local ndef = minetest.registered_nodes[node.name]
  204. local meta = itemstack:get_meta()
  205. local worn = meta:get_int("worn") or 0
  206. -- Using this hack allows tools to have more than 65535 uses, and still behave correctly.
  207. local uses
  208. if not (ndef and tool) then return end
  209. local wear = 0
  210. if ndef.groups.cracky and tool.groupcaps.cracky then
  211. uses = tool.groupcaps.cracky.uses
  212. wear = (4-ndef.groups.cracky)
  213. elseif ndef.groups.choppy and tool.groupcaps.choppy then
  214. uses = tool.groupcaps.choppy.uses
  215. wear = (4-ndef.groups.choppy)
  216. elseif ndef.groups.crumbly and tool.groupcaps.crumbly then
  217. uses = tool.groupcaps.crumbly.uses
  218. wear = (4-ndef.groups.crumbly)
  219. elseif ndef.groups.snappy and tool.groupcaps.snappy then
  220. uses = tool.groupcaps.snappy.uses
  221. wear = (4-ndef.groups.snappy)
  222. else
  223. return
  224. end
  225. if itemstack:get_wear() ~= math.floor(worn * (65536/uses)) then
  226. -- Something tried to change the wear value, adjust the true value to compensate.
  227. worn = math.floor((uses*itemstack:get_wear()/65536) + 0.5)
  228. end
  229. worn = worn + wear
  230. local breaksound = itemstack:get_definition().sound.breaks
  231. if uses then itemstack:set_wear(math.floor(worn * (65536/uses))) end
  232. if itemstack:get_count() == 0 and breaksound then
  233. minetest.sound_play(breaksound, {pos=user:get_pos(), max_hear_distance=6, gain=0.5})
  234. else
  235. meta:set_int("worn", worn)
  236. end
  237. return itemstack
  238. end
  239. instant_ores.null_function = function() end
  240. instant_ores.register_toolset = function(mod, name, desc, color, level, ingredient, --[[ Parameters after this can be omitted ]] optional_durability, optional_speed, infinite_use)
  241. local durability = optional_durability or (20*level*level*level)
  242. local afteruse = infinite_use and instant_ores.null_function or instant_ores.after_use
  243. local maketool = infinite_use and
  244. function(name, def)
  245. def.stack_max = 1
  246. minetest.register_craftitem(name, def)
  247. end
  248. or minetest.register_tool
  249. if level < 1 then level = 1 end
  250. local speed = optional_speed or level
  251. if speed > 2 then
  252. speed = speed*speed/level -- Correct for maxlevel having an effect on speed
  253. elseif speed < 0.001 then
  254. speed = 0.001
  255. else
  256. speed = speed/level
  257. end
  258. local gcap = {
  259. cracky = {},
  260. crumbly = {},
  261. choppy = {},
  262. snappy = {}
  263. }
  264. gcap.cracky[3] = 2.00/speed
  265. gcap.crumbly[3] = 1.00/speed
  266. gcap.crumbly[2] = 2.40/speed
  267. gcap.crumbly[1] = 3.60/speed
  268. gcap.choppy[3] = 2.60/speed
  269. gcap.choppy[2] = 4.00/speed
  270. gcap.snappy[3] = 0.80 / speed
  271. gcap.snappy[2] = 2.80 / speed
  272. if level > 1 then
  273. gcap.cracky[2] = 4.00 / speed
  274. gcap.choppy[1] = 6.00 /speed
  275. if level > 2 then
  276. gcap.cracky[1] = 6.00 /speed
  277. gcap.snappy[1] = 7.50 /speed
  278. end
  279. end
  280. maketool(":"..mod..":pick_"..name, {
  281. description = desc.." Pickaxe",
  282. inventory_image = "tool_base.png^tool_pick_base.png^(tool_pick.png^[colorize:"..color..")",
  283. tool_capabilities = {
  284. full_punch_interval = 2.67/(optional_speed or level),
  285. max_drop_level=level,
  286. groupcaps={
  287. cracky = {uses=durability, maxlevel=level, times=gcap.cracky},
  288. },
  289. damage_groups = {fleshy=level+1},
  290. },
  291. groups = {pick = 1},
  292. sound = {breaks = "default_tool_breaks"},
  293. after_use = afteruse,
  294. })
  295. if instant_ores.stick then
  296. minetest.register_craft({
  297. output = mod..":pick_"..name,
  298. recipe = {
  299. {ingredient, ingredient, ingredient},
  300. {"",instant_ores.stick,""},
  301. {"",instant_ores.stick,""}
  302. }
  303. })
  304. end
  305. maketool(":"..mod..":shovel_"..name, {
  306. description = desc.." Shovel",
  307. inventory_image = "tool_base.png^tool_shovel_base.png^(tool_shovel.png^[colorize:"..color..")",
  308. wield_image = "tool_base.png^tool_shovel_base.png^(tool_shovel.png^[colorize:"..color..")^[transformR90",
  309. tool_capabilities = {
  310. full_punch_interval = 3/(optional_speed or level),
  311. max_drop_level=level,
  312. groupcaps={
  313. crumbly = {uses=durability, maxlevel=level, times=gcap.crumbly},
  314. },
  315. damage_groups = {fleshy=level},
  316. },
  317. groups = {shovel = 1},
  318. sound = {breaks = "default_tool_breaks"},
  319. after_use = afteruse,
  320. })
  321. if instant_ores.stick then
  322. minetest.register_craft({
  323. output = mod..":shovel_"..name,
  324. recipe = {
  325. {ingredient},
  326. {instant_ores.stick},
  327. {instant_ores.stick}
  328. }
  329. })
  330. end
  331. maketool(":"..mod..":axe_"..name, {
  332. description = desc.." Axe",
  333. inventory_image = "tool_base.png^tool_axe_base.png^(tool_axe.png^[colorize:"..color..")",
  334. tool_capabilities = {
  335. full_punch_interval = 2.67/(optional_speed or level),
  336. max_drop_level=level,
  337. groupcaps={
  338. choppy={uses=durability, maxlevel=level, times=gcap.choppy},
  339. },
  340. damage_groups = {fleshy=level+2},
  341. },
  342. groups = {axe = 1},
  343. sound = {breaks = "default_tool_breaks"},
  344. after_use = afteruse,
  345. })
  346. if instant_ores.stick then
  347. minetest.register_craft({
  348. output = mod..":axe_"..name,
  349. recipe = {
  350. {ingredient, ingredient},
  351. {ingredient,instant_ores.stick},
  352. {"",instant_ores.stick}
  353. }
  354. })
  355. end
  356. maketool(":"..mod..":sword_"..name, {
  357. description = desc.." Sword",
  358. inventory_image = "tool_base.png^tool_sword_base.png^(tool_sword.png^[colorize:"..color..")",
  359. tool_capabilities = {
  360. full_punch_interval = 2.25/(optional_speed or level),
  361. max_drop_level=level,
  362. groupcaps={
  363. snappy={uses=durability, maxlevel=level, times=gcap.snappy},
  364. },
  365. damage_groups = {fleshy=level+3},
  366. },
  367. groups = {sword = 1},
  368. sound = {breaks = "default_tool_breaks"},
  369. after_use = afteruse,
  370. })
  371. if instant_ores.stick then
  372. minetest.register_craft({
  373. output = mod..":sword_"..name,
  374. recipe = {
  375. {ingredient},
  376. {ingredient},
  377. {instant_ores.stick}
  378. }
  379. })
  380. end
  381. if farming then
  382. farming.register_hoe(mod..":hoe_"..name, {
  383. description = desc.." Hoe",
  384. inventory_image = "tool_base.png^tool_hoe_base.png^(tool_hoe.png^[colorize:"..color..")",
  385. max_uses = durability,
  386. material = ingredient,
  387. groups = {hoe=1},
  388. after_use = afteruse,
  389. })
  390. end
  391. end
  392. instant_ores.register_metal = function(metal)
  393. local name = string.split(metal.name, ":")
  394. if #name ~= 2 then
  395. error("metal.name must be the mod name and the metal name separated by ':'")
  396. end
  397. -- name should be in 'mod:material' format (e.g 'aliens:plutonium', 'minerals_plus:tungsten', 'fairytest:enchanted_steel')
  398. -- Fallbacks for properties that *shouldn't* be omitted
  399. metal.description = metal.description or "Terribly Programmed" -- :P
  400. metal.power = metal.power or 3 -- If someone can't decide how strong to make their metal, make it a bit stronger than steel.
  401. --Properties that can reasonably be omitted, as they're not strictly necessary, and sane defaults exist.
  402. --NOTE: setting a custom image will disable automatic colorization.
  403. metal.lump_image = metal.lump_image or ("metal_lump_base.png^(metal_lump.png^[colorize:"..metal.color..")")
  404. metal.ingot_image = metal.ingot_image or ("default_steel_ingot.png^[colorize:"..metal.color)
  405. metal.ore_image = metal.ore_image or ("default_stone.png^mineral_0_base.png^(mineral_0.png^[colorize:"..metal.color..")")
  406. metal.block_image = metal.block_image or ("default_steel_block.png^[colorize:"..metal.color)
  407. metal.tool_ingredient = metal.tool_ingredient or (metal.name.."_ingot")
  408. metal.hardness = metal.hardness or (metal.power - 1)
  409. local crackiness = 1
  410. if metal.hardness < 3 then
  411. if metal.hardness < 1 then
  412. crackiness = 3
  413. else
  414. crackiness = 4 - metal.hardness
  415. end
  416. end
  417. local groups = {cracky = crackiness, level=metal.hardness}
  418. minetest.register_craftitem(":"..metal.name.."_ingot", {
  419. description = metal.description.." Ingot",
  420. inventory_image = metal.ingot_image,
  421. })
  422. minetest.register_node(":"..metal.name.."block", {
  423. description = metal.description.." Block",
  424. tiles = {metal.block_image},
  425. is_ground_content = false,
  426. groups = table.copy(groups),
  427. sounds = instant_ores.node_sound_metal_defaults(),
  428. })
  429. local i = metal.name.."_ingot"
  430. local iii = {i,i,i}
  431. minetest.register_craft({
  432. output = metal.name.."block",
  433. recipe = {iii,iii,iii}
  434. })
  435. minetest.register_craft({
  436. type="shapeless",
  437. output = i.." 9",
  438. recipe = {metal.name.."block"}
  439. })
  440. if not metal.artificial then -- Ore-less metals (like bronze) can disable lumps and ore. This will *NOT* make a recipe for your alloy/special metal/whatever.
  441. --Depth and rarity only needed if ore generated.
  442. metal.depth = metal.depth or 32
  443. metal.rarity = metal.rarity or 11
  444. metal.large_depth = metal.large_depth or 2*metal.depth
  445. minetest.register_craftitem(":"..metal.name.."_lump", {
  446. description = metal.description.." Lump",
  447. inventory_image = metal.lump_image,
  448. })
  449. minetest.register_craft({
  450. type = "cooking",
  451. output = metal.name.."_ingot",
  452. recipe = metal.name.."_lump",
  453. cooktime = metal.cooktime
  454. })
  455. minetest.register_node(":"..name[1]..":stone_with_"..name[2], {
  456. description = metal.description.." Ore",
  457. tiles = {metal.ore_image},
  458. groups = table.copy(groups),
  459. drop = metal.name.."_lump",
  460. sounds = instant_ores.node_sound_stone_defaults(),
  461. })
  462. instant_ores.register_gen_ore(
  463. name[1]..":stone_with_"..name[2],
  464. metal.rarity,
  465. --[[ For reference,
  466. 8 = coal (approx)
  467. 12 = copper (approx)
  468. 14 = mese (approx)
  469. Actual scarcity of clusters is this value cubed, but this affects the size of clusters as well.
  470. ]]
  471. -metal.depth,
  472. -metal.large_depth
  473. )
  474. end
  475. if not metal.no_tools then
  476. instant_ores.register_toolset(
  477. name[1],
  478. name[2],
  479. metal.description,
  480. metal.color,
  481. metal.power, -- For reference, 2 is based on the power of stone tools.
  482. metal.tool_ingredient, --Must be a valid item
  483. metal.durability, -- can be nil, will be calculated from power if omitted.
  484. metal.speed,
  485. metal.infinite_uses
  486. )
  487. end
  488. if not metal.no_armor then
  489. instant_ores.register_armorset(name[1], name[2],
  490. metal.description,
  491. metal.color,
  492. metal.power,
  493. metal.tool_ingredient,
  494. metal.armor_durability or metal.durability, -- will be calculated from power if both are nil.
  495. metal.infinite_uses,
  496. metal.shield_damage_sound or "default_dig_metal",
  497. metal.armor_protection,
  498. metal.armor_hurtback,
  499. metal.armor_weight)
  500. end
  501. end
  502. instant_ores.register_crystal = function(crystal)
  503. local name = string.split(crystal.name, ":")
  504. if #name ~= 2 then
  505. error("crystal.name must be the mod name and the crystal name separated by ':'")
  506. end
  507. -- Fallbacks for properties that *shouldn't* be omitted
  508. crystal.description = crystal.description or "Terribly Programmed" -- :P
  509. crystal.power = crystal.power or 3 -- If someone can't decide how strong to make their crystal, make it a bit stronger than steel.
  510. --Properties that can reasonably be omitted, as they're not strictly necessary, and sane defaults exist.
  511. --NOTE: setting a custom image will disable automatic colorization.
  512. crystal.shard_image = crystal.shard_image or ("crystal_shard_base.png^(crystal_shard.png^[colorize:"..crystal.color..")")
  513. crystal.crystal_image = crystal.crystal_image or ("crystal_1_base.png^(crystal_1.png^[colorize:"..crystal.color..")")
  514. crystal.ore_image = crystal.ore_image or ("default_stone.png^mineral_1_base.png^(mineral_1.png^[colorize:"..crystal.color..")")
  515. crystal.block_image = crystal.block_image or ("crystal_block.png^[colorize:"..crystal.color)
  516. crystal.tool_ingredient = crystal.tool_ingredient or (crystal.name.."_crystal")
  517. crystal.hardness = crystal.hardness or (crystal.power - 1)
  518. local crackiness = 1
  519. if crystal.hardness < 3 then
  520. if crystal.hardness < 1 then
  521. crackiness = 3
  522. else
  523. crackiness = 4 - crystal.hardness
  524. end
  525. end
  526. local groups = {cracky = crackiness, level=crystal.hardness}
  527. minetest.register_craftitem(":"..crystal.name.."_crystal", {
  528. description = crystal.description.." Crystal",
  529. inventory_image = crystal.crystal_image,
  530. })
  531. minetest.register_craftitem(":"..crystal.name.."_shard", {
  532. description = crystal.description.." Shard",
  533. inventory_image = crystal.shard_image,
  534. })
  535. minetest.register_node(":"..crystal.name.."block", {
  536. description = crystal.description.." Block",
  537. tiles = {crystal.block_image},
  538. is_ground_content = false,
  539. groups = table.copy(groups),
  540. sounds = instant_ores.node_sound_stone_defaults(),
  541. })
  542. local s = crystal.name.."_shard"
  543. local sss = {s,s,s}
  544. local i = crystal.name.."_crystal"
  545. local iii = {i,i,i}
  546. minetest.register_craft({
  547. output = i,
  548. recipe = {sss,sss,sss}
  549. })
  550. minetest.register_craft({
  551. type = "shapeless",
  552. output = s.." 9",
  553. recipe = {i}
  554. })
  555. minetest.register_craft({
  556. output = crystal.name.."block",
  557. recipe = {iii,iii,iii}
  558. })
  559. minetest.register_craft({
  560. type="shapeless",
  561. output = i.." 9",
  562. recipe = {crystal.name.."block"}
  563. })
  564. if not crystal.artificial then -- Ore-less crystals can disable oregen. This will *NOT* make a recipe for your crystal/whatever.
  565. --Depth and rarity only needed if ore generated.
  566. crystal.depth = crystal.depth or 32
  567. crystal.rarity = crystal.rarity or 11
  568. crystal.large_depth = crystal.large_depth or 2*crystal.depth
  569. minetest.register_node(":"..name[1]..":stone_with_"..name[2], {
  570. description = crystal.description.." Ore",
  571. tiles = {crystal.ore_image},
  572. groups = table.copy(groups),
  573. drop = crystal.name.."_crystal",
  574. sounds = instant_ores.node_sound_stone_defaults(),
  575. })
  576. instant_ores.register_gen_ore(
  577. name[1]..":stone_with_"..name[2],
  578. crystal.rarity,
  579. --[[ For reference,
  580. 8 = coal (approx)
  581. 12 = copper (approx)
  582. 14 = mese (approx)
  583. Actual scarcity of clusters is this value cubed, but this affects the size of clusters as well.
  584. ]]
  585. -crystal.depth,
  586. -crystal.large_depth
  587. )
  588. end
  589. if not crystal.no_tools then
  590. instant_ores.register_toolset(
  591. name[1],
  592. name[2],
  593. crystal.description,
  594. crystal.color,
  595. crystal.power, -- For reference, 2 is based on the power of stone tools.
  596. crystal.tool_ingredient, --Must be a valid item
  597. crystal.durability, -- can be nil, will be calculated from power if omitted.
  598. crystal.speed,
  599. crystal.infinite_uses
  600. )
  601. end
  602. instant_ores.register_armorset(name[1], name[2],
  603. crystal.description,
  604. crystal.color,
  605. crystal.power,
  606. crystal.tool_ingredient,
  607. crystal.armor_durability or crystal.durability, -- will be calculated from power if both are nil.
  608. crystal.infinite_uses,
  609. crystal.shield_damage_sound or "default_glass_footstep",
  610. crystal.armor_protection,
  611. crystal.armor_hurtback,
  612. crystal.armor_weight)
  613. end
  614. -- test-ores (WARNING: _VERY_ UNBALANCED)
  615. --dofile(minetest.get_modpath("instant_ores").."/examples.lua")