Created
September 25, 2011 20:27
-
-
Save agrif/1241110 to your computer and use it in GitHub Desktop.
a simple demo of loading block data with libredstone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <libredstone/redstone.h> | |
int main(int argc, char* argv[]) | |
{ | |
RSRegion* region = rs_region_open("path/to/regions/r.0.0.mcr", false); | |
if (!region) | |
{ | |
/* file didn't load... */ | |
return 1; | |
} | |
RSNBT* chunk = rs_nbt_parse_from_region(region, 0, 0); /* 0, 0 == coords */ | |
if (!chunk) | |
{ | |
/* chunk doesn't exist... */ | |
return 1; | |
} | |
RSTag* blockdata_tag = rs_nbt_find(chunk, "Blocks"); | |
if (!blockdata_tag) | |
{ | |
/* invalid chunk format... */ | |
return 1; | |
} | |
uint8_t* blocks = rs_tag_get_byte_array(blockdata_tag); | |
/* do something with blocks, which is a flat, 1d array */ | |
blocks[0] = 0; | |
/* free used memory */ | |
rs_nbt_free(chunk); | |
rs_region_close(region); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment