2022-09-19 19:30:43 +02:00
local wea = worldeditadditions
2022-09-18 18:59:57 +02:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2020-06-26 22:23:03 +02:00
-- ██ ██ █████ ██ ██ ███████
-- ██ ██ ██ ██ ██ ██ ██
-- ██ █ ██ ███████ ██ ██ ███████
-- ██ ███ ██ ██ ██ ██ ██ ██
-- ███ ███ ██ ██ ███████ ███████ ███████
2022-05-19 23:10:09 +02:00
worldeditadditions_core.register_command ( " walls " , {
2021-10-31 17:41:52 +01:00
params = " [<replace_node=dirt> [<thickness=1>]] " ,
2021-08-05 03:00:38 +02:00
description = " Creates vertical walls of <replace_node> around the inside edges of the defined region. Optionally specifies a thickness for the walls to be created (defaults to 1) " ,
2020-05-11 22:44:18 +02:00
privs = { worldedit = true } ,
require_pos = 2 ,
parse = function ( params_text )
2021-10-31 17:41:52 +01:00
if not params_text or params_text == " " then params_text = " dirt " end
2022-09-18 18:59:57 +02:00
local parts = wea_c.split_shell ( params_text )
2021-08-05 03:00:38 +02:00
local target_node
local thickness = 1
local target_node_raw = table.remove ( parts , 1 )
target_node = worldedit.normalize_nodename ( target_node_raw )
2020-05-11 22:44:18 +02:00
if not target_node then
2021-08-05 03:00:38 +02:00
return false , " Error: Invalid node name ' " .. target_node_raw .. " '. "
2020-05-11 22:44:18 +02:00
end
2021-08-05 03:00:38 +02:00
if # parts > 0 then
local thickness_raw = table.remove ( parts , 1 )
thickness = tonumber ( thickness_raw )
if not thickness then return false , " Error: Invalid thickness value ' " .. thickness_raw .. " '. The thickness value must be a positive integer greater than or equal to 0. " end
if thickness < 1 then return false , " Error: That thickness value ' " .. thickness_raw .. " ' is out of range. The thickness value must be a positive integer greater than or equal to 0. " end
end
return true , target_node , math.floor ( thickness )
2020-05-11 22:44:18 +02:00
end ,
2021-08-05 03:07:20 +02:00
nodes_needed = function ( name , target_node , thickness )
2020-05-11 22:44:18 +02:00
-- //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 ] )
2021-08-05 03:07:20 +02:00
local pos3 = {
x = pos2.x - thickness * 2 ,
z = pos2.z - thickness * 2 ,
y = pos2.y }
2020-05-11 22:44:18 +02:00
return worldedit.volume ( pos1 , pos2 ) - worldedit.volume ( pos1 , pos3 )
end ,
2021-08-05 03:00:38 +02:00
func = function ( name , target_node , thickness )
2022-09-18 18:59:57 +02:00
local start_time = wea_c.get_ms_time ( )
local pos1 , pos2 = Vector3.sort ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
2022-09-19 19:30:43 +02:00
local success , replaced = wea.walls (
2022-09-18 18:59:57 +02:00
pos1 , pos2 ,
2021-08-05 03:00:38 +02:00
target_node , thickness
)
2022-09-18 18:59:57 +02:00
local time_taken = wea_c.get_ms_time ( ) - start_time
2020-05-11 22:44:18 +02:00
2022-09-18 18:59:57 +02:00
minetest.log ( " action " , name .. " used //walls from " .. pos1 .. " to " .. pos2 .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
return true , replaced .. " nodes replaced in " .. wea_c.format . human_time ( time_taken )
2020-05-11 22:44:18 +02:00
end
} )