diff --git a/technic/machines/LV/lamp.lua b/technic/machines/LV/lamp.lua index 86cc07b3..67f8218c 100644 --- a/technic/machines/LV/lamp.lua +++ b/technic/machines/LV/lamp.lua @@ -2,7 +2,6 @@ -- LV Lamp - a powerful light source. -- Illuminates a 7x7x3(H) volume below itself with light bright as the sun. - local S = technic.getter local desc = S("@1 Lamp", S("LV")) @@ -11,7 +10,6 @@ local unpowered_desc = S("@1 Unpowered", desc) local off_desc = S("@1 Off", desc) local demand = 50 - -- Invisible light source node used for illumination minetest.register_node("technic:dummy_light_source", { description = S("Dummy light source node"), @@ -29,16 +27,31 @@ minetest.register_node("technic:dummy_light_source", { groups = {not_in_creative_inventory = 1} }) +local cid_light = minetest.get_content_id("technic:dummy_light_source") +local cid_air = minetest.CONTENT_AIR local function illuminate(pos, active) - local pos1 = {x = pos.x - 3, y = pos.y - 1, z = pos.z - 3} - local pos2 = {x = pos.x + 3, y = pos.y - 3, z = pos.z + 3} - - local find_node = active and "air" or "technic:dummy_light_source" - local set_node = {name = (active and "technic:dummy_light_source" or "air")} - - for _,p in pairs(minetest.find_nodes_in_area(pos1, pos2, find_node)) do - minetest.set_node(p, set_node) + local pos1 = {x = pos.x - 3, y = pos.y - 3, z = pos.z - 3} + local pos2 = {x = pos.x + 3, y = pos.y - 1, z = pos.z + 3} + + local vm = minetest.get_voxel_manip() + local emin, emax = vm:read_from_map(pos1, pos2) + local va = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) + local node_data = vm:get_data() + + local find_node = active and cid_air or cid_light + local set_node = active and cid_light or cid_air + + local dirty = false + for i in va:iterp(pos1, pos2) do + if node_data[i] == find_node then + node_data[i] = set_node + dirty = true + end + end + if dirty then + vm:set_data(node_data) + vm:write_to_map() end end