From 9d6cc18569775b1470aaf9b882b96ef329fb981a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Fri, 25 Oct 2024 17:51:47 +0200 Subject: [PATCH] Change API to schedule updates --- mods/ITEMS/REDSTONE/mcl_comparators/init.lua | 4 ++-- mods/ITEMS/REDSTONE/mcl_redstone/API.md | 2 +- mods/ITEMS/REDSTONE/mcl_redstone/eventqueue.lua | 2 +- mods/ITEMS/REDSTONE/mcl_redstone/logic.lua | 7 ++++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua index f27ef3ac2..3fd97be24 100644 --- a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua @@ -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 diff --git a/mods/ITEMS/REDSTONE/mcl_redstone/API.md b/mods/ITEMS/REDSTONE/mcl_redstone/API.md index fee0ca53e..fa2005a65 100644 --- a/mods/ITEMS/REDSTONE/mcl_redstone/API.md +++ b/mods/ITEMS/REDSTONE/mcl_redstone/API.md @@ -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`. diff --git a/mods/ITEMS/REDSTONE/mcl_redstone/eventqueue.lua b/mods/ITEMS/REDSTONE/mcl_redstone/eventqueue.lua index 5a715652d..0d66a1352 100644 --- a/mods/ITEMS/REDSTONE/mcl_redstone/eventqueue.lua +++ b/mods/ITEMS/REDSTONE/mcl_redstone/eventqueue.lua @@ -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 diff --git a/mods/ITEMS/REDSTONE/mcl_redstone/logic.lua b/mods/ITEMS/REDSTONE/mcl_redstone/logic.lua index 36b608376..3a8453b4e 100644 --- a/mods/ITEMS/REDSTONE/mcl_redstone/logic.lua +++ b/mods/ITEMS/REDSTONE/mcl_redstone/logic.lua @@ -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.