diff --git a/src/main/resources/assets/carpet/scripts/distance_beta.sc b/src/main/resources/assets/carpet/scripts/distance_beta.sc index a3428132..b1b3bc6d 100644 --- a/src/main/resources/assets/carpet/scripts/distance_beta.sc +++ b/src/main/resources/assets/carpet/scripts/distance_beta.sc @@ -2,44 +2,46 @@ import('math','_euclidean','_manhattan','_round'); __config()->{ 'commands'->{ - 'from '->'set_start', - 'from to '->'_calculate', - 'to '->_(end_pos)->(_calculate(null,end_pos)), + 'from '->'set_start', + 'from to '->'_calculate', + 'to '->_(end_pos)->(_calculate(null,end_pos)), 'toggle_line'->'_toggle_line' }, - 'scope'->'player' + 'arguments' -> { + 'start' -> {'type' -> 'location'}, + 'end' -> {'type' -> 'location'} + } }; -global_position=null; -global_end_position=null; +global_start=null; +global_end=null; global_show_line=false; -global_line = { - 'start_pos'->global_position, - 'end_pos'->global_end_position -}; +__mktp(pos) -> str('!/tp %.6f %.6f %.6f', pos); set_start(pos)->( - global_position= pos; - print(player(),format('gi Initial point set to: ', 'g '+pos,'?/tp '+(str(pos)-','-'['-']'))) + global_start = pos; + global_end = null; + print(player(),format('gi Initial point set to: ', 'g '+pos, __mktp(pos))) ); _toggle_line()->( global_show_line= !global_show_line; if(global_show_line, print('Toggled lines on'); - if(global_end_position,_draw_line()),//making sure that there is a start an end pos, and Ive made it so there is no end pos without start pos + _draw_line() + , // else print('Toggled lines off') ); - null ); _calculate(start_pos, end_pos)->( if(start_pos!=null, set_start(start_pos); - calculate(end_pos), - if(global_position, + calculate(end_pos) + , // else + if(global_start, calculate(end_pos), print(player(),format('r There was no initial point for '+player())); set_start(end_pos) @@ -47,42 +49,43 @@ _calculate(start_pos, end_pos)->( ) ); -__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) ->( - pos = pos_offset(block,face);//for clicking against the wall. +__on_player_places_block(player, item_tuple, hand, block) ->( if(block=='brown_carpet' && system_info('world_carpet_rules'):'carpets'=='true', - if(global_position==null||player~'sneaking',//wont complain for first carpet - set_start(pos), - _calculate(null,pos) + effective_pos = pos(block)+[0.5, 0, 0.5]; + if(global_start==null||player~'sneaking',//wont complain for first carpet + set_start(effective_pos), + _calculate(null, effective_pos) ) ) ); calculate(end_pos)->( - start_pos = global_position; - [dx,dy,dz] = map(start_pos-end_pos,abs(_)); - - manhattan = _round(_manhattan([dx, dy, dz],[0,0,0]),100);//rounding to nearest 0.01 for precision, but not ridiculous decimal places - spherical = _round(_euclidean([dx, dy, dz],[0,0,0]),100); - cylindrical = _round(_euclidean([dx, 0, dz],[0,0,0]),100);//useful for chunk distances etc. + global_end = end_pos; + manhattan = _round(_manhattan(global_start, global_end),0.001);//rounding to nearest 0.01 for precision, but not ridiculous decimal places + spherical = _round(_euclidean(global_start, global_end), 0.001); + //useful for chunk distances etc. + cylindrical = _round(_euclidean(global_start, [global_end:0, global_start:1, global_end:2]), 0.001); + print(player(),format( 'w Distance between ', - 'c '+start_pos,'?/tp '+(str(start_pos)-','-'['-']'), 'w and ', - 'c '+end_pos,'?/tp '+(str(end_pos)-','-'['-']'), 'w :\n', + 'c '+str('[%.1f, %.1f, %.1f]', global_start), __mktp(global_start), + 'w and ', + 'c '+str('[%.1f, %.1f, %.1f]', global_end), __mktp(global_end), 'w :\n', 'w - Spherical: ', 'wb '+spherical+'\n', 'w - Cylindrical: ', 'wb '+cylindrical+'\n', 'w - Manhattan: ', 'wb '+manhattan )); - global_end_position = end_pos; - schedule(0,'_draw_line'); ); _draw_line()->( if(global_show_line,//It will always draw from the global positions, so it will turn on if there is a line - draw_shape('line',20,'from',global_position,'to',global_end_position, 'player',player(),'color',0x000000FF); - draw_shape('label',20,'pos',global_end_position,'text',_round(_euclidean(global_position,global_end_position),100),'color',0x000000FF); + if ( global_start && global_end, + draw_shape('line',20,'from',global_start,'to',global_end, 'player',player()); + draw_shape('label',20,'pos',global_end,'text',_round(_euclidean(global_start,global_end),0.001)); + ); schedule(20,'_draw_line') ) ); diff --git a/src/main/resources/assets/carpet/scripts/math.scl b/src/main/resources/assets/carpet/scripts/math.scl index d6e7c26b..4af9ae32 100644 --- a/src/main/resources/assets/carpet/scripts/math.scl +++ b/src/main/resources/assets/carpet/scripts/math.scl @@ -2,4 +2,4 @@ _euclidean_sq(vec1, vec2) -> reduce(vec1 - vec2, _a + _*_, 0); _euclidean(vec1, vec2) -> sqrt(reduce(vec1 - vec2, _a + _*_, 0)); _manhattan(vec1, vec2) -> reduce(vec1-vec2,_a+abs(_),0); _vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0)); -_round(num,precision) -> round(num*precision)/precision; +_round(num,precision) -> round(num/precision)*precision;