From 5b4240b0f922021c746020d9ad1bdced41012b21 Mon Sep 17 00:00:00 2001 From: kakalak-lumberjack Date: Thu, 25 May 2023 21:53:36 -0400 Subject: [PATCH] Do not replace pointed nodes with corresponding conversion nodes and code clean up --- init.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index b19bf48..394ea33 100644 --- a/init.lua +++ b/init.lua @@ -176,10 +176,20 @@ replacer.replace = function(itemstack, user, pointed_thing, mode) return nil end - -- do not replace if there is nothing to be done + -- do not replace if pointed node is same as current replacement node unless orientation is changed if (node.name == daten[1]) then - - -- the node itshelf remains the same, but the orientation was changed + -- the node itself remains the same, but the orientation was changed + if (node.param1 ~= daten[2] or node.param2 ~= daten[3]) then + minetest.add_node(pos, { + name = node.name, + param1 = daten[2], + param2 = daten[3] + }) + end + return nil + -- do not replace nodes that would be converted to current replacement node if selected by replacer + elseif (replacer.conversions[node.name] == daten[1]) then + -- if orientation is changed then maintain pointed node type if (node.param1 ~= daten[2] or node.param2 ~= daten[3]) then minetest.add_node(pos, { name = node.name, @@ -187,7 +197,6 @@ replacer.replace = function(itemstack, user, pointed_thing, mode) param2 = daten[3] }) end - return nil end