This repo contains a Go module/pakage to make NBT (named binary tags) readable and editable in a Lua script environment, and a command-line interface similar to native lua to run Lua scripts which can load, modify, and write NBT data.
use_bedrock_encoding()
- Sets future NBT encoding decoding using the Bedrock Edition (little endian) formatuse_java_encoding()
- Sets future NBT encoding decoding using the Java Edition (little endian) formatloadnbt(path)
- Wherepath
is a path to an NBT file, it will auto-detect whether it's compressed and populate thenbt
variable with its datasavenbt(path, compress)
- Convertsnbt
back to NBT and writes topath
.compress
istrue
for compressed output and ommitted orfalse
for uncompressed output.
- lua's global
nbt
is a table{}
in which each top-level nbt tag is - in many cases there is only one top-level nbt compound tag, so
nbt[1]
is that tag, andnbt[1][1]
,nbt[1][2]
... are the first-tier tags you're looking for. Trynbt[1][1].name
or the equivalentnbt[1][1]["name"]
- All tags (except tag 0 / end) are added as tables, and they have a
tagType
,value
, andname
- Compound and list tags' values are again tables of the values beginning with
[1]
See /examples folder for example lua scripts.
See examples/go-example.go for how to use the package
func Nbt2Lua(b []byte, L *lua.LState) error
- pass it an uncompressed nbt byte array and the gopher-lua state variable, and it will populate thenbt
global variable in Lua with a table hierarchy representing the nbt datafunc Lua2Nbt(L *lua.LState) ([]byte, error)
- pass it the gopher-lua state variable, and it will convert thenbt
global variable into an nbt byte array and return itfunc UseBedrockEncoding()
- This makes any future conversions read/write the nbt usable by Minecraft Bedrock Edition (little endian). This is the default state when the package is loaded.func UseJavaEncoding()
- This makes any future conversions read/write the nbt usable by Minecraft Java Edition (big endian)func NewState() *lua.LState
- This can be used in place of calling lua.NewState for one less include in the client program, and it calls Nlua before returing LStatefunc Nlua(L *lua.LState)
- Nlua injectsloadnbt()
and (future)savenbt()
functions into a lua environment