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.

386 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. hoe = {
  235. uses = 300,
  236. },
  237. shovel = {
  238. crumbly = {times = {[1] = 1.10, [2] = 0.40, [3] = 0.25}, uses = 100, maxlevel = 1},
  239. },
  240. axe = {
  241. choppy = {times = {[1] = 2.50, [2] = 0.80, [3] = 0.50}, uses = 100, maxlevel = 1},
  242. fleshy = {times = {[2] = 1.10, [3] = 0.60}, uses = 100, maxlevel = 1}
  243. },
  244. sword = {
  245. fleshy = {times = {[2] = 0.70, [3] = 0.30}, uses = 100, maxlevel = 1},
  246. snappy = {times = {[2] = 0.70, [3] = 0.30}, uses = 100, maxlevel = 1},
  247. choppy = {times = {[3] = 0.80}, uses = 100, maxlevel = 0},
  248. },
  249. },
  250. full_punch_interval = 1.0,
  251. damage_groups = {fleshy = 6},
  252. },
  253. mithril = {
  254. description = "Mithril",
  255. makes = {ore = true, block = true, lump = true, ingot = true, chest = false},
  256. oredef = {
  257. clust_scarcity = moreores.mithril_chunk_size ^ 3,
  258. clust_num_ores = moreores.mithril_ore_per_chunk,
  259. clust_size = moreores.mithril_chunk_size,
  260. y_min = moreores.mithril_min_depth,
  261. y_max = moreores.mithril_max_depth,
  262. },
  263. tools = {
  264. pick = {
  265. cracky = {times = {[1] = 2.25, [2] = 0.55, [3] = 0.35}, uses = 200, maxlevel = 2}
  266. },
  267. hoe = {
  268. uses = 1000,
  269. },
  270. shovel = {
  271. crumbly = {times = {[1] = 0.70, [2] = 0.35, [3] = 0.20}, uses = 200, maxlevel = 2},
  272. },
  273. axe = {
  274. choppy = {times = {[1] = 1.75, [2] = 0.45, [3] = 0.45}, uses = 200, maxlevel = 2},
  275. fleshy = {times = {[2] = 0.95, [3] = 0.30}, uses = 200, maxlevel = 1}
  276. },
  277. sword = {
  278. fleshy = {times = {[2] = 0.65, [3] = 0.25}, uses = 200, maxlevel = 2},
  279. snappy = {times = {[2] = 0.70, [3] = 0.25}, uses = 200, maxlevel = 2},
  280. choppy = {times = {[3] = 0.65}, uses = 200, maxlevel = 0},
  281. },
  282. },
  283. full_punch_interval = 0.45,
  284. damage_groups = {fleshy = 9},
  285. }
  286. }
  287. -- If tin is available in the `default` mod, don't register More Ores' variant of tin
  288. local default_tin
  289. if minetest.registered_items["default:tin_ingot"] then
  290. default_tin = true
  291. else
  292. default_tin = false
  293. end
  294. if default_tin then
  295. minetest.register_alias("moreores:mineral_tin", "default:stone_with_tin")
  296. minetest.register_alias("moreores:tin_lump", "default:tin_lump")
  297. minetest.register_alias("moreores:tin_ingot", "default:tin_ingot")
  298. minetest.register_alias("moreores:tin_block", "default:tinblock")
  299. else
  300. oredefs.tin = {
  301. description = "Tin",
  302. makes = {ore = true, block = true, lump = true, ingot = true, chest = false},
  303. oredef = {
  304. clust_scarcity = moreores.tin_chunk_size ^ 3,
  305. clust_num_ores = moreores.tin_ore_per_chunk,
  306. clust_size = moreores.tin_chunk_size,
  307. y_min = moreores.tin_min_depth,
  308. y_max = moreores.tin_max_depth,
  309. },
  310. tools = {},
  311. }
  312. -- Bronze has some special cases, because it is made from copper and tin
  313. minetest.register_craft({
  314. type = "shapeless",
  315. output = "default:bronze_ingot 3",
  316. recipe = {
  317. "moreores:tin_ingot",
  318. "default:copper_ingot",
  319. "default:copper_ingot",
  320. },
  321. })
  322. end
  323. -- Copper rail (unique node)
  324. if minetest.get_modpath("carts") then
  325. carts:register_rail("moreores:copper_rail", {
  326. description = S("Copper Rail"),
  327. tiles = {
  328. "moreores_copper_rail.png",
  329. "moreores_copper_rail_curved.png",
  330. "moreores_copper_rail_t_junction.png",
  331. "moreores_copper_rail_crossing.png",
  332. },
  333. inventory_image = "moreores_copper_rail.png",
  334. wield_image = "moreores_copper_rail.png",
  335. groups = carts:get_rail_groups(),
  336. }, {})
  337. end
  338. minetest.register_craft({
  339. output = "moreores:copper_rail 24",
  340. recipe = {
  341. {"default:copper_ingot", "", "default:copper_ingot"},
  342. {"default:copper_ingot", "group:stick", "default:copper_ingot"},
  343. {"default:copper_ingot", "", "default:copper_ingot"},
  344. },
  345. })
  346. for orename, def in pairs(oredefs) do
  347. -- Register everything
  348. add_ore("moreores", def.description, orename, def)
  349. end