Skip to content

Commit

Permalink
packet/camera_instruction.go: Only marshal a single instruction inste…
Browse files Browse the repository at this point in the history
…ad of a slice
  • Loading branch information
TwistedAsylumMC committed Oct 25, 2023
1 parent f5d13fd commit cb0334f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
17 changes: 0 additions & 17 deletions minecraft/protocol/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,6 @@ func (x *CameraEase) Marshal(r IO) {
r.Float32(&x.Duration)
}

// CameraInstruction represents an instruction that can be one of three different operations.
type CameraInstruction struct {
// Set is a camera instruction that sets the camera to a specified preset.
Set Optional[CameraInstructionSet]
// Clear can be set to true to clear all the current camera instructions.
Clear Optional[bool]
// Fade is a camera instruction that fades the screen to a specified colour.
Fade Optional[CameraInstructionFade]
}

// Marshal encodes/decodes a CameraInstruction.
func (x *CameraInstruction) Marshal(r IO) {
OptionalMarshaler(r, &x.Set)
OptionalFunc(r, &x.Clear, r.Bool)
OptionalMarshaler(r, &x.Fade)
}

// CameraInstructionSet represents a camera instruction that sets the camera to a specified preset and can be extended
// with easing functions and translations to the camera's position and rotation.
type CameraInstructionSet struct {
Expand Down
12 changes: 9 additions & 3 deletions minecraft/protocol/packet/camera_instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import (

// CameraInstruction gives a custom camera specific instructions to operate.
type CameraInstruction struct {
// Instructions is a list of the instructions that should be executed by the camera.
Instructions []protocol.CameraInstruction
// Set is a camera instruction that sets the camera to a specified preset.
Set protocol.Optional[protocol.CameraInstructionSet]
// Clear can be set to true to clear all the current camera instructions.
Clear protocol.Optional[bool]
// Fade is a camera instruction that fades the screen to a specified colour.
Fade protocol.Optional[protocol.CameraInstructionFade]
}

// ID ...
Expand All @@ -16,5 +20,7 @@ func (*CameraInstruction) ID() uint32 {
}

func (pk *CameraInstruction) Marshal(io protocol.IO) {
protocol.Slice(io, &pk.Instructions)
protocol.OptionalMarshaler(io, &pk.Set)
protocol.OptionalFunc(io, &pk.Clear, io.Bool)
protocol.OptionalMarshaler(io, &pk.Fade)
}

0 comments on commit cb0334f

Please sign in to comment.