forked from mtcontrib/pipeworks
Accept multiple input inventories, fix bug with mesecons_mvps
This commit is contained in:
parent
8efcd39e39
commit
fd3c88eb86
|
@ -134,23 +134,36 @@ minetest.register_node("pipeworks:filter", {
|
||||||
tube.before_filter(frompos)
|
tube.before_filter(frompos)
|
||||||
end
|
end
|
||||||
local frommeta = minetest.get_meta(frompos)
|
local frommeta = minetest.get_meta(frompos)
|
||||||
local frominvname = tube.input_inventory
|
|
||||||
local frominv = frommeta:get_inventory()
|
local frominv = frommeta:get_inventory()
|
||||||
local sname
|
|
||||||
local fired = false
|
local function from_inventory(frominvname)
|
||||||
for _,filter in ipairs(inv:get_list("main")) do
|
local sname
|
||||||
sname = filter:get_name()
|
for _,filter in ipairs(inv:get_list("main")) do
|
||||||
if sname ~= "" then
|
sname = filter:get_name()
|
||||||
-- XXX: that's a lot of parameters
|
if sname ~= "" then
|
||||||
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir) then
|
-- XXX: that's a lot of parameters
|
||||||
fired = true
|
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if inv:is_empty("main") then
|
||||||
|
grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(tube.input_inventory) == "table" then
|
||||||
|
for _, i in ipairs(tube.input_inventory) do
|
||||||
|
if from_inventory(i) then -- fired an item
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
from_inventory(tube.input_inventory)
|
||||||
end
|
end
|
||||||
if not fired and inv:is_empty("main") then
|
|
||||||
grabAndFire(frominv,frominvname,frompos,fromnode,nil,tube,idef,dir)
|
|
||||||
end
|
|
||||||
if tube.after_filter then
|
if tube.after_filter then
|
||||||
tube.after_filter(frompos)
|
tube.after_filter(frompos)
|
||||||
end
|
end
|
||||||
|
@ -207,18 +220,43 @@ minetest.register_node("pipeworks:mese_filter", {
|
||||||
if not (tube and tube.input_inventory) then
|
if not (tube and tube.input_inventory) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local frommeta = minetest.get_meta(frompos)
|
|
||||||
local frominvname = minetest.registered_nodes[fromnode.name].tube.input_inventory
|
if tube.before_filter then
|
||||||
local frominv = frommeta:get_inventory()
|
tube.before_filter(frompos)
|
||||||
local sname
|
|
||||||
for _,filter in ipairs(inv:get_list("main")) do
|
|
||||||
sname = filter:get_name()
|
|
||||||
if sname ~= "" then
|
|
||||||
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir, true) then return end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if inv:is_empty("main") then
|
local frommeta = minetest.get_meta(frompos)
|
||||||
grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir, true)
|
local frominv = frommeta:get_inventory()
|
||||||
|
|
||||||
|
local function from_inventory(frominvname)
|
||||||
|
local sname
|
||||||
|
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, true) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if inv:is_empty("main") then
|
||||||
|
grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir, true)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(tube.input_inventory) == "table" then
|
||||||
|
for _, i in ipairs(tube.input_inventory) do
|
||||||
|
if from_inventory(i) then -- fired an item
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
from_inventory(tube.input_inventory)
|
||||||
|
end
|
||||||
|
|
||||||
|
if tube.after_filter then
|
||||||
|
tube.after_filter(frompos)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -473,6 +511,16 @@ minetest.register_entity("pipeworks:tubed_item", {
|
||||||
})
|
})
|
||||||
|
|
||||||
if minetest.get_modpath("mesecons_mvps") ~= nil then
|
if minetest.get_modpath("mesecons_mvps") ~= nil then
|
||||||
|
local function add_table(table,toadd)
|
||||||
|
local i = 1
|
||||||
|
while true do
|
||||||
|
o = table[i]
|
||||||
|
if o == toadd then return end
|
||||||
|
if o == nil then break end
|
||||||
|
i = i+1
|
||||||
|
end
|
||||||
|
table[i] = toadd
|
||||||
|
end
|
||||||
mesecon:register_mvps_unmov("pipeworks:tubed_item")
|
mesecon:register_mvps_unmov("pipeworks:tubed_item")
|
||||||
mesecon:register_on_mvps_move(function(moved_nodes)
|
mesecon:register_on_mvps_move(function(moved_nodes)
|
||||||
local objects_to_move = {}
|
local objects_to_move = {}
|
||||||
|
@ -481,7 +529,8 @@ if minetest.get_modpath("mesecons_mvps") ~= nil then
|
||||||
for _, obj in ipairs(objects) do
|
for _, obj in ipairs(objects) do
|
||||||
local entity = obj:get_luaentity()
|
local entity = obj:get_luaentity()
|
||||||
if entity and entity.name == "pipeworks:tubed_item" then
|
if entity and entity.name == "pipeworks:tubed_item" then
|
||||||
objects_to_move[#objects_to_move+1] = obj
|
--objects_to_move[#objects_to_move+1] = obj
|
||||||
|
add_table(objects_to_move, obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user