mirror of
https://codeberg.org/AntumLuanti/mod-cleaner.git
synced 2025-03-21 15:41:22 +00:00
Add support for unregistering ores
This commit is contained in:
parent
69f87b6b73
commit
2d7c5aee1f
4 changed files with 76 additions and 1 deletions
2
TODO.txt
2
TODO.txt
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
- add localization support
|
- add localization support
|
||||||
- add support for unregistering/replacing ores
|
- add support for unregistering ores via world path file
|
||||||
- change API method names to "register_[replace/remove]_*"
|
- change API method names to "register_[replace/remove]_*"
|
||||||
|
|
37
api.lua
37
api.lua
|
@ -62,3 +62,40 @@ function cleaner.replace_node(src, tgt)
|
||||||
|
|
||||||
replace_nodes[src] = tgt
|
replace_nodes[src] = tgt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Unsafe methods.
|
||||||
|
--
|
||||||
|
-- Enabled with `cleaner.unsafe` setting.
|
||||||
|
--
|
||||||
|
-- @section unsafe
|
||||||
|
|
||||||
|
|
||||||
|
if cleaner.unsafe then
|
||||||
|
--- Removes an ore definition.
|
||||||
|
--
|
||||||
|
-- @tparam string src Ore technical name.
|
||||||
|
function cleaner.remove_ore(src)
|
||||||
|
local remove_ids = {}
|
||||||
|
local total_removed = 0
|
||||||
|
local registered = false
|
||||||
|
|
||||||
|
for id, def in pairs(core.registered_ores) do
|
||||||
|
if def.ore == src then
|
||||||
|
table.insert(remove_ids, id)
|
||||||
|
registered = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, id in ipairs(remove_ids) do
|
||||||
|
core.registered_ores[id] = nil
|
||||||
|
if core.registered_ores[id] then
|
||||||
|
cleaner.log("error", "unable to unregister ore " .. id)
|
||||||
|
else
|
||||||
|
total_removed = total_removed + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return registered, total_removed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ v1.2
|
||||||
- replace_node
|
- replace_node
|
||||||
- find_unknown_nodes
|
- find_unknown_nodes
|
||||||
- added setting for enabling "unsafe" methods & commands
|
- added setting for enabling "unsafe" methods & commands
|
||||||
|
- added support for unregistering ores
|
||||||
|
|
||||||
v1.1
|
v1.1
|
||||||
----
|
----
|
||||||
|
|
37
chat.lua
37
chat.lua
|
@ -239,3 +239,40 @@ core.register_chatcommand("find_unknown_nodes", {
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
--- Unsafe commands.
|
||||||
|
--
|
||||||
|
-- Enabled with `cleaner.unsafe` setting.
|
||||||
|
--
|
||||||
|
-- @section unsafe
|
||||||
|
|
||||||
|
|
||||||
|
if cleaner.unsafe then
|
||||||
|
--- Registers an ore to be removed.
|
||||||
|
--
|
||||||
|
-- @chatcmd remove_ore
|
||||||
|
-- @param ore Ore technical name.
|
||||||
|
core.register_chatcommand("remove_ore", {
|
||||||
|
privs = {server=true},
|
||||||
|
description = "Remove an ore from game.",
|
||||||
|
params = "<ore>",
|
||||||
|
func = function(name, param)
|
||||||
|
if param:find(" ") then
|
||||||
|
return false, "Too many parameters."
|
||||||
|
end
|
||||||
|
|
||||||
|
core.after(0, function()
|
||||||
|
local registered, total_removed = cleaner.remove_ore(param)
|
||||||
|
|
||||||
|
if not registered then
|
||||||
|
core.chat_send_player(name, "Ore \"" .. param .. "\" not found, not unregistering.")
|
||||||
|
else
|
||||||
|
core.chat_send_player(name, "Unregistered " .. total_removed .. " ores (this will be undone after server restart).")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue