Skip to content

Commit

Permalink
packet/packet.go: Eradicated separate Marshal and Unmarshal methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Mar 23, 2023
1 parent 3492077 commit f53c54a
Show file tree
Hide file tree
Showing 196 changed files with 931 additions and 2,858 deletions.
2 changes: 1 addition & 1 deletion minecraft/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p *packetData) decode(conn *Conn) (pks []packet.Packet, err error) {
err = fmt.Errorf("%T: %w", pk, recoveredErr.(error))
}
}()
pk.Unmarshal(r)
pk.Marshal(r)
if p.payload.Len() != 0 {
err = fmt.Errorf("%T: %v unread bytes left: 0x%x", pk, p.payload.Len(), p.payload.Bytes())
}
Expand Down
18 changes: 4 additions & 14 deletions minecraft/protocol/packet/actor_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,8 @@ func (*ActorEvent) ID() uint32 {
return IDActorEvent
}

// Marshal ...
func (pk *ActorEvent) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *ActorEvent) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *ActorEvent) marshal(r protocol.IO) {
r.Varuint64(&pk.EntityRuntimeID)
r.Uint8(&pk.EventType)
r.Varint32(&pk.EventData)
func (pk *ActorEvent) Marshal(io protocol.IO) {
io.Varuint64(&pk.EntityRuntimeID)
io.Uint8(&pk.EventType)
io.Varint32(&pk.EventData)
}
18 changes: 4 additions & 14 deletions minecraft/protocol/packet/actor_pick_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,8 @@ func (*ActorPickRequest) ID() uint32 {
return IDActorPickRequest
}

// Marshal ...
func (pk *ActorPickRequest) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *ActorPickRequest) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *ActorPickRequest) marshal(r protocol.IO) {
r.Int64(&pk.EntityUniqueID)
r.Uint8(&pk.HotBarSlot)
r.Bool(&pk.WithData)
func (pk *ActorPickRequest) Marshal(io protocol.IO) {
io.Int64(&pk.EntityUniqueID)
io.Uint8(&pk.HotBarSlot)
io.Bool(&pk.WithData)
}
38 changes: 14 additions & 24 deletions minecraft/protocol/packet/add_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,18 @@ func (*AddActor) ID() uint32 {
return IDAddActor
}

// Marshal ...
func (pk *AddActor) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddActor) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddActor) marshal(r protocol.IO) {
r.Varint64(&pk.EntityUniqueID)
r.Varuint64(&pk.EntityRuntimeID)
r.String(&pk.EntityType)
r.Vec3(&pk.Position)
r.Vec3(&pk.Velocity)
r.Float32(&pk.Pitch)
r.Float32(&pk.Yaw)
r.Float32(&pk.HeadYaw)
r.Float32(&pk.BodyYaw)
protocol.Slice(r, &pk.Attributes)
r.EntityMetadata(&pk.EntityMetadata)
protocol.Single(r, &pk.EntityProperties)
protocol.Slice(r, &pk.EntityLinks)
func (pk *AddActor) Marshal(io protocol.IO) {
io.Varint64(&pk.EntityUniqueID)
io.Varuint64(&pk.EntityRuntimeID)
io.String(&pk.EntityType)
io.Vec3(&pk.Position)
io.Vec3(&pk.Velocity)
io.Float32(&pk.Pitch)
io.Float32(&pk.Yaw)
io.Float32(&pk.HeadYaw)
io.Float32(&pk.BodyYaw)
protocol.Slice(io, &pk.Attributes)
io.EntityMetadata(&pk.EntityMetadata)
protocol.Single(io, &pk.EntityProperties)
protocol.Slice(io, &pk.EntityLinks)
}
14 changes: 2 additions & 12 deletions minecraft/protocol/packet/add_behaviour_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ func (*AddBehaviourTree) ID() uint32 {
return IDAddBehaviourTree
}

// Marshal ...
func (pk *AddBehaviourTree) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddBehaviourTree) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddBehaviourTree) marshal(r protocol.IO) {
r.String(&pk.BehaviourTree)
func (pk *AddBehaviourTree) Marshal(io protocol.IO) {
io.String(&pk.BehaviourTree)
}
14 changes: 2 additions & 12 deletions minecraft/protocol/packet/add_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ func (pk *AddEntity) ID() uint32 {
return IDAddEntity
}

// Marshal ...
func (pk *AddEntity) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddEntity) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddEntity) marshal(r protocol.IO) {
r.Varuint64(&pk.EntityNetworkID)
func (pk *AddEntity) Marshal(io protocol.IO) {
io.Varuint64(&pk.EntityNetworkID)
}
26 changes: 8 additions & 18 deletions minecraft/protocol/packet/add_item_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,12 @@ func (*AddItemActor) ID() uint32 {
return IDAddItemActor
}

// Marshal ...
func (pk *AddItemActor) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddItemActor) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddItemActor) marshal(r protocol.IO) {
r.Varint64(&pk.EntityUniqueID)
r.Varuint64(&pk.EntityRuntimeID)
r.ItemInstance(&pk.Item)
r.Vec3(&pk.Position)
r.Vec3(&pk.Velocity)
r.EntityMetadata(&pk.EntityMetadata)
r.Bool(&pk.FromFishing)
func (pk *AddItemActor) Marshal(io protocol.IO) {
io.Varint64(&pk.EntityUniqueID)
io.Varuint64(&pk.EntityRuntimeID)
io.ItemInstance(&pk.Item)
io.Vec3(&pk.Position)
io.Vec3(&pk.Velocity)
io.EntityMetadata(&pk.EntityMetadata)
io.Bool(&pk.FromFishing)
}
22 changes: 6 additions & 16 deletions minecraft/protocol/packet/add_painting.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,10 @@ func (*AddPainting) ID() uint32 {
return IDAddPainting
}

// Marshal ...
func (pk *AddPainting) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddPainting) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddPainting) marshal(r protocol.IO) {
r.Varint64(&pk.EntityUniqueID)
r.Varuint64(&pk.EntityRuntimeID)
r.Vec3(&pk.Position)
r.Varint32(&pk.Direction)
r.String(&pk.Title)
func (pk *AddPainting) Marshal(io protocol.IO) {
io.Varint64(&pk.EntityUniqueID)
io.Varuint64(&pk.EntityRuntimeID)
io.Vec3(&pk.Position)
io.Varint32(&pk.Direction)
io.String(&pk.Title)
}
46 changes: 18 additions & 28 deletions minecraft/protocol/packet/add_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,22 @@ func (*AddPlayer) ID() uint32 {
return IDAddPlayer
}

// Marshal ...
func (pk *AddPlayer) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddPlayer) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddPlayer) marshal(r protocol.IO) {
r.UUID(&pk.UUID)
r.String(&pk.Username)
r.Varuint64(&pk.EntityRuntimeID)
r.String(&pk.PlatformChatID)
r.Vec3(&pk.Position)
r.Vec3(&pk.Velocity)
r.Float32(&pk.Pitch)
r.Float32(&pk.Yaw)
r.Float32(&pk.HeadYaw)
r.ItemInstance(&pk.HeldItem)
r.Varint32(&pk.GameType)
r.EntityMetadata(&pk.EntityMetadata)
protocol.Single(r, &pk.EntityProperties)
protocol.Single(r, &pk.AbilityData)
protocol.Slice(r, &pk.EntityLinks)
r.String(&pk.DeviceID)
r.Int32(&pk.BuildPlatform)
func (pk *AddPlayer) Marshal(io protocol.IO) {
io.UUID(&pk.UUID)
io.String(&pk.Username)
io.Varuint64(&pk.EntityRuntimeID)
io.String(&pk.PlatformChatID)
io.Vec3(&pk.Position)
io.Vec3(&pk.Velocity)
io.Float32(&pk.Pitch)
io.Float32(&pk.Yaw)
io.Float32(&pk.HeadYaw)
io.ItemInstance(&pk.HeldItem)
io.Varint32(&pk.GameType)
io.EntityMetadata(&pk.EntityMetadata)
protocol.Single(io, &pk.EntityProperties)
protocol.Single(io, &pk.AbilityData)
protocol.Slice(io, &pk.EntityLinks)
io.String(&pk.DeviceID)
io.Int32(&pk.BuildPlatform)
}
28 changes: 9 additions & 19 deletions minecraft/protocol/packet/add_volume_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,13 @@ func (*AddVolumeEntity) ID() uint32 {
return IDAddVolumeEntity
}

// Marshal ...
func (pk *AddVolumeEntity) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AddVolumeEntity) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AddVolumeEntity) marshal(r protocol.IO) {
r.Uint64(&pk.EntityRuntimeID)
r.NBT(&pk.EntityMetadata, nbt.NetworkLittleEndian)
r.String(&pk.EncodingIdentifier)
r.String(&pk.InstanceIdentifier)
r.UBlockPos(&pk.Bounds[0])
r.UBlockPos(&pk.Bounds[1])
r.Varint32(&pk.Dimension)
r.String(&pk.EngineVersion)
func (pk *AddVolumeEntity) Marshal(io protocol.IO) {
io.Uint64(&pk.EntityRuntimeID)
io.NBT(&pk.EntityMetadata, nbt.NetworkLittleEndian)
io.String(&pk.EncodingIdentifier)
io.String(&pk.InstanceIdentifier)
io.UBlockPos(&pk.Bounds[0])
io.UBlockPos(&pk.Bounds[1])
io.Varint32(&pk.Dimension)
io.String(&pk.EngineVersion)
}
24 changes: 7 additions & 17 deletions minecraft/protocol/packet/adventure_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,11 @@ func (*AdventureSettings) ID() uint32 {
return IDAdventureSettings
}

// Marshal ...
func (pk *AdventureSettings) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AdventureSettings) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AdventureSettings) marshal(r protocol.IO) {
r.Varuint32(&pk.Flags)
r.Varuint32(&pk.CommandPermissionLevel)
r.Varuint32(&pk.ActionPermissions)
r.Varuint32(&pk.PermissionLevel)
r.Varuint32(&pk.CustomStoredPermissions)
r.Int64(&pk.PlayerUniqueID)
func (pk *AdventureSettings) Marshal(io protocol.IO) {
io.Varuint32(&pk.Flags)
io.Varuint32(&pk.CommandPermissionLevel)
io.Varuint32(&pk.ActionPermissions)
io.Varuint32(&pk.PermissionLevel)
io.Varuint32(&pk.CustomStoredPermissions)
io.Int64(&pk.PlayerUniqueID)
}
18 changes: 4 additions & 14 deletions minecraft/protocol/packet/agent_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,8 @@ func (*AgentAction) ID() uint32 {
return IDAgentAction
}

// Marshal ...
func (pk *AgentAction) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AgentAction) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AgentAction) marshal(r protocol.IO) {
r.String(&pk.Identifier)
r.Varint32(&pk.Action)
r.ByteSlice(&pk.Response)
func (pk *AgentAction) Marshal(io protocol.IO) {
io.String(&pk.Identifier)
io.Varint32(&pk.Action)
io.ByteSlice(&pk.Response)
}
18 changes: 4 additions & 14 deletions minecraft/protocol/packet/animate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,10 @@ func (*Animate) ID() uint32 {
return IDAnimate
}

// Marshal ...
func (pk *Animate) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *Animate) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *Animate) marshal(r protocol.IO) {
r.Varint32(&pk.ActionType)
r.Varuint64(&pk.EntityRuntimeID)
func (pk *Animate) Marshal(io protocol.IO) {
io.Varint32(&pk.ActionType)
io.Varuint64(&pk.EntityRuntimeID)
if pk.ActionType&0x80 != 0 {
r.Float32(&pk.BoatRowingTime)
io.Float32(&pk.BoatRowingTime)
}
}
26 changes: 8 additions & 18 deletions minecraft/protocol/packet/animate_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,12 @@ func (*AnimateEntity) ID() uint32 {
return IDAnimateEntity
}

// Marshal ...
func (pk *AnimateEntity) Marshal(w *protocol.Writer) {
pk.marshal(w)
}

// Unmarshal ...
func (pk *AnimateEntity) Unmarshal(r *protocol.Reader) {
pk.marshal(r)
}

func (pk *AnimateEntity) marshal(r protocol.IO) {
r.String(&pk.Animation)
r.String(&pk.NextState)
r.String(&pk.StopCondition)
r.Int32(&pk.StopConditionVersion)
r.String(&pk.Controller)
r.Float32(&pk.BlendOutTime)
protocol.FuncSlice(r, &pk.EntityRuntimeIDs, r.Varuint64)
func (pk *AnimateEntity) Marshal(io protocol.IO) {
io.String(&pk.Animation)
io.String(&pk.NextState)
io.String(&pk.StopCondition)
io.Int32(&pk.StopConditionVersion)
io.String(&pk.Controller)
io.Float32(&pk.BlendOutTime)
protocol.FuncSlice(io, &pk.EntityRuntimeIDs, io.Varuint64)
}

0 comments on commit f53c54a

Please sign in to comment.