Libanvil is a C++ library for reading and writing Minecraft "Anvil" files
- About -- About the project
- Building -- How to build the project
- Usage -- How to use the project
- Changelog -- Log of project changes
The project is implemented in C++ and exposes a simple API, described in include/region*.h
and bin/lib/libanvil.a
.
- Open Minecraft "Anvil" map files (.mca)
- Retrieve various bits of data (per chunk):
- Biome data at a given x, z coord
- HeightMap data at a given x, z coord
- Block data at a given x, y, z coord
- (or any tag with a known name)
- Read extended block ids (ie. those blocks that use the "AddBlocks" tag)
- This will be fixed soon, once more information becomes available!
- Create/Write .mca files
Instructions for compiling libanvil from source code
- g++ 4.4.3 or newer
- make 3.8 or newer
- boost regex 1.42 or newer
- zlib 1.2.3.3 or newer
sudo apt-get install build-essential make zlib-dev libboost1.42-all-dev
make
g++ -o <EXECUTABLE NAME> <MAIN>.cpp -std=c++0x -lboost_regex -lz -I <PATH_TO_LIBNBT> -L <PATH_TO_LIBNBT> -lanvil
The easiest way to access block/heightmap data for each chunk is to use the region_file_reader object. No cleanup is necessary. All allocations/deallocations are handled internally within the reader.
region_file_reader reader;
reader = region_file_reader("path-to-region-file");
OR
region_file_reader reader("path-to-region-file");
std::vector<int> blocks, heights;
...
blocks = reader.get_blocks_at(x, z);
heights = reader.get_heightmap_at(x, z);
Data is stored in the chunks from the top-left to bottom right, and all coord are relative to the chunk itself.
Block {x, y, z} = (y * 16 + z) * 16 + x
HeightMap {x, z} = x + z * 16
#include <iostream>
#include <stdexcept>
#include <vector>
#include "region_file_reader.h"
int main(int argc, char *argv[]) {
// instantiate a file reader
region_file_reader reader;
// create vectors to hold block/height data
std::vector<int> blocks, heights;
try {
// open a region file
reader = region_file_reader("path-to-region-file");
reader.read();
// iterate through all possible chunks within a region
for(unsigned int z = 0; z < 32; ++z)
for(unsigned int x = 0; x < 32; ++x) {
// this keeps an exception from being thrown
// when a non-existant chunk is requested
if(!reader.is_filled(x, z))
continue;
// if everything goes well, retrieve the block/height data
blocks = reader.get_blocks_at(x, z);
heights = reader.get_heightmap_at(x, z);
// ...
}
// catch all exception that may occur
} catch(std::runtime_error &exc) {
std::cerr << exc.what() << std::endl;
return 1;
}
return 0;
}
Updated: 4/5/2020
- Minor code cleanup/bug fixes
- Updated build process
- Added example program
Updated: 8/16/2019
- Project refactoring
Updated: 2/6/2017
- Minor bug fix in long NBT tag
- Updated documentation
Changelog truncated (see file history for full log)