|
| 1 | +//Draw command in scarpet |
| 2 | +//By: Ghoulboy & gnembon |
| 3 | +//The reason I used c_for loops is cos I copied directly from java and am too lazy to replace it all myself. |
| 4 | +//Also may serve as an example to newcomers to how c_for loops work |
| 5 | + |
| 6 | +__command()->print('Draw command.'); |
| 7 | + |
| 8 | +//Command functions |
| 9 | + |
| 10 | +ball(radius, block)-> __drawSphere(radius,block,true); |
| 11 | + |
| 12 | +sphere(radius, block)-> __drawSphere(radius, block,false); |
| 13 | + |
| 14 | +cone(x, y, z, radius, height, pointup, orientation, block)->__drawPyramid(x, y, z, radius, height, pointup, orientation, block, false); |
| 15 | + |
| 16 | +pyramid(x, y, z, radius, height, pointup, orientation, block)->__drawPyramid(x, y, z, radius, height, pointup, orientation, block, true); |
| 17 | + |
| 18 | +diamond_shape(cx,cy,cz,radius,block)->(//If I do diamond, it conflicts with diamond iterator |
| 19 | + affected=0; |
| 20 | + for(range(radius), |
| 21 | + y=_-radius+1; |
| 22 | + r=_; |
| 23 | + for(range(-r,r+1), |
| 24 | + x=_; |
| 25 | + z=r-abs(x); |
| 26 | + affected+=__set_block(x+cx,cy+y,cz-z,block); |
| 27 | + affected+=__set_block(x+cx,y+cy,z+cz,block); |
| 28 | + affected+=__set_block(x+cx,cy-y,cz-z,block); |
| 29 | + affected+=__set_block(x+cx,cy-y,cz+z,block) |
| 30 | + ); |
| 31 | + ); |
| 32 | + print('Successfully filled '+affected+' blocks') |
| 33 | +); |
| 34 | + |
| 35 | +//Other functions |
| 36 | + |
| 37 | +__set_block(pos,block)->( |
| 38 | + if(block(pos)!=block, |
| 39 | + set(pos,block); |
| 40 | + return(1) |
| 41 | + ); |
| 42 | + return(0) |
| 43 | +); |
| 44 | + |
| 45 | +__lengthSq(x,y,z)->return((x * x) + (y * y) + (z * z)); |
| 46 | + |
| 47 | +__fillFlat(x,y,z, offset,radius,orientation,block,square)->( |
| 48 | + success=0; |
| 49 | + if(orientation=='x', |
| 50 | + scan(x + offset,y,z, 0, radius, radius, |
| 51 | + if((square||sqrt(__lengthSq(x + offset -_x,y -_y,z -_z))<1), |
| 52 | + success+=__set_block(pos(_),block) |
| 53 | + ) |
| 54 | + ) |
| 55 | + ); |
| 56 | + if(orientation=='y', |
| 57 | + scan(x,y+ offset,z, radius, 0, radius, |
| 58 | + if((square||sqrt(__lengthSq(x -_x,y + offset -_y,z -_z))<1), |
| 59 | + success+=__set_block(pos(_),block) |
| 60 | + ) |
| 61 | + ) |
| 62 | + ); |
| 63 | + if(orientation=='z', |
| 64 | + scan(x,y,z+ offset, radius, radius, 0, |
| 65 | + if((square||sqrt(__lengthSq(x -_x,y -_y,z + offset -_z))<1), |
| 66 | + success+=__set_block(pos(_),block) |
| 67 | + ) |
| 68 | + ) |
| 69 | + ); |
| 70 | + return(success) |
| 71 | +); |
| 72 | + |
| 73 | +__drawPyramid(x, y, z, radius, height, pointup, orientation, block, isSquare)->( |
| 74 | + affected=0; |
| 75 | + c_for(i =0, i<height, i+=1, |
| 76 | + r = if(pointup, radius - radius * i / height - 1 , radius * i / height); |
| 77 | + affected+=__fillFlat(x,y,z,i,r,orientation,block,isSquare); |
| 78 | + ); |
| 79 | + |
| 80 | + print('Successfully filled '+affected+' blocks'); |
| 81 | +); |
| 82 | + |
| 83 | +__drawSphere(radius,block,solid)->( |
| 84 | + |
| 85 | + pos=pos(player()); |
| 86 | + affected = 0; |
| 87 | + |
| 88 | + radiusX = radius+0.5; |
| 89 | + radiusY = radius+0.5; |
| 90 | + radiusZ = radius+0.5; |
| 91 | + |
| 92 | + invRadiusX = 1 / radiusX; |
| 93 | + invRadiusY = 1 / radiusY; |
| 94 | + invRadiusZ = 1 / radiusZ; |
| 95 | + |
| 96 | + ceilRadiusX = ceil(radiusX); |
| 97 | + ceilRadiusY = ceil(radiusY); |
| 98 | + ceilRadiusZ = ceil(radiusZ); |
| 99 | + |
| 100 | + |
| 101 | + nextXn = 0; |
| 102 | + |
| 103 | + c_for (x = 0, x <= ceilRadiusX, x+=1, |
| 104 | + xn = nextXn; |
| 105 | + nextXn = (x + 1) * invRadiusX; |
| 106 | + nextYn = 0; |
| 107 | + c_for (y = 0, y <= ceilRadiusY, y+=1, |
| 108 | + |
| 109 | + yn = nextYn; |
| 110 | + nextYn = (y + 1) * invRadiusY; |
| 111 | + nextZn = 0; |
| 112 | + c_for (z = 0, z <= ceilRadiusZ, z+=1, |
| 113 | + |
| 114 | + zn = nextZn; |
| 115 | + nextZn = (z + 1) * invRadiusZ; |
| 116 | + |
| 117 | + distanceSq = __lengthSq(xn, yn, zn); |
| 118 | + if (distanceSq > 1,break()); |
| 119 | + |
| 120 | + if (!solid && __lengthSq(nextXn, yn, zn) <= 1 && __lengthSq(xn, nextYn, zn) <= 1 && __lengthSq(xn, yn, nextZn) <= 1, |
| 121 | + continue(); |
| 122 | + ); |
| 123 | + |
| 124 | + c_for (xmod = -1, xmod < 2, xmod += 2, |
| 125 | + |
| 126 | + c_for (ymod = -1, ymod < 2, ymod += 2, |
| 127 | + |
| 128 | + c_for (zmod = -1, zmod < 2, zmod += 2, |
| 129 | + |
| 130 | + affected+=__set_block(pos+l(xmod * x,ymod * y,zmod * z),block); |
| 131 | + ) |
| 132 | + ) |
| 133 | + ) |
| 134 | + ) |
| 135 | + ) |
| 136 | + ); |
| 137 | + return('Successfully sent '+affected+' blocks') |
| 138 | +); |
| 139 | + |
0 commit comments