Exemple #1
0
static void update_status_text() {
  static char s_buff[32];
  snprintf(s_buff, sizeof(s_buff), "(%d,%d,%d) | %s | %s", 
    s_cursor.x, s_cursor.y, s_cursor.z, get_mode_string(), get_block_name()
  );
  text_layer_set_text(s_status_layer, s_buff);
}
int main(int argc, char** argv) {
  int32_t chunkx = 0, chunkz = 0;
  char* rfile = NULL;
  int arg, optindex;
  while ((arg = getopt_long(argc, argv, "hr:x:z:", g_LongOpts, &optindex)) != -1) {
    switch (arg) {
    case 'h':
      return usage(argv[0]);
    case 'r':
      rfile = optarg;
      break;
    case 'x':
      chunkx = atoi(optarg);
      break;
    case 'z':
      chunkz = atoi(optarg);
      break;
    }
  }
  if (!rfile)
    return usage(argv[0]);
  regionfile* region = open_regionfile(rfile);
  if (!region_contains_chunk(region, chunkx, chunkz)) {
    fprintf(stderr, "This region file doesn't contain chunk x:%d, z:%d\n", chunkx, chunkz);
    char buf[BUFSIZ];
    if (determine_region_file(buf, sizeof(buf), chunkx, chunkz) > 0)
      fprintf(stderr, "I suggest you look in \"%s\" instead.\n", buf);
    free_region(region);
    return 1;
  }
  fprintf(stderr, "Chunk %d, %d consists of %d internal sectors.\n", chunkx, chunkz, region_chunk_sector_count(region, chunkx, chunkz));
  chunk* c = get_chunk(region, chunkx, chunkz, 0);
  if (c) {
    uint64_t analyze[256][16];
    bzero(analyze, sizeof(analyze));
    uint8_t analyze_biomes[256];
    bzero(analyze_biomes, sizeof(analyze_biomes));
    uint8_t x, z, y;
    for (x = 0; x < 16; x++) {
      for (z = 0; z < 16; z++) {
        analyze_biomes[c->biomes[z][x]]++;
        for (y = 0; y < 255; y++)
          analyze[c->blocks[y][z][x]][c->data[y][z][x]]++;
      }
    }
    free_chunk(c);
    initblockdb();
    size_t i;
    for (i = 0; i < 256; i++) {
      size_t j;
      for (j = 0; j < 16; j++) {
        if (analyze[i][j] > 0)
          fprintf(stderr, "%s %lu\n", get_block_name(i, j), analyze[i][j]);
      }
    }
    initbiomedb();
    for (i = 0; i < 256; i++) {
      if (analyze_biomes[i] > 0)
        fprintf(stderr, "%s %hhu\n", get_biome_name(i), analyze_biomes[i]);
    }
  } else {
    fprintf(stderr, "%s\n", nbt_error_to_string(errno));
  }
  free_region(region);
  return 0;
};