2017-03-30 05:28:47 +02:00
|
|
|
local time = 0
|
2017-08-09 16:17:00 +02:00
|
|
|
local update_time = tonumber(minetest.settings:get("wieldview_update_time"))
|
2017-03-30 05:28:47 +02:00
|
|
|
if not update_time then
|
|
|
|
update_time = 2
|
2017-08-09 16:17:00 +02:00
|
|
|
minetest.settings:set("wieldview_update_time", tostring(update_time))
|
2017-03-30 05:28:47 +02:00
|
|
|
end
|
2017-08-09 16:17:00 +02:00
|
|
|
local node_tiles = minetest.settings:get_bool("wieldview_node_tiles")
|
2017-03-30 05:28:47 +02:00
|
|
|
if not node_tiles then
|
|
|
|
node_tiles = false
|
2017-08-09 16:17:00 +02:00
|
|
|
minetest.settings:set("wieldview_node_tiles", "false")
|
2017-03-30 05:28:47 +02: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 17:46:25 +01:00
|
|
|
local texture = "blank.png"
|
2017-03-30 05:28:47 +02: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 14:51:08 +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)
|
2017-03-30 05:28:47 +02: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 19:17:01 +02:00
|
|
|
if not armor.textures[name] then
|
|
|
|
return
|
|
|
|
end
|
2017-03-30 05:28:47 +02: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 12:58:30 +01:00
|
|
|
local itementity = minetest.add_entity(player:get_pos(), "wieldview:wieldnode")
|
2021-03-19 12:41:03 +01:00
|
|
|
itementity:set_attach(player, "Hand_Right", vector.new(0, 1, 0), vector.new(90, 0, 45))
|
2021-02-24 12:58:30 +01:00
|
|
|
itementity:get_luaentity().wielder = name
|
2017-03-30 05:28:47 +02:00
|
|
|
end, player)
|
|
|
|
end)
|
|
|
|
|
2021-02-16 13:34:26 +01:00
|
|
|
minetest.register_globalstep(function()
|
2021-03-16 17:39:06 +01:00
|
|
|
for _,player in pairs(minetest.get_connected_players()) do
|
2021-02-16 13:34:26 +01:00
|
|
|
wieldview:update_wielded_item(player)
|
2017-03-30 05:28:47 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-02-24 12:58:30 +01: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()
|
2021-02-25 17:35:44 +01:00
|
|
|
local itemstring = wielded:get_name()
|
2021-03-19 16:28:33 +01:00
|
|
|
|
2021-02-24 12:58:30 +01:00
|
|
|
if self.itemstring ~= itemstring then
|
2021-02-25 17:35:44 +01:00
|
|
|
local def = minetest.registered_items[itemstring]
|
2021-02-24 12:58:30 +01:00
|
|
|
self.object:set_properties({glow = def and def.light_source or 0})
|
2021-03-19 16:28:33 +01:00
|
|
|
|
|
|
|
-- wield item as cubic
|
2021-02-24 12:58:30 +01:00
|
|
|
if armor.textures[self.wielder].wielditem == "blank.png" then
|
2021-02-25 17:35:44 +01:00
|
|
|
self.object:set_properties({textures = {itemstring}})
|
2021-03-20 01:42:48 +01:00
|
|
|
else -- wield item as flat
|
2021-02-25 17:35:44 +01:00
|
|
|
self.object:set_properties({textures = {""}})
|
2021-02-24 12:58:30 +01:00
|
|
|
end
|
2021-03-19 16:28:33 +01:00
|
|
|
|
2021-02-24 12:58:30 +01:00
|
|
|
self.itemstring = itemstring
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|