More Ores
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

380 lines
11KB

  1. --[[
  2. =====================================================================
  3. ** More Ores **
  4. By Calinou, with the help of Nore.
  5. Copyright © 2011-2020 Hugo Locurcio and contributors.
  6. Licensed under the zlib license. See LICENSE.md for more information.
  7. =====================================================================
  8. --]]
  9. moreores = {}
  10. local modpath = minetest.get_modpath("moreores")
  11. local S = minetest.get_translator("moreores")
  12. moreores.S = S
  13. dofile(modpath .. "/_config.txt")
  14. -- `mg` mapgen support
  15. if minetest.get_modpath("mg") then
  16. dofile(modpath .. "/mg.lua")
  17. end
  18. -- `frame` support
  19. local use_frame = minetest.get_modpath("frame")
  20. local default_stone_sounds = default.node_sound_stone_defaults()
  21. local default_metal_sounds = default.node_sound_metal_defaults()
  22. -- Returns the crafting recipe table for a given material and item.
  23. local function get_recipe(material, item)
  24. if item == "sword" then
  25. return {
  26. {material},
  27. {material},
  28. {"group:stick"},
  29. }
  30. end
  31. if item == "shovel" then
  32. return {
  33. {material},
  34. {"group:stick"},
  35. {"group:stick"},
  36. }
  37. end
  38. if item == "axe" then
  39. return {
  40. {material, material},
  41. {material, "group:stick"},
  42. {"", "group:stick"},
  43. }
  44. end
  45. if item == "pick" then
  46. return {
  47. {material, material, material},
  48. {"", "group:stick", ""},
  49. {"", "group:stick", ""},
  50. }
  51. end
  52. if item == "block" then
  53. return {
  54. {material, material, material},
  55. {material, material, material},
  56. {material, material, material},
  57. }
  58. end
  59. if item == "lockedchest" then
  60. return {
  61. {"group:wood", "group:wood", "group:wood"},
  62. {"group:wood", material, "group:wood"},
  63. {"group:wood", "group:wood", "group:wood"},
  64. }
  65. end
  66. end
  67. local function add_ore(modname, description, mineral_name, oredef)
  68. local img_base = modname .. "_" .. mineral_name
  69. local toolimg_base = modname .. "_tool_"..mineral_name
  70. local tool_base = modname .. ":"
  71. local tool_post = "_" .. mineral_name
  72. local item_base = tool_base .. mineral_name
  73. local ingot = item_base .. "_ingot"
  74. local lump_item = item_base .. "_lump"
  75. if oredef.makes.ore then
  76. minetest.register_node(modname .. ":mineral_" .. mineral_name, {
  77. description = S("@1 Ore", S(description)),
  78. tiles = {"default_stone.png^" .. modname .. "_mineral_" .. mineral_name .. ".png"},
  79. groups = {cracky = 2},
  80. sounds = default_stone_sounds,
  81. drop = lump_item,
  82. })
  83. if use_frame then
  84. frame.register(modname .. ":mineral_" .. mineral_name)
  85. end
  86. end
  87. if oredef.makes.block then
  88. local block_item = item_base .. "_block"
  89. minetest.register_node(block_item, {
  90. description = S("@1 Block", S(description)),
  91. tiles = {img_base .. "_block.png"},
  92. groups = {snappy = 1, bendy = 2, cracky = 1, melty = 2, level = 2},
  93. sounds = default_metal_sounds,
  94. })
  95. minetest.register_alias(mineral_name.."_block", block_item)
  96. if oredef.makes.ingot then
  97. minetest.register_craft( {
  98. output = block_item,
  99. recipe = get_recipe(ingot, "block")
  100. })
  101. minetest.register_craft( {
  102. output = ingot .. " 9",
  103. recipe = {
  104. {block_item},
  105. }
  106. })
  107. end
  108. if use_frame then
  109. frame.register(block_item)
  110. end
  111. end
  112. if oredef.makes.lump then
  113. minetest.register_craftitem(lump_item, {
  114. description = S("@1 Lump", S(description)),
  115. inventory_image = img_base .. "_lump.png",
  116. })
  117. minetest.register_alias(mineral_name .. "_lump", lump_item)
  118. if oredef.makes.ingot then
  119. minetest.register_craft({
  120. type = "cooking",
  121. output = ingot,
  122. recipe = lump_item,
  123. })
  124. end
  125. if use_frame then
  126. frame.register(lump_item)
  127. end
  128. end
  129. if oredef.makes.ingot then
  130. minetest.register_craftitem(ingot, {
  131. description = S("@1 Ingot", S(description)),
  132. inventory_image = img_base .. "_ingot.png",
  133. })
  134. minetest.register_alias(mineral_name .. "_ingot", ingot)
  135. if use_frame then
  136. frame.register(ingot)
  137. end
  138. end
  139. if oredef.makes.chest then
  140. minetest.register_craft( {
  141. output = "default:chest_locked",
  142. recipe = {
  143. {ingot},
  144. {"default:chest"},
  145. }
  146. })
  147. minetest.register_craft( {
  148. output = "default:chest_locked",
  149. recipe = get_recipe(ingot, "lockedchest")
  150. })
  151. end
  152. oredef.oredef.ore_type = "scatter"
  153. oredef.oredef.ore = modname .. ":mineral_" .. mineral_name
  154. oredef.oredef.wherein = "default:stone"
  155. minetest.register_ore(oredef.oredef)
  156. for tool_name, tooldef in pairs(oredef.tools) do
  157. local tdef = {
  158. description = "",
  159. inventory_image = toolimg_base .. tool_name .. ".png",
  160. tool_capabilities = {
  161. max_drop_level = 3,
  162. groupcaps = tooldef,
  163. },
  164. sound = {breaks = "default_tool_breaks"},
  165. }
  166. if tool_name == "sword" then
  167. tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval
  168. tdef.tool_capabilities.damage_groups = oredef.damage_groups
  169. tdef.description = S("@1 Sword", S(description))
  170. end
  171. if tool_name == "pick" then
  172. tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval
  173. tdef.tool_capabilities.damage_groups = oredef.damage_groups
  174. tdef.description = S("@1 Pickaxe", S(description))
  175. end
  176. if tool_name == "axe" then
  177. tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval
  178. tdef.tool_capabilities.damage_groups = oredef.damage_groups
  179. tdef.description = S("@1 Axe", S(description))
  180. end
  181. if tool_name == "shovel" then
  182. tdef.full_punch_interval = oredef.full_punch_interval
  183. tdef.tool_capabilities.damage_groups = oredef.damage_groups
  184. tdef.description = S("@1 Shovel", S(description))
  185. tdef.wield_image = toolimg_base .. tool_name .. ".png^[transformR90"
  186. end
  187. local fulltool_name = tool_base .. tool_name .. tool_post
  188. if tool_name == "hoe" and minetest.get_modpath("farming") then
  189. tdef.max_uses = tooldef.uses
  190. tdef.description = S("@1 Hoe", S(description))
  191. farming.register_hoe(fulltool_name, tdef)
  192. end
  193. -- Hoe registration is handled above.
  194. -- There are no crafting recipes for hoes, as they have been
  195. -- deprecated from Minetest Game:
  196. -- https://github.com/minetest/minetest_game/commit/9c459e77a
  197. if tool_name ~= "hoe" then
  198. minetest.register_tool(fulltool_name, tdef)
  199. if oredef.makes.ingot then
  200. minetest.register_craft({
  201. output = fulltool_name,
  202. recipe = get_recipe(ingot, tool_name)
  203. })
  204. end
  205. end
  206. -- Toolranks support
  207. if minetest.get_modpath("toolranks") then
  208. minetest.override_item(fulltool_name, {
  209. original_description = tdef.description,
  210. description = toolranks.create_description(tdef.description, 0, 1),
  211. after_use = toolranks.new_afteruse})
  212. end
  213. minetest.register_alias(tool_name .. tool_post, fulltool_name)
  214. if use_frame then
  215. frame.register(fulltool_name)
  216. end
  217. end
  218. end
  219. local oredefs = {
  220. silver = {
  221. description = "Silver",
  222. makes = {ore = true, block = true, lump = true, ingot = true, chest = true},
  223. oredef = {
  224. clust_scarcity = moreores.silver_chunk_size ^ 3,
  225. clust_num_ores = moreores.silver_ore_per_chunk,
  226. clust_size = moreores.silver_chunk_size,
  227. y_min = moreores.silver_min_depth,
  228. y_max = moreores.silver_max_depth,
  229. },
  230. tools = {
  231. pick = {
  232. cracky = {times = {[1] = 2.60, [2] = 1.00, [3] = 0.60}, uses = 100, maxlevel = 1},
  233. },
  234. shovel = {
  235. crumbly = {times = {[1] = 1.10, [2] = 0.40, [3] = 0.25}, uses = 100, maxlevel = 1},
  236. },
  237. axe = {
  238. choppy = {times = {[1] = 2.50, [2] = 0.80, [3] = 0.50}, uses = 100, maxlevel = 1},
  239. fleshy = {times = {[2] = 1.10, [3] = 0.60}, uses = 100, maxlevel = 1}
  240. },
  241. sword = {
  242. fleshy = {times = {[2] = 0.70, [3] = 0.30}, uses = 100, maxlevel = 1},
  243. snappy = {times = {[2] = 0.70, [3] = 0.30}, uses = 100, maxlevel = 1},
  244. choppy = {times = {[3] = 0.80}, uses = 100, maxlevel = 0},
  245. },
  246. },
  247. full_punch_interval = 1.0,
  248. damage_groups = {fleshy = 6},
  249. },
  250. mithril = {
  251. description = "Mithril",
  252. makes = {ore = true, block = true, lump = true, ingot = true, chest = false},
  253. oredef = {
  254. clust_scarcity = moreores.mithril_chunk_size ^ 3,
  255. clust_num_ores = moreores.mithril_ore_per_chunk,
  256. clust_size = moreores.mithril_chunk_size,
  257. y_min = moreores.mithril_min_depth,
  258. y_max = moreores.mithril_max_depth,
  259. },
  260. tools = {
  261. pick = {
  262. cracky = {times = {[1] = 2.25, [2] = 0.55, [3] = 0.35}, uses = 200, maxlevel = 2}
  263. },
  264. shovel = {
  265. crumbly = {times = {[1] = 0.70, [2] = 0.35, [3] = 0.20}, uses = 200, maxlevel = 2},
  266. },
  267. axe = {
  268. choppy = {times = {[1] = 1.75, [2] = 0.45, [3] = 0.45}, uses = 200, maxlevel = 2},
  269. fleshy = {times = {[2] = 0.95, [3] = 0.30}, uses = 200, maxlevel = 1}
  270. },
  271. sword = {
  272. fleshy = {times = {[2] = 0.65, [3] = 0.25}, uses = 200, maxlevel = 2},
  273. snappy = {times = {[2] = 0.70, [3] = 0.25}, uses = 200, maxlevel = 2},
  274. choppy = {times = {[3] = 0.65}, uses = 200, maxlevel = 0},
  275. },
  276. },
  277. full_punch_interval = 0.45,
  278. damage_groups = {fleshy = 9},
  279. }
  280. }
  281. -- If tin is available in the `default` mod, don't register More Ores' variant of tin
  282. local default_tin
  283. if minetest.registered_items["default:tin_ingot"] then
  284. default_tin = true
  285. else
  286. default_tin = false
  287. end
  288. if default_tin then
  289. minetest.register_alias("moreores:mineral_tin", "default:stone_with_tin")
  290. minetest.register_alias("moreores:tin_lump", "default:tin_lump")
  291. minetest.register_alias("moreores:tin_ingot", "default:tin_ingot")
  292. minetest.register_alias("moreores:tin_block", "default:tinblock")
  293. else
  294. oredefs.tin = {
  295. description = "Tin",
  296. makes = {ore = true, block = true, lump = true, ingot = true, chest = false},
  297. oredef = {
  298. clust_scarcity = moreores.tin_chunk_size ^ 3,
  299. clust_num_ores = moreores.tin_ore_per_chunk,
  300. clust_size = moreores.tin_chunk_size,
  301. y_min = moreores.tin_min_depth,
  302. y_max = moreores.tin_max_depth,
  303. },
  304. tools = {},
  305. }
  306. -- Bronze has some special cases, because it is made from copper and tin
  307. minetest.register_craft({
  308. type = "shapeless",
  309. output = "default:bronze_ingot 3",
  310. recipe = {
  311. "moreores:tin_ingot",
  312. "default:copper_ingot",
  313. "default:copper_ingot",
  314. },
  315. })
  316. end
  317. -- Copper rail (unique node)
  318. if minetest.get_modpath("carts") then
  319. carts:register_rail("moreores:copper_rail", {
  320. description = S("Copper Rail"),
  321. tiles = {
  322. "moreores_copper_rail.png",
  323. "moreores_copper_rail_curved.png",
  324. "moreores_copper_rail_t_junction.png",
  325. "moreores_copper_rail_crossing.png",
  326. },
  327. inventory_image = "moreores_copper_rail.png",
  328. wield_image = "moreores_copper_rail.png",
  329. groups = carts:get_rail_groups(),
  330. }, {})
  331. end
  332. minetest.register_craft({
  333. output = "moreores:copper_rail 18",
  334. recipe = {
  335. {"default:copper_ingot", "group:wood", "default:copper_ingot"},
  336. {"default:copper_ingot", "", "default:copper_ingot"},
  337. {"default:copper_ingot", "group:wood", "default:copper_ingot"},
  338. },
  339. })
  340. for orename, def in pairs(oredefs) do
  341. -- Register everything
  342. add_ore("moreores", def.description, orename, def)
  343. end