fixup codes

This commit is contained in:
2025-08-26 12:06:00 +08:00
committed by 蒟蒻
parent 093fdaaecf
commit 9ae126c648
252 changed files with 627 additions and 369 deletions

View File

@ -3,20 +3,23 @@ package client
import (
"context"
"git.konjactw.dev/patyhank/minego/pkg/bot"
"git.konjactw.dev/falloutBot/go-mc/data/packetid"
pk "git.konjactw.dev/falloutBot/go-mc/net/packet"
"git.konjactw.dev/patyhank/minego/pkg/protocol/packet/game/client"
"github.com/Tnze/go-mc/data/packetid"
)
func newPacketHandler() bot.PacketHandler {
func newPacketHandler() *packetHandler {
return &packetHandler{
handlerMap: make(map[packetid.ClientboundPacketID][]func(ctx context.Context, p client.ClientboundPacket)),
rawMap: make(map[packetid.ClientboundPacketID][]func(ctx context.Context, p pk.Packet)),
}
}
type packetHandler struct {
handlerMap map[packetid.ClientboundPacketID][]func(ctx context.Context, p client.ClientboundPacket)
genericMap []func(ctx context.Context, p client.ClientboundPacket)
rawMap map[packetid.ClientboundPacketID][]func(ctx context.Context, p pk.Packet)
}
func (ph *packetHandler) AddPacketHandler(id packetid.ClientboundPacketID, handler func(ctx context.Context, p client.ClientboundPacket)) {
@ -29,13 +32,16 @@ func (ph *packetHandler) AddGenericPacketHandler(handler func(ctx context.Contex
ph.genericMap = append(ph.genericMap, handler)
}
func (ph *packetHandler) AddRawPacketHandler(id packetid.ClientboundPacketID, handler func(ctx context.Context, p pk.Packet)) {
ph.rawMap[id] = append(ph.rawMap[id], handler)
}
func (ph *packetHandler) HandlePacket(ctx context.Context, p client.ClientboundPacket) {
f := ph.handlerMap[p.PacketID()]
if f != nil {
for _, handler := range f {
handler(ctx, p)
}
for _, handler := range f {
handler(ctx, p)
}
for _, handler := range ph.genericMap {
handler(ctx, p)
}