Skip to content

A Typescript library for reading Minecraft Anvil format files and Minecraft NBT format files in the browser.

License

Notifications You must be signed in to change notification settings

hpratt/mc-anvil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7dfc8e4 · Jul 31, 2023

History

50 Commits
Dec 26, 2020
Jan 1, 2022
Dec 26, 2020
Jul 31, 2023
Jul 31, 2023
Jan 1, 2021
Dec 26, 2020
Dec 26, 2020
Dec 26, 2020
Dec 27, 2020
Jul 31, 2023
Jan 1, 2021
Jan 18, 2022

Repository files navigation

mc-anvil

A Typescript library for reading Minecraft Anvil format files and Minecraft NBT format files in the browser.

Installation

For npm use: npm install mc-anvil --save

For yarn use: yarn add mc-anvil

Usage

Importing

import { NBTParser, AnvilParser } from "mc-anvil";

Reading NBT data

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 data

Reading Anvil data

The 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

For contributers

Building

  • Run yarn install to install dependencies.
  • Run yarn build to build.

Testing

You must have Node.js and docker-compose installed.

  • scripts/test.sh to run automated tests.
  • scripts/run-dependencies.sh to stand up a web server to host static sample NBT and Anvil files. scripts/test.sh runs this for you.
  • scripts/stop-dependencies.sh to stop bring down the server.

About

A Typescript library for reading Minecraft Anvil format files and Minecraft NBT format files in the browser.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages