Fix bug in mesecon.find_receptor that caused false turnoffs and rewrite lever +

switch
This commit is contained in:
Jeija 2014-11-22 20:49:54 +01:00
parent a550323fea
commit 80d136125e
5 changed files with 62 additions and 71 deletions

View File

@ -486,9 +486,10 @@ function mesecon.find_receptor_on(pos, link)
local links = mesecon.rules_link_rule_all_inverted(f.pos, r) local links = mesecon.rules_link_rule_all_inverted(f.pos, r)
for _, l in ipairs(links) do for _, l in ipairs(links) do
if not checked[f.pos.x .. f.pos.y .. f.pos.z] then local checkedstring = np.x..np.y..np.z..l.x..l.y..l.z
if not checked[checkedstring] then
table.insert(frontiers, {pos = np, link = l}) table.insert(frontiers, {pos = np, link = l})
checked[f.pos.x .. f.pos.y .. f.pos.z] = true checked[checkedstring] = true
end end
end end
end end

View File

@ -195,7 +195,7 @@ function mesecon.cmpAny(t1, t2)
end end
-- does not overwrite values; number keys (ipairs) are appended, not overwritten -- does not overwrite values; number keys (ipairs) are appended, not overwritten
mesecon.mergetable = function(source, dest) function mesecon.mergetable(source, dest)
local rval = mesecon.tablecopy(dest) local rval = mesecon.tablecopy(dest)
for k, v in pairs(source) do for k, v in pairs(source) do
@ -208,8 +208,11 @@ mesecon.mergetable = function(source, dest)
return rval return rval
end end
mesecon.register_node = function(name, spec_common, spec_off, spec_on) function mesecon.register_node(name, spec_common, spec_off, spec_on)
spec_common.drop = spec_common.drop or name .. "_off" spec_common.drop = spec_common.drop or name .. "_off"
spec_common.__mesecon_basename = name
spec_on.__mesecon_state = "on"
spec_off.__mesecon_state = "off"
spec_on = mesecon.mergetable(spec_common, spec_on); spec_on = mesecon.mergetable(spec_common, spec_on);
spec_off = mesecon.mergetable(spec_common, spec_off); spec_off = mesecon.mergetable(spec_common, spec_off);
@ -217,3 +220,16 @@ mesecon.register_node = function(name, spec_common, spec_off, spec_on)
minetest.register_node(name .. "_on", spec_on) minetest.register_node(name .. "_on", spec_on)
minetest.register_node(name .. "_off", spec_off) minetest.register_node(name .. "_off", spec_off)
end end
-- swap onstate and offstate nodes, returns new state
function mesecon.flipstate(pos, node)
local nodedef = minetest.registered_nodes[node.name]
local newstate
if (nodedef.__mesecon_state == "on") then newstate = "off" end
if (nodedef.__mesecon_state == "off") then newstate = "on" end
minetest.swap_node(pos, {name = nodedef.__mesecon_basename .. "_" .. newstate,
param2 = node.param2})
return newstate
end

View File

@ -61,6 +61,7 @@ local vertical_updatepos = function (pos)
else -- no vertical wire above, no vertical wire below: use bottom else -- no vertical wire above, no vertical wire below: use bottom
minetest.add_node(pos, {name = basename .. "bottom_" .. namestate}) minetest.add_node(pos, {name = basename .. "bottom_" .. namestate})
end end
mesecon.update_autoconnect(pos)
end end
end end

View File

@ -1,35 +1,28 @@
-- MESECON_SWITCH -- MESECON_SWITCH
minetest.register_node("mesecons_switch:mesecon_switch_off", { mesecon.register_node("mesecons_switch:mesecon_switch", {
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", paramtype2="facedir",
groups = {dig_immediate=2}, groups = {dig_immediate=2},
description="Switch", description="Switch",
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = {
state = mesecon.state.off
}},
on_punch = function (pos, node) on_punch = function (pos, node)
minetest.swap_node(pos, {name = "mesecons_switch:mesecon_switch_on", param2 = node.param2}) if(mesecon.flipstate(pos, node) == "on") then
mesecon:receptor_on(pos) mesecon.receptor_on(pos)
minetest.sound_play("mesecons_switch", {pos=pos}) else
end mesecon.receptor_off(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},
drop="mesecons_switch:mesecon_switch_off 1",
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = {
state = mesecon.state.on
}},
on_punch = function(pos, node)
minetest.swap_node(pos, {name = "mesecons_switch:mesecon_switch_off", param2 = node.param2})
mesecon:receptor_off(pos)
minetest.sound_play("mesecons_switch", {pos=pos}) minetest.sound_play("mesecons_switch", {pos=pos})
end end
},{
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"},
mesecons = {receptor = { state = mesecon.state.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_on.png"},
mesecons = {receptor = { state = mesecon.state.on }}
}) })
minetest.register_craft({ minetest.register_craft({

View File

@ -1,16 +1,9 @@
-- WALL LEVER -- WALL LEVER
-- Basically a switch that can be attached to a wall -- Basically a switch that can be attached to a wall
-- Powers the block 2 nodes behind (using a receiver) -- Powers the block 2 nodes behind (using a receiver)
minetest.register_node("mesecons_walllever:wall_lever_off", { mesecon.register_node("mesecons_walllever:wall_lever", {
description="Lever",
drawtype = "nodebox", drawtype = "nodebox",
tiles = {
"jeija_wall_lever_tb.png",
"jeija_wall_lever_bottom.png",
"jeija_wall_lever_sides.png",
"jeija_wall_lever_sides.png",
"jeija_wall_lever_back.png",
"jeija_wall_lever_off.png",
},
inventory_image = "jeija_wall_lever_off.png", inventory_image = "jeija_wall_lever_off.png",
wield_image = "jeija_wall_lever_off.png", wield_image = "jeija_wall_lever_off.png",
paramtype = "light", paramtype = "light",
@ -21,29 +14,34 @@ minetest.register_node("mesecons_walllever:wall_lever_off", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, 3/16, 8/16, 8/16, 8/16 }, fixed = { -8/16, -8/16, 3/16, 8/16, 8/16, 8/16 },
}, },
sounds = default.node_sound_wood_defaults(),
on_punch = function (pos, node)
if(mesecon.flipstate(pos, node) == "on") then
mesecon.receptor_on(pos, mesecon.rules.buttonlike_get(node))
else
mesecon.receptor_off(pos, mesecon.rules.buttonlike_get(node))
end
minetest.sound_play("mesecons_lever", {pos=pos})
end
},{
tiles = { "jeija_wall_lever_tb.png", "jeija_wall_lever_bottom.png",
"jeija_wall_lever_sides.png", "jeija_wall_lever_sides.png",
"jeija_wall_lever_back.png", "jeija_wall_lever_off.png",
},
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = {{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the base "slab" fixed = {{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the base "slab"
{ -5/16, -3/16, 5/16, 5/16, 3/16, 6/16 }, -- the lighted ring area { -5/16, -3/16, 5/16, 5/16, 3/16, 6/16 }, -- the lighted ring area
{ -4/16, -2/16, 4/16, 4/16, 2/16, 5/16 }, -- the raised bit that the lever "sits" on { -4/16, -2/16, 4/16, 4/16, 2/16, 5/16 }, -- the raised bit
{ -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge" { -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge"
{ -1/16, -8/16, 4/16, 1/16, 0, 6/16 }} -- the lever itself. { -1/16, -8/16, 4/16, 1/16, 0, 6/16 }} -- the lever itself.
}, },
groups = {dig_immediate=2, mesecon_needs_receiver = 1},
description="Lever",
on_punch = function (pos, node)
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,
sounds = default.node_sound_wood_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
rules = mesecon.rules.buttonlike_get, rules = mesecon.rules.buttonlike_get,
state = mesecon.state.off state = mesecon.state.off
}} }},
}) groups = {dig_immediate = 2, mesecon_needs_receiver = 1}
minetest.register_node("mesecons_walllever:wall_lever_on", { },{
drawtype = "nodebox",
tiles = { tiles = {
"jeija_wall_lever_top.png", "jeija_wall_lever_top.png",
"jeija_wall_lever_tb.png", "jeija_wall_lever_tb.png",
@ -52,37 +50,19 @@ minetest.register_node("mesecons_walllever:wall_lever_on", {
"jeija_wall_lever_back.png", "jeija_wall_lever_back.png",
"jeija_wall_lever_on.png", "jeija_wall_lever_on.png",
}, },
inventory_image = "jeija_wall_lever_on.png",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
walkable = false,
light_source = LIGHT_MAX-7,
selection_box = {
type = "fixed",
fixed = { -8/16, -8/16, 3/16, 8/16, 8/16, 8/16 },
},
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = {{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the base "slab" fixed = {{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the base "slab"
{ -5/16, -3/16, 5/16, 5/16, 3/16, 6/16 }, -- the lighted ring area { -5/16, -3/16, 5/16, 5/16, 3/16, 6/16 }, -- the lighted ring area
{ -4/16, -2/16, 4/16, 4/16, 2/16, 5/16 }, -- the raised bit that the lever "sits" on { -4/16, -2/16, 4/16, 4/16, 2/16, 5/16 }, -- the raised bit
{ -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge" { -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. { -1/16, 0, 4/16, 1/16, 8/16, 6/16 }} -- the lever itself.
}, },
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)
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,
sounds = default.node_sound_wood_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
rules = mesecon.rules.buttonlike_get, rules = mesecon.rules.buttonlike_get,
state = mesecon.state.on state = mesecon.state.on
}} }},
groups = {dig_immediate = 2, mesecon_needs_receiver = 1, not_in_creative_inventory = 1}
}) })
minetest.register_craft({ minetest.register_craft({