From 41550da87ba4057e7fc4f33c077f70d8115c08bb Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 21 Feb 2022 16:51:52 +0100 Subject: [PATCH] Fix redstone comparator flooding crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redstone comparators have two modes, comparison mode & subtraction mode. Before this patch, the functions to turn comparators on or off attempted to swap nodes with comparators in the same mode, but failed to determine the correct replacement node, if the existing node was not a comparator. When a comparator in an on state (e.g. powered by a filled cauldron) was flooded, the flooding dropped the comparator and replaced the comparator node that was to be swapped out with air, which lead to a server crash. This patch changes the functions that turn comparators on or off so they only swap existing nodes with comparators in the same mode if the name of the replacement node can be determined – i.e. if it is not nil. --- mods/ITEMS/REDSTONE/mcl_comparators/init.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua index 3517e09cbf..01b42c3403 100644 --- a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua @@ -43,14 +43,20 @@ end local function comparator_activate(pos, node) local def = minetest.registered_nodes[node.name] - minetest.swap_node(pos, { name = def.comparator_onstate, param2 = node.param2 }) + local onstate = def.comparator_onstate + if onstate then + minetest.swap_node(pos, { name = onstate, param2 = node.param2 }) + end minetest.after(0.1, comparator_turnon , {pos = pos, node = node}) end local function comparator_deactivate(pos, node) local def = minetest.registered_nodes[node.name] - minetest.swap_node(pos, { name = def.comparator_offstate, param2 = node.param2 }) + local offstate = def.comparator_offstate + if offstate then + minetest.swap_node(pos, { name = offstate, param2 = node.param2 }) + end minetest.after(0.1, comparator_turnoff, {pos = pos, node = node}) end