init.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. --------------------------------------------------------------------------------
  2. -- Gem Tools Mod for Must Test Survival
  3. -- Author: GoldFireUn
  4. -- License of Source Code: MIT
  5. -- License of Media: CC BY-SA 3.0
  6. --------------------------------------------------------------------------------
  7. gem_tools = gem_tools or {}
  8. gem_tools.modpath = minetest.get_modpath("gem_tools")
  9. -- This code is executed only once.
  10. if not gem_tools.registered then
  11. local function register_sword(material, result, reinforced)
  12. minetest.register_craft({
  13. output = result,
  14. recipe = {
  15. {'', material, ''},
  16. {'farming:string', material, 'farming:string'},
  17. {'', 'default:sword_steel', ''},
  18. }
  19. })
  20. minetest.register_craft({
  21. output = reinforced,
  22. recipe = {
  23. {'', material, ''},
  24. {'farming:string', material, 'farming:string'},
  25. {'', 'titanium:sword', ''},
  26. }
  27. })
  28. end
  29. local function register_pick(material, result, reinforced)
  30. minetest.register_craft({
  31. output = result,
  32. recipe = {
  33. {material, material, material},
  34. {'', 'farming:string', ''},
  35. {'', 'default:pick_steel', ''},
  36. }
  37. })
  38. minetest.register_craft({
  39. output = reinforced,
  40. recipe = {
  41. {material, material, material},
  42. {'', 'farming:string', ''},
  43. {'', 'titanium:pick', ''},
  44. }
  45. })
  46. end
  47. local function register_axe(material, result, reinforced)
  48. minetest.register_craft({
  49. output = result,
  50. recipe = {
  51. {material, material, ''},
  52. {material, 'farming:string', ''},
  53. {'', 'default:axe_steel', ''},
  54. }
  55. })
  56. minetest.register_craft({
  57. output = result,
  58. recipe = {
  59. {'', material, material},
  60. {'', 'farming:string', material},
  61. {'', 'default:axe_steel', ''},
  62. }
  63. })
  64. minetest.register_craft({
  65. output = reinforced,
  66. recipe = {
  67. {material, material, ''},
  68. {material, 'farming:string', ''},
  69. {'', 'titanium:axe', ''},
  70. }
  71. })
  72. minetest.register_craft({
  73. output = reinforced,
  74. recipe = {
  75. {'', material, material},
  76. {'', 'farming:string', material},
  77. {'', 'titanium:axe', ''},
  78. }
  79. })
  80. end
  81. local function register_shovel(material, result, reinforced)
  82. minetest.register_craft({
  83. output = result,
  84. recipe = {
  85. {material},
  86. {'farming:string'},
  87. {'default:shovel_steel'},
  88. }
  89. })
  90. minetest.register_craft({
  91. output = reinforced,
  92. recipe = {
  93. {material},
  94. {'farming:string'},
  95. {'titanium:shovel'},
  96. }
  97. })
  98. end
  99. local gems = {
  100. {name="ruby", desc="Ruby"},
  101. {name="amethyst", desc="Amethyst"},
  102. {name="sapphire", desc="Sapphire"},
  103. {name="emerald", desc="Emerald"},
  104. }
  105. local tools = {
  106. {tool="pick", desc="Pickaxe", register=register_pick},
  107. {tool="sword", desc="Sword", register=register_sword},
  108. {tool="axe", desc="Axe", register=register_axe},
  109. {tool="shovel", desc="Shovel", register=register_shovel},
  110. }
  111. for k, v in ipairs(gems) do
  112. for i, j in ipairs(tools) do
  113. local material = "gems:" .. v.name .. "_gem"
  114. local tool = "gems:" .. j.tool .. "_" .. v.name
  115. local tool_rf_old = "gems:stone_" .. j.tool .. "_" .. v.name
  116. local tool_rf = "gems:rf_" .. j.tool .. "_" .. v.name
  117. local desc = v.desc .. " " .. j.desc
  118. local desc_rf = v.desc .. " " .. j.desc .. " (Reinforced Handle)"
  119. local data = j.tool .. "_" .. v.name
  120. local data_rf = j.tool .. "_" .. v.name .. "_rf"
  121. local iimg = "gem_tools_" .. v.name .. "_" .. j.tool .. ".png"
  122. local iimg_rf = "gem_tools_rf_" .. v.name .. "_" .. j.tool .. ".png"
  123. -- Ensure tooldata exists.
  124. assert(tooldata[data])
  125. assert(tooldata[data_rf])
  126. minetest.register_tool(":" .. tool, {
  127. description = desc,
  128. inventory_image = iimg,
  129. tool_capabilities = tooldata[data],
  130. groups = {gem_tool=1},
  131. })
  132. minetest.register_tool(":" .. tool_rf, {
  133. description = desc_rf,
  134. inventory_image = iimg_rf,
  135. tool_capabilities = tooldata[data_rf],
  136. groups = {gem_tool=1},
  137. })
  138. -- Register craft recipes.
  139. j.register(material, tool, tool_rf)
  140. -- Alias old tools.
  141. minetest.register_alias(tool_rf_old, tool_rf)
  142. end
  143. end
  144. -- Give players back their steel ingots.
  145. minetest.register_alias("gems:stone_rod", "default:steel_ingot")
  146. local c = "gem_tools:core"
  147. local f = gem_tools.modpath .. "/init.lua"
  148. reload.register_file(c, f, false)
  149. gem_tools.registered = true
  150. end