2020-05-02 23:37:18 +00:00
-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██
2020-05-10 20:32:01 +00:00
worldedit.register_command ( " overlay " , {
2020-05-02 23:37:18 +00:00
params = " <replace_node> " ,
description = " Places <replace_node> in the last contiguous air space encountered above the first non-air node. In other words, overlays all top-most nodes in the specified area with <replace_node>. " ,
privs = { worldedit = true } ,
2020-05-10 20:32:01 +00:00
require_pos = 2 ,
parse = function ( params_text )
2020-05-02 23:37:18 +00:00
local target_node = worldedit.normalize_nodename ( params_text )
if not target_node then
2020-05-10 20:32:01 +00:00
return false , " Error: Invalid node name "
2020-05-02 23:37:18 +00:00
end
2020-05-10 20:32:01 +00:00
return true , target_node
end ,
nodes_needed = function ( name )
-- //overlay only modifies up to 1 node per column in the selected region
local pos1 , pos2 = worldedit.sort_pos ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
return ( pos2.x - pos1.x ) * ( pos2.y - pos1.y )
end ,
func = function ( name , target_node )
2020-05-02 23:37:18 +00:00
local start_time = os.clock ( )
2020-05-10 20:32:01 +00:00
local changes = worldeditadditions.overlay ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , target_node )
2020-05-02 23:37:18 +00:00
local time_taken = os.clock ( ) - start_time
minetest.log ( " action " , name .. " used //overlay at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " , replacing " .. changes.updated .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. " s " )
2020-05-10 20:32:01 +00:00
return true , changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. " s "
end
2020-05-02 23:37:18 +00:00
} )