From 974c147b45863ee17481a72ff1b72b3b210d892d Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 9 Sep 2019 18:23:50 +0200 Subject: [PATCH] move switches,palm-scanner and digicode to own file --- common.lua | 22 +++ digicode.lua | 152 ++++++++++++++++++++ init.lua | 7 + nodeboxes.lua | 357 ----------------------------------------------- palm_scanner.lua | 120 ++++++++++++++++ switches.lua | 62 ++++++++ 6 files changed, 363 insertions(+), 357 deletions(-) create mode 100644 common.lua create mode 100644 digicode.lua create mode 100644 palm_scanner.lua create mode 100644 switches.lua diff --git a/common.lua b/common.lua new file mode 100644 index 0000000..e8e9c6a --- /dev/null +++ b/common.lua @@ -0,0 +1,22 @@ + + +function scifi_nodes.get_switch_rules(param2) + + -- param2 = 2 + local rules = { + {x=1, y=-1, z=-1}, + {x=1, y=-1, z=1}, + {x=0, y=-1, z=-1}, + {x=0, y=-1, z=1}, + } + +-- Left and right when looking to +y ? + if param2 == 3 then + rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right (rules)) + elseif param2 == 4 then + rules = mesecon.rotate_rules_right(rules) + elseif param2 == 5 then + rules = mesecon.rotate_rules_left(rules) + end + return rules +end diff --git a/digicode.lua b/digicode.lua new file mode 100644 index 0000000..0d89183 --- /dev/null +++ b/digicode.lua @@ -0,0 +1,152 @@ + +-------------- +-- Digicode -- +-------------- + +local secret_code = "1234" +local allowed_chars = "0123456789" +local code_length = 4 +local digicode_context = {} + +-- after_place_node, use by digicode and palm_scanner +-- placer is a player object +local function set_owner(pos, placer, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name()) + meta:set_string("code", secret_code) +end + +local function toggle_digicode(pos) + local node = minetest.get_node(pos) + local name = node.name + if name == "scifi_nodes:digicode_off" then + minetest.swap_node(pos, {name="scifi_nodes:digicode_on", param2=node.param2}) + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + minetest.get_node_timer(pos):start(2) + elseif name == "scifi_nodes:digicode_on" then + minetest.swap_node(pos, {name="scifi_nodes:digicode_off", param2=node.param2}) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + end +end + +local function code_is_valid(code) + local valid = false + if type(code) == "string" and #code == code_length then + valid = true + end + for i=1, #code do + if not string.find(allowed_chars, string.sub(code,i,i)) then + valid = false + end + end + return valid +end + +local function update_code(pos, code) + local meta = minetest.get_meta(pos) + meta:set_string("code", code) +end + +local function show_digicode_formspec(pos, node, player, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local current_code = meta:get_string("code") + local current_player = player:get_player_name() + + -- Gathering datas that will be used by callback function + digicode_context[current_player] = {code = current_code, pos = pos} + + if current_player == owner then + minetest.show_formspec(current_player, "digicode_formspec", + "size[6,3]".. + "field[1,1;3,1;code;Code;]".. -- type, position, size, name, label + "button_exit[1,2;2,1;change;Change code]".. + "button_exit[3,2;2,1;open;Open door]") + else + minetest.show_formspec(current_player, "digicode_formspec", + "size[6,3]".. + "field[2,1;3,1;code;Code;]".. + "button_exit[2,2;3,1;open;Open door]") + end +end + +-- Process datas from digicode_formspec +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "digicode_formspec" then + return false + end + + local sounds = {"scifi_nodes_scanner_granted","scifi_nodes_scanner_refused", + "scifi_nodes_digicode_granted","scifi_nodes_digicode_refused" + } + local sound_index + + -- We have the right formspec so we can proceed it. + -- Let's retrieve the datas we need : + local context = digicode_context[player:get_player_name()] + + if fields.change and code_is_valid(fields.code) then + update_code(context.pos, fields.code) + sound_index = 1 + elseif + fields.change and not code_is_valid(fields.code) then + sound_index = 2 + elseif + fields.open and fields.code == context.code then + toggle_digicode(context.pos) + sound_index = 3 + elseif + fields.open and fields.code ~= context.code then + sound_index = 4 + end + -- play sound at context position + minetest.sound_play(sounds[sound_index], { + pos = context.pos, + max_hear_distance = 10 + }) + context[player:get_player_name()] = nil -- we don't need it anymore +end) + +minetest.register_node("scifi_nodes:digicode_on", { + description = "Digicode", + sunlight_propagates = true, + buildable_to = false, + tiles = {"scifi_nodes_digicode_on.png",}, + inventory_image = "scifi_nodes_digicode_on.png", + wield_image = "scifi_nodes_digicode_on.png", + drawtype = "signlike", + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + light_source = 5, + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + drop = {items = {"scifi_nodes:digicode_off"}}, + mesecons = {receptor = {state = mesecon.state.on,}}, + on_timer = toggle_digicode, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:digicode_off", { + description = "Digicode", + tiles = {"scifi_nodes_digicode_off.png",}, + inventory_image = "scifi_nodes_digicode_off.png", + wield_image = "scifi_nodes_digicode_off.png", + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.off,}}, + after_place_node = set_owner, + on_rightclick = show_digicode_formspec, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_craft({ + output = "scifi_nodes:digicode_off 2", + recipe = {{"mesecons_switch:mesecon_switch_off", "scifi_nodes:grey", ""}} +}) diff --git a/init.lua b/init.lua index 86cc7fd..b1bba98 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,22 @@ --scifi_nodes by D00Med + +scifi_nodes = {} + local MP = minetest.get_modpath("scifi_nodes") if minetest.get_modpath("xpanes") then dofile(MP.."/panes.lua") end +dofile(MP.."/common.lua") dofile(MP.."/builder.lua") dofile(MP.."/chest.lua") dofile(MP.."/plants.lua") dofile(MP.."/nodes.lua") dofile(MP.."/doors.lua") +dofile(MP.."/switches.lua") dofile(MP.."/nodeboxes.lua") +dofile(MP.."/palm_scanner.lua") +dofile(MP.."/digicode.lua") dofile(MP.."/models.lua") dofile(MP.."/crafts.lua") diff --git a/nodeboxes.lua b/nodeboxes.lua index 621e9ba..d6efcc2 100644 --- a/nodeboxes.lua +++ b/nodeboxes.lua @@ -1203,360 +1203,3 @@ minetest.register_node("scifi_nodes:windowpanel", { on_place = minetest.rotate_node, sounds = default.node_sound_glass_defaults(), }) - - --------------- --- Switches -- --------------- - -local function get_switch_rules(param2) - - -- param2 = 2 - local rules = { - {x=1, y=-1, z=-1}, - {x=1, y=-1, z=1}, - {x=0, y=-1, z=-1}, - {x=0, y=-1, z=1}, - } - --- Left and right when looking to +y ? - if param2 == 3 then - rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right (rules)) - elseif param2 == 4 then - rules = mesecon.rotate_rules_right(rules) - elseif param2 == 5 then - rules = mesecon.rotate_rules_left(rules) - end - return rules -end - -local function toggle_switch(pos) - local node = minetest.get_node(pos) - local name = node.name - if name == "scifi_nodes:switch_on" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) - minetest.set_node(pos, {name = "scifi_nodes:switch_off", param2 = node.param2}) - mesecon.receptor_off(pos, get_switch_rules(node.param2)) - elseif name == "scifi_nodes:switch_off" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) - minetest.set_node(pos, {name = "scifi_nodes:switch_on", param2 = node.param2}) - mesecon.receptor_on(pos, get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - end -end - -minetest.register_node("scifi_nodes:switch_on", { - description = "Wall switch", - sunlight_propagates = true, - buildable_to = false, - tiles = {"scifi_nodes_switch_on.png",}, - inventory_image = "scifi_nodes_switch_on.png", - wield_image = "scifi_nodes_switch_on.png", - drawtype = "signlike", - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - light_source = 5, - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.on,}}, - sounds = default.node_sound_glass_defaults(), - on_rightclick = toggle_switch, - on_timer = toggle_switch -}) - -minetest.register_node("scifi_nodes:switch_off", { - description = "Wall switch", - tiles = {"scifi_nodes_switch_off.png",}, - inventory_image = "scifi_nodes_switch_on.png", - wield_image = "scifi_nodes_switch_on.png", - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, - sounds = default.node_sound_glass_defaults(), - on_rightclick = toggle_switch -}) - -minetest.register_craft({ - output = "scifi_nodes:switch_off 2", - recipe = {{"mesecons_button:button_off", "scifi_nodes:grey", ""}} -}) - - --------------- --- Digicode -- --------------- - -local secret_code = "1234" -local allowed_chars = "0123456789" -local code_length = 4 -local digicode_context = {} - --- after_place_node, use by digicode and palm_scanner --- placer is a player object -local function set_owner(pos, placer, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name()) - meta:set_string("code", secret_code) -end - -local function toggle_digicode(pos) - local node = minetest.get_node(pos) - local name = node.name - if name == "scifi_nodes:digicode_off" then - minetest.swap_node(pos, {name="scifi_nodes:digicode_on", param2=node.param2}) - mesecon.receptor_on(pos, get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - elseif name == "scifi_nodes:digicode_on" then - minetest.swap_node(pos, {name="scifi_nodes:digicode_off", param2=node.param2}) - mesecon.receptor_off(pos, get_switch_rules(node.param2)) - end -end - -local function code_is_valid(code) - local valid = false - if type(code) == "string" and #code == code_length then - valid = true - end - for i=1, #code do - if not string.find(allowed_chars, string.sub(code,i,i)) then - valid = false - end - end - return valid -end - -local function update_code(pos, code) - local meta = minetest.get_meta(pos) - meta:set_string("code", code) -end - -local function show_digicode_formspec(pos, node, player, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local current_code = meta:get_string("code") - local current_player = player:get_player_name() - - -- Gathering datas that will be used by callback function - digicode_context[current_player] = {code = current_code, pos = pos} - - if current_player == owner then - minetest.show_formspec(current_player, "digicode_formspec", - "size[6,3]".. - "field[1,1;3,1;code;Code;]".. -- type, position, size, name, label - "button_exit[1,2;2,1;change;Change code]".. - "button_exit[3,2;2,1;open;Open door]") - else - minetest.show_formspec(current_player, "digicode_formspec", - "size[6,3]".. - "field[2,1;3,1;code;Code;]".. - "button_exit[2,2;3,1;open;Open door]") - end -end - --- Process datas from digicode_formspec -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "digicode_formspec" then - return false - end - - local sounds = {"scifi_nodes_scanner_granted","scifi_nodes_scanner_refused", - "scifi_nodes_digicode_granted","scifi_nodes_digicode_refused" - } - local sound_index - - -- We have the right formspec so we can proceed it. - -- Let's retrieve the datas we need : - local context = digicode_context[player:get_player_name()] - - if fields.change and code_is_valid(fields.code) then - update_code(context.pos, fields.code) - sound_index = 1 - elseif - fields.change and not code_is_valid(fields.code) then - sound_index = 2 - elseif - fields.open and fields.code == context.code then - toggle_digicode(context.pos) - sound_index = 3 - elseif - fields.open and fields.code ~= context.code then - sound_index = 4 - end - -- play sound at context position - minetest.sound_play(sounds[sound_index], { - pos = context.pos, - max_hear_distance = 10 - }) - context[player:get_player_name()] = nil -- we don't need it anymore -end) - -minetest.register_node("scifi_nodes:digicode_on", { - description = "Digicode", - sunlight_propagates = true, - buildable_to = false, - tiles = {"scifi_nodes_digicode_on.png",}, - inventory_image = "scifi_nodes_digicode_on.png", - wield_image = "scifi_nodes_digicode_on.png", - drawtype = "signlike", - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - light_source = 5, - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - drop = {items = {"scifi_nodes:digicode_off"}}, - mesecons = {receptor = {state = mesecon.state.on,}}, - on_timer = toggle_digicode, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:digicode_off", { - description = "Digicode", - tiles = {"scifi_nodes_digicode_off.png",}, - inventory_image = "scifi_nodes_digicode_off.png", - wield_image = "scifi_nodes_digicode_off.png", - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, - after_place_node = set_owner, - on_rightclick = show_digicode_formspec, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_craft({ - output = "scifi_nodes:digicode_off 2", - recipe = {{"mesecons_switch:mesecon_switch_off", "scifi_nodes:grey", ""}} -}) - - ------------------------------------------------ --- Palm scanner -- ------------------------------------------------ --- /!\ When "overriding" a callback function -- --- re-use all the parameters in same order ! -- ------------------------------------------------ - --- after_place_node --- placer is a player object -local function set_scanner_owner(pos, placer, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name()) -end - -local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing) - -- Some calling function don't send node param, but everybody sends a pos, so : - if not node then - node = minetest.get_node(pos) - end - - if node.name == "scifi_nodes:palm_scanner_off" then - local meta = minetest.get_meta(pos) - meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2}) - minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.chat_send_player(player:get_player_name(), "Checking : please wait.") - minetest.get_node_timer(pos):start(2) - elseif node.name == "scifi_nodes:palm_scanner_checking" then - minetest.swap_node(pos,{name = "scifi_nodes:palm_scanner_on", param2 = node.param2}) - mesecon.receptor_on(pos, get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - elseif node.name == "scifi_nodes:palm_scanner_on" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) - mesecon.receptor_off (pos, get_switch_rules(node.param2)) - end -end - --- palm_scanner_checking.on_timer -local function check_owner(pos, elapsed) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local clicker = meta:get_string("clicker") - local node = minetest.get_node(pos) - if clicker == owner then - minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.chat_send_player(clicker, "Access granted !") - toggle_palm_scanner (pos) - else - minetest.chat_send_player(clicker, "Access refused !") - minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) - mesecon.receptor_off(pos, get_switch_rules(node.param2)) - end -end - -minetest.register_node("scifi_nodes:palm_scanner_off", { - description = "Palm scanner", - tiles = {"scifi_nodes_palm_scanner_off.png",}, - inventory_image = "scifi_nodes_palm_scanner_off.png", - wield_image = "scifi_nodes_palm_scanner_on.png", - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, - after_place_node = set_scanner_owner, - on_rightclick = toggle_palm_scanner, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:palm_scanner_checking", { - description = "Palm scanner", - tiles = {{ - name = "scifi_nodes_palm_scanner_checking.png", - animation = {type = "vertical_frames",aspect_w = 16,aspect_h = 16,length = 1.5} - }}, - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - drop = "scifi_nodes:palm_scanner_off", - sounds = default.node_sound_glass_defaults(), - on_timer = check_owner, -}) - -minetest.register_node("scifi_nodes:palm_scanner_on", { - description = "Palm scanner", - sunlight_propagates = true, - buildable_to = false, - tiles = {"scifi_nodes_palm_scanner_on.png",}, - inventory_image = "scifi_nodes_palm_scanner_on.png", - wield_image = "scifi_nodes_palm_scanner_on.png", - drawtype = "signlike", - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - light_source = 5, - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - drop = "scifi_nodes:palm_scanner_off", - mesecons = {receptor = {state = mesecon.state.on,}}, - on_timer = toggle_palm_scanner, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_craft({ - output = "scifi_nodes:palm_scanner_off 2", - recipe = {{"mesecons_powerplant:power_plant", "scifi_nodes:grey", ""}} -}) diff --git a/palm_scanner.lua b/palm_scanner.lua new file mode 100644 index 0000000..da17cbc --- /dev/null +++ b/palm_scanner.lua @@ -0,0 +1,120 @@ + + +----------------------------------------------- +-- Palm scanner -- +----------------------------------------------- +-- /!\ When "overriding" a callback function -- +-- re-use all the parameters in same order ! -- +----------------------------------------------- + +-- after_place_node +-- placer is a player object +local function set_scanner_owner(pos, placer, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name()) +end + +local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing) + -- Some calling function don't send node param, but everybody sends a pos, so : + if not node then + node = minetest.get_node(pos) + end + + if node.name == "scifi_nodes:palm_scanner_off" then + local meta = minetest.get_meta(pos) + meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere + minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2}) + minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.chat_send_player(player:get_player_name(), "Checking : please wait.") + minetest.get_node_timer(pos):start(2) + elseif node.name == "scifi_nodes:palm_scanner_checking" then + minetest.swap_node(pos,{name = "scifi_nodes:palm_scanner_on", param2 = node.param2}) + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + minetest.get_node_timer(pos):start(2) + elseif node.name == "scifi_nodes:palm_scanner_on" then + minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) + mesecon.receptor_off (pos, scifi_nodes.get_switch_rules(node.param2)) + end +end + +-- palm_scanner_checking.on_timer +local function check_owner(pos, elapsed) + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local clicker = meta:get_string("clicker") + local node = minetest.get_node(pos) + if clicker == owner then + minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.chat_send_player(clicker, "Access granted !") + toggle_palm_scanner (pos) + else + minetest.chat_send_player(clicker, "Access refused !") + minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + end +end + +minetest.register_node("scifi_nodes:palm_scanner_off", { + description = "Palm scanner", + tiles = {"scifi_nodes_palm_scanner_off.png",}, + inventory_image = "scifi_nodes_palm_scanner_off.png", + wield_image = "scifi_nodes_palm_scanner_on.png", + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.off,}}, + after_place_node = set_scanner_owner, + on_rightclick = toggle_palm_scanner, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:palm_scanner_checking", { + description = "Palm scanner", + tiles = {{ + name = "scifi_nodes_palm_scanner_checking.png", + animation = {type = "vertical_frames",aspect_w = 16,aspect_h = 16,length = 1.5} + }}, + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + drop = "scifi_nodes:palm_scanner_off", + sounds = default.node_sound_glass_defaults(), + on_timer = check_owner, +}) + +minetest.register_node("scifi_nodes:palm_scanner_on", { + description = "Palm scanner", + sunlight_propagates = true, + buildable_to = false, + tiles = {"scifi_nodes_palm_scanner_on.png",}, + inventory_image = "scifi_nodes_palm_scanner_on.png", + wield_image = "scifi_nodes_palm_scanner_on.png", + drawtype = "signlike", + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + light_source = 5, + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + drop = "scifi_nodes:palm_scanner_off", + mesecons = {receptor = {state = mesecon.state.on,}}, + on_timer = toggle_palm_scanner, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_craft({ + output = "scifi_nodes:palm_scanner_off 2", + recipe = {{"mesecons_powerplant:power_plant", "scifi_nodes:grey", ""}} +}) diff --git a/switches.lua b/switches.lua new file mode 100644 index 0000000..eb79053 --- /dev/null +++ b/switches.lua @@ -0,0 +1,62 @@ + +-------------- +-- Switches -- +-------------- + +local function toggle_switch(pos) + local node = minetest.get_node(pos) + local name = node.name + if name == "scifi_nodes:switch_on" then + minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) + minetest.set_node(pos, {name = "scifi_nodes:switch_off", param2 = node.param2}) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + elseif name == "scifi_nodes:switch_off" then + minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) + minetest.set_node(pos, {name = "scifi_nodes:switch_on", param2 = node.param2}) + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + minetest.get_node_timer(pos):start(2) + end +end + +minetest.register_node("scifi_nodes:switch_on", { + description = "Wall switch", + sunlight_propagates = true, + buildable_to = false, + tiles = {"scifi_nodes_switch_on.png",}, + inventory_image = "scifi_nodes_switch_on.png", + wield_image = "scifi_nodes_switch_on.png", + drawtype = "signlike", + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + light_source = 5, + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.on,}}, + sounds = default.node_sound_glass_defaults(), + on_rightclick = toggle_switch, + on_timer = toggle_switch +}) + +minetest.register_node("scifi_nodes:switch_off", { + description = "Wall switch", + tiles = {"scifi_nodes_switch_off.png",}, + inventory_image = "scifi_nodes_switch_on.png", + wield_image = "scifi_nodes_switch_on.png", + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.off,}}, + sounds = default.node_sound_glass_defaults(), + on_rightclick = toggle_switch +}) + +minetest.register_craft({ + output = "scifi_nodes:switch_off 2", + recipe = {{"mesecons_button:button_off", "scifi_nodes:grey", ""}} +})