add support for unregistering ores via world path file

This commit is contained in:
Jordan Irwin 2021-07-12 18:11:37 -07:00
parent efc5ef2660
commit bb36a723d3
4 changed files with 34 additions and 1 deletions

View file

@ -1,4 +1,3 @@
TODO:
- add localization support
- add support for unregistering ores via world path file

16
api.lua
View file

@ -72,6 +72,22 @@ end
if cleaner.unsafe then
local remove_ores = {}
--- Retrieves list of ores to be removed.
--
-- @treturn table Ores to be replaced.
function cleaner.get_remove_ores()
return remove_ores
end
--- Registers an ore to be removed after server startup.
--
-- @tparam string src Ore technical name.
function cleaner.register_ore_removal(src)
table.insert(remove_ores, src)
end
--- Removes an ore definition.
--
-- @tparam string src Ore technical name.

View file

@ -43,6 +43,7 @@ local scripts = {
"entities",
"nodes",
"items",
"ores",
}
for _, script in ipairs(scripts) do

17
ores.lua Normal file
View file

@ -0,0 +1,17 @@
if not cleaner.unsafe then return end
local aux = dofile(cleaner.modpath .. "/misc_functions.lua")
local ores_data = aux.get_world_data().ores
for _, ore in ipairs(ores_data.remove) do
cleaner.register_ore_removal(ore)
end
core.register_on_mods_loaded(function()
for _, ore in ipairs(cleaner.get_remove_ores()) do
cleaner.log("action", "unregistering ore: " .. ore)
cleaner.remove_ore(ore)
end
end)