3 Remove only arrow entities

This commit is contained in:
Juraj Vajda 2022-10-06 02:50:12 +00:00
commit 53b9b56b26
4 changed files with 16 additions and 6 deletions

View File

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

View File

@ -145,7 +145,7 @@ minetest.register_entity('x_bows:arrow_entity', {
}) })
end, end,
on_death = function(self, killer) --luacheck:ignore on_death = function(self, killer)
if not self._old_pos then if not self._old_pos then
self.object:remove() self.object:remove()
return return
@ -457,9 +457,15 @@ minetest.register_entity('x_bows:arrow_entity', {
self._attached_to.type = pointed_thing.type self._attached_to.type = pointed_thing.type
self._attached_to.pos = position self._attached_to.pos = position
local children = pointed_thing.ref:get_children()
-- remove last arrow when too many already attached -- 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 if #children >= 5 then
children[1]:remove() children[1]:remove()
end 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 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 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
end end

View File

@ -160,7 +160,7 @@ function x_bows.load(itemstack, user, pointed_thing)
end end
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 time_shoot = minetest.get_us_time();
local meta = itemstack:get_meta() local meta = itemstack:get_meta()
local meta_arrow = meta:get_string('arrow') 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}, groups = {snappy=3, flammable=4, fall_damage_add_percent=-30},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
mesecons = {receptor = {state = 'off'}}, mesecons = {receptor = {state = 'off'}},
on_timer = function (pos, elapsed) --luacheck:ignore on_timer = function (pos, elapsed)
mesecon.receptor_off(pos) mesecon.receptor_off(pos)
return false return false
end, end,