Improve sneak pick items

This commit is contained in:
Juraj Vajda 2024-03-10 11:28:23 -04:00
parent e704adbc15
commit 2ac24a856d

View File

@ -50,11 +50,28 @@ local function pick_dropped_items(player)
local luaentity = object:get_luaentity() local luaentity = object:get_luaentity()
local itemstack = ItemStack(luaentity.itemstring) local itemstack = ItemStack(luaentity.itemstring)
if if not luaentity._being_collected then
inv:room_for_item('main', itemstack) -- Invoke global on_item_pickup callbacks.
and not luaentity._being_collected -- for _, callback in ipairs(minetest.registered_on_item_pickups) do
then -- local result = callback(itemstack, player, { type = 'object', ref = object })
inv:add_item('main', itemstack)
-- if result then
-- itemstack = ItemStack(result)
-- end
-- end
local leftover_stack = inv:add_item('main', itemstack)
local stack_count_prev = itemstack:get_count()
local stack_count_leftover = leftover_stack:get_count()
if leftover_stack and stack_count_prev ~= stack_count_leftover then
-- Collect item / Item fits in the inventory
local pos_obj = object:get_pos()
if leftover_stack ~= 0 then
minetest.spawn_item(pos_obj, leftover_stack:to_string())
end
luaentity._being_collected = true luaentity._being_collected = true
object:set_acceleration({ x = 0, y = 0, z = 0 }) object:set_acceleration({ x = 0, y = 0, z = 0 })
object:set_velocity({ x = 0, y = 0, z = 0 }) object:set_velocity({ x = 0, y = 0, z = 0 })
@ -68,8 +85,6 @@ local function pick_dropped_items(player)
collisionbox = { 0, 0, 0, 0, 0, 0 } collisionbox = { 0, 0, 0, 0, 0, 0 }
}) })
local pos_obj = object:get_pos()
object:move_to(vector.new( object:move_to(vector.new(
(pos.x - pos_obj.x) + pos_obj.x, (pos.x - pos_obj.x) + pos_obj.x,
(pos.y - pos_obj.y) + pos_obj.y + 1.25, (pos.y - pos_obj.y) + pos_obj.y + 1.25,
@ -90,6 +105,7 @@ local function pick_dropped_items(player)
end end
end end
end end
end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local player_meta = player:get_meta() local player_meta = player:get_meta()