init.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. -- support for i18n
  2. local S = armor_i18n.gettext
  3. local disable_sounds = minetest.settings:get_bool("shields_disable_sounds")
  4. local use_moreores = minetest.get_modpath("moreores")
  5. local function play_sound_effect(player, name)
  6. if not disable_sounds and player then
  7. local pos = player:get_pos()
  8. if pos then
  9. minetest.sound_play(name, {
  10. pos = pos,
  11. max_hear_distance = 10,
  12. gain = 0.5,
  13. })
  14. end
  15. end
  16. end
  17. if minetest.global_exists("armor") and armor.elements then
  18. table.insert(armor.elements, "shield")
  19. local mult = armor.config.level_multiplier or 1
  20. armor.config.level_multiplier = mult * 0.9
  21. end
  22. -- Regisiter Shields
  23. armor:register_armor("shields:shield_admin", {
  24. description = S("Admin Shield"),
  25. inventory_image = "shields_inv_shield_admin.png",
  26. groups = {armor_shield=1000, armor_heal=100, armor_use=0, not_in_creative_inventory=1},
  27. })
  28. minetest.register_alias("adminshield", "shields:shield_admin")
  29. if armor.materials.wood then
  30. armor:register_armor("shields:shield_wood", {
  31. description = S("Wooden Shield"),
  32. inventory_image = "shields_inv_shield_wood.png",
  33. groups = {armor_shield=1, armor_heal=0, armor_use=2000, flammable=1},
  34. armor_groups = {fleshy=5},
  35. damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1},
  36. reciprocate_damage = true,
  37. on_damage = function(player, index, stack)
  38. play_sound_effect(player, "default_wood_footstep")
  39. end,
  40. on_destroy = function(player, index, stack)
  41. play_sound_effect(player, "default_wood_footstep")
  42. end,
  43. })
  44. armor:register_armor("shields:shield_enhanced_wood", {
  45. description = S("Enhanced Wood Shield"),
  46. inventory_image = "shields_inv_shield_enhanced_wood.png",
  47. groups = {armor_shield=1, armor_heal=0, armor_use=2000},
  48. armor_groups = {fleshy=8},
  49. damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=2},
  50. reciprocate_damage = true,
  51. on_damage = function(player, index, stack)
  52. play_sound_effect(player, "default_dig_metal")
  53. end,
  54. on_destroy = function(player, index, stack)
  55. play_sound_effect(player, "default_dug_metal")
  56. end,
  57. })
  58. minetest.register_craft({
  59. output = "shields:shield_enhanced_wood",
  60. recipe = {
  61. {"default:steel_ingot"},
  62. {"shields:shield_wood"},
  63. {"default:steel_ingot"},
  64. },
  65. })
  66. end
  67. if armor.materials.cactus then
  68. armor:register_armor("shields:shield_cactus", {
  69. description = S("Cactus Shield"),
  70. inventory_image = "shields_inv_shield_cactus.png",
  71. groups = {armor_shield=1, armor_heal=0, armor_use=1000},
  72. armor_groups = {fleshy=5},
  73. damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1},
  74. reciprocate_damage = true,
  75. on_damage = function(player, index, stack)
  76. play_sound_effect(player, "default_wood_footstep")
  77. end,
  78. on_destroy = function(player, index, stack)
  79. play_sound_effect(player, "default_wood_footstep")
  80. end,
  81. })
  82. armor:register_armor("shields:shield_enhanced_cactus", {
  83. description = S("Enhanced Cactus Shield"),
  84. inventory_image = "shields_inv_shield_enhanced_cactus.png",
  85. groups = {armor_shield=1, armor_heal=0, armor_use=1000},
  86. armor_groups = {fleshy=8},
  87. damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=2},
  88. reciprocate_damage = true,
  89. on_damage = function(player, index, stack)
  90. play_sound_effect(player, "default_dig_metal")
  91. end,
  92. on_destroy = function(player, index, stack)
  93. play_sound_effect(player, "default_dug_metal")
  94. end,
  95. })
  96. minetest.register_craft({
  97. output = "shields:shield_enhanced_cactus",
  98. recipe = {
  99. {"default:steel_ingot"},
  100. {"shields:shield_cactus"},
  101. {"default:steel_ingot"},
  102. },
  103. })
  104. end
  105. if armor.materials.steel then
  106. armor:register_armor("shields:shield_steel", {
  107. description = S("Steel Shield"),
  108. inventory_image = "shields_inv_shield_steel.png",
  109. groups = {armor_shield=1, armor_heal=0, armor_use=800,
  110. physics_speed=-0.03, physics_gravity=0.03},
  111. armor_groups = {fleshy=10},
  112. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2},
  113. reciprocate_damage = true,
  114. on_damage = function(player, index, stack)
  115. play_sound_effect(player, "default_dig_metal")
  116. end,
  117. on_destroy = function(player, index, stack)
  118. play_sound_effect(player, "default_dug_metal")
  119. end,
  120. })
  121. end
  122. if armor.materials.bronze then
  123. armor:register_armor("shields:shield_bronze", {
  124. description = S("Bronze Shield"),
  125. inventory_image = "shields_inv_shield_bronze.png",
  126. groups = {armor_shield=1, armor_heal=6, armor_use=400,
  127. physics_speed=-0.03, physics_gravity=0.03},
  128. armor_groups = {fleshy=10},
  129. damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2},
  130. reciprocate_damage = true,
  131. on_damage = function(player, index, stack)
  132. play_sound_effect(player, "default_dig_metal")
  133. end,
  134. on_destroy = function(player, index, stack)
  135. play_sound_effect(player, "default_dug_metal")
  136. end,
  137. })
  138. end
  139. if armor.materials.diamond then
  140. armor:register_armor("shields:shield_diamond", {
  141. description = S("Diamond Shield"),
  142. inventory_image = "shields_inv_shield_diamond.png",
  143. groups = {armor_shield=1, armor_heal=12, armor_use=200},
  144. armor_groups = {fleshy=15},
  145. damage_groups = {cracky=2, snappy=1, choppy=1, level=3},
  146. reciprocate_damage = true,
  147. on_damage = function(player, index, stack)
  148. play_sound_effect(player, "default_glass_footstep")
  149. end,
  150. on_destroy = function(player, index, stack)
  151. play_sound_effect(player, "default_break_glass")
  152. end,
  153. })
  154. end
  155. if armor.materials.gold then
  156. armor:register_armor("shields:shield_gold", {
  157. description = S("Gold Shield"),
  158. inventory_image = "shields_inv_shield_gold.png",
  159. groups = {armor_shield=1, armor_heal=6, armor_use=300,
  160. physics_speed=-0.04, physics_gravity=0.04},
  161. armor_groups = {fleshy=10},
  162. damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2},
  163. reciprocate_damage = true,
  164. on_damage = function(player, index, stack)
  165. play_sound_effect(player, "default_dig_metal")
  166. end,
  167. on_destroy = function(player, index, stack)
  168. play_sound_effect(player, "default_dug_metal")
  169. end,
  170. })
  171. end
  172. if armor.materials.mithril then
  173. armor:register_armor("shields:shield_mithril", {
  174. description = S("Mithril Shield"),
  175. inventory_image = "shields_inv_shield_mithril.png",
  176. groups = {armor_shield=1, armor_heal=12, armor_use=100},
  177. armor_groups = {fleshy=15},
  178. damage_groups = {cracky=2, snappy=1, level=3},
  179. reciprocate_damage = true,
  180. on_damage = function(player, index, stack)
  181. play_sound_effect(player, "default_glass_footstep")
  182. end,
  183. on_destroy = function(player, index, stack)
  184. play_sound_effect(player, "default_break_glass")
  185. end,
  186. })
  187. end
  188. if armor.materials.crystal then
  189. armor:register_armor("shields:shield_crystal", {
  190. description = S("Crystal Shield"),
  191. inventory_image = "shields_inv_shield_crystal.png",
  192. groups = {armor_shield=1, armor_heal=12, armor_use=100, armor_fire=1},
  193. armor_groups = {fleshy=15},
  194. damage_groups = {cracky=2, snappy=1, level=3},
  195. reciprocate_damage = true,
  196. on_damage = function(player, index, stack)
  197. play_sound_effect(player, "default_glass_footstep")
  198. end,
  199. on_destroy = function(player, index, stack)
  200. play_sound_effect(player, "default_break_glass")
  201. end,
  202. })
  203. end
  204. for k, v in pairs(armor.materials) do
  205. minetest.register_craft({
  206. output = "shields:shield_"..k,
  207. recipe = {
  208. {v, v, v},
  209. {v, v, v},
  210. {"", v, ""},
  211. },
  212. })
  213. end