Update draw_beta.sc
This commit is contained in:
1 parent
14018c8e1b
commit
96bce75db1
1 file changed
+116
-54
@@ -2,20 +2,26 @@ import('math','_euclidean_sq','_vec_length');
|
|||||||
|
|
||||||
__config() -> {
|
__config() -> {
|
||||||
'commands'->{
|
'commands'->{
|
||||||
'sphere <center> <radius> <block>'->['draw_sphere',null,true],
|
'sphere <center> <radius> <block>'->_(c,r,b)->draw('draw_sphere',[c,r,b,null,true]),
|
||||||
'sphere <center> <radius> <block> replace <replacement>'->['draw_sphere',true],
|
'sphere <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_sphere',[c,r,b,rp,true]),
|
||||||
'ball <center> <radius> <block>'->['draw_sphere',null,false],
|
'ball <center> <radius> <block>'->_(c,r,b)->draw('draw_sphere',[c,r,b,null,false]),
|
||||||
'ball <center> <radius> <block> replace <replacement>'->['draw_sphere',false],
|
'ball <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_sphere',[c,r,b,rp,false]),
|
||||||
'diamond <center> <radius> <block>'->['draw_diamond',null],
|
'diamond <center> <radius> <block> hollow' -> _(c,r,b)->draw('draw_diamond',[c,r,b,null]),
|
||||||
'diamond <center> <radius> <block> replace <replacement>'->'draw_diamond',
|
'diamond <center> <radius> <block> hollow replace <replacement>'->_(c,r,b,rp)->draw('draw_diamond',[c, r, b, rp]),
|
||||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->['draw_pyramid',null, true],
|
'diamond <center> <radius> <block>' -> _(c,r,b)->draw('draw_filled_diamond',[c,r,b,null]),
|
||||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->['draw_pyramid', true],
|
'diamond <center> <radius> <block> replace <replacement>'->_(c,r,b,rp)->draw('draw_filled_diamond',[c, r, b, rp]),
|
||||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->['draw_pyramid',null, false],
|
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,b,ho,null, true]),
|
||||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->['draw_pyramid', false],
|
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,b,ho,rp,true]),
|
||||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow>'->['draw_prism', null, true],
|
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,b,ho,null, false]),
|
||||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->['draw_prism', true],
|
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,b,ho,rp,false]),
|
||||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow>'->['draw_prism', null, false],
|
'cuboid <center> <radius> <height> <orientation> <block> <hollow>'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,b,ho,null, true]),
|
||||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->['draw_prism', false]
|
'cuboid <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,b,ho,rp,true]),
|
||||||
|
'cylinder <center> <radius> <height> <orientation> <block> <hollow>'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,b,ho,null, false]),
|
||||||
|
'cylinder <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,b,ho,rp,false]),
|
||||||
|
if(system_info('server_dev_environment')||system_info('world_carpet_rules'):'superSecretSetting',
|
||||||
|
'debug <bool>'->_(bool)->global_debug=bool,
|
||||||
|
''->_()->''
|
||||||
|
)
|
||||||
},
|
},
|
||||||
'arguments'->{
|
'arguments'->{
|
||||||
'center'->{'type'->'pos', 'loaded'->'true'},
|
'center'->{'type'->'pos', 'loaded'->'true'},
|
||||||
@@ -25,13 +31,16 @@ __config() -> {
|
|||||||
'orientation'->{'type'->'term', 'suggest'->['x','y','z']},
|
'orientation'->{'type'->'term', 'suggest'->['x','y','z']},
|
||||||
'pointing'->{'type'->'term','suggest'->['up','down']},
|
'pointing'->{'type'->'term','suggest'->['up','down']},
|
||||||
'hollow'->{'type'->'term','suggest'->['hollow','solid']},
|
'hollow'->{'type'->'term','suggest'->['hollow','solid']},
|
||||||
|
'mode'->{'type'->'term','options'->['never', 'ingame', 'always']}
|
||||||
},
|
},
|
||||||
'scope'->'global'
|
'scope'->'global'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
global_debug=false;
|
||||||
|
|
||||||
//"Boilerplate" code
|
//"Boilerplate" code
|
||||||
|
|
||||||
|
|
||||||
_block_matches(existing, block_predicate) ->
|
_block_matches(existing, block_predicate) ->
|
||||||
(
|
(
|
||||||
[name, block_tag, properties, nbt] = block_predicate;
|
[name, block_tag, properties, nbt] = block_predicate;
|
||||||
@@ -42,26 +51,16 @@ _block_matches(existing, block_predicate) ->
|
|||||||
(!tag || tag_matches(block_data(existing), tag))
|
(!tag || tag_matches(block_data(existing), tag))
|
||||||
);
|
);
|
||||||
|
|
||||||
set_block(x, y, z, block, replacement)-> (
|
set_block(x, y, z, block, replacement)->//doing it like this so I can get list of blocks to place from functions
|
||||||
existing = block(x, y, z);
|
global_positions:0+=[[x, y, z], block, replacement];//Cos optional args return list always
|
||||||
if(block != existing && (replacement && _block_matches(existing, replacement) ),
|
|
||||||
without_updates( if (set(existing,block),
|
|
||||||
global_affected += [x, y, z];
|
|
||||||
));
|
|
||||||
);
|
|
||||||
);
|
|
||||||
|
|
||||||
global_affected = [];
|
|
||||||
|
global_positions = [{}, 0];//using a set so I dont waste compute on duplicate positions
|
||||||
|
|
||||||
affected(player) -> (
|
affected(player) -> (
|
||||||
affected = length(global_affected);
|
affected = global_positions;
|
||||||
print(player,format('gi Filled ' + affected + ' blocks'));
|
print(player,format('gi Filled ' + affected:1 + ' blocks'));
|
||||||
|
global_positions = [{},0];
|
||||||
if(system_info('world_carpet_rules'):'fillUpdates',
|
|
||||||
for(global_affected,update(_));//updating if fillUpdates is true
|
|
||||||
);
|
|
||||||
|
|
||||||
global_affected = [];
|
|
||||||
affected
|
affected
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -93,55 +92,114 @@ fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->
|
|||||||
(!rectangle && (_y^2 + _x^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_x)+1)^2 >= drsq)))),//If hollow and not 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)
|
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
|
//Drawing commands
|
||||||
|
|
||||||
draw_sphere(centre, radius, block, replacement, hollow)->(
|
draw(what, args)->(//custom setter cos it's easier
|
||||||
scan(centre,[radius,radius,radius],
|
call(what,args);//putting blocks to be set into the first element of global_positions
|
||||||
l = length_sq([_x,_y,_z]-centre);
|
|
||||||
if((l<=radius^2+radius) && (!hollow || l>=radius^2-radius),
|
for(global_positions:0,
|
||||||
set_block(_x, _y, _z, block, replacement)
|
[pos, block, replacement]=_;
|
||||||
|
existing = block(pos);
|
||||||
|
if(block != existing && (!replacement || _block_matches(existing, replacement) ),
|
||||||
|
global_positions:1 += bool(set(existing,block))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
affected(player());
|
affected(player());
|
||||||
);
|
);
|
||||||
|
|
||||||
draw_diamond(pos, radius, block, replacement)->(
|
draw_sphere(args)->(
|
||||||
|
if(global_debug, start_time=unix_time());
|
||||||
|
|
||||||
|
[centre, radius, block, replacement, hollow] = args;
|
||||||
|
|
||||||
|
[cx,cy,cz]=centre;
|
||||||
|
for(range(-90, 90, 45/radius),
|
||||||
|
cpitch = cos(_);
|
||||||
|
spitch = sin(_);
|
||||||
|
for(range(0, 180, 45/radius),
|
||||||
|
cyaw = cos(_)*cpitch*radius;
|
||||||
|
syaw = sin(_)*cpitch*radius;
|
||||||
|
if(hollow,
|
||||||
|
set_block(cx+cyaw,cy+spitch*radius,cz+syaw,block,replacement);
|
||||||
|
set_block(cx+cos(_+180)*cpitch*radius,cy+spitch*radius,cz+sin(_+180)*cpitch*radius,block,replacement),
|
||||||
|
for(range(-syaw,syaw+1),
|
||||||
|
set_block(cx+cyaw*cpitch,cy+spitch*radius,cz+_,block,replacement)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(global_debug,
|
||||||
|
print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms'))
|
||||||
|
);
|
||||||
|
return(global_positions)
|
||||||
|
);
|
||||||
|
|
||||||
|
draw_diamond(args)->(
|
||||||
|
if(global_debug, start_time=unix_time());
|
||||||
|
|
||||||
|
[pos, radius, block, replacement] = args;
|
||||||
|
|
||||||
c_for(r=0, r<radius, r+=1,
|
c_for(r=0, r<radius, r+=1,
|
||||||
y = r-radius+1;
|
y = r-radius+1;
|
||||||
c_for(x=-r,x<=r,x+=1,
|
c_for(x=-r,x<=r,x+=1,
|
||||||
z=r-abs(x);
|
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);
|
||||||
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())
|
if(global_debug,
|
||||||
|
print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms'))
|
||||||
|
);
|
||||||
|
return(global_positions)
|
||||||
);
|
);
|
||||||
|
|
||||||
draw_pyramid(pos, radius, height, pointing, orientation, block, fill_type, replacement, is_square)->(
|
draw_filled_diamond(args)->(
|
||||||
|
if(global_debug, start_time=unix_time());
|
||||||
|
|
||||||
|
[pos, radius, block, replacement] = args;
|
||||||
|
|
||||||
|
for(diamond(pos,radius,radius),
|
||||||
|
set_block(_x,_y,_z,block,replacement)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(global_debug,
|
||||||
|
print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms'))
|
||||||
|
);
|
||||||
|
return(global_positions)
|
||||||
|
);
|
||||||
|
|
||||||
|
draw_pyramid(args)->(
|
||||||
|
if(global_debug, start_time=unix_time());
|
||||||
|
|
||||||
|
[pos, radius, height, pointing, orientation, block, fill_type, replacement, is_square] = args;
|
||||||
|
|
||||||
hollow = fill_type=='hollow';
|
hollow = fill_type=='hollow';
|
||||||
pointup = pointing=='up';
|
pointup = pointing=='up';
|
||||||
|
|
||||||
for(range(height),
|
for(range(height),
|
||||||
r = if(pointup, radius - radius * _ / height -1, radius * _ / height);
|
r = if(pointup, radius * ( 1- _ / 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
|
fill_flat(pos, _, r, is_square, orientation, block, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow),replacement)//Always close bottom off
|
||||||
);
|
);
|
||||||
affected(player())
|
|
||||||
|
if(global_debug,
|
||||||
|
print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms'))
|
||||||
|
);
|
||||||
|
return(global_positions)
|
||||||
);
|
);
|
||||||
|
|
||||||
draw_prism(pos, rad, height, orientation, block, fill_type, replacement, is_square)->(
|
draw_prism(args)->(
|
||||||
|
if(global_debug, start_time=unix_time());
|
||||||
|
|
||||||
|
[pos, rad, height, orientation, block, fill_type, replacement, is_square]=args;
|
||||||
|
|
||||||
hollow = fill_type =='hollow';
|
hollow = fill_type =='hollow';
|
||||||
radius = rad+0.5;
|
radius = rad+0.5;
|
||||||
@@ -149,5 +207,9 @@ draw_prism(pos, rad, height, orientation, block, fill_type, replacement, is_squa
|
|||||||
for(range(height),
|
for(range(height),
|
||||||
fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off
|
fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off
|
||||||
);
|
);
|
||||||
affected(player())
|
|
||||||
);
|
if(global_debug,
|
||||||
|
print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms'))
|
||||||
|
);
|
||||||
|
return(global_positions)
|
||||||
|
);
|
||||||
Reference in new issue
Block a user