Guest User

Untitled

a guest
Sep 11th, 2016
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function has_neighbour_with_name(pos, name)
  2.      for x = -1, 1, 1 do
  3.             for y = -1, 1, 1 do
  4.                  for z = -1, 1, 1 do
  5.                         local pos0 = { x = pos.x + x,
  6.                                                      y = pos.y + y,
  7.                                                      z = pos.z + z }
  8.                         if pos.x ~= pos0.x or pos.y ~= pos0.y or pos.z ~= pos0.z then
  9.                              local node = minetest.get_node_or_nil(pos0)
  10.                              if node and node ~=nil and node.name ~= nil and node.name == name then
  11.                                     return true
  12.                              end
  13.                         end
  14.                  end
  15.             end
  16.      end
  17.  
  18.      return false
  19. end
  20.  
  21. bulb_node_base =
  22. {
  23.     groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
  24.     on_construct =
  25.         function(pos)
  26.              -- schedule timer
  27.              minetest.get_node_timer(pos):start(0.1)
  28.         end,
  29.  
  30.     on_destruct =
  31.         function(pos)
  32.              minetest.get_node_timer(pos):stop()
  33.         end,
  34.  
  35.     on_timer =
  36.         function(pos, elapsed)
  37.              local self = minetest.get_node_or_nil(pos)
  38.  
  39.              if has_neighbour_with_name(pos, "tutorial:bulb") or
  40.                   has_neighbour_with_name(pos, "tutorial:bulb_shine") then
  41.                     if self.name ~= "tutorial:bulb_shine" then
  42.                          minetest.add_node(pos, {name="tutorial:bulb_shine"})
  43.                          return
  44.                     end
  45.              else
  46.                     if self.name ~= "tutorial:bulb" then
  47.                          minetest.add_node(pos, {name="tutorial:bulb"})
  48.                          return
  49.                     end
  50.              end
  51.  
  52.              -- re-schedule timer
  53.              minetest.get_node_timer(pos):start(0.1)
  54.         end,
  55. }
  56.  
  57. bulb_node = bulb_node_base
  58. bulb_node.tiles =
  59. {
  60.   "tutorial_1.png",
  61.   "tutorial_2.png",
  62.   "tutorial_3.png",
  63.   "tutorial_4.png",
  64.   "tutorial_5.png",
  65.   "tutorial_6.png"
  66. }
  67. minetest.register_node("tutorial:bulb", bulb_node)
  68.  
  69. bulb_shine_node = bulb_node_base
  70. bulb_shine_node.tiles = {"tutorial_light.png"}
  71. bulb_shine_node.light_source = 14
  72. minetest.register_node("tutorial:bulb_shine", bulb_shine_node)
  73.  
  74.  
  75. minetest.register_craft({
  76.     output = 'tutorial:bulb 99',
  77.     recipe = {
  78.         {'default:wood', 'default:stone', ''},
  79.         {'',             '',              ''},
  80.         {'',             '',              ''},
  81.     }
  82. })
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×