Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2020-11-25 02:12:41 -04:00
commit 253604b34a
18 files changed
+381 -32

No files matched your search

@@ -638,14 +638,14 @@ save_as(file) ->
//otherwise mojang will interpret 0.0d as 0i and fail to insert
put(path_nbt:'points', point_nbt, _i);
);
store_app_data(path_nbt, file);
write_file(file, 'nbt', path_nbt);
'stored path as '+file;
);
// loads path under the local file that
load(file) ->
(
path_nbt = load_app_data(file);
path_nbt = read_file(file, 'nbt');
if (!path_nbt, exit('No path to load: '+file));
new_points = map(get(path_nbt, 'points[]'), l(_:'pos[]', _:'duration', _:'type'));
if (!new_points || first(new_points, length(_:0) != 5),
@@ -0,0 +1,91 @@
import('math','_euclidean','_manhattan','_round');
__config()->{
'commands'->{
'from <start>'->'set_start',
'from <start> to <end>'->'_calculate',
'to <end>'->_(end_pos)->(_calculate(null,end_pos)),
'toggle_line'->'_toggle_line'
},
'arguments' -> {
'start' -> {'type' -> 'location'},
'end' -> {'type' -> 'location'}
}
};
global_start=null;
global_end=null;
global_show_line=false;
__mktp(pos) -> str('!/tp %.6f %.6f %.6f', pos);
set_start(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');
_draw_line()
, // else
print('Toggled lines off')
);
);
_calculate(start_pos, end_pos)->(
if(start_pos!=null,
set_start(start_pos);
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)
)
)
);
__on_player_places_block(player, item_tuple, hand, block) ->(
if(block=='brown_carpet' && system_info('world_carpet_rules'):'carpets'=='true',
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)->(
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 '+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
));
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
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')
)
);
@@ -0,0 +1,142 @@
import('math','_euclidean_sq','_vec_length');
__config() -> {
'commands'->{
'sphere <center> <radius> <block>'->['draw_sphere',null,true],
'sphere <center> <radius> <block> replace <replacement>'->['draw_sphere',true],
'ball <center> <radius> <block>'->['draw_sphere',null,false],
'ball <center> <radius> <block> replace <replacement>'->['draw_sphere',false],
'diamond <center> <radius> <block>'->['draw_diamond',null],
'diamond <center> <radius> <block> replace <replacement>'->'draw_diamond',
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->['draw_pyramid',null, true],
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->['draw_pyramid', true],
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->['draw_pyramid',null, false],
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->['draw_pyramid', false],
'cuboid <center> <radius> <height> <orientation> <block> <hollow>'->['draw_prism', null, true],
'cuboid <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->['draw_prism', true],
'cylinder <center> <radius> <height> <orientation> <block> <hollow>'->['draw_prism', null, false],
'cylinder <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->['draw_prism', false]
},
'arguments'->{
'center'->{'type'->'pos', 'loaded'->'true'},
'radius'->{'type'->'int', 'suggest'->[], 'min'->0},//to avoid default suggestions
'replacement'->{'type'->'block'},
'height'->{'type'->'int', 'suggest'->[],'min'->0},
'orientation'->{'type'->'term', 'suggest'->['x','y','z']},
'pointing'->{'type'->'term','suggest'->['up','down']},
'hollow'->{'type'->'term','suggest'->['hollow','solid']},
},
'scope'->'global'
};
//"Boilerplate" code
set_block(x, y, z, block, replacement)-> (
if(block != block(x, y, z),
without_updates( if (set([x, y, z],block),
global_affected += [x, y, z];
));
);
);
global_affected = [];
affected(player) -> (
affected = length(global_affected);
print(player,format('gi Filled ' + affected + ' blocks'));
if(system_info('world_carpet_rules'):'fillUpdates',
for(global_affected,update(_));//updating if fillUpdates is true
);
global_affected = [];
affected
);
length_sq(vec) -> reduce(vec, _a + _*_, 0);
fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->(
r = floor(dr);
drsq = dr^2;
if(orientation=='x',
scan(pos,0,-r,-r,
if((!hollow && (rectangle || _y^2 + _z^2 <= drsq))||//if not hollow, vry simple
(hollow && ((rectangle && (abs(_y) == r || abs(_z) ==r)) || //If hollow and it's a rectangle
(!rectangle && (_y^2 + _z^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_z)+1)^2 >= drsq)))),//If hollow and not rectangle
set_block(_x+offset,_y,_z,block, replacement)
)
),
orientation == 'y',
scan(pos,-r,0,-r,
if((!hollow && (rectangle || _x^2 + _z^2 <= drsq))||//if not hollow, vry simple
(hollow && ((rectangle && (abs(_x) == r || abs(_z) ==r)) || //If hollow and it's a rectangle
(!rectangle && (_x^2 + _z^2 <= drsq && (abs(_x)+1)^ 2 + (abs(_z)+1)^2 >= drsq)))),//If hollow and not rectangle
set_block(_x,_y+offset,_z,block, replacement)
)
),
orientation == 'z',
scan(pos,-r,-r,0,
if((!hollow && (rectangle || _y^2 + _x^2 <= drsq))||//if not hollow, vry simple
(hollow && ((rectangle && (abs(_y) == r || abs(_x) ==r)) || //If hollow and it's a rectangle
(!rectangle && (_y^2 + _x^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_x)+1)^2 >= drsq)))),//If hollow and not rectangle
set_block(_x,_y,_z+offset,block, replacement)
)
),
print(player(),format('r Error while running command: orientation can only be "x", "y" or "z", '+orientation+' is invalid.'));
global_affected = [];
);
);
//drawing commands
draw_sphere(centre, radius, block, replacement, hollow)->(
scan(centre,[radius,radius,radius],
l = length_sq([_x,_y,_z]-centre);
if((l<=radius^2+radius) && (!hollow || l>=radius^2-radius),
set_block(_x, _y, _z, block, replacement)
)
);
affected(player());
);
draw_diamond(pos, radius, block, replacement)->(
c_for(r=0, r<radius, r+=1,
y = r-radius+1;
c_for(x=-r,x<=r,x+=1,
z=r-abs(x);
set_block(pos:0+x,pos:1-y,pos:2+z, block, replacement);
set_block(pos:0+x,pos:1-y,pos:2-z, block, replacement);
set_block(pos:0+x,pos:1+y,pos:2+z, block, replacement);
set_block(pos:0+x,pos:1+y,pos:2-z, block, replacement);
)
);
affected(player())
);
draw_pyramid(pos, radius, height, pointing, orientation, block, fill_type, replacement, is_square)->(
hollow = fill_type=='hollow';
pointup = pointing=='up';
for(range(height),
r = if(pointup, radius - radius * _ / height -1, radius * _ / height);
fill_flat(pos, _, r, is_square, orientation, block, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow),replacement)//Always close bottom off
);
affected(player())
);
draw_prism(pos, rad, height, orientation, block, fill_type, replacement, is_square)->(
hollow = fill_type =='hollow';
radius = rad+0.5;
for(range(height),
fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off
);
affected(player())
);
@@ -1,3 +1,5 @@
_euclidean_sq(vec1, vec2) -> reduce(vec1 - vec2, _a + _*_, 0);
_euclidean(vec1, vec2) -> sqrt(reduce(vec1 - vec2, _a + _*_, 0));
_vec_length(vec) -> sqrt(reduce(vec, _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;