forked from Mirrorlandia_minetest/mesecons
Fix conductor lighting when aliases are used (#582)
This commit is contained in:
parent
4eea0834b5
commit
4c5b13a347
@ -372,7 +372,6 @@ end
|
||||
local light_update_conductors
|
||||
|
||||
-- Calculate the contents of the above set if they have not been calculated.
|
||||
-- This must be called before get_update_light_conductor.
|
||||
local function find_light_update_conductors()
|
||||
-- The expensive calculation is only done the first time.
|
||||
if light_update_conductors then return end
|
||||
@ -415,12 +414,6 @@ local function find_light_update_conductors()
|
||||
end
|
||||
end
|
||||
|
||||
-- This is the callback for swap_node_force in turnon and turnoff. It determines
|
||||
-- whether a conductor node necessitates a lighting update.
|
||||
local function get_update_light_conductor(pos, name)
|
||||
return light_update_conductors[name] ~= nil
|
||||
end
|
||||
|
||||
-- Turn off an equipotential section starting at `pos`, which outputs in the direction of `link`.
|
||||
-- Breadth-first search. Map is abstracted away in a voxelmanip.
|
||||
-- Follow all all conductor paths replacing conductors that were already
|
||||
@ -453,7 +446,7 @@ function mesecon.turnon(pos, link)
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link), get_update_light_conductor)
|
||||
mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link), light_update_conductors[node.name] ~= nil)
|
||||
end
|
||||
|
||||
-- Only conductors with flat rules can be reliably skipped later
|
||||
@ -527,7 +520,7 @@ function mesecon.turnoff(pos, link)
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link), get_update_light_conductor)
|
||||
mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link), light_update_conductors[node.name] ~= nil)
|
||||
end
|
||||
|
||||
-- Only conductors with flat rules can be reliably skipped later
|
||||
|
@ -389,10 +389,10 @@ end
|
||||
--
|
||||
-- Existing param1, param2, and metadata are left alone.
|
||||
--
|
||||
-- See mesecon.swap_node_force for documentation about get_update_light.
|
||||
function mesecon.vm_swap_node(pos, name, get_update_light)
|
||||
-- The swap will necessitate a light update unless update_light equals false.
|
||||
function mesecon.vm_swap_node(pos, name, update_light)
|
||||
local tbl = vm_get_or_create_entry(pos)
|
||||
tbl.update_light = tbl.update_light or (get_update_light == nil or get_update_light(pos, name))
|
||||
tbl.update_light = update_light ~= false or tbl.update_light
|
||||
local index = tbl.va:indexp(pos)
|
||||
tbl.data[index] = minetest.get_content_id(name)
|
||||
tbl.dirty = true
|
||||
@ -426,15 +426,15 @@ end
|
||||
-- Outside a VM transaction, if the mapblock is not loaded, it is pulled into
|
||||
-- the server’s main map data cache and then accessed from there.
|
||||
--
|
||||
-- Inside a VM transaction, the transaction’s VM cache is used. If a third
|
||||
-- argument is supplied, it may be called. If it returns false, the swap does
|
||||
-- not necessitate a lighting update.
|
||||
-- Inside a VM transaction, the transaction’s VM cache is used.
|
||||
--
|
||||
-- This function can only be used to change the node’s name, not its parameters
|
||||
-- or metadata.
|
||||
function mesecon.swap_node_force(pos, name, get_update_light)
|
||||
--
|
||||
-- The swap will necessitate a light update unless update_light equals false.
|
||||
function mesecon.swap_node_force(pos, name, update_light)
|
||||
if vm_cache then
|
||||
return mesecon.vm_swap_node(pos, name, get_update_light)
|
||||
return mesecon.vm_swap_node(pos, name, update_light)
|
||||
else
|
||||
-- This serves to both ensure the mapblock is loaded and also hand us
|
||||
-- the old node table so we can preserve param2.
|
||||
|
Loading…
Reference in New Issue
Block a user