(string.find(nym.name, "pipeworks:pump") ~= nil) then
pym=1
end
+
+-- ...extra devices specified via the function's parameters
+-- ...except that this part is not implemented yet
+--
+-- if (string.find(nym.name, "aero:outlet") ~= nil) then
+-- pxm, pxp, pym, and/or pyp = 1 depending on the needed rules
+-- end
+
end
function pipe_look_for_stackable_tanks(pos)
{ -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
}
+spigot_bottomstub = {
+ { -2/64, -16/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
+ { -4/64, -16/64, -5/64, 4/64, 1/64, 5/64 },
+ { -5/64, -16/64, -4/64, 5/64, 1/64, 4/64 },
+ { -6/64, -16/64, -2/64, 6/64, 1/64, 2/64 },
+
+ { -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 }, -- (the flange for it)
+ { -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
+ { -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
+ { -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
+ { -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
+}
+
+entry_panel = {
+ { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
+}
-- Now define the nodes.
local states = { "on", "off" }
groups = dgroups,
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
+ pipelike = 1,
+ on_construct = function(pos)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_int("pipelike",1)
+ end,
after_place_node = function(pos)
pipe_scanforobjects(pos)
end,
groups = dgroups,
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
+ pipelike = 1,
+ on_construct = function(pos)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_int("pipelike",1)
+ end,
after_place_node = function(pos)
pipe_scanforobjects(pos)
end,
end,
drop = "pipeworks:valve_off",
pipelike=1,
- on_construct = function(pos)
- local meta = minetest.env:get_meta(pos)
- meta:set_int("pipelike",1)
- end,
})
end
groups = {snappy=3, pipe=1},
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
after_place_node = function(pos)
pipe_scanforobjects(pos)
end,
groups = {snappy=3, pipe=1},
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
+ pipelike=1,
+ on_construct = function(pos)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_int("pipelike",1)
+ end,
after_place_node = function(pos)
pipe_scanforobjects(pos)
end,
after_dig_node = function(pos)
pipe_scanforobjects(pos)
end,
- pipelike=1,
- on_construct = function(pos)
- local meta = minetest.env:get_meta(pos)
- meta:set_int("pipelike",1)
- end,
node_box = {
type = "fixed",
fixed = spigotboxes,
groups = {snappy=3, pipe=1},
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
after_place_node = function(pos)
pipe_scanforobjects(pos)
end,
groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
drop = "pipeworks:storage_tank_"..fill,
after_place_node = function(pos)
pipe_look_for_stackable_tanks(pos)
groups = sgroups,
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
after_place_node = function(pos)
pipe_look_for_stackable_tanks(pos)
pipe_scanforobjects(pos)
--- /dev/null
+-- This file provides the actual flow and pathfinding logic that makes water
+-- move through the pipes.
+--
+-- Contributed by mauvebic, 2013-01-03, with tweaks by Vanessa Ezekowitz
+--
+
+local check4liquids = function(pos)
+ local coords = {
+ {x=pos.x,y=pos.y-1,z=pos.z},
+ {x=pos.x,y=pos.y+1,z=pos.z},
+ {x=pos.x-1,y=pos.y,z=pos.z},
+ {x=pos.x+1,y=pos.y,z=pos.z},
+ {x=pos.x,y=pos.y,z=pos.z-1},
+ {x=pos.x,y=pos.y,z=pos.z+1}, }
+ for i =1,6 do
+ local name = minetest.env:get_node(coords[i]).name
+ if string.find(name,'water') then return true end
+ end
+ return false
+end
+
+local check4inflows = function(pos,node)
+ local coords = {
+ {x=pos.x,y=pos.y-1,z=pos.z},
+ {x=pos.x,y=pos.y+1,z=pos.z},
+ {x=pos.x-1,y=pos.y,z=pos.z},
+ {x=pos.x+1,y=pos.y,z=pos.z},
+ {x=pos.x,y=pos.y,z=pos.z-1},
+ {x=pos.x,y=pos.y,z=pos.z+1}, }
+ local newnode = false
+ local source = false
+ for i =1,6 do
+ if newnode then break end
+ local name = minetest.env:get_node(coords[i]).name
+ if (name == 'pipeworks:pump_on' and check4liquids(coords[i])) or string.find(name,'_loaded') then
+ if string.find(name,'_loaded') then
+ local source = minetest.env:get_meta(coords[i]):get_string('source')
+ if source == minetest.pos_to_string(pos) then break end
+ end
+ newnode = string.gsub(node.name,'empty','loaded')
+ source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
+ if newnode ~= nil then dbg(newnode) end
+ end
+ end
+ if newnode then dbg(newnode..' to replace '..node.name) end
+ if newnode then
+ minetest.env:add_node(pos,{name=newnode})
+ minetest.env:get_meta(pos):set_string('source',minetest.pos_to_string(source))
+ end
+end
+
+local checksources = function(pos,node)
+ local sourcepos = minetest.string_to_pos(minetest.env:get_meta(pos):get_string('source'))
+ local source = minetest.env:get_node(sourcepos).name
+ local newnode = false
+ if not ((source == 'pipeworks:pump_on' and check4liquids(sourcepos)) or string.find(source,'_loaded') or source == 'ignore' ) then
+ newnode = string.gsub(node.name,'loaded','empty')
+ end
+
+ if newnode then dbg(newnode..' to replace '..node.name) end
+ if newnode then
+ minetest.env:add_node(pos,{name=newnode})
+ minetest.env:get_meta(pos):set_string('source','')
+ end
+end
+
+local update_outlet = function(pos)
+ local top = minetest.env:get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
+ if string.find(top,'_loaded') then
+ minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'})
+ elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
+ minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z})
+ end
+end
+
+local spigot_check = function(pos,node)
+ local check = {{x=pos.x,y=pos.y,z=pos.z+1},{x=pos.x+1,y=pos.y,z=pos.z},{x=pos.x,y=pos.y,z=pos.z-1},{x=pos.x-1,y=pos.y,z=pos.z} }
+ dbg(node.param2..' checking '..minetest.pos_to_string(check[node.param2+1])..' for spigot at '..minetest.pos_to_string(pos))
+ local top = minetest.env:get_node(check[node.param2+1]).name
+ dbg('found '..top)
+ if string.find(top,'_loaded') then
+ minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'})
+ elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
+ minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z})
+ end
+end
+
+minetest.register_abm({
+ nodenames = empty_nodenames,
+ interval = 15,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider) check4inflows(pos,node) end
+})
+
+minetest.register_abm({
+ nodenames = full_nodenames,
+ interval = 10,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider) checksources(pos,node) end
+})
+
+minetest.register_abm({
+ nodenames = {'pipeworks:outlet','pipeworks:spigot'},
+ interval = 10,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ if node.name == 'pipeworks:outlet' then update_outlet(pos)
+ elseif node.name == 'pipeworks:spigot' then spigot_check(pos,node) end
+ end
+})
-- Un-comment the following dofile line to re-enable the old pipe nodes.
-- dofile(minetest.get_modpath("pipeworks").."/oldpipes.lua")
+--
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
+local DEBUG = true
pipe_leftstub = {
{ -32/64, -2/64, -6/64, 1/64, 2/64, 6/64 }, -- pipe segment against -X face
{ -3/64, -3/64, -5/64, 3/64, 3/64, 5/64 }
}
-spigot_bottomstub = {
- { -2/64, -16/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
- { -4/64, -16/64, -5/64, 4/64, 1/64, 5/64 },
- { -5/64, -16/64, -4/64, 5/64, 1/64, 4/64 },
- { -6/64, -16/64, -2/64, 6/64, 1/64, 2/64 },
-
- { -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 }, -- (the flange for it)
- { -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
- { -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
- { -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
- { -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
-}
-
-entry_panel = {
- { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
-}
-
-- Functions
dbg = function(s)
- if DEBUG == 1 then
+ if DEBUG then
print('[PIPEWORKS] ' .. s)
end
end
-- now define the nodes!
+local empty_nodenames = {}
+local full_nodenames = {}
+
for xm = 0, 1 do
for xp = 0, 1 do
for ym = 0, 1 do
groups = pgroups,
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
drop = "pipeworks:pipe_110000_empty",
pipelike=1,
on_construct = function(pos)
- local meta = minetest.env:get_meta(pos)
- meta:set_int("pipelike",1)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_int("pipelike",1)
end,
after_place_node = function(pos)
pipe_scanforobjects(pos)
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
walkable = true,
- stack_max = 99,
drop = "pipeworks:pipe_110000_empty",
pipelike=1,
on_construct = function(pos)
- local meta = minetest.env:get_meta(pos)
- meta:set_int("pipelike",1)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_int("pipelike",1)
end,
after_place_node = function(pos)
pipe_scanforobjects(pos)
pipe_scanforobjects(pos)
end
})
+ table.insert(empty_nodenames,"pipeworks:pipe_"..pname.."_empty") -- for the abms
+ table.insert(full_nodenames,"pipeworks:pipe_"..pname.."_loaded") -- for bacon
end
end
end
dofile(minetest.get_modpath("pipeworks").."/devices.lua")
dofile(minetest.get_modpath("pipeworks").."/autoplace.lua")
dofile(minetest.get_modpath("pipeworks").."/crafts.lua")
+dofile(minetest.get_modpath("pipeworks").."/flowing_logic.lua")
print("Pipeworks loaded!")