-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolar.go
84 lines (63 loc) · 1.56 KB
/
polar.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
package polar
import "fmt"
const MagicNumber = 0x506F6C72 // `Polr`
const LatestVersion int16 = 3
type Compression int8
const (
CompressionNone Compression = iota
CompressionZstd
)
type World struct {
Version int16
Compression Compression
MinSection int8
MaxSection int8
chunks map[ChunkIndex]*Chunk
}
func (w *World) SectionCount() int {
return int(w.MaxSection - w.MinSection + 1)
}
func (w *World) GetChunk(x, z int) *Chunk {
if w.chunks == nil {
return nil
}
idx := ChunkIndexFromXZ(x, z)
return w.chunks[idx]
}
func (w *World) SetChunk(chunk *Chunk) {
if w.chunks == nil {
w.chunks = make(map[ChunkIndex]*Chunk)
}
idx := ChunkIndexFromXZ(int(chunk.X), int(chunk.Z))
if _, ok := w.chunks[idx]; ok {
panic(fmt.Sprintf("chunk %d, %d already exists", chunk.X, chunk.Z))
}
w.chunks[idx] = chunk
}
type Chunk struct {
X int32
Z int32
Sections []*Section
BlockEntities []*BlockEntity
//todo heightmaps
//todo user data
}
type Section struct {
BlockPalette []string
BlockStates []uint64
BiomePalette []string
BiomeStates []uint64
BlockLight []byte // 2048 bytes, or nil
SkyLight []byte // 2048 bytes, or nil
}
func (s *Section) IsEmpty() bool {
return len(s.BlockPalette) == 0 && len(s.BlockStates) == 0 && s.BlockLight == nil && s.SkyLight == nil
}
type BlockEntity struct {
ChunkPos int32
ID string // Can be empty string if missing
Data map[string]interface{} // NBT data, or nil if not present. todo type here
}
func (b *BlockEntity) Pos() (int, int, int) {
return ChunkPosToXYZ(b.ChunkPos)
}