/
change_dimension.go
54 lines (48 loc) · 1.86 KB
/
change_dimension.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package packet
import (
"bytes"
"encoding/binary"
"github.com/go-gl/mathgl/mgl32"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
const (
DimensionOverworld = iota
DimensionNether
DimensionEnd
)
// ChangeDimension is sent by the server to the client to send a dimension change screen client-side. Once the
// screen is cleared client-side, the client will send a PlayerAction packet with
// PlayerActionDimensionChangeDone.
type ChangeDimension struct {
// Dimension is the dimension that the client should be changed to. The fog colour will change depending
// on the type of dimension, which is one of the constants above.
// Note that Dimension MUST be a different dimension than the one that the player is currently in. Sending
// a ChangeDimension packet with a Dimension that the player is currently in will result in a never-ending
// dimension change screen.
Dimension int32
// Position is the position in the new dimension that the player is spawned in.
Position mgl32.Vec3
// Respawn specifies if the dimension change was respawn based, meaning that the player died in one
// dimension and got respawned into another. The client will send a PlayerAction packet with
// PlayerActionDimensionChangeRequest if it dies in another dimension, indicating that it needs a
// DimensionChange packet with Respawn set to true.
Respawn bool
}
// ID ...
func (*ChangeDimension) ID() uint32 {
return IDChangeDimension
}
// Marshal ...
func (pk *ChangeDimension) Marshal(buf *bytes.Buffer) {
_ = protocol.WriteVarint32(buf, pk.Dimension)
_ = protocol.WriteVec3(buf, pk.Position)
_ = binary.Write(buf, binary.LittleEndian, pk.Respawn)
}
// Unmarshal ...
func (pk *ChangeDimension) Unmarshal(buf *bytes.Buffer) error {
return chainErr(
protocol.Varint32(buf, &pk.Dimension),
protocol.Vec3(buf, &pk.Position),
binary.Read(buf, binary.LittleEndian, &pk.Respawn),
)
}