mirror of
https://codeberg.org/AntumLuanti/mod-cleaner.git
synced 2025-03-15 12:51:22 +00:00
56 lines
1.1 KiB
Lua
56 lines
1.1 KiB
Lua
--[[ Cleaner mod
|
|
License: CC0
|
|
]]
|
|
|
|
|
|
cleaner = {}
|
|
cleaner.name = core.get_current_modname()
|
|
|
|
local debug = core.settings:get_bool('enable_debug_mods')
|
|
|
|
local function log(level, msg)
|
|
core.log(level, '[' .. cleaner.name .. '] ' .. msg)
|
|
end
|
|
|
|
local function logDebug(msg)
|
|
if debug then
|
|
core.log('DEBUG: [' .. cleaner.name .. '] ' .. msg)
|
|
end
|
|
end
|
|
|
|
|
|
local old_entities = {}
|
|
|
|
-- 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
|
|
|
|
for _, entity_name in ipairs(old_entities) do
|
|
logDebug('Cleaning entity: ' .. entity_name)
|
|
|
|
core.register_entity(':' .. entity_name, {
|
|
on_activate = function(self, staticdata)
|
|
self.object:remove()
|
|
end,
|
|
})
|
|
end
|