avoid loop in is_arrow() function

This commit is contained in:
Alexander Weber 2018-05-08 22:17:42 +02:00 committed by Pierre-Adrien Langrognet
parent 7104780868
commit be9d9753c4
1 changed files with 2 additions and 7 deletions

View File

@ -10,12 +10,7 @@ throwing.modname = minetest.get_current_modname()
--------- Arrows functions ---------
function throwing.is_arrow(itemstack)
for _, arrow in ipairs(throwing.arrows) do
if (type(itemstack) == "string" and itemstack or itemstack:get_name()) == arrow then
return true
end
end
return false
return throwing.arrows[ItemStack(itemstack):get_name()]
end
function throwing.spawn_arrow_entity(pos, arrow, player)
@ -222,7 +217,7 @@ on_throw(pos, hitter)
Unlike on_hit, it is optional.
]]
function throwing.register_arrow(name, def)
table.insert(throwing.arrows, name)
throwing.arrows[name] = true
local registration_name = name
if name:sub(1,9) == "throwing:" then