Experimental fastnbt library

This commit is contained in:
Tnze
2023-04-24 01:40:22 +08:00
parent de254fb1c6
commit ad3f69e40b
7 changed files with 565 additions and 0 deletions

47
nbt/fastnbt/update.go Normal file
View File

@ -0,0 +1,47 @@
package fastnbt
import "github.com/Tnze/go-mc/nbt"
func (v *Value) Set(key string, val *Value) {
if v.tag != nbt.TagCompound {
panic("cannot set non-Compound Tag")
}
v.comp.Set(key, val)
}
func (v *Value) Get(keys ...string) *Value {
for _, key := range keys {
if v.tag == nbt.TagCompound {
v = v.comp.Get(key)
if v == nil {
return nil
}
} else {
return nil
}
}
return v
}
func (c *Compound) Set(key string, val *Value) {
for i := range c.kvs {
if c.kvs[i].tag == key {
c.kvs[i].v = val
return
}
}
c.kvs = append(c.kvs, kv{key, val})
}
func (c *Compound) Get(key string) *Value {
for _, tag := range c.kvs {
if tag.tag == key {
return tag.v
}
}
return nil
}
func (c *Compound) Len() int {
return len(c.kvs)
}