summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2013-07-04 00:01:08 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2013-07-04 00:01:08 -0400
commit7e7ddd9c951745e6e34fa7d1eb2f7683be192e78 (patch)
tree13da16fe9e7740296cf2467e3eba86aa83628431
parent479df82f2b87adc731403561861b45125ef04116 (diff)
downloadpipeworks-7e7ddd9c951745e6e34fa7d1eb2f7683be192e78.tar
pipeworks-7e7ddd9c951745e6e34fa7d1eb2f7683be192e78.tar.gz
pipeworks-7e7ddd9c951745e6e34fa7d1eb2f7683be192e78.tar.bz2
pipeworks-7e7ddd9c951745e6e34fa7d1eb2f7683be192e78.tar.xz
pipeworks-7e7ddd9c951745e6e34fa7d1eb2f7683be192e78.zip
rewrite flowing logic a bit to eliminate excessive add_node/remove_node calls
also got rid of obsolete optdepends
-rw-r--r--flowing_logic.lua83
-rw-r--r--optdepends.txt2
2 files changed, 39 insertions, 46 deletions
diff --git a/flowing_logic.lua b/flowing_logic.lua
index facf1b2..b68bb8c 100644
--- a/flowing_logic.lua
+++ b/flowing_logic.lua
@@ -4,6 +4,8 @@
-- Contributed by mauvebic, 2013-01-03, with tweaks by Vanessa Ezekowitz
--
+local finitewater = minetest.setting_getbool("liquid_finite")
+
local check4liquids = function(pos)
local coords = {
{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}, }
for i =1,6 do
local name = minetest.get_node(coords[i]).name
- if string.find(name,'water') then
- minetest.remove_node(coords[i])
+ if string.find(name,"water") then
+ if finitewater then minetest.remove_node(coords[i]) end
return true
end
end
@@ -35,66 +37,60 @@ local check4inflows = function(pos,node)
for i =1,6 do
if newnode then break end
local name = minetest.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.get_meta(coords[i]):get_string('source')
+ if (name == "pipeworks:pump_on" and check4liquids(coords[i])) or string.find(name,"_loaded") then
+ if string.find(name,"_loaded") then
+ local source = minetest.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')
+ 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)
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
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
local source = minetest.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')
+ 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.add_node(pos,{name=newnode, param2 = node.param2})
- 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})
+ minetest.get_meta(pos):set_string("source","")
end
end
-local spigot_check = function(pos,node)
- 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} }
- dbg(fdir..' checking '..minetest.pos_to_string(check[fdir+1])..' for spigot at '..minetest.pos_to_string(pos))
- local top = minetest.get_node(check[fdir+1]).name
- dbg('found '..top)
- local name = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
- 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'})
- minetest.add_node(pos,{name='pipeworks:spigot_pouring', param2 = fdir})
- else
- if minetest.get_node(pos).name == 'pipeworks:spigot_pouring' then
- 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
- minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
+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 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}
+ }
+ if string.find(minetest.get_node(check[fdir+1]).name, "_loaded") then
+ 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
+ if spigotname == "pipeworks:spigot_pouring" then
+ minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:spigot", param2 = fdir})
+ if belowname == "default:water_source" and not finitewater then
+ minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
+ end
end
end
end
@@ -127,11 +123,10 @@ minetest.register_abm({
})
minetest.register_abm({
- nodenames = {'pipeworks:outlet','pipeworks:spigot','pipeworks:spigot_pouring'},
+ nodenames = {"pipeworks:spigot","pipeworks:spigot_pouring"},
interval = 1,
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' or node.name == 'pipeworks:spigot_pouring' then spigot_check(pos,node) end
+ spigot_check(pos,node)
end
})
diff --git a/optdepends.txt b/optdepends.txt
deleted file mode 100644
index d92a438..0000000
--- a/optdepends.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-mesecons
-