Minetest mod that adds scifi themed nodes https://content.minetest.net/packages/D00Med/scifi_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.

82 lines
2.4KB

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