init.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -- support for i18n
  2. local S = armor_i18n.gettext
  3. local F = minetest.formspec_escape
  4. local has_technic = minetest.get_modpath("technic") ~= nil
  5. if not minetest.global_exists("unified_inventory") then
  6. minetest.log("warning", S("3d_armor_ui: Mod loaded but unused."))
  7. return
  8. end
  9. if unified_inventory.sfinv_compat_layer then
  10. return
  11. end
  12. armor:register_on_update(function(player)
  13. local name = player:get_player_name()
  14. if unified_inventory.current_page[name] == "armor" then
  15. unified_inventory.set_inventory_formspec(player, "armor")
  16. end
  17. end)
  18. unified_inventory.register_button("armor", {
  19. type = "image",
  20. image = "inventory_plus_armor.png",
  21. tooltip = S("3d Armor")
  22. })
  23. unified_inventory.register_page("armor", {
  24. get_formspec = function(player, perplayer_formspec)
  25. local fy = perplayer_formspec.formspec_y
  26. local name = player:get_player_name()
  27. if armor.def[name].init_time == 0 then
  28. return {formspec="label[0,0;"..F(S("Armor not initialized!")).."]"}
  29. end
  30. local formspec = "background[0.06,"..(fy-1)..";7.92,8.52;3d_armor_ui_form.png]"..
  31. "label[2.15,0;"..F(S("Armor")).."]"..
  32. "list[detached:"..name.."_armor;armor;0,"..(fy-.75)..";1,4;]"..
  33. "list[detached:"..name.."_armor;armor;4,"..(fy-.75)..";1,4;4]"..
  34. "image[1.6,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]"..
  35. "label[5.25,"..(fy + 0.00)..";"..F(S("Heal"))..": "..(math.floor(armor.def[name].heal))..' (Actual: '..(armor.def[name].heal)..')]'..
  36. "label[5.25,"..(fy + 0.25)..";"..F(S("Block"))..": "..armor.def[name].block.."]"..
  37. "label[5.25,"..(fy + 0.50)..";"..F(S("DMG Resistance"))..": "..(math.floor(armor.def[name].dmg_resist))..' (Actual: '..(armor.def[name].dmg_resist)..')]'..
  38. "label[5.25,"..(fy + 0.75)..";"..F(S("Fire"))..": "..(math.floor(armor.def[name].fire))..' (Actual: '..(armor.def[name].fire)..')]'..
  39. "label[5.25,"..(fy + 1.00)..";"..F(S("Oxygen Regen"))..": "..(math.floor(armor.def[name].water))..' (Actual: '..(armor.def[name].water)..')]'..
  40. "label[5.25,"..(fy + 1.25)..";"..F(S("Speed Multiplier"))..": "..armor.def[name].speed.."]"..
  41. "label[5.25,"..(fy + 1.50)..";"..F(S("Jump Multiplier"))..": "..armor.def[name].jump.."]"..
  42. "label[5.25,"..(fy + 1.75)..";"..F(S("Gravity Multiplier"))..": "..armor.def[name].gravity.."]"..
  43. "listring[current_player;main]"..
  44. "listring[detached:"..name.."_armor;armor]"
  45. return {formspec=formspec}
  46. end,
  47. })