2020-08-18 03:11:37 +02:00
worldeditadditions.erode = { }
dofile ( worldeditadditions.modpath .. " /lib/erode/snowballs.lua " )
2020-08-21 14:27:40 +02:00
function worldeditadditions . erode . run ( pos1 , pos2 , algorithm , params )
pos1 , pos2 = worldedit.sort_pos ( pos1 , pos2 )
local manip , area = worldedit.manip_helpers . init ( pos1 , pos2 )
local data = manip : get_data ( )
local heightmap_size = { }
heightmap_size [ 0 ] = ( pos2.z - pos1.z ) + 1
heightmap_size [ 1 ] = ( pos2.x - pos1.x ) + 1
2020-08-21 21:59:50 +02:00
local region_height = ( pos2.y - pos1.y ) + 1
2020-08-21 14:27:40 +02:00
local heightmap = worldeditadditions.make_heightmap ( pos1 , pos2 , manip , area , data )
local heightmap_eroded = worldeditadditions.shallowcopy ( heightmap )
2020-08-21 21:59:50 +02:00
-- print("[erode.run] algorithm: "..algorithm..", params:");
-- print(worldeditadditions.map_stringify(params))
2020-08-21 14:27:40 +02:00
worldeditadditions.print_2d ( heightmap , heightmap_size [ 1 ] )
if algorithm == " snowballs " then
2020-08-21 21:59:50 +02:00
local success , msg = worldeditadditions.erode . snowballs ( heightmap , heightmap_eroded , heightmap_size , region_height , params )
2020-08-21 14:27:40 +02:00
if not success then return success , msg end
else
return false , " Error: Unknown algorithm ' " .. algorithm .. " '. Currently implemented algorithms: snowballs (2d; hydraulic-like). Ideas for algorithms to implement are welcome! "
end
2020-08-21 16:21:10 +02:00
local success , stats = worldeditadditions.apply_heightmap_changes (
2020-08-21 14:27:40 +02:00
pos1 , pos2 , area , data ,
heightmap , heightmap_eroded , heightmap_size
)
2020-08-21 16:21:10 +02:00
if not success then return success , stats end
2020-08-21 14:27:40 +02:00
worldedit.manip_helpers . finish ( manip , data )
2020-08-21 16:21:10 +02:00
print ( " [erode] stats " )
print ( worldeditadditions.map_stringify ( stats ) )
2020-08-21 14:27:40 +02:00
return true , stats
end