summaryrefslogtreecommitdiff
path: root/lua/api.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-10-26 13:49:03 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-10-26 13:49:03 +0200
commitff07f5e43d9f2b5eb468d7c913ded4efd589e51c (patch)
tree045e8484b3b9f658aa42c8a17ae6c7e7a5bd0aa8 /lua/api.lua
parent23a05553bccbd300de889c98d72b89761a93ac5c (diff)
Add function for pipeworks can_insert, so items don't attempt to enter a drawer with no room for them.
Diffstat (limited to 'lua/api.lua')
-rwxr-xr-xlua/api.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/lua/api.lua b/lua/api.lua
index ad32a3f..f5fb779 100755
--- a/lua/api.lua
+++ b/lua/api.lua
@@ -185,6 +185,18 @@ function drawers.drawer_insert_object(pos, node, stack, direction)
return leftover
end
+function drawers.drawer_can_insert_object(pos, node, stack, direction)
+ local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)]
+ if not drawer_visuals then return false end
+
+ local leftover = stack
+ for _, visual in pairs(drawer_visuals) do
+ leftover = visual:try_insert_stack(leftover, true)
+ end
+ return not (leftover == stack)
+
+end
+
function drawers.register_drawer(name, def)
def.description = def.description or S("Wooden")
def.drawtype = "nodebox"
@@ -215,7 +227,10 @@ function drawers.register_drawer(name, def)
def.groups.tubedevice_receiver = 1
def.tube = def.tube or {}
def.tube.insert_object = def.tube.insert_object or
- drawers.drawer_insert_object
+ drawers.drawer_insert_object
+ def.tube.can_insert = def.tube.can_insert or
+ drawers.drawer_can_insert_object
+
def.tube.connect_sides = {left = 1, right = 1, back = 1, top = 1,
bottom = 1}
def.after_place_node = pipeworks.after_place