Merge pull request #83 from masp/master
rename tag for nbt_type to list instead of noarray and add documentation
This commit is contained in:
@ -1,4 +1,53 @@
|
||||
# NBT
|
||||
This package implement the Named Binary Tag format of Minecraft.
|
||||
This package implement the Named Binary Tag format of Minecraft. It supports all formats
|
||||
of NBT including compact arrays for longs.
|
||||
|
||||
# Usage
|
||||
For the following NBT tag:
|
||||
|
||||
```
|
||||
TAG_Compound("hello world") {
|
||||
TAG_String('name'): 'Bananrama'
|
||||
}
|
||||
```
|
||||
|
||||
To read and write would look like:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "bytes"
|
||||
import "github.com/Tnze/go-mc/nbt"
|
||||
|
||||
type Compound struct {
|
||||
Name string `nbt:"name"` // Note that if name is private (name), the field will not be used
|
||||
}
|
||||
|
||||
func main() {
|
||||
var out bytes.Buffer
|
||||
banana := Compound{Name: "Bananrama"}
|
||||
_ = nbt.Marshal(&out, banana)
|
||||
|
||||
var rama Compound
|
||||
_ = nbt.Unmarshal(out.Bytes(), &rama)
|
||||
}
|
||||
```
|
||||
|
||||
# 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.
|
||||
|
||||
For example:
|
||||
```go
|
||||
type Compound struct {
|
||||
LongArray []int64
|
||||
LongList []int64 `nbt_type:"list"` // forces a long list instead of a long array
|
||||
}
|
||||
```
|
||||
|
||||
# Docs
|
||||
[](https://godoc.org/github.com/Tnze/go-mc/nbt)
|
@ -186,11 +186,11 @@ func parseTag(f reflect.StructField, tagName string) tagProps {
|
||||
|
||||
nbtType := f.Tag.Get("nbt_type")
|
||||
result.Type = getTagType(f.Type)
|
||||
if strings.Contains(nbtType, "noarray") {
|
||||
if strings.Contains(nbtType, "list") {
|
||||
if IsArrayTag(result.Type) {
|
||||
result.Type = TagList // for expanding the array to a standard list
|
||||
} else {
|
||||
panic("noarray is only supported for array types (byte, int, long)")
|
||||
panic("list is only supported for array types (byte, int, long)")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ type BigTestStruct struct {
|
||||
Value float32 `nbt:"value"`
|
||||
} `nbt:"egg"`
|
||||
} `nbt:"nested compound test"`
|
||||
ListTest []int64 `nbt:"listTest (long)" nbt_type:"noarray"`
|
||||
ListTest []int64 `nbt:"listTest (long)" nbt_type:"list"`
|
||||
ListTest2 [2]struct {
|
||||
Name string `nbt:"name"`
|
||||
CreatedOn int64 `nbt:"created-on"`
|
||||
|
Reference in New Issue
Block a user