From be9d9753c4677c5a6723dc52b4fd5a12de7517bc Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Tue, 8 May 2018 22:17:42 +0200 Subject: [PATCH] avoid loop in is_arrow() function --- init.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index 6cd8b4b..2afde48 100644 --- a/init.lua +++ b/init.lua @@ -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