lamp.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. --[[
  2. Tube Library
  3. ============
  4. Copyright (C) 2017-2020 Joachim Stolberg
  5. AGPL v3
  6. See LICENSE.txt for more information
  7. lamp.lua:
  8. Example of a simple communication node, only receiving messages from others.
  9. This node claims a position number and registers its message interface.
  10. The Lamp supports the following messages:
  11. - topic = "on", payload = nil
  12. - topic = "off" , payload = nil
  13. ]]--
  14. -- Load support for I18n
  15. local S = tubelib.S
  16. local function switch_on(pos, node)
  17. node.name = "tubelib:lamp_on"
  18. minetest.swap_node(pos, node)
  19. end
  20. local function switch_off(pos, node)
  21. node.name = "tubelib:lamp"
  22. minetest.swap_node(pos, node)
  23. end
  24. minetest.register_node("tubelib:lamp", {
  25. description = S("Tubelib Lamp"),
  26. tiles = {
  27. 'tubelib_lamp.png',
  28. },
  29. after_place_node = function(pos, placer)
  30. local number = tubelib.add_node(pos, "tubelib:lamp") -- <<=== tubelib
  31. local meta = minetest.get_meta(pos)
  32. meta:set_string("infotext", S("Tubelib Lamp").." "..number)
  33. end,
  34. on_rightclick = function(pos, node, clicker)
  35. if not minetest.is_protected(pos, clicker:get_player_name()) then
  36. switch_on(pos, node)
  37. end
  38. end,
  39. after_dig_node = function(pos)
  40. tubelib.remove_node(pos) -- <<=== tubelib
  41. end,
  42. paramtype = "light",
  43. light_source = 0,
  44. sunlight_propagates = true,
  45. paramtype2 = "facedir",
  46. groups = {choppy=2, cracky=2, crumbly=2},
  47. is_ground_content = false,
  48. sounds = default.node_sound_wood_defaults(),
  49. })
  50. minetest.register_node("tubelib:lamp_on", {
  51. description = S("Tubelib Lamp"),
  52. tiles = {
  53. 'tubelib_lamp.png',
  54. },
  55. on_rightclick = function(pos, node, clicker)
  56. if not minetest.is_protected(pos, clicker:get_player_name()) then
  57. switch_off(pos, node)
  58. end
  59. end,
  60. paramtype = "light",
  61. light_source = minetest.LIGHT_MAX,
  62. sunlight_propagates = true,
  63. paramtype2 = "facedir",
  64. groups = {crumbly=0, not_in_creative_inventory=1},
  65. is_ground_content = false,
  66. sounds = default.node_sound_wood_defaults(),
  67. })
  68. minetest.register_craft({
  69. output = "tubelib:lamp 4",
  70. recipe = {
  71. {"wool:white", "wool:white", "wool:white"},
  72. {"tubelib:wlanchip", "default:coal_lump", ""},
  73. {"group:wood", "", "group:wood"},
  74. },
  75. })
  76. --------------------------------------------------------------- tubelib
  77. tubelib.register_node("tubelib:lamp", {"tubelib:lamp_on"}, {
  78. on_pull_item = nil, -- lamp has no inventory
  79. on_push_item = nil, -- lamp has no inventory
  80. on_unpull_item = nil, -- lamp has no inventory
  81. on_recv_message = function(pos, topic, payload)
  82. local node = minetest.get_node(pos)
  83. if topic == "on" then
  84. switch_on(pos, node)
  85. elseif topic == "off" then
  86. switch_off(pos, node)
  87. end
  88. end,
  89. })
  90. --------------------------------------------------------------- tubelib