init.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. dofile(armor.modpath .. "/duel.lua")
  23. if not armor.run_once then
  24. armor.run_once = true
  25. local function register_piece(name, data)
  26. data._armor_resist_groups = sysdmg.get_armor_resist_for(name)
  27. data._armor_wear_groups = sysdmg.get_armor_wear_for(name)
  28. data.groups = sysdmg.get_armor_groups_for(name, data.groups)
  29. minetest.register_tool(name, data)
  30. end
  31. -- Materials can only be loaded once, obviously.
  32. ARMOR_MATERIALS = {
  33. wood = {item="group:wood" , name="Wood" , padding="farming:cotton" , fuel=10, cook=0 , shield=true , chestplate_name="" , boots_name="" , helmet_name="" , leggings_name="Chausses" , not_repaired_by_anvil = true },
  34. steel = {item="default:steel_ingot" , name="Wrought Iron", padding="group:leather_padding", fuel=0 , cook=15, shield=true , chestplate_name="" , boots_name="" , helmet_name="" , leggings_name="" , not_repaired_by_anvil = false},
  35. bronze = {item="default:bronze_ingot" , name="Bronze" , padding="group:leather_padding", fuel=0 , cook=15, shield=true , chestplate_name="" , boots_name="" , helmet_name="" , leggings_name="" , not_repaired_by_anvil = false},
  36. -- Note to self so I don't forget: diamond armor doesn't use leather in its craft ON PURPOSE!
  37. -- This is also true for wood armor. Leather is hard to get!
  38. diamond = {item="default:diamond" , name="Diamond" , padding="farming:cloth" , fuel=0 , cook=0 , shield=true , chestplate_name="Shardplate" , boots_name="Shoes" , helmet_name="Crown" , leggings_name="" , not_repaired_by_anvil = false},
  39. gold = {item="default:gold_ingot" , name="Golden" , padding="group:leather_padding", fuel=0 , cook=15, shield=true , chestplate_name="" , boots_name="" , helmet_name="" , leggings_name="" , not_repaired_by_anvil = false},
  40. mithril = {item="moreores:mithril_ingot", name="Mithril" , padding="group:leather_padding", fuel=0 , cook=15, shield=true , chestplate_name="" , boots_name="" , helmet_name="" , leggings_name="" , not_repaired_by_anvil = false},
  41. carbon = {item="carbon_steel:ingot" , name="Carbon Steel", padding="group:leather_padding", fuel=0 , cook=15, shield=true , chestplate_name="" , boots_name="" , helmet_name="" , leggings_name="" , not_repaired_by_anvil = false},
  42. -- Note, cotton/leather armor textures are from UncleBob, CC0.
  43. cotton = {item="farming:cloth" , name="Cloth" , padding="farming:cotton" , fuel=4 , cook=0 , shield=false , chestplate_name="Jerkin" , boots_name="Shoes" , helmet_name="Cap" , leggings_name="Chausses" , not_repaired_by_anvil = true },
  44. leather = {item="mobs:leather" , name="Leather" , padding="farming:cloth" , fuel=6 , cook=0 , shield=false , chestplate_name="Jerkin" , boots_name="Shoes" , helmet_name="Cap" , leggings_name="Chausses" , not_repaired_by_anvil = true },
  45. }
  46. for key, data in pairs(ARMOR_MATERIALS) do
  47. local capname = "Helmet"
  48. if data.helmet_name ~= "" then
  49. capname = data.helmet_name
  50. end
  51. local nrba = nil
  52. if data.not_repaired_by_anvil then
  53. nrba = 1
  54. end
  55. register_piece("3d_armor:helmet_" .. key, {
  56. description = data.name .. " " .. capname,
  57. inventory_image = "3d_armor_inv_helmet_" .. key .. ".png",
  58. groups = {armor_head=1, not_repaired_by_anvil=nrba},
  59. })
  60. local chestname = "Chestplate"
  61. if data.chestplate_name ~= "" then
  62. chestname = data.chestplate_name
  63. end
  64. register_piece("3d_armor:chestplate_" .. key, {
  65. description = data.name .. " " .. chestname,
  66. inventory_image = "3d_armor_inv_chestplate_" .. key .. ".png",
  67. groups = {armor_torso=1, not_repaired_by_anvil=nrba},
  68. })
  69. local legname = "Leggings"
  70. if data.leggings_name ~= "" then
  71. legname = data.leggings_name
  72. end
  73. register_piece("3d_armor:leggings_" .. key, {
  74. description = data.name .. " " .. legname,
  75. inventory_image = "3d_armor_inv_leggings_" .. key .. ".png",
  76. groups = {armor_legs=1, not_repaired_by_anvil=nrba},
  77. })
  78. local shoename = "Boots"
  79. if data.boots_name ~= "" then
  80. shoename = data.boots_name
  81. end
  82. register_piece("3d_armor:boots_" .. key, {
  83. description = data.name .. " " .. shoename,
  84. inventory_image = "3d_armor_inv_boots_" .. key .. ".png",
  85. groups = {armor_feet=1, not_repaired_by_anvil=nrba},
  86. })
  87. end
  88. -- Register Player Model
  89. default.player_register_model("3d_armor_character.b3d", {
  90. animation_speed = 30,
  91. textures = {
  92. armor.default_skin..".png",
  93. "3d_armor_trans.png",
  94. "3d_armor_trans.png",
  95. },
  96. animations = {
  97. stand = {x=0, y=79},
  98. lay = {x=162, y=166},
  99. walk = {x=168, y=187},
  100. mine = {x=189, y=198},
  101. walk_mine = {x=200, y=219},
  102. sit = {x=81, y=160},
  103. },
  104. })
  105. -- Register Callbacks
  106. minetest.register_on_player_receive_fields(function(...)
  107. return armor.on_player_receive_fields(...) end)
  108. minetest.register_on_joinplayer(function(...)
  109. return armor.on_joinplayer(...) end)
  110. -- Warning: this must be the ONLY hp-change-modifier in the entire Lua code!
  111. minetest.register_on_player_hpchange(function(...)
  112. return armor.on_player_hp_change(...) end, true)
  113. inventory_plus.register_button("armor", "Armor")
  114. local c = "armor:core"
  115. local f = armor.modpath .. "/init.lua"
  116. reload.register_file(c, f, false)
  117. end