A Typescript library for reading Minecraft Anvil format files and Minecraft NBT format files in the browser.
For npm use: npm install mc-anvil --save
For yarn use: yarn add mc-anvil
import { NBTParser, AnvilParser } from "mc-anvil";The following example reads the root tag from an NBT file uploaded into the browser:
const reader = new FileReader();
reader.onload = e => {
const parser = new NBTParser(e);
const tag = parser.getTag(); // receives contents of the root tag
};
reader.readAsArrayBuffer(file); // file is a File object or Blob containing NBT dataThe following example extracts a chunk from an Anvil file uploaded into the browser:
const reader = new FileReader();
reader.onload = e => {
const parser = new AnvilParser(e);
const chunks = parser.getLocationEntries();
const firstNonEmptyChunk = chunks.filter(x => x.offset > 0)[0].offset;
const data = parser.getChunkData(firstNonEmptyChunk); // receives NBT data of the first chunk
const nbtParser = new NBTParser(data);
const tag = nbtParser.getTag(); // receives contents of the chunk's root NBT tag
};
reader.readAsArrayBuffer(file); // file is a File object or Blob containing Anvil data- Run
yarn installto install dependencies. - Run
yarn buildto build.
You must have Node.js and docker-compose installed.
scripts/test.shto run automated tests.scripts/run-dependencies.shto stand up a web server to host static sample NBT and Anvil files.scripts/test.shruns this for you.scripts/stop-dependencies.shto stop bring down the server.