diff --git a/TODO.txt b/TODO.txt index 743eb23..8d013ea 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,4 +4,3 @@ TODO: - update inventories when items are replaced: - creative - storage (chests, etc.) -- fix top nodes disappearing with /replace_node command diff --git a/chat.lua b/chat.lua index 0e4a4dc..c25e9f1 100644 --- a/chat.lua +++ b/chat.lua @@ -241,8 +241,7 @@ core.register_chatcommand(cmd_repo.node.cmd_rep, { return false, cmd_repo.param.mal_radius .. "\n\n" .. help end - local new_node = core.registered_nodes[tgt] - if not new_node then + if not core.registered_nodes[tgt] then return false, S('Cannot use unknown node "@1" as replacement.', tgt) end @@ -251,9 +250,11 @@ core.register_chatcommand(cmd_repo.node.cmd_rep, { for _, npos in ipairs(pos_list(ppos, radius)) do local node = core.get_node_or_nil(npos) if node and node.name == src then - core.remove_node(npos) - core.place_node(npos, new_node) - total_replaced = total_replaced + 1 + if core.swap_node(npos, {name=tgt}) then + total_replaced = total_replaced + 1 + else + cleaner.log("error", "could not replace node at " .. core.pos_to_string(npos, 0)) + end end end diff --git a/nodes.lua b/nodes.lua index 4f1239d..f3878ab 100644 --- a/nodes.lua +++ b/nodes.lua @@ -75,12 +75,9 @@ core.register_lbm({ nodenames = {"group:to_replace"}, run_at_every_load = true, action = function(pos, node) - core.remove_node(pos) - local new_node_name = cleaner.get_replace_nodes()[node.name] - local new_node = core.registered_nodes[new_node_name] - if new_node then - core.place_node(pos, new_node) + if core.registered_nodes[new_node_name] then + core.swap_node(pos, {name=new_node_name}) else cleaner.log("error", "cannot replace with unregistered node \"" .. tostring(new_node_name) .. "\"") end