residentsleeper/scripting/minecraft/nbt.go
Tyler b52b38179a
Some checks failed
continuous-integration/drone/push Build is failing
Major updates/patches, functionality, api
2020-07-09 21:01:29 -04:00

34 lines
700 B
Go

package minecraft
import (
"github.com/ppacher/nbt"
lua "github.com/yuin/gopher-lua"
)
func TagToLuaValue(L *lua.LState, tag nbt.Tag) lua.LValue {
switch tag.TagID() {
case nbt.TagDouble:
return lua.LNumber(tag.(*nbt.DoubleTag).Value)
case nbt.TagFloat:
return lua.LNumber(tag.(*nbt.FloatTag).Value)
case nbt.TagInt:
return lua.LNumber(tag.(*nbt.IntTag).Value)
case nbt.TagLong:
return lua.LNumber(tag.(*nbt.LongTag).Value)
case nbt.TagString:
return lua.LString(tag.(*nbt.StringTag).Value)
case nbt.TagCompound:
t := L.NewTable()
c := tag.(*nbt.CompoundTag)
for key, v := range c.Tags {
t.RawSetString(key, TagToLuaValue(L, v))
}
return t
}
return lua.LNil
}