Use more appropriate node swapping
This commit is contained in:
parent
9fa1b2b4ff
commit
9365fd9515
1
TODO.txt
1
TODO.txt
@ -4,4 +4,3 @@ TODO:
|
||||
- update inventories when items are replaced:
|
||||
- creative
|
||||
- storage (chests, etc.)
|
||||
- fix top nodes disappearing with /replace_node command
|
||||
|
9
chat.lua
9
chat.lua
@ -241,8 +241,7 @@ core.register_chatcommand(cmd_repo.node.cmd_rep, {
|
||||
return false, cmd_repo.param.mal_radius .. "\n\n" .. help
|
||||
end
|
||||
|
||||
local new_node = core.registered_nodes[tgt]
|
||||
if not new_node then
|
||||
if not core.registered_nodes[tgt] then
|
||||
return false, S('Cannot use unknown node "@1" as replacement.', tgt)
|
||||
end
|
||||
|
||||
@ -251,9 +250,11 @@ core.register_chatcommand(cmd_repo.node.cmd_rep, {
|
||||
for _, npos in ipairs(pos_list(ppos, radius)) do
|
||||
local node = core.get_node_or_nil(npos)
|
||||
if node and node.name == src then
|
||||
core.remove_node(npos)
|
||||
core.place_node(npos, new_node)
|
||||
if core.swap_node(npos, {name=tgt}) then
|
||||
total_replaced = total_replaced + 1
|
||||
else
|
||||
cleaner.log("error", "could not replace node at " .. core.pos_to_string(npos, 0))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,12 +75,9 @@ core.register_lbm({
|
||||
nodenames = {"group:to_replace"},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
core.remove_node(pos)
|
||||
|
||||
local new_node_name = cleaner.get_replace_nodes()[node.name]
|
||||
local new_node = core.registered_nodes[new_node_name]
|
||||
if new_node then
|
||||
core.place_node(pos, new_node)
|
||||
if core.registered_nodes[new_node_name] then
|
||||
core.swap_node(pos, {name=new_node_name})
|
||||
else
|
||||
cleaner.log("error", "cannot replace with unregistered node \"" .. tostring(new_node_name) .. "\"")
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user