2013-03-26 21:54:01 +01:00
|
|
|
local time = 0
|
|
|
|
local update_time = tonumber(minetest.setting_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
|
|
|
|
minetest.setting_set("wieldview_update_time", tostring(update_time))
|
|
|
|
end
|
2013-08-04 23:17:08 +02:00
|
|
|
local node_tiles = minetest.setting_getbool("wieldview_node_tiles")
|
|
|
|
if not node_tiles then
|
|
|
|
node_tiles = false
|
|
|
|
minetest.setting_set("wieldview_node_tiles", "false")
|
|
|
|
end
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
2013-11-12 22:22:52 +01:00
|
|
|
local texture = "3d_armor_trans.png"
|
2013-06-22 20:31:57 +02:00
|
|
|
if item ~= "" then
|
|
|
|
if minetest.registered_items[item] then
|
2015-02-19 23:01:09 +01:00
|
|
|
if minetest.registered_items[item].inventory_image ~= "" then
|
|
|
|
texture = minetest.registered_items[item].inventory_image
|
|
|
|
elseif node_tiles == true and minetest.registered_items[item].tiles
|
|
|
|
and type(minetest.registered_items[item].tiles[1]) == "string"
|
|
|
|
and minetest.registered_items[item].tiles[1] ~= "" then
|
|
|
|
texture = minetest.inventorycube(minetest.registered_items[item].tiles[1])
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
if wieldview.transform[item] then
|
|
|
|
texture = texture.."^[transform"..wieldview.transform[item]
|
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
|
|
|
|
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
|
2013-11-12 22:22:52 +01: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] = ""
|
2013-04-11 21:56:35 +02:00
|
|
|
minetest.after(0, function(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
wieldview:update_wielded_item(player)
|
2013-03-26 21:54:01 +01:00
|
|
|
end, player)
|
|
|
|
end)
|
|
|
|
|
2019-05-12 19:20:27 +02:00
|
|
|
function step()
|
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
|
|
|
wieldview:update_wielded_item(player)
|
2013-03-26 21:54:01 +01:00
|
|
|
end
|
2019-05-12 19:20:27 +02:00
|
|
|
time = 0
|
|
|
|
minetest.after(update_time, step)
|
|
|
|
end
|
|
|
|
minetest.after(0, step)
|
2013-03-26 21:54:01 +01:00
|
|
|
|