2017-03-30 06:28:47 +03:00
|
|
|
local time = 0
|
2017-08-09 17:17:00 +03:00
|
|
|
local update_time = tonumber(minetest.settings:get("wieldview_update_time"))
|
2017-03-30 06:28:47 +03:00
|
|
|
if not update_time then
|
|
|
|
update_time = 2
|
2017-08-09 17:17:00 +03:00
|
|
|
minetest.settings:set("wieldview_update_time", tostring(update_time))
|
2017-03-30 06:28:47 +03:00
|
|
|
end
|
2017-08-09 17:17:00 +03:00
|
|
|
local node_tiles = minetest.settings:get_bool("wieldview_node_tiles")
|
2017-03-30 06:28:47 +03:00
|
|
|
if not node_tiles then
|
|
|
|
node_tiles = false
|
2017-08-09 17:17:00 +03:00
|
|
|
minetest.settings:set("wieldview_node_tiles", "false")
|
2017-03-30 06:28:47 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
wieldview = {
|
|
|
|
wielded_item = {},
|
|
|
|
transform = {},
|
|
|
|
}
|
|
|
|
|
|
|
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua")
|
|
|
|
|
|
|
|
wieldview.get_item_texture = function(self, item)
|
2020-02-17 19:46:25 +03:00
|
|
|
local texture = "blank.png"
|
2017-03-30 06:28:47 +03:00
|
|
|
if item ~= "" then
|
|
|
|
if minetest.registered_items[item] then
|
|
|
|
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])
|
|
|
|
end
|
|
|
|
end
|
2020-03-29 15:51:08 +03: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)
|
2017-03-30 06:28:47 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return texture
|
|
|
|
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
|
|
|
|
if self.wielded_item[name] then
|
|
|
|
if self.wielded_item[name] == item then
|
|
|
|
return
|
|
|
|
end
|
2020-06-19 20:17:01 +03:00
|
|
|
if not armor.textures[name] then
|
|
|
|
return
|
|
|
|
end
|
2017-03-30 06:28:47 +03:00
|
|
|
armor.textures[name].wielditem = self:get_item_texture(item)
|
|
|
|
armor:update_player_visuals(player)
|
|
|
|
end
|
|
|
|
self.wielded_item[name] = item
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
wieldview.wielded_item[name] = ""
|
|
|
|
minetest.after(0, function(player)
|
|
|
|
wieldview:update_wielded_item(player)
|
2021-02-24 14:58:30 +03:00
|
|
|
local itementity = minetest.add_entity(player:get_pos(), "wieldview:wieldnode")
|
|
|
|
itementity:set_attach(player, "Right_Hand", vector.new(0, 0, 0), vector.new(15, 45, 0))
|
|
|
|
itementity:get_luaentity().wielder = name
|
2017-03-30 06:28:47 +03:00
|
|
|
end, player)
|
|
|
|
end)
|
|
|
|
|
2021-02-16 15:34:26 +03:00
|
|
|
minetest.register_globalstep(function()
|
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
|
|
|
wieldview:update_wielded_item(player)
|
2017-03-30 06:28:47 +03:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-02-24 14:58:30 +03:00
|
|
|
minetest.register_entity("wieldview:wieldnode", {
|
|
|
|
initial_properties = {
|
|
|
|
hp_max = 1,
|
|
|
|
visual = "wielditem",
|
|
|
|
physical = false,
|
|
|
|
textures = {""},
|
|
|
|
automatic_rotate = 1.5,
|
|
|
|
is_visible = true,
|
|
|
|
pointable = false,
|
|
|
|
collide_with_objects = false,
|
|
|
|
static_save = false,
|
|
|
|
collisionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21},
|
|
|
|
selectionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21},
|
|
|
|
visual_size = {x = 0.21, y = 0.21},
|
|
|
|
},
|
|
|
|
|
|
|
|
itemstring = "",
|
|
|
|
|
|
|
|
on_step = function(self)
|
|
|
|
local player = minetest.get_player_by_name(self.wielder)
|
|
|
|
if player then
|
|
|
|
local wielded = player:get_wielded_item()
|
|
|
|
local itemstring = wielded:to_string()
|
|
|
|
if self.itemstring ~= itemstring then
|
|
|
|
local itemname = wielded:get_name()
|
|
|
|
local def = minetest.registered_items[itemname]
|
|
|
|
self.object:set_properties({glow = def and def.light_source or 0})
|
|
|
|
if armor.textures[self.wielder].wielditem == "blank.png" then
|
|
|
|
self.object:set_properties({textures = {itemname}, wield_item = itemstring})
|
|
|
|
else
|
|
|
|
self.object:set_properties({textures = {""}, wield_item = ""})
|
|
|
|
end
|
|
|
|
self.itemstring = itemstring
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|