From 388e5481e73729aa6a0d706dc800cc9f6753bd9a Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Wed, 30 Aug 2017 15:26:59 -0700 Subject: [PATCH] Re-add functionality to clean nodes: Nodes to clean can be listed in 'clean_nodes.txt' file in world path. --- README.md | 2 +- description.txt | 2 +- init.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2dd34e..15faf00 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ --- ### **Description:** -Fork of [PilzAdam's ***clean*** mod][f.pilzadam] for Minetest. +A simple Minetest mod that can be used to remove unknown entities & nodes. Forked from [PilzAdam's ***clean*** mod][f.pilzadam]. --- diff --git a/description.txt b/description.txt index 8f895d0..6611e0e 100644 --- a/description.txt +++ b/description.txt @@ -1 +1 @@ -A simple mod that can be used to remove unknown entities. +A simple mod that can be used to remove unknown entities & nodes. diff --git a/init.lua b/init.lua index f369431..1051499 100644 --- a/init.lua +++ b/init.lua @@ -19,6 +19,8 @@ local function logDebug(msg) end +-- ENTITIES + local old_entities = {} -- Populate entities list from file in world path @@ -54,3 +56,47 @@ for _, entity_name in ipairs(old_entities) do end, }) end + + +-- NODES + +local old_nodes = {} + +-- Populate nodes list from file in world path +local n_list = nil +local n_path = core.get_worldpath() .. '/clean_nodes.txt' +local n_file = io.open(n_path, 'r') +if n_file then + n_list = n_file:read('*a') + n_file:close() +else + -- Create empty file + n_file = io.open(n_path, 'w') + if n_file then + n_file:close() + end +end + +if n_list then + logDebug('Loading nodes to clean from file ...') + + n_list = string.split(n_list, '\n') + for _, node_name in ipairs(n_list) do + table.insert(old_nodes, node_name) + end +end + +for _, node_name in ipairs(old_nodes) do + core.register_node(':' .. node_name, { + groups = {old=1}, + }) +end + +core.register_abm({ + nodenames = {'group:old'}, + interval = 1, + chance = 1, + action = function(pos, node) + core.remove_node(pos) + end, +})