add player package with key client-side player functionality, update protocol codecs, and refactor metadata definitions and slot usage
This commit is contained in:
24
pkg/bot/handler.go
Normal file
24
pkg/bot/handler.go
Normal file
@ -0,0 +1,24 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.konjactw.dev/patyhank/minego/pkg/protocol/packet/game/client"
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
)
|
||||
|
||||
type PacketHandler interface {
|
||||
AddPacketHandler(id packetid.ClientboundPacketID, handler func(ctx context.Context, p client.ClientboundPacket))
|
||||
AddGenericPacketHandler(handler func(ctx context.Context, p client.ClientboundPacket))
|
||||
HandlePacket(ctx context.Context, p client.ClientboundPacket)
|
||||
}
|
||||
|
||||
type HandlerFunc[T client.ClientboundPacket] func(ctx context.Context, p T)
|
||||
|
||||
func AddHandler[T client.ClientboundPacket](c Client, f HandlerFunc[T]) {
|
||||
var t T
|
||||
handler := c.PacketHandler()
|
||||
handler.AddPacketHandler(t.PacketID(), func(ctx context.Context, p client.ClientboundPacket) {
|
||||
f(ctx, p.(T))
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user