Fix mesecon delayer bugs and other non-functional changes

This commit is contained in:
Jeija 2012-08-12 21:28:53 +02:00
parent 3be48e6985
commit 3ea68a6eae
4 changed files with 68 additions and 43 deletions

View File

@ -9,9 +9,11 @@ function mesecon:is_receptor_node(nodename, pos, ownpos) --ownpos must be positi
return true
end
local rules = mesecon.pwr_srcs[i].rules
local get_rules = mesecon.pwr_srcs[i].get_rules
local node = minetest.env:get_node(pos)
if rules==nil then
rules=mesecon.pwr_srcs[i].get_rules(node.param2)
if get_rules~=nil then --get_rules preferred
rules = get_rules(node.param2)
end
j=1
@ -38,9 +40,11 @@ function mesecon:is_receptor_node_off(nodename, pos, ownpos) --ownpos must be po
return true
end
local rules = mesecon.pwr_srcs_off[i].rules
local rules = mesecon.pwr_srcs_off[i].get_rules
local node = minetest.env:get_node(pos)
if rules==nil then
rules=mesecon.pwr_srcs_off[i].get_rules(node.param2)
if get_rules ~= nil then
rules = get_rules(node.param2)
end
j=1
@ -258,16 +262,6 @@ end
function mesecon:turnoff(pos)
local node = minetest.env:get_node(pos)
local connected = 0
if minetest.get_item_group(node.name, "mesecon_effector_on") == 1 then
if not mesecon:check_if_turnon(pos) then --Check if the signal comes from another source
--Send Signals to effectors:
mesecon:deactivate(pos)
end
mesecon:changesignal(pos) --Changesignal is always thrown because nodes can be both receptors and effectors
end
if mesecon:is_conductor_on(node.name) then
minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name)})
@ -284,6 +278,13 @@ function mesecon:turnoff(pos)
i=i+1
end
end
mesecon:changesignal(pos) --Changesignal is always thrown because nodes can be both receptors and effectors
if minetest.get_item_group(node.name, "mesecon_effector_on") == 1 and
not mesecon:check_if_turnon(pos) then --Check if the signal comes from another source
--Send Signals to effectors:
mesecon:deactivate(pos)
end
end
@ -331,6 +332,9 @@ function mesecon:check_if_turnon(pos)
local i=1
local j=1
local k=1
local l=1
local m=1
local n=1
local rcpt
local rcpt_pos={}
local rules
@ -355,6 +359,26 @@ function mesecon:check_if_turnon(pos)
end
i=i+1
end
--[[while mesecon.pwr_srcs[l]~= nil do
if mesecon.pwr_srcs[l].get_rules ~= nil then
rules = mesecon.pwr_srcs[l].get_rules("all")
while rules[m]~=nil do
rcpt_pos = {x = pos.x-rules[j].x, y = pos.y-rules[j].y, z = pos.z-rules[j].z}
rcpt = minetest.env:get_node(rcpt_pos)
if rcpt.name == mesecon.pwr_srcs[l].name then --this name is always the onstate, offstate would be pwr_srcs_off
actual_rules = mesecon.pwr_srcs[l].get_rules(rcpt_pos)
if (actual_rules.x == rules.x and actual_rules.y == rules.y and actual_rules.z == rules.z) then
return true
end
end
m = m + 1
end
end
l = l + 1
end]] --that was rubbish
return false
end
@ -381,7 +405,6 @@ minetest.register_on_dignode(
function(pos, oldnode, digger)
if mesecon:is_conductor_on(oldnode.name) then
local i = 1
mesecon:receptor_off(pos)
end
end

View File

@ -1,9 +1,9 @@
for i = 1, 4 do
local groups = {}
if i == 1 then
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 2}
else
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, not_in_creative_inventory=1, mesecon = 2}
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 2}
end
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
@ -113,13 +113,13 @@ minetest.register_on_punchnode(function (pos, node)
end
end)
mesecon.delayer_signal_change = function(pos, node)
mesecon.delayer_update = function(pos, node)
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
rules = mesecon.delayer_get_input_rules(node.param2)[1]
np = {x = pos.x + rules.x, y = pos.y + rules.y, z = pos.z + rules.z}
local input_rules = mesecon.delayer_get_input_rules(node.param2)[1]
np = {x = pos.x + input_rules.x, y = pos.y + input_rules.y, z = pos.z + input_rules.z}
if mesecon:is_power_on(np) then
local time
local time = 0
if node.name=="mesecons_delayer:delayer_off_1" then
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
time=0.1
@ -137,15 +137,15 @@ mesecon.delayer_signal_change = function(pos, node)
time=1
end
minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2})
end
end
end
end
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
rules = mesecon.delayer_get_input_rules(node.param2)[1]
np = {x = pos.x + rules.x, y = pos.y + rules.y, z = pos.z + rules.z}
local input_rules = mesecon.delayer_get_input_rules(node.param2)[1]
np = {x = pos.x + input_rules.x, y = pos.y + input_rules.y, z = pos.z + input_rules.z}
if not mesecon:is_power_on(np) then
local time
local time = 0
if node.name=="mesecons_delayer:delayer_on_1" then
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
time=0.1
@ -167,7 +167,7 @@ mesecon.delayer_signal_change = function(pos, node)
end
end
mesecon:register_on_signal_change(mesecon.delayer_signal_change)
mesecon:register_on_signal_change(mesecon.delayer_update)
mesecon.delayer_turnon=function(params)
local rules = mesecon.delayer_get_output_rules(params.param2)
@ -180,7 +180,7 @@ mesecon.delayer_turnoff=function(params)
end
mesecon.delayer_get_output_rules = function(param2)
rules = {}
local rules = {}
if param2 == 0 then
table.insert(rules, {x = 1, y = 0, z = 0})
elseif param2 == 2 then
@ -194,7 +194,7 @@ mesecon.delayer_get_output_rules = function(param2)
end
mesecon.delayer_get_input_rules = function(param2)
rules = {}
local rules = {}
if param2 == 0 then
table.insert(rules, {x =-1, y = 0, z = 0})
elseif param2 == 2 then
@ -207,12 +207,14 @@ mesecon.delayer_get_input_rules = function(param2)
return rules
end
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", nil, mesecon.delayer_get_output_rules)
all_rules = {{x = 1, y = 0, z = 0}, {x =-1, y = 0, z = 0}, {x = 0, y = 0, z =-1}, {x = 0, y = 0, z = 1}} --required to check if a newly placed should be turned on
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", nil, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_output_rules)
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_output_rules)

View File

@ -45,7 +45,7 @@ minetest.register_node("mesecons_lamp:lamp_off", {
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon = 2},
groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1, mesecon = 2},
description="Meselamp",
})

View File

@ -6,9 +6,9 @@ for c = 0, 1 do
for d = 0, 1 do
local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a)
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 0, mesecon = 2}
else
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 0, mesecon = 2}
end
minetest.register_node(nodename, {
description = "Microcontroller",