rewrite flowing logic a bit to eliminate excessive add_node/remove_node calls

also got rid of obsolete optdepends
This commit is contained in:
Vanessa Ezekowitz 2013-07-04 00:01:08 -04:00
parent 479df82f2b
commit 7e7ddd9c95
2 changed files with 39 additions and 46 deletions

@ -4,6 +4,8 @@
-- Contributed by mauvebic, 2013-01-03, with tweaks by Vanessa Ezekowitz -- Contributed by mauvebic, 2013-01-03, with tweaks by Vanessa Ezekowitz
-- --
local finitewater = minetest.setting_getbool("liquid_finite")
local check4liquids = function(pos) local check4liquids = function(pos)
local coords = { local coords = {
{x=pos.x,y=pos.y-1,z=pos.z}, {x=pos.x,y=pos.y-1,z=pos.z},
@ -14,8 +16,8 @@ local check4liquids = function(pos)
{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 for i =1,6 do
local name = minetest.get_node(coords[i]).name local name = minetest.get_node(coords[i]).name
if string.find(name,'water') then if string.find(name,"water") then
minetest.remove_node(coords[i]) if finitewater then minetest.remove_node(coords[i]) end
return true return true
end end
end end
@ -35,70 +37,64 @@ local check4inflows = function(pos,node)
for i =1,6 do for i =1,6 do
if newnode then break end if newnode then break end
local name = minetest.get_node(coords[i]).name local name = minetest.get_node(coords[i]).name
if (name == 'pipeworks:pump_on' and check4liquids(coords[i])) or string.find(name,'_loaded') then if (name == "pipeworks:pump_on" and check4liquids(coords[i])) or string.find(name,"_loaded") then
if string.find(name,'_loaded') then if string.find(name,"_loaded") then
local source = minetest.get_meta(coords[i]):get_string('source') local source = minetest.get_meta(coords[i]):get_string("source")
if source == minetest.pos_to_string(pos) then break end if source == minetest.pos_to_string(pos) then break end
end end
newnode = string.gsub(node.name,'empty','loaded') newnode = string.gsub(node.name,"empty","loaded")
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z} source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
if newnode ~= nil then dbg(newnode) end
end end
end end
if newnode then if newnode then
dbg(newnode..' to replace '..node.name)
minetest.add_node(pos,{name=newnode, param2 = node.param2}) minetest.add_node(pos,{name=newnode, param2 = node.param2})
minetest.get_meta(pos):set_string('source',minetest.pos_to_string(source)) minetest.get_meta(pos):set_string("source",minetest.pos_to_string(source))
end end
end end
local checksources = function(pos,node) local checksources = function(pos,node)
local sourcepos = minetest.string_to_pos(minetest.get_meta(pos):get_string('source')) local sourcepos = minetest.string_to_pos(minetest.get_meta(pos):get_string("source"))
if not sourcepos then return end if not sourcepos then return end
local source = minetest.get_node(sourcepos).name local source = minetest.get_node(sourcepos).name
local newnode = false local newnode = false
if not ((source == 'pipeworks:pump_on' and check4liquids(sourcepos)) or string.find(source,'_loaded') or source == 'ignore' ) then 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') newnode = string.gsub(node.name,"loaded","empty")
end end
if newnode then dbg(newnode..' to replace '..node.name) end
if newnode then if newnode then
minetest.add_node(pos,{name=newnode, param2 = node.param2}) minetest.add_node(pos,{name=newnode, param2 = node.param2})
minetest.get_meta(pos):set_string('source','') minetest.get_meta(pos):set_string("source","")
end
end
local update_outlet = function(pos)
local top = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
if string.find(top,'_loaded') then
local name = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
if name == 'air' or name == "default:water_source" or name == "default:water_flowing" then
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'})
end
elseif minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
end end
end end
local spigot_check = function(pos, node) local spigot_check = function(pos, node)
local belowname = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
if belowname == "air" or belowname == "default:water_flowing" or belowname == "default:water_source" then
local spigotname = minetest.get_node(pos).name
local fdir=node.param2 local fdir=node.param2
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} } local check = {
dbg(fdir..' checking '..minetest.pos_to_string(check[fdir+1])..' for spigot at '..minetest.pos_to_string(pos)) {x=pos.x,y=pos.y,z=pos.z+1},
local top = minetest.get_node(check[fdir+1]).name {x=pos.x+1,y=pos.y,z=pos.z},
dbg('found '..top) {x=pos.x,y=pos.y,z=pos.z-1},
local name = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name {x=pos.x-1,y=pos.y,z=pos.z}
if string.find(top,'_loaded') and (name == 'air' or name == "default:water_source" or name == "default:water_flowing") then }
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'}) if string.find(minetest.get_node(check[fdir+1]).name, "_loaded") then
minetest.add_node(pos,{name='pipeworks:spigot_pouring', param2 = fdir}) if spigotname == "pipeworks:spigot" then
minetest.add_node(pos,{name = "pipeworks:spigot_pouring", param2 = fdir})
if finitewater or belowname ~= "default:water_source" then
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name = "default:water_source"})
end
end
else else
if minetest.get_node(pos).name == 'pipeworks:spigot_pouring' then if spigotname == "pipeworks:spigot_pouring" then
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name='pipeworks:spigot', param2 = fdir}) minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:spigot", param2 = fdir})
if name == 'air' or name == "default:water_source" or name == "default:water_flowing" then if belowname == "default:water_source" and not finitewater then
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z}) minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
end end
end end
end end
end end
end
table.insert(pipes_empty_nodenames,"pipeworks:valve_on_empty") table.insert(pipes_empty_nodenames,"pipeworks:valve_on_empty")
table.insert(pipes_empty_nodenames,"pipeworks:valve_off_empty") table.insert(pipes_empty_nodenames,"pipeworks:valve_off_empty")
@ -127,11 +123,10 @@ minetest.register_abm({
}) })
minetest.register_abm({ minetest.register_abm({
nodenames = {'pipeworks:outlet','pipeworks:spigot','pipeworks:spigot_pouring'}, nodenames = {"pipeworks:spigot","pipeworks:spigot_pouring"},
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
if node.name == 'pipeworks:outlet' then update_outlet(pos) spigot_check(pos,node)
elseif node.name == 'pipeworks:spigot' or node.name == 'pipeworks:spigot_pouring' then spigot_check(pos,node) end
end end
}) })

@ -1,2 +0,0 @@
mesecons