Re-add functionality to clean nodes:

Nodes to clean can be listed in 'clean_nodes.txt' file in world path.
This commit is contained in:
Jordan Irwin 2017-08-30 15:26:59 -07:00
parent 04338946da
commit 388e5481e7
3 changed files with 48 additions and 2 deletions

View file

@ -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].
---

View file

@ -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.

View file

@ -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,
})