Use minetest.swap_node() instead of mesecons' version, Minor code changes

here and there to facilitate this.
This commit is contained in:
Vanessa Ezekowitz 2013-11-30 20:20:01 -05:00
parent 669e3d0880
commit f46bc329de
15 changed files with 40 additions and 44 deletions

View File

@ -10,7 +10,7 @@ mesecon.on_placenode = function (pos, node)
mesecon:activate(pos, node)
end
elseif mesecon:is_conductor_on(node.name) then
mesecon:swap_node(pos, mesecon:get_conductor_off(node.name))
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node.name)})
elseif mesecon:is_effector_on (node.name) then
mesecon:deactivate(pos, node)
end

View File

@ -1,11 +1,3 @@
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:move_node(pos, newpos)
local node = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos):to_table()

View File

@ -62,7 +62,7 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
state = mesecon.state.on
}},
on_punch = function(pos, node, puncher)
mesecon:swap_node(pos, "mesecons_blinkyplant:blinky_plant")
minetest.swap_node(pos, {name = "mesecons_blinkyplant:blinky_plant"})
mesecon:receptor_off(pos)
end
})

View File

@ -5,7 +5,7 @@
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")
minetest.swap_node(pos, {name = "mesecons_button:button_off", param2=node.param2})
minetest.sound_play("mesecons_button_pop", {pos=pos})
local rules = mesecon.rules.buttonlike_get(node)
mesecon:receptor_off(pos, rules)
@ -41,7 +41,7 @@ minetest.register_node("mesecons_button:button_off", {
groups = {dig_immediate=2, mesecon_needs_receiver = 1},
description = "Button",
on_punch = function (pos, node)
mesecon:swap_node(pos, "mesecons_button:button_on")
minetest.swap_node(pos, {name = "mesecons_button:button_on", param2=node.param2})
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_button_push", {pos=pos})
minetest.after(1, mesecon.button_turnoff, pos)

View File

@ -144,7 +144,7 @@ local commandblock_action_on = function(pos, node)
return
end
mesecon:swap_node(pos, "mesecons_commandblock:commandblock_on")
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_on"})
local meta = minetest.env:get_meta(pos)
local command = minetest.chatcommands[meta:get_string("command")]
@ -166,7 +166,7 @@ end
local commandblock_action_off = function(pos, node)
if node.name == "mesecons_commandblock:commandblock_on" then
mesecon:swap_node(pos, "mesecons_commandblock:commandblock_off")
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_off"})
end
end

View File

@ -30,14 +30,14 @@ end
local delayer_activate = function(pos, node)
local def = minetest.registered_nodes[node.name]
local time = def.delayer_time
mesecon:swap_node(pos, def.delayer_onstate)
minetest.swap_node(pos, {name = def.delayer_onstate, param2=node.param2})
minetest.after(time, delayer_turnon , {pos = pos, node = node})
end
local delayer_deactivate = function(pos, node)
local def = minetest.registered_nodes[node.name]
local time = def.delayer_time
mesecon:swap_node(pos, def.delayer_offstate)
minetest.swap_node(pos, {name = def.delayer_offstate, param2=node.param2})
minetest.after(time, delayer_turnoff, {pos = pos, node = node})
end
@ -99,13 +99,13 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
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")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_2", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_off_2" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_3")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_3", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_off_3" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_4")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_4", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_off_4" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_1", param2=node.param2})
end
end,
delayer_time = delaytime,
@ -154,13 +154,13 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
drop = 'mesecons_delayer:delayer_off_1',
on_punch = function (pos, node)
if node.name=="mesecons_delayer:delayer_on_1" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_2")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_2", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_on_2" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_3")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_3", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_on_3" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_4")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_4", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_on_4" then
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1")
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_1", param2=node.param2})
end
end,
delayer_time = delaytime,

View File

@ -88,7 +88,7 @@ minetest.register_abm(
chance = 1,
action = function(pos)
if object_detector_scan(pos) then
mesecon:swap_node(pos, "mesecons_detector:object_detector_on")
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_on"})
mesecon:receptor_on(pos)
end
end,
@ -100,7 +100,7 @@ minetest.register_abm(
chance = 1,
action = function(pos)
if not object_detector_scan(pos) then
mesecon:swap_node(pos, "mesecons_detector:object_detector_off")
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_off"})
mesecon:receptor_off(pos)
end
end,

View File

@ -51,14 +51,15 @@ function set_gate(pos, on)
if yc_overheat(meta) then
pop_gate(pos)
else
local node = minetest.get_node(pos)
if on then
mesecon:swap_node(pos, "mesecons_gates:"..gate.."_on")
minetest.swap_node(pos, {name = "mesecons_gates:"..gate.."_on", param2=node.param2})
mesecon:receptor_on(pos,
gate_get_output_rules(minetest.env:get_node(pos)))
gate_get_output_rules(node))
else
mesecon:swap_node(pos, "mesecons_gates:"..gate.."_off")
minetest.swap_node(pos, {name = "mesecons_gates:"..gate.."_off", param2=node.param2})
mesecon:receptor_off(pos,
gate_get_output_rules(minetest.env:get_node(pos)))
gate_get_output_rules(node))
end
end
end

View File

@ -25,7 +25,7 @@ minetest.register_node("mesecons_lamp:lamp_on", {
sounds = default.node_sound_glass_defaults(),
mesecons = {effector = {
action_off = function (pos, node)
mesecon:swap_node(pos, "mesecons_lamp:lamp_off")
minetest.swap_node(pos, {name = "mesecons_lamp:lamp_off", param2 = node.param2})
end
}}
})
@ -46,7 +46,7 @@ minetest.register_node("mesecons_lamp:lamp_off", {
sounds = default.node_sound_glass_defaults(),
mesecons = {effector = {
action_on = function (pos, node)
mesecon:swap_node(pos, "mesecons_lamp:lamp_on")
minetest.swap_node(pos, {name = "mesecons_lamp:lamp_on", param2 = node.param2})
end
}}
})

View File

@ -6,7 +6,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = {
action_on = function (pos, node)
mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_on")
minetest.swap_node(pos, {name = "mesecons_lightstone:lightstone_" .. name .. "_on", param2 = node.param2})
end
}}
})
@ -18,7 +18,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = {
action_off = function (pos, node)
mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_off")
minetest.swap_node(pos, {name = "mesecons_lightstone:lightstone_" .. name .. "_off", param2 = node.param2})
end
}}
})

View File

@ -72,7 +72,8 @@ local setport = function (pos, rule, state)
end
local action = function (pos, ports)
local name = minetest.env:get_node(pos).name
local node = minetest.get_node(pos)
local name = node.name
local vports = minetest.registered_nodes[name].virtual_portstates
local newname = generate_name(ports)
@ -80,7 +81,7 @@ local action = function (pos, ports)
local rules_on = {}
local rules_off = {}
mesecon:swap_node(pos, newname)
minetest.swap_node(pos, {name = newname, param2 = node.param2})
if ports.a ~= vports.a then setport(pos, rules.a, ports.a) end
if ports.b ~= vports.b then setport(pos, rules.b, ports.b) end
@ -285,7 +286,8 @@ local do_overheat = function (pos, meta)
heat(meta)
--minetest.after(0.5, cool, meta)
if overheat(meta) then
mesecon:swap_node(pos, BASENAME.."_burnt")
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2})
minetest.env:get_meta(pos):set_string("lc_interrupts", "")
minetest.after(0.2, overheat_off, pos) -- wait for pending operations
return true

View File

@ -590,7 +590,8 @@ function yc_action(pos, L) --L-->Lvirtual
..tonumber(L.c and 1 or 0)
..tonumber(L.b and 1 or 0)
..tonumber(L.a and 1 or 0)
mesecon:swap_node(pos, name)
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = name, param2 = node.param2})
yc_action_setports(pos, L, Lv)
end

View File

@ -10,7 +10,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_off", {
state = mesecon.state.off
}},
on_punch = function(pos, node)
mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_on")
minetest.swap_node(pos, {name = "mesecons_switch:mesecon_switch_on", param2 = node.param2})
mesecon:receptor_on(pos)
minetest.sound_play("mesecons_switch", {pos=pos})
end
@ -26,7 +26,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_on", {
state = mesecon.state.on
}},
on_punch = function(pos, node)
mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_off")
minetest.swap_node(pos, {name = "mesecons_switch:mesecon_switch_off", param2 = node.param2})
mesecon:receptor_off(pos)
minetest.sound_play("mesecons_switch", {pos=pos})
end

View File

@ -99,11 +99,11 @@ minetest.register_abm({
if is_powered then
if node.name == "mesecons_torch:mesecon_torch_on" then
mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_off")
minetest.swap_node(pos, {name = "mesecons_torch:mesecon_torch_off", param2 = node.param2})
mesecon:receptor_off(pos, torch_get_output_rules(node))
end
elseif node.name == "mesecons_torch:mesecon_torch_off" then
mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_on")
minetest.swap_node(pos, {name = "mesecons_torch:mesecon_torch_on", param2 = node.param2})
mesecon:receptor_on(pos, torch_get_output_rules(node))
end
end

View File

@ -32,7 +32,7 @@ minetest.register_node("mesecons_walllever:wall_lever_off", {
groups = {dig_immediate=2, mesecon_needs_receiver = 1},
description="Lever",
on_punch = function (pos, node)
mesecon:swap_node(pos, "mesecons_walllever:wall_lever_on")
minetest.swap_node(pos, {name = "mesecons_walllever:wall_lever_on", param2 = node.param2})
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_lever", {pos=pos})
end,
@ -74,7 +74,7 @@ minetest.register_node("mesecons_walllever:wall_lever_on", {
drop = "mesecons_walllever:wall_lever_off 1",
description="Lever",
on_punch = function (pos, node)
mesecon:swap_node(pos, "mesecons_walllever:wall_lever_off")
minetest.swap_node(pos, {name = "mesecons_walllever:wall_lever_off", param2 = node.param2})
mesecon:receptor_off(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_lever", {pos=pos})
end,