Add generic event

This commit is contained in:
Tnze
2021-02-27 14:49:11 +08:00
parent 3b83aaf8ae
commit 8e7ac43bf5
10 changed files with 316 additions and 195 deletions

View File

@ -12,6 +12,7 @@ type Player struct {
PlayerInfo
WorldInfo
isSpawn bool
}
func NewPlayer(c *bot.Client, settings Settings) *Player {
@ -19,14 +20,33 @@ func NewPlayer(c *bot.Client, settings Settings) *Player {
c.Events.AddListener(
bot.PacketHandler{Priority: 0, ID: packetid.Login, F: b.handleJoinGamePacket},
bot.PacketHandler{Priority: 0, ID: packetid.KeepAliveClientbound, F: b.handleKeepAlivePacket},
bot.PacketHandler{Priority: 0, ID: packetid.PositionClientbound, F: b.handlePlayerPositionAndLook},
)
return b
}
func (p *Player) Respawn() error {
const PerformRespawn = 0
return p.c.Conn.WritePacket(pk.Marshal(
err := p.c.Conn.WritePacket(pk.Marshal(
packetid.ClientCommand,
pk.VarInt(PerformRespawn),
))
if err != nil {
return Error{err}
}
return nil
}
type Error struct {
Err error
}
func (e Error) Error() string {
return "bot/basic: " + e.Err.Error()
}
func (e Error) Unwrap() error {
return e.Err
}