industriallamp.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. --[[
  2. Tubelib Addons 2
  3. ================
  4. Copyright (C) 2017-2020 Joachim Stolberg
  5. AGPL v3
  6. See LICENSE.txt for more information
  7. industriallamp.lua:
  8. ]]--
  9. -- Load support for I18n
  10. local S = tubelib_addons2.S
  11. local function switch_on(pos, node)
  12. if string.sub(node.name, -3) ~= "_on" then
  13. node.name = node.name.."_on"
  14. minetest.swap_node(pos, node)
  15. end
  16. end
  17. local function switch_off(pos, node)
  18. if string.sub(node.name, -3) == "_on" then
  19. node.name = string.sub(node.name, 1, -4)
  20. minetest.swap_node(pos, node)
  21. local pos1 = {x=pos.x-5, y=pos.y-5, z=pos.z-5}
  22. local pos2 = {x=pos.x+5, y=pos.y+5, z=pos.z+5}
  23. minetest.fix_light(pos1, pos2)
  24. end
  25. end
  26. local function register_lamp(tbl)
  27. local num, tiles, tiles_on, node_box, size = tbl.num, tbl.tiles, tbl.tiles_on, tbl.node_box, tbl.size
  28. minetest.register_node("tubelib_addons2:industriallamp"..num, {
  29. description = S("Tubelib Industrial Lamp").." "..num,
  30. tiles = tiles,
  31. drawtype = "nodebox",
  32. node_box = node_box,
  33. inventory_image = 'tubelib_addons2_industriallamp_inv'..num..'.png',
  34. selection_box = {
  35. type = "wallmounted",
  36. wall_top = {-size.x, 0.5 - size.y, -size.z, size.x, 0.5, size.z},
  37. wall_bottom = {-size.x, -0.5, -size.z, size.x, -0.5 + size.y, size.z},
  38. wall_side = {-0.5, -size.z, size.x, -0.5 + size.y, size.z, -size.x},
  39. },
  40. after_place_node = function(pos, placer)
  41. local number = tubelib.add_node(pos, "tubelib_addons2:industriallamp"..num)
  42. local meta = minetest.get_meta(pos)
  43. meta:set_string("infotext", S("Tubelib Industrial Lamp").." "..num..": "..number)
  44. end,
  45. on_rightclick = function(pos, node, clicker)
  46. if not minetest.is_protected(pos, clicker:get_player_name()) then
  47. node.name = "tubelib_addons2:industriallamp"..num.."_on"
  48. minetest.swap_node(pos, node)
  49. end
  50. end,
  51. after_dig_node = function(pos)
  52. tubelib.remove_node(pos)
  53. end,
  54. paramtype = "light",
  55. light_source = 0,
  56. sunlight_propagates = true,
  57. paramtype2 = "wallmounted",
  58. groups = {choppy=2, cracky=2, crumbly=2},
  59. is_ground_content = false,
  60. sounds = default.node_sound_glass_defaults(),
  61. })
  62. minetest.register_node("tubelib_addons2:industriallamp"..num.."_on", {
  63. description = S("Tubelib Industrial Lamp").." "..num,
  64. tiles = tiles_on,
  65. drawtype = "nodebox",
  66. node_box = node_box,
  67. selection_box = {
  68. type = "wallmounted",
  69. wall_top = {-size.x, 0.5 - size.y, -size.z, size.x, 0.5, size.z},
  70. wall_bottom = {-size.x, -0.5, -size.z, size.x, -0.5 + size.y, size.z},
  71. wall_side = {-0.5, -size.z, size.x, -0.5 + size.y, size.z, -size.x},
  72. },
  73. after_place_node = function(pos, placer)
  74. local number = tubelib.add_node(pos, "tubelib_addons2:industriallamp"..num)
  75. local meta = minetest.get_meta(pos)
  76. meta:set_string("infotext", S("Tubelib Industrial Lamp").." "..num..": "..number)
  77. end,
  78. on_rightclick = function(pos, node, clicker)
  79. if not minetest.is_protected(pos, clicker:get_player_name()) then
  80. node.name = "tubelib_addons2:industriallamp"..num
  81. minetest.swap_node(pos, node)
  82. local pos1 = {x=pos.x-5, y=pos.y-5, z=pos.z-5}
  83. local pos2 = {x=pos.x+5, y=pos.y+5, z=pos.z+5}
  84. minetest.fix_light(pos1, pos2)
  85. end
  86. end,
  87. after_dig_node = function(pos)
  88. tubelib.remove_node(pos)
  89. end,
  90. paramtype = "light",
  91. light_source = minetest.LIGHT_MAX,
  92. sunlight_propagates = true,
  93. paramtype2 = "wallmounted",
  94. groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
  95. drop = "tubelib_addons2:industriallamp"..num,
  96. is_ground_content = false,
  97. sounds = default.node_sound_glass_defaults(),
  98. })
  99. tubelib.register_node("tubelib_addons2:industriallamp"..num, {"tubelib_addons2:industriallamp"..num.."_on"}, {
  100. on_recv_message = function(pos, topic, payload)
  101. local node = minetest.get_node(pos)
  102. if topic == "on" then
  103. switch_on(pos, node)
  104. elseif topic == "off" then
  105. switch_off(pos, node)
  106. end
  107. end,
  108. })
  109. end
  110. minetest.register_craft({
  111. output = "tubelib_addons2:industriallamp1 2",
  112. recipe = {
  113. {"", "", ""},
  114. {"default:glass", "tubelib:wlanchip", "dye:grey"},
  115. {"basic_materials:plastic_strip", "default:copper_ingot", "basic_materials:plastic_strip"},
  116. },
  117. })
  118. minetest.register_craft({
  119. output = "tubelib_addons2:industriallamp2 2",
  120. recipe = {
  121. {"default:glass", "default:glass", ""},
  122. {"tubelib:wlanchip", "dye:black", ""},
  123. {"basic_materials:steel_bar", "basic_materials:steel_bar", ""},
  124. },
  125. })
  126. register_lamp({
  127. num = 1,
  128. tiles = {
  129. -- up, down, right, left, back, front
  130. 'tubelib_addons2_industriallamp1.png',
  131. 'tubelib_addons2_industriallamp1.png',
  132. 'tubelib_addons2_industriallamp1.png^[transformR180',
  133. 'tubelib_addons2_industriallamp1.png^[transformR180',
  134. 'tubelib_addons2_industriallamp1.png',
  135. 'tubelib_addons2_industriallamp1.png',
  136. },
  137. tiles_on = {
  138. -- up, down, right, left, back, front
  139. 'tubelib_addons2_industriallamp1_on.png',
  140. 'tubelib_addons2_industriallamp1_on.png',
  141. 'tubelib_addons2_industriallamp1_on.png^[transformR180',
  142. 'tubelib_addons2_industriallamp1_on.png^[transformR180',
  143. 'tubelib_addons2_industriallamp1_on.png',
  144. 'tubelib_addons2_industriallamp1_on.png',
  145. },
  146. node_box = {
  147. type = "fixed",
  148. fixed = {
  149. {-8/16, -8/16, -3/32, -6/16, -9/32, 3/32},
  150. { 6/16, -8/16, -3/32, 8/16, -9/32, 3/32},
  151. {-6/16, -7/16, -1/16, 6/16, -5/16, 1/16},
  152. },
  153. },
  154. size = {x = 8/16, y = 7/32, z = 3/32}
  155. })
  156. register_lamp({
  157. num = 2,
  158. tiles = {
  159. -- up, down, right, left, back, front
  160. 'tubelib_addons2_industriallamp2.png',
  161. 'tubelib_addons2_industriallamp2.png',
  162. 'tubelib_addons2_industriallamp2.png^[transformR180',
  163. 'tubelib_addons2_industriallamp2.png^[transformR180',
  164. 'tubelib_addons2_industriallamp2.png',
  165. 'tubelib_addons2_industriallamp2.png',
  166. },
  167. tiles_on = {
  168. -- up, down, right, left, back, front
  169. 'tubelib_addons2_industriallamp2_on.png',
  170. 'tubelib_addons2_industriallamp2_on.png',
  171. 'tubelib_addons2_industriallamp2_on.png^[transformR180',
  172. 'tubelib_addons2_industriallamp2_on.png^[transformR180',
  173. 'tubelib_addons2_industriallamp2_on.png',
  174. 'tubelib_addons2_industriallamp2_on.png',
  175. },
  176. node_box = {
  177. type = "fixed",
  178. fixed = {
  179. {-8/32, -16/32, -4/32, 8/32, -9/32, 4/32},
  180. {-7/32, -16/32, -5/32, 7/32, -9/32, 5/32},
  181. {-7/32, -9/32, -4/32, 7/32, -8/32, 4/32},
  182. },
  183. },
  184. size = {x = 8/32, y = 8/32, z = 5/32}
  185. })