From 96bce75db11c16c9b70c75808be01889c1f15a33 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 09:40:20 +0100 Subject: [PATCH 01/12] Update draw_beta.sc --- .../assets/carpet/scripts/draw_beta.sc | 170 ++++++++++++------ 1 file changed, 116 insertions(+), 54 deletions(-) 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 From 180b2285f9b0ba2bbc732da7aae9608f60fd87bb Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 09:44:43 +0100 Subject: [PATCH 02/12] moved drawing commands to separate library app now gotta import, and fix issues --- .../assets/carpet/scripts/draw_beta.sc | 132 ------------------ .../assets/carpet/scripts/shapes.scl | 132 ++++++++++++++++++ 2 files changed, 132 insertions(+), 132 deletions(-) create mode 100644 src/main/resources/assets/carpet/scripts/shapes.scl diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc index 954fed07..32da53c5 100644 --- a/src/main/resources/assets/carpet/scripts/draw_beta.sc +++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc @@ -66,36 +66,6 @@ affected(player) -> ( 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) - ) - ) - ) -); - //Drawing commands draw(what, args)->(//custom setter cos it's easier @@ -111,105 +81,3 @@ draw(what, args)->(//custom setter cos it's easier affected(player()); ); - -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( - 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 * ( 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 - ); - - if(global_debug, - print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) - ); - return(global_positions) -); - -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; - - for(range(height), - fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off - ); - - if(global_debug, - print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) - ); - return(global_positions) -); \ No newline at end of file diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl new file mode 100644 index 00000000..c33ea53e --- /dev/null +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -0,0 +1,132 @@ + +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( + 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 * ( 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 + ); + + if(global_debug, + print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) + ); + return(global_positions) +); + +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; + + for(range(height), + fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off + ); + + if(global_debug, + print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) + ); + return(global_positions) +); + +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) + ) + ) + ) +); From 8eba0b9b8afdab2eff485f5eacefe85ee9cf5b1f Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 09:46:28 +0100 Subject: [PATCH 03/12] removed debug and easter egg --- .../assets/carpet/scripts/draw_beta.sc | 6 ------ .../assets/carpet/scripts/shapes.scl | 20 ------------------- 2 files changed, 26 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc index 32da53c5..c29aa359 100644 --- a/src/main/resources/assets/carpet/scripts/draw_beta.sc +++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc @@ -18,10 +18,6 @@ __config() -> { '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'}, @@ -36,7 +32,6 @@ __config() -> { 'scope'->'global' }; -global_debug=false; //"Boilerplate" code @@ -64,7 +59,6 @@ affected(player) -> ( affected ); -length_sq(vec) -> reduce(vec, _a + _*_, 0); //Drawing commands diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl index c33ea53e..170f2e43 100644 --- a/src/main/resources/assets/carpet/scripts/shapes.scl +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -1,6 +1,5 @@ draw_sphere(args)->( - if(global_debug, start_time=unix_time()); [centre, radius, block, replacement, hollow] = args; @@ -21,14 +20,10 @@ draw_sphere(args)->( ) ); - 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; @@ -44,14 +39,10 @@ draw_diamond(args)->( ) ); - if(global_debug, - print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) - ); return(global_positions) ); draw_filled_diamond(args)->( - if(global_debug, start_time=unix_time()); [pos, radius, block, replacement] = args; @@ -59,14 +50,10 @@ draw_filled_diamond(args)->( 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; @@ -77,14 +64,10 @@ draw_pyramid(args)->( fill_flat(pos, _, r, is_square, orientation, block, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow),replacement)//Always close bottom off ); - if(global_debug, - print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) - ); return(global_positions) ); draw_prism(args)->( - if(global_debug, start_time=unix_time()); [pos, rad, height, orientation, block, fill_type, replacement, is_square]=args; @@ -95,9 +78,6 @@ draw_prism(args)->( fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off ); - if(global_debug, - print(player(),format('gi Time taken: '+(unix_time()-start_time)+'ms')) - ); return(global_positions) ); From ac031090ef04e3c7c85f21e3cced14a2938773c4 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 10:14:28 +0100 Subject: [PATCH 04/12] making the shapes in shapes.scl purely mathematical, no strings attached, only returning a set of the positions to iterate over. --- .../assets/carpet/scripts/draw_beta.sc | 68 ++++++---------- .../assets/carpet/scripts/shapes.scl | 81 +++++++++---------- 2 files changed, 63 insertions(+), 86 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc index c29aa359..53ce82d5 100644 --- a/src/main/resources/assets/carpet/scripts/draw_beta.sc +++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc @@ -1,23 +1,23 @@ -import('math','_euclidean_sq','_vec_length'); +import('shapes','draw_sphere', 'draw_diamond', 'draw_filled_diamond', 'draw_pyramid', 'draw_prism'); //importing all the shape funcs from the other app __config() -> { 'commands'->{ - '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]), + 'sphere
'->_(c,r,b)->draw('draw_sphere',[c,r, true],b,null), + 'sphere
replace '->_(c,r,b,rp)->draw('draw_sphere',[c,r,true],b,rp), + 'ball
'->_(c,r,b)->draw('draw_sphere',[c,r,false],b,null), + 'ball
replace '->_(c,r,b,rp)->draw('draw_sphere',[c,r,false],b,rp), + '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,ho, true],b,null), + 'pyramid
replace '->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,ho,true],b,rp), + 'cone
'->_(c,r,h,p,o,b,ho)->draw('draw_pyramid',[c,r,h,p,o,ho, false],b,null), + 'cone
replace '->_(c,r,h,p,o,b,ho,rp)->draw('draw_pyramid', [c,r,h,p,o,ho,false],b,rp), + 'cuboid
'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,ho, true],b,null), + 'cuboid
replace '->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,ho,true],b,rp), + 'cylinder
'->_(c,r,h,o,b,ho)->draw('draw_prism',[c,r,h,p,o,ho, false],b,null), + 'cylinder
replace '->_(c,r,h,o,b,ho,rp)->draw('draw_prism', [c,r,h,o,ho,false],b,rp), }, 'arguments'->{ 'center'->{'type'->'pos', 'loaded'->'true'}, @@ -32,10 +32,6 @@ __config() -> { 'scope'->'global' }; - -//"Boilerplate" code - - _block_matches(existing, block_predicate) -> ( [name, block_tag, properties, nbt] = block_predicate; @@ -46,32 +42,16 @@ _block_matches(existing, block_predicate) -> (!tag || tag_matches(block_data(existing), tag)) ); -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 +draw(what, args, block, replacement)->(//custom setter cos it's easier + positions = call(what,args); //returning blocks to be set + affected = 0 -global_positions = [{}, 0];//using a set so I dont waste compute on duplicate positions - -affected(player) -> ( - affected = global_positions; - print(player,format('gi Filled ' + affected:1 + ' blocks')); - global_positions = [{},0]; - affected -); - - -//Drawing commands - -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); + for(positions, + existing = block(_); if(block != existing && (!replacement || _block_matches(existing, replacement) ), - global_positions:1 += bool(set(existing,block)) + affected += bool(set(existing,block)) ) ); - - affected(player()); + print(player,format('gi Filled ' + affected + ' blocks')); ); diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl index 170f2e43..7659c9c6 100644 --- a/src/main/resources/assets/carpet/scripts/shapes.scl +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -1,8 +1,14 @@ +//a library app, mostly for the draw command, which allows to import these shape-drawing functions into your own app. +//Arguments for each are to be given as a singleton list, for ease of use. This is with the exception of fill_flat, with +//the assumption that it is unlikely to be used outside of internal calls, but it is still available to be called if necessary. +//Make sure you read the arguments and input them in the correct order, or it will mess up. +//these functions return a set of all the positions in the shape, given the parameters, without repeating a position. +//This way, you can efficiently iterate over the positions once having generated them. See draw_beta.sc for an example. + draw_sphere(args)->( - - [centre, radius, block, replacement, hollow] = args; - + [centre, radius, hollow] = args; + positions = {}; [cx,cy,cz]=centre; for(range(-90, 90, 45/radius), cpitch = cos(_); @@ -11,85 +17,75 @@ draw_sphere(args)->( 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), + positions += [cx+cyaw,cy+spitch*radius,cz+syaw]; + positions += [cx+cos(_+180)*cpitch*radius,cy+spitch*radius,cz+sin(_+180)*cpitch*radius], for(range(-syaw,syaw+1), - set_block(cx+cyaw*cpitch,cy+spitch*radius,cz+_,block,replacement) + positions += [cx+cyaw*cpitch,cy+spitch*radius,cz+_] ) ) ) ); - - return(global_positions) + return(positions) ); draw_diamond(args)->( - - [pos, radius, block, replacement] = args; - + [pos, radius] = args; + positions = {}; c_for(r=0, r( - - [pos, radius, block, replacement] = args; - + [pos, radius] = args; + positions = {}; for(diamond(pos,radius,radius), - set_block(_x,_y,_z,block,replacement) + positions += pos(_) ); - - return(global_positions) + return(positions) ); draw_pyramid(args)->( - - [pos, radius, height, pointing, orientation, block, fill_type, replacement, is_square] = args; - + [pos, radius, height, pointing, orientation, fill_type, is_square] = args;//todo change to hollow boolean arg + positions = {}; hollow = fill_type=='hollow'; pointup = pointing=='up'; for(range(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 + positions += fill_flat(pos, _, r, is_square, orientation, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow))//Always close bottom off ); - - return(global_positions) + return(positions) ); draw_prism(args)->( - - [pos, rad, height, orientation, block, fill_type, replacement, is_square]=args; - + [pos, rad, height, orientation, fill_type, is_square]=args;//todo change to hollow boolean arg + positions = {}; 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 + positions += fill_flat(pos, _, radius, is_square, orientation, if(_==0 || _==height-1,false,hollow))//Always close ends off ); - - return(global_positions) + return(positions) ); -fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->( +fill_flat(pos, offset, dr, rectangle, orientation, hollow)->( r = floor(dr); drsq = dr^2; + positions = {}; 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) + positions += [_x+offset,_y,_z] ) ), orientation == 'y', @@ -97,7 +93,7 @@ fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)-> 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) + positions += [_x,_y+offset,_z] ) ), orientation == 'z', @@ -105,8 +101,9 @@ fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)-> 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) + positions += [_x,_y,_z+offset] ) ) - ) + ); + return(positions) ); From eafc618792d64e04d205aafa1fb9201754d89a77 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 10:14:57 +0100 Subject: [PATCH 05/12] oboi, remember that caching bs? I apparently forgot to remove this bit lol --- src/main/resources/assets/carpet/scripts/draw_beta.sc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc index 53ce82d5..d1c9992e 100644 --- a/src/main/resources/assets/carpet/scripts/draw_beta.sc +++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc @@ -27,7 +27,6 @@ __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' }; From fa75401278da6c4a7634e237c91bba8621f0ab22 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 10:17:06 +0100 Subject: [PATCH 06/12] minor editing tweaks --- src/main/resources/assets/carpet/scripts/draw_beta.sc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc index d1c9992e..0b8ba312 100644 --- a/src/main/resources/assets/carpet/scripts/draw_beta.sc +++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc @@ -28,7 +28,7 @@ __config() -> { 'pointing'->{'type'->'term','suggest'->['up','down']}, 'hollow'->{'type'->'term','suggest'->['hollow','solid']}, }, - 'scope'->'global' + 'scope'->'global'//todo decide whether it rly needs to be global or not... }; _block_matches(existing, block_predicate) -> @@ -48,7 +48,7 @@ draw(what, args, block, replacement)->(//custom setter cos it's easier for(positions, existing = block(_); - if(block != existing && (!replacement || _block_matches(existing, replacement) ), + if(block != existing && (!replacement || _block_matches(existing, replacement)), affected += bool(set(existing,block)) ) ); From 467767a8e7c52f3e17f97ecd381129936b534aea Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 12:06:17 +0100 Subject: [PATCH 07/12] using bresenham algorithm for circles to make it more efficient --- .../assets/carpet/scripts/shapes.scl | 151 +++++++++++++++--- 1 file changed, 127 insertions(+), 24 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl index 7659c9c6..b8b085c2 100644 --- a/src/main/resources/assets/carpet/scripts/shapes.scl +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -1,9 +1,9 @@ -//a library app, mostly for the draw command, which allows to import these shape-drawing functions into your own app. -//Arguments for each are to be given as a singleton list, for ease of use. This is with the exception of fill_flat, with -//the assumption that it is unlikely to be used outside of internal calls, but it is still available to be called if necessary. +//This is a library app, mostly for the draw command, which allows to import these shape-drawing functions into your own app. +//Arguments for each are to be given as a singleton list, for ease of use. This is with the exception of the fill_flat functions, with +//the assumption that they're unlikely to be used outside of internal calls, but it is still available to be called if necessary. //Make sure you read the arguments and input them in the correct order, or it will mess up. //these functions return a set of all the positions in the shape, given the parameters, without repeating a position. -//This way, you can efficiently iterate over the positions once having generated them. See draw_beta.sc for an example. +//This way, you can efficiently iterate over the positions once having generated them. See draw_beta.sc for an example. todo change to draw once renamed draw_sphere(args)->( @@ -76,34 +76,137 @@ draw_prism(args)->( return(positions) ); -fill_flat(pos, offset, dr, rectangle, orientation, hollow)->( +fill_flat(pos, offset, dr, rectangle, orientation, hollow)-> + if(rectangle, + fill_flat_rectangle(pos, offset, dr, orientation, hollow), + fill_flat_circle(pos, offset, dr, orientation, hollow) + ); + +fill_flat_circle(pos, offset, dr, orientation, hollow) ->( //Bresenham circle algorithm to be super efficient r = floor(dr); - drsq = dr^2; + a=0; + b=r; + d=3-(2*r); + positions = {}; - 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 - positions += [_x+offset,_y,_z] + + positions += fill_flat_circle_points(pos, orientation, offset, hollow, a, b); + + while(a<=b, 10^10, + if(d<=0, + d += (4*a)+6, + d += (4*a)-(4*b)+10; + b=b-1 + ); + a+=1; + positions += fill_flat_circle_points(pos, orientation, offset, hollow, a, b) + ); + return(positions) +); + +fill_flat_circle_points(pos, orientation, offset, hollow, a, b) ->( + [x, y, z] = pos; + positions = {}; + if(orientation == 'x', + if(hollow, + positions += [x + offset, a+y, b+z]; + positions += [x + offset, a+y,-b+z]; + positions += [x + offset,-a+y,-b+z]; + positions += [x + offset,-a+y, b+z]; + positions += [x + offset, b+y, a+z]; + positions += [x + offset, b+y,-a+z]; + positions += [x + offset,-b+y,-a+z]; + positions += [x + offset,-b+y, a+z], + c_for(c = -a, c<=a, c+=1, + positions += [x + offset,c+y, b + z]; + positions += [x + offset,c+y,-b + z] + ); + c_for(c = -b, c<=b, c+=1, + positions += [x + offset, a+y,c + z]; + positions += [x + offset,-a+y,c + z] ) ), - 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 - positions += [_x,_y+offset,_z] + orientation=='y', + if(hollow, + positions += [ a+x, y + offset, b+z]; + positions += [ a+x, y + offset,-b+z]; + positions += [-a+x, y + offset,-b+z]; + positions += [-a+x, y + offset, b+z]; + positions += [ b+x, y + offset, a+z]; + positions += [ b+x, y + offset,-a+z]; + positions += [-b+x, y + offset,-a+z]; + positions += [-b+x, y + offset, a+z], + c_for(c = -a, c<=a, c+=1, + positions += [c+x,y + offset, b + z]; + positions += [c+x,y + offset,-b + z] + ); + c_for(c = -b, c<=b, c+=1, + positions += [ a+x,y + offset,c + z]; + positions += [-a+x,y + offset,c + z] ) ), - 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 - positions += [_x,_y,_z+offset] + orientation=='z', + if(hollow, + positions += [ a+x, b+y, z + offset]; + positions += [ a+x,-b+y, z + offset]; + positions += [-a+x,-b+y, z + offset]; + positions += [-a+x, b+y, z + offset]; + positions += [ b+x, a+y, z + offset]; + positions += [ b+x,-a+y, z + offset]; + positions += [-b+x,-a+y, z + offset]; + positions += [-b+x, a+y, z + offset], + c_for(c = -a, c<=a, c+=1, + positions += [c+x, b + y,z + offset]; + positions += [c+x,-b + y,z + offset] + ); + c_for(c = -b, c<=b, c+=1, + positions += [ a+x,c + y,z + offset]; + positions += [-a+x,c + y,z + offset] ) ) + ) +); + +fill_flat_rectangle(pos, offset, dr, orientation, hollow) -> ( + r = floor(dr); + drsq = dr^2; + positions = {}; + if(orientation == 'x', + c_for(a = -r, a <=r, a +=1, + if(hollow, + positions += [r + offset, a, r]; + positions += [r + offset, a,-r]; + positions += [r + offset, r, a]; + positions += [r + offset,-r, a], + c_for(b = -r, b <=r, b +=1, + positions += [r + offset, a, b] + ) + ) + ), + orientation == 'y', + c_for(a = -r, a <=r, a +=1, + if(hollow, + positions += [ r, r + offset,a]; + positions += [-r, r + offset,a]; + positions += [a, r + offset, r]; + positions += [a, r + offset,-r], + c_for(b = -r, b <=r, b +=1, + positions += [a, r + offset, b] + ) + ) + ), + orientation == 'z', + c_for(a = -r, a <=r, a +=1, + if(hollow, + positions += [ r, a,r + offset]; + positions += [-r, a,r + offset]; + positions += [a, r, r + offset]; + positions += [a,-r, r + offset], + c_for(b = -r, b <=r, b +=1, + positions += [b, a, r + offset] + ) + ) + ), ); return(positions) ); From facac439cfe5d24f57d4a0a36ace90fdcaabd802 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Wed, 24 Feb 2021 12:11:51 +0100 Subject: [PATCH 08/12] compacting hollow code --- src/main/resources/assets/carpet/scripts/shapes.scl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl index b8b085c2..440b0425 100644 --- a/src/main/resources/assets/carpet/scripts/shapes.scl +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -60,7 +60,7 @@ draw_pyramid(args)->( pointup = pointing=='up'; for(range(height), r = if(pointup, radius * ( 1- _ / height) -1, radius * _ / height); - positions += fill_flat(pos, _, r, is_square, orientation, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow))//Always close bottom off + positions += fill_flat(pos, _, r, is_square, orientation, !((pointup&&_==0)||(!pointup && _==height-1)) && hollow)//Always close bottom off ); return(positions) ); @@ -71,7 +71,7 @@ draw_prism(args)->( hollow = fill_type =='hollow'; radius = rad+0.5; for(range(height), - positions += fill_flat(pos, _, radius, is_square, orientation, if(_==0 || _==height-1,false,hollow))//Always close ends off + positions += fill_flat(pos, _, radius, is_square, orientation, !(_==0 || _==height-1) && hollow)//Always close ends off ); return(positions) ); From ae63c7be1d806e559fa9fadbde759ebd92559db3 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Thu, 25 Feb 2021 09:32:00 +0100 Subject: [PATCH 09/12] registering as built-in library (thx @altrisi) --- src/main/java/carpet/script/CarpetScriptServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java index 8634ca00..e86eb4c9 100644 --- a/src/main/java/carpet/script/CarpetScriptServer.java +++ b/src/main/java/carpet/script/CarpetScriptServer.java @@ -93,6 +93,7 @@ public class CarpetScriptServer registerBuiltInScript(BundledModule.carpetNative("chunk_display", false)); registerBuiltInScript(BundledModule.carpetNative("ai_tracker", false)); registerBuiltInScript(BundledModule.carpetNative("draw_beta", false)); + registerBuiltInScript(BundledModule.carpetNative("shapes", true)); registerBuiltInScript(BundledModule.carpetNative("distance_beta", false)); } From 6d7f7a7bdc16dea3026c87d7e3bf31bf6ad4a257 Mon Sep 17 00:00:00 2001 From: Ghoulboy78 Date: Fri, 5 Mar 2021 22:24:42 +0100 Subject: [PATCH 10/12] improving prims not to calculate blocks unnecessarily (thx @Firigion) --- .../assets/carpet/scripts/shapes.scl | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl index 440b0425..6da87888 100644 --- a/src/main/resources/assets/carpet/scripts/shapes.scl +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -70,9 +70,30 @@ draw_prism(args)->( positions = {}; hollow = fill_type =='hollow'; radius = rad+0.5; - for(range(height), - positions += fill_flat(pos, _, radius, is_square, orientation, !(_==0 || _==height-1) && hollow)//Always close ends off - ); + filled_circle_points = fill_flat(pos, 0, radius, is_square, orientation, false); //I dont actually need to generate all the points lol + offset_vector = if(orientation=='x', [1,0,0], orientation=='y', [0,1,0],[0,0,1]); + if(hollow, + hollow_circle_points = fill_flat(pos, 0, radius, is_square, orientation, true); + + for(filled_circle_points,//Always close ends off + positions+=_; + positions+=_+offset_vector*(height-1) + ); + + for(range(1, height-1),//cos Im adding ends as filled anyways + offset=_; + for(hollow_circle_points, + positions+= _ + offset_vector * offset + ) + ), + + for(range(height), + offset = _; + for(filled_circle_points, + positions += _ + offset_vector * offset + ) + ); + ) return(positions) ); From 36f766ae752d50bd7f5727c421f316ba401d4de3 Mon Sep 17 00:00:00 2001 From: Ghoulboy Date: Fri, 12 Mar 2021 22:36:25 +0100 Subject: [PATCH 11/12] Removing return statements to improve performance by a few microprocessor ticks to satisfy @altrisi --- .../resources/assets/carpet/scripts/shapes.scl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/shapes.scl b/src/main/resources/assets/carpet/scripts/shapes.scl index 6da87888..adad5bcb 100644 --- a/src/main/resources/assets/carpet/scripts/shapes.scl +++ b/src/main/resources/assets/carpet/scripts/shapes.scl @@ -25,7 +25,7 @@ draw_sphere(args)->( ) ) ); - return(positions) + positions ); draw_diamond(args)->( @@ -41,7 +41,7 @@ draw_diamond(args)->( positions += [pos:0+x, pos:1 -y, pos:2-z]; ) ); - return(positions) + positions ); draw_filled_diamond(args)->( @@ -50,7 +50,7 @@ draw_filled_diamond(args)->( for(diamond(pos,radius,radius), positions += pos(_) ); - return(positions) + positions ); draw_pyramid(args)->( @@ -62,7 +62,7 @@ draw_pyramid(args)->( r = if(pointup, radius * ( 1- _ / height) -1, radius * _ / height); positions += fill_flat(pos, _, r, is_square, orientation, !((pointup&&_==0)||(!pointup && _==height-1)) && hollow)//Always close bottom off ); - return(positions) + positions ); draw_prism(args)->( @@ -94,7 +94,7 @@ draw_prism(args)->( ) ); ) - return(positions) + positions ); fill_flat(pos, offset, dr, rectangle, orientation, hollow)-> @@ -122,7 +122,7 @@ fill_flat_circle(pos, offset, dr, orientation, hollow) ->( //Bresenham circle al a+=1; positions += fill_flat_circle_points(pos, orientation, offset, hollow, a, b) ); - return(positions) + positions ); fill_flat_circle_points(pos, orientation, offset, hollow, a, b) ->( @@ -229,5 +229,5 @@ fill_flat_rectangle(pos, offset, dr, orientation, hollow) -> ( ) ), ); - return(positions) + positions ); From 02e097dc4fd9f0b2ca51e9c74fef8aa4ec9c0fb6 Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 23 Mar 2021 04:15:51 -0300 Subject: [PATCH 12/12] fix --- src/main/java/carpet/script/value/EntityValue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 5172c4d9..3b90cdeb 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -1307,7 +1307,7 @@ public class EntityValue extends Value else if (v instanceof ListValue) { List lv = ((ListValue) v).getItems(); - if (lv.size() >= 1 && lv.size() <= 5) + if (lv.size() >= 1 && lv.size() <= 6) { String effectName = lv.get(0).getString(); StatusEffect effect = Registry.STATUS_EFFECT.get(new Identifier(effectName));