mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-11-22 22:53:46 +01:00
Try to insert incom. stacks to the correct drawer slot first
This commit is contained in:
parent
a939d8cc9f
commit
14f21a434e
10
lua/api.lua
10
lua/api.lua
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user