Merge branch 'master' of github.com:Jeija/minetest-mod-mesecons

This commit is contained in:
Vanessa Ezekowitz 2012-08-13 04:37:58 -04:00
commit 2f5ccf5b4f
4 changed files with 39 additions and 15 deletions

@ -98,7 +98,6 @@ dofile(minetest.get_modpath("mesecons").."/settings.lua")
--Internal API
dofile(minetest.get_modpath("mesecons").."/internal_api.lua");
-- API API API API API API API API API API API API API API API API API API
function mesecon:add_receptor_node(nodename, rules, get_rules) --rules table is optional; if rules depend on param2 pass (nodename, nil, function get_rules)
@ -152,13 +151,16 @@ function mesecon:receptor_off(pos, rules)
rules = mesecon:get_rules("default")
end
local checked = {}
local connected = false
local i = 1
while rules[i]~=nil do
local np = {}
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
if not mesecon:connected_to_pw_src(np, {}) then
connected, checked = mesecon:connected_to_pw_src(np, checked)
if not connected then
mesecon:turnoff(np)
end
i=i+1
@ -220,3 +222,6 @@ print("[MESEcons] Main mod Loaded!")
--The actual wires
dofile(minetest.get_modpath("mesecons").."/wires.lua");
--Services like turnoff receptor on dignode and so on
dofile(minetest.get_modpath("mesecons").."/services.lua");

@ -288,21 +288,27 @@ end
function mesecon:connected_to_pw_src(pos, checked)
if checked == nil then
checked = {}
end
local connected
local i = 1
while checked[i] ~= nil do --find out if node has already been checked
if checked[i].x == pos.x and checked[i].y == pos.y and checked[i].z == pos.z then
return false
return false, checked
end
i = i + 1
end
checked[i] = {x=pos.x, y=pos.y, z=pos.z} --add current node to checked
local node = minetest.env:get_node_or_nil(pos)
if node == nil then return false end
if node == nil then return false, checked end
if mesecon:is_conductor_on(node.name) or mesecon:is_conductor_off(node.name) then
if mesecon:is_powered_from_receptor(pos) then --return if conductor is powered
return true
if mesecon:is_powered_by_receptor(pos) then --return if conductor is powered
return true, checked
end
local rules = mesecon:get_rules("default") --TODO: Use conductor specific rules
@ -312,16 +318,17 @@ function mesecon:connected_to_pw_src(pos, checked)
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
if mesecon:connected_to_pw_src(np, checked) == true then
return true
connected, checked = mesecon:connected_to_pw_src(np, checked)
if connected then
return true
end
i=i+1
end
end
return false
return false, checked
end
function mesecon:is_powered_from_receptor(pos)
function mesecon:is_powered_by_receptor(pos)
local rcpt
local rcpt_pos = {}
local rcpt_checked = {} --using a checked array speeds this up
@ -361,7 +368,7 @@ function mesecon:is_powered_from_receptor(pos)
return false
end
function mesecon:is_powered_from_conductor(pos)
function mesecon:is_powered_by_conductor(pos)
local k=1
rules=mesecon:get_rules("default") --TODO: use conductor specific rules
@ -375,11 +382,11 @@ function mesecon:is_powered_from_conductor(pos)
end
function mesecon:is_powered(pos)
return mesecon:is_powered_from_conductor(pos) or mesecon:is_powered_from_receptor(pos)
return mesecon:is_powered_by_conductor(pos) or mesecon:is_powered_by_receptor(pos)
end
function mesecon:updatenode(pos)
if mesecon:connected_to_pw_src(pos, {}) then
if mesecon:connected_to_pw_src(pos) then
mesecon:turnon(pos)
else
mesecon:turnoff(pos)

12
mesecons/services.lua Normal file

@ -0,0 +1,12 @@
minetest.register_on_dignode(
function(pos, oldnode, digger)
if mesecon:is_conductor_on(oldnode.name) then
local i = 1
mesecon:receptor_off(pos)
end
if mesecon:is_receptor_node(oldnode.name) then
mesecon:receptor_off(pos)
end
end
)

@ -87,8 +87,8 @@ for zmy=0, 1 do
if zpy == 1 then table.insert(nodebox, box_zpy) end
if xmy == 1 then table.insert(nodebox, box_xmy) end
if zmy == 1 then table.insert(nodebox, box_zmy) end
nobump = xp+zp+xm+zm
if adjx and adjz and (nobump > 2) then
if adjx and adjz and (xp + zp + xm + zm > 2) then
table.insert(nodebox, box_bump1)
table.insert(nodebox, box_bump2)
tiles_off = {