mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-11-22 14:43:45 +01:00
Try to insert incom. stacks to the correct drawer slot first
This commit is contained in:
parent
a939d8cc9f
commit
14f21a434e
12
lua/api.lua
12
lua/api.lua
@ -181,9 +181,19 @@ 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
|
||||||
leftover = visual:try_insert_stack(leftover, true)
|
if visual.itemName == stack:get_name() then
|
||||||
|
leftover = visual:try_insert_stack(leftover, true)
|
||||||
|
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
|
end
|
||||||
return leftover
|
return leftover
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user