3 #include "server/schematic.h"
6 void schematic_load(List *schematic, const char *path, SchematicMapping *mappings, size_t num_mappings)
10 FILE *file = fopen(path, "r");
12 fprintf(stderr, "[warning] failed to open schematic %s\n", path);
21 // getline is POSIX 2008, so we can use it
22 while ((length = getline(&line, &siz, file)) > 0) {
28 SchematicNode *node = malloc(sizeof *node);
29 node->data = (Blob) {0, NULL};
32 if (sscanf(line, "%d %d %d %2x%2x%2x",
33 &node->pos.x, &node->pos.z, &node->pos.y,
34 &color.x, &color.y, &color.z) != 6) {
35 fprintf(stderr, "[warning] syntax error in schematic %s in line %d: %s\n",
41 SchematicMapping *mapping = NULL;
42 for (size_t i = 0; i < num_mappings; i++)
43 if (v3s32_equals(color, mappings[i].color)) {
44 mapping = &mappings[i];
49 fprintf(stderr, "[warning] color not mapped to node in schematic %s in line %d: %02x%02x%02x\n",
50 path, count, color.x, color.y, color.z);
55 node->type = mapping->type;
57 if (mapping->use_color)
58 ColorData_write(&node->data, &(ColorData) {{
64 list_apd(schematic, node);
73 void schematic_place(List *schematic, v3s32 pos, TerrainGenStage tgs, List *changed_chunks)
75 LIST_ITERATE(schematic, list_node) {
76 SchematicNode *node = list_node->dat;
78 server_terrain_gen_node(
79 v3s32_add(pos, node->pos),
80 terrain_node_create(node->type, node->data),
85 static void delete_schematic_node(SchematicNode *node)
87 Blob_free(&node->data);
91 void schematic_delete(List *schematic)
93 list_clr(schematic, (void *) &delete_schematic_node, NULL, NULL);