init.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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..";7.92,7.52;3d_armor_ui_form.png]"..
  31. "label[0,0;"..F(S("Armor")).."]"..
  32. "list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]"..
  33. "image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]"..
  34. "label[5.0,"..(fy + 0.0)..";"..F(S("Level"))..": "..armor.def[name].level.."]"..
  35. "label[5.0,"..(fy + 0.5)..";"..F(S("Heal"))..": "..armor.def[name].heal.."]"..
  36. "listring[current_player;main]"..
  37. "listring[detached:"..name.."_armor;armor]"
  38. if armor.config.fire_protect then
  39. formspec = formspec.."label[5.0,"..(fy + 1.0)..";"..
  40. F(S("Fire"))..": "..armor.def[name].fire.."]"
  41. end
  42. if has_technic then
  43. formspec = formspec.."label[5.0,"..(fy + 1.5)..";"..
  44. F(S("Radiation"))..": "..armor.def[name].groups["radiation"].."]"
  45. end
  46. return {formspec=formspec}
  47. end,
  48. })