mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-11-08 07:53:44 +01:00
Allow controller to store item even when current drawers are full (#69)
This commit is contained in:
parent
0ea57687b3
commit
3e6ba27d49
@ -255,29 +255,14 @@ local function controller_get_drawer_index(pos, itemstring)
|
||||
return drawer_net_index
|
||||
end
|
||||
|
||||
local function controller_insert_to_drawers(pos, stack)
|
||||
local function controller_try_new_drawer(pos,stack)
|
||||
-- Inizialize metadata
|
||||
local meta = core.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local drawer_net_index = controller_get_drawer_index(pos, stack:get_name())
|
||||
|
||||
-- We check if there is a drawer with the item and it isn't full. We will
|
||||
-- put the items we can into it.
|
||||
if drawer_net_index[stack:get_name()] then
|
||||
local drawer_pos = drawer_net_index[stack:get_name()]["drawer_pos"]
|
||||
local visualid = drawer_net_index[stack:get_name()]["visualid"]
|
||||
local content = drawers.drawer_get_content(drawer_pos, visualid)
|
||||
|
||||
-- If the the item in the drawer is the same as the one we are trying to
|
||||
-- store, the drawer is not full, and the drawer entity is loaded, we
|
||||
-- will put the items in the drawer
|
||||
if content.name == stack:get_name() and
|
||||
content.count < content.maxCount and
|
||||
drawers.drawer_visuals[core.hash_node_position(drawer_pos)] then
|
||||
return drawers.drawer_insert_object(drawer_pos, stack, visualid)
|
||||
end
|
||||
elseif drawer_net_index["empty"] then
|
||||
if drawer_net_index["empty"] then
|
||||
local drawer_pos = drawer_net_index["empty"]["drawer_pos"]
|
||||
local visualid = drawer_net_index["empty"]["visualid"]
|
||||
local content = drawers.drawer_get_content(drawer_pos, visualid)
|
||||
@ -298,6 +283,44 @@ local function controller_insert_to_drawers(pos, stack)
|
||||
end
|
||||
end
|
||||
|
||||
-- If we do not have an empty drawer or the empty drawer is not actually empty, fail out
|
||||
-- We cannot store this right now
|
||||
return stack
|
||||
end
|
||||
|
||||
local function controller_insert_to_drawers(pos, stack)
|
||||
-- Inizialize metadata
|
||||
local meta = core.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local drawer_net_index = controller_get_drawer_index(pos, stack:get_name())
|
||||
|
||||
-- We check if there is a drawer with the item and it isn't full. We will
|
||||
-- put the items we can into it.
|
||||
if drawer_net_index[stack:get_name()] then
|
||||
local drawer_pos = drawer_net_index[stack:get_name()]["drawer_pos"]
|
||||
local visualid = drawer_net_index[stack:get_name()]["visualid"]
|
||||
local content = drawers.drawer_get_content(drawer_pos, visualid)
|
||||
|
||||
-- If the the item in the drawer is the same as the one we are trying to
|
||||
-- store, the drawer is not full, and the drawer entity is loaded, we
|
||||
-- will put the items in the drawer
|
||||
if content.name == stack:get_name() and
|
||||
drawers.drawer_visuals[core.hash_node_position(drawer_pos)] then
|
||||
if content.count < content.maxCount then
|
||||
return drawers.drawer_insert_object(drawer_pos, stack, visualid)
|
||||
else
|
||||
-- No room in any existing drawers, try to make a new drawer for this
|
||||
return controller_try_new_drawer(pos, stack)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- No drawer currently contains this item, try to make a new drawer for this
|
||||
return controller_try_new_drawer(pos, stack)
|
||||
end
|
||||
|
||||
-- If the contents do not actually match the index, fail out
|
||||
-- We cannot store this right now
|
||||
return stack
|
||||
end
|
||||
|
||||
@ -334,7 +357,12 @@ local function controller_allow_metadata_inventory_put(pos, listname, index, sta
|
||||
local drawer = drawer_net_index[stack:get_name()]
|
||||
|
||||
if drawers.drawer_get_content(drawer.drawer_pos, drawer.visualid).name == stack:get_name() then
|
||||
return drawers.drawer_can_insert_stack(drawer.drawer_pos, stack, drawer["visualid"])
|
||||
local can_store = drawers.drawer_can_insert_stack(drawer.drawer_pos, stack, drawer["visualid"])
|
||||
-- If we have a drawer for this item, but can't put anything there, it's probably full
|
||||
-- attempt to put in a new empty drawer
|
||||
if can_store ~= 0 then
|
||||
return can_store
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user