##############################
##
##        WorldEdit
##    Made By M7mdTG ;)
##
##############################

#Distance travelled by smallest surface: 100

scoreboard players operation @e[type=worldedit:pos1,tag=!we_done_first] we_cph1 = @e[type=worldedit:pos1] we_x_scale
scoreboard players operation @e[type=worldedit:pos1,tag=!we_done_first] we_cph2 = @e[type=worldedit:pos1] we_y_scale
scoreboard players set @e[type=worldedit:pos1,tag=!we_done_first] we_x_score 0
scoreboard players set @e[type=worldedit:pos1,tag=!we_done_first] we_y_score 0
scoreboard players set @e[type=worldedit:pos1,tag=!we_done_first] we_z_score 0
tag @e[type=worldedit:pos1,tag=!we_done_first] add we_done_first
 
# xy
 
scoreboard players remove @e[type=worldedit:pos1,scores={we_cph1=1..},tag=we_done_first,tag=!we_done_second] we_cph2 1
scoreboard players remove @e[type=worldedit:pos1,scores={we_cph1=1..},tag=we_done_first,tag=!we_done_second] we_cph1 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=1..},tag=we_done_first,tag=!we_done_second] we_y_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=..-1},tag=we_done_first,tag=!we_done_second] we_x_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=0},tag=we_done_first,tag=!we_done_second] we_y_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=0},tag=we_done_first,tag=!we_done_second] we_x_score 1
tag @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_first,tag=!we_done_secondd] add we_done_secondd
scoreboard players operation @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_first,tag=!we_done_second] we_cph2 = @e[type=worldedit:pos1] we_z_scale
scoreboard players operation @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_first,tag=!we_done_second] we_cph1 = @e[type=worldedit:pos1] we_x_scale
tag @e[type=worldedit:pos1,tag=we_done_first,tag=we_done_secondd,tag=!done_second] add we_done_second
tag @e[type=worldedit:pos1,tag=we_done_first,tag=we_done_second] remove we_done_secondd
 
# xz
 
scoreboard players remove @e[type=worldedit:pos1,scores={we_cph1=1..},tag=we_done_second,tag=!we_done_third] we_cph2 1
scoreboard players remove @e[type=worldedit:pos1,scores={we_cph1=1..},tag=we_done_second,tag=!we_done_third] we_cph1 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=1..},tag=we_done_second,tag=!we_done_third] we_z_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=..-1},tag=we_done_second,tag=!we_done_third] we_x_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=0},tag=we_done_second,tag=!we_done_third] we_z_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=0},tag=we_done_second,tag=!we_done_third] we_x_score 1
tag @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_second,tag=!we_done_thirdd] add we_done_thirdd
scoreboard players operation @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_second,tag=!we_done_third] we_cph2 = @e[type=worldedit:pos1] we_z_scale
scoreboard players operation @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_second,tag=!we_done_third] we_cph1 = @e[type=worldedit:pos1] we_y_scale
tag @e[type=worldedit:pos1,tag=we_done_second,tag=we_done_thirdd,tag=!we_done_third] add we_done_third
tag @e[type=worldedit:pos1,tag=we_done_second,tag=we_done_third] remove we_done_thirdd
 
# yz
 
scoreboard players remove @e[type=worldedit:pos1,scores={we_cph1=1..},tag=we_done_third,tag=!we_done_fourth] we_cph2 1
scoreboard players remove @e[type=worldedit:pos1,scores={we_cph1=1..},tag=we_done_third,tag=!we_done_fourth] we_cph1 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=1..},tag=we_done_third,tag=!we_done_fourth] we_z_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=..-1},tag=we_done_third,tag=!we_done_fourth] we_y_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=0},tag=we_done_third,tag=!we_done_fourth] we_z_score 1
scoreboard players add @e[type=worldedit:pos1,scores={we_cph1=0,we_cph2=0},tag=we_done_third,tag=!we_done_fourth] we_y_score 1
tag @e[type=worldedit:pos1,scores={we_cph1=0},tag=we_done_third,tag=!we_done_fourth] add we_done_fourth
#execute @e[type=worldedit:pos1,tag=we_done_third,tag=we_done_fourth] ~~~ tellraw @a[tag=we_host] {"rawtext":[{"text":"X: <"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_x_score"}},{"text":">, Y: <"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_y_score"}},{"text":">, Z: <"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_z_score"}},{"text":">"}]}

tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=2,we_y_score=..1,we_z_score=..1,we_x_scale=..100}] add we_found_good_surface
tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=2,we_y_score=2,we_z_score=0,we_y_scale=..100}] add we_found_good_surface
tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=2,we_y_score=0,we_z_score=2,we_z_scale=..100}] add we_found_good_surface
tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=..1,we_y_score=2,we_z_score=..1,we_y_scale=..100}] add we_found_good_surface
tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=0,we_y_score=2,we_z_score=2,we_y_scale=..100}] add we_found_good_surface
tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=..1,we_y_score=..1,we_z_score=2,we_z_scale=..100}] add we_found_good_surface
tag @e[type=worldedit:pos1,tag=we_done_fourth,scores={we_x_score=2,we_y_score=2,we_z_score=2,we_x_scale=..100}] add we_found_good_surface

tag @e[type=worldedit:pos1,tag=we_done_fourth,tag=!we_found_good_surface] add we_found_bad_surface
tag @e[type=worldedit:pos1,tag=we_found_good_surface] remove we_done_first
tag @e[type=worldedit:pos1,tag=we_found_good_surface] remove we_done_second
tag @e[type=worldedit:pos1,tag=we_found_good_surface] remove we_done_third
tag @e[type=worldedit:pos1,tag=we_found_good_surface] remove we_done_fourth
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_done_first
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_done_second
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_done_third
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_done_fourth
execute @e[tag=!we_found_good_surface,tag=!we_found_bad_surface,type=worldedit:pos1] ~~~ function we/high-end/optimization/find-surface