2021-10-31 16:11:01 +01:00
2022-09-18 18:59:57 +02:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2021-10-31 16:11:01 +01:00
2022-09-18 18:59:57 +02:00
wea_c.register_command ( " spiral2 " , {
2022-05-24 02:05:09 +02:00
params = " [circle|square] [<replace_node=dirt> [<interval=3> [<acceleration=0>] ] ] " ,
2021-10-31 18:11:24 +01:00
description = " Generates a spiral that fills the defined region using the specified replace node. The spiral is either square (default) or circular in shape. The interval specifies the distance between the walls of the spiral, and the acceleration specifies how quickly this value should increase. " ,
2021-10-31 16:11:01 +01:00
privs = { worldedit = true } ,
require_pos = 2 ,
parse = function ( params_text )
2021-10-31 17:42:12 +01:00
if not params_text then params_text = " " end
2022-09-18 18:59:57 +02:00
params_text = wea_c.trim ( params_text )
2021-10-31 18:11:24 +01:00
if params_text == " " then return true , " square " , " dirt " , 3 , 0 end
2021-10-31 16:11:01 +01:00
2022-09-18 18:59:57 +02:00
local parts = wea_c.split_shell ( params_text )
2021-10-31 16:11:01 +01:00
2021-10-31 18:11:24 +01:00
local mode = " square "
2021-10-31 16:11:01 +01:00
local target_node = " dirt "
local target_node_found = false
local interval = 3
local acceleration = 0
if parts [ 1 ] ~= " circle " and parts [ 1 ] ~= " square " then
target_node = parts [ 1 ]
target_node_found = true
2021-10-31 17:42:12 +01:00
table.remove ( parts , 1 )
2021-10-31 16:11:01 +01:00
else
mode = parts [ 1 ]
table.remove ( parts , 1 )
end
if # parts >= 1 and not target_node_found then
target_node = parts [ 1 ]
table.remove ( parts , 1 )
end
if # parts >= 1 then
interval = tonumber ( parts [ 1 ] )
2021-10-31 17:42:12 +01:00
if not interval then
2021-10-31 20:48:51 +01:00
return false , " Error: Invalid interval value ' " .. tostring ( parts [ 1 ] ) .. " '. Interval values must be integers. "
2021-10-31 17:42:12 +01:00
end
2021-10-31 16:11:01 +01:00
table.remove ( parts , 1 )
end
if # parts >= 1 then
2021-10-31 17:42:12 +01:00
acceleration = tonumber ( parts [ 1 ] )
if not acceleration then
2021-10-31 20:48:51 +01:00
return false , " Error: Invalid acceleration value ' " .. tostring ( parts [ 1 ] ) .. " '. Acceleration values must be integers. "
2021-10-31 17:42:12 +01:00
end
2021-10-31 16:11:01 +01:00
table.remove ( parts , 1 )
end
local target_node_norm = worldedit.normalize_nodename ( target_node )
if not target_node_norm then
2021-10-31 20:48:51 +01:00
return false , " Error: Unknown node ' " .. tostring ( target_node ) .. " '. "
2021-10-31 16:11:01 +01:00
end
return true , mode , target_node_norm , interval , acceleration
end ,
nodes_needed = function ( name )
return worldedit.volume ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
end ,
func = function ( name , mode , target_node , interval , acceleration )
2022-09-18 18:59:57 +02:00
local start_time = wea_c.get_ms_time ( )
2021-10-31 16:11:01 +01:00
local pos1 , pos2 = Vector3.sort ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
local success , count
if mode == " circle " then
2022-09-18 18:59:57 +02:00
success , count = worldeditadditions.spiral_circle (
2021-10-31 17:42:12 +01:00
pos1 , pos2 ,
target_node ,
interval , acceleration
)
if not success then return success , count end
2021-10-31 16:11:01 +01:00
else
2022-09-18 18:59:57 +02:00
success , count = worldeditadditions.spiral_square (
2021-10-31 16:11:01 +01:00
pos1 , pos2 ,
target_node ,
interval , acceleration
)
if not success then return success , count end
end
2022-09-18 18:59:57 +02:00
local time_taken = wea_c.get_ms_time ( ) - start_time
2021-10-31 16:11:01 +01:00
minetest.log ( " action " , name .. " used //spiral at " .. pos1 .. " - " .. pos2 .. " , adding " .. count .. " nodes in " .. time_taken .. " s " )
2022-09-18 18:59:57 +02:00
return true , count .. " nodes replaced in " .. wea_c.format . human_time ( time_taken )
2021-10-31 16:11:01 +01:00
end
} )