From bb36a723d322ccf377a699dce6e3536936bf8cbf Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 12 Jul 2021 18:11:37 -0700 Subject: [PATCH] add support for unregistering ores via world path file --- TODO.txt | 1 - api.lua | 16 ++++++++++++++++ init.lua | 1 + ores.lua | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ores.lua diff --git a/TODO.txt b/TODO.txt index e315a16..61ac1fb 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,4 +1,3 @@ TODO: - add localization support -- add support for unregistering ores via world path file diff --git a/api.lua b/api.lua index 622df35..8911c86 100644 --- a/api.lua +++ b/api.lua @@ -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. diff --git a/init.lua b/init.lua index 3a46afd..31df5ff 100644 --- a/init.lua +++ b/init.lua @@ -43,6 +43,7 @@ local scripts = { "entities", "nodes", "items", + "ores", } for _, script in ipairs(scripts) do diff --git a/ores.lua b/ores.lua new file mode 100644 index 0000000..517f60a --- /dev/null +++ b/ores.lua @@ -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)