Skip to content

Instantly share code, notes, and snippets.

@agrif
Created September 25, 2011 20:27
Show Gist options
  • Save agrif/1241110 to your computer and use it in GitHub Desktop.
Save agrif/1241110 to your computer and use it in GitHub Desktop.
a simple demo of loading block data with libredstone
#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