Fix conductors with aliases again

This commit is contained in:
Jude Melton-Houghton 2022-05-20 22:14:29 -04:00
parent 27c3c515b4
commit f3a354c683
2 changed files with 23 additions and 5 deletions

View File

@ -372,17 +372,33 @@ end
-- The set of conductor states which require light updates when they change. -- The set of conductor states which require light updates when they change.
local light_update_conductors local light_update_conductors
-- Calculate the contents of the above set if they have not been calculated. -- Prepare all conductor content before the first turnon/turnoff:
local function find_light_update_conductors() -- - Resolve aliases in conductor state lists.
-- - Calculate the contents of light_update_conductors.
local function prepare_conductors()
-- The expensive calculation is only done the first time. -- The expensive calculation is only done the first time.
if light_update_conductors then return end if light_update_conductors then return end
light_update_conductors = {} light_update_conductors = {}
-- Find conductors whose lighting characteristics change depending on their state.
local checked = {} local checked = {}
for name, def in pairs(minetest.registered_nodes) do for name, def in pairs(minetest.registered_nodes) do
local conductor = mesecon.get_conductor(name) local conductor = mesecon.get_conductor(name)
-- Resolve aliases in state list.
if conductor then
if conductor.onstate then
conductor.onstate = minetest.registered_aliases[conductor.onstate] or conductor.onstate
elseif conductor.offstate then
conductor.offstate = minetest.registered_aliases[conductor.offstate] or conductor.offstate
else
for i, state in ipairs(conductor.states) do
conductor.states[i] = minetest.registered_aliases[state] or state
end
end
end
-- Find conductors whose lighting characteristics change depending on their state.
if conductor and not checked[name] then if conductor and not checked[name] then
-- Find the other states of the conductor besides the current one. -- Find the other states of the conductor besides the current one.
local other_states local other_states
@ -420,7 +436,7 @@ end
-- Follow all all conductor paths replacing conductors that were already -- Follow all all conductor paths replacing conductors that were already
-- looked at, activating / changing all effectors along the way. -- looked at, activating / changing all effectors along the way.
function mesecon.turnon(pos, link) function mesecon.turnon(pos, link)
find_light_update_conductors() prepare_conductors()
local frontiers = mesecon.fifo_queue.new() local frontiers = mesecon.fifo_queue.new()
frontiers:add({pos = pos, link = link}) frontiers:add({pos = pos, link = link})
@ -483,7 +499,7 @@ end
-- depth = indicates order in which signals wire fired, higher is later -- depth = indicates order in which signals wire fired, higher is later
-- } -- }
function mesecon.turnoff(pos, link) function mesecon.turnoff(pos, link)
find_light_update_conductors() prepare_conductors()
local frontiers = mesecon.fifo_queue.new() local frontiers = mesecon.fifo_queue.new()
frontiers:add({pos = pos, link = link}) frontiers:add({pos = pos, link = link})

View File

@ -403,6 +403,7 @@ function mesecon.vm_get_node(pos)
end end
-- Sets a nodes name during a VoxelManipulator-based transaction. -- Sets a nodes name during a VoxelManipulator-based transaction.
-- Aliases may not work correctly.
-- --
-- Existing param1, param2, and metadata are left alone. -- Existing param1, param2, and metadata are left alone.
-- --
@ -453,6 +454,7 @@ end
-- the servers main map data cache and then accessed from there. -- the servers main map data cache and then accessed from there.
-- --
-- Inside a VM transaction, the transactions VM cache is used. -- Inside a VM transaction, the transactions VM cache is used.
-- Aliases may not work correctly.
-- --
-- This function can only be used to change the nodes name, not its parameters -- This function can only be used to change the nodes name, not its parameters
-- or metadata. -- or metadata.