ceilinglamp.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --[[
  2. Tubelib Addons 2
  3. ================
  4. Copyright (C) 2017-2020 Joachim Stolberg
  5. AGPL v3
  6. See LICENSE.txt for more information
  7. ceilinglamp.lua:
  8. ]]--
  9. -- Load support for I18n
  10. local S = tubelib_addons2.S
  11. local function switch_on(pos, node)
  12. node.name = "tubelib_addons2:ceilinglamp_on"
  13. minetest.swap_node(pos, node)
  14. end
  15. local function switch_off(pos, node)
  16. node.name = "tubelib_addons2:ceilinglamp"
  17. minetest.swap_node(pos, node)
  18. local pos1 = {x=pos.x-5, y=pos.y-5, z=pos.z-5}
  19. local pos2 = {x=pos.x+5, y=pos.y+5, z=pos.z+5}
  20. minetest.fix_light(pos1, pos2)
  21. end
  22. minetest.register_node("tubelib_addons2:ceilinglamp", {
  23. description = S("Tubelib Ceiling Lamp"),
  24. tiles = {
  25. -- up, down, right, left, back, front
  26. 'tubelib_addons2_ceilinglamp_top.png',
  27. 'tubelib_addons2_ceilinglamp_bottom.png',
  28. 'tubelib_addons2_ceilinglamp.png',
  29. },
  30. drawtype = "nodebox",
  31. node_box = {
  32. type = "fixed",
  33. fixed = {
  34. {-5/16, -5/16, -5/16, 5/16, -7/16, 5/16},
  35. {-4/16, -7/16, -4/16, 4/16, -8/16, 4/16},
  36. },
  37. },
  38. selection_box = {
  39. type = "wallmounted",
  40. wall_top = {-5/16, 5/16, -5/16, 5/16, 8/16, 5/16},
  41. wall_bottom = {-5/16, -8/16, -5/16, 5/16, -5/16, 5/16},
  42. wall_side = {-8/16, -5/16, -5/16, -5/16, 5/16, 5/16}
  43. },
  44. after_place_node = function(pos, placer)
  45. local number = tubelib.add_node(pos, "tubelib_addons2:ceilinglamp")
  46. local meta = minetest.get_meta(pos)
  47. meta:set_string("infotext", S("Tubelib Ceiling Lamp").." "..number)
  48. end,
  49. on_rightclick = function(pos, node, clicker)
  50. if not minetest.is_protected(pos, clicker:get_player_name()) then
  51. switch_on(pos, node)
  52. end
  53. end,
  54. after_dig_node = function(pos)
  55. tubelib.remove_node(pos)
  56. end,
  57. paramtype = "light",
  58. light_source = 0,
  59. sunlight_propagates = true,
  60. paramtype2 = "wallmounted",
  61. groups = {choppy=2, cracky=2, crumbly=2},
  62. is_ground_content = false,
  63. sounds = default.node_sound_glass_defaults(),
  64. })
  65. minetest.register_node("tubelib_addons2:ceilinglamp_on", {
  66. description = S("Tubelib Ceiling Lamp"),
  67. tiles = {
  68. -- up, down, right, left, back, front
  69. 'tubelib_addons2_ceilinglamp_top.png',
  70. 'tubelib_addons2_ceilinglamp_bottom.png',
  71. 'tubelib_addons2_ceilinglamp.png',
  72. },
  73. drawtype = "nodebox",
  74. node_box = {
  75. type = "fixed",
  76. fixed = {
  77. {-5/16, -5/16, -5/16, 5/16, -7/16, 5/16},
  78. {-4/16, -7/16, -4/16, 4/16, -8/16, 4/16},
  79. },
  80. },
  81. selection_box = {
  82. type = "wallmounted",
  83. wall_top = {-5/16, 5/16, -5/16, 5/16, 8/16, 5/16},
  84. wall_bottom = {-5/16, -8/16, -5/16, 5/16, -5/16, 5/16},
  85. wall_side = {-8/16, -5/16, -5/16, -5/16, 5/16, 5/16}
  86. },
  87. on_rightclick = function(pos, node, clicker)
  88. if not minetest.is_protected(pos, clicker:get_player_name()) then
  89. switch_off(pos, node)
  90. end
  91. end,
  92. paramtype = "light",
  93. light_source = 12,
  94. sunlight_propagates = true,
  95. paramtype2 = "wallmounted",
  96. groups = {crumbly=0, not_in_creative_inventory=1},
  97. is_ground_content = false,
  98. sounds = default.node_sound_glass_defaults(),
  99. })
  100. minetest.register_craft({
  101. type = "shapeless",
  102. output = "tubelib_addons2:ceilinglamp 3",
  103. recipe = {"tubelib:lamp", "default:wood", "default:glass"},
  104. })
  105. tubelib.register_node("tubelib_addons2:ceilinglamp", {"tubelib_addons2:ceilinglamp_on"}, {
  106. on_recv_message = function(pos, topic, payload)
  107. local node = minetest.get_node(pos)
  108. if topic == "on" then
  109. switch_on(pos, node)
  110. elseif topic == "off" then
  111. switch_off(pos, node)
  112. end
  113. end,
  114. })