diff --git a/api.lua b/api.lua index dfeedab..e6b5ef7 100644 --- a/api.lua +++ b/api.lua @@ -16,8 +16,14 @@ light_tool.light_beam = function(pos, dir, range) local lightable = light_tool.check(light_tool.lightable_nodes, node.name) local lightable_index = light_tool.check_index(light_tool.lightable_nodes, node.name) local lit = light_tool.check(light_tool.lit_nodes, node.name) - if node.name == "air" or node.name == "light_tool:light" then - minetest.set_node(new_pos, {name = "light_tool:light"}) + + if node.name == "air" then + -- Place temporary light nodes in air: + minetest.set_node(new_pos, {name = "light_tool:light"}) + minetest.get_node_timer(new_pos):start(0.2) + elseif node.name == "light_tool:light" then + -- Reset destruction timer for this light node: + minetest.get_node_timer(new_pos):start(0.2) elseif lightable or node.name == lit then local index = light_tool.check_index(light_tool.lightable_nodes, node.name) diff --git a/init.lua b/init.lua index cf8ee1f..dc5f91a 100644 --- a/init.lua +++ b/init.lua @@ -9,6 +9,9 @@ minetest.register_tool("light_tool:light_tool", { }) light_tool.add_tool("light_tool:light_tool", 20) +-- This is a temporary light source which forms the light beam of a flashlight. +-- When you constructed it, call minetest.get_node_timer(pos):start(lifetime) to make it delete itself. +-- Call start() again to extend the lifetime. minetest.register_node("light_tool:light", { drawtype = "airlike", tiles = {"blank.png"}, @@ -18,10 +21,8 @@ minetest.register_node("light_tool:light", { light_source = 8, pointable = false, buildable_to = true, - on_construct = function(pos) - minetest.after(0.1, function() - minetest.set_node(pos, {name = "air"}) - end) + on_timer = function(pos) + minetest.set_node(pos, {name = "air"}) end, })