2013-03-26 21:54:01 +01:00
|
|
|
local time = 0
|
2017-05-13 09:08:18 +02:00
|
|
|
local update_time = tonumber(minetest.settings:get("wieldview_update_time"))
|
2013-04-11 21:56:35 +02:00
|
|
|
if not update_time then
|
2013-03-26 21:54:01 +01:00
|
|
|
update_time = 2
|
2017-05-13 09:08:18 +02:00
|
|
|
minetest.settings:set("wieldview_update_time", tostring(update_time))
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
2013-08-04 23:17:08 +02:00
|
|
|
|
2013-03-26 21:54:01 +01:00
|
|
|
wieldview = {
|
2013-06-22 20:31:57 +02:00
|
|
|
wielded_item = {},
|
2013-11-12 22:22:52 +01:00
|
|
|
transform = {},
|
2013-03-26 21:54:01 +01:00
|
|
|
}
|
|
|
|
|
2022-11-13 20:55:31 +01:00
|
|
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/get_texture.lua")
|
2013-11-12 22:22:52 +01:00
|
|
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua")
|
|
|
|
|
2013-06-22 20:31:57 +02:00
|
|
|
wieldview.get_item_texture = function(self, item)
|
2024-04-04 07:25:05 +02:00
|
|
|
local texture = "blank.png"
|
2013-06-22 20:31:57 +02:00
|
|
|
if item ~= "" then
|
2022-11-13 20:55:31 +01:00
|
|
|
texture = armor.get_wield_image(item)
|
|
|
|
|
2017-03-30 06:02:54 +02:00
|
|
|
-- Get item image transformation, first from group, then from transform.lua
|
|
|
|
local transform = minetest.get_item_group(item, "wieldview_transform")
|
|
|
|
if transform == 0 then
|
|
|
|
transform = wieldview.transform[item]
|
|
|
|
end
|
|
|
|
if transform then
|
|
|
|
-- This actually works with groups ratings because transform1, transform2, etc.
|
|
|
|
-- have meaning and transform0 is used for identidy, so it can be ignored
|
|
|
|
texture = texture.."^[transform"..tostring(transform)
|
2013-08-04 23:17:08 +02:00
|
|
|
end
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
2013-08-04 23:17:08 +02:00
|
|
|
return texture
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
wieldview.update_wielded_item = function(self, player)
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local stack = player:get_wielded_item()
|
|
|
|
local item = stack:get_name()
|
|
|
|
if not item then
|
|
|
|
return
|
|
|
|
end
|
2013-06-22 20:31:57 +02:00
|
|
|
if self.wielded_item[name] then
|
2020-09-15 06:43:55 +02:00
|
|
|
if player:get_meta():get_int("show_wielded_item") == 2 then
|
|
|
|
item = ""
|
|
|
|
end
|
2013-06-22 20:31:57 +02:00
|
|
|
if self.wielded_item[name] == item then
|
2013-03-26 21:54:01 +01:00
|
|
|
return
|
2013-04-11 21:56:35 +02:00
|
|
|
end
|
2017-04-13 20:47:43 +02:00
|
|
|
armor.textures[name].wielditem = self:get_item_texture(item)
|
|
|
|
armor:update_player_visuals(player)
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
2013-06-22 20:31:57 +02:00
|
|
|
self.wielded_item[name] = item
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
local name = player:get_player_name()
|
|
|
|
wieldview.wielded_item[name] = ""
|
2021-06-26 20:21:15 +02:00
|
|
|
minetest.after(0, function(pname)
|
|
|
|
local pplayer = minetest.get_player_by_name(pname)
|
|
|
|
if pplayer then
|
2020-02-13 12:26:32 +01:00
|
|
|
wieldview:update_wielded_item(pplayer)
|
|
|
|
end
|
2021-06-26 20:21:15 +02:00
|
|
|
end, name)
|
2013-03-26 21:54:01 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
time = time + dtime
|
|
|
|
if time > update_time then
|
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
|
|
|
wieldview:update_wielded_item(player)
|
|
|
|
end
|
|
|
|
time = 0
|
|
|
|
end
|
|
|
|
end)
|