summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCiaran Gultnieks <ciaran@ciarang.com>2014-02-10 19:18:18 +0000
committerCiaran Gultnieks <ciaran@ciarang.com>2014-02-10 19:19:57 +0000
commit7bac96c58816b4c4ad5dc95dcbdce9e435fcfb50 (patch)
treedf81b188071cc0abdefced54e5a839c5108bc676
parent458fbb6240acd92877271bbe334c4aedb8e4061d (diff)
downloadpipeworks-7bac96c58816b4c4ad5dc95dcbdce9e435fcfb50.tar
pipeworks-7bac96c58816b4c4ad5dc95dcbdce9e435fcfb50.tar.gz
pipeworks-7bac96c58816b4c4ad5dc95dcbdce9e435fcfb50.tar.bz2
pipeworks-7bac96c58816b4c4ad5dc95dcbdce9e435fcfb50.tar.xz
pipeworks-7bac96c58816b4c4ad5dc95dcbdce9e435fcfb50.zip
Add optional before/after filter callbacks
These allow nodes that manage inventory in a non-standard manner (e.g. a barrel) to still be able to work with pipeworks filters.
-rw-r--r--item_transport.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/item_transport.lua b/item_transport.lua
index b97d5bb..1e698bf 100644
--- a/item_transport.lua
+++ b/item_transport.lua
@@ -130,20 +130,30 @@ minetest.register_node("pipeworks:filter", {
if not (tube and tube.input_inventory) then
return
end
+ if tube.before_filter then
+ tube.before_filter(frompos)
+ end
local frommeta = minetest.get_meta(frompos)
local frominvname = tube.input_inventory
local frominv = frommeta:get_inventory()
local sname
+ local fired = false
for _,filter in ipairs(inv:get_list("main")) do
sname = filter:get_name()
if sname ~= "" then
-- XXX: that's a lot of parameters
- if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir) then return end
+ if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir) then
+ fired = true
+ break
+ end
end
end
- if inv:is_empty("main") then
+ if not fired and inv:is_empty("main") then
grabAndFire(frominv,frominvname,frompos,fromnode,nil,tube,idef,dir)
end
+ if tube.after_filter then
+ tube.after_filter(frompos)
+ end
end,
})
@@ -208,7 +218,7 @@ minetest.register_node("pipeworks:mese_filter", {
end
end
if inv:is_empty("main") then
- grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir, true)
+ grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir, true)
end
end,
})