From 7cb8086a259c2a66b3920f1e272843c86c9cba6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Wed, 15 Apr 2020 20:21:48 +0200 Subject: [PATCH] Get player inventory before looping (#30) This prevents the inventory check on each object in the loop and thus shortens the code. Additionally, the inventory existence check is removed because get_inventory never returns nil for player objects. --- init.lua | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/init.lua b/init.lua index 25145b1..bc0fc1a 100644 --- a/init.lua +++ b/init.lua @@ -262,7 +262,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", local pos = player:get_pos() pos.y = pos.y+0.5 - local inv + local inv = player:get_inventory() local objectlist = minetest.get_objects_inside_radius(pos, magnet_mode and magnet_radius or pickup_radius) @@ -271,14 +271,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", local ent = opt_get_ent(object) if ent and item_drop.can_pickup(ent, player) then - if not inv then - inv = player:get_inventory() - if not inv then - minetest.log("error", "[item_drop] Couldn't " .. - "get inventory") - return - end - end local item = ItemStack(ent.itemstring) if inv:room_for_item("main", item) then local flying_item