Move decode of complex packets into their own package

This commit is contained in:
Tom
2020-09-12 21:13:37 -07:00
parent b58d959b93
commit d3bb141fcd
7 changed files with 409 additions and 254 deletions

35
net/ptypes/motion.go Normal file
View File

@ -0,0 +1,35 @@
// Package ptypes implements encoding and decoding for high-level packets.
package ptypes
import (
pk "github.com/Tnze/go-mc/net/packet"
)
// PositionAndLookClientbound describes the location and orientation of
// the player.
type PositionAndLookClientbound struct {
X, Y, Z pk.Double
Yaw, Pitch pk.Float
Flags pk.Byte
TeleportID pk.VarInt
}
func (p *PositionAndLookClientbound) RelativeX() bool {
return p.Flags&0x01 != 0
}
func (p *PositionAndLookClientbound) RelativeY() bool {
return p.Flags&0x02 != 0
}
func (p *PositionAndLookClientbound) RelativeZ() bool {
return p.Flags&0x04 != 0
}
func (p *PositionAndLookClientbound) RelativeYaw() bool {
return p.Flags&0x08 != 0
}
func (p *PositionAndLookClientbound) RelativePitch() bool {
return p.Flags&0x10 != 0
}
func (p *PositionAndLookClientbound) Decode(pkt pk.Packet) error {
return pkt.Scan(&p.X, &p.Y, &p.Z, &p.Yaw, &p.Pitch, &p.Flags, &p.TeleportID)
}