Minetest mod that adds scifi themed nodes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
2.7 KiB

  1. --------------
  2. -- Switches --
  3. --------------
  4. local has_mesecons = minetest.get_modpath("mesecons")
  5. local function toggle_switch(pos, _, player)
  6. local node = minetest.get_node(pos)
  7. local name = node.name
  8. if name == "scifi_nodes:protected_switch_on" then
  9. -- toggle off
  10. minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos})
  11. minetest.set_node(pos, {name = "scifi_nodes:protected_switch_off", param2 = node.param2})
  12. mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2))
  13. elseif name == "scifi_nodes:protected_switch_off" then
  14. -- toggle on, check protection first
  15. if player and minetest.is_protected(pos, player:get_player_name()) then
  16. -- position is protected, abort
  17. minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos})
  18. return
  19. end
  20. minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos})
  21. minetest.set_node(pos, {name = "scifi_nodes:protected_switch_on", param2 = node.param2})
  22. mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2))
  23. minetest.get_node_timer(pos):start(2)
  24. end
  25. end
  26. minetest.register_node("scifi_nodes:protected_switch_on", {
  27. description = "Protected wall switch",
  28. sunlight_propagates = true,
  29. buildable_to = false,
  30. tiles = {"scifi_nodes_switch_on.png",},
  31. inventory_image = "scifi_nodes_switch_on.png",
  32. wield_image = "scifi_nodes_switch_on.png",
  33. drawtype = "signlike",
  34. node_box = {type = "wallmounted",},
  35. selection_box = {type = "wallmounted",},
  36. paramtype = "light",
  37. paramtype2 = "wallmounted",
  38. light_source = 5,
  39. groups = {
  40. cracky=1,
  41. oddly_breakable_by_hand = 1,
  42. not_in_creative_inventory = 1,
  43. mesecon_needs_receiver = 1
  44. },
  45. mesecons = {
  46. receptor = {
  47. state = (has_mesecons and mesecon.state.on)
  48. }
  49. },
  50. sounds = default.node_sound_glass_defaults(),
  51. on_rightclick = (has_mesecons and toggle_switch),
  52. on_timer = (has_mesecons and toggle_switch)
  53. })
  54. minetest.register_node("scifi_nodes:protected_switch_off", {
  55. description = "Protected wall switch",
  56. tiles = {"scifi_nodes_switch_off.png",},
  57. inventory_image = "scifi_nodes_switch_on.png",
  58. wield_image = "scifi_nodes_switch_on.png",
  59. drawtype = "signlike",
  60. sunlight_propagates = true,
  61. buildable_to = false,
  62. node_box = {type = "wallmounted",},
  63. selection_box = {type = "wallmounted",},
  64. paramtype = "light",
  65. paramtype2 = "wallmounted",
  66. groups = {
  67. cracky = 1,
  68. oddly_breakable_by_hand = 1,
  69. mesecon_needs_receiver = 1
  70. },
  71. mesecons = {
  72. receptor = {
  73. state = (has_mesecons and mesecon.state.off)
  74. }
  75. },
  76. sounds = default.node_sound_glass_defaults(),
  77. on_rightclick = (has_mesecons and toggle_switch)
  78. })
  79. minetest.register_craft({
  80. output = "scifi_nodes:protected_switch_off 2",
  81. type = "shapeless",
  82. recipe = {"scifi_nodes:switch_off", "default:steel_ingot"}
  83. })