2015-10-20 19:59:21 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Wielditem mod
|
|
|
|
-- By Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
2015-10-20 19:59:21 +02:00
|
|
|
wielditem = {}
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local update_time = 1
|
2015-10-20 19:59:21 +02:00
|
|
|
local timer = 10 -- needs to be more than update_time
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-10-20 19:59:21 +02:00
|
|
|
"wielditem:null",
|
|
|
|
{
|
2019-08-29 05:46:44 +02:00
|
|
|
wield_image = "blank.png"
|
2015-10-20 19:59:21 +02:00
|
|
|
})
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_entity(
|
2015-10-20 19:59:21 +02:00
|
|
|
"wielditem:wielditem",
|
|
|
|
{
|
|
|
|
textures = {"default:broadsword"},
|
|
|
|
|
|
|
|
visual = "wielditem",
|
|
|
|
visual_size = {x = 0.17, y = 0.17},
|
|
|
|
|
|
|
|
hp_max = 1,
|
|
|
|
|
|
|
|
physical = false,
|
2019-08-31 15:23:39 +02:00
|
|
|
pointable = false,
|
2015-10-20 19:59:21 +02:00
|
|
|
collide_with_objects = false,
|
|
|
|
makes_footstep_sounds = false,
|
|
|
|
|
|
|
|
on_step = function(self, dtime)
|
|
|
|
local player = self.wielder
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
if player == nil or (minetest.get_player_by_name(player:get_player_name()) == nil) then
|
2015-10-20 19:59:21 +02:00
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local itemname = player:get_wielded_item():get_name()
|
|
|
|
|
|
|
|
if itemname ~= "" then
|
|
|
|
self.object:set_properties({textures = {itemname}})
|
|
|
|
else
|
|
|
|
self.object:set_properties({textures = {"wielditem:null"}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local function attach_wielditem(player)
|
|
|
|
local name = player:get_player_name()
|
2019-03-20 15:04:20 +01:00
|
|
|
local pos = player:get_pos()
|
2015-10-20 19:59:21 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
wielditem[name] = minetest.add_entity(pos, "wielditem:wielditem")
|
2015-10-21 18:31:00 +02:00
|
|
|
wielditem[name]:set_attach(player, "right_arm", {x = -1.5, y = 5.7, z = 2.5}, {x = 90, y = -45, z = 270})
|
2015-10-20 19:59:21 +02:00
|
|
|
wielditem[name]:get_luaentity().wielder = player
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2015-10-20 19:59:21 +02:00
|
|
|
local function detach_wielditem(player)
|
|
|
|
local name = player:get_player_name()
|
2015-09-29 22:06:38 +02:00
|
|
|
|
2015-10-20 19:59:21 +02:00
|
|
|
wielditem[name]:remove()
|
2015-10-20 20:44:38 +02:00
|
|
|
wielditem[name] = nil
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_on_joinplayer(attach_wielditem)
|
|
|
|
minetest.register_on_leaveplayer(detach_wielditem)
|
2015-10-17 23:15:34 +02:00
|
|
|
|
2019-08-29 05:46:44 +02:00
|
|
|
default.log("mod:wielditem", "loaded")
|