Change API to schedule updates

This commit is contained in:
Elias Åström 2024-10-25 17:51:47 +02:00 committed by cora
parent d06e025e89
commit 9d6cc18569
4 changed files with 10 additions and 5 deletions

View File

@ -13,12 +13,12 @@ function mcl_redstone.update_comparators(pos)
local node2 = minetest.get_node(pos2)
if dir == minetest.fourdir_to_dir(node2.param2) and node2.name:find("mcl_comparators:comparator_") then
mcl_redstone.schedule_update(pos2)
mcl_redstone.update_node(pos2)
elseif mcl_redstone._solid_opaque_tab[node2.name] then
local pos3 = pos2:add(dir)
local node3 = minetest.get_node(pos3)
if dir == minetest.fourdir_to_dir(node3.param2) and node3.name:find("mcl_comparators:comparator_") then
mcl_redstone.schedule_update(pos3)
mcl_redstone.update_node(pos3)
end
end
end

View File

@ -145,7 +145,7 @@ power level of all six directions.
It is only valid to call this function from a redstone callback (`init` or
`update`). Using it in other places will result in an error.
## `mcl_redstone.schedule_update(pos)`
## `mcl_redstone.update_node(pos)`
Schedule an update to redstone component at `pos`.

View File

@ -202,7 +202,7 @@ function mcl_redstone.tick_step()
end
nupdates = nupdates + 1
mcl_redstone.schedule_update(pos)
mcl_redstone._schedule_update(pos)
mcl_redstone._pending_updates[h] = nil
end

View File

@ -223,7 +223,7 @@ local function call_init(pos)
end
end
function mcl_redstone.schedule_update(pos)
function mcl_redstone._schedule_update(pos)
local node = minetest.get_node(pos)
if update_tab[node.name] then
local ret = update_tab[node.name](pos, node)
@ -233,6 +233,11 @@ function mcl_redstone.schedule_update(pos)
end
end
-- TODO: A bit ugly, could be refactored.
function mcl_redstone.update_node(pos)
mcl_redstone._pending_updates[minetest.hash_node_position(pos)] = pos
end
-- Piston pusher nodes calls this during init to avoid circuits stopping if a
-- piston was extended just before a server restart. It is not a clean solution
-- but it works.