init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. -- WALL BUTTON
  2. -- A button that when pressed emits power for 1 second
  3. -- and then turns off again
  4. mesecon.button_turnoff = function (pos)
  5. local node = minetest.env:get_node(pos)
  6. if node.name=="mesecons_button:button_on" then --has not been dug
  7. mesecon:swap_node(pos, "mesecons_button:button_off")
  8. minetest.sound_play("mesecons_button_pop", {pos=pos})
  9. local rules = mesecon.rules.buttonlike_get(node)
  10. mesecon:receptor_off(pos, rules)
  11. end
  12. end
  13. minetest.register_node("mesecons_button:button_off", {
  14. drawtype = "nodebox",
  15. tiles = {
  16. "jeija_wall_button_sides.png",
  17. "jeija_wall_button_sides.png",
  18. "jeija_wall_button_sides.png",
  19. "jeija_wall_button_sides.png",
  20. "jeija_wall_button_sides.png",
  21. "jeija_wall_button_off.png"
  22. },
  23. paramtype = "light",
  24. paramtype2 = "facedir",
  25. legacy_wallmounted = true,
  26. walkable = false,
  27. sunlight_propagates = true,
  28. selection_box = {
  29. type = "fixed",
  30. fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 }
  31. },
  32. node_box = {
  33. type = "fixed",
  34. fixed = {
  35. { -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 }, -- the thin plate behind the button
  36. { -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself
  37. }
  38. },
  39. groups = {dig_immediate=2, mesecon_needs_receiver = 1},
  40. description = "Button",
  41. on_punch = function (pos, node)
  42. mesecon:swap_node(pos, "mesecons_button:button_on")
  43. mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
  44. minetest.sound_play("mesecons_button_push", {pos=pos})
  45. minetest.after(1, mesecon.button_turnoff, pos)
  46. end,
  47. sounds = default.node_sound_stone_defaults(),
  48. mesecons = {receptor = {
  49. state = mesecon.state.off,
  50. rules = mesecon.rules.buttonlike_get
  51. }}
  52. })
  53. minetest.register_node("mesecons_button:button_on", {
  54. drawtype = "nodebox",
  55. tiles = {
  56. "jeija_wall_button_sides.png",
  57. "jeija_wall_button_sides.png",
  58. "jeija_wall_button_sides.png",
  59. "jeija_wall_button_sides.png",
  60. "jeija_wall_button_sides.png",
  61. "jeija_wall_button_on.png"
  62. },
  63. paramtype = "light",
  64. paramtype2 = "facedir",
  65. legacy_wallmounted = true,
  66. walkable = false,
  67. light_source = LIGHT_MAX-7,
  68. sunlight_propagates = true,
  69. selection_box = {
  70. type = "fixed",
  71. fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 }
  72. },
  73. node_box = {
  74. type = "fixed",
  75. fixed = {
  76. { -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 },
  77. { -4/16, -2/16, 11/32, 4/16, 2/16, 6/16 }
  78. }
  79. },
  80. groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
  81. drop = 'mesecons_button:button_off',
  82. description = "Button",
  83. sounds = default.node_sound_stone_defaults(),
  84. mesecons = {receptor = {
  85. state = mesecon.state.on,
  86. rules = mesecon.rules.buttonlike_get
  87. }}
  88. })
  89. minetest.register_craft({
  90. output = "mesecons_button:button_off 2",
  91. recipe = {
  92. {"group:mesecon_conductor_craftable","default:stone"},
  93. }
  94. })