Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions technic/machines/LV/lamp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"),
Expand All @@ -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

Expand Down