mcchunktools
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
mcchunk.h
Go to the documentation of this file.
1 /* mcchunktools
2  * Copyright (C) 2013-2014 Toon Schoenmakers
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _MCCHUNK_H
19 #define _MCCHUNK_H
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #else
24 # if __STDC_VERSION__ < 199901L
25 # define restrict
26 # endif
27 #endif
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdint.h>
32 
33 #include "nbt.h"
34 
35 #define SECTOR_BYTES 4096
36 #define SECTOR_INTS 1024
37 
38 typedef struct {
39  uint32_t offsets[SECTOR_INTS];
40  uint32_t timestamps[SECTOR_INTS];
41  unsigned char* freeSectors; /* Dynamic array, 0x00 terminated. 1 is free sector, otherwise is used sector */
42  char* filename;
43  int32_t x, z;
44  FILE* file;
45  unsigned char keepopen : 1;
46 } regionfile;
47 
48 #define CHUNK_WIDTH 16
49 #define CHUNK_LENGTH 16
50 #define CHUNK_HEIGHT 256
51 
52 typedef struct {
53  int32_t x;
54  int32_t z;
57  int8_t biomes[CHUNK_LENGTH][CHUNK_WIDTH];
58  int64_t inhabitedTime;
61 } chunk;
62 
65  GET_ENTITIES = (1<<1)
66 };
67 
71 regionfile* open_regionfile(char* filename);
72 
75 void free_region(regionfile* region);
76 
80 size_t count_chunks(regionfile* region);
81 
82 typedef void (*raw_chunk_func)(nbt_node* node, void* context);
83 
87 void for_each_chunk_raw(regionfile* region, raw_chunk_func function, void* context);
88 
89 typedef void (*chunk_func)(chunk* c, void* context);
90 
97 void for_each_chunk(regionfile* region, chunk_func function, void* context);
98 
113 int region_contains_chunk(regionfile* region, int32_t cx, int32_t cz);
114 
118 uint8_t region_chunk_sector_count(regionfile* region, int32_t cx, int32_t cz);
119 
123 nbt_node* get_raw_chunk(regionfile* region, int32_t cx, int32_t cz);
124 
128 chunk* nbt_to_chunk(nbt_node* node, uint16_t flags);
129 
132 #define chunk_from_coord(i) (i/16)
133 
138 size_t determine_region_file(char* buf, size_t len, int32_t cx, int32_t cz);
139 
142 int write_chunk(regionfile* region, int32_t cx, int32_t cz, chunk* c);
143 
147 void initblockdb();
148 
153 char* get_block_name(uint8_t block_id, uint8_t data);
154 
158 void initbiomedb();
159 
164 char* get_biome_name(uint8_t biome_id);
165 
171 chunk* get_chunk(regionfile* region, int32_t cx, int32_t cz, uint16_t flags);
172 
175 void free_chunk(chunk* c);
176 
177 typedef struct {
178  char* filename;
179  char* levelname;
180  int64_t seed;
181  uint64_t last_played;
182  uint8_t allowCommands : 1;
183  uint8_t hardcore : 1;
184  uint64_t time;
185  uint64_t daytime;
186  union {
187  int32_t x;
188  int32_t y;
189  int32_t z;
190  } spawn;
191  uint8_t raining : 1;
192  uint8_t thundering : 1;
193  int32_t rainTime;
194  int32_t thunderTime;
195  union {
196  uint8_t commandBlockOutput : 1;
197  uint8_t doDaylightCycle : 1;
198  uint8_t doFireTick : 1;
199  uint8_t doMobLoot : 1;
200  uint8_t doMobSpawning : 1;
201  uint8_t doTileDrops : 1;
202  uint8_t keepInventory : 1;
203  uint8_t mobGriefing : 1;
204  uint8_t naturalRegeneration : 1;
205  } gamerules;
206 } level;
207 
210 level* open_level(char* filename);
211 
215 int write_level(level* lvl, char* into);
216 
219 void free_level(level* lvl);
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #endif //_MCCHUNK_H
void initbiomedb()
level * open_level(char *filename)
regionfile * open_regionfile(char *filename)
int32_t x
Definition: mcchunk.h:187
size_t determine_region_file(char *buf, size_t len, int32_t cx, int32_t cz)
char * filename
Definition: mcchunk.h:42
int64_t seed
Definition: mcchunk.h:180
int32_t z
Definition: mcchunk.h:189
Definition: mcchunk.h:177
#define SECTOR_INTS
Definition: mcchunk.h:36
chunk * get_chunk(regionfile *region, int32_t cx, int32_t cz, uint16_t flags)
char * levelname
Definition: mcchunk.h:179
char * get_biome_name(uint8_t biome_id)
void for_each_chunk_raw(regionfile *region, raw_chunk_func function, void *context)
Definition: mcchunk.h:52
uint64_t last_played
Definition: mcchunk.h:181
#define CHUNK_LENGTH
Definition: mcchunk.h:49
void for_each_chunk(regionfile *region, chunk_func function, void *context)
char * filename
Definition: mcchunk.h:178
int32_t thunderTime
Definition: mcchunk.h:194
char * get_block_name(uint8_t block_id, uint8_t data)
nbt_node * tile_entities
Definition: mcchunk.h:59
int32_t z
Definition: mcchunk.h:43
uint64_t time
Definition: mcchunk.h:184
int write_chunk(regionfile *region, int32_t cx, int32_t cz, chunk *c)
int64_t inhabitedTime
Definition: mcchunk.h:58
void initblockdb()
int32_t x
Definition: mcchunk.h:53
size_t count_chunks(regionfile *region)
void(* chunk_func)(chunk *c, void *context)
Definition: mcchunk.h:89
void free_region(regionfile *region)
int write_level(level *lvl, char *into)
int region_contains_chunk(regionfile *region, int32_t cx, int32_t cz)
#define CHUNK_HEIGHT
Definition: mcchunk.h:50
void(* raw_chunk_func)(nbt_node *node, void *context)
Definition: mcchunk.h:82
uint8_t region_chunk_sector_count(regionfile *region, int32_t cx, int32_t cz)
int32_t rainTime
Definition: mcchunk.h:193
void free_level(level *lvl)
int32_t y
Definition: mcchunk.h:188
#define CHUNK_WIDTH
Definition: mcchunk.h:48
void free_chunk(chunk *c)
uint64_t daytime
Definition: mcchunk.h:185
Definition: nbt.h:67
unsigned char * freeSectors
Definition: mcchunk.h:41
FILE * file
Definition: mcchunk.h:44
nbt_node * entities
Definition: mcchunk.h:60
chunk * nbt_to_chunk(nbt_node *node, uint16_t flags)
int32_t z
Definition: mcchunk.h:54
nbt_node * get_raw_chunk(regionfile *region, int32_t cx, int32_t cz)
chunk_options
Definition: mcchunk.h:63