2021-04-14 16:46:52 +03:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
2022-06-18 00:15:46 +03:00
|
|
|
if not player or not player:is_player() then
|
|
|
|
return
|
2021-04-14 16:46:52 +03:00
|
|
|
end
|
2022-06-18 00:15:46 +03:00
|
|
|
local itementity = minetest.add_entity(player:get_pos(), "mcl_wieldview:wieldnode")
|
|
|
|
if not itementity then return end
|
2022-08-18 21:36:02 +03:00
|
|
|
itementity:set_attach(player, "Wield_Item")
|
2022-06-18 00:15:46 +03:00
|
|
|
--itementity:set_attach(player, "Hand_Right", vector.new(0, 1, 0), vector.new(90, 45, 90))
|
|
|
|
itementity:get_luaentity()._wielder = player
|
2021-04-14 16:46:52 +03:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_entity("mcl_wieldview:wieldnode", {
|
2022-06-28 00:29:06 +03:00
|
|
|
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},
|
|
|
|
},
|
|
|
|
|
2021-04-14 16:46:52 +03:00
|
|
|
on_step = function(self)
|
2022-06-28 00:29:06 +03:00
|
|
|
local player = self._wielder
|
|
|
|
|
|
|
|
if not player or not player:is_player() then
|
2021-04-14 16:46:52 +03:00
|
|
|
self.object:remove()
|
2022-06-28 00:29:06 +03:00
|
|
|
return
|
2021-04-14 16:46:52 +03:00
|
|
|
end
|
2022-06-18 00:15:46 +03:00
|
|
|
|
|
|
|
local item = player:get_wielded_item():get_name()
|
|
|
|
|
|
|
|
if item == self._item then return end
|
|
|
|
|
|
|
|
self._item = item
|
|
|
|
|
2022-06-28 00:29:06 +03:00
|
|
|
local def = player:get_wielded_item():get_definition()
|
|
|
|
if def and def._mcl_wieldview_item then
|
|
|
|
item = def._mcl_wieldview_item
|
2022-06-18 00:15:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local item_def = minetest.registered_items[item]
|
|
|
|
self.object:set_properties({
|
|
|
|
glow = item_def and item_def.light_source or 0,
|
|
|
|
wield_item = item,
|
|
|
|
is_visible = item ~= ""
|
|
|
|
})
|
2021-04-14 16:46:52 +03:00
|
|
|
end,
|
|
|
|
})
|