Skip to content

Commit

Permalink
Pressure plates and the object detector will send power to vertical
Browse files Browse the repository at this point in the history
wires 2 nodes below them, allows to hide circuitry powered by them.
Fixes #179
Rewrite pressure plates + vertical wires using mesecon.register_node.
  • Loading branch information
Jeija committed Nov 22, 2014
1 parent 194155f commit b5cc933
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 141 deletions.
7 changes: 3 additions & 4 deletions mesecons/init.lua
Expand Up @@ -47,15 +47,14 @@ mesecon.queue.funcs={} -- contains all ActionQueue functions
-- Settings
dofile(minetest.get_modpath("mesecons").."/settings.lua")

-- Presets (eg default rules)
dofile(minetest.get_modpath("mesecons").."/presets.lua");


-- Utilities like comparing positions,
-- adding positions and rules,
-- mostly things that make the source look cleaner
dofile(minetest.get_modpath("mesecons").."/util.lua");

-- Presets (eg default rules)
dofile(minetest.get_modpath("mesecons").."/presets.lua");

-- The ActionQueue
-- Saves all the actions that have to be execute in the future
dofile(minetest.get_modpath("mesecons").."/actionqueue.lua");
Expand Down
3 changes: 3 additions & 0 deletions mesecons/presets.lua
Expand Up @@ -15,6 +15,9 @@ mesecon.rules.default =
{x=0, y=1, z=-1},
{x=0, y=-1, z=-1}}

mesecon.rules.pplate = {{x=0, y=-2, z=0}}
mesecon.mergetable(mesecon.rules.default, mesecon.rules.pplate)

mesecon.rules.buttonlike =
{{x = 1, y = 0, z = 0},
{x = 1, y = 1, z = 0},
Expand Down
3 changes: 3 additions & 0 deletions mesecons/util.lua
Expand Up @@ -199,6 +199,9 @@ mesecon.mergetable = function(source, dest)
for k, v in pairs(source) do
dest[k] = dest[k] or v
end
for i, v in ipairs(source) do
dest[i] = dest[i] or v
end
end
mesecon.register_node = function(name, spec_common, spec_off, spec_on)
Expand Down
10 changes: 6 additions & 4 deletions mesecons_detector/init.lua
Expand Up @@ -55,7 +55,8 @@ minetest.register_node("mesecons_detector:object_detector_off", {
groups = {cracky=3},
description="Player Detector",
mesecons = {receptor = {
state = mesecon.state.off
state = mesecon.state.off,
rules = mesecon.rules.pplate
}},
on_construct = object_detector_make_formspec,
on_receive_fields = object_detector_on_receive_fields,
Expand All @@ -70,7 +71,8 @@ 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
state = mesecon.state.on,
rules = mesecon.rules.pplate
}},
on_construct = object_detector_make_formspec,
on_receive_fields = object_detector_on_receive_fields,
Expand All @@ -94,7 +96,7 @@ minetest.register_abm(
action = function(pos)
if object_detector_scan(pos) then
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_on"})
mesecon:receptor_on(pos)
mesecon:receptor_on(pos, mesecon.rules.pplate)
end
end,
})
Expand All @@ -106,7 +108,7 @@ minetest.register_abm(
action = function(pos)
if not object_detector_scan(pos) then
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_off"})
mesecon:receptor_off(pos)
mesecon:receptor_off(pos, mesecon.rules.pplate)
end
end,
})
Expand Down
133 changes: 51 additions & 82 deletions mesecons_extrawires/vertical.lua
Expand Up @@ -18,15 +18,15 @@ local bottom_box = {

local vertical_rules = {
{x=0, y=1, z=0},
{x=0, y=-1, z=0},
{x=0, y=-1, z=0}
}

local top_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},
{x=0,y=-1, z=0},
{x=0,y=-1, z=0}
}

local bottom_rules = {
Expand All @@ -35,26 +35,31 @@ local bottom_rules = {
{x=0, y=0, z=1},
{x=0, y=0, z=-1},
{x=0, y=1, z=0},
{x=0, y=2, z=0} -- receive power from pressure plate / detector / ... 2 nodes above
}

local vertical_updatepos = function (pos)
local node = minetest.get_node(pos)
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].is_vertical_conductor then
if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].is_vertical_conductor then
local node_above = minetest.get_node(mesecon:addPosRule(pos, vertical_rules[1]))
local node_below = minetest.get_node(mesecon:addPosRule(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 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_"
if above and below then -- above and below: vertical mesecon
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_" .. namestate})
minetest.add_node(pos, {name = basename .. namestate})
elseif above and not below then -- above only: bottom
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_bottom_" .. namestate})
minetest.add_node(pos, {name = basename .. "bottom_" .. namestate})
elseif not above and below then -- below only: top
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_top_" .. namestate})
else -- no vertical wire above, no vertical wire below: use default wire
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_" .. namestate})
minetest.add_node(pos, {name = basename .. "top_" .. namestate})
else -- no vertical wire above, no vertical wire below: use bottom
minetest.add_node(pos, {name = basename .. "bottom_" .. namestate})
end
end
end
Expand All @@ -66,136 +71,100 @@ local vertical_update = function (pos, node)
end

-- Vertical wire
minetest.register_node("mesecons_extrawires:vertical_on", {
mesecon.register_node("mesecons_extrawires:vertical", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"mesecons_wire_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate=3, not_in_creative_inventory=1},
selection_box = vertical_box,
node_box = vertical_box,
is_vertical_conductor = true,
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_off",
rules = vertical_rules,
}},
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
after_dig_node = vertical_update,
})

minetest.register_node("mesecons_extrawires:vertical_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
after_dig_node = vertical_update
},{
tiles = {"mesecons_wire_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate=3},
selection_box = vertical_box,
node_box = vertical_box,
is_vertical_conductor = true,
vertical_conductor_state = "off",
mesecons = {conductor = {
state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_on",
rules = vertical_rules,
}},
after_place_node = vertical_update,
after_dig_node = vertical_update,
})

-- Vertical wire top
minetest.register_node("mesecons_extrawires:vertical_top_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
}}
},{
tiles = {"mesecons_wire_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate=3, not_in_creative_inventory=1},
selection_box = top_box,
node_box = top_box,
is_vertical_conductor = true,
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_top_off",
rules = top_rules,
}},
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
after_dig_node = vertical_update,
offstate = "mesecons_extrawires:vertical_off",
rules = vertical_rules,
}}
})

minetest.register_node("mesecons_extrawires:vertical_top_off", {
-- Vertical wire top
mesecon.register_node("mesecons_extrawires:vertical_top", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"mesecons_wire_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate=3, not_in_creative_inventory=1},
selection_box = top_box,
node_box = top_box,
is_vertical_conductor = true,
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
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",
rules = top_rules,
}},
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
after_dig_node = vertical_update,
})

-- Vertical wire bottom
minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
}}
},{
tiles = {"mesecons_wire_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
vertical_conductor_state = "on",
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bottom_box,
node_box = bottom_box,
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_bottom_off",
rules = bottom_rules,
}},
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
after_dig_node = vertical_update,
offstate = "mesecons_extrawires:vertical_top_off",
rules = top_rules,
}}
})

minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
-- Vertical wire bottom
mesecon.register_node("mesecons_extrawires:vertical_bottom", {
description = "Vertical mesecon",
drawtype = "nodebox",
tiles = {"mesecons_wire_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bottom_box,
node_box = bottom_box,
is_vertical_conductor = true,
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
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",
rules = bottom_rules,
}},
drop = "mesecons_extrawires:vertical_off",
after_place_node = vertical_update,
after_dig_node = vertical_update,
}}
},{
tiles = {"mesecons_wire_on.png"},
vertical_conductor_state = "on",
mesecons = {conductor = {
state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_bottom_off",
rules = bottom_rules,
}}
})

minetest.register_craft({
Expand Down

0 comments on commit b5cc933

Please sign in to comment.