mirror of
https://codeberg.org/AntumLuanti/mod-cleaner.git
synced 2025-03-21 15:41:22 +00:00
Add method for cleaning/replacing items
This commit is contained in:
parent
8b5d09283e
commit
0daee12f57
4 changed files with 57 additions and 1 deletions
1
TODO.txt
1
TODO.txt
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
- allow nodes to be cleaned to be replaced by another node
|
- allow nodes to be cleaned to be replaced by another node
|
||||||
- methods for cleaning/replacing items
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
- changed license to MIT
|
- changed license to MIT
|
||||||
- "clean_entities" & "clean_nodes" files now use json format
|
- "clean_entities" & "clean_nodes" files now use json format
|
||||||
- nodes can be replaced with other nodes
|
- nodes can be replaced with other nodes
|
||||||
|
- items can be replaced with other items (<world_path>/clean_items.json file)
|
||||||
|
|
||||||
|
|
||||||
0.4
|
0.4
|
||||||
|
|
1
init.lua
1
init.lua
|
@ -34,6 +34,7 @@ end
|
||||||
local scripts = {
|
local scripts = {
|
||||||
"entities",
|
"entities",
|
||||||
"nodes",
|
"nodes",
|
||||||
|
"items",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, script in ipairs(scripts) do
|
for _, script in ipairs(scripts) do
|
||||||
|
|
55
items.lua
Normal file
55
items.lua
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
|
||||||
|
local misc = dofile(cleaner.modpath .. "/misc_functions.lua")
|
||||||
|
|
||||||
|
-- populate nodes list from file in world path
|
||||||
|
local i_list = {replace={}}
|
||||||
|
local i_path = core.get_worldpath() .. "/clean_items.json"
|
||||||
|
local i_file = io.open(i_path, "r")
|
||||||
|
|
||||||
|
if i_file then
|
||||||
|
local data_in = core.parse_json(i_file:read("*a"))
|
||||||
|
i_file:close()
|
||||||
|
if data_in then
|
||||||
|
i_list = data_in
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- update json file with any changes
|
||||||
|
i_file = io.open(i_path, "w")
|
||||||
|
if i_file then
|
||||||
|
local data_out = core.write_json(i_list, true)
|
||||||
|
|
||||||
|
data_out = data_out:gsub("\"replace\" : null", "\"replace\" : {}")
|
||||||
|
|
||||||
|
i_file:write(data_out)
|
||||||
|
i_file:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- register actions for after server startup
|
||||||
|
core.after(0, function()
|
||||||
|
for i_old, i_new in pairs(i_list.replace) do
|
||||||
|
cleaner.log("action", "replacing item \"" .. i_old .. "\" with \"" .. i_new .. "\"")
|
||||||
|
|
||||||
|
if not core.registered_items[i_old] then
|
||||||
|
cleaner.log("info", "\"" .. i_old .. "\" not registered, not unregistering")
|
||||||
|
else
|
||||||
|
cleaner.log("warning", "overriding registered item \"" .. i_old .. "\"")
|
||||||
|
|
||||||
|
core.unregister_item(i_old)
|
||||||
|
if core.registered_items[i_old] then
|
||||||
|
cleaner.log("error", "could not unregister \"" .. i_old .. "\"")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not core.registered_items[i_new] then
|
||||||
|
cleaner.log("warning", "adding alias for unregistered item \"" .. i_new .. "\"")
|
||||||
|
end
|
||||||
|
|
||||||
|
core.register_alias(i_old, i_new)
|
||||||
|
if core.registered_aliases[i_old] == i_new then
|
||||||
|
cleaner.log("info", "registered alias \"" .. i_old .. "\" for \"" .. i_new .. "\"")
|
||||||
|
else
|
||||||
|
cleaner.log("error", "could not register alias \"" .. i_old .. "\" for \"" .. i_new .. "\"")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
Loading…
Add table
Reference in a new issue