1
0
Fork 0

Additional cleanup, impelemnt partial item stack pickup

This commit is contained in:
teknomunk 2024-02-16 13:49:15 +00:00
parent 0a294c55a1
commit 13ce4f9092
1 changed files with 33 additions and 30 deletions

View File

@ -116,30 +116,29 @@ end
local function try_object_pickup(player, inv, object, checkpos) local function try_object_pickup(player, inv, object, checkpos)
if not inv then return end if not inv then return end
local le = object:get_luaentity()
-- Check magnet timer -- Check magnet timer
if not (object:get_luaentity()._magnet_timer >= 0) then return end if not (le._magnet_timer >= 0) then return end
if not (object:get_luaentity()._magnet_timer < item_drop_settings.magnet_time) then return end if not (le._magnet_timer < item_drop_settings.magnet_time) then return end
-- Make sure we have room for the item -- Don't try to collect again
local itemstack = ItemStack(object:get_luaentity().itemstring) if le._removed then return end
if not inv:room_for_item("main", itemstack ) then
return
end
-- Collection
if object:get_luaentity()._removed then return end
-- Ignore if itemstring is not set yet -- Ignore if itemstring is not set yet
if object:get_luaentity().itemstring == "" then return end if le.itemstring == "" then return end
inv:add_item("main", itemstack ) -- Add what we can to the inventory
local itemstack = ItemStack(le.itemstring)
local leftovers = inv:add_item("main", itemstack )
check_pickup_achievements(object, player) check_pickup_achievements(object, player)
if leftovers:is_empty() then
-- Destroy entity -- Destroy entity
-- This just prevents this section to be run again because object:remove() doesn't remove the item immediately. -- This just prevents this section to be run again because object:remove() doesn't remove the item immediately.
object:get_luaentity().target = checkpos le.target = checkpos
object:get_luaentity()._removed = true le._removed = true
-- Stop the object -- Stop the object
object:set_velocity(vector.zero()) object:set_velocity(vector.zero())
@ -157,6 +156,10 @@ local function try_object_pickup(player, inv, object, checkpos)
object:remove() object:remove()
end end
end) end)
else
-- Update entity itemstring
le.itemstring = leftovers:to_string()
end
end end
minetest.register_globalstep(function(_) minetest.register_globalstep(function(_)