/
client_bound_map_item_data.go
102 lines (90 loc) · 4.01 KB
/
client_bound_map_item_data.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package packet
import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
"image/color"
)
const (
MapUpdateFlagTexture = 1 << (iota + 1)
MapUpdateFlagDecoration
MapUpdateFlagInitialisation
)
// ClientBoundMapItemData is sent by the server to the client to update the data of a map shown to the client.
// It is sent with a combination of flags that specify what data is updated.
// The ClientBoundMapItemData packet may be used to update specific parts of the map only. It is not required
// to send the entire map each time when updating one part.
type ClientBoundMapItemData struct {
// MapID is the unique identifier that represents the map that is updated over network. It remains
// consistent across sessions.
MapID int64
// UpdateFlags is a combination of flags found above that indicate what parts of the map should be updated
// client-side.
UpdateFlags uint32
// Dimension is the dimension of the map that should be updated, for example the overworld (0), the nether
// (1) or the end (2).
Dimension byte
// LockedMap specifies if the map that was updated was a locked map, which may be done using a cartography
// table.
LockedMap bool
// Origin is the center position of the map being updated.
Origin protocol.BlockPos
// Scale is the scale of the map as it is shown in-game. It is written when any of the MapUpdateFlags are
// set to the UpdateFlags field.
Scale byte
// The following fields apply only for the MapUpdateFlagInitialisation.
// MapsIncludedIn holds an array of map IDs that the map updated is included in. This has to do with the
// scale of the map: Each map holds its own map ID and all map IDs of maps that include this map and have
// a bigger scale. This means that a scale 0 map will have 5 map IDs in this slice, whereas a scale 4 map
// will have only 1 (its own).
// The actual use of this field remains unknown.
MapsIncludedIn []int64
// The following fields apply only for the MapUpdateFlagDecoration.
// TrackedObjects is a list of tracked objects on the map, which may either be entities or blocks. The
// client makes sure these tracked objects are actually tracked. (position updated etc.)
TrackedObjects []protocol.MapTrackedObject
// Decorations is a list of fixed decorations located on the map. The decorations will not change
// client-side, unless the server updates them.
Decorations []protocol.MapDecoration
// The following fields apply only for the MapUpdateFlagTexture update flag.
// Height is the height of the texture area that was updated. The height may be a subset of the total
// height of the map.
Height int32
// Width is the width of the texture area that was updated. The width may be a subset of the total width
// of the map.
Width int32
// XOffset is the X offset in pixels at which the updated texture area starts. From this X, the updated
// texture will extend exactly Width pixels to the right.
XOffset int32
// YOffset is the Y offset in pixels at which the updated texture area starts. From this Y, the updated
// texture will extend exactly Height pixels up.
YOffset int32
// Pixels is a list of pixel colours for the new texture of the map. It is indexed as Pixels[y*height + x].
Pixels []color.RGBA
}
// ID ...
func (*ClientBoundMapItemData) ID() uint32 {
return IDClientBoundMapItemData
}
func (pk *ClientBoundMapItemData) Marshal(io protocol.IO) {
io.Varint64(&pk.MapID)
io.Varuint32(&pk.UpdateFlags)
io.Uint8(&pk.Dimension)
io.Bool(&pk.LockedMap)
io.BlockPos(&pk.Origin)
if pk.UpdateFlags&MapUpdateFlagInitialisation != 0 {
protocol.FuncSlice(io, &pk.MapsIncludedIn, io.Varint64)
}
if pk.UpdateFlags&(MapUpdateFlagInitialisation|MapUpdateFlagDecoration|MapUpdateFlagTexture) != 0 {
io.Uint8(&pk.Scale)
}
if pk.UpdateFlags&MapUpdateFlagDecoration != 0 {
protocol.Slice(io, &pk.TrackedObjects)
protocol.Slice(io, &pk.Decorations)
}
if pk.UpdateFlags&MapUpdateFlagTexture != 0 {
io.Varint32(&pk.Width)
io.Varint32(&pk.Height)
io.Varint32(&pk.XOffset)
io.Varint32(&pk.YOffset)
protocol.FuncSlice(io, &pk.Pixels, io.VarRGBA)
}
}