Apply the waring in nbt/README.md
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
# NBT [](https://pkg.go.dev/github.com/Tnze/go-mc/nbt)
|
||||
This package implement the [Named Binary Tag](https://wiki.vg/NBT) format of Minecraft.
|
||||
|
||||
The API is very similar to the standard library `encoding/json`. If you (high probability) have used that, it is easy to use this.
|
||||
This package implement the [Named Binary Tag](https://wiki.vg/NBT) format of Minecraft.
|
||||
|
||||
# Basic Usage
|
||||
> I don't know why `Marshal` looks like that, and **I will change it** to `func Marshal(v interface{}) ([]byte, error)`.
|
||||
> **Use `Encoder` is recommended now.**
|
||||
The API is very similar to the standard library `encoding/json`. If you (high probability) have used that, it is easy to
|
||||
use this.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
For the following NBT tag:
|
||||
|
||||
@ -20,7 +20,6 @@ To read and write would look like:
|
||||
```go
|
||||
package main
|
||||
|
||||
import "bytes"
|
||||
import "github.com/Tnze/go-mc/nbt"
|
||||
|
||||
type Compound struct {
|
||||
@ -28,27 +27,26 @@ type Compound struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var out bytes.Buffer
|
||||
banana := Compound{Name: "Bananrama"}
|
||||
_ = nbt.Marshal(&out, banana)
|
||||
data, _ := nbt.Marshal(banana)
|
||||
|
||||
var rama Compound
|
||||
_ = nbt.Unmarshal(out.Bytes(), &rama)
|
||||
_ = nbt.Unmarshal(data, &rama)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
# Struct field tags
|
||||
## Struct field tags
|
||||
|
||||
There are two tags supported:
|
||||
|
||||
- nbt
|
||||
- nbt_type
|
||||
|
||||
The `nbt` tag is used to change the name of the NBT Tag field, whereas the `nbt_type`
|
||||
tag is used to enforce a certain NBT Tag type when it is ambiguous.
|
||||
tag is used to enforce a certain NBT Tag type when it is ambiguous.
|
||||
|
||||
For example:
|
||||
|
||||
```go
|
||||
type Compound struct {
|
||||
LongArray []int64
|
||||
@ -56,5 +54,25 @@ type Compound struct {
|
||||
}
|
||||
```
|
||||
|
||||
## Stringified NBT
|
||||
|
||||
You can transform SNBT string into binary NBT by using go-mc, which could be useful when parsing command, but the
|
||||
reverse conversion is not supported at the moment.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var buf bytes.Buffer
|
||||
e := nbt.NewEncoder(&buf)
|
||||
err := e.WriteSNBT(`{Tnze: 1, 'sp ace': [I;1,2,3]}`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user