Record TagType when decoding RawMessage.

Display item's NBT in example/daze.
Upgrade data/item to 1.17
This commit is contained in:
Tnze
2021-07-05 13:35:22 +08:00
parent 8d14180744
commit e6246ce675
3 changed files with 2432 additions and 2046 deletions

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,7 @@ func onScreenSlotChange(id, index int) error {
slot := container.(*screen.Inventory).Slots[index] slot := container.(*screen.Inventory).Slots[index]
itemInfo := item.ByID[item.ID(slot.ID)] itemInfo := item.ByID[item.ID(slot.ID)]
if slot.ID != 0 { if slot.ID != 0 {
log.Printf("Slot: Screen[%d].Slot[%d]: [%v] * %d", id, index, itemInfo.DisplayName, slot.Count) log.Printf("Slot: Screen[%d].Slot[%d]: [%v] * %d | NBT: %v", id, index, itemInfo.DisplayName, slot.Count, slot.NBT)
} }
} }
} }

View File

@ -3,6 +3,7 @@ package nbt
import ( import (
"bytes" "bytes"
"io" "io"
"strings"
) )
type RawMessage struct { type RawMessage struct {
@ -29,6 +30,22 @@ func (m *RawMessage) Decode(tagType byte, r DecoderReader) error {
if err != nil { if err != nil {
return err return err
} }
m.Type = tagType
m.Data = buf.Bytes() m.Data = buf.Bytes()
return nil return nil
} }
func (m RawMessage) String() string {
if m.Type == TagEnd {
return "TagEnd"
}
var snbt StringifiedMessage
var sb strings.Builder
r := bytes.NewReader(m.Data)
d := NewDecoder(r)
err := snbt.encode(d, &sb, m.Type)
if err != nil {
return "Invalid"
}
return sb.String()
}