Add tags implement

This commit is contained in:
Tnze
2024-07-27 23:53:35 +08:00
parent d88ee401fd
commit 31375289b0
7 changed files with 218 additions and 13 deletions

View File

@ -43,6 +43,7 @@ func NewPlayer(c *bot.Client, settings Settings, events EventsListener) *Player
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundPing, F: p.handlePingPacket},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundCookieRequest, F: p.handleCookieRequestPacket},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundStoreCookie, F: p.handleStoreCookiePacket},
bot.PacketHandler{Priority: 0, ID: packetid.ClientboundUpdateTags, F: p.handleUpdateTags},
)
events.attach(p)
return p

37
bot/basic/tags.go Normal file
View File

@ -0,0 +1,37 @@
package basic
import (
"bytes"
"errors"
pk "github.com/Tnze/go-mc/net/packet"
)
func (p *Player) handleUpdateTags(packet pk.Packet) error {
r := bytes.NewReader(packet.Data)
var length pk.VarInt
_, err := length.ReadFrom(r)
if err != nil {
return Error{err}
}
var registryID pk.Identifier
for i := 0; i < int(length); i++ {
_, err = registryID.ReadFrom(r)
if err != nil {
return Error{err}
}
registry := p.c.Registries.Registry(string(registryID))
if registry == nil {
return Error{errors.New("unknown registry: " + string(registryID))}
}
_, err = registry.ReadTagsFrom(r)
if err != nil {
return Error{err}
}
}
return nil
}