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,43 +50,59 @@ 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)
luaentity._being_collected = true
object:set_acceleration({ x = 0, y = 0, z = 0 })
object:set_velocity({ x = 0, y = 0, z = 0 })
luaentity.physical_state = false
luaentity.object:set_properties({
physical = false,
-- prevent picking up items while they are moving to the player
-- since the items are in the players inventory already this would
-- duplicate the itemstack
selectionbox = { 0, 0, 0, 0, 0, 0 },
collisionbox = { 0, 0, 0, 0, 0, 0 }
})
local pos_obj = object:get_pos() -- if result then
-- itemstack = ItemStack(result)
-- end
-- end
object:move_to(vector.new( local leftover_stack = inv:add_item('main', itemstack)
(pos.x - pos_obj.x) + pos_obj.x, local stack_count_prev = itemstack:get_count()
(pos.y - pos_obj.y) + pos_obj.y + 1.25, local stack_count_leftover = leftover_stack:get_count()
(pos.z - pos_obj.z) + pos_obj.z
))
minetest.sound_play('everness_item_drop_pickup', { if leftover_stack and stack_count_prev ~= stack_count_leftover then
pos = pos, -- Collect item / Item fits in the inventory
max_hear_distance = 16, local pos_obj = object:get_pos()
gain = 0.4,
})
minetest.after(0.25, function(v_object) if leftover_stack ~= 0 then
if v_object and v_object:get_luaentity() then minetest.spawn_item(pos_obj, leftover_stack:to_string())
v_object:remove()
end end
end, object)
luaentity._being_collected = true
object:set_acceleration({ x = 0, y = 0, z = 0 })
object:set_velocity({ x = 0, y = 0, z = 0 })
luaentity.physical_state = false
luaentity.object:set_properties({
physical = false,
-- prevent picking up items while they are moving to the player
-- since the items are in the players inventory already this would
-- duplicate the itemstack
selectionbox = { 0, 0, 0, 0, 0, 0 },
collisionbox = { 0, 0, 0, 0, 0, 0 }
})
object:move_to(vector.new(
(pos.x - pos_obj.x) + pos_obj.x,
(pos.y - pos_obj.y) + pos_obj.y + 1.25,
(pos.z - pos_obj.z) + pos_obj.z
))
minetest.sound_play('everness_item_drop_pickup', {
pos = pos,
max_hear_distance = 16,
gain = 0.4,
})
minetest.after(0.25, function(v_object)
if v_object and v_object:get_luaentity() then
v_object:remove()
end
end, object)
end
end end
end end
end end