All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Typedefs | Enumerations | Functions
mcchunk.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "nbt.h"
Include dependency graph for mcchunk.h:

Go to the source code of this file.

Data Structures

struct  regionfile
struct  chunk
struct  level


#define restrict
#define SECTOR_BYTES   4096
#define SECTOR_INTS   1024
#define CHUNK_WIDTH   16
#define CHUNK_LENGTH   16
#define CHUNK_HEIGHT   256
#define chunk_from_coord(i)   (i/16)


typedef void(* raw_chunk_func )(nbt_node *node, void *context)
typedef void(* chunk_func )(chunk *c, void *context)


enum  chunk_options { GET_TILE_ENTITIES = (1<<0), GET_ENTITIES = (1<<1) }


regionfileopen_regionfile (char *filename)
void free_region (regionfile *region)
size_t count_chunks (regionfile *region)
void for_each_chunk_raw (regionfile *region, raw_chunk_func function, void *context)
void for_each_chunk (regionfile *region, chunk_func function, void *context)
int region_contains_chunk (regionfile *region, int32_t cx, int32_t cz)
uint8_t region_chunk_sector_count (regionfile *region, int32_t cx, int32_t cz)
nbt_nodeget_raw_chunk (regionfile *region, int32_t cx, int32_t cz)
chunknbt_to_chunk (nbt_node *node, uint16_t flags)
size_t determine_region_file (char *buf, size_t len, int32_t cx, int32_t cz)
int write_chunk (regionfile *region, int32_t cx, int32_t cz, chunk *c)
void initblockdb ()
char * get_block_name (uint8_t block_id, uint8_t data)
void initbiomedb ()
char * get_biome_name (uint8_t biome_id)
chunkget_chunk (regionfile *region, int32_t cx, int32_t cz, uint16_t flags)
void free_chunk (chunk *c)
levelopen_level (char *filename)
int write_level (level *lvl, char *into)
void free_level (level *lvl)

Macro Definition Documentation

#define chunk_from_coord (   i)    (i/16)

Calculate in which chunk this coordinate is

Definition at line 132 of file mcchunk.h.

#define CHUNK_HEIGHT   256

Definition at line 50 of file mcchunk.h.

#define CHUNK_LENGTH   16

Definition at line 49 of file mcchunk.h.

#define CHUNK_WIDTH   16

Definition at line 48 of file mcchunk.h.

#define restrict

Definition at line 25 of file mcchunk.h.

#define SECTOR_BYTES   4096

Definition at line 35 of file mcchunk.h.

#define SECTOR_INTS   1024

Definition at line 36 of file mcchunk.h.

Typedef Documentation

typedef void(* chunk_func)(chunk *c, void *context)

Definition at line 89 of file mcchunk.h.

typedef void(* raw_chunk_func)(nbt_node *node, void *context)

Definition at line 82 of file mcchunk.h.

Enumeration Type Documentation


Definition at line 63 of file mcchunk.h.

Function Documentation

size_t count_chunks ( regionfile region)

Count the amount of chunks available in this region structure

size_t determine_region_file ( char *  buf,
size_t  len,
int32_t  cx,
int32_t  cz 

Determine in which region file the chunk cx, cz is located.

See Also
chunk_from_coord Don't forget to free the output!
void for_each_chunk ( regionfile region,
chunk_func  function,
void *  context 

Loop through all the available chunks in our regionfile don't do some odd for loop yourself calling get_chunk as this function is simply more efficient, it keeps the file open for example. (And it's just easier..) Don't keep the chunk around, as it is freed automatically

void for_each_chunk_raw ( regionfile region,
raw_chunk_func  function,
void *  context 

Similar to for_each_chunk but gives you access to the raw nbt_node* instead.

void free_chunk ( chunk c)

Free function for the chunk structure

void free_level ( level lvl)

Free function for the level structure

void free_region ( regionfile region)

Used to free the region structure

char* get_biome_name ( uint8_t  biome_id)

Get the human readable name for biome_id if this biome_id simply doesn't exist it'll return NULL (-1 isn't even handled)

See Also
char* get_block_name ( uint8_t  block_id,
uint8_t  data 

Get the human readable name for block_id with data if the block simply doesn't exist it'll return NULL

See Also
chunk* get_chunk ( regionfile region,
int32_t  cx,
int32_t  cz,
uint16_t  flags 

Get a chunk structure for the chunk located at cx, cz in region. Blocks in this structure are accessed using the blocks and data arrays, it would look like the following: c->blocks[y][z][x];

nbt_node* get_raw_chunk ( regionfile region,
int32_t  cx,
int32_t  cz 

Returns the nbt structure for this particular chunk

See Also
void initbiomedb ( )

Initialize the biome name database you must call this before using

See Also
void initblockdb ( )

Initialize the block names database you must call this once before using

See Also
chunk* nbt_to_chunk ( nbt_node node,
uint16_t  flags 

Convert a raw nbt_node* to a chunk structure instead will return NULL upon failure.

level* open_level ( char *  filename)

Open a level.dat file

regionfile* open_regionfile ( char *  filename)

Used to open a region file simply pass the filename into it

uint8_t region_chunk_sector_count ( regionfile region,
int32_t  cx,
int32_t  cz 

Return the amount of internal sectors this chunk consists of, will return 0 on error.

int region_contains_chunk ( regionfile region,
int32_t  cx,
int32_t  cz 

Check if this region structure contains the chunk located at x: cx y: cy returns 1 if it is in the region structure, 0 otherwise ingame you can get the chunk coordinates from the debug screen (F3). It'll look something like this: x: -20.64464 (-21) // c: -2 (11) y: 120.500 (feet pos, 122.120 eyes pos) z: 36.39552 (36) // c: 2 (4)

The x, y & z coordinates here are your players location the number just behind "c:" is the chunk number. So in this case it would be x: -2, z: 2.

int write_chunk ( regionfile region,
int32_t  cx,
int32_t  cz,
chunk c 

Writes the chunk to the regionfile at position cx, cz

int write_level ( level lvl,
char *  into 

Write our level structure into a file

intothe filepath to write into, must exist. If NULL it'll be written into the original path.