-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk.go
48 lines (41 loc) · 887 Bytes
/
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
package main
// Big credits to https://github.com/Tnze/go-mc/blob/fe34dbd8bb6a93e3c9dfd33670fd7bc350915860/save/chunk.go and hub for fixing it
import (
"bytes"
"compress/gzip"
"compress/zlib"
"errors"
"io"
"github.com/Tnze/go-mc/nbt"
)
type Chunk struct {
Level struct {
InhabitedTime int64
XPos int32 `nbt:"xPos"`
ZPos int32 `nbt:"zPos"`
}
InhabitedTime int64
XPos int32 `nbt:"xPos"`
ZPos int32 `nbt:"zPos"`
}
func (c *Chunk) Load(data []byte) (err error) {
var reader io.Reader = bytes.NewReader(data[1:])
switch data[0] {
case 1:
reader, err = gzip.NewReader(reader)
case 2:
reader, err = zlib.NewReader(reader)
case 3:
// no compression
default:
err = errors.New("unknown compression")
}
if err != nil {
return err
}
_, err = nbt.NewDecoder(reader).Decode(&c)
if err != nil {
return err
}
return
}