Files
go-mc/level/block/properties.go
2022-03-09 16:12:47 +08:00

39 lines
729 B
Go

package block
import (
"strconv"
)
type (
Boolean bool
Direction string
Integer int
)
func (b Boolean) MarshalText() (text []byte, err error) {
return []byte(strconv.FormatBool(bool(b))), nil
}
func (b *Boolean) UnmarshalText(text []byte) (err error) {
*((*bool)(b)), err = strconv.ParseBool(string(text))
return
}
func (d Direction) MarshalText() (text []byte, err error) {
return []byte(d), nil
}
func (d *Direction) UnmarshalText(text []byte) error {
*d = Direction(text)
return nil
}
func (i Integer) MarshalText() (text []byte, err error) {
return []byte(strconv.Itoa(int(i))), nil
}
func (i *Integer) UnmarshalText(text []byte) (err error) {
*((*int)(i)), err = strconv.Atoi(string(text))
return
}