Add 1.21.1 chat support (#284)

Merge this without verification. Otherwise can't be reviewed in the further updates.
This commit is contained in:
Tnze
2024-12-24 11:20:05 +08:00
committed by GitHub
parent 9a1f543137
commit 539b4a3a7f
5 changed files with 115 additions and 15 deletions

36
chat/nbtmessage_test.go Normal file
View File

@ -0,0 +1,36 @@
package chat_test
import (
"testing"
"github.com/Tnze/go-mc/chat"
en_us "github.com/Tnze/go-mc/data/lang/en-us"
"github.com/Tnze/go-mc/nbt"
)
func TestMessage_UnmarshalJSON_string(t *testing.T) {
snbts := []string{
"{translate: sleep.players_sleeping, with: [I; 1, 37]}",
}
texts := []string{
"1/37 players sleeping",
}
chat.SetLanguage(en_us.Map)
for i, v := range snbts {
bytes, err := nbt.Marshal(nbt.StringifiedMessage(v))
if err != nil {
t.Errorf("Invalid SNBT: %v", err)
continue
}
var cm chat.Message
if err := nbt.Unmarshal(bytes, &cm); err != nil {
t.Error(err)
}
if str := cm.String(); str != texts[i] {
t.Errorf("gets %q, wants %q", str, texts[i])
}
}
}