init.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. -- Unified Skins for Minetest - based modified Bags from unfied_inventory and skins from inventory_plus
  2. -- Copyright (c) 2012 cornernote, Dean Montgomery
  3. -- Rework 2017 by bell07
  4. -- License: GPLv3
  5. skins = {}
  6. skins.modpath = minetest.get_modpath(minetest.get_current_modname())
  7. skins.default = "character"
  8. dofile(skins.modpath.."/skin_meta_api.lua")
  9. dofile(skins.modpath.."/api.lua")
  10. dofile(skins.modpath.."/skinlist.lua")
  11. dofile(skins.modpath.."/formspecs.lua")
  12. dofile(skins.modpath.."/chatcommands.lua")
  13. -- Unified inventory page/integration
  14. if minetest.get_modpath("unified_inventory") then
  15. dofile(skins.modpath.."/unified_inventory_page.lua")
  16. end
  17. if minetest.get_modpath("sfinv") then
  18. dofile(skins.modpath.."/sfinv_page.lua")
  19. end
  20. -- ie.loadfile does not exist?
  21. skins.ie = minetest.request_insecure_environment()
  22. skins.http = minetest.request_http_api()
  23. dofile(skins.modpath.."/skins_updater.lua")
  24. skins.ie = nil
  25. skins.http = nil
  26. -- 3d_armor compatibility
  27. if minetest.global_exists("armor") then
  28. skins.armor_loaded = true
  29. armor.get_player_skin = function(self, name)
  30. local skin = skins.get_player_skin(minetest.get_player_by_name(name))
  31. return skin:get_texture()
  32. end
  33. armor.get_preview = function(self, name)
  34. local skin = skins.get_player_skin(minetest.get_player_by_name(name))
  35. return skin:get_preview()
  36. end
  37. armor.update_player_visuals = function(self, player)
  38. if not player then
  39. return
  40. end
  41. local skin = skins.get_player_skin(player)
  42. skin:apply_skin_to_player(player)
  43. armor:run_callbacks("on_update", player)
  44. end
  45. end
  46. if minetest.global_exists("clothing") and clothing.player_textures then
  47. skins.clothing_loaded = true
  48. clothing:register_on_update(skins.update_player_skin)
  49. end
  50. -- Update skin on join
  51. skins.ui_context = {}
  52. minetest.register_on_joinplayer(function(player)
  53. skins.update_player_skin(player)
  54. end)
  55. minetest.register_on_leaveplayer(function(player)
  56. skins.ui_context[player:get_player_name()] = nil
  57. end)
  58. player_api.register_model("skinsdb_3d_armor_character_5.b3d", {
  59. animation_speed = 30,
  60. textures = {
  61. "blank.png",
  62. "blank.png",
  63. "blank.png",
  64. "blank.png"
  65. },
  66. animations = {
  67. stand = {x=0, y=79},
  68. lay = {x=162, y=166},
  69. walk = {x=168, y=187},
  70. mine = {x=189, y=198},
  71. walk_mine = {x=200, y=219},
  72. sit = {x=81, y=160},
  73. },
  74. })
  75. -- Register default character.png if not part of this mod
  76. local default_skin_obj = skins.get(skins.default)
  77. if not default_skin_obj then
  78. default_skin_obj = skins.new(skins.default)
  79. default_skin_obj:set_texture("character.png")
  80. default_skin_obj:set_meta("format", '1.0')
  81. default_skin_obj:set_meta("_sort_id", 0)
  82. default_skin_obj:set_meta("name", "Sam")
  83. end