Skip to content

A golang library for reading and writing minecraft anvil files

License

Notifications You must be signed in to change notification settings

FireworkMC/anvil

Repository files navigation

anvil

Go Go Report Card codecov Go Reference

anvil is a simple library for reading and writing minecraft anvil files.

Installation

go get github.com/FireworkMC/anvil

Usage

Reading and writing data from a directory containing anvil files

a, err := anvil.Open("/path/to/anvil/dir")
if err != nil{
    // handle error
}

var buffer bytes.Buffer
_, err = a.ReadTo(chunkX, chunkZ, &buffer)

// do stuff with the buffer


err = a.Write(chunkX, chunkZ, buffer.Bytes())

err = a.Close()

The anvil.Anvil returned by Open contains a cache of opened anvil files. It is recommended to use Open instead of OpenFile since opening anvil files is an expensive operation.

Reading and writing data from a single anvil file

f, err := anvil.OpenFile("/path/to/anvil/file")
if err != nil{
    // handle error
}

var buffer bytes.Buffer
// relative coordinates of the chunk data must be used
// If the chunk exists at chunkX, chunkZ: chunkX % 32, chunkZ % 32 should be used. 
_, err = f.ReadTo(chunkX%32, chunkZ%32, &buffer)


// do stuff with buffer

_, err = f.Write(chunkX%32, chunkZ%32, buffer.Bytes())

About

A golang library for reading and writing minecraft anvil files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages