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.
This commit is contained in:
Loïc Blot 2020-04-15 20:21:48 +02:00 committed by GitHub
parent 8ef6ba3c0f
commit 7cb8086a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -262,7 +262,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
local pos = player:get_pos() local pos = player:get_pos()
pos.y = pos.y+0.5 pos.y = pos.y+0.5
local inv local inv = player:get_inventory()
local objectlist = minetest.get_objects_inside_radius(pos, local objectlist = minetest.get_objects_inside_radius(pos,
magnet_mode and magnet_radius or pickup_radius) 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) local ent = opt_get_ent(object)
if ent if ent
and item_drop.can_pickup(ent, player) then 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) local item = ItemStack(ent.itemstring)
if inv:room_for_item("main", item) then if inv:room_for_item("main", item) then
local flying_item local flying_item