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