2017-08-30 14:54:33 -07:00
|
|
|
--[[ Clean Entities mod
|
2017-08-30 14:38:48 -07:00
|
|
|
License: CC0
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
2017-08-30 14:54:33 -07:00
|
|
|
cleane = {}
|
|
|
|
cleane.name = core.get_current_modname()
|
2017-08-30 14:38:48 -07:00
|
|
|
|
|
|
|
local debug = core.settings:get_bool('enable_debug_mods')
|
|
|
|
|
|
|
|
local function log(level, msg)
|
2017-08-30 14:54:33 -07:00
|
|
|
core.log(level, '[' .. cleane.name .. '] ' .. msg)
|
2017-08-30 14:38:48 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local function logDebug(msg)
|
|
|
|
if debug then
|
2017-08-30 14:54:33 -07:00
|
|
|
core.log('DEBUG: [' .. cleane.name .. '] ' .. msg)
|
2017-08-30 14:38:48 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-07 21:46:59 -07:00
|
|
|
local old_nodes = {}
|
2017-05-18 15:06:02 -07:00
|
|
|
local old_entities = {}
|
|
|
|
|
2017-05-18 16:20:49 -07:00
|
|
|
-- Old/Missing nodes that should be replaced with something currently in game
|
|
|
|
local replace_nodes = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- "Replaces" an old/non-existent node
|
|
|
|
local function replace_node(old_node, new_node)
|
2017-08-30 14:12:44 -07:00
|
|
|
core.register_alias(old_node, new_node)
|
2017-05-18 16:20:49 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-05-18 15:06:02 -07:00
|
|
|
for _,node_name in ipairs(old_nodes) do
|
2017-08-30 14:14:55 -07:00
|
|
|
core.register_node(':' .. node_name, {
|
2017-05-18 15:06:02 -07:00
|
|
|
groups = {old=1},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-08-30 14:12:44 -07:00
|
|
|
core.register_abm({
|
2017-06-07 21:46:17 -07:00
|
|
|
nodenames = {'group:old'},
|
2017-05-18 15:06:02 -07:00
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node)
|
2017-08-30 14:12:44 -07:00
|
|
|
core.remove_node(pos)
|
2017-05-18 15:06:02 -07:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-08-30 14:39:12 -07:00
|
|
|
|
|
|
|
-- Populate entities list from file in world path
|
|
|
|
local e_list = nil
|
|
|
|
local e_path = core.get_worldpath() .. '/clean_entities.txt'
|
|
|
|
local e_file = io.open(e_path, 'r')
|
|
|
|
if e_file then
|
|
|
|
e_list = e_file:read('*a')
|
|
|
|
e_file:close()
|
|
|
|
else
|
|
|
|
-- Create empty file
|
|
|
|
e_file = io.open(e_path, 'w')
|
|
|
|
if e_file then
|
|
|
|
e_file:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if e_list then
|
|
|
|
logDebug('Loading entities to clean from file ...')
|
|
|
|
|
|
|
|
e_list = string.split(e_list, '\n')
|
|
|
|
for _, entity_name in ipairs(e_list) do
|
|
|
|
table.insert(old_entities, entity_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-30 14:14:55 -07:00
|
|
|
for _, entity_name in ipairs(old_entities) do
|
2017-08-30 14:39:12 -07:00
|
|
|
logDebug('Cleaning entity: ' .. entity_name)
|
|
|
|
|
2017-08-30 14:14:55 -07:00
|
|
|
core.register_entity(':' .. entity_name, {
|
2017-05-18 15:06:02 -07:00
|
|
|
on_activate = function(self, staticdata)
|
|
|
|
self.object:remove()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2017-05-18 16:20:49 -07:00
|
|
|
|
|
|
|
-- Replace old nodes
|
|
|
|
for _, node_group in pairs(replace_nodes) do
|
|
|
|
replace_node(node_group[1], node_group[2])
|
|
|
|
end
|