Try to insert incom. stacks to the correct drawer slot first

This commit is contained in:
Linus Jahn 2019-05-19 01:09:29 +02:00
parent a939d8cc9f
commit 14f21a434e
No known key found for this signature in database
GPG Key ID: 4663231A91A1E27B

@ -181,10 +181,20 @@ function drawers.drawer_insert_object(pos, node, stack, direction)
local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)] local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)]
if not drawer_visuals then return stack end if not drawer_visuals then return stack end
-- first try to insert in the correct slot (if there are already items)
local leftover = stack local leftover = stack
for _, visual in pairs(drawer_visuals) do for _, visual in pairs(drawer_visuals) do
if visual.itemName == stack:get_name() then
leftover = visual:try_insert_stack(leftover, true) leftover = visual:try_insert_stack(leftover, true)
end end
end
-- if there's still something left, also use other slots
if leftover:get_count() > 0 then
for _, visual in pairs(drawer_visuals) do
leftover = visual:try_insert_stack(leftover, true)
end
end
return leftover return leftover
end end