3 Remove only arrow entities

This commit is contained in:
Juraj Vajda 2022-10-05 22:44:46 -04:00
parent 8f21c829f2
commit 9480dfd5fd
4 changed files with 16 additions and 6 deletions

View File

@ -1,3 +1,6 @@
unused_args = false
allow_defined_top = true
globals = {
'x_bows'
}
@ -12,5 +15,6 @@ read_globals = {
'playerphysics',
'hb',
'mesecon',
'dump',
'player_monoids'
}

View File

@ -145,7 +145,7 @@ minetest.register_entity('x_bows:arrow_entity', {
})
end,
on_death = function(self, killer) --luacheck:ignore
on_death = function(self, killer)
if not self._old_pos then
self.object:remove()
return
@ -457,9 +457,15 @@ minetest.register_entity('x_bows:arrow_entity', {
self._attached_to.type = pointed_thing.type
self._attached_to.pos = position
local children = pointed_thing.ref:get_children()
-- remove last arrow when too many already attached
local children = {}
for _, object in ipairs(pointed_thing.ref:get_children()) do
if object:get_luaentity() and object:get_luaentity().name == 'x_bows:arrow_entity' then
table.insert(children, object)
end
end
if #children >= 5 then
children[1]:remove()
end
@ -520,7 +526,7 @@ minetest.register_entity('x_bows:arrow_entity', {
for _, object in ipairs(minetest.get_objects_inside_radius(pointed_thing.under, 1)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == 'x_bows:arrow_entity' then
table.insert(children ,object)
table.insert(children, object)
end
end

View File

@ -160,7 +160,7 @@ function x_bows.load(itemstack, user, pointed_thing)
end
end
function x_bows.shoot(itemstack, user, pointed_thing) --luacheck:ignore
function x_bows.shoot(itemstack, user, pointed_thing)
local time_shoot = minetest.get_us_time();
local meta = itemstack:get_meta()
local meta_arrow = meta:get_string('arrow')

View File

@ -32,7 +32,7 @@ minetest.register_node('x_bows:target', {
groups = {snappy=3, flammable=4, fall_damage_add_percent=-30},
sounds = default.node_sound_leaves_defaults(),
mesecons = {receptor = {state = 'off'}},
on_timer = function (pos, elapsed) --luacheck:ignore
on_timer = function (pos, elapsed)
mesecon.receptor_off(pos)
return false
end,