wieldview.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. local time = 0
  2. local update_time = 2
  3. local node_tiles = true
  4. lottarmor = {
  5. wielded_item = {},
  6. transform = {},
  7. }
  8. dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua")
  9. lottarmor.get_item_texture = function(self, item)
  10. local texture = "lottarmor_trans.png"
  11. if item ~= "" then
  12. if minetest.registered_items[item] then
  13. if minetest.registered_items[item].inventory_image ~= "" then
  14. texture = minetest.registered_items[item].inventory_image
  15. elseif node_tiles == true and minetest.registered_items[item].tiles
  16. and type(minetest.registered_items[item].tiles[1]) == "string"
  17. and minetest.registered_items[item].tiles[1] ~= "" then
  18. texture = minetest.inventorycube(minetest.registered_items[item].tiles[1])
  19. end
  20. end
  21. if lottarmor.transform[item] then
  22. texture = texture.."^[transform"..lottarmor.transform[item]
  23. end
  24. end
  25. return texture
  26. end
  27. lottarmor.update_wielded_item = function(self, player)
  28. if not player then
  29. return
  30. end
  31. local name = player:get_player_name()
  32. local stack = player:get_wielded_item()
  33. local item = stack:get_name()
  34. if not item then
  35. return
  36. end
  37. if self.wielded_item[name] then
  38. if self.wielded_item[name] == item then
  39. return
  40. end
  41. multiskin[name].wielditem = self:get_item_texture(item)
  42. multiskin:update_player_visuals(player)
  43. end
  44. self.wielded_item[name] = item
  45. end
  46. minetest.register_on_joinplayer(function(player)
  47. local name = player:get_player_name()
  48. lottarmor.wielded_item[name] = ""
  49. minetest.after(0, function(player)
  50. lottarmor:update_wielded_item(player)
  51. end, player)
  52. end)
  53. minetest.register_globalstep(function(dtime)
  54. time = time + dtime
  55. if time > update_time then
  56. for _,player in ipairs(minetest.get_connected_players()) do
  57. lottarmor:update_wielded_item(player)
  58. end
  59. time = 0
  60. end
  61. end)