From d9764fdac68190af379266f4c46562e99ecabb4b Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Tue, 22 Feb 2022 18:03:05 +0100 Subject: [PATCH 1/2] Add comparator test structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a new test structure to the “/spawnstruct” command which can be spawned with this command: /spawnstruct test_structure_comparator The structure was added to reduce manual work when examining or verifying comparator behaviour after changes to comparator code. --- mods/MAPGEN/mcl_structures/init.lua | 9 ++++++++- .../mcl_structures_test_structure_comparator.mts | Bin 0 -> 242 bytes 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 mods/MAPGEN/mcl_structures/schematics/mcl_structures_test_structure_comparator.mts diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 0383c48a..0c3b1820 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -532,6 +532,11 @@ local function dir_to_rotation(dir) return "0" end +mcl_structures.generate_test_structure_comparator = function(pos, rotation, pr) + local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_test_structure_comparator.mts" + mcl_structures.place_schematic(pos, path, rotation, nil, true, nil, nil, pr) +end + mcl_structures.generate_test_structure_fireproof = function(pos, rotation, pr) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_test_structure_fireproof.mts" mcl_structures.place_schematic(pos, path, rotation, nil, true, nil, nil, pr) @@ -539,7 +544,7 @@ end -- Debug command minetest.register_chatcommand("spawnstruct", { - params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_portal_shrine | test_structure_fireproof", + params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_portal_shrine | test_structure_comparator | test_structure_fireproof", description = S("Generate a pre-defined structure near your position."), privs = {debug = true}, func = function(name, param) @@ -573,6 +578,8 @@ minetest.register_chatcommand("spawnstruct", { mcl_structures.generate_end_exit_portal(pos, rot, pr) elseif param == "end_portal_shrine" then mcl_structures.generate_end_portal_shrine(pos, rot, pr) + elseif param == "test_structure_comparator" then + mcl_structures.generate_test_structure_comparator(pos, rot, pr) elseif param == "test_structure_fireproof" then mcl_structures.generate_test_structure_fireproof(pos, rot, pr) elseif param == "" then diff --git a/mods/MAPGEN/mcl_structures/schematics/mcl_structures_test_structure_comparator.mts b/mods/MAPGEN/mcl_structures/schematics/mcl_structures_test_structure_comparator.mts new file mode 100644 index 0000000000000000000000000000000000000000..608beff9d81be192fd1b245986855ed717b6802f GIT binary patch literal 242 zcmYL?u?~VT6h&XGsd02+aRE*I2GhjVurO&Ht)&ztDU`HD-Ei_79P~$>ETA~Ole}~9 zjkcQzhJauIsIFlIlblP+l@>(BCQC9_0AiU2KNm)DRTvsq)~bSZhZ@I%sx$?!O|nWR z+G&J;3Fcj6UNX(B((a>v+~nL?Uc#)em)Y@T+g9?&b|C1T3zJfcv(Tg=+G3+zpZox5 bjTinMQtaU!ek`YmukbAl!aaufYwUdhm!VVu literal 0 HcmV?d00001 From be915478afe1a87b1c7846e53971a5961404163c Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 21 Feb 2022 16:51:52 +0100 Subject: [PATCH 2/2] 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 a8fab81d..c5cae6ad 100644 --- a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua @@ -43,14 +43,20 @@ end local comparator_activate = function(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 comparator_deactivate = function(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