/
sub_chunk.go
76 lines (67 loc) · 2.07 KB
/
sub_chunk.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
package protocol
import "math"
const (
HeightMapDataNone = iota
HeightMapDataHasData
HeightMapDataTooHigh
HeightMapDataTooLow
)
const (
SubChunkRequestModeLimitless = math.MaxUint32 - iota
SubChunkRequestModeLimited
)
const (
SubChunkResultSuccess = iota + 1
SubChunkResultChunkNotFound
SubChunkResultInvalidDimension
SubChunkResultPlayerNotFound
SubChunkResultIndexOutOfBounds
SubChunkResultSuccessAllAir
)
// SubChunkEntry contains the data of a sub-chunk entry relative to a center sub chunk position, used for the sub-chunk
// requesting system introduced in v1.18.10.
type SubChunkEntry struct {
// Offset contains the offset between the sub-chunk position and the center position.
Offset SubChunkOffset
// Result is always one of the constants defined in the SubChunkResult constants.
Result byte
// RawPayload contains the serialized sub-chunk data.
RawPayload []byte
// HeightMapType is always one of the constants defined in the HeightMapData constants.
HeightMapType byte
// HeightMapData is the data for the height map.
HeightMapData []int8
// BlobHash is the hash of the blob.
BlobHash uint64
}
// Marshal encodes/decodes a SubChunkEntry assuming the blob cache is enabled.
func (x *SubChunkEntry) Marshal(r IO) {
Single(r, &x.Offset)
r.Uint8(&x.Result)
if x.Result != SubChunkResultSuccessAllAir {
r.ByteSlice(&x.RawPayload)
}
r.Uint8(&x.HeightMapType)
if x.HeightMapType == HeightMapDataHasData {
FuncSliceOfLen(r, 256, &x.HeightMapData, r.Int8)
}
r.Uint64(&x.BlobHash)
}
// SubChunkEntryNoCache encodes/decodes a SubChunkEntry assuming the blob cache is not enabled.
func SubChunkEntryNoCache(r IO, x *SubChunkEntry) {
Single(r, &x.Offset)
r.Uint8(&x.Result)
r.ByteSlice(&x.RawPayload)
r.Uint8(&x.HeightMapType)
if x.HeightMapType == HeightMapDataHasData {
FuncSliceOfLen(r, 256, &x.HeightMapData, r.Int8)
}
}
// SubChunkOffset represents an offset from the base position of another sub chunk.
type SubChunkOffset [3]int8
// Marshal encodes/decodes a SubChunkOffset.
func (x *SubChunkOffset) Marshal(r IO) {
r.Int8(&x[0])
r.Int8(&x[1])
r.Int8(&x[2])
}