forked from minetest-mods/mesecons
Merge branch 'master' of github.com:Jeija/minetest-mod-mesecons
This commit is contained in:
commit
2f5ccf5b4f
@ -98,7 +98,6 @@ dofile(minetest.get_modpath("mesecons").."/settings.lua")
|
|||||||
--Internal API
|
--Internal API
|
||||||
dofile(minetest.get_modpath("mesecons").."/internal_api.lua");
|
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
|
-- 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)
|
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")
|
rules = mesecon:get_rules("default")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local checked = {}
|
||||||
|
local connected = false
|
||||||
local i = 1
|
local i = 1
|
||||||
while rules[i]~=nil do
|
while rules[i]~=nil do
|
||||||
local np = {}
|
local np = {}
|
||||||
np.x = pos.x + rules[i].x
|
np.x = pos.x + rules[i].x
|
||||||
np.y = pos.y + rules[i].y
|
np.y = pos.y + rules[i].y
|
||||||
np.z = pos.z + rules[i].z
|
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)
|
mesecon:turnoff(np)
|
||||||
end
|
end
|
||||||
i=i+1
|
i=i+1
|
||||||
@ -220,3 +222,6 @@ print("[MESEcons] Main mod Loaded!")
|
|||||||
|
|
||||||
--The actual wires
|
--The actual wires
|
||||||
dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
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)
|
function mesecon:connected_to_pw_src(pos, checked)
|
||||||
|
if checked == nil then
|
||||||
|
checked = {}
|
||||||
|
end
|
||||||
|
local connected
|
||||||
local i = 1
|
local i = 1
|
||||||
|
|
||||||
while checked[i] ~= nil do --find out if node has already been checked
|
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
|
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
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
checked[i] = {x=pos.x, y=pos.y, z=pos.z} --add current node to checked
|
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)
|
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_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
|
if mesecon:is_powered_by_receptor(pos) then --return if conductor is powered
|
||||||
return true
|
return true, checked
|
||||||
end
|
end
|
||||||
|
|
||||||
local rules = mesecon:get_rules("default") --TODO: Use conductor specific rules
|
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.x = pos.x + rules[i].x
|
||||||
np.y = pos.y + rules[i].y
|
np.y = pos.y + rules[i].y
|
||||||
np.z = pos.z + rules[i].z
|
np.z = pos.z + rules[i].z
|
||||||
if mesecon:connected_to_pw_src(np, checked) == true then
|
connected, checked = mesecon:connected_to_pw_src(np, checked)
|
||||||
|
if connected then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
i=i+1
|
i=i+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false, checked
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:is_powered_from_receptor(pos)
|
function mesecon:is_powered_by_receptor(pos)
|
||||||
local rcpt
|
local rcpt
|
||||||
local rcpt_pos = {}
|
local rcpt_pos = {}
|
||||||
local rcpt_checked = {} --using a checked array speeds this up
|
local rcpt_checked = {} --using a checked array speeds this up
|
||||||
@ -361,7 +368,7 @@ function mesecon:is_powered_from_receptor(pos)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:is_powered_from_conductor(pos)
|
function mesecon:is_powered_by_conductor(pos)
|
||||||
local k=1
|
local k=1
|
||||||
|
|
||||||
rules=mesecon:get_rules("default") --TODO: use conductor specific rules
|
rules=mesecon:get_rules("default") --TODO: use conductor specific rules
|
||||||
@ -375,11 +382,11 @@ function mesecon:is_powered_from_conductor(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:is_powered(pos)
|
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
|
end
|
||||||
|
|
||||||
function mesecon:updatenode(pos)
|
function mesecon:updatenode(pos)
|
||||||
if mesecon:connected_to_pw_src(pos, {}) then
|
if mesecon:connected_to_pw_src(pos) then
|
||||||
mesecon:turnon(pos)
|
mesecon:turnon(pos)
|
||||||
else
|
else
|
||||||
mesecon:turnoff(pos)
|
mesecon:turnoff(pos)
|
||||||
|
12
mesecons/services.lua
Normal file
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 zpy == 1 then table.insert(nodebox, box_zpy) end
|
||||||
if xmy == 1 then table.insert(nodebox, box_xmy) end
|
if xmy == 1 then table.insert(nodebox, box_xmy) end
|
||||||
if zmy == 1 then table.insert(nodebox, box_zmy) 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_bump1)
|
||||||
table.insert(nodebox, box_bump2)
|
table.insert(nodebox, box_bump2)
|
||||||
tiles_off = {
|
tiles_off = {
|
||||||
|
Loading…
Reference in New Issue
Block a user