api.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. local rock_def_prototype =
  2. {
  3. is_ground_content = true,
  4. sounds = generic_media.node_sound_stone_defaults(),
  5. groups = {cracky = 3, stone = 1},
  6. drop = "cobble",
  7. }
  8. local rubble_def_prototype =
  9. {
  10. is_ground_content = false,
  11. groups = {crumbly = 3, falling_node = 1},
  12. sounds = generic_media.node_sound_gravel_defaults(),
  13. drop = "cobble",
  14. }
  15. local function get_rock_definition(texture)
  16. local ret = {}
  17. ret.tiles = {texture}
  18. for k, v in pairs(rock_def_prototype)
  19. do
  20. ret[k] = v
  21. end
  22. return ret
  23. end
  24. local function get_rubble_definition(texture)
  25. local ret = {}
  26. ret.tiles = {texture}
  27. for k, v in pairs(rubble_def_prototype)
  28. do
  29. ret[k] = v
  30. end
  31. return ret
  32. end
  33. local minerals =
  34. {
  35. "coal",
  36. "iron",
  37. "gold",
  38. "diamond",
  39. get_ore_def_gold = function(parent_rock_name)
  40. return
  41. {
  42. ore_type = "scatter",
  43. ore = parent_rock_name .. "_with_gold",
  44. wherein = parent_rock_name .. "_with_iron",
  45. clust_scarcity = 8 * 8 * 8,
  46. clust_num_ores = 6,
  47. clust_size = 3,
  48. y_min = -30,
  49. y_max = 1000,
  50. }
  51. end,
  52. get_ore_def_iron = function(parent_rock_name)
  53. return
  54. {
  55. ore_type = "scatter",
  56. ore = parent_rock_name .. "_with_iron",
  57. wherein = parent_rock_name .. "_with_coal",
  58. clust_scarcity = 4 * 4 * 4,
  59. clust_num_ores = 9,
  60. clust_size = 3,
  61. y_min = -30,
  62. y_max = 1000,
  63. }
  64. end,
  65. get_ore_def_diamond = function(parent_rock_name)
  66. return
  67. {
  68. ore_type = "scatter",
  69. ore = parent_rock_name .. "_with_diamond",
  70. wherein = parent_rock_name .. "_with_iron",
  71. clust_scarcity = 8 * 8 * 8,
  72. clust_num_ores = 6,
  73. clust_size = 3,
  74. y_min = -30,
  75. y_max = 1000,
  76. }
  77. end,
  78. get_ore_def_coal = function(parent_rock_name)
  79. return
  80. {
  81. ore_type = "vein",
  82. ore = parent_rock_name .. "_with_coal",
  83. wherein = parent_rock_name,
  84. clust_scarcity = 16 * 16 * 16,
  85. clust_num_ores = 3,
  86. clust_size = 3,
  87. y_min = -30,
  88. y_max = 1000,
  89. }
  90. end,
  91. }
  92. --TODO: register rubble versions
  93. local function register_ore_nodes(name, rock_texture, rubble_texture, S)
  94. for _, mineral in ipairs(minerals)
  95. do
  96. local rockdef = get_rock_definition(rock_texture ..
  97. "^rocks_api_" .. mineral .. "_ore.png")
  98. local rubbledef = get_rubble_definition(rubble_texture ..
  99. "^rocks_api_" .. mineral .. "_rubble.png")
  100. local descr = string.capitalize_first(mineral) .. " Ore"
  101. rockdef.description = S(descr)
  102. rubbledef.description = S(descr .. " Rubble")
  103. rockdef.drop =
  104. {
  105. max_items = 3,
  106. items =
  107. {
  108. {rarity = 1, items = {"cobble"}},
  109. {rarity = 1, items = {mineral}},
  110. {rarity = 2, items = {mineral}},
  111. }
  112. }
  113. rubbledef.drop = rockdef.drop
  114. minetest.register_node(name .. "_with_" .. mineral, rockdef)
  115. minetest.register_ore(minerals["get_ore_def_" .. mineral](name))
  116. minetest.register_node(name .. "_rubble_with_" .. mineral, rubbledef)
  117. erosion.register_erosion({name .. "_with_" .. mineral,
  118. name .. "_rubble_with_" .. mineral})
  119. end
  120. end
  121. function rocks_api.register_rock(name, description, texture, rubble_texture, translation_textdomain)
  122. local S = minetest.get_translator(translation_textdomain)
  123. local rockdef = get_rock_definition(texture)
  124. local rubbledef = get_rubble_definition(rubble_texture)
  125. rockdef.description = S(description)
  126. rubbledef.description = S(description .. " Rubble")
  127. minetest.register_node(name, rockdef)
  128. minetest.register_node(name .. "_rubble", rubbledef)
  129. register_ore_nodes(name, texture, rubble_texture, S)
  130. end