2019-03-02 22:53:42 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-03-12 22:12:40 -04:00
|
|
|
local minetest, table
|
|
|
|
= minetest, table
|
2019-03-03 12:02:57 -05:00
|
|
|
local table_remove
|
|
|
|
= table.remove
|
2019-03-02 22:53:42 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
2019-03-03 12:02:57 -05:00
|
|
|
local function entprops(stack, conf)
|
2019-03-02 22:53:42 -05:00
|
|
|
local t = {
|
|
|
|
hp_max = 1,
|
|
|
|
physical = false,
|
|
|
|
collide_with_objects = false,
|
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
|
|
|
visual = "wielditem",
|
|
|
|
visual_size = {x = 0.1, y = 0.1, z = 0.1},
|
|
|
|
textures = {""},
|
|
|
|
spritediv = {x = 1, y = 1},
|
|
|
|
initial_sprite_basepos = {x = 0, y = 0},
|
2019-03-04 19:33:55 -05:00
|
|
|
is_visible = false,
|
|
|
|
static_save = false
|
2019-03-02 22:53:42 -05:00
|
|
|
}
|
2019-03-12 21:27:29 -04:00
|
|
|
if not stack then return t end
|
|
|
|
if stack:is_empty() then return t end
|
|
|
|
local def = minetest.registered_items[stack:get_name()] or {}
|
|
|
|
if def.virtual_item then return t end
|
|
|
|
t.is_visible = true
|
|
|
|
t.textures[1] = stack:get_name()
|
|
|
|
if conf and conf.slot == 0 then
|
|
|
|
t.visual_size = {x = 0.2, y = 0.2, z = 0.2}
|
2019-03-02 22:53:42 -05:00
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2019-03-03 12:32:07 -05:00
|
|
|
local attq = {}
|
|
|
|
|
2019-03-02 22:53:42 -05:00
|
|
|
minetest.register_entity(modname .. ":ent", {
|
|
|
|
initial_properties = entprops(),
|
|
|
|
on_step = function(self, dtime)
|
2019-03-03 12:02:57 -05:00
|
|
|
local conf = self.conf
|
|
|
|
if not conf then return self.object:remove() end
|
|
|
|
|
2019-03-03 12:32:07 -05:00
|
|
|
-- if self.ttl then
|
|
|
|
-- self.ttl = self.ttl - dtime
|
|
|
|
-- if self.ttl <= 0 then
|
|
|
|
-- attq[#attq + 1] = conf
|
|
|
|
-- return self.object:remove()
|
|
|
|
-- end
|
|
|
|
-- else self.ttl = math_random() * 5 + 5 end
|
|
|
|
|
2019-03-03 12:02:57 -05:00
|
|
|
local player = minetest.get_player_by_name(conf.pname)
|
|
|
|
if not player then return self.object:remove() end
|
|
|
|
|
|
|
|
if not self.att then
|
|
|
|
self.att = true
|
2019-03-03 12:15:38 -05:00
|
|
|
return self.object:set_attach(player,
|
|
|
|
conf.bone, conf.apos, conf.arot)
|
2019-03-03 12:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
local sz = inv:get_size("main")
|
|
|
|
local s = conf.slot + player:get_wield_index()
|
|
|
|
if s > sz then s = s - sz end
|
|
|
|
|
|
|
|
local stack = inv:get_stack("main", s)
|
|
|
|
local sn = stack:get_name()
|
|
|
|
if sn ~= self.sn then
|
|
|
|
self.sn = sn
|
2019-03-03 12:15:38 -05:00
|
|
|
self.object:set_properties(entprops(stack, conf))
|
2019-03-02 22:53:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2019-03-02 23:14:41 -05:00
|
|
|
minetest.register_globalstep(function()
|
2019-03-03 12:02:57 -05:00
|
|
|
local v = table_remove(attq, 1)
|
|
|
|
if not v then return end
|
|
|
|
|
2019-03-02 23:14:41 -05:00
|
|
|
local player = minetest.get_player_by_name(v.pname)
|
|
|
|
if not player then return end
|
2019-03-03 12:02:57 -05:00
|
|
|
|
|
|
|
if not minetest.get_node_or_nil(player:get_pos()) then
|
|
|
|
attq[#attq + 1] = v
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-03-02 23:14:41 -05:00
|
|
|
local obj = minetest.add_entity(v.pos, modname .. ":ent")
|
|
|
|
local ent = obj:get_luaentity()
|
2019-03-03 12:04:57 -05:00
|
|
|
ent.conf = v
|
2019-03-02 23:14:41 -05:00
|
|
|
end)
|
|
|
|
|
2019-03-02 22:53:42 -05:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local pos = player:get_pos()
|
|
|
|
|
|
|
|
local function addslot(n, b, x, y, z, rx, ry, rz)
|
2019-03-03 12:02:57 -05:00
|
|
|
attq[#attq + 1] = {
|
2019-03-02 23:14:41 -05:00
|
|
|
pname = pname,
|
2019-03-03 12:02:57 -05:00
|
|
|
slot = n,
|
2019-03-02 23:14:41 -05:00
|
|
|
pos = pos,
|
|
|
|
bone = b,
|
2019-03-03 12:02:57 -05:00
|
|
|
apos = {
|
|
|
|
x = x,
|
|
|
|
y = y,
|
|
|
|
z = z
|
|
|
|
},
|
|
|
|
arot = {
|
|
|
|
x = rx or 0,
|
|
|
|
y = ry or 0,
|
|
|
|
z = rz or 0
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 22:53:42 -05:00
|
|
|
end
|
|
|
|
|
2019-03-02 23:37:39 -05:00
|
|
|
addslot(0, "Arm_Right", -2.5, 8, 0, 2, 178, 60)
|
2019-03-02 22:53:42 -05:00
|
|
|
|
2019-03-12 22:12:40 -04:00
|
|
|
-- local function cslot(n, x, z)
|
|
|
|
-- return addslot(n, nil, x * 1.6,
|
|
|
|
-- (nodecore.mt_old and -4 or 5.5) + x / 2,
|
|
|
|
-- z * 2.1)
|
|
|
|
-- end
|
|
|
|
|
|
|
|
-- cslot(1, 1, 1)
|
|
|
|
-- cslot(2, 0, 1.2)
|
|
|
|
-- cslot(3, -1, 1)
|
|
|
|
-- cslot(4, -2, 0)
|
|
|
|
-- cslot(5, -1, -1)
|
|
|
|
-- cslot(6, 0, -1.2)
|
|
|
|
-- cslot(7, 1, -1)
|
2019-03-02 22:53:42 -05:00
|
|
|
end)
|