Use single ABM with group for replacing nodes
This commit is contained in:
parent
35f409c5c0
commit
e8359d8db3
17
nodes.lua
17
nodes.lua
@ -68,13 +68,24 @@ core.register_abm({
|
|||||||
for n_old, n_new in pairs(n_list.replace) do
|
for n_old, n_new in pairs(n_list.replace) do
|
||||||
cleaner.log("debug", "Replacing node \"" .. n_old .. "\" with \"" .. n_new .. "\"")
|
cleaner.log("debug", "Replacing node \"" .. n_old .. "\" with \"" .. n_new .. "\"")
|
||||||
|
|
||||||
|
core.register_node(":" .. n_old, {
|
||||||
|
groups = {to_replace=1},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
core.register_abm({
|
core.register_abm({
|
||||||
nodenames = {n_old},
|
nodenames = {"group:to_replace"},
|
||||||
interval = 1,
|
interval = 1,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
core.remove_node(pos)
|
core.remove_node(pos)
|
||||||
core.place_node(pos, n_new)
|
|
||||||
|
local new_node_name = n_list.replace[node.name]
|
||||||
|
local new_node = core.registered_nodes[new_node_name]
|
||||||
|
if new_node then
|
||||||
|
core.place_node(pos, new_node)
|
||||||
|
else
|
||||||
|
cleaner.log("error", "cannot replace with unregistered node \"" .. tostring(new_node_name) .. "\"")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user