init.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. if not minetest.global_exists("armor") then armor = {} end
  2. armor.modname = armor.modname or minetest.get_current_modname()
  3. armor.modpath = minetest.get_modpath(armor.modname)
  4. armor.worldpath = minetest.get_worldpath()
  5. -- Increase this if you get initialization glitches when a player first joins.
  6. ARMOR_INIT_DELAY = 1
  7. -- Number of initialization attempts.
  8. -- Use in conjunction with ARMOR_INIT_DELAY if initialization problems persist.
  9. ARMOR_INIT_TIMES = 1
  10. -- Increase this if armor is not getting into bones due to server lag.
  11. ARMOR_BONES_DELAY = 1
  12. -- How often player armor/wield items are updated.
  13. ARMOR_UPDATE_TIME = 1
  14. -- You can use this to increase or decrease overall armor effectiveness,
  15. -- eg: ARMOR_LEVEL_MULTIPLIER = 0.5 will reduce armor level by half.
  16. ARMOR_LEVEL_MULTIPLIER = 1.0
  17. -- You can use this to increase or decrease overall armor healing,
  18. -- eg: ARMOR_HEAL_MULTIPLIER = 0 will disable healing altogether.
  19. ARMOR_HEAL_MULTIPLIER = 1.0
  20. dofile(armor.modpath .. "/armor.lua")
  21. dofile(armor.modpath .. "/stomp.lua")
  22. if not armor.run_once then
  23. armor.run_once = true
  24. local function register_piece(name, data)
  25. data._armor_resist_groups = sysdmg.get_armor_resist_for(name)
  26. data._armor_wear_groups = sysdmg.get_armor_wear_for(name)
  27. data.groups = sysdmg.get_armor_groups_for(name, data.groups)
  28. minetest.register_tool(name, data)
  29. end
  30. -- Materials can only be loaded once, obviously.
  31. ARMOR_MATERIALS = {
  32. wood = "group:wood",
  33. steel = "default:steel_ingot",
  34. bronze = "default:bronze_ingot",
  35. diamond = "default:diamond",
  36. gold = "default:gold_ingot",
  37. mithril = "moreores:mithril_ingot",
  38. carbon = "carbon_steel:ingot",
  39. }
  40. if ARMOR_MATERIALS.wood then
  41. register_piece("3d_armor:helmet_wood", {
  42. description = "Wood Helmet",
  43. inventory_image = "3d_armor_inv_helmet_wood.png",
  44. groups = {armor_head=1},
  45. })
  46. register_piece("3d_armor:chestplate_wood", {
  47. description = "Wood Chestplate",
  48. inventory_image = "3d_armor_inv_chestplate_wood.png",
  49. groups = {armor_torso=1},
  50. })
  51. register_piece("3d_armor:leggings_wood", {
  52. description = "Wood Leggings",
  53. inventory_image = "3d_armor_inv_leggings_wood.png",
  54. groups = {armor_legs=1},
  55. })
  56. register_piece("3d_armor:boots_wood", {
  57. description = "Wood Boots",
  58. inventory_image = "3d_armor_inv_boots_wood.png",
  59. groups = {armor_feet=1},
  60. })
  61. end
  62. if ARMOR_MATERIALS.steel then
  63. register_piece("3d_armor:helmet_steel", {
  64. description = "Wrought Iron Helmet",
  65. inventory_image = "3d_armor_inv_helmet_steel.png",
  66. groups = {armor_head=1},
  67. })
  68. register_piece("3d_armor:chestplate_steel", {
  69. description = "Wrought Iron Chestplate",
  70. inventory_image = "3d_armor_inv_chestplate_steel.png",
  71. groups = {armor_torso=1},
  72. })
  73. register_piece("3d_armor:leggings_steel", {
  74. description = "Wrought Iron Leggings",
  75. inventory_image = "3d_armor_inv_leggings_steel.png",
  76. groups = {armor_legs=1},
  77. })
  78. register_piece("3d_armor:boots_steel", {
  79. description = "Wrought Iron Boots",
  80. inventory_image = "3d_armor_inv_boots_steel.png",
  81. groups = {armor_feet=1},
  82. })
  83. end
  84. if ARMOR_MATERIALS.carbon then
  85. register_piece("3d_armor:helmet_carbon", {
  86. description = "Carbon Steel Helmet",
  87. inventory_image = "3d_armor_inv_helmet_carbon.png",
  88. groups = {armor_head=1},
  89. })
  90. register_piece("3d_armor:chestplate_carbon", {
  91. description = "Carbon Steel Chestplate",
  92. inventory_image = "3d_armor_inv_chestplate_carbon.png",
  93. groups = {armor_torso=1},
  94. })
  95. register_piece("3d_armor:leggings_carbon", {
  96. description = "Carbon Steel Leggings",
  97. inventory_image = "3d_armor_inv_leggings_carbon.png",
  98. groups = {armor_legs=1},
  99. })
  100. register_piece("3d_armor:boots_carbon", {
  101. description = "Carbon Steel Boots",
  102. inventory_image = "3d_armor_inv_boots_carbon.png",
  103. groups = {armor_feet=1},
  104. })
  105. end
  106. if ARMOR_MATERIALS.bronze then
  107. register_piece("3d_armor:helmet_bronze", {
  108. description = "Bronze Helmet",
  109. inventory_image = "3d_armor_inv_helmet_bronze.png",
  110. groups = {armor_head=1},
  111. })
  112. register_piece("3d_armor:chestplate_bronze", {
  113. description = "Bronze Chestplate",
  114. inventory_image = "3d_armor_inv_chestplate_bronze.png",
  115. groups = {armor_torso=1},
  116. })
  117. register_piece("3d_armor:leggings_bronze", {
  118. description = "Bronze Leggings",
  119. inventory_image = "3d_armor_inv_leggings_bronze.png",
  120. groups = {armor_legs=1},
  121. })
  122. register_piece("3d_armor:boots_bronze", {
  123. description = "Bronze Boots",
  124. inventory_image = "3d_armor_inv_boots_bronze.png",
  125. groups = {armor_feet=1},
  126. })
  127. end
  128. if ARMOR_MATERIALS.diamond then
  129. register_piece("3d_armor:helmet_diamond", {
  130. description = "Diamond Helmet",
  131. inventory_image = "3d_armor_inv_helmet_diamond.png",
  132. groups = {armor_head=1},
  133. })
  134. register_piece("3d_armor:chestplate_diamond", {
  135. description = "Diamond Chestplate",
  136. inventory_image = "3d_armor_inv_chestplate_diamond.png",
  137. groups = {armor_torso=1},
  138. })
  139. register_piece("3d_armor:leggings_diamond", {
  140. description = "Diamond Leggings",
  141. inventory_image = "3d_armor_inv_leggings_diamond.png",
  142. groups = {armor_legs=1},
  143. })
  144. register_piece("3d_armor:boots_diamond", {
  145. description = "Diamond Boots",
  146. inventory_image = "3d_armor_inv_boots_diamond.png",
  147. groups = {armor_feet=1},
  148. })
  149. end
  150. if ARMOR_MATERIALS.gold then
  151. register_piece("3d_armor:helmet_gold", {
  152. description = "Golden Helmet",
  153. inventory_image = "3d_armor_inv_helmet_gold.png",
  154. groups = {armor_head=1},
  155. })
  156. register_piece("3d_armor:chestplate_gold", {
  157. description = "Golden Chestplate",
  158. inventory_image = "3d_armor_inv_chestplate_gold.png",
  159. groups = {armor_torso=1},
  160. })
  161. register_piece("3d_armor:leggings_gold", {
  162. description = "Golden Leggings",
  163. inventory_image = "3d_armor_inv_leggings_gold.png",
  164. groups = {armor_legs=1},
  165. })
  166. register_piece("3d_armor:boots_gold", {
  167. description = "Golden Boots",
  168. inventory_image = "3d_armor_inv_boots_gold.png",
  169. groups = {armor_feet=1},
  170. })
  171. end
  172. if ARMOR_MATERIALS.mithril then
  173. register_piece("3d_armor:helmet_mithril", {
  174. description = "Mithril Helmet",
  175. inventory_image = "3d_armor_inv_helmet_mithril.png",
  176. groups = {armor_head=1},
  177. })
  178. register_piece("3d_armor:chestplate_mithril", {
  179. description = "Mithril Chestplate",
  180. inventory_image = "3d_armor_inv_chestplate_mithril.png",
  181. groups = {armor_torso=1},
  182. })
  183. register_piece("3d_armor:leggings_mithril", {
  184. description = "Mithril Leggings",
  185. inventory_image = "3d_armor_inv_leggings_mithril.png",
  186. groups = {armor_legs=1},
  187. })
  188. register_piece("3d_armor:boots_mithril", {
  189. description = "Mithril Boots",
  190. inventory_image = "3d_armor_inv_boots_mithril.png",
  191. groups = {armor_feet=1},
  192. })
  193. end
  194. -- Register Player Model
  195. default.player_register_model("3d_armor_character.b3d", {
  196. animation_speed = 30,
  197. textures = {
  198. armor.default_skin..".png",
  199. "3d_armor_trans.png",
  200. "3d_armor_trans.png",
  201. },
  202. animations = {
  203. stand = {x=0, y=79},
  204. lay = {x=162, y=166},
  205. walk = {x=168, y=187},
  206. mine = {x=189, y=198},
  207. walk_mine = {x=200, y=219},
  208. sit = {x=81, y=160},
  209. },
  210. })
  211. -- Register Callbacks
  212. minetest.register_on_player_receive_fields(function(...)
  213. return armor.on_player_receive_fields(...) end)
  214. minetest.register_on_joinplayer(function(...)
  215. return armor.on_joinplayer(...) end)
  216. -- Warning: this must be the ONLY hp-change-modifier in the entire Lua code!
  217. minetest.register_on_player_hpchange(function(...)
  218. return armor.on_player_hp_change(...) end, true)
  219. inventory_plus.register_button("armor", "Armor")
  220. local c = "armor:core"
  221. local f = armor.modpath .. "/init.lua"
  222. reload.register_file(c, f, false)
  223. end