2022-09-18 16:59:57 +00:00
local wea_c = worldeditadditions_core
2021-12-28 02:17:26 +00:00
local wea = worldeditadditions
2022-09-18 16:59:57 +00:00
local wea_cmd = worldeditadditions_commands
local Vector3 = wea_c.Vector3
2021-12-28 02:17:26 +00:00
-- ███████ ██████ ██ ██ ██ ██████ ████████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██ ██████ ██
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ██████ ███████ ██ ██
2022-05-19 21:10:09 +00:00
worldeditadditions_core.register_command ( " sculpt " , {
2023-07-01 01:38:14 +00:00
params = " [<brush_name=default> [<brush_size=8> [<height=1>]]] " ,
2021-12-28 02:17:26 +00:00
description = " Applies a sculpting brush to the terrain with a given height. See //sculptlist to list all available brushes. Note that while the brush size is configurable, the actual brush size you end up with may be slightly different to that which you request due to brush size restrictions. " ,
privs = { worldedit = true } ,
require_pos = 1 ,
parse = function ( params_text )
if not params_text or params_text == " " then
2023-06-29 02:19:30 +00:00
params_text = " circle "
2021-12-28 02:17:26 +00:00
end
2022-09-18 16:59:57 +00:00
local parts = wea_c.split_shell ( params_text )
2021-12-28 02:17:26 +00:00
2023-06-29 02:19:30 +00:00
local brush_name = " circle "
local brush_size = 8
2023-07-01 01:38:14 +00:00
local height = 1
2021-12-28 02:17:26 +00:00
if # parts >= 1 then
brush_name = table.remove ( parts , 1 )
if not wea.sculpt . brushes [ brush_name ] then
return false , " A brush with the name ' " .. brush_name .. " ' doesn't exist. Try using //sculptlist to list all available brushes. "
end
end
if # parts >= 1 then
brush_size = tonumber ( table.remove ( parts , 1 ) )
if not brush_size or brush_size < 1 then
return false , " Invalid brush size. Brush sizes must be a positive integer. "
end
end
2023-07-01 01:38:14 +00:00
if # parts >= 1 then
height = tonumber ( table.remove ( parts , 1 ) )
if not height then
return false ,
" Invalid height value (must be an integer - negative values lower terrain instead of raising it) "
end
end
2021-12-28 02:17:26 +00:00
2021-12-28 15:22:51 +00:00
brush_size = Vector3.new ( brush_size , brush_size , 0 ) : floor ( )
2023-07-01 01:38:14 +00:00
return true , brush_name , brush_size , math.floor ( height )
2021-12-28 02:17:26 +00:00
end ,
2023-07-01 01:38:14 +00:00
nodes_needed = function ( name , brush_name , brush_size , height )
2021-12-28 02:17:26 +00:00
local success , brush , size_actual = wea.sculpt . make_brush ( brush_name , brush_size )
if not success then return 0 end
-- This solution allows for brushes with negative values
-- it also allows for brushes that 'break the rules' and have values
-- that exceed the -1 to 1 range
2022-09-18 16:59:57 +00:00
local brush_min = wea_c.min ( brush )
local brush_max = wea_c.max ( brush )
2021-12-28 02:17:26 +00:00
local range_nodes = ( brush_max * height ) - ( brush_min * height )
return size_actual.x * size_actual.y * range_nodes
end ,
2023-07-01 01:38:14 +00:00
func = function ( name , brush_name , brush_size , height )
2022-09-18 16:59:57 +00:00
local start_time = wea_c.get_ms_time ( )
2022-01-02 14:45:46 +00:00
2022-09-18 16:59:57 +00:00
local pos1 = wea_c.Vector3 . clone ( worldedit.pos1 [ name ] )
2021-12-28 02:17:26 +00:00
local success , stats = wea.sculpt . apply (
pos1 ,
2023-07-01 01:38:14 +00:00
brush_name , brush_size , height
2021-12-28 02:17:26 +00:00
)
if not success then return success , stats.added end
2022-09-18 16:59:57 +00:00
local time_taken = wea_c.get_ms_time ( ) - start_time
2021-12-28 02:17:26 +00:00
minetest.log ( " action " , name .. " used //sculpt at " .. pos1 .. " , adding " .. stats.added .. " nodes and removing " .. stats.removed .. " nodes in " .. time_taken .. " s " )
2022-09-18 16:59:57 +00:00
return true , stats.added .. " nodes added and " .. stats.removed .. " removed in " .. wea_c.format . human_time ( time_taken )
2021-12-28 02:17:26 +00:00
end
} )