From e0aa5b1d3de31cd8724f680db9bfb9798c89e59e Mon Sep 17 00:00:00 2001 From: Jeija Date: Sat, 8 Dec 2012 14:14:04 +0100 Subject: New branch: Move mesecon to node definition instead of functions like register_conductor; first steps: move everything to legacy --- mesecons/init.lua | 97 +++++---------------------------------------------- mesecons/internal.lua | 94 ++++++++++++++++++++++++++++++++++++++++++------- mesecons/legacy.lua | 80 ++++++++++++++++++++++++++++++++++++++++++ mesecons/presets.lua | 19 ++++++++++ 4 files changed, 189 insertions(+), 101 deletions(-) create mode 100644 mesecons/presets.lua diff --git a/mesecons/init.lua b/mesecons/init.lua index 40aa7d9..d980419 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -3,7 +3,7 @@ -- | \/ | |___ ____ |___ | | | | \ | |____ -- | | | | | | | | | \ | | -- | | |___ ____| |___ |____ |____| | \| ____| --- by Jeija and Minerd247 +-- by Jeija, Uberi (Temperest), sfan5, VanessaE, -- -- -- @@ -21,110 +21,29 @@ mesecon.actions_off={} -- Saves registered function callbacks for mesecon off mesecon.actions_change={} -- Saves registered function callbacks for mesecon change mesecon.receptors={} mesecon.effectors={} -mesecon.rules={} mesecon.conductors={} -- INCLUDE SETTINGS dofile(minetest.get_modpath("mesecons").."/settings.lua") +--Presets (eg default rules) +dofile(minetest.get_modpath("mesecons").."/presets.lua"); + --Internal API dofile(minetest.get_modpath("mesecons").."/internal.lua"); --- API API API API API API API API API API API API API API API API API API - -function mesecon:register_receptor(onstate, offstate, rules, get_rules) - if get_rules == nil and rules == nil then - rules = mesecon:get_rules("default") - end - table.insert(mesecon.receptors, - {onstate = onstate, - offstate = offstate, - rules = rules, - get_rules = get_rules}) -end - -function mesecon:register_effector(onstate, offstate, input_rules, get_input_rules) - if get_input_rules==nil and input_rules==nil then - rules=mesecon:get_rules("default") - end - table.insert(mesecon.effectors, - {onstate = onstate, - offstate = offstate, - input_rules = input_rules, - get_input_rules = get_input_rules}) -end - -function mesecon:receptor_on(pos, rules) - if rules == nil then - rules = mesecon:get_rules("default") - end - - for i, rule in ipairs(rules) do - local np = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z} - if mesecon:rules_link(pos, np, rules) then - mesecon:turnon(np, pos) - end - end -end - -function mesecon:receptor_off(pos, rules) - if rules == nil then - rules = mesecon:get_rules("default") - end - - for i, rule in ipairs(rules) do - local np = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z} - if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then - mesecon:turnoff(np, pos) - end - end -end - -function mesecon:register_on_signal_on(action) - table.insert(mesecon.actions_on, action) -end +--Deprecated stuff +dofile(minetest.get_modpath("mesecons").."/legacy.lua"); -function mesecon:register_on_signal_off(action) - table.insert(mesecon.actions_off, action) -end +-- API API API API API API API API API API API API API API API API API API -function mesecon:register_on_signal_change(action) - table.insert(mesecon.actions_change, action) -end -function mesecon:register_conductor (onstate, offstate, rules, get_rules) - if rules == nil then - rules = mesecon:get_rules("default") - end - table.insert(mesecon.conductors, {onstate = onstate, offstate = offstate, rules = rules, get_rules = get_rules}) -end -mesecon:add_rules("default", -{{x=0, y=0, z=-1}, -{x=1, y=0, z=0}, -{x=-1, y=0, z=0}, -{x=0, y=0, z=1}, -{x=1, y=1, z=0}, -{x=1, y=-1, z=0}, -{x=-1, y=1, z=0}, -{x=-1, y=-1, z=0}, -{x=0, y=1, z=1}, -{x=0, y=-1, z=1}, -{x=0, y=1, z=-1}, -{x=0, y=-1, z=-1}}) -print("[MESEcons] Main mod Loaded!") +print("[OK] mesecons") --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"); ---Deprecated stuff -dofile(minetest.get_modpath("mesecons").."/legacy.lua"); diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 7a576d6..8c4ccaf 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -2,6 +2,11 @@ --Receptors function mesecon:is_receptor_node(nodename) + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.receptor + and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then + return true + end for _, receptor in ipairs(mesecon.receptors) do if receptor.onstate == nodename then return true @@ -11,6 +16,11 @@ function mesecon:is_receptor_node(nodename) end function mesecon:is_receptor_node_off(nodename, pos, ownpos) + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.receptor + and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.off then + return true + end for _, receptor in ipairs(mesecon.receptors) do if receptor.offstate == nodename then return true @@ -20,7 +30,16 @@ function mesecon:is_receptor_node_off(nodename, pos, ownpos) end function mesecon:receptor_get_rules(node) - for i, receptor in ipairs(mesecon.receptors) do + if minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.receptor then + local rules = minetest.registered_nodes[node.name].mesecons.receptor.rules + if type(rules) == 'function' then + return rules(node) + else + return rules + end + end + for i, receptor in ipairs(mesecon.receptors) do --TODO if receptor.onstate == node.name or receptor.offstate == node.name then if receptor.get_rules ~= nil then return receptor.get_rules(node.param2) @@ -36,28 +55,51 @@ end -- Effectors function mesecon:is_effector_on(nodename) - for i, effector in ipairs(mesecon.effectors) do + for i, effector in ipairs(mesecon.effectors) do --TODO if effector.onstate == nodename then return true end end + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.effector + and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.on then + return true + end return false end function mesecon:is_effector_off(nodename) - for i, effector in ipairs(mesecon.effectors) do + for i, effector in ipairs(mesecon.effectors) do --TODO if effector.offstate == nodename then return true end end + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.effector + and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.off then + return true + end return false end function mesecon:is_effector(nodename) - return mesecon:is_effector_on(nodename) or mesecon:is_effector_off(nodename) + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.effector then + return true + end + return mesecon:is_effector_on(nodename) or mesecon:is_effector_off(nodename) --TODO end function mesecon:effector_get_input_rules(node) + if minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.effector then + local rules = minetest.registered_nodes[node.name].mesecons.effector.rules + if type(rules) == 'function' then + return rules(node) + else + return rules + end + end for i, effector in ipairs(mesecon.effectors) do if effector.onstate == node.name or effector.offstate == node.name then @@ -74,21 +116,21 @@ end --Signals -function mesecon:activate(pos) +function mesecon:activate(pos) --TODO local node = minetest.env:get_node(pos) for i, action in ipairs(mesecon.actions_on) do action(pos, node) end end -function mesecon:deactivate(pos) +function mesecon:deactivate(pos) --TODO local node = minetest.env:get_node(pos) for i, action in ipairs(mesecon.actions_off) do action(pos, node) end end -function mesecon:changesignal(pos) +function mesecon:changesignal(pos) --TODO local node = minetest.env:get_node(pos) for i, action in ipairs(mesecon.actions_change) do action(pos, node) @@ -112,7 +154,11 @@ end --Conductor system stuff function mesecon:get_conductor_on(offstate) - for i, conductor in ipairs(mesecon.conductors) do + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.condcutor then + return minetest.registered_nodes[nodename].mesecons.conductor.onstate + end + for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.offstate == offstate then return conductor.onstate end @@ -121,7 +167,11 @@ function mesecon:get_conductor_on(offstate) end function mesecon:get_conductor_off(onstate) - for i, conductor in ipairs(mesecon.conductors) do + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.condcutor then + return minetest.registered_nodes[nodename].mesecons.conductor.offstate + end + for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.onstate == onstate then return conductor.offstate end @@ -130,7 +180,12 @@ function mesecon:get_conductor_off(onstate) end function mesecon:is_conductor_on(name) - for i, conductor in ipairs(mesecon.conductors) do + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.condcutor + and minetest.registered_nodes[nodename].mesecons.condcutor.state == mesecon.state.on then + return true + end + for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.onstate == name then return true end @@ -139,7 +194,12 @@ function mesecon:is_conductor_on(name) end function mesecon:is_conductor_off(name) - for i, conductor in ipairs(mesecon.conductors) do + if minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.condcutor + and minetest.registered_nodes[nodename].mesecons.condcutor.state == mesecon.state.off then + return true + end + for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.offstate == name then return true end @@ -148,11 +208,21 @@ function mesecon:is_conductor_off(name) end function mesecon:is_conductor(name) + --TODO: simplify return mesecon:is_conductor_on(name) or mesecon:is_conductor_off(name) end function mesecon:conductor_get_rules(node) - for i, conductor in ipairs(mesecon.conductors) do + if minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.condcutor then + local rules = minetest.registered_nodes[node.name].mesecons.condcutor.rules + if type(rules) == 'function' then + return rules(node) + else + return rules + end + end + for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.onstate == node.name or conductor.offstate == node.name then if conductor.get_rules ~= nil then diff --git a/mesecons/legacy.lua b/mesecons/legacy.lua index 4fd73dd..271221a 100644 --- a/mesecons/legacy.lua +++ b/mesecons/legacy.lua @@ -1,3 +1,5 @@ +--very old: + function mesecon:add_receptor_node(name, rules, get_rules) if get_rules==nil and rules==nil then rules=mesecon:get_rules("default") @@ -11,3 +13,81 @@ function mesecon:add_receptor_node_off(name, rules, get_rules) end table.insert(mesecon.receptors, {offstate = name, rules = rules, get_rules = get_rules}) end + +--old: + +function mesecon:register_receptor(onstate, offstate, rules, get_rules) + if get_rules == nil and rules == nil then + rules = mesecon:get_rules("default") + end + + table.insert(mesecon.receptors, + {onstate = onstate, + offstate = offstate, + rules = rules, + get_rules = get_rules}) +end + +function mesecon:register_effector(onstate, offstate, input_rules, get_input_rules) + if get_input_rules==nil and input_rules==nil then + rules=mesecon:get_rules("default") + end + table.insert(mesecon.effectors, + {onstate = onstate, + offstate = offstate, + input_rules = input_rules, + get_input_rules = get_input_rules}) +end + +function mesecon:receptor_on(pos, rules) + if rules == nil then + rules = mesecon:get_rules("default") + end + + for i, rule in ipairs(rules) do + local np = { + x = pos.x + rule.x, + y = pos.y + rule.y, + z = pos.z + rule.z} + if mesecon:rules_link(pos, np, rules) then + mesecon:turnon(np, pos) + end + end +end + +function mesecon:receptor_off(pos, rules) + if rules == nil then + rules = mesecon:get_rules("default") + end + + for i, rule in ipairs(rules) do + local np = { + x = pos.x + rule.x, + y = pos.y + rule.y, + z = pos.z + rule.z} + if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then + mesecon:turnoff(np, pos) + end + end +end + +function mesecon:register_on_signal_on(action) + table.insert(mesecon.actions_on, action) +end + +function mesecon:register_on_signal_off(action) + table.insert(mesecon.actions_off, action) +end + +function mesecon:register_on_signal_change(action) + table.insert(mesecon.actions_change, action) +end + +function mesecon:register_conductor (onstate, offstate, rules, get_rules) + if rules == nil then + rules = mesecon:get_rules("default") + end + table.insert(mesecon.conductors, {onstate = onstate, offstate = offstate, rules = rules, get_rules = get_rules}) +end + +mesecon:add_rules("default", mesecon.rules.default) diff --git a/mesecons/presets.lua b/mesecons/presets.lua new file mode 100644 index 0000000..450f039 --- /dev/null +++ b/mesecons/presets.lua @@ -0,0 +1,19 @@ +mesecon.rules={} +mesecon.state = {} + +mesecon.rules.default = +{{x=0, y=0, z=-1}, +{x=1, y=0, z=0}, +{x=-1, y=0, z=0}, +{x=0, y=0, z=1}, +{x=1, y=1, z=0}, +{x=1, y=-1, z=0}, +{x=-1, y=1, z=0}, +{x=-1, y=-1, z=0}, +{x=0, y=1, z=1}, +{x=0, y=-1, z=1}, +{x=0, y=1, z=-1}, +{x=0, y=-1, z=-1}} + +mesecon.state.on = "on" +mesecon.state.off = "off" -- cgit v1.2.3 From 472650f099deda6a3f1ab0900c7319a78b352d68 Mon Sep 17 00:00:00 2001 From: Jeija Date: Sat, 8 Dec 2012 17:50:25 +0100 Subject: Finish new mesecon-in-nodedef for conductors and receptors. Make wires and switch use it for reference. --- mesecons/internal.lua | 101 +++++++++++++++++++++++++++-------------------- mesecons/legacy.lua | 5 +-- mesecons/wires.lua | 75 +++++++++++++---------------------- mesecons_button/init.lua | 2 +- mesecons_switch/init.lua | 32 +++++++-------- 5 files changed, 103 insertions(+), 112 deletions(-) diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 8c4ccaf..c4bef7c 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -2,7 +2,8 @@ --Receptors function mesecon:is_receptor_node(nodename) - if minetest.registered_nodes[nodename].mesecons + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.receptor and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then return true @@ -16,7 +17,8 @@ function mesecon:is_receptor_node(nodename) end function mesecon:is_receptor_node_off(nodename, pos, ownpos) - if minetest.registered_nodes[nodename].mesecons + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.receptor and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.off then return true @@ -33,7 +35,9 @@ function mesecon:receptor_get_rules(node) if minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.receptor then local rules = minetest.registered_nodes[node.name].mesecons.receptor.rules - if type(rules) == 'function' then + if not rules then + return mesecon.rules.default + elseif type(rules) == 'function' then return rules(node) else return rules @@ -60,7 +64,8 @@ function mesecon:is_effector_on(nodename) return true end end - if minetest.registered_nodes[nodename].mesecons + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.on then return true @@ -74,7 +79,8 @@ function mesecon:is_effector_off(nodename) return true end end - if minetest.registered_nodes[nodename].mesecons + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.off then return true @@ -83,7 +89,8 @@ function mesecon:is_effector_off(nodename) end function mesecon:is_effector(nodename) - if minetest.registered_nodes[nodename].mesecons + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector then return true end @@ -94,7 +101,9 @@ function mesecon:effector_get_input_rules(node) if minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.effector then local rules = minetest.registered_nodes[node.name].mesecons.effector.rules - if type(rules) == 'function' then + if not rules then + return mesecon.rules.default + elseif type(rules) == 'function' then return rules(node) else return rules @@ -117,7 +126,7 @@ end --Signals function mesecon:activate(pos) --TODO - local node = minetest.env:get_node(pos) + local node = minetest.env:get_node(pos) for i, action in ipairs(mesecon.actions_on) do action(pos, node) end @@ -154,9 +163,10 @@ end --Conductor system stuff function mesecon:get_conductor_on(offstate) - if minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.condcutor then - return minetest.registered_nodes[nodename].mesecons.conductor.onstate + if minetest.registered_nodes[offstate] + and minetest.registered_nodes[offstate].mesecons + and minetest.registered_nodes[offstate].mesecons.conductor then + return minetest.registered_nodes[offstate].mesecons.conductor.onstate end for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.offstate == offstate then @@ -167,9 +177,10 @@ function mesecon:get_conductor_on(offstate) end function mesecon:get_conductor_off(onstate) - if minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.condcutor then - return minetest.registered_nodes[nodename].mesecons.conductor.offstate + if minetest.registered_nodes[onstate] + and minetest.registered_nodes[onstate].mesecons + and minetest.registered_nodes[onstate].mesecons.conductor then + return minetest.registered_nodes[onstate].mesecons.conductor.offstate end for i, conductor in ipairs(mesecon.conductors) do --TODO if conductor.onstate == onstate then @@ -179,44 +190,49 @@ function mesecon:get_conductor_off(onstate) return false end -function mesecon:is_conductor_on(name) - if minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.condcutor - and minetest.registered_nodes[nodename].mesecons.condcutor.state == mesecon.state.on then +function mesecon:is_conductor_on(nodename) + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.conductor + and minetest.registered_nodes[nodename].mesecons.conductor.state == mesecon.state.on then return true end - for i, conductor in ipairs(mesecon.conductors) do --TODO - if conductor.onstate == name then + for _, conductor in ipairs(mesecon.conductors) do --TODO + if conductor.onstate == nodename then return true end end return false end -function mesecon:is_conductor_off(name) - if minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.condcutor - and minetest.registered_nodes[nodename].mesecons.condcutor.state == mesecon.state.off then +function mesecon:is_conductor_off(nodename) + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.conductor + and minetest.registered_nodes[nodename].mesecons.conductor.state == mesecon.state.off then return true end - for i, conductor in ipairs(mesecon.conductors) do --TODO - if conductor.offstate == name then + for _, conductor in ipairs(mesecon.conductors) do --TODO + if conductor.offstate == nodename then return true end end return false end -function mesecon:is_conductor(name) +function mesecon:is_conductor(nodename) --TODO: simplify - return mesecon:is_conductor_on(name) or mesecon:is_conductor_off(name) + return mesecon:is_conductor_on(nodename) or mesecon:is_conductor_off(nodename) end function mesecon:conductor_get_rules(node) - if minetest.registered_nodes[node.name].mesecons - and minetest.registered_nodes[node.name].mesecons.condcutor then - local rules = minetest.registered_nodes[node.name].mesecons.condcutor.rules - if type(rules) == 'function' then + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.conductor then + local rules = minetest.registered_nodes[node.name].mesecons.conductor.rules + if not rules then + return mesecon.rules.default + elseif type(rules) == 'function' then return rules(node) else return rules @@ -272,17 +288,17 @@ function mesecon:turnon(pos) if mesecon:is_effector(node.name) then mesecon:changesignal(pos) - if mesecon:is_effector_off(node.name) then mesecon:activate(pos) end + if mesecon:is_effector_off(node.name) then + mesecon:activate(pos) + end end end function mesecon:turnoff(pos) --receptor rules used because output could have been dug local node = minetest.env:get_node(pos) - local rules if mesecon:is_conductor_on(node.name) then - rules = mesecon:conductor_get_rules(node) - + local rules = mesecon:conductor_get_rules(node) minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name), param2 = node.param2}) for i, rule in ipairs(rules) do @@ -299,7 +315,10 @@ function mesecon:turnoff(pos) --receptor rules used because output could have be if mesecon:is_effector(node.name) then mesecon:changesignal(pos) - if mesecon:is_effector_on(node.name) and not mesecon:is_powered(pos) then mesecon:deactivate(pos) end + if mesecon:is_effector_on(node.name) + and not mesecon:is_powered(pos) then + mesecon:deactivate(pos) + end end end @@ -347,9 +366,6 @@ function mesecon:connected_to_pw_src(pos, checked) end function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug) - local k = 1 - local l = 1 - local outputnode = minetest.env:get_node(output) local inputnode = minetest.env:get_node(input) @@ -375,12 +391,11 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p end - for k, outputrule in ipairs(outputrules) do + for _, outputrule in ipairs(outputrules) do if outputrule.x + output.x == input.x and outputrule.y + output.y == input.y and outputrule.z + output.z == input.z then -- Check if output sends to input - l = 1 - for k, inputrule in ipairs(inputrules) do + for _, inputrule in ipairs(inputrules) do if inputrule.x + input.x == output.x and inputrule.y + input.y == output.y and inputrule.z + input.z == output.z then --Check if input accepts from output diff --git a/mesecons/legacy.lua b/mesecons/legacy.lua index 271221a..3f87b1b 100644 --- a/mesecons/legacy.lua +++ b/mesecons/legacy.lua @@ -18,13 +18,12 @@ end function mesecon:register_receptor(onstate, offstate, rules, get_rules) if get_rules == nil and rules == nil then - rules = mesecon:get_rules("default") + rules=mesecon:get_rules("default") end - table.insert(mesecon.receptors, {onstate = onstate, offstate = offstate, - rules = rules, + rules = input_rules, get_rules = get_rules}) end diff --git a/mesecons/wires.lua b/mesecons/wires.lua index bda872f..d6d92e2 100644 --- a/mesecons/wires.lua +++ b/mesecons/wires.lua @@ -69,10 +69,10 @@ for zmy=0, 1 do tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy) if nodeid == "00000000" then - groups = {dig_immediate = 3, mesecon = 2, mesecon_conductor_craftable=1} + groups = {dig_immediate = 3, mesecon_conductor_craftable=1} wiredesc = "Mesecon" else - groups = {dig_immediate = 3, mesecon = 2, not_in_creative_inventory = 1} + groups = {dig_immediate = 3, not_in_creative_inventory = 1} wiredesc = "Mesecons Wire (ID: "..nodeid..")" end @@ -153,7 +153,11 @@ for zmy=0, 1 do groups = groups, walkable = false, stack_max = 99, - drop = "mesecons:wire_00000000_off" + drop = "mesecons:wire_00000000_off", + mesecons = {conductor={ + state = mesecon.state.off, + onstate = "mesecons:wire_"..nodeid.."_on" + }} }) minetest.register_node("mesecons:wire_"..nodeid.."_on", { @@ -174,9 +178,12 @@ for zmy=0, 1 do groups = {dig_immediate = 3, mesecon = 2, not_in_creative_inventory = 1}, walkable = false, stack_max = 99, - drop = "mesecons:wire_00000000_off" + drop = "mesecons:wire_00000000_off", + mesecons = {conductor={ + state = mesecon.state.on, + offstate = "mesecons:wire_"..nodeid.."_off" + }} }) - mesecon:register_conductor("mesecons:wire_"..nodeid.."_on", "mesecons:wire_"..nodeid.."_off") end end end @@ -187,13 +194,13 @@ end end minetest.register_on_placenode(function(pos, node) - if minetest.get_item_group(node.name, "mesecon") > 1 then + if minetest.registered_nodes[node.name].mesecons then mesecon:update_autoconnect(pos) end end) minetest.register_on_dignode(function(pos, node) - if minetest.get_item_group(node.name, "mesecon") > 1 then + if minetest.registered_nodes[node.name].mesecons then mesecon:update_autoconnect(pos) end end) @@ -234,48 +241,20 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old) nodename = minetest.env:get_node(pos).name if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end + if mesecon:rules_link_bothdir(pos, xppos) then xp = 1 else xp = 0 end + if mesecon:rules_link_bothdir(pos, xmpos) then xm = 1 else xm = 0 end + if mesecon:rules_link_bothdir(pos, zppos) then zp = 1 else zp = 0 end + if mesecon:rules_link_bothdir(pos, zmpos) then zm = 1 else zm = 0 end - --if the groups mesecon == 1 then wires won't connect to it - local zmg = minetest.get_item_group(minetest.env:get_node(zmpos ).name, "mesecon") - local zmymg = minetest.get_item_group(minetest.env:get_node(zmympos).name, "mesecon") - local xmg = minetest.get_item_group(minetest.env:get_node(xmpos ).name, "mesecon") - local xmymg = minetest.get_item_group(minetest.env:get_node(xmympos).name, "mesecon") - local zpg = minetest.get_item_group(minetest.env:get_node(zppos ).name, "mesecon") - local zpymg = minetest.get_item_group(minetest.env:get_node(zpympos).name, "mesecon") - local xpg = minetest.get_item_group(minetest.env:get_node(xppos ).name, "mesecon") - local xpymg = minetest.get_item_group(minetest.env:get_node(xpympos).name, "mesecon") - - - local xpyg = minetest.get_item_group(minetest.env:get_node(xpypos).name, "mesecon") - local zpyg = minetest.get_item_group(minetest.env:get_node(zpypos).name, "mesecon") - local xmyg = minetest.get_item_group(minetest.env:get_node(xmypos).name, "mesecon") - local zmyg = minetest.get_item_group(minetest.env:get_node(zmypos).name, "mesecon") - - if ((zmg == 2) or (zmymg == 2)) == true then zm = 1 else zm = 0 end - if ((xmg == 2) or (xmymg == 2)) == true then xm = 1 else xm = 0 end - if ((zpg == 2) or (zpymg == 2)) == true then zp = 1 else zp = 0 end - if ((xpg == 2) or (xpymg == 2)) == true then xp = 1 else xp = 0 end - - if xpyg == 2 then xpy = 1 else xpy = 0 end - if zpyg == 2 then zpy = 1 else zpy = 0 end - if xmyg == 2 then xmy = 1 else xmy = 0 end - if zmyg == 2 then zmy = 1 else zmy = 0 end - - -- If group == 3 then the mesecon only connects to input and output ports - if xpg == 3 and mesecon:rules_link_bothdir(pos, xppos) then xp = 1 end - if xmg == 3 and mesecon:rules_link_bothdir(pos, xmpos) then xm = 1 end - if zpg == 3 and mesecon:rules_link_bothdir(pos, zppos) then zp = 1 end - if zmg == 3 and mesecon:rules_link_bothdir(pos, zmpos) then zm = 1 end - - if xpymg == 3 and mesecon:rules_link_bothdir(pos, xpympos) then xp = 1 end - if xmymg == 3 and mesecon:rules_link_bothdir(pos, xmympos) then xm = 1 end - if zpymg == 3 and mesecon:rules_link_bothdir(pos, zpympos) then zp = 1 end - if zmymg == 3 and mesecon:rules_link_bothdir(pos, zmympos) then zm = 1 end - - if xpyg == 3 then if mesecon:rules_link(pos, xpypos) then xpy = 1 end end - if zpyg == 3 then if mesecon:rules_link(pos, zpypos) then zpy = 1 end end - if xmyg == 3 then if mesecon:rules_link(pos, xmypos) then xmy = 1 end end - if zmyg == 3 then if mesecon:rules_link(pos, zmypos) then zmy = 1 end end + if mesecon:rules_link_bothdir(pos, xpympos) then xp = 1 end + if mesecon:rules_link_bothdir(pos, xmympos) then xm = 1 end + if mesecon:rules_link_bothdir(pos, zpympos) then zp = 1 end + if mesecon:rules_link_bothdir(pos, zmympos) then zm = 1 end + + if mesecon:rules_link(pos, xpypos) then xpy = 1 else xpy = 0 end + if mesecon:rules_link(pos, zpypos) then zpy = 1 else zpy = 0 end + if mesecon:rules_link(pos, xmypos) then xmy = 1 else xmy = 0 end + if mesecon:rules_link(pos, zmypos) then zmy = 1 else zmy = 0 end -- Backward compatibility if replace_old then diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua index dd8819d..25251c6 100644 --- a/mesecons_button/init.lua +++ b/mesecons_button/init.lua @@ -28,6 +28,7 @@ minetest.register_node("mesecons_button:button_off", { groups = {dig_immediate=2, mesecon = 3, mesecon_needs_receiver = 1}, description = "Button", }) + minetest.register_node("mesecons_button:button_on", { drawtype = "nodebox", tiles = { @@ -108,4 +109,3 @@ mesecon:add_rules("button", { mesecon:add_receptor_node_off("mesecons_button:button_off", nil, mesecon.button_get_rules) mesecon:add_receptor_node("mesecons_button:button_on", nil, mesecon.button_get_rules) - diff --git a/mesecons_switch/init.lua b/mesecons_switch/init.lua index a8b3415..2af5101 100644 --- a/mesecons_switch/init.lua +++ b/mesecons_switch/init.lua @@ -3,32 +3,30 @@ minetest.register_node("mesecons_switch:mesecon_switch_off", { tiles = {"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_off.png"}, paramtype2="facedir", - groups = {dig_immediate=2, mesecon = 2}, - description="Switch", + groups = {dig_immediate=2}, + description="Switch", + mesecons = {receptor = { + state = mesecon.state.off + }}, + on_punch = function(pos, node) + minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2}) + mesecon:receptor_on(pos) + end }) minetest.register_node("mesecons_switch:mesecon_switch_on", { tiles = {"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_on.png"}, paramtype2="facedir", - groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2}, + groups = {dig_immediate=2,not_in_creative_inventory=1}, drop='"mesecons_switch:mesecon_switch_off" 1', - description="Switch", -}) - -mesecon:register_receptor("mesecons_switch:mesecon_switch_on", "mesecons_switch:mesecon_switch_off") - -minetest.register_on_punchnode(function(pos, node, puncher) - if node.name == "mesecons_switch:mesecon_switch_on" then + mesecons = {receptor = { + state = mesecon.state.on + }}, + on_punch = function(pos, node) minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2}) - nodeupdate(pos) mesecon:receptor_off(pos) end - if node.name == "mesecons_switch:mesecon_switch_off" then - minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2}) - nodeupdate(pos) - mesecon:receptor_on(pos) - end -end) +}) minetest.register_craft({ output = '"mesecons_switch:mesecon_switch_off" 2', -- cgit v1.2.3 From 8578fd89c859162bda64af48826b7c1ae1c9e744 Mon Sep 17 00:00:00 2001 From: Jeija Date: Sat, 8 Dec 2012 19:02:34 +0100 Subject: Port lightstones (as reference for effectors) + blinky plant to the new nodedef system --- mesecons/internal.lua | 58 ++++++++++++++++++++++++++++--------------- mesecons_blinkyplant/init.lua | 6 +++++ mesecons_lightstone/init.lua | 51 ++++++++++++++++++------------------- 3 files changed, 70 insertions(+), 45 deletions(-) diff --git a/mesecons/internal.lua b/mesecons/internal.lua index c4bef7c..ce72d38 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -2,7 +2,7 @@ --Receptors function mesecon:is_receptor_node(nodename) - if minetest.registered_nodes[nodename] + if minetest.registered_nodes[nodename] and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.receptor and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then @@ -43,7 +43,7 @@ function mesecon:receptor_get_rules(node) return rules end end - for i, receptor in ipairs(mesecon.receptors) do --TODO + for _, receptor in ipairs(mesecon.receptors) do --TODO if receptor.onstate == node.name or receptor.offstate == node.name then if receptor.get_rules ~= nil then return receptor.get_rules(node.param2) @@ -59,38 +59,38 @@ end -- Effectors function mesecon:is_effector_on(nodename) - for i, effector in ipairs(mesecon.effectors) do --TODO - if effector.onstate == nodename then - return true - end - end if minetest.registered_nodes[nodename] and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.on then return true end - return false -end - -function mesecon:is_effector_off(nodename) for i, effector in ipairs(mesecon.effectors) do --TODO - if effector.offstate == nodename then + if effector.onstate == nodename then return true end end + return false +end + +function mesecon:is_effector_off(nodename) if minetest.registered_nodes[nodename] and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.off then return true end + for i, effector in ipairs(mesecon.effectors) do --TODO + if effector.offstate == nodename then + return true + end + end return false end function mesecon:is_effector(nodename) - if minetest.registered_nodes[nodename] - and minetest.registered_nodes[nodename].mesecons + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector then return true end @@ -125,22 +125,40 @@ end --Signals -function mesecon:activate(pos) --TODO +function mesecon:activate(pos) local node = minetest.env:get_node(pos) - for i, action in ipairs(mesecon.actions_on) do + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.effector + and minetest.registered_nodes[node.name].mesecons.effector.action_on then + minetest.registered_nodes[node.name].mesecons.effector.action_on (pos, node) + end + for _, action in ipairs(mesecon.actions_on) do --TODO action(pos, node) end end function mesecon:deactivate(pos) --TODO - local node = minetest.env:get_node(pos) - for i, action in ipairs(mesecon.actions_off) do + local node = minetest.env:get_node(pos) + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.effector + and minetest.registered_nodes[node.name].mesecons.effector.action_off then + minetest.registered_nodes[node.name].mesecons.effector.action_off(pos, node) + end + for _, action in ipairs(mesecon.actions_off) do action(pos, node) end end function mesecon:changesignal(pos) --TODO - local node = minetest.env:get_node(pos) + local node = minetest.env:get_node(pos) + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.effector + and minetest.registered_nodes[nodename].mesecons.effector.action_change then + minetest.registered_nodes[nodename].mesecons.action_change(pos, node) + end for i, action in ipairs(mesecon.actions_change) do action(pos, node) end @@ -221,7 +239,7 @@ function mesecon:is_conductor_off(nodename) end function mesecon:is_conductor(nodename) - --TODO: simplify + --TODO return mesecon:is_conductor_on(nodename) or mesecon:is_conductor_off(nodename) end diff --git a/mesecons_blinkyplant/init.lua b/mesecons_blinkyplant/init.lua index 145467e..9571359 100644 --- a/mesecons_blinkyplant/init.lua +++ b/mesecons_blinkyplant/init.lua @@ -13,6 +13,9 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_off", { type = "fixed", fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, }, + mesecons = {receptor = { + state = mesecon.state.off + }} }) minetest.register_node("mesecons_blinkyplant:blinky_plant_on", { @@ -30,6 +33,9 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", { type = "fixed", fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, }, + mesecons = {receptor = { + state = mesecon.state.on + }} }) minetest.register_craft({ diff --git a/mesecons_lightstone/init.lua b/mesecons_lightstone/init.lua index fd8b5bf..9edd99d 100644 --- a/mesecons_lightstone/init.lua +++ b/mesecons_lightstone/init.lua @@ -1,30 +1,32 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) - minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", { - tiles = {texture_off}, - inventory_image = minetest.inventorycube(texture_off), - groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2}, - description=name.." Lightstone", + minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", { + tiles = {texture_off}, + inventory_image = minetest.inventorycube(texture_off), + groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2}, + description=name.." Lightstone", + mesecons = {effector = { + state = mesecon.state.off, + action_on = function (pos, node) + minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_on"}) + mesecon:receptor_on(pos) + end + }} }) - minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", { - tiles = {texture_on}, - inventory_image = minetest.inventorycube(texture_on), - groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2}, - drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", - light_source = LIGHT_MAX-2, - description=name.." Lightstone", + minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", { + tiles = {texture_on}, + inventory_image = minetest.inventorycube(texture_on), + groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2}, + drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", + light_source = LIGHT_MAX-2, + mesecons = {effector = { + state = mesecon.state.on, + action_off = function (pos, node) + minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_off"}) + mesecon:receptor_off(pos) + end + }} }) - assert(loadstring('mesecon:register_on_signal_on(function(pos, node) \n \ - if node.name == "mesecons_lightstone:lightstone_' .. name .. '_off" then \n \ - minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_' .. name .. '_on"}) \n \ - nodeupdate(pos) \n \ - end \n \ - end)'))() - assert(loadstring('mesecon:register_on_signal_off(function(pos, node) \n \ - if node.name == "mesecons_lightstone:lightstone_' .. name .. '_on" then \n \ - minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_' .. name .. '_off"}) \n \ - nodeupdate(pos) \n \ - end \n \ - end)'))() + minetest.register_craft({ output = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", recipe = { @@ -33,7 +35,6 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) {'','group:mesecon_conductor_craftable',''}, } }) - mesecon:register_effector("mesecons_lightstone:lightstone_" .. name .. "_on", "mesecons_lightstone:lightstone_" .. name .. "_off") end -- cgit v1.2.3 From 00e071b695574928fce2ca56e3e8eca6ad3d35ef Mon Sep 17 00:00:00 2001 From: Jeija Date: Sat, 8 Dec 2012 21:56:09 +0100 Subject: Cleanup, make and use util.lua, port command block and delayer to nodedef --- mesecons/init.lua | 94 ++++++++++++--- mesecons/internal.lua | 107 +++++++--------- mesecons/legacy.lua | 32 ----- mesecons/presets.lua | 10 +- mesecons/util.lua | 15 +++ mesecons_button/init.lua | 99 ++++++++------- mesecons_commandblock/init.lua | 82 ++++++------- mesecons_delayer/init.lua | 268 ++++++++++++++++++++--------------------- mesecons_lightstone/init.lua | 2 - mesecons_switch/init.lua | 4 +- 10 files changed, 363 insertions(+), 350 deletions(-) create mode 100644 mesecons/util.lua diff --git a/mesecons/init.lua b/mesecons/init.lua index d980419..aa3f001 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -3,41 +3,105 @@ -- | \/ | |___ ____ |___ | | | | \ | |____ -- | | | | | | | | | \ | | -- | | |___ ____| |___ |____ |____| | \| ____| --- by Jeija, Uberi (Temperest), sfan5, VanessaE, +-- by Jeija, Uberi (Temperest), sfan5, VanessaE -- -- -- -- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest. --- -- See the documentation on the forum for additional information, especially about crafting -- --- For developer documentation see the Developers' section on mesecons.tk +-- +-- For developer documentation see the Developers' section on mesecons.TK +-- +-- +-- +--Quick draft for the mesecons array in the node's definition +--mesecons = +--{ +-- receptor = +-- { +-- state = mesecon.state.on/off +-- rules = rules/get_rules +-- } +-- effector = +-- { +-- action_on = function +-- action_off = function +-- action_change = function +-- rules = rules/get_rules +-- } +-- conductor = +-- { +-- state = mesecon.state.on/off +-- offstate = opposite state (for state = on only) +-- onstate = opposite state (for state = off only) +-- rules = rules/get_rules +-- } +--} -- PUBLIC VARIABLES mesecon={} -- contains all functions and all global variables -mesecon.actions_on={} -- Saves registered function callbacks for mesecon on -mesecon.actions_off={} -- Saves registered function callbacks for mesecon off -mesecon.actions_change={} -- Saves registered function callbacks for mesecon change -mesecon.receptors={} -mesecon.effectors={} -mesecon.conductors={} - --- INCLUDE SETTINGS +mesecon.actions_on={} -- Saves registered function callbacks for mesecon on | DEPRECATED +mesecon.actions_off={} -- Saves registered function callbacks for mesecon off | DEPRECATED +mesecon.actions_change={} -- Saves registered function callbacks for mesecon change | DEPRECATED +mesecon.receptors={} -- saves all information about receptors | DEPRECATED +mesecon.effectors={} -- saves all information about effectors | DEPRECATED +mesecon.conductors={} -- saves all information about conductors | DEPRECATED + +-- Settings dofile(minetest.get_modpath("mesecons").."/settings.lua") ---Presets (eg default rules) +-- Presets (eg default rules) dofile(minetest.get_modpath("mesecons").."/presets.lua"); ---Internal API + +-- Utilities like comparing positions, +-- adding positions and rules, +-- mostly things that make the source look cleaner +dofile(minetest.get_modpath("mesecons").."/util.lua"); + +-- Internal stuff +-- This is the most important file +-- it handles signal transmission and basically everything else +-- It is also responsible for managing the nodedef things, +-- like calling action_on/off/change dofile(minetest.get_modpath("mesecons").."/internal.lua"); ---Deprecated stuff +-- Deprecated stuff +-- To be removed in future releases dofile(minetest.get_modpath("mesecons").."/legacy.lua"); --- API API API API API API API API API API API API API API API API API API +-- API +-- these are the only functions you need to remember + +function mesecon:receptor_on(pos, rules) + rules = rules or mesecon.rules.default + + for _, rule in ipairs(rules) do + local np = { + x = pos.x + rule.x, + y = pos.y + rule.y, + z = pos.z + rule.z} + if mesecon:rules_link(pos, np, rules) then + mesecon:turnon(np, pos) + end + end +end +function mesecon:receptor_off(pos, rules) + rules = rules or mesecon.rules.default + for _, rule in ipairs(rules) do + local np = { + x = pos.x + rule.x, + y = pos.y + rule.y, + z = pos.z + rule.z} + if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then + mesecon:turnoff(np, pos) + end + end +end print("[OK] mesecons") diff --git a/mesecons/internal.lua b/mesecons/internal.lua index ce72d38..d438a53 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -1,6 +1,7 @@ -- INTERNAL ---Receptors +-- Receptors +-- Nodes that can power mesecons function mesecon:is_receptor_node(nodename) if minetest.registered_nodes[nodename] and minetest.registered_nodes[nodename].mesecons @@ -35,11 +36,9 @@ function mesecon:receptor_get_rules(node) if minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.receptor then local rules = minetest.registered_nodes[node.name].mesecons.receptor.rules - if not rules then - return mesecon.rules.default - elseif type(rules) == 'function' then + if type(rules) == 'function' then return rules(node) - else + elseif rules then return rules end end @@ -54,18 +53,20 @@ function mesecon:receptor_get_rules(node) end end end - return nil + return mesecon.rules.default end -- Effectors +-- Nodes that can be powered by mesecons function mesecon:is_effector_on(nodename) - if minetest.registered_nodes[nodename] - and minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.effector - and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.on then + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.effector + and (minetest.registered_nodes[nodename].mesecons.effector.action_off + or minetest.registered_nodes[nodename].mesecons.effector.action_change) then return true end - for i, effector in ipairs(mesecon.effectors) do --TODO + for _, effector in ipairs(mesecon.effectors) do --TODO if effector.onstate == nodename then return true end @@ -74,13 +75,14 @@ function mesecon:is_effector_on(nodename) end function mesecon:is_effector_off(nodename) - if minetest.registered_nodes[nodename] - and minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.effector - and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.off then + if minetest.registered_nodes[nodename] + and minetest.registered_nodes[nodename].mesecons + and minetest.registered_nodes[nodename].mesecons.effector + and (minetest.registered_nodes[nodename].mesecons.effector.action_on + or minetest.registered_nodes[nodename].mesecons.effector.action_change) then return true end - for i, effector in ipairs(mesecon.effectors) do --TODO + for _, effector in ipairs(mesecon.effectors) do --TODO if effector.offstate == nodename then return true end @@ -101,11 +103,9 @@ function mesecon:effector_get_input_rules(node) if minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.effector then local rules = minetest.registered_nodes[node.name].mesecons.effector.rules - if not rules then - return mesecon.rules.default - elseif type(rules) == 'function' then + if type(rules) == 'function' then return rules(node) - else + elseif rules then return rules end end @@ -121,6 +121,7 @@ function mesecon:effector_get_input_rules(node) end end end + return mesecon.rules.default end --Signals @@ -153,11 +154,11 @@ end function mesecon:changesignal(pos) --TODO local node = minetest.env:get_node(pos) - if minetest.registered_nodes[nodename] - and minetest.registered_nodes[nodename].mesecons - and minetest.registered_nodes[nodename].mesecons.effector - and minetest.registered_nodes[nodename].mesecons.effector.action_change then - minetest.registered_nodes[nodename].mesecons.action_change(pos, node) + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecons + and minetest.registered_nodes[node.name].mesecons.effector + and minetest.registered_nodes[node.name].mesecons.effector.action_change then + minetest.registered_nodes[node.name].mesecons.effector.action_change(pos, node) end for i, action in ipairs(mesecon.actions_change) do action(pos, node) @@ -178,7 +179,7 @@ function mesecon:get_rules(name) end end ---Conductor system stuff +-- Conductors function mesecon:get_conductor_on(offstate) if minetest.registered_nodes[offstate] @@ -248,11 +249,9 @@ function mesecon:conductor_get_rules(node) and minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.conductor then local rules = minetest.registered_nodes[node.name].mesecons.conductor.rules - if not rules then - return mesecon.rules.default - elseif type(rules) == 'function' then + if type(rules) == 'function' then return rules(node) - else + elseif rules then return rules end end @@ -266,6 +265,7 @@ function mesecon:conductor_get_rules(node) end end end + return mesecon.rules.default end -- @@ -292,11 +292,8 @@ function mesecon:turnon(pos) local rules = mesecon:conductor_get_rules(node) minetest.env:add_node(pos, {name=mesecon:get_conductor_on(node.name), param2 = node.param2}) - for i, rule in ipairs(rules) do - local np = {} - np.x = pos.x + rule.x - np.y = pos.y + rule.y - np.z = pos.z + rule.z + for _, rule in ipairs(rules) do + local np = mesecon:addPosRule(pos, rule) if mesecon:rules_link(pos, np) then mesecon:turnon(np) @@ -319,11 +316,8 @@ function mesecon:turnoff(pos) --receptor rules used because output could have be local rules = mesecon:conductor_get_rules(node) minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name), param2 = node.param2}) - for i, rule in ipairs(rules) do - local np = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z,} + for _, rule in ipairs(rules) do + local np = mesecon:addPosRule(pos, rule) if mesecon:rules_link(pos, np) then mesecon:turnoff(np) @@ -345,7 +339,7 @@ function mesecon:connected_to_pw_src(pos, checked) local c = 1 checked = checked or {} while checked[c] ~= nil do --find out if node has already been checked (to prevent from endless loop) - if compare_pos(checked[c], pos) then + if mesecon:cmpPos(checked[c], pos) then return false, checked end c = c + 1 @@ -368,11 +362,8 @@ function mesecon:connected_to_pw_src(pos, checked) return false, checked end - for i, rule in ipairs(rules) do - local np = {} - np.x = pos.x + rule.x - np.y = pos.y + rule.y - np.z = pos.z + rule.z + for _, rule in ipairs(rules) do + local np = mesecon:addPosRule(pos, rule) if mesecon:rules_link(pos, np) then connected, checked = mesecon:connected_to_pw_src(np, checked) if connected then @@ -410,13 +401,9 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p for _, outputrule in ipairs(outputrules) do - if outputrule.x + output.x == input.x - and outputrule.y + output.y == input.y - and outputrule.z + output.z == input.z then -- Check if output sends to input + if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then -- Check if output sends to input for _, inputrule in ipairs(inputrules) do - if inputrule.x + input.x == output.x - and inputrule.y + input.y == output.y - and inputrule.z + input.z == output.z then --Check if input accepts from output + if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then --Check if input accepts from output return true end end @@ -447,11 +434,8 @@ function mesecon:is_powered_by_conductor(pos) return false end - for i, rule in ipairs(rules) do - local con_pos = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z} + for _, rule in ipairs(rules) do + local con_pos = mesecon:addPosRule(pos, rule) con_node = minetest.env:get_node(con_pos) @@ -482,10 +466,7 @@ function mesecon:is_powered_by_receptor(pos) end for i, rule in ipairs(rules) do - local rcpt_pos = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z} + local rcpt_pos = mesecon:addPosRule(pos, rule) rcpt_node = minetest.env:get_node(rcpt_pos) @@ -509,10 +490,6 @@ function mesecon:updatenode(pos) end end -function compare_pos(pos1, pos2) - return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z -end - --Rules rotation Functions: function mesecon:rotate_rules_right(rules) local nr={}; diff --git a/mesecons/legacy.lua b/mesecons/legacy.lua index 3f87b1b..947c100 100644 --- a/mesecons/legacy.lua +++ b/mesecons/legacy.lua @@ -38,38 +38,6 @@ function mesecon:register_effector(onstate, offstate, input_rules, get_input_rul get_input_rules = get_input_rules}) end -function mesecon:receptor_on(pos, rules) - if rules == nil then - rules = mesecon:get_rules("default") - end - - for i, rule in ipairs(rules) do - local np = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z} - if mesecon:rules_link(pos, np, rules) then - mesecon:turnon(np, pos) - end - end -end - -function mesecon:receptor_off(pos, rules) - if rules == nil then - rules = mesecon:get_rules("default") - end - - for i, rule in ipairs(rules) do - local np = { - x = pos.x + rule.x, - y = pos.y + rule.y, - z = pos.z + rule.z} - if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then - mesecon:turnoff(np, pos) - end - end -end - function mesecon:register_on_signal_on(action) table.insert(mesecon.actions_on, action) end diff --git a/mesecons/presets.lua b/mesecons/presets.lua index 450f039..463a0f8 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -1,7 +1,7 @@ mesecon.rules={} mesecon.state = {} -mesecon.rules.default = +mesecon.rules.default = {{x=0, y=0, z=-1}, {x=1, y=0, z=0}, {x=-1, y=0, z=0}, @@ -15,5 +15,13 @@ mesecon.rules.default = {x=0, y=1, z=-1}, {x=0, y=-1, z=-1}} +mesecon.rules.buttonlike = +{{x = 1, y = 0, z = 0}, +{x = 1, y = 1, z = 0}, +{x = 1, y =-1, z = 0}, +{x = 1, y =-1, z = 1}, +{x = 1, y =-1, z =-1}, +{x = 2, y = 0, z = 0}} + mesecon.state.on = "on" mesecon.state.off = "off" diff --git a/mesecons/util.lua b/mesecons/util.lua new file mode 100644 index 0000000..b95cf6e --- /dev/null +++ b/mesecons/util.lua @@ -0,0 +1,15 @@ +function mesecon:swap_node(pos, name) + local node = minetest.env:get_node(pos) + local data = minetest.env:get_meta(pos):to_table() + node.name = name + minetest.env:add_node(pos, node) + minetest.env:get_meta(pos):from_table(data) +end + +function mesecon:addPosRule(p, r) + return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z} +end + +function mesecon:cmpPos(p1, p2) + return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z) +end diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua index 25251c6..f5c0eb9 100644 --- a/mesecons_button/init.lua +++ b/mesecons_button/init.lua @@ -1,7 +1,10 @@ -- WALL BUTTON +-- A button that when pressed emits power for 1 second +-- and then turns off again + minetest.register_node("mesecons_button:button_off", { - drawtype = "nodebox", - tiles = { + drawtype = "nodebox", + tiles = { "jeija_wall_button_sides.png", "jeija_wall_button_sides.png", "jeija_wall_button_sides.png", @@ -9,24 +12,34 @@ minetest.register_node("mesecons_button:button_off", { "jeija_wall_button_sides.png", "jeija_wall_button_off.png" }, - paramtype = "light", - paramtype2 = "facedir", - legacy_wallmounted = true, - walkable = false, - sunlight_propagates = true, - selection_box = { - type = "fixed", - fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 } - }, - node_box = { - type = "fixed", - fixed = { + paramtype = "light", + paramtype2 = "facedir", + legacy_wallmounted = true, + walkable = false, + sunlight_propagates = true, + selection_box = { + type = "fixed", + fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 } + }, + node_box = { + type = "fixed", + fixed = { { -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the thin plate behind the button { -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself } - }, - groups = {dig_immediate=2, mesecon = 3, mesecon_needs_receiver = 1}, - description = "Button", + }, + groups = {dig_immediate=2, mesecon_needs_receiver = 1}, + description = "Button", + on_punch = function (pos, node) + mesecon:swap_node(pos, "mesecons_button:button_on") + local rules=mesecon.button_get_rules(node.param2) + mesecon:receptor_on(pos, rules) + minetest.after(1, mesecon.button_turnoff, {pos=pos, param2=node.param2}) + end, + mesecons = {receptor = { + state = mesecon.state.off, + rules = button_get_rules + }} }) minetest.register_node("mesecons_button:button_on", { @@ -45,48 +58,41 @@ minetest.register_node("mesecons_button:button_on", { walkable = false, light_source = LIGHT_MAX-7, sunlight_propagates = true, - selection_box = { - type = "fixed", - fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 } - }, - node_box = { - type = "fixed", + selection_box = { + type = "fixed", + fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 } + }, + node_box = { + type = "fixed", fixed = { { -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, { -4/16, -2/16, 11/32, 4/16, 2/16, 6/16 } } }, - groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, mesecon_needs_receiver = 1}, + groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, drop = 'mesecons_button:button_off', description = "Button", + mesecons = {receptor = { + state = mesecon.state.on, + rules = button_get_rules + }} }) -minetest.register_on_punchnode(function(pos, node, puncher) - if node.name == "mesecons_button:button_off" then - minetest.env:add_node(pos, {name="mesecons_button:button_on",param2=node.param2}) - local rules=mesecon.button_get_rules(node.param2) - mesecon:receptor_on(pos, rules) - minetest.after(1, mesecon.button_turnoff, {pos=pos, param2=node.param2}) - end -end) - mesecon.button_turnoff = function (params) if minetest.env:get_node(params.pos).name=="mesecons_button:button_on" then - minetest.env:add_node(params.pos, {name="mesecons_button:button_off", param2=params.param2}) + mesecon:swap_node(params.pos, "mesecons_button:button_off") local rules=mesecon.button_get_rules(params.param2) mesecon:receptor_off(params.pos, rules) end end -mesecon.button_get_rules = function(param2) - local rules=mesecon:get_rules("button") - if param2 == 2 then +mesecon.button_get_rules = function(node) + local rules = mesecon.rules.buttonlike + if node.param2 == 2 then rules=mesecon:rotate_rules_left(rules) - end - if param2 == 3 then + elseif node.param2 == 3 then rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) - end - if param2 == 0 then + elseif node.param2 == 0 then rules=mesecon:rotate_rules_right(rules) end return rules @@ -98,14 +104,3 @@ minetest.register_craft({ {'"group:mesecon_conductor_craftable"','"default:stone"'}, } }) - -mesecon:add_rules("button", { -{x = 1, y = 0, z = 0}, -{x = 1, y = 1, z = 0}, -{x = 1, y =-1, z = 0}, -{x = 1, y =-1, z = 1}, -{x = 1, y =-1, z =-1}, -{x = 2, y = 0, z = 0},}) - -mesecon:add_receptor_node_off("mesecons_button:button_off", nil, mesecon.button_get_rules) -mesecon:add_receptor_node("mesecons_button:button_on", nil, mesecon.button_get_rules) diff --git a/mesecons_commandblock/init.lua b/mesecons_commandblock/init.lua index 345ca7c..b61c85b 100644 --- a/mesecons_commandblock/init.lua +++ b/mesecons_commandblock/init.lua @@ -87,11 +87,42 @@ local resolve_player = function(name, pos) return name end +local commandblock_action_on = function(pos, node) + if node.name ~= "mesecons_commandblock:commandblock_off" then + return + end + + mesecon:swap_node(pos, "mesecons_commandblock:commandblock_on") + + local meta = minetest.env:get_meta(pos) + local command = minetest.chatcommands[meta:get_string("command")] + if command == nil then + return + end + local owner = meta:get_string("owner") + if owner == "" then + return + end + local has_privs, missing_privs = minetest.check_player_privs(owner, command.privs) + if not has_privs then + minetest.chat_send_player(owner, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")") + return + end + local player = resolve_player(meta:get_string("player"), pos) + command.func(player, meta:get_string("param")) +end + +local commandblock_action_off = function(pos, node) + if node.name == "mesecons_commandblock:commandblock_on" then + mesecon:swap_node(pos, "mesecons_commandblock:commandblock_off") + end +end + minetest.register_node("mesecons_commandblock:commandblock_off", { description = "Command Block", tiles = {"jeija_commandblock_off.png"}, inventory_image = minetest.inventorycube("jeija_commandblock_off.png"), - groups = {cracky=2, mesecon_effector_off=1, mesecon=2}, + groups = {cracky=2, mesecon_effector_off=1}, on_construct = construct, after_place_node = after_place, on_receive_fields = receive_fields, @@ -99,11 +130,14 @@ minetest.register_node("mesecons_commandblock:commandblock_off", { local owner = minetest.env:get_meta(pos):get_string("owner") return owner == "" or owner == player:get_player_name() end, + mesecons = {effector = { + action_on = commandblock_action_on + }} }) minetest.register_node("mesecons_commandblock:commandblock_on", { tiles = {"jeija_commandblock_on.png"}, - groups = {cracky=2, mesecon_effector_on=1, mesecon=2, not_in_creative_inventory=1}, + groups = {cracky=2, mesecon_effector_on=1, not_in_creative_inventory=1}, light_source = 10, drop = "mesecons_commandblock:commandblock_off", on_construct = construct, @@ -113,45 +147,7 @@ minetest.register_node("mesecons_commandblock:commandblock_on", { local owner = minetest.env:get_meta(pos):get_string("owner") return owner == "" or owner == player:get_player_name() end, + mesecons = {effector = { + action_off = commandblock_action_off + }} }) - -mesecon:register_effector("mesecons_commandblock:commandblock_on", "mesecons_commandblock:commandblock_off") - -local swap_node = function(pos, name) - local node = minetest.env:get_node(pos) - local data = minetest.env:get_meta(pos):to_table() - node.name = name - minetest.env:add_node(pos, node) - minetest.env:get_meta(pos):from_table(data) -end - -mesecon:register_on_signal_on(function(pos, node) - if node.name ~= "mesecons_commandblock:commandblock_off" then - return - end - - swap_node(pos, "mesecons_commandblock:commandblock_on") - - local meta = minetest.env:get_meta(pos) - local command = minetest.chatcommands[meta:get_string("command")] - if command == nil then - return - end - local owner = meta:get_string("owner") - if owner == "" then - return - end - local has_privs, missing_privs = minetest.check_player_privs(owner, command.privs) - if not has_privs then - minetest.chat_send_player(owner, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")") - return - end - local player = resolve_player(meta:get_string("player"), pos) - command.func(player, meta:get_string("param")) -end) - -mesecon:register_on_signal_off(function(pos, node) - if node.name == "mesecons_commandblock:commandblock_on" then - swap_node(pos, "mesecons_commandblock:commandblock_off") - end -end) \ No newline at end of file diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua index c732a17..ca28258 100644 --- a/mesecons_delayer/init.lua +++ b/mesecons_delayer/init.lua @@ -1,9 +1,91 @@ +-- Function that get the input/output rules of the delayer +local delayer_get_output_rules = function(node) + local rules = {} + if node.param2 == 0 then + table.insert(rules, {x = 1, y = 0, z = 0}) + elseif node.param2 == 2 then + table.insert(rules, {x =-1, y = 0, z = 0}) + elseif node.param2 == 1 then + table.insert(rules, {x = 0, y = 0, z =-1}) + elseif node.param2 == 3 then + table.insert(rules, {x = 0, y = 0, z = 1}) + end + return rules +end + +local delayer_get_input_rules = function(node) + local rules = {} + if node.param2 == 0 then + table.insert(rules, {x =-1, y = 0, z = 0}) + elseif node.param2 == 2 then + table.insert(rules, {x = 1, y = 0, z = 0}) + elseif node.param2 == 1 then + table.insert(rules, {x = 0, y = 0, z = 1}) + elseif node.param2 == 3 then + table.insert(rules, {x = 0, y = 0, z =-1}) + end + return rules +end + +-- Functions that are called after the delay time + +local delayer_turnon = function(params) + local rules = delayer_get_output_rules(params) + mesecon:receptor_on(params.pos, rules) +end + +local delayer_turnoff = function(params) + local rules = delayer_get_output_rules(params) + mesecon:receptor_off(params.pos, rules) +end + +local delayer_update = function(pos, node) + print("update") + if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then + local time = 0 + if node.name=="mesecons_delayer:delayer_off_1" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_on_1") + time=0.1 + elseif node.name=="mesecons_delayer:delayer_off_2" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_on_2") + time=0.3 + elseif node.name=="mesecons_delayer:delayer_off_3" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_on_3") + time=0.5 + elseif node.name=="mesecons_delayer:delayer_off_4" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_on_4") + time=1 + end + minetest.after(time, delayer_turnon, {pos=pos, param2=node.param2}) + end + + if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then + local time = 0 + if node.name=="mesecons_delayer:delayer_on_1" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_off_1") + time=0.1 + elseif node.name=="mesecons_delayer:delayer_on_2" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_off_2") + time=0.3 + elseif node.name=="mesecons_delayer:delayer_on_3" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_off_3") + time=0.5 + elseif node.name=="mesecons_delayer:delayer_on_4" then + mesecon:swap_node(pos, "mesecons_delayer:delayer_off_4") + time=1 + end + minetest.after(time, delayer_turnoff, {pos=pos, param2=node.param2}) + end +end + +--Actually register the 2 (states) x 4 (delay times) delayers + for i = 1, 4 do local groups = {} if i == 1 then - groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 3} + groups = {bendy=2,snappy=1,dig_immediate=2} else - groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} + groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1} end boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab @@ -46,6 +128,29 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), { sunlight_propagates = true, is_ground_content = true, drop = 'mesecons_delayer:delayer_off_1', + on_punch = function (pos, node) + if node.name=="mesecons_delayer:delayer_off_1" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_off_2") + elseif node.name=="mesecons_delayer:delayer_off_2" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_off_3") + elseif node.name=="mesecons_delayer:delayer_off_3" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_off_4") + elseif node.name=="mesecons_delayer:delayer_off_4" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1") + end + end, + mesecons = { + receptor = + { + state = mesecon.state.off, + rules = delayer_get_output_rules + }, + effector = + { + rules = delayer_get_input_rules, + action_change = delayer_update + } + } }) @@ -69,147 +174,34 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), { type = "fixed", fixed = boxes }, - groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}, + groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1}, paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, is_ground_content = true, drop = 'mesecons_delayer:delayer_off_1', -}) -end - - - - -minetest.register_on_punchnode(function (pos, node) - mesecon.delayer_get_output_rules(node.param2) - if node.name=="mesecons_delayer:delayer_off_1" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2}) - end - if node.name=="mesecons_delayer:delayer_off_2" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2}) - end - if node.name=="mesecons_delayer:delayer_off_3" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2}) - end - if node.name=="mesecons_delayer:delayer_off_4" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2}) - end -end) - -minetest.register_on_punchnode(function (pos, node) - mesecon.delayer_get_output_rules(node.param2) - if node.name=="mesecons_delayer:delayer_on_1" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2}) - end - if node.name=="mesecons_delayer:delayer_on_2" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2}) - end - if node.name=="mesecons_delayer:delayer_on_3" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2}) - end - if node.name=="mesecons_delayer:delayer_on_4" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2}) - end -end) - -mesecon.delayer_update = function(pos, node) - if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then - 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 - end - if node.name=="mesecons_delayer:delayer_off_2" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2}) - time=0.3 - end - if node.name=="mesecons_delayer:delayer_off_3" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2}) - time=0.5 - end - if node.name=="mesecons_delayer:delayer_off_4" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2}) - time=1 - end - minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2}) - end - - if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then - local time = 0 + on_punch = function (pos, node) 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 + mesecon:swap_node(pos,"mesecons_delayer:delayer_on_2") + elseif node.name=="mesecons_delayer:delayer_on_2" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_on_3") + elseif node.name=="mesecons_delayer:delayer_on_3" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_on_4") + elseif node.name=="mesecons_delayer:delayer_on_4" then + mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1") end - if node.name=="mesecons_delayer:delayer_on_2" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2}) - time=0.3 - end - if node.name=="mesecons_delayer:delayer_on_3" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2}) - time=0.5 - end - if node.name=="mesecons_delayer:delayer_on_4" then - minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2}) - time=1 - end - minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2}) - end -end - -mesecon:register_on_signal_change(mesecon.delayer_update) - -mesecon.delayer_turnon=function(params) - local rules = mesecon.delayer_get_output_rules(params.param2) - mesecon:receptor_on(params.pos, rules) -end - -mesecon.delayer_turnoff=function(params) - local rules = mesecon.delayer_get_output_rules(params.param2) - mesecon:receptor_off(params.pos, rules) -end - -mesecon.delayer_get_output_rules = function(param2) - local rules = {} - if param2 == 0 then - table.insert(rules, {x = 1, y = 0, z = 0}) - elseif param2 == 2 then - table.insert(rules, {x =-1, y = 0, z = 0}) - elseif param2 == 1 then - table.insert(rules, {x = 0, y = 0, z =-1}) - elseif param2 == 3 then - table.insert(rules, {x = 0, y = 0, z = 1}) - end - return rules -end - -mesecon.delayer_get_input_rules = function(param2) - local rules = {} - if param2 == 0 then - table.insert(rules, {x =-1, y = 0, z = 0}) - elseif param2 == 2 then - table.insert(rules, {x = 1, y = 0, z = 0}) - elseif param2 == 1 then - table.insert(rules, {x = 0, y = 0, z = 1}) - elseif param2 == 3 then - table.insert(rules, {x = 0, y = 0, z =-1}) - end - return rules + end, + mesecons = { + receptor = + { + state = mesecon.state.on, + rules = delayer_get_output_rules + }, + effector = + { + rules = delayer_get_input_rules, + action_change = delayer_update + } + } +}) end - -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("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) - -mesecon:register_effector("mesecons_delayer:delayer_on_1", "mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_input_rules) -mesecon:register_effector("mesecons_delayer:delayer_on_2", "mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_input_rules) -mesecon:register_effector("mesecons_delayer:delayer_on_3", "mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_input_rules) -mesecon:register_effector("mesecons_delayer:delayer_on_4", "mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_input_rules) diff --git a/mesecons_lightstone/init.lua b/mesecons_lightstone/init.lua index 9edd99d..d8b523c 100644 --- a/mesecons_lightstone/init.lua +++ b/mesecons_lightstone/init.lua @@ -5,7 +5,6 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2}, description=name.." Lightstone", mesecons = {effector = { - state = mesecon.state.off, action_on = function (pos, node) minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_on"}) mesecon:receptor_on(pos) @@ -19,7 +18,6 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", light_source = LIGHT_MAX-2, mesecons = {effector = { - state = mesecon.state.on, action_off = function (pos, node) minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_off"}) mesecon:receptor_off(pos) diff --git a/mesecons_switch/init.lua b/mesecons_switch/init.lua index 2af5101..0519e03 100644 --- a/mesecons_switch/init.lua +++ b/mesecons_switch/init.lua @@ -9,7 +9,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_off", { state = mesecon.state.off }}, on_punch = function(pos, node) - minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2}) + mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_on") mesecon:receptor_on(pos) end }) @@ -23,7 +23,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_on", { state = mesecon.state.on }}, on_punch = function(pos, node) - minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2}) + mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_off") mesecon:receptor_off(pos) end }) -- cgit v1.2.3 From cf6080f7237af1c55a6d80bea4725dcb5c8cb1eb Mon Sep 17 00:00:00 2001 From: Jeija Date: Sat, 8 Dec 2012 22:28:46 +0100 Subject: Port more blocks to nodedef system: object detector, extrawires, water turbine, insulated wire --- mesecons/internal.lua | 4 +-- mesecons/presets.lua | 17 ++++++++++++ mesecons/settings.lua | 1 + mesecons_detector/init.lua | 27 ++++++++++++-------- mesecons_extrawires/crossing.lua | 2 ++ mesecons_extrawires/init.lua | 3 ++- mesecons_extrawires/tjunction.lua | 54 ++++++++++++++++++++------------------- mesecons_hydroturbine/init.lua | 16 ++++++++---- mesecons_insulated/init.lua | 33 +++++++++++++----------- mesecons_pressureplates/init.lua | 17 ------------ 10 files changed, 98 insertions(+), 76 deletions(-) diff --git a/mesecons/internal.lua b/mesecons/internal.lua index d438a53..8337f62 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -290,7 +290,7 @@ function mesecon:turnon(pos) if mesecon:is_conductor_off(node.name) then local rules = mesecon:conductor_get_rules(node) - minetest.env:add_node(pos, {name=mesecon:get_conductor_on(node.name), param2 = node.param2}) + mesecon:swap_node(pos, mesecon:get_conductor_on(node.name)) for _, rule in ipairs(rules) do local np = mesecon:addPosRule(pos, rule) @@ -314,7 +314,7 @@ function mesecon:turnoff(pos) --receptor rules used because output could have be if mesecon:is_conductor_on(node.name) then local rules = mesecon:conductor_get_rules(node) - minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name), param2 = node.param2}) + mesecon:swap_node(pos, mesecon:get_conductor_off(node.name)) for _, rule in ipairs(rules) do local np = mesecon:addPosRule(pos, rule) diff --git a/mesecons/presets.lua b/mesecons/presets.lua index 463a0f8..ffbcae9 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -23,5 +23,22 @@ mesecon.rules.buttonlike = {x = 1, y =-1, z =-1}, {x = 2, y = 0, z = 0}} +mesecon.rules.pressurplatelike = +{{x=0, y=1, z=-1}, +{x=0, y=0, z=-1}, +{x=0, y=-1, z=-1}, +{x=0, y=1, z=1}, +{x=0, y=-1, z=1}, +{x=0, y=0, z=1}, +{x=1, y=0, z=0}, +{x=1, y=1, z=0}, +{x=1, y=-1, z=0}, +{x=-1, y=1, z=0}, +{x=-1, y=-1, z=0}, +{x=-1, y=0, z=0}, +{x=0, y=-1, z=0}, +{x=0, y=-2, z=0}, +{x=0, y=1, z=0}} + mesecon.state.on = "on" mesecon.state.off = "off" diff --git a/mesecons/settings.lua b/mesecons/settings.lua index db084c6..398ee6d 100644 --- a/mesecons/settings.lua +++ b/mesecons/settings.lua @@ -2,3 +2,4 @@ BLINKY_PLANT_INTERVAL = 3 NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires PRESSURE_PLATE_INTERVAL = 0.1 +OBJECT_DETECTOR_RADIUS = 6 diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua index cbee787..1d5b214 100644 --- a/mesecons_detector/init.lua +++ b/mesecons_detector/init.lua @@ -1,19 +1,29 @@ ---SHORT RANGE DETECTORS +-- Object detector +-- Detects all entities in a certain radius +-- The radius can be specified in mesecons/settings.lua + minetest.register_node("mesecons_detector:object_detector_off", { tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"}, paramtype = "light", walkable = true, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3}, description="Player Detector", + mesecons = {receptor = { + state = mesecon.state.off, + rules = mesecon.rules.pressurplatelike + }} }) minetest.register_node("mesecons_detector:object_detector_on", { tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png"}, paramtype = "light", walkable = true, - groups = {cracky=3,not_in_creative_inventory=1, mesecon = 2}, + groups = {cracky=3,not_in_creative_inventory=1}, drop = 'mesecons_detector:object_detector_off', - description="Player Detector", + mesecons = {receptor = { + state = mesecon.state.on, + rules = mesecon.rules.pressurplatelike + }} }) minetest.register_craft({ @@ -30,9 +40,9 @@ minetest.register_abm( interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local objs = minetest.env:get_objects_inside_radius(pos, 6) + local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS) for k, obj in pairs(objs) do - if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj:get_player_name()~=nil then -- Detected object is not piston pusher - will be changed if every entity has a type (like entity_type=mob) + if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj:get_player_name()~=nil then if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name=="default:sign_wall" then if obj:get_player_name()~=minetest.env:get_meta({x=pos.x, y=pos.y-1, z=pos.z}):get_string("text") then return @@ -51,7 +61,7 @@ minetest.register_abm( interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local objs = minetest.env:get_objects_inside_radius(pos, 6) + local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS) local objectfound=0 for k, obj in pairs(objs) do if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj~=nil @@ -72,6 +82,3 @@ minetest.register_abm( end end, }) - -mesecon:add_receptor_node("mesecons_detector:object_detector_on", mesecon:get_rules("pressureplate")) -mesecon:add_receptor_node_off("mesecons_detector:object_detector_off", mesecon:get_rules("pressureplate")) diff --git a/mesecons_extrawires/crossing.lua b/mesecons_extrawires/crossing.lua index 9ceb9ac..53f12b2 100644 --- a/mesecons_extrawires/crossing.lua +++ b/mesecons_extrawires/crossing.lua @@ -1,3 +1,5 @@ +-- CODE NOT ACTIVE + for x=-1, 1 do for z=-1, 1 do rules = {} nodename = "mesecons_extrawires:crossing" diff --git a/mesecons_extrawires/init.lua b/mesecons_extrawires/init.lua index a8e937f..c9e0773 100644 --- a/mesecons_extrawires/init.lua +++ b/mesecons_extrawires/init.lua @@ -1,2 +1,3 @@ -dofile(minetest.get_modpath("mesecons_extrawires").."/crossing.lua"); +-- dofile(minetest.get_modpath("mesecons_extrawires").."/crossing.lua"); +-- The crossing code is not active right now because it is hard to maintain dofile(minetest.get_modpath("mesecons_extrawires").."/tjunction.lua"); diff --git a/mesecons_extrawires/tjunction.lua b/mesecons_extrawires/tjunction.lua index 93eac0a..9f0c125 100644 --- a/mesecons_extrawires/tjunction.lua +++ b/mesecons_extrawires/tjunction.lua @@ -9,6 +9,22 @@ local tjunction_selectionbox = { fixed = { -16/32-0.001, -18/32, -16/32, 16/32+0.001, -12/32, 7/32 }, } +local tjunction_get_rules = function (node) + local rules = + {{x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}, + {x = 0, y = 0, z = -1}} + + if node.param2 == 1 then + rules = mesecon:rotate_rules_left(rules) + elseif node.param2 == 2 then + rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) + elseif node.param2 == 3 then + rules = mesecon:rotate_rules_right(rules) + end + return rules +end + minetest.register_node("mesecons_extrawires:tjunction_on", { drawtype = "nodebox", tiles = { @@ -27,7 +43,12 @@ minetest.register_node("mesecons_extrawires:tjunction_on", { node_box = tjunction_nodebox, groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1}, drop = "mesecons_insulated:insulated_off", - + mesecons = {conductor = + { + state = mesecon.state.on, + rules = tjunction_get_rules, + offstate = "mesecons_extrawires:tjunction_off" + }} }) minetest.register_node("mesecons_extrawires:tjunction_off", { @@ -48,6 +69,12 @@ minetest.register_node("mesecons_extrawires:tjunction_off", { selection_box = tjunction_selectionbox, node_box = tjunction_nodebox, groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1}, + mesecons = {conductor = + { + state = mesecon.state.off, + rules = tjunction_get_rules, + onstate = "mesecons_extrawires:tjunction_on" + }} }) minetest.register_craft({ @@ -58,28 +85,3 @@ minetest.register_craft({ {"", "mesecons_insulated:insulated_off", ""}, } }) - -mesecon:add_rules("tjunction_all", { --all possible 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},}) - -mesecon:add_rules("tjunction", { -{x = 1, y = 0, z = 0}, -{x =-1, y = 0, z = 0}, -{x = 0, y = 0, z = -1},}) - -function tjunction_get_rules(param2) - local rules = mesecon:get_rules("tjunction") - if param2 == 1 then - rules = mesecon:rotate_rules_left(mesecon:get_rules("tjunction")) - elseif param2 == 2 then - rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(mesecon:get_rules("tjunction"))) - elseif param2 == 3 then - rules = mesecon:rotate_rules_right(mesecon:get_rules("tjunction")) - end - return rules -end - -mesecon:register_conductor("mesecons_extrawires:tjunction_on", "mesecons_extrawires:tjunction_off", mesecon:get_rules("tjunction_all"), tjunction_get_rules) diff --git a/mesecons_hydroturbine/init.lua b/mesecons_hydroturbine/init.lua index 872d18d..70b7d28 100644 --- a/mesecons_hydroturbine/init.lua +++ b/mesecons_hydroturbine/init.lua @@ -1,9 +1,12 @@ -- HYDRO_TURBINE +-- Water turbine: +-- Active if flowing >water< above it +-- (does not work with other liquids) minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", { drawtype = "nodebox", tiles = {"jeija_hydro_turbine_off.png"}, - groups = {dig_immediate=2, mesecon = 2}, + groups = {dig_immediate=2}, description="Water Turbine", paramtype = "light", selection_box = { @@ -20,13 +23,16 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", { {-0.45, 1.15, -0.1, 0.45, 1.45, 0.1}, {-0.1, 1.15, -0.45, 0.1, 1.45, 0.45}}, }, + mesecons = {receptor = { + state = mesecon.state.off + }} }) minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", { drawtype = "nodebox", tiles = {"jeija_hydro_turbine_on.png"}, drop = '"mesecons_hydroturbine:hydro_turbine_off" 1', - groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2}, + groups = {dig_immediate=2,not_in_creative_inventory=1}, description="Water Turbine", paramtype = "light", selection_box = { @@ -43,6 +49,9 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", { {-0.5, 1.15, -0.1, 0.5, 1.45, 0.1}, {-0.1, 1.15, -0.5, 0.1, 1.45, 0.5}}, }, + mesecons = {receptor = { + state = mesecon.state.on + }} }) @@ -74,9 +83,6 @@ nodenames = {"mesecons_hydroturbine:hydro_turbine_on"}, end, }) -mesecon:add_receptor_node("mesecons_hydroturbine:hydro_turbine_on") -mesecon:add_receptor_node_off("mesecons_hydroturbine:hydro_turbine_off") - minetest.register_craft({ output = '"mesecons_hydroturbine:hydro_turbine_off" 2', recipe = { diff --git a/mesecons_insulated/init.lua b/mesecons_insulated/init.lua index 5b48716..fe929d6 100644 --- a/mesecons_insulated/init.lua +++ b/mesecons_insulated/init.lua @@ -21,9 +21,13 @@ minetest.register_node("mesecons_insulated:insulated_on", { type = "fixed", fixed = { -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 } }, - groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1}, + groups = {dig_immediate = 3, not_in_creative_inventory = 1}, drop = "mesecons_insulated:insulated_off", - + mesecons = {conductor = { + state = mesecon.state.on, + offstate = "mesecons_insulated:insulated_off", + rules = insulated_wire_get_rules + }} }) minetest.register_node("mesecons_insulated:insulated_off", { @@ -49,7 +53,12 @@ minetest.register_node("mesecons_insulated:insulated_off", { type = "fixed", fixed = { -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 } }, - groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1}, + groups = {dig_immediate = 3}, + mesecons = {conductor = { + state = mesecon.state.off, + onstate = "mesecons_insulated:insulated_on", + rules = insulated_wire_get_rules + }} }) minetest.register_craft({ @@ -61,21 +70,15 @@ minetest.register_craft({ } }) -mesecon:add_rules("insulated_all", { --all possible 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},}) - mesecon:add_rules("insulated", { {x = 1, y = 0, z = 0}, -{x =-1, y = 0, z = 0},}) +{x =-1, y = 0, z = 0}}) -function insulated_wire_get_rules(param2) +function insulated_wire_get_rules(node) + local rules = {{x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}} if param2 == 1 or param2 == 3 then - return mesecon:rotate_rules_right(mesecon:get_rules("insulated")) + return mesecon:rotate_rules_right(rules) end - return mesecon:get_rules("insulated") + return rules end - -mesecon:register_conductor("mesecons_insulated:insulated_on", "mesecons_insulated:insulated_off", mesecon:get_rules("insulated_all"), insulated_wire_get_rules) diff --git a/mesecons_pressureplates/init.lua b/mesecons_pressureplates/init.lua index 49edb48..f7a2edd 100644 --- a/mesecons_pressureplates/init.lua +++ b/mesecons_pressureplates/init.lua @@ -150,23 +150,6 @@ minetest.register_craft({ } }) -mesecon:add_rules("pressureplate", -{{x=0, y=1, z=-1}, -{x=0, y=0, z=-1}, -{x=0, y=-1, z=-1}, -{x=0, y=1, z=1}, -{x=0, y=-1, z=1}, -{x=0, y=0, z=1}, -{x=1, y=0, z=0}, -{x=1, y=1, z=0}, -{x=1, y=-1, z=0}, -{x=-1, y=1, z=0}, -{x=-1, y=-1, z=0}, -{x=-1, y=0, z=0}, -{x=0, y=-1, z=0}, -{x=0, y=-2, z=0}, -{x=0, y=1, z=0}}) - mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_wood_on", mesecon:get_rules("pressureplate")) mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_wood_off", mesecon:get_rules("pressureplate")) -- cgit v1.2.3 From b37bdbf55cf6d3205d5dd7a2491a8bd855cbbd76 Mon Sep 17 00:00:00 2001 From: Jeija Date: Sun, 9 Dec 2012 00:42:30 +0100 Subject: Port a lot more (basically everything apart from gates, pistons and extrawire crossing) to the new nodedef system. There are some problems with wall button and wall lever (in the way they visually connect to wires) --- mesecons/presets.lua | 17 ---- mesecons_button/init.lua | 4 +- mesecons_delayer/init.lua | 1 - mesecons_detector/init.lua | 10 +-- mesecons_lamp/init.lua | 33 ++++---- mesecons_microcontroller/init.lua | 63 ++++++++------- mesecons_movestones/init.lua | 165 ++++++++++++++++++-------------------- mesecons_noteblock/init.lua | 31 +++---- mesecons_pistons/init.lua | 26 +++--- mesecons_powerplant/init.lua | 8 +- mesecons_pressureplates/init.lua | 26 +++--- mesecons_random/init.lua | 44 +++++----- mesecons_receiver/init.lua | 56 ++++++------- mesecons_solarpanel/init.lua | 14 ++-- mesecons_torch/init.lua | 146 ++++++++++++++++----------------- mesecons_walllever/init.lua | 73 ++++++++--------- 16 files changed, 337 insertions(+), 380 deletions(-) diff --git a/mesecons/presets.lua b/mesecons/presets.lua index ffbcae9..463a0f8 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -23,22 +23,5 @@ mesecon.rules.buttonlike = {x = 1, y =-1, z =-1}, {x = 2, y = 0, z = 0}} -mesecon.rules.pressurplatelike = -{{x=0, y=1, z=-1}, -{x=0, y=0, z=-1}, -{x=0, y=-1, z=-1}, -{x=0, y=1, z=1}, -{x=0, y=-1, z=1}, -{x=0, y=0, z=1}, -{x=1, y=0, z=0}, -{x=1, y=1, z=0}, -{x=1, y=-1, z=0}, -{x=-1, y=1, z=0}, -{x=-1, y=-1, z=0}, -{x=-1, y=0, z=0}, -{x=0, y=-1, z=0}, -{x=0, y=-2, z=0}, -{x=0, y=1, z=0}} - mesecon.state.on = "on" mesecon.state.off = "off" diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua index f5c0eb9..d4e6802 100644 --- a/mesecons_button/init.lua +++ b/mesecons_button/init.lua @@ -32,7 +32,7 @@ minetest.register_node("mesecons_button:button_off", { description = "Button", on_punch = function (pos, node) mesecon:swap_node(pos, "mesecons_button:button_on") - local rules=mesecon.button_get_rules(node.param2) + local rules=mesecon.button_get_rules(node) mesecon:receptor_on(pos, rules) minetest.after(1, mesecon.button_turnoff, {pos=pos, param2=node.param2}) end, @@ -81,7 +81,7 @@ minetest.register_node("mesecons_button:button_on", { mesecon.button_turnoff = function (params) if minetest.env:get_node(params.pos).name=="mesecons_button:button_on" then mesecon:swap_node(params.pos, "mesecons_button:button_off") - local rules=mesecon.button_get_rules(params.param2) + local rules=mesecon.button_get_rules(params) mesecon:receptor_off(params.pos, rules) end end diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua index ca28258..6bdb72d 100644 --- a/mesecons_delayer/init.lua +++ b/mesecons_delayer/init.lua @@ -40,7 +40,6 @@ local delayer_turnoff = function(params) end local delayer_update = function(pos, node) - print("update") if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then local time = 0 if node.name=="mesecons_delayer:delayer_off_1" then diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua index 1d5b214..2394e96 100644 --- a/mesecons_detector/init.lua +++ b/mesecons_detector/init.lua @@ -9,8 +9,7 @@ minetest.register_node("mesecons_detector:object_detector_off", { groups = {cracky=3}, description="Player Detector", mesecons = {receptor = { - state = mesecon.state.off, - rules = mesecon.rules.pressurplatelike + state = mesecon.state.off }} }) @@ -21,8 +20,7 @@ minetest.register_node("mesecons_detector:object_detector_on", { groups = {cracky=3,not_in_creative_inventory=1}, drop = 'mesecons_detector:object_detector_off', mesecons = {receptor = { - state = mesecon.state.on, - rules = mesecon.rules.pressurplatelike + state = mesecon.state.on }} }) @@ -50,7 +48,7 @@ minetest.register_abm( end local objpos=obj:getpos() minetest.env:add_node(pos, {name="mesecons_detector:object_detector_on"}) - mesecon:receptor_on(pos, mesecon:get_rules("pressureplate")) + mesecon:receptor_on(pos) end end end, @@ -78,7 +76,7 @@ minetest.register_abm( end if objectfound==0 then minetest.env:add_node(pos, {name="mesecons_detector:object_detector_off"}) - mesecon:receptor_off(pos, mesecon:get_rules("pressureplate")) + mesecon:receptor_off(pos) end end, }) diff --git a/mesecons_lamp/init.lua b/mesecons_lamp/init.lua index 553941c..d20236b 100644 --- a/mesecons_lamp/init.lua +++ b/mesecons_lamp/init.lua @@ -1,4 +1,7 @@ -- MESELAMPS +-- A lamp is "is an electrical device used to create artificial light" (wikipedia) +-- guess what? + minetest.register_node("mesecons_lamp:lamp_on", { drawtype = "nodebox", tiles = {"jeija_meselamp_on.png"}, @@ -20,8 +23,13 @@ minetest.register_node("mesecons_lamp:lamp_on", { 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,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon = 2}, + groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1}, drop='"mesecons_lamp:lamp_off" 1', + mesecons = {effector = { + action_off = function (pos, node) + mesecon:swap_node(pos, "mesecons_lamp:lamp_off") + end + }} }) minetest.register_node("mesecons_lamp:lamp_off", { @@ -45,8 +53,13 @@ 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_effector_off = 1, mesecon = 2}, + groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1}, description="Meselamp", + mesecons = {effector = { + action_on = function (pos, node) + mesecon:swap_node(pos, "mesecons_lamp:lamp_on") + end + }} }) minetest.register_craft({ @@ -57,19 +70,3 @@ minetest.register_craft({ {'', '"default:glass"', ''}, } }) - -mesecon:register_on_signal_on(function(pos, node) - if node.name == "mesecons_lamp:lamp_off" then - minetest.env:add_node(pos, {name="mesecons_lamp:lamp_on", param2 = node.param2}) - nodeupdate(pos) - end -end) - -mesecon:register_on_signal_off(function(pos, node) - if node.name == "mesecons_lamp:lamp_on" then - minetest.env:add_node(pos, {name="mesecons_lamp:lamp_off", param2 = node.param2}) - nodeupdate(pos) - end -end) - -mesecon:register_effector("mesecons_lamp:lamp_on", "mesecons_lamp:lamp_off") diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 121eb25..19fc42d 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -23,6 +23,33 @@ if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then else groups = {dig_immediate=2, mesecon = 3} end +local rules={} +if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end +if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end +if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end +if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end + +local input_rules={} +if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0}) end +if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1}) end +if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0}) end +if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1}) end +mesecon:add_rules(nodename, rules) + +local mesecons = {effector = +{ + rules = input_rules, + action_change = function (pos, node) + update_yc(pos) + end +}} +if nodename ~= "mesecons_microcontroller:microcontroller0000" then + mesecons.receptor = { + state = mesecon.state.on, + rules = rules + } +end + minetest.register_node(nodename, { description = "Microcontroller", drawtype = "nodebox", @@ -101,25 +128,12 @@ minetest.register_node(nodename, { yc_reset (pos) update_yc(pos) end, + mesecons = mesecons, + on_dig = function (pos, node) + rules = mesecon:get_rules(node.name) + mesecon:receptor_off(pos, rules) + end, }) - -local rules={} -if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end -if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end -if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end -if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end - -local input_rules={} -if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0}) end -if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1}) end -if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0}) end -if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1}) end -mesecon:add_rules(nodename, rules) - -mesecon:register_effector(nodename, nodename, input_rules) -if nodename ~= "mesecons_microcontroller:microcontroller0000" then - mesecon:add_receptor_node(nodename, rules) -end end end end @@ -682,16 +696,3 @@ function yc_overheat_off(pos) rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111") mesecon:receptor_off(pos, rules) end - -mesecon:register_on_signal_change(function(pos, node) - if string.find(node.name, "mesecons_microcontroller:microcontroller")~=nil then - update_yc(pos) - end -end) - -minetest.register_on_dignode(function(pos, node) - if string.find(node.name, "mesecons_microcontroller:microcontroller") then - rules = mesecon:get_rules(node.name) - mesecon:receptor_off(pos, rules) - end -end) diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua index 5198a29..b17874f 100644 --- a/mesecons_movestones/init.lua +++ b/mesecons_movestones/init.lua @@ -1,33 +1,53 @@ -- MOVESTONE +-- Non-sticky: +-- Moves along mesecon lines +-- Pushes all blocks in front of it +-- +-- Sticky one +-- Moves along mesecon lines +-- Pushes all block in front of it +-- Pull all blocks in its back function mesecon:get_movestone_direction(pos) - getactivated=0 + getactivated = 0 local lpos - local getactivated=0 - local rules=mesecon:get_rules("movestone") - - lpos={x=pos.x+1, y=pos.y, z=pos.z} - for n=1, 3 do + local getactivated = 0 + local rules = { + {x=0, y=1, z=-1}, + {x=0, y=0, z=-1}, + {x=0, y=-1, z=-1}, + {x=0, y=1, z=1}, + {x=0, y=-1, z=1}, + {x=0, y=0, z=1}, + {x=1, y=0, z=0}, + {x=1, y=1, z=0}, + {x=1, y=-1, z=0}, + {x=-1, y=1, z=0}, + {x=-1, y=-1, z=0}, + {x=-1, y=0, z=0}} + + lpos = {x=pos.x+1, y=pos.y, z=pos.z} + for n = 1, 3 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=0, y=0, z=-1} end end - lpos={x=pos.x-1, y=pos.y, z=pos.z} + lpos = {x = pos.x-1, y = pos.y, z = pos.z} for n=4, 6 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=0, y=0, z=1} end end - lpos={x=pos.x, y=pos.y, z=pos.z+1} + lpos = {x = pos.x, y = pos.y, z = pos.z+1} for n=7, 9 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=-1, y=0, z=0} end end - lpos={x=pos.x, y=pos.y, z=pos.z-1} + lpos = {x = pos.x, y = pos.y, z = pos.z-1} for n=10, 12 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=1, y=0, z=0} @@ -41,8 +61,27 @@ minetest.register_node("mesecons_movestones:movestone", { legacy_facedir_simple = true, groups = {cracky=3}, description="Movestone", + mesecons = {effector = { + action_on = function (pos, node) + local direction=mesecon:get_movestone_direction(pos) + if not direction then return end + local checknode={} + local collpos={x=pos.x, y=pos.y, z=pos.z} + repeat -- Check if it collides with a stopper + collpos = addPosRule(collpos, direction) + checknode=minetest.env:get_node(collpos) + if mesecon:is_mvps_stopper(checknode.name) then + return + end + until checknode.name=="air" + or checknode.name=="ignore" + or not(minetest.registered_nodes[checknode.name].liquidtype == "none") + minetest.env:remove_node(pos) + mesecon:update_autoconnect(pos) + minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity") + end + }} }) -mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone") minetest.register_entity("mesecons_movestones:movestone_entity", { physical = false, @@ -50,10 +89,6 @@ minetest.register_entity("mesecons_movestones:movestone_entity", { textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"}, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, visual = "cube", - --on_activate = function(self, staticdata) - --self.object:setsprite({x=0,y=0}, 1, 0, true) - --self.object:setvelocity({x=-3, y=0, z=0}) - --end, on_punch = function(self, hitter) self.object:remove() @@ -73,7 +108,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", { self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3}) mesecon:mvps_push(pos, direction) - end + end, }) minetest.register_craft({ @@ -85,28 +120,6 @@ minetest.register_craft({ } }) -mesecon:register_on_signal_on(function (pos, node) - if node.name=="mesecons_movestones:movestone" then - local direction=mesecon:get_movestone_direction(pos) - if not direction then return end - local checknode={} - local collpos={x=pos.x, y=pos.y, z=pos.z} - repeat -- Check if it collides with a stopper - collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z} - checknode=minetest.env:get_node(collpos) - if mesecon:is_mvps_stopper(checknode.name) then - return - end - until checknode.name=="air" - or checknode.name=="ignore" - or not(minetest.registered_nodes[checknode.name].liquidtype == "none") - minetest.env:remove_node(pos) - nodeupdate(pos) - minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity") - end -end) - - -- STICKY_MOVESTONE @@ -118,8 +131,36 @@ minetest.register_node("mesecons_movestones:sticky_movestone", { legacy_facedir_simple = true, groups = {cracky=3}, description="Sticky Movestone", + mesecons = {effector = { + action_on = function (pos, node) + local direction=mesecon:get_movestone_direction(pos) + if not direction then return end + local checknode={} + local collpos={x=pos.x, y=pos.y, z=pos.z} + repeat -- Check if it collides with a stopper + collpos = addPosRule(collpos, direction) + checknode=minetest.env:get_node(collpos) + if mesecon:is_mvps_stopper(checknode.name) then + return + end + until checknode.name=="air" + or checknode.name=="ignore" + or not(minetest.registered_nodes[checknode.name].liquidtype == "none") + repeat -- Check if it collides with a stopper (pull direction) + collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z} + checknode=minetest.env:get_node(collpos) + if mesecon:is_mvps_stopper(checknode.name) then + return + end + until checknode.name=="air" + or checknode.name=="ignore" + or not(minetest.registered_nodes[checknode.name].liquidtype == "none") + minetest.env:remove_node(pos) + mesecon:update_autoconnect(pos) + minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity") + end + }} }) -mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone") minetest.register_craft({ output = '"mesecons_movestones:sticky_movestone" 2', @@ -146,8 +187,6 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", { local direction=mesecon:get_movestone_direction(colp) if not direction then - --or (minetest.env:get_node_or_nil(pos).name ~="air" - --and minetest.env:get_node_or_nil(pos).name ~= nil) then minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"}) self.object:remove() return @@ -159,49 +198,5 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", { --STICKY mesecon:mvps_pull_all(pos, direction) - end + end, }) - -mesecon:register_on_signal_on(function (pos, node) - if node.name=="mesecons_movestones:sticky_movestone" then - local direction=mesecon:get_movestone_direction(pos) - if not direction then return end - local checknode={} - local collpos={x=pos.x, y=pos.y, z=pos.z} - repeat -- Check if it collides with a stopper - collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z} - checknode=minetest.env:get_node(collpos) - if mesecon:is_mvps_stopper(checknode.name) then - return - end - until checknode.name=="air" - or checknode.name=="ignore" - or not(minetest.registered_nodes[checknode.name].liquidtype == "none") - repeat -- Check if it collides with a stopper (pull direction) - collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z} - checknode=minetest.env:get_node(collpos) - if mesecon:is_mvps_stopper(checknode.name) then - return - end - until checknode.name=="air" - or checknode.name=="ignore" - or not(minetest.registered_nodes[checknode.name].liquidtype == "none") - minetest.env:remove_node(pos) - nodeupdate(pos) - minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity") - end -end) - -mesecon:add_rules("movestone", { -{x=0, y=1, z=-1}, -{x=0, y=0, z=-1}, -{x=0, y=-1, z=-1}, -{x=0, y=1, z=1}, -{x=0, y=-1, z=1}, -{x=0, y=0, z=1}, -{x=1, y=0, z=0}, -{x=1, y=1, z=0}, -{x=1, y=-1, z=0}, -{x=-1, y=1, z=0}, -{x=-1, y=-1, z=0}, -{x=-1, y=0, z=0}}) diff --git a/mesecons_noteblock/init.lua b/mesecons_noteblock/init.lua index 0b05bbb..073524c 100644 --- a/mesecons_noteblock/init.lua +++ b/mesecons_noteblock/init.lua @@ -1,15 +1,25 @@ minetest.register_node("mesecons_noteblock:noteblock", { description = "Noteblock", tiles = {"mesecons_noteblock.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, drawtype = "allfaces_optional", visual_scale = 1.3, paramtype="light", after_place_node = function(pos) minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0}) - end + end, + on_punch = function (pos, node) -- change sound when punched + local param2 = node.param2+1 + if param2==12 then param2=0 end + minetest.env:add_node(pos, {name = node.name, param2 = param2}) + mesecon.noteblock_play(pos, param2) + end, + mesecons = {effector = { -- play sound when activated + action_on = function (pos, node) + mesecon.noteblock_play(pos, node.param2) + end + }} }) -mesecon:register_effector("mesecons_noteblock:noteblock", "mesecons_noteblock:noteblock") minetest.register_craft({ output = '"mesecons_noteblock:noteblock" 1', @@ -20,15 +30,6 @@ minetest.register_craft({ } }) -minetest.register_on_punchnode(function (pos, node) - if node.name=="mesecons_noteblock:noteblock" then - local param2 = node.param2+1 - if param2==12 then param2=0 end - minetest.env:add_node(pos, {name=node.name, param2=param2}) - mesecon.noteblock_play(pos, param2) - end -end) - mesecon.noteblock_play = function (pos, param2) local soundname if param2==8 then @@ -75,9 +76,3 @@ mesecon.noteblock_play = function (pos, param2) minetest.sound_play(soundname, {pos = pos, gain = 1.0, max_hear_distance = 32,}) end - -mesecon:register_on_signal_on(function(pos, node) - if node.name=="mesecons_noteblock:noteblock" then - mesecon.noteblock_play(pos, node.param2) - end -end) diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 935ca66..dd3f599 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -1,5 +1,11 @@ --PISTONS +local update = function(pos, node) + local timer = minetest.env:get_node_timer(pos) + timer:stop() + timer:start(0) +end + minetest.register_node("mesecons_pistons:piston_normal", { description = "Piston", tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"}, @@ -25,8 +31,10 @@ minetest.register_node("mesecons_pistons:piston_normal", { end return false end, + mesecons = {effector={ + action_change = update + }} }) -mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal") minetest.register_node("mesecons_pistons:piston_sticky", { description = "Sticky Piston", @@ -53,8 +61,10 @@ minetest.register_node("mesecons_pistons:piston_sticky", { end return false end, + mesecons = {effector={ + action_change = update + }} }) -mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky") minetest.register_craft({ output = '"mesecons_pistons:piston_normal" 2', @@ -127,18 +137,6 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", { mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal") mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky") -local update = function(pos, node) - if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then - return - end - - local timer = minetest.env:get_node_timer(pos) - timer:stop() - timer:start(0) -end -mesecon:register_on_signal_on(update) --push action -mesecon:register_on_signal_off(update) --pull action - function mesecon:piston_push(pos) local node = minetest.env:get_node(pos) local dir = mesecon:piston_get_direction(node) diff --git a/mesecons_powerplant/init.lua b/mesecons_powerplant/init.lua index a45f5cc..006fc19 100644 --- a/mesecons_powerplant/init.lua +++ b/mesecons_powerplant/init.lua @@ -1,4 +1,5 @@ - -- The POWER_PLANT +-- The POWER_PLANT +-- Just emits power. always. minetest.register_node("mesecons_powerplant:power_plant", { drawtype = "plantlike", @@ -14,6 +15,9 @@ minetest.register_node("mesecons_powerplant:power_plant", { type = "fixed", fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, }, + mesecons = {receptor = { + state = mesecon.state.on + }} }) minetest.register_craft({ @@ -24,5 +28,3 @@ minetest.register_craft({ {'"default:sapling"'}, } }) - -mesecon:add_receptor_node("mesecons_powerplant:power_plant") diff --git a/mesecons_pressureplates/init.lua b/mesecons_pressureplates/init.lua index f7a2edd..2e88d2f 100644 --- a/mesecons_pressureplates/init.lua +++ b/mesecons_pressureplates/init.lua @@ -25,7 +25,7 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_wood_off", { local objpos=obj:getpos() if objpos.y>pos.y-1 and objpos.ypos.y-1 and objpos.y Date: Sun, 9 Dec 2012 11:13:32 +0100 Subject: Fix microcontroller alias --- mesecons_alias/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesecons_alias/init.lua b/mesecons_alias/init.lua index c0f95d1..eaebbc6 100644 --- a/mesecons_alias/init.lua +++ b/mesecons_alias/init.lua @@ -23,7 +23,7 @@ minetest.register_alias("mesecons:mesecon_inverter", "mesecons_temperest:mesecon minetest.register_alias("mesecons:movestone", "mesecons_movestones:movestone") minetest.register_alias("mesecons:sticky_movestone", "mesecons_movestones:sticky_movestone") minetest.register_alias("mesecons:noteblock", "mesecons_noteblock:noteblock") -minetest.register_alias("mesecons:microcontroller", "mesecons_microcontroller:microcontroller") +minetest.register_alias("mesecons:microcontroller", "mesecons_microcontroller:microcontroller0000") minetest.register_alias("mesecons:delayer", "mesecons_delayer:delayer_off_1") minetest.register_alias("mesecons:solarpanel", "mesecons_solarpanel:solar_panel_off") -- cgit v1.2.3 From 961b955f2d0872c4e84d9df63ea10a18643dfcbe Mon Sep 17 00:00:00 2001 From: Jeija Date: Sun, 9 Dec 2012 13:28:32 +0100 Subject: Port door, fix button/lever bug, new visual style for receiver --- mesecons/presets.lua | 14 +- mesecons_button/init.lua | 38 ++--- mesecons_compatibility/init.lua | 174 +++++++++++++++++++-- mesecons_receiver/init.lua | 10 +- mesecons_textures/textures/receiver_bottom_off.png | Bin 242 -> 494 bytes mesecons_textures/textures/receiver_bottom_on.png | Bin 247 -> 239 bytes mesecons_textures/textures/receiver_fb_off.png | Bin 374 -> 494 bytes mesecons_textures/textures/receiver_fb_on.png | Bin 517 -> 239 bytes mesecons_textures/textures/receiver_lr_off.png | Bin 317 -> 494 bytes mesecons_textures/textures/receiver_lr_on.png | Bin 321 -> 239 bytes mesecons_textures/textures/receiver_top_off.png | Bin 240 -> 494 bytes mesecons_textures/textures/receiver_top_on.png | Bin 245 -> 239 bytes mesecons_walllever/init.lua | 34 ++-- 13 files changed, 205 insertions(+), 65 deletions(-) diff --git a/mesecons/presets.lua b/mesecons/presets.lua index 463a0f8..9988d22 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -1,4 +1,4 @@ -mesecon.rules={} +mesecon.rules = {} mesecon.state = {} mesecon.rules.default = @@ -23,5 +23,17 @@ mesecon.rules.buttonlike = {x = 1, y =-1, z =-1}, {x = 2, y = 0, z = 0}} +mesecon.rules.buttonlike_get = function(node) + local rules = mesecon.rules.buttonlike + if node.param2 == 2 then + rules=mesecon:rotate_rules_left(rules) + elseif node.param2 == 3 then + rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) + elseif node.param2 == 0 then + rules=mesecon:rotate_rules_right(rules) + end + return rules +end + mesecon.state.on = "on" mesecon.state.off = "off" diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua index d4e6802..282e305 100644 --- a/mesecons_button/init.lua +++ b/mesecons_button/init.lua @@ -2,6 +2,15 @@ -- A button that when pressed emits power for 1 second -- and then turns off again +mesecon.button_turnoff = function (pos) + local node = minetest.env:get_node(pos) + if node.name=="mesecons_button:button_on" then --has not been dug + mesecon:swap_node(pos, "mesecons_button:button_off") + local rules = mesecon.rules.buttonlike_get(node) + mesecon:receptor_off(pos, rules) + end +end + minetest.register_node("mesecons_button:button_off", { drawtype = "nodebox", tiles = { @@ -32,13 +41,12 @@ minetest.register_node("mesecons_button:button_off", { description = "Button", on_punch = function (pos, node) mesecon:swap_node(pos, "mesecons_button:button_on") - local rules=mesecon.button_get_rules(node) - mesecon:receptor_on(pos, rules) - minetest.after(1, mesecon.button_turnoff, {pos=pos, param2=node.param2}) + mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node)) + minetest.after(1, mesecon.button_turnoff, pos) end, mesecons = {receptor = { state = mesecon.state.off, - rules = button_get_rules + rules = mesecon.rules.buttonlike_get }} }) @@ -74,30 +82,10 @@ minetest.register_node("mesecons_button:button_on", { description = "Button", mesecons = {receptor = { state = mesecon.state.on, - rules = button_get_rules + rules = mesecon.rules.buttonlike_get }} }) -mesecon.button_turnoff = function (params) - if minetest.env:get_node(params.pos).name=="mesecons_button:button_on" then - mesecon:swap_node(params.pos, "mesecons_button:button_off") - local rules=mesecon.button_get_rules(params) - mesecon:receptor_off(params.pos, rules) - end -end - -mesecon.button_get_rules = function(node) - local rules = mesecon.rules.buttonlike - if node.param2 == 2 then - rules=mesecon:rotate_rules_left(rules) - elseif node.param2 == 3 then - rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) - elseif node.param2 == 0 then - rules=mesecon:rotate_rules_right(rules) - end - return rules -end - minetest.register_craft({ output = '"mesecons_button:button_off" 2', recipe = { diff --git a/mesecons_compatibility/init.lua b/mesecons_compatibility/init.lua index dcf94de..b2f793c 100644 --- a/mesecons_compatibility/init.lua +++ b/mesecons_compatibility/init.lua @@ -1,11 +1,165 @@ -minetest.after(0, -function () - if minetest.registered_nodes["doors:door_wood_b_1"] then - mesecon:register_effector("doors:door_wood_b_1", "doors:door_wood_b_2") - mesecon:register_on_signal_change(function(pos, node) - if node.name == "doors:door_wood_b_2" or node.name == "doors:door_wood_b_1" then - minetest.registered_nodes[node.name].on_punch(pos, node) - end - end) +doors = {} + +-- Registers a door - REDEFINITION ONLY | DOORS MOD MUST HAVE BEEN LOADED BEFORE +-- name: The name of the door +-- def: a table with the folowing fields: +-- description +-- inventory_image +-- groups +-- tiles_bottom: the tiles of the bottom part of the door {front, side} +-- tiles_top: the tiles of the bottom part of the door {front, side} +-- If the following fields are not defined the default values are used +-- node_box_bottom +-- node_box_top +-- selection_box_bottom +-- selection_box_top +-- only_placer_can_open: if true only the player who placed the door can +-- open it + +function doors:register_door(name, def) + def.groups.not_in_creative_inventory = 1 + + local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5+1.5/16}} + + if not def.node_box_bottom then + def.node_box_bottom = box + end + if not def.node_box_top then + def.node_box_top = box + end + if not def.selection_box_bottom then + def.selection_box_bottom= box + end + if not def.selection_box_top then + def.selection_box_top = box + end + + local tt = def.tiles_top + local tb = def.tiles_bottom + + local function after_dig_node(pos, name) + if minetest.env:get_node(pos).name == name then + minetest.env:remove_node(pos) + end + end + + local function on_punch(pos, dir, check_name, replace, replace_dir, params) + pos.y = pos.y+dir + if not minetest.env:get_node(pos).name == check_name then + return + end + local p2 = minetest.env:get_node(pos).param2 + p2 = params[p2+1] + + local meta = minetest.env:get_meta(pos):to_table() + minetest.env:set_node(pos, {name=replace_dir, param2=p2}) + minetest.env:get_meta(pos):from_table(meta) + + pos.y = pos.y-dir + meta = minetest.env:get_meta(pos):to_table() + minetest.env:set_node(pos, {name=replace, param2=p2}) + minetest.env:get_meta(pos):from_table(meta) end -end) + + local function on_mesecons_signal_open (pos, node) + on_punch(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) + end + + local function on_mesecons_signal_close (pos, node) + on_punch(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) + end + + local function check_player_priv(pos, player) + if not def.only_placer_can_open then + return true + end + local meta = minetest.env:get_meta(pos) + local pn = player:get_player_name() + return meta:get_string("doors_owner") == pn + end + + minetest.register_node(":"..name.."_b_1", { + tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"}, + paramtype = "light", + paramtype2 = "facedir", + drop = name, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_bottom + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_bottom + }, + groups = def.groups, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + pos.y = pos.y+1 + after_dig_node(pos, name.."_t_1") + end, + + on_punch = function(pos, node, puncher) + if check_player_priv(pos, puncher) then + on_punch(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) + end + end, + + mesecons = {effector = { + action_on = on_mesecons_signal_open + }}, + + can_dig = check_player_priv, + }) + + minetest.register_node(":"..name.."_b_2", { + tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]}, + paramtype = "light", + paramtype2 = "facedir", + drop = name, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_bottom + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_bottom + }, + groups = def.groups, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + pos.y = pos.y+1 + after_dig_node(pos, name.."_t_2") + end, + + on_punch = function(pos, node, puncher) + if check_player_priv(pos, puncher) then + on_punch(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) + end + end, + + mesecons = {effector = { + action_off = on_mesecons_signal_close + }}, + + can_dig = check_player_priv, + }) +end + +doors:register_door("doors:door_wood", { + description = "Wooden Door", + inventory_image = "door_wood.png", + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1}, + tiles_bottom = {"door_wood_b.png", "door_brown.png"}, + tiles_top = {"door_wood_a.png", "door_brown.png"}, +}) + +doors:register_door("doors:door_steel", { + description = "Steel Door", + inventory_image = "door_steel.png", + groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2,door=1}, + tiles_bottom = {"door_steel_b.png", "door_grey.png"}, + tiles_top = {"door_steel_a.png", "door_grey.png"}, + only_placer_can_open = true, +}) diff --git a/mesecons_receiver/init.lua b/mesecons_receiver/init.lua index d830d19..de2b535 100644 --- a/mesecons_receiver/init.lua +++ b/mesecons_receiver/init.lua @@ -1,8 +1,8 @@ rcvboxes = { { -3/16, -3/16 , -8/16 , 3/16, 3/16, -13/32 }, -- the smaller bump - { -5/32, -5/32 , -13/32 , 5/32, 5/32, -12/32 }, -- the receiver itself - { -3/32, -.5-1/32, -.5 , 3/32, 0 , -.5002+3/32 }, -- the vertical wire bit - { -3/32, -17/32 , -7/16+0.002 , 3/32, -13/32, 16/32+0.001 } -- the horizontal wire + { -1/32, -1/32 , -3/2 , 1/32, 1/32, -1/2 }, -- the wire through the block + { -2/32, -.5-1/32, -.5 , 2/32, 0 , -.5002+3/32 }, -- the vertical wire bit + { -2/32, -17/32 , -7/16+0.002 , 2/32, -14/32, 16/32+0.001 } -- the horizontal wire } local receiver_get_rules = function (node) @@ -31,6 +31,7 @@ minetest.register_node("mesecons_receiver:receiver_on", { paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, + walkable = false, selection_box = { type = "fixed", fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 } @@ -62,6 +63,7 @@ minetest.register_node("mesecons_receiver:receiver_off", { paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, + walkable = false, selection_box = { type = "fixed", fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 } @@ -113,7 +115,7 @@ function mesecon:receiver_place(rcpt_pos) minetest.env:dig_node(pos) if mesecon:is_power_on(rcpt_pos) then minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2}) - mesecon:receptor_on(pos, receiver_get_rules(node.param2)) + mesecon:receptor_on(pos, receiver_get_rules(node)) else minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2}) end diff --git a/mesecons_textures/textures/receiver_bottom_off.png b/mesecons_textures/textures/receiver_bottom_off.png index 8542e7d..b95903e 100644 Binary files a/mesecons_textures/textures/receiver_bottom_off.png and b/mesecons_textures/textures/receiver_bottom_off.png differ diff --git a/mesecons_textures/textures/receiver_bottom_on.png b/mesecons_textures/textures/receiver_bottom_on.png index 98ca72a..d0b7006 100644 Binary files a/mesecons_textures/textures/receiver_bottom_on.png and b/mesecons_textures/textures/receiver_bottom_on.png differ diff --git a/mesecons_textures/textures/receiver_fb_off.png b/mesecons_textures/textures/receiver_fb_off.png index 3decca5..aed3008 100644 Binary files a/mesecons_textures/textures/receiver_fb_off.png and b/mesecons_textures/textures/receiver_fb_off.png differ diff --git a/mesecons_textures/textures/receiver_fb_on.png b/mesecons_textures/textures/receiver_fb_on.png index 3715efd..0916736 100644 Binary files a/mesecons_textures/textures/receiver_fb_on.png and b/mesecons_textures/textures/receiver_fb_on.png differ diff --git a/mesecons_textures/textures/receiver_lr_off.png b/mesecons_textures/textures/receiver_lr_off.png index 50c602c..1fb2b3a 100644 Binary files a/mesecons_textures/textures/receiver_lr_off.png and b/mesecons_textures/textures/receiver_lr_off.png differ diff --git a/mesecons_textures/textures/receiver_lr_on.png b/mesecons_textures/textures/receiver_lr_on.png index 1eeda68..087c0b4 100644 Binary files a/mesecons_textures/textures/receiver_lr_on.png and b/mesecons_textures/textures/receiver_lr_on.png differ diff --git a/mesecons_textures/textures/receiver_top_off.png b/mesecons_textures/textures/receiver_top_off.png index 35bed5c..ae50106 100644 Binary files a/mesecons_textures/textures/receiver_top_off.png and b/mesecons_textures/textures/receiver_top_off.png differ diff --git a/mesecons_textures/textures/receiver_top_on.png b/mesecons_textures/textures/receiver_top_on.png index 158dda2..5b48cac 100644 Binary files a/mesecons_textures/textures/receiver_top_on.png and b/mesecons_textures/textures/receiver_top_on.png differ diff --git a/mesecons_walllever/init.lua b/mesecons_walllever/init.lua index da427be..6fc0770 100644 --- a/mesecons_walllever/init.lua +++ b/mesecons_walllever/init.lua @@ -1,22 +1,6 @@ -- WALL LEVER -local walllever_get_rules = function(node) - local rules = { - {x = 1, y = 0, z = 0}, - {x = 1, y = 1, z = 0}, - {x = 1, y =-1, z = 0}, - {x = 1, y =-1, z = 1}, - {x = 1, y =-1, z =-1}, - {x = 2, y = 0, z = 0}} - if node.param2 == 2 then - rules=mesecon:rotate_rules_left(rules) - elseif node.param2 == 3 then - rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) - elseif node.param2 == 0 then - rules=mesecon:rotate_rules_right(rules) - end - return rules -end - +-- Basically a switch that can be attached to a wall +-- Powers the block 2 nodes behind (using a receiver) minetest.register_node("mesecons_walllever:wall_lever_off", { drawtype = "nodebox", tiles = { @@ -49,10 +33,10 @@ minetest.register_node("mesecons_walllever:wall_lever_off", { description="Lever", on_punch = function (pos, node) mesecon:swap_node(pos, "mesecons_walllever:wall_lever_on") - mesecon:receptor_on(pos, walllever_get_rules(node)) + mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node)) end, - mesecon = {receptor = { - rules = walllever_get_rules, + mesecons = {receptor = { + rules = mesecon.rules.buttonlike_get, state = mesecon.state.off }} }) @@ -84,15 +68,15 @@ minetest.register_node("mesecons_walllever:wall_lever_on", { { -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge" { -1/16, 0, 4/16, 1/16, 8/16, 6/16 }} -- the lever itself. }, - groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 3, mesecon_needs_receiver = 1}, + groups = {dig_immediate = 2, not_in_creative_inventory = 1, mesecon_needs_receiver = 1}, drop = '"mesecons_walllever:wall_lever_off" 1', description="Lever", on_punch = function (pos, node) mesecon:swap_node(pos, "mesecons_walllever:wall_lever_off") - mesecon:receptor_off(pos, walllever_get_rules(node)) + mesecon:receptor_off(pos, mesecon.rules.buttonlike_get(node)) end, - mesecon = {receptor = { - rules = walllever_get_rules, + mesecons = {receptor = { + rules = mesecon.rules.buttonlike_get, state = mesecon.state.on }} }) -- cgit v1.2.3 From 05def1540a0defb99234bce994352a05f632f69f Mon Sep 17 00:00:00 2001 From: Jeija Date: Sun, 9 Dec 2012 15:32:29 +0100 Subject: Fix microcontroller digging --- mesecons_microcontroller/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 19fc42d..a359d05 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -129,7 +129,7 @@ minetest.register_node(nodename, { update_yc(pos) end, mesecons = mesecons, - on_dig = function (pos, node) + after_dig_node = function (pos, node) rules = mesecon:get_rules(node.name) mesecon:receptor_off(pos, rules) end, -- cgit v1.2.3 From d5825f9602cc293f5a6724b9f83e549ded1d4f83 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 10 Dec 2012 17:19:30 +0100 Subject: Fix insulated mesecon --- mesecons_gates/init.lua | 83 ++++++++++++++++++++++++++------------------- mesecons_insulated/init.lua | 18 +++++----- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index 8a4629f..67a090f 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -1,16 +1,20 @@ -outrules = { +local outrules = { {x=1, y=0, z=0}, } -oneinput = { + +local oneinput = { {x=-1, y=0, z=0}, {x=1, y=0, z=0}, } -twoinputs = { + +local twoinputs = { {x=0, y=0, z=1}, {x=0, y=0, z=-1}, {x=1, y=0, z=0}, } + function get_gate_rules(param2, onlyout, singleinput) + if not param2 then return end if onlyout then rules = outrules else @@ -20,15 +24,25 @@ function get_gate_rules(param2, onlyout, singleinput) rules = twoinputs end end - for rotations=0, param2-1 do + for rotations = 0, param2 - 1 do rules = mesecon:rotate_rules_left(rules) end return rules end -function get_gate_rules_one(param2) return get_gate_rules(param2, false, true) end -function get_gate_rules_two(param2) return get_gate_rules(param2, false, false) end -function get_gate_rules_out(param2) return get_gate_rules(param2, true) end +function get_gate_rules_one(node) + print("gettin"..dump(node).." | PARAM2: "..node.param2) + return get_gate_rules(node.param2, false, true) +end + +function get_gate_rules_two(node) + return get_gate_rules(node.param2, false, false) +end + +function get_gate_rules_out(node) + return get_gate_rules(node.param2, true) +end + gates = {"diode", "not", "nand", "and", "xor"} for g in ipairs(gates) do gate = gates[g] if g < 3 then @@ -43,15 +57,12 @@ for g in ipairs(gates) do gate = gates[g] drop = nodename.."_off" nodename = nodename.."_"..onoff description = "You hacker you!" - groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} - mesecon:add_receptor_node(nodename, get_rules, get_gate_rules_out) - --mesecon:add_receptor_node(nodename, mesecon:get_rules("insulated_all")) + groups = {dig_immediate=2, not_in_creative_inventory=1} else onoff = "off" nodename = nodename.."_"..onoff description = gate.." Gate" - groups = {dig_immediate=2, mesecon = 3} - --mesecon:add_receptor_node_off(nodename, get_gate_rules_out) + groups = {dig_immediate=2} end tiles = "jeija_microcontroller_bottom.png^".. @@ -65,6 +76,13 @@ for g in ipairs(gates) do gate = gates[g] }, } + local mesecon_state + if on == 1 then + mesecon_state = mesecon.state.on + else + mesecon_state = mesecon.state.off + end + minetest.register_node(nodename, { description = description, paramtype = "light", @@ -82,10 +100,22 @@ for g in ipairs(gates) do gate = gates[g] end, groups = groups, drop = drop, - + mesecons = + { + receptor = + { + state = mesecon_state, + rules = get_gate_rules_out + }, + effector = + { + rules = get_rules, + action_change = function (pos, node) + update_gate(pos) + end + } + } }) - - mesecon:register_effector(nodename, nodename, all_rules, get_rules) end end @@ -121,22 +151,11 @@ function set_gate(pos, on) if yc_overheat(meta) then pop_gate(pos) else - heat = meta:get_int("heat") - if on then - onoff = "_on" - else - onoff = "_off" - end - param2 = minetest.env:get_node(pos).param2 - minetest.env:add_node(pos, { - name = "mesecons_gates:"..gate..onoff, - param2 = param2, - }) - local meta2 = minetest.env:get_meta(pos) - meta2:set_int("heat", heat) if on then + mesecon:swap_node(pos, "mesecons_gates:"..gate.."_on") mesecon:receptor_on(pos, get_gate_rules(param2, true)) else + mesecon:swap_node(pos, "mesecons_gates:"..gate.."_off") mesecon:receptor_off(pos, all_rules) end end @@ -168,17 +187,11 @@ function update_gate(pos) set_gate(pos, not(L.b and L.d)) elseif gate == "and" then set_gate(pos, L.b and L.d) - else--if gate == "xor" then + elseif gate == "xor" then set_gate(pos, (L.b and not L.d) or (not L.b and L.d)) end end -mesecon:register_on_signal_change(function(pos,node) - if string.find(node.name, "mesecons_gates:")~=nil then - update_gate(pos) - end -end) - minetest.register_craft({ output = 'mesecons_gates:diode_off', recipe = { diff --git a/mesecons_insulated/init.lua b/mesecons_insulated/init.lua index fe929d6..8bf75c7 100644 --- a/mesecons_insulated/init.lua +++ b/mesecons_insulated/init.lua @@ -1,3 +1,12 @@ +function insulated_wire_get_rules(node) + local rules = {{x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}} + if node.param2 == 1 or node.param2 == 3 then + return mesecon:rotate_rules_right(rules) + end + return rules +end + minetest.register_node("mesecons_insulated:insulated_on", { drawtype = "nodebox", description = "insulated mesecons", @@ -73,12 +82,3 @@ minetest.register_craft({ mesecon:add_rules("insulated", { {x = 1, y = 0, z = 0}, {x =-1, y = 0, z = 0}}) - -function insulated_wire_get_rules(node) - local rules = {{x = 1, y = 0, z = 0}, - {x =-1, y = 0, z = 0}} - if param2 == 1 or param2 == 3 then - return mesecon:rotate_rules_right(rules) - end - return rules -end -- cgit v1.2.3 From 5904abbd79c1ee611f620b60c214823567f3a5f0 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 10 Dec 2012 19:46:24 +0100 Subject: Port gates (finally) --- mesecons/internal.lua | 55 +++++-------- mesecons_gates/init.lua | 214 ++++++++++++++++++++++-------------------------- 2 files changed, 118 insertions(+), 151 deletions(-) diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 8337f62..f6873ea 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -62,8 +62,7 @@ function mesecon:is_effector_on(nodename) if minetest.registered_nodes[nodename] and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector - and (minetest.registered_nodes[nodename].mesecons.effector.action_off - or minetest.registered_nodes[nodename].mesecons.effector.action_change) then + and minetest.registered_nodes[nodename].mesecons.effector.action_off then return true end for _, effector in ipairs(mesecon.effectors) do --TODO @@ -78,8 +77,7 @@ function mesecon:is_effector_off(nodename) if minetest.registered_nodes[nodename] and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons.effector - and (minetest.registered_nodes[nodename].mesecons.effector.action_on - or minetest.registered_nodes[nodename].mesecons.effector.action_change) then + and minetest.registered_nodes[nodename].mesecons.effector.action_on then return true end for _, effector in ipairs(mesecon.effectors) do --TODO @@ -109,12 +107,12 @@ function mesecon:effector_get_input_rules(node) return rules end end - for i, effector in ipairs(mesecon.effectors) do + for _, effector in ipairs(mesecon.effectors) do if effector.onstate == node.name or effector.offstate == node.name then if effector.get_input_rules ~= nil then return effector.get_input_rules(node.param2) - elseif mesecon.effectors[i].input_rules ~=nil then + elseif effector.input_rules ~=nil then return effector.input_rules else return mesecon:get_rules("default") @@ -126,8 +124,7 @@ end --Signals -function mesecon:activate(pos) - local node = minetest.env:get_node(pos) +function mesecon:activate(pos, node) if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.effector @@ -139,8 +136,7 @@ function mesecon:activate(pos) end end -function mesecon:deactivate(pos) --TODO - local node = minetest.env:get_node(pos) +function mesecon:deactivate(pos, node) --TODO if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.effector @@ -152,15 +148,14 @@ function mesecon:deactivate(pos) --TODO end end -function mesecon:changesignal(pos) --TODO - local node = minetest.env:get_node(pos) +function mesecon:changesignal(pos, node) --TODO if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].mesecons and minetest.registered_nodes[node.name].mesecons.effector and minetest.registered_nodes[node.name].mesecons.effector.action_change then minetest.registered_nodes[node.name].mesecons.effector.action_change(pos, node) end - for i, action in ipairs(mesecon.actions_change) do + for _, action in ipairs(mesecon.actions_change) do action(pos, node) end end @@ -168,15 +163,11 @@ end --Rules function mesecon:add_rules(name, rules) - table.insert(mesecon.rules, {name = name, rules = rules}) + mesecon.rules[name] = rules end function mesecon:get_rules(name) - for i, rule in ipairs(mesecon.rules) do - if rule.name==name then - return rule.rules - end - end + return mesecon.rules[name] end -- Conductors @@ -187,7 +178,7 @@ function mesecon:get_conductor_on(offstate) and minetest.registered_nodes[offstate].mesecons.conductor then return minetest.registered_nodes[offstate].mesecons.conductor.onstate end - for i, conductor in ipairs(mesecon.conductors) do --TODO + for _, conductor in ipairs(mesecon.conductors) do --TODO if conductor.offstate == offstate then return conductor.onstate end @@ -201,7 +192,7 @@ function mesecon:get_conductor_off(onstate) and minetest.registered_nodes[onstate].mesecons.conductor then return minetest.registered_nodes[onstate].mesecons.conductor.offstate end - for i, conductor in ipairs(mesecon.conductors) do --TODO + for _, conductor in ipairs(mesecon.conductors) do --TODO if conductor.onstate == onstate then return conductor.offstate end @@ -255,7 +246,7 @@ function mesecon:conductor_get_rules(node) return rules end end - for i, conductor in ipairs(mesecon.conductors) do --TODO + for _, conductor in ipairs(mesecon.conductors) do --TODO if conductor.onstate == node.name or conductor.offstate == node.name then if conductor.get_rules ~= nil then @@ -302,9 +293,9 @@ function mesecon:turnon(pos) end if mesecon:is_effector(node.name) then - mesecon:changesignal(pos) + mesecon:changesignal(pos, node) if mesecon:is_effector_off(node.name) then - mesecon:activate(pos) + mesecon:activate(pos, node) end end end @@ -326,10 +317,10 @@ function mesecon:turnoff(pos) --receptor rules used because output could have be end if mesecon:is_effector(node.name) then - mesecon:changesignal(pos) + mesecon:changesignal(pos, node) if mesecon:is_effector_on(node.name) and not mesecon:is_powered(pos) then - mesecon:deactivate(pos) + mesecon:deactivate(pos, node) end end end @@ -349,18 +340,14 @@ function mesecon:connected_to_pw_src(pos, checked) local node = minetest.env:get_node_or_nil(pos) if node == nil then return false, checked end + if not mesecon:is_conductor(node.name) then return false, checked end if mesecon:is_powered_by_receptor(pos) then --return if conductor is powered return true, checked end --Check if conductors around are connected - if mesecon:is_conductor(node.name) then - rules = mesecon:conductor_get_rules(node) - elseif mesecon:is_effector(node.name) then - rules = mesecon:effector_get_input_rules(node) - else - return false, checked - end + local connected + local rules = mesecon:conductor_get_rules(node) for _, rule in ipairs(rules) do local np = mesecon:addPosRule(pos, rule) @@ -465,7 +452,7 @@ function mesecon:is_powered_by_receptor(pos) return false end - for i, rule in ipairs(rules) do + for _, rule in ipairs(rules) do local rcpt_pos = mesecon:addPosRule(pos, rule) rcpt_node = minetest.env:get_node(rcpt_pos) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index 67a090f..dabefd5 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -1,57 +1,111 @@ -local outrules = { - {x=1, y=0, z=0}, -} +function gate_rotate_rules(node) + for rotations = 0, node.param2 - 1 do + rules = mesecon:rotate_rules_left(rules) + end + return rules +end -local oneinput = { - {x=-1, y=0, z=0}, - {x=1, y=0, z=0}, -} +function gate_get_output_rules(node) + rules = {{x=1, y=0, z=0}} + return gate_rotate_rules(node) +end + +function gate_get_input_rules_oneinput(node) + rules = {{x=-1, y=0, z=0}, {x=1, y=0, z=0}} + return gate_rotate_rules(node) +end -local twoinputs = { +function gate_get_input_rules_twoinputs(node) + rules = { {x=0, y=0, z=1}, {x=0, y=0, z=-1}, - {x=1, y=0, z=0}, -} - -function get_gate_rules(param2, onlyout, singleinput) - if not param2 then return end - if onlyout then - rules = outrules - else - if singleinput then - rules = oneinput + {x=1, y=0, z=0}} + return gate_rotate_rules(node) +end + +function update_gate(pos) + gate = get_gate(pos) + L = rotate_ports( + yc_get_real_portstates(pos), + minetest.env:get_node(pos).param2 + ) + if gate == "diode" then + set_gate(pos, L.a) + elseif gate == "not" then + set_gate(pos, not L.a) + elseif gate == "nand" then + set_gate(pos, not(L.b and L.d)) + elseif gate == "and" then + set_gate(pos, L.b and L.d) + elseif gate == "xor" then + set_gate(pos, (L.b and not L.d) or (not L.b and L.d)) + end +end + +function set_gate(pos, on) + gate = get_gate(pos) + local meta = minetest.env:get_meta(pos) + if on ~= gate_state(pos) then + yc_heat(meta) + minetest.after(0.5, yc_cool, meta) + if yc_overheat(meta) then + pop_gate(pos) else - rules = twoinputs + if on then + mesecon:swap_node(pos, "mesecons_gates:"..gate.."_on") + mesecon:receptor_on(pos, + gate_get_output_rules(minetest.env:get_node(pos))) + else + mesecon:swap_node(pos, "mesecons_gates:"..gate.."_off") + mesecon:receptor_off(pos, + gate_get_output_rules(minetest.env:get_node(pos))) + end end end - for rotations = 0, param2 - 1 do - rules = mesecon:rotate_rules_left(rules) - end - return rules end -function get_gate_rules_one(node) - print("gettin"..dump(node).." | PARAM2: "..node.param2) - return get_gate_rules(node.param2, false, true) +function get_gate(pos) + return minetest.registered_nodes[minetest.env:get_node(pos).name].mesecons_gate end -function get_gate_rules_two(node) - return get_gate_rules(node.param2, false, false) +function gate_state(pos) + name = minetest.env:get_node(pos).name + return string.find(name, "_on") ~= nil end -function get_gate_rules_out(node) - return get_gate_rules(node.param2, true) +function pop_gate(pos) + gate = get_gate(pos) + minetest.env:remove_node(pos) + minetest.after(0.2, yc_overheat_off, pos) + minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off") +end + +function rotate_ports(L, param2) + for rotations=0, param2-1 do + port = L.a + L.a = L.b + L.b = L.c + L.c = L.d + L.d = port + end + return L end -gates = {"diode", "not", "nand", "and", "xor"} -for g in ipairs(gates) do gate = gates[g] - if g < 3 then - get_rules = get_gate_rules_one - else - get_rules = get_gate_rules_two +gates = { +{name = "diode", inputnumber = 1}, +{name = "not" , inputnumber = 1}, +{name = "nand" , inputnumber = 2}, +{name = "and" , inputnumber = 2}, +{name = "xor" , inputnumber = 2}} + +for i, gate in ipairs(gates) do + if gate.inputnumber == 1 then + get_rules = gate_get_input_rules_oneinput + elseif gate.inputnumber == 2 then + get_rules = gate_get_input_rules_twoinputs end - for on=0,1 do - nodename = "mesecons_gates:"..gate + for on = 0, 1 do + nodename = "mesecons_gates:"..gate.name if on == 1 then onoff = "on" drop = nodename.."_off" @@ -61,13 +115,13 @@ for g in ipairs(gates) do gate = gates[g] else onoff = "off" nodename = nodename.."_"..onoff - description = gate.." Gate" + description = gate.name.." Gate" groups = {dig_immediate=2} end tiles = "jeija_microcontroller_bottom.png^".. "jeija_gate_"..onoff..".png^".. - "jeija_gate_"..gate..".png" + "jeija_gate_"..gate.name..".png" node_box = { type = "fixed", @@ -100,98 +154,24 @@ for g in ipairs(gates) do gate = gates[g] end, groups = groups, drop = drop, + mesecons_gate = gate.name, mesecons = { receptor = { state = mesecon_state, - rules = get_gate_rules_out + rules = gate_get_output_rules }, effector = { rules = get_rules, - action_change = function (pos, node) - update_gate(pos) - end + action_change = update_gate } } }) end end -function get_gate(pos) - return - string.gsub( - string.gsub( - string.gsub( - minetest.env:get_node(pos).name - , "mesecons_gates:", "") --gate - ,"_on", "") - ,"_off", "") -end - -function gate_state(pos) - name = minetest.env:get_node(pos).name - return string.find(name, "_on") ~= nil -end - -function pop_gate(pos) - gate = get_gate(pos) - minetest.env:remove_node(pos) - minetest.after(0.2, yc_overheat_off, pos) - minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off") -end - -function set_gate(pos, on) - gate = get_gate(pos) - local meta = minetest.env:get_meta(pos) - if on ~= gate_state(pos) then - yc_heat(meta) - minetest.after(0.5, yc_cool, meta) - if yc_overheat(meta) then - pop_gate(pos) - else - if on then - mesecon:swap_node(pos, "mesecons_gates:"..gate.."_on") - mesecon:receptor_on(pos, get_gate_rules(param2, true)) - else - mesecon:swap_node(pos, "mesecons_gates:"..gate.."_off") - mesecon:receptor_off(pos, all_rules) - end - end - end -end - -function rotate_ports(L, param2) - for rotations=0, param2-1 do - port = L.a - L.a = L.b - L.b = L.c - L.c = L.d - L.d = port - end - return L -end - -function update_gate(pos) - gate = get_gate(pos) - L = rotate_ports( - yc_get_real_portstates(pos), - minetest.env:get_node(pos).param2 - ) - if gate == "diode" then - set_gate(pos, L.a) - elseif gate == "not" then - set_gate(pos, not L.a) - elseif gate == "nand" then - set_gate(pos, not(L.b and L.d)) - elseif gate == "and" then - set_gate(pos, L.b and L.d) - elseif gate == "xor" then - set_gate(pos, (L.b and not L.d) or (not L.b and L.d)) - end -end - minetest.register_craft({ output = 'mesecons_gates:diode_off', recipe = { -- cgit v1.2.3 From e9f2beb2c60f407fbd225888668fb4dc0a5fb369 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 10 Dec 2012 20:39:12 +0100 Subject: Slightly change wire look (may be reverted?) --- mesecons/wires.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/mesecons/wires.lua b/mesecons/wires.lua index d6d92e2..3f4e345 100644 --- a/mesecons/wires.lua +++ b/mesecons/wires.lua @@ -41,7 +41,6 @@ else -- NEW STYLE WIRES box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/16, 1/16} box_bump1 = { -2/16, -8/16, -2/16, 2/16, -13/32, 2/16 } -box_bump2 = { -3/32, -13/32, -3/32, 3/32, -12/32, 3/32 } box_xp = {1/16, -.5, -1/16, 8/16, -.5+1/16, 1/16} box_zp = {-1/16, -.5, 1/16, 1/16, -.5+1/16, 8/16} @@ -90,7 +89,6 @@ for zmy=0, 1 do if adjx and adjz and (xp + zp + xm + zm > 2) then table.insert(nodebox, box_bump1) - table.insert(nodebox, box_bump2) tiles_off = { "wires_bump_off.png", "wires_bump_off.png", -- cgit v1.2.3 From 59a39204a9dc5ccc108bb2e51421fc7821ffeaa1 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 10 Dec 2012 20:55:13 +0100 Subject: Remove dead parts of the mod/dead textures/wireless mesecons --- mesecons_dev/README | 4 - mesecons_dev/init.lua | 1 - mesecons_dev/mesecons_wireless/depends.txt | 2 - mesecons_dev/mesecons_wireless/init.lua | 313 --------------------- mesecons_textures/textures/jeija_ic.png | Bin 462 -> 0 bytes .../textures/jeija_wireless_inverter_off.png | Bin 635 -> 0 bytes .../textures/jeija_wireless_inverter_on.png | Bin 715 -> 0 bytes .../textures/jeija_wireless_inverter_tb.png | Bin 678 -> 0 bytes .../textures/jeija_wireless_receiver_off.png | Bin 579 -> 0 bytes .../textures/jeija_wireless_receiver_on.png | Bin 620 -> 0 bytes .../textures/jeija_wireless_receiver_tb_off.png | Bin 678 -> 0 bytes .../textures/jeija_wireless_receiver_tb_on.png | Bin 678 -> 0 bytes .../textures/jeija_wireless_transmitter_off.png | Bin 590 -> 0 bytes .../textures/jeija_wireless_transmitter_on.png | Bin 621 -> 0 bytes .../textures/jeija_wireless_transmitter_tb.png | Bin 678 -> 0 bytes 15 files changed, 320 deletions(-) delete mode 100644 mesecons_dev/README delete mode 100644 mesecons_dev/init.lua delete mode 100644 mesecons_dev/mesecons_wireless/depends.txt delete mode 100644 mesecons_dev/mesecons_wireless/init.lua delete mode 100644 mesecons_textures/textures/jeija_ic.png delete mode 100644 mesecons_textures/textures/jeija_wireless_inverter_off.png delete mode 100644 mesecons_textures/textures/jeija_wireless_inverter_on.png delete mode 100644 mesecons_textures/textures/jeija_wireless_inverter_tb.png delete mode 100644 mesecons_textures/textures/jeija_wireless_receiver_off.png delete mode 100644 mesecons_textures/textures/jeija_wireless_receiver_on.png delete mode 100644 mesecons_textures/textures/jeija_wireless_receiver_tb_off.png delete mode 100644 mesecons_textures/textures/jeija_wireless_receiver_tb_on.png delete mode 100644 mesecons_textures/textures/jeija_wireless_transmitter_off.png delete mode 100644 mesecons_textures/textures/jeija_wireless_transmitter_on.png delete mode 100644 mesecons_textures/textures/jeija_wireless_transmitter_tb.png diff --git a/mesecons_dev/README b/mesecons_dev/README deleted file mode 100644 index c8a3abd..0000000 --- a/mesecons_dev/README +++ /dev/null @@ -1,4 +0,0 @@ -Please note: -The mesecons modules in here have been disabled for various reasons: -They are old and deprecated, are not needed anymore or are buggy atm. -You can create a module out of them, but it is not recommended to use any of them. diff --git a/mesecons_dev/init.lua b/mesecons_dev/init.lua deleted file mode 100644 index 0613ab3..0000000 --- a/mesecons_dev/init.lua +++ /dev/null @@ -1 +0,0 @@ ---read README diff --git a/mesecons_dev/mesecons_wireless/depends.txt b/mesecons_dev/mesecons_wireless/depends.txt deleted file mode 100644 index bc7b062..0000000 --- a/mesecons_dev/mesecons_wireless/depends.txt +++ /dev/null @@ -1,2 +0,0 @@ -mesecons -mesecons_materials diff --git a/mesecons_dev/mesecons_wireless/init.lua b/mesecons_dev/mesecons_wireless/init.lua deleted file mode 100644 index b024499..0000000 --- a/mesecons_dev/mesecons_wireless/init.lua +++ /dev/null @@ -1,313 +0,0 @@ ---COMMON WIRELESS FUNCTIONS - -mesecon.wireless_receivers={} - -function mesecon:read_wlre_from_file() - print "[MESEcons] Reading Mesecon Data..." - mesecon_file=io.open(minetest.get_modpath("jeija").."/mesecon_data", "r") - if mesecon_file==nil then return end - local row=mesecon_file:read() - local i=1 - while row~=nil do - mesecon.wireless_receivers[i]={} - mesecon.wireless_receivers[i].pos={} - mesecon.wireless_receivers[i].pos.x=tonumber(mesecon_file:read()) - mesecon.wireless_receivers[i].pos.y=tonumber(mesecon_file:read()) - mesecon.wireless_receivers[i].pos.z=tonumber(mesecon_file:read()) - mesecon.wireless_receivers[i].channel=mesecon_file:read() - mesecon.wireless_receivers[i].requested_state=tonumber(mesecon_file:read()) - mesecon.wireless_receivers[i].inverting=tonumber(mesecon_file:read()) - i=i+1 - row=mesecon_file:read() - end - mesecon_file:close() - print "[MESEcons] Finished Reading Mesecon Data..." -end - - -function mesecon:register_wireless_receiver(pos, inverting) - local i = 1 - repeat - if mesecon.wireless_receivers[i]==nil then break end - i=i+1 - until false - - - local node_under_pos={} - node_under_pos.x=pos.x - node_under_pos.y=pos.y - node_under_pos.z=pos.z - - node_under_pos.y=node_under_pos.y-1 - local node_under=minetest.env:get_node(node_under_pos) - mesecon.wireless_receivers[i]={} - mesecon.wireless_receivers[i].pos={} - mesecon.wireless_receivers[i].pos.x=pos.x - mesecon.wireless_receivers[i].pos.y=pos.y - mesecon.wireless_receivers[i].pos.z=pos.z - mesecon.wireless_receivers[i].channel=node_under.name - mesecon.wireless_receivers[i].requested_state=0 - mesecon.wireless_receivers[i].inverting=inverting -end - -function mesecon:remove_wireless_receiver(pos) - local i = 1 - while mesecon.wireless_receivers[i]~=nil do - if mesecon.wireless_receivers[i].pos.x==pos.x and - mesecon.wireless_receivers[i].pos.y==pos.y and - mesecon.wireless_receivers[i].pos.z==pos.z then - mesecon.wireless_receivers[i]=nil - break - end - i=i+1 - end -end - -function mesecon:set_wlre_channel(pos, channel) - --local i = 1 - --while mesecon.wireless_receivers[i]~=nil do - -- if tonumber(mesecon.wireless_receivers[i].pos.x)==tonumber(pos.x) and - -- tonumber(mesecon.wireless_receivers[i].pos.y)==tonumber(pos.y) and - -- tonumber(mesecon.wireless_receivers[i].pos.z)==tonumber(pos.z) then - -- mesecon.wireless_receivers[i].channel=channel - -- break - -- end - -- i=i+1 - --end - local wlre=mesecon:get_wlre(pos) - if wlre~=nil then - wlre.channel=channel - end -end - -function mesecon:get_wlre(pos) - local i=1 - while mesecon.wireless_receivers[i]~=nil do - if mesecon.wireless_receivers[i].pos.x==pos.x and - mesecon.wireless_receivers[i].pos.y==pos.y and - mesecon.wireless_receivers[i].pos.z==pos.z then - return mesecon.wireless_receivers[i] - end - i=i+1 - end -end - -minetest.register_on_placenode(function(pos, newnode, placer) - pos.y=pos.y+1 - if minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_off" or - minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_on" or - minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_off" or - minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_on" then - mesecon:set_wlre_channel(pos, newnode.name) - end -end) - -minetest.register_on_dignode( - function(pos, oldnode, digger) - local channel - pos.y=pos.y+1 - if minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_on" or - minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_off" or - minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_on" or - minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_off" then - mesecon:set_wlre_channel(pos, "air") - end - end -) - -minetest.register_abm( - {nodenames = {"mesecons_wireless:wireless_receiver_on", "mesecons_wireless:wireless_receiver_off", - "mesecons_wireless:wireless_inverter_on", "mesecons_wireless:wireless_inverter_off"}, - interval = 1.0, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local wlre=mesecon:get_wlre(pos) - if (wlre==nil) then return end - - if node.name=="mesecons_wireless:wireless_receiver_on" and wlre.requested_state==0 then - minetest.env:add_node(pos, {name="mesecons_wireless:wireless_receiver_off"}) - mesecon:receptor_off(pos) - end - if node.name=="mesecons_wireless:wireless_receiver_off" and wlre.requested_state==1 then - minetest.env:add_node(pos, {name="mesecons_wireless:wireless_receiver_on"}) - mesecon:receptor_on(pos) - end - if node.name=="mesecons_wireless:wireless_inverter_off" and wlre.requested_state==0 and wlre.inverting==1 then - minetest.env:add_node(pos, {name="mesecons_wireless:wireless_inverter_on"}) - mesecon:receptor_on(pos) - end - if node.name=="mesecons_wireless:wireless_inverter_on" and wlre.requested_state==1 and wlre.inverting==1 then - minetest.env:add_node(pos, {name="mesecons_wireless:wireless_inverter_off"}) - mesecon:receptor_off(pos) - end - end, -}) - ---WIRELESS RECEIVER - -minetest.register_node("mesecons_wireless:wireless_receiver_off", { - tile_images = {"jeija_wireless_receiver_tb_off.png", "jeija_wireless_receiver_tb_off.png", "jeija_wireless_receiver_off.png", "jeija_wireless_receiver_off.png", "jeija_wireless_receiver_off.png", "jeija_wireless_receiver_off.png"}, - inventory_image = minetest.inventorycube("jeija_wireless_receiver_off.png"), - groups = {choppy=2}, - description="Wireless Receiver", - after_place_node = function(pos) - mesecon:register_wireless_receiver(pos, 0) - end, - after_dig_node = function(pos) - mesecon:remove_wireless_receiver(pos) - mesecon:receptor_off(pos) - end -}) - -minetest.register_node("mesecons_wireless:wireless_receiver_on", { - tile_images = {"jeija_wireless_receiver_tb_on.png", "jeija_wireless_receiver_tb_on.png", "jeija_wireless_receiver_on.png", "jeija_wireless_receiver_on.png", "jeija_wireless_receiver_on.png", "jeija_wireless_receiver_on.png"}, - inventory_image = minetest.inventorycube("jeija_wireless_receiver_on.png"), - groups = {choppy=2}, - drop = 'mesecons_wireless:wireless_receiver_off', - description="Wireless Receiver", - after_place_node = function(pos) - mesecon:register_wireless_receiver(pos, 0) - end, - after_dig_node = function(pos) - mesecon:remove_wireless_receiver(pos) - end -}) - -minetest.register_craft({ - output = '"mesecons_wireless:wireless_receiver_off" 2', - recipe = { - {'', "group:mesecon_conductor_craftable", ''}, - {'', "group:mesecon_conductor_craftable", ''}, - {'', "mesecons_materials:ic", ''}, - } -}) - -minetest.register_abm( -- SAVE WIRELESS RECEIVERS TO FILE - {nodenames = {"mesecons_wireless:wireless_receiver_off", "mesecons_wireless:wireless_receiver_on", "mesecons_wireless:wireless_inverter_on", "mesecons_wireless:wireless_inverter_off"}, - interval = 10, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local mesecon_file = io.open(minetest.get_modpath("jeija").."/mesecon_data", "w") - local i=1 - while mesecon.wireless_receivers[i]~=nil do - mesecon_file:write("NEXT\n") - mesecon_file:write(mesecon.wireless_receivers[i].pos.x.."\n") - mesecon_file:write(mesecon.wireless_receivers[i].pos.y.."\n") - mesecon_file:write(mesecon.wireless_receivers[i].pos.z.."\n") - mesecon_file:write(mesecon.wireless_receivers[i].channel.."\n") - mesecon_file:write(mesecon.wireless_receivers[i].requested_state.."\n") - mesecon_file:write(mesecon.wireless_receivers[i].inverting.."\n") - i=i+1 - end - mesecon_file:close() - end, -}) - -mesecon:add_receptor_node("mesecons_wireless:wireless_receiver_on") -mesecon:add_receptor_node_off("mesecons_wireless:wireless_receiver_off") - --- WIRELESS INVERTER OFF/ON BELONGS TO THE OUTPUT STATE (ON=INPUT OFF) - -minetest.register_node("mesecons_wireless:wireless_inverter_off", { - tile_images = {"jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_off.png", "jeija_wireless_inverter_off.png", "jeija_wireless_inverter_off.png", "jeija_wireless_inverter_off.png"}, - inventory_image = minetest.inventorycube("jeija_wireless_inverter_off.png"), - groups = {choppy=2}, - drop = 'mesecons_wireless:wireless_inverter_on', - description = "Wireless Inverter", - after_place_node = function(pos) - mesecon:register_wireless_receiver(pos, 1) - mesecon:receptor_on(pos) - end, - after_dig_node = function(pos) - mesecon:remove_wireless_receiver(pos) - end -}) - -minetest.register_node("mesecons_wireless:wireless_inverter_on", { - tile_images = {"jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_on.png", "jeija_wireless_inverter_on.png", "jeija_wireless_inverter_on.png", "jeija_wireless_inverter_on.png"}, - inventory_image = minetest.inventorycube("jeija_wireless_inverter_on.png"), - groups = {choppy=2}, - description = "Wireless Inverter", - after_place_node = function(pos) - mesecon:register_wireless_receiver(pos, 1) - mesecon:receptor_on(pos) - end, - after_dig_node = function(pos) - mesecon:remove_wireless_receiver(pos) - mesecon:receptor_off(pos) - end -}) - -minetest.register_craft({ - output = '"mesecons_wireless:wireless_inverter_off" 2', - recipe = { - {'', 'default:steel_ingot', ''}, - {'mesecons_materials:ic', 'group:mesecon_conductor_craftable', 'mesecons_materials:ic'}, - {'', 'group:mesecon_conductor_craftable', ''}, - } -}) - -mesecon:add_receptor_node("mesecons_wireless:wireless_inverter_on") -mesecon:add_receptor_node_off("mesecons_wireless:wireless_inverter_off") - --- WIRELESS TRANSMITTER - -function mesecon:wireless_transmit(channel, senderstate) - local i = 1 - while mesecon.wireless_receivers[i]~=nil do - if mesecon.wireless_receivers[i].channel==channel then - if senderstate==1 then - mesecon.wireless_receivers[i].requested_state=1 - elseif senderstate==0 then - mesecon.wireless_receivers[i].requested_state=0 - end - end - i=i+1 - end -end - -minetest.register_node("mesecons_wireless:wireless_transmitter_on", { - tile_images = {"jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_on.png", "jeija_wireless_transmitter_on.png", "jeija_wireless_transmitter_on.png", "jeija_wireless_transmitter_on.png"}, - inventory_image = minetest.inventorycube("jeija_wireless_transmitter_on.png"), - groups = {choppy=2}, - drop = {'"mesecons_wireless:wireless_transmitter_off" 1'}, - description="Wireless Transmitter", -}) - -minetest.register_node("mesecons_wireless:wireless_transmitter_off", { - tile_images = {"jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_off.png", "jeija_wireless_transmitter_off.png", "jeija_wireless_transmitter_off.png", "jeija_wireless_transmitter_off.png"}, - inventory_image = minetest.inventorycube("jeija_wireless_transmitter_off.png"), - groups = {choppy=2}, - description="Wireless Transmitter", -}) - -minetest.register_craft({ - output = '"mesecons_wireless:wireless_transmitter_off" 2', - recipe = { - {'default:steel_ingot', 'group:mesecon_conductor_craftable', 'default:steel_ingot'}, - {'', 'group:mesecon_conductor_craftable', ''}, - {'', 'mesecons_materials:ic', ''}, - } -}) - -mesecon:register_on_signal_on(function(pos, node) - if node.name=="mesecons_wireless:wireless_transmitter_off" then - minetest.env:add_node(pos, {name="mesecons_wireless:wireless_transmitter_on"}) - local node_under_pos=pos - node_under_pos.y=node_under_pos.y-1 - local node_under=minetest.env:get_node(node_under_pos) - mesecon:wireless_transmit(node_under.name, 1) - end -end) - -mesecon:register_on_signal_off(function(pos, node) - if node.name=="mesecons_wireless:wireless_transmitter_on" then - minetest.env:add_node(pos, {name="mesecons_wireless:wireless_transmitter_off"}) - local node_under_pos=pos - node_under_pos.y=node_under_pos.y-1 - local node_under=minetest.env:get_node(node_under_pos) - mesecon:wireless_transmit(node_under.name, 0) - end -end) - -mesecon:read_wlre_from_file() diff --git a/mesecons_textures/textures/jeija_ic.png b/mesecons_textures/textures/jeija_ic.png deleted file mode 100644 index 77b551e..0000000 Binary files a/mesecons_textures/textures/jeija_ic.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_inverter_off.png b/mesecons_textures/textures/jeija_wireless_inverter_off.png deleted file mode 100644 index c63e9b7..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_inverter_off.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_inverter_on.png b/mesecons_textures/textures/jeija_wireless_inverter_on.png deleted file mode 100644 index 437c7fc..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_inverter_on.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_inverter_tb.png b/mesecons_textures/textures/jeija_wireless_inverter_tb.png deleted file mode 100644 index f3c9201..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_inverter_tb.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_receiver_off.png b/mesecons_textures/textures/jeija_wireless_receiver_off.png deleted file mode 100644 index abc9456..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_receiver_off.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_receiver_on.png b/mesecons_textures/textures/jeija_wireless_receiver_on.png deleted file mode 100644 index 6ca254f..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_receiver_on.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_receiver_tb_off.png b/mesecons_textures/textures/jeija_wireless_receiver_tb_off.png deleted file mode 100644 index c589f37..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_receiver_tb_off.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_receiver_tb_on.png b/mesecons_textures/textures/jeija_wireless_receiver_tb_on.png deleted file mode 100644 index 4a2157e..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_receiver_tb_on.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_transmitter_off.png b/mesecons_textures/textures/jeija_wireless_transmitter_off.png deleted file mode 100644 index 3cc2504..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_transmitter_off.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_transmitter_on.png b/mesecons_textures/textures/jeija_wireless_transmitter_on.png deleted file mode 100644 index e098068..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_transmitter_on.png and /dev/null differ diff --git a/mesecons_textures/textures/jeija_wireless_transmitter_tb.png b/mesecons_textures/textures/jeija_wireless_transmitter_tb.png deleted file mode 100644 index 839071f..0000000 Binary files a/mesecons_textures/textures/jeija_wireless_transmitter_tb.png and /dev/null differ -- cgit v1.2.3 From 192b9eca4fa5fd2075711fff5bdc1f06aad2e018 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 10 Dec 2012 21:14:03 +0100 Subject: Fix crash when digging unknown nodes --- mesecons/wires.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mesecons/wires.lua b/mesecons/wires.lua index 3f4e345..bea84dd 100644 --- a/mesecons/wires.lua +++ b/mesecons/wires.lua @@ -191,17 +191,15 @@ end end end -minetest.register_on_placenode(function(pos, node) - if minetest.registered_nodes[node.name].mesecons then +local update_on_place_dig = function (pos, node) + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].mesecons then mesecon:update_autoconnect(pos) end -end) +end -minetest.register_on_dignode(function(pos, node) - if minetest.registered_nodes[node.name].mesecons then - mesecon:update_autoconnect(pos) - end -end) +minetest.register_on_placenode(update_on_place_dig) +minetest.register_on_dignode(update_on_place_dig) function mesecon:update_autoconnect(pos, secondcall, replace_old) local xppos = {x=pos.x+1, y=pos.y, z=pos.z} -- cgit v1.2.3 From a55874b5d2d66b8fc2baa7c9514c41df68ec6049 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 10 Dec 2012 22:05:13 +0100 Subject: Fix blinky plant bug (crash when placing mesecon next to it) --- mesecons_blinkyplant/init.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/mesecons_blinkyplant/init.lua b/mesecons_blinkyplant/init.lua index 9571359..853354d 100644 --- a/mesecons_blinkyplant/init.lua +++ b/mesecons_blinkyplant/init.lua @@ -70,6 +70,3 @@ minetest.register_abm({ mesecon:receptor_off(pos) end, }) - -mesecon:add_receptor_node("mesecons_blinkyplant:blinky_plant_on") -mesecon:add_receptor_node_off("mesecons_blinkyplant:blinky_plant_off") -- cgit v1.2.3 From 5540fcbcb31eb32003fa0391113ed3b1dea25e47 Mon Sep 17 00:00:00 2001 From: Jeija Date: Tue, 11 Dec 2012 18:15:44 +0100 Subject: Fix a bug reported here: http://minetest.net/forum/viewtopic.php?pid=56152#p56152 --- mesecons_lightstone/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mesecons_lightstone/init.lua b/mesecons_lightstone/init.lua index d8b523c..aa0c9b3 100644 --- a/mesecons_lightstone/init.lua +++ b/mesecons_lightstone/init.lua @@ -6,8 +6,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) description=name.." Lightstone", mesecons = {effector = { action_on = function (pos, node) - minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_on"}) - mesecon:receptor_on(pos) + mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_on") end }} }) @@ -19,8 +18,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) light_source = LIGHT_MAX-2, mesecons = {effector = { action_off = function (pos, node) - minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_off"}) - mesecon:receptor_off(pos) + mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_off") end }} }) -- cgit v1.2.3