nbt lib handle TagByte as signed int8 now
This commit is contained in:
@ -83,7 +83,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
return ErrEND
|
return ErrEND
|
||||||
|
|
||||||
case TagByte:
|
case TagByte:
|
||||||
value, err := d.r.ReadByte()
|
value, err := d.readByte()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagShort:
|
case TagShort:
|
||||||
value, err := d.readInt16()
|
value, err := d.readShort()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagInt:
|
case TagInt:
|
||||||
value, err := d.readInt32()
|
value, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagFloat:
|
case TagFloat:
|
||||||
vInt, err := d.readInt32()
|
vInt, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagLong:
|
case TagLong:
|
||||||
value, err := d.readInt64()
|
value, err := d.readLong()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagDouble:
|
case TagDouble:
|
||||||
vInt, err := d.readInt64()
|
vInt, err := d.readLong()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagByteArray:
|
case TagByteArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TagIntArray:
|
case TagIntArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
|
|
||||||
buf := reflect.MakeSlice(vt, int(aryLen), int(aryLen))
|
buf := reflect.MakeSlice(vt, int(aryLen), int(aryLen))
|
||||||
for i := 0; i < int(aryLen); i++ {
|
for i := 0; i < int(aryLen); i++ {
|
||||||
value, err := d.readInt32()
|
value, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
val.Set(buf)
|
val.Set(buf)
|
||||||
|
|
||||||
case TagLongArray:
|
case TagLongArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
|
|
||||||
buf := reflect.MakeSlice(vt, int(aryLen), int(aryLen))
|
buf := reflect.MakeSlice(vt, int(aryLen), int(aryLen))
|
||||||
for i := 0; i < int(aryLen); i++ {
|
for i := 0; i < int(aryLen); i++ {
|
||||||
value, err := d.readInt64()
|
value, err := d.readLong()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
listLen, err := d.readInt32()
|
listLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -465,7 +465,7 @@ func (d *Decoder) rawRead(tagType byte) error {
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown to read 0x%02x", tagType)
|
return fmt.Errorf("unknown to read 0x%02x", tagType)
|
||||||
case TagByte:
|
case TagByte:
|
||||||
_, err := d.r.ReadByte()
|
_, err := d.readByte()
|
||||||
return err
|
return err
|
||||||
case TagString:
|
case TagString:
|
||||||
_, err := d.readString()
|
_, err := d.readString()
|
||||||
@ -480,7 +480,7 @@ func (d *Decoder) rawRead(tagType byte) error {
|
|||||||
_, err := io.ReadFull(d.r, buf[:8])
|
_, err := io.ReadFull(d.r, buf[:8])
|
||||||
return err
|
return err
|
||||||
case TagByteArray:
|
case TagByteArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -489,23 +489,23 @@ func (d *Decoder) rawRead(tagType byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case TagIntArray:
|
case TagIntArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < int(aryLen); i++ {
|
for i := 0; i < int(aryLen); i++ {
|
||||||
if _, err := d.readInt32(); err != nil {
|
if _, err := d.readInt(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case TagLongArray:
|
case TagLongArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < int(aryLen); i++ {
|
for i := 0; i < int(aryLen); i++ {
|
||||||
if _, err := d.readInt64(); err != nil {
|
if _, err := d.readLong(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,7 +515,7 @@ func (d *Decoder) rawRead(tagType byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
listLen, err := d.readInt32()
|
listLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -554,20 +554,26 @@ func (d *Decoder) readTag() (tagType byte, tagName string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) readInt16() (int16, error) {
|
func (d *Decoder) readByte() (int8, error) {
|
||||||
|
b, err := d.r.ReadByte()
|
||||||
|
// TagByte is signed byte (that's what in Java), so we need to convert to int8
|
||||||
|
return int8(b), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Decoder) readShort() (int16, error) {
|
||||||
var data [2]byte
|
var data [2]byte
|
||||||
_, err := io.ReadFull(d.r, data[:])
|
_, err := io.ReadFull(d.r, data[:])
|
||||||
return int16(data[0])<<8 | int16(data[1]), err
|
return int16(data[0])<<8 | int16(data[1]), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) readInt32() (int32, error) {
|
func (d *Decoder) readInt() (int32, error) {
|
||||||
var data [4]byte
|
var data [4]byte
|
||||||
_, err := io.ReadFull(d.r, data[:])
|
_, err := io.ReadFull(d.r, data[:])
|
||||||
return int32(data[0])<<24 | int32(data[1])<<16 |
|
return int32(data[0])<<24 | int32(data[1])<<16 |
|
||||||
int32(data[2])<<8 | int32(data[3]), err
|
int32(data[2])<<8 | int32(data[3]), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) readInt64() (int64, error) {
|
func (d *Decoder) readLong() (int64, error) {
|
||||||
var data [8]byte
|
var data [8]byte
|
||||||
_, err := io.ReadFull(d.r, data[:])
|
_, err := io.ReadFull(d.r, data[:])
|
||||||
return int64(data[0])<<56 | int64(data[1])<<48 |
|
return int64(data[0])<<56 | int64(data[1])<<48 |
|
||||||
@ -577,7 +583,7 @@ func (d *Decoder) readInt64() (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) readString() (string, error) {
|
func (d *Decoder) readString() (string, error) {
|
||||||
length, err := d.readInt16()
|
length, err := d.readShort()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
} else if length < 0 {
|
} else if length < 0 {
|
||||||
|
22
nbt/snbt.go
22
nbt/snbt.go
@ -89,29 +89,29 @@ func (m *StringifiedMessage) encode(d *Decoder, sb *strings.Builder, tagType byt
|
|||||||
writeEscapeStr(sb, str)
|
writeEscapeStr(sb, str)
|
||||||
return err
|
return err
|
||||||
case TagShort:
|
case TagShort:
|
||||||
s, err := d.readInt16()
|
s, err := d.readShort()
|
||||||
sb.WriteString(strconv.FormatInt(int64(s), 10) + "S")
|
sb.WriteString(strconv.FormatInt(int64(s), 10) + "S")
|
||||||
return err
|
return err
|
||||||
case TagInt:
|
case TagInt:
|
||||||
i, err := d.readInt32()
|
i, err := d.readInt()
|
||||||
sb.WriteString(strconv.FormatInt(int64(i), 10))
|
sb.WriteString(strconv.FormatInt(int64(i), 10))
|
||||||
return err
|
return err
|
||||||
case TagFloat:
|
case TagFloat:
|
||||||
i, err := d.readInt32()
|
i, err := d.readInt()
|
||||||
f := float64(math.Float32frombits(uint32(i)))
|
f := float64(math.Float32frombits(uint32(i)))
|
||||||
sb.WriteString(strconv.FormatFloat(f, 'f', 10, 32) + "F")
|
sb.WriteString(strconv.FormatFloat(f, 'f', 10, 32) + "F")
|
||||||
return err
|
return err
|
||||||
case TagLong:
|
case TagLong:
|
||||||
i, err := d.readInt64()
|
i, err := d.readLong()
|
||||||
sb.WriteString(strconv.FormatInt(i, 10) + "L")
|
sb.WriteString(strconv.FormatInt(i, 10) + "L")
|
||||||
return err
|
return err
|
||||||
case TagDouble:
|
case TagDouble:
|
||||||
i, err := d.readInt64()
|
i, err := d.readLong()
|
||||||
f := math.Float64frombits(uint64(i))
|
f := math.Float64frombits(uint64(i))
|
||||||
sb.WriteString(strconv.FormatFloat(f, 'f', 10, 64) + "D")
|
sb.WriteString(strconv.FormatFloat(f, 'f', 10, 64) + "D")
|
||||||
return err
|
return err
|
||||||
case TagByteArray:
|
case TagByteArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -131,14 +131,14 @@ func (m *StringifiedMessage) encode(d *Decoder, sb *strings.Builder, tagType byt
|
|||||||
}
|
}
|
||||||
sb.WriteString("]")
|
sb.WriteString("]")
|
||||||
case TagIntArray:
|
case TagIntArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sb.WriteString("[I;")
|
sb.WriteString("[I;")
|
||||||
first := true
|
first := true
|
||||||
for i := 0; i < int(aryLen); i++ {
|
for i := 0; i < int(aryLen); i++ {
|
||||||
v, err := d.readInt32()
|
v, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -151,14 +151,14 @@ func (m *StringifiedMessage) encode(d *Decoder, sb *strings.Builder, tagType byt
|
|||||||
}
|
}
|
||||||
sb.WriteString("]")
|
sb.WriteString("]")
|
||||||
case TagLongArray:
|
case TagLongArray:
|
||||||
aryLen, err := d.readInt32()
|
aryLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
first := true
|
first := true
|
||||||
sb.WriteString("[L;")
|
sb.WriteString("[L;")
|
||||||
for i := 0; i < int(aryLen); i++ {
|
for i := 0; i < int(aryLen); i++ {
|
||||||
v, err := d.readInt64()
|
v, err := d.readLong()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ func (m *StringifiedMessage) encode(d *Decoder, sb *strings.Builder, tagType byt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
listLen, err := d.readInt32()
|
listLen, err := d.readInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ type Chunk struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Section struct {
|
type Section struct {
|
||||||
Y byte
|
Y int8
|
||||||
BlockStates struct {
|
BlockStates struct {
|
||||||
Palette []BlockState `nbt:"palette"`
|
Palette []BlockState `nbt:"palette"`
|
||||||
Data []int64 `nbt:"data"`
|
Data []int64 `nbt:"data"`
|
||||||
|
Reference in New Issue
Block a user