Skip to content

Commit fe3e7b3

Browse files
committed
added array builder command
1 parent 42e6dbc commit fe3e7b3

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/main.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,29 @@ void paste() {
18581858
}
18591859
}
18601860

1861+
void array(Block *b1, Block *b2, int xc, int yc, int zc) {
1862+
if (b1->w != b2->w) {
1863+
return;
1864+
}
1865+
int w = b1->w;
1866+
int dx = b2->x - b1->x;
1867+
int dy = b2->y - b1->y;
1868+
int dz = b2->z - b1->z;
1869+
xc = dx ? xc : 1;
1870+
yc = dy ? yc : 1;
1871+
zc = dz ? zc : 1;
1872+
for (int i = 0; i < xc; i++) {
1873+
int x = b1->x + dx * i;
1874+
for (int j = 0; j < yc; j++) {
1875+
int y = b1->y + dy * j;
1876+
for (int k = 0; k < zc; k++) {
1877+
int z = b1->z + dz * k;
1878+
builder_block(x, y, z, w);
1879+
}
1880+
}
1881+
}
1882+
}
1883+
18611884
void cube(Block *b1, Block *b2, int fill) {
18621885
if (b1->w != b2->w) {
18631886
return;
@@ -2001,7 +2024,7 @@ void parse_command(const char *buffer, int forward) {
20012024
char server_addr[MAX_ADDR_LENGTH];
20022025
int server_port = DEFAULT_PORT;
20032026
char filename[MAX_PATH_LENGTH];
2004-
int radius;
2027+
int radius, count, xc, yc, zc;
20052028
if (sscanf(buffer, "/identity %128s %128s", username, token) == 2) {
20062029
db_auth_set(username, token);
20072030
add_message("Successfully imported identity token!");
@@ -2058,6 +2081,12 @@ void parse_command(const char *buffer, int forward) {
20582081
else if (strcmp(buffer, "/tree") == 0) {
20592082
tree(&g->block0);
20602083
}
2084+
else if (sscanf(buffer, "/array %d %d %d", &xc, &yc, &zc) == 3) {
2085+
array(&g->block1, &g->block0, xc, yc, zc);
2086+
}
2087+
else if (sscanf(buffer, "/array %d", &count) == 1) {
2088+
array(&g->block1, &g->block0, count, count, count);
2089+
}
20612090
else if (strcmp(buffer, "/fcube") == 0) {
20622091
cube(&g->block0, &g->block1, 1);
20632092
}

0 commit comments

Comments
 (0)