Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function has_neighbour_with_name(pos, name)
- for x = -1, 1, 1 do
- for y = -1, 1, 1 do
- for z = -1, 1, 1 do
- local pos0 = { x = pos.x + x,
- y = pos.y + y,
- z = pos.z + z }
- if pos.x ~= pos0.x or pos.y ~= pos0.y or pos.z ~= pos0.z then
- local node = minetest.get_node_or_nil(pos0)
- if node and node ~=nil and node.name ~= nil and node.name == name then
- return true
- end
- end
- end
- end
- end
- return false
- end
- bulb_node_base =
- {
- groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
- on_construct =
- function(pos)
- -- schedule timer
- minetest.get_node_timer(pos):start(0.1)
- end,
- on_destruct =
- function(pos)
- minetest.get_node_timer(pos):stop()
- end,
- on_timer =
- function(pos, elapsed)
- local self = minetest.get_node_or_nil(pos)
- if has_neighbour_with_name(pos, "tutorial:bulb") or
- has_neighbour_with_name(pos, "tutorial:bulb_shine") then
- if self.name ~= "tutorial:bulb_shine" then
- minetest.add_node(pos, {name="tutorial:bulb_shine"})
- return
- end
- else
- if self.name ~= "tutorial:bulb" then
- minetest.add_node(pos, {name="tutorial:bulb"})
- return
- end
- end
- -- re-schedule timer
- minetest.get_node_timer(pos):start(0.1)
- end,
- }
- bulb_node = bulb_node_base
- bulb_node.tiles =
- {
- "tutorial_1.png",
- "tutorial_2.png",
- "tutorial_3.png",
- "tutorial_4.png",
- "tutorial_5.png",
- "tutorial_6.png"
- }
- minetest.register_node("tutorial:bulb", bulb_node)
- bulb_shine_node = bulb_node_base
- bulb_shine_node.tiles = {"tutorial_light.png"}
- bulb_shine_node.light_source = 14
- minetest.register_node("tutorial:bulb_shine", bulb_shine_node)
- minetest.register_craft({
- output = 'tutorial:bulb 99',
- recipe = {
- {'default:wood', 'default:stone', ''},
- {'', '', ''},
- {'', '', ''},
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement