mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-24 17:30:19 +01:00
Fix bug in mesecon.find_receptor that caused false turnoffs and rewrite lever +
switch
This commit is contained in:
parent
a550323fea
commit
80d136125e
@ -486,9 +486,10 @@ function mesecon.find_receptor_on(pos, link)
|
||||
|
||||
local links = mesecon.rules_link_rule_all_inverted(f.pos, r)
|
||||
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})
|
||||
checked[f.pos.x .. f.pos.y .. f.pos.z] = true
|
||||
checked[checkedstring] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -195,7 +195,7 @@ function mesecon.cmpAny(t1, t2)
|
||||
end
|
||||
|
||||
-- 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)
|
||||
|
||||
for k, v in pairs(source) do
|
||||
@ -208,8 +208,11 @@ mesecon.mergetable = function(source, dest)
|
||||
return rval
|
||||
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.__mesecon_basename = name
|
||||
spec_on.__mesecon_state = "on"
|
||||
spec_off.__mesecon_state = "off"
|
||||
|
||||
spec_on = mesecon.mergetable(spec_common, spec_on);
|
||||
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 .. "_off", spec_off)
|
||||
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
|
||||
|
@ -61,6 +61,7 @@ local vertical_updatepos = function (pos)
|
||||
else -- no vertical wire above, no vertical wire below: use bottom
|
||||
minetest.add_node(pos, {name = basename .. "bottom_" .. namestate})
|
||||
end
|
||||
mesecon.update_autoconnect(pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,35 +1,28 @@
|
||||
-- MESECON_SWITCH
|
||||
|
||||
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"},
|
||||
mesecon.register_node("mesecons_switch:mesecon_switch", {
|
||||
paramtype2="facedir",
|
||||
groups = {dig_immediate=2},
|
||||
description="Switch",
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}},
|
||||
on_punch = function (pos, node)
|
||||
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
|
||||
})
|
||||
|
||||
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)
|
||||
if(mesecon.flipstate(pos, node) == "on") then
|
||||
mesecon.receptor_on(pos)
|
||||
else
|
||||
mesecon.receptor_off(pos)
|
||||
end
|
||||
minetest.sound_play("mesecons_switch", {pos=pos})
|
||||
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({
|
||||
|
@ -1,16 +1,9 @@
|
||||
-- WALL LEVER
|
||||
-- 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", {
|
||||
mesecon.register_node("mesecons_walllever:wall_lever", {
|
||||
description="Lever",
|
||||
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",
|
||||
wield_image = "jeija_wall_lever_off.png",
|
||||
paramtype = "light",
|
||||
@ -21,29 +14,34 @@ minetest.register_node("mesecons_walllever:wall_lever_off", {
|
||||
type = "fixed",
|
||||
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 = {
|
||||
type = "fixed",
|
||||
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
|
||||
{ -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"
|
||||
{ -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 = {
|
||||
rules = mesecon.rules.buttonlike_get,
|
||||
state = mesecon.state.off
|
||||
}}
|
||||
})
|
||||
minetest.register_node("mesecons_walllever:wall_lever_on", {
|
||||
drawtype = "nodebox",
|
||||
}},
|
||||
groups = {dig_immediate = 2, mesecon_needs_receiver = 1}
|
||||
},{
|
||||
tiles = {
|
||||
"jeija_wall_lever_top.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_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 = {
|
||||
type = "fixed",
|
||||
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
|
||||
{ -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"
|
||||
{ -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 = {
|
||||
rules = mesecon.rules.buttonlike_get,
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
}},
|
||||
groups = {dig_immediate = 2, mesecon_needs_receiver = 1, not_in_creative_inventory = 1}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
Loading…
Reference in New Issue
Block a user