diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc
index c88739d1..954fed07 100644
--- a/src/main/resources/assets/carpet/scripts/draw_beta.sc
+++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc
@@ -2,20 +2,26 @@ import('math','_euclidean_sq','_vec_length');
__config() -> {
'commands'->{
- 'sphere
'->['draw_sphere',null,true],
- 'sphere replace '->['draw_sphere',true],
- 'ball '->['draw_sphere',null,false],
- 'ball replace '->['draw_sphere',false],
- 'diamond '->['draw_diamond',null],
- 'diamond replace '->'draw_diamond',
- 'pyramid '->['draw_pyramid',null, true],
- 'pyramid replace '->['draw_pyramid', true],
- 'cone '->['draw_pyramid',null, false],
- 'cone replace '->['draw_pyramid', false],
- 'cuboid '->['draw_prism', null, true],
- 'cuboid replace '->['draw_prism', true],
- 'cylinder '->['draw_prism', null, false],
- 'cylinder replace '->['draw_prism', false]
+ 'sphere '->_(c,r,b)->draw('draw_sphere',[c,r,b,null,true]),
+ 'sphere replace '->_(c,r,b,rp)->draw('draw_sphere',[c,r,b,rp,true]),
+ 'ball '->_(c,r,b)->draw('draw_sphere',[c,r,b,null,false]),
+ 'ball replace '->_(c,r,b,rp)->draw('draw_sphere',[c,r,b,rp,false]),
+ 'diamond hollow' -> _(c,r,b)->draw('draw_diamond',[c,r,b,null]),
+ 'diamond hollow replace '->_(c,r,b,rp)->draw('draw_diamond',[c, r, b, rp]),
+ 'diamond ' -> _(c,r,b)->draw('draw_filled_diamond',[c,r,b,null]),
+ 'diamond replace '->_(c,r,b,rp)->draw('draw_filled_diamond',[c, r, b, rp]),
+ 'pyramid '->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,b,ho,null, true]),
+ 'pyramid replace '->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,b,ho,rp,true]),
+ 'cone '->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,b,ho,null, false]),
+ 'cone replace '->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,b,ho,rp,false]),
+ 'cuboid '->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,b,ho,null, true]),
+ 'cuboid replace '->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,b,ho,rp,true]),
+ 'cylinder '->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,b,ho,null, false]),
+ 'cylinder replace '->_(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)->global_debug=bool,
+ ''->_()->''
+ )
},
'arguments'->{
'center'->{'type'->'pos', 'loaded'->'true'},
@@ -25,13 +31,16 @@ __config() -> {
'orientation'->{'type'->'term', 'suggest'->['x','y','z']},
'pointing'->{'type'->'term','suggest'->['up','down']},
'hollow'->{'type'->'term','suggest'->['hollow','solid']},
+ 'mode'->{'type'->'term','options'->['never', 'ingame', 'always']}
},
'scope'->'global'
};
+global_debug=false;
//"Boilerplate" code
+
_block_matches(existing, 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))
);
-set_block(x, y, z, block, replacement)-> (
- existing = block(x, y, z);
- if(block != existing && (replacement && _block_matches(existing, replacement) ),
- without_updates( if (set(existing,block),
- global_affected += [x, y, z];
- ));
- );
-);
+set_block(x, y, z, block, replacement)->//doing it like this so I can get list of blocks to place from functions
+ global_positions:0+=[[x, y, z], block, replacement];//Cos optional args return list always
-global_affected = [];
+
+global_positions = [{}, 0];//using a set so I dont waste compute on duplicate positions
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 = global_positions;
+ print(player,format('gi Filled ' + affected:1 + ' blocks'));
+ global_positions = [{},0];
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
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)->(
- 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)
+draw(what, args)->(//custom setter cos it's easier
+ call(what,args);//putting blocks to be set into the first element of global_positions
+
+ for(global_positions:0,
+ [pos, block, replacement]=_;
+ existing = block(pos);
+ if(block != existing && (!replacement || _block_matches(existing, replacement) ),
+ global_positions:1 += bool(set(existing,block))
)
);
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(
+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';
pointup = pointing=='up';
-
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
);
- 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';
radius = rad+0.5;
@@ -149,5 +207,9 @@ draw_prism(pos, rad, height, orientation, block, fill_type, replacement, is_squa
for(range(height),
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)
+);
\ No newline at end of file