diff options
-rw-r--r-- | mesecons_detector/init.lua | 91 | ||||
-rw-r--r-- | mesecons_doors/init.lua | 111 | ||||
-rw-r--r-- | mesecons_mvps/init.lua | 21 |
3 files changed, 139 insertions, 84 deletions
diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua index edef641..65e5c6e 100644 --- a/mesecons_detector/init.lua +++ b/mesecons_detector/init.lua @@ -12,10 +12,7 @@ local function object_detector_make_formspec(pos) end local function object_detector_on_receive_fields(pos, _, fields) - if not fields.scanname - or not fields.digiline_channel then - return - end + if not fields.scanname or not fields.digiline_channel then return end local meta = minetest.get_meta(pos) meta:set_string("scanname", fields.scanname) @@ -26,19 +23,24 @@ end -- returns true if player was found, false if not local function object_detector_scan(pos) local objs = minetest.get_objects_inside_radius(pos, mesecon.setting("detector_radius", 6)) - if not next(objs) then - return false - end + + -- abort if no scan results were found + if next(objs) == nil then return false end local scanname = minetest.get_meta(pos):get_string("scanname") local every_player = scanname == "" - for _,obj in pairs(objs) do - local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil! - if isname ~= "" - and (every_player or isname == scanname) then -- no scanname specified or player with scanname found - return true + for _, obj in pairs(objs) do + -- "" is returned if it is not a player; "" ~= nil; so only handle objects with foundname ~= "" + local foundname = obj:get_player_name() + + if foundname ~= "" then + -- return true if scanning for any player or if specific playername was detected + if scanname == "" or foundname == scanname then + return true + end end end + return false end @@ -101,9 +103,8 @@ minetest.register_abm({ interval = 1, chance = 1, action = function(pos, node) - if not object_detector_scan(pos) then - return - end + if not object_detector_scan(pos) then return end + node.name = "mesecons_detector:object_detector_on" minetest.swap_node(pos, node) mesecon.receptor_on(pos, mesecon.rules.pplate) @@ -115,9 +116,8 @@ minetest.register_abm({ interval = 1, chance = 1, action = function(pos, node) - if object_detector_scan(pos) then - return - end + if object_detector_scan(pos) then return end + node.name = "mesecons_detector:object_detector_off" minetest.swap_node(pos, node) mesecon.receptor_off(pos, mesecon.rules.pplate) @@ -135,10 +135,7 @@ local function node_detector_make_formspec(pos) end local function node_detector_on_receive_fields(pos, _, fields) - if not fields.scanname - or not fields.digiline_channel then - return - end + if not fields.scanname or not fields.digiline_channel then return end local meta = minetest.get_meta(pos) meta:set_string("scanname", fields.scanname) @@ -146,18 +143,18 @@ local function node_detector_on_receive_fields(pos, _, fields) node_detector_make_formspec(pos) end --- returns true if player was found, false if not +-- returns true if node was found, false if not local function node_detector_scan(pos) local node = minetest.get_node_or_nil(pos) - if not node then - return - end + if not node then return end + local frontname = minetest.get_node( vector.subtract(pos, minetest.facedir_to_dir(node.param2)) ).name - local meta = minetest.get_meta(pos) - return (frontname == meta:get_string("scanname")) or - (frontname ~= "air" and frontname ~= "ignore" and meta:get_string("scanname") == "") + local scanname = minetest.get_meta(pos):get_string("scanname") + + return (frontname == scanname) or + (frontname ~= "air" and frontname ~= "ignore" and scanname == "") end -- set player name when receiving a digiline signal on a specific channel @@ -165,15 +162,14 @@ local node_detector_digiline = { effector = { action = function(pos, node, channel, msg) local meta = minetest.get_meta(pos) - if channel ~= meta:get_string("digiline_channel") then - return - end + if channel ~= meta:get_string("digiline_channel") then return end + if msg == GET_COMMAND then - digiline:receptor_send(pos, digiline.rules.default, channel, - minetest.get_node( - vector.subtract(pos, minetest.facedir_to_dir(node.param2)) - ).name - ) + local nodename = minetest.get_node( + vector.subtract(pos, minetest.facedir_to_dir(node.param2)) + ).name + + digiline:receptor_send(pos, digiline.rules.default, channel, nodename) else meta:set_string("scanname", msg) node_detector_make_formspec(pos) @@ -198,7 +194,6 @@ local function after_place_node_detector(pos, placer) local node = minetest.get_node(pos) node.param2 = minetest.dir_to_facedir(vector.subtract(pos, placer_pos), true) minetest.set_node(pos, node) - --minetest.log("action", "real (6d) facedir: " .. node.param2) end minetest.register_node("mesecons_detector:node_detector_off", { @@ -249,11 +244,11 @@ minetest.register_abm({ interval = 1, chance = 1, action = function(pos, node) - if node_detector_scan(pos) then - node.name = "mesecons_detector:node_detector_on" - minetest.swap_node(pos, node) - mesecon.receptor_on(pos) - end + if not node_detector_scan(pos) then return end + + node.name = "mesecons_detector:node_detector_on" + minetest.swap_node(pos, node) + mesecon.receptor_on(pos) end, }) @@ -262,10 +257,10 @@ minetest.register_abm({ interval = 1, chance = 1, action = function(pos, node) - if not node_detector_scan(pos) then - node.name = "mesecons_detector:node_detector_off" - minetest.swap_node(pos, node) - mesecon.receptor_off(pos) - end + if node_detector_scan(pos) then return end + + node.name = "mesecons_detector:node_detector_off" + minetest.swap_node(pos, node) + mesecon.receptor_off(pos) end, }) diff --git a/mesecons_doors/init.lua b/mesecons_doors/init.lua index 7346128..52d6c17 100644 --- a/mesecons_doors/init.lua +++ b/mesecons_doors/init.lua @@ -20,31 +20,53 @@ local function on_rightclick(pos, dir, check_name, replace, replace_dir, params) end local function meseconify_door(name) - if not minetest.registered_items[name] then return end + if minetest.registered_items[name .. "_b_1"] then + -- old style double-node doors + local function toggle_state1 (pos, node) + on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) + end - local function toggle_state1 (pos, node) - on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) - end - - local function toggle_state2 (pos, node) - on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) - end + local function toggle_state2 (pos, node) + on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) + end - minetest.override_item(name.."_b_1", { - mesecons = {effector = { - action_on = toggle_state1, - action_off = toggle_state1, - rules = mesecon.rules.pplate - }}, - }) + minetest.override_item(name.."_b_1", { + mesecons = {effector = { + action_on = toggle_state1, + action_off = toggle_state1, + rules = mesecon.rules.pplate + }} + }) - minetest.override_item(name.."_b_2", { - mesecons = {effector = { - action_on = toggle_state2, - action_off = toggle_state2, - rules = mesecon.rules.pplate - }}, - }) + minetest.override_item(name.."_b_2", { + mesecons = {effector = { + action_on = toggle_state2, + action_off = toggle_state2, + rules = mesecon.rules.pplate + }} + }) + elseif minetest.registered_items[name .. "_a"] then + -- new style mesh node based doors + local override = { + mesecons = {effector = { + action_on = function(pos, node) + local door = doors.get(pos) + if door then + door:open() + end + end, + action_off = function(pos, node) + local door = doors.get(pos) + if door then + door:close() + end + end, + rules = mesecon.rules.pplate + }} + } + minetest.override_item(name .. "_a", override) + minetest.override_item(name .. "_b", override) + end end meseconify_door("doors:door_wood") @@ -67,18 +89,41 @@ local function trapdoor_switch(pos, node) minetest.get_meta(pos):set_int("state", state == 1 and 0 or 1) end -if minetest.registered_nodes["doors:trapdoor"] then - minetest.override_item("doors:trapdoor", { +if doors and doors.get then + local override = { mesecons = {effector = { - action_on = trapdoor_switch, - action_off = trapdoor_switch + action_on = function(pos, node) + local door = doors.get(pos) + if door then + door:open() + end + end, + action_off = function(pos, node) + local door = doors.get(pos) + if door then + door:close() + end + end, }}, - }) + } + minetest.override_item("doors:trapdoor", override) + minetest.override_item("doors:trapdoor_open", override) + minetest.override_item("doors:trapdoor_steel", override) + minetest.override_item("doors:trapdoor_steel_open", override) +else + if minetest.registered_nodes["doors:trapdoor"] then + minetest.override_item("doors:trapdoor", { + mesecons = {effector = { + action_on = trapdoor_switch, + action_off = trapdoor_switch + }}, + }) - minetest.override_item("doors:trapdoor_open", { - mesecons = {effector = { - action_on = trapdoor_switch, - action_off = trapdoor_switch - }}, - }) + minetest.override_item("doors:trapdoor_open", { + mesecons = {effector = { + action_on = trapdoor_switch, + action_off = trapdoor_switch + }}, + }) + end end diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index beec94b..2f4edfc 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -15,10 +15,16 @@ end -- Nodes that cannot be pushed / pulled by movestones, pistons function mesecon.is_mvps_stopper(node, pushdir, stack, stackid) + -- unknown nodes are always stoppers + if not minetest.registered_nodes[node.name] then + return true + end + local get_stopper = mesecon.mvps_stoppers[node.name] if type (get_stopper) == "function" then get_stopper = get_stopper(node, pushdir, stack, stackid) end + return get_stopper end @@ -47,6 +53,17 @@ function mesecon.mvps_process_stack(stack) end end +-- tests if the node can be pushed into, e.g. air, water, grass +local function node_replaceable(name) + if name == "ignore" then return true end + + if minetest.registered_nodes[name] then + return minetest.registered_nodes[name].buildable_to or false + end + + return false +end + function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky) -- determine the number of nodes to be pushed local nodes = {} @@ -56,9 +73,7 @@ function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky) local np = frontiers[1] local nn = minetest.get_node(np) - if nn.name ~= "air" - and minetest.registered_nodes[nn.name] - and minetest.registered_nodes[nn.name].liquidtype == "none" then + if not node_replaceable(nn.name) then table.insert(nodes, {node = nn, pos = np}) if #nodes > maximum then return nil end |