Fix vertical wires not updating power when adding to / removing from a vertical line

Call mesecon.on_dignode / mesecon.on_placenode to take care of that.
This commit is contained in:
Jeija 2016-02-15 22:52:56 +01:00
parent fe9c6871de
commit 80f72b2621

View File

@ -44,24 +44,28 @@ local vertical_updatepos = function (pos)
and minetest.registered_nodes[node.name].is_vertical_conductor then
local node_above = minetest.get_node(vector.add(pos, vertical_rules[1]))
local node_below = minetest.get_node(vector.add(pos, vertical_rules[2]))
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
local above = minetest.registered_nodes[node_above.name]
and minetest.registered_nodes[node_above.name].is_vertical_conductor
local below = minetest.registered_nodes[node_below.name]
and minetest.registered_nodes[node_below.name].is_vertical_conductor
local basename = "mesecons_extrawires:vertical_"
mesecon.on_dignode(pos, node)
-- Always place offstate conductor and let mesecon.on_placenode take care
local newname = "mesecons_extrawires:vertical_"
if above and below then -- above and below: vertical mesecon
minetest.set_node(pos, {name = basename .. namestate})
newname = newname .. "off"
elseif above and not below then -- above only: bottom
minetest.set_node(pos, {name = basename .. "bottom_" .. namestate})
newname = newname .. "bottom_off"
elseif not above and below then -- below only: top
minetest.set_node(pos, {name = basename .. "top_" .. namestate})
newname = newname .. "top_off"
else -- no vertical wire above, no vertical wire below: use bottom
minetest.set_node(pos, {name = basename .. "bottom_" .. namestate})
newname = newname .. "bottom_off"
end
mesecon.update_autoconnect(pos)
minetest.set_node(pos, {name = newname})
mesecon.on_placenode(pos, {name = newname})
end
end
@ -87,7 +91,6 @@ mesecon.register_node("mesecons_extrawires:vertical", {
},{
tiles = {"mesecons_wire_off.png"},
groups = {dig_immediate=3},
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_on",
@ -96,7 +99,6 @@ mesecon.register_node("mesecons_extrawires:vertical", {
},{
tiles = {"mesecons_wire_on.png"},
groups = {dig_immediate=3, not_in_creative_inventory=1},
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_off",
@ -120,7 +122,6 @@ mesecon.register_node("mesecons_extrawires:vertical_top", {
after_dig_node = vertical_update
},{
tiles = {"mesecons_wire_off.png"},
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_top_on",
@ -128,7 +129,6 @@ mesecon.register_node("mesecons_extrawires:vertical_top", {
}}
},{
tiles = {"mesecons_wire_on.png"},
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_top_off",
@ -152,7 +152,6 @@ mesecon.register_node("mesecons_extrawires:vertical_bottom", {
after_dig_node = vertical_update
},{
tiles = {"mesecons_wire_off.png"},
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_bottom_on",
@ -160,7 +159,6 @@ mesecon.register_node("mesecons_extrawires:vertical_bottom", {
}}
},{
tiles = {"mesecons_wire_on.png"},
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_bottom_off",