lights.light_above = function(pos, val)
   local val = val or '14'
   local above = {x=pos.x, y=pos.y+1, z=pos.z}
   local top_node = minetest.get_node(above)
   if top_node.name == 'air' then
      minetest.set_node(above,{name='lights:source_'..val})
   end
end

lights.remove_above = function(pos)
   local above = {x=pos.x, y=pos.y+1, z=pos.z}
   local top_node = minetest.get_node(above)
   if minetest.get_item_group(top_node.name, 'invisible_light') > 0 then
      minetest.remove_node(above)
   end
end

lights.chandelier_placement = function(pos)
   local pos1 = {x=pos.x-2, y=pos.y-4, z=pos.z-2}
   local pos2 = {x=pos.x+2, y=pos.y-4, z=pos.z+2}
   worldedit.replace(pos1, pos2, 'air', 'lights:source_14', false)
end

lights.chandelier_removal = function(pos)
   local pos1 = {x=pos.x-2, y=pos.y-4, z=pos.z-2}
   local pos2 = {x=pos.x+2, y=pos.y-4, z=pos.z+2}
   worldedit.replace(pos1, pos2, 'lights:source_14', 'air', false)
end

lights.drop_light = function(pos, val) --Drops a light to the ground
   local i = 1
   while i < 20 do
      local new_pos = {x=pos.x, y=pos.y-i, z=pos.z}
      local new_node = minetest.get_node(new_pos)
      if new_node.name == 'air' then
         i = i + 1
      end
      if new_node.name ~= 'air' then
         if i > 2 then
            i = i - 1
            minetest.set_node({x=pos.x, y=pos.y-i, z=pos.z},{name='lights:source_'..val})
         end
         i = 21
      end
   end
end

lights.dropped_light_removal = function(pos) --Removes a dropped light.
   local i = 1
   while i < 20 do
      local new_pos = {x=pos.x, y=pos.y-i, z=pos.z}
      local new_node = minetest.get_node(new_pos)
      if minetest.get_item_group(new_node.name, 'invisible_light') > 0 then
         minetest.remove_node(new_pos)
         i = 21
      end
      i = i + 1
   end
end
