-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlevel.go
155 lines (108 loc) · 3.58 KB
/
level.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package level
/*
level
Copyright (c) 2019 beito
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/
import (
"github.com/beito123/nbt"
)
// Level is a simple level loader
type Level struct {
}
// Format is a simple interface for level formats
// This needs to be supported concurrency
type Format interface {
// Name returns name of level
Name() string
// SetName sets the name of level
SetName(name string)
// GameType returns the default game mode of level
GameType() GameType
// SetGameType sets the game mode of level
SetGameType(typ GameType)
// Spawn returns the default spawn of level
Spawn() (x, y, z int)
// SetSpawn sets the default spawn of level
SetSpawn(x, y, z int)
// Property returns a property of level.dat
Property(name string) (tag nbt.Tag, ok bool)
// SetProperty sets a property
SetProperty(tag nbt.Tag)
// AllProperties returns all properties
AllProperties() *nbt.Compound
// SetAllProperties sets all properties
SetAllProperties(com *nbt.Compound)
// Close closes the level format
// You must close after you use the format
// It's should not run other functions after format is closed
Close() error
// Dimension return dimension of the level
Dimension() Dimension
// SetDimension set dimension of the level
SetDimension(Dimension)
// LoadChunk loads a chunk.
// If create is enabled, generates a chunk if it doesn't exist
LoadChunk(x, y int, create bool) error
// UnloadChunk unloads a chunk.
UnloadChunk(x, y int) error
// GenerateChunk generates a chunk
GenerateChunk(x, y int) error
// HasGeneratedChunk returns whether the chunk is generaged
HasGeneratedChunk(x, y int) (bool, error)
// IsLoadedChunk returns weather a chunk is loaded.
IsLoadedChunk(x, y int) bool
// SaveChunk saves a chunk.
SaveChunk(x, y int) error
// SaveChunks saves all chunks.
SaveChunks() error
// Chunk returns a chunk.
// If a chunk is not loaded, it will be loaded
Chunk(x, y int) (Chunk, error)
// LoadedChunks returns loaded chunks.
LoadedChunks() []Chunk
}
// Chunk is a simple interface for chunk
type Chunk interface {
// X returns x coordinate
X() int
// Y returns y coordinate
Y() int
// SetX set x coordinate
SetX(x int)
// SetY set y coordinate
SetY(y int)
// Height returns the height of the highest block at chunk coordinate
Height(x, y int) (height uint16)
// Biome returns biome
Biome(x, y int) byte
// SetBiome set biome
SetBiome(x, y int, biome byte)
// Entities returns entities of nbt data
Entities() []*nbt.Compound
// SetEntities set entities of nbt data
SetEntities(entities []*nbt.Compound)
// BlockEntities returns block entities of nbt data
BlockEntities() []*nbt.Compound
// SetBlockEntities set block entities of nbt data
SetBlockEntities(entities []*nbt.Compound)
// GetBlock gets a BlockState at chunk coordinate
GetBlock(x, y, z int) (BlockState, error)
// SetBlock set a BlockState at chunk coordinate
SetBlock(x, y, z int, state BlockState) error
}
// BlockState is a block information
type BlockState interface { // TODO: fix bad codes :P
// Name returns block name
Name() string
// ToBlockNameProperties returns block name and properties
// If it's not supported, returns false for ok
ToBlockNameProperties() (name string, properties map[string]string, ok bool)
// ToBlockNameMeta returns block name and meta
// If it's not supported, returns false for ok
ToBlockNameMeta() (name string, meta int, ok bool)
// ToBlockIDMeta returns block id and meta
// If it's not supported, returns false for ok
ToBlockIDMeta() (id int, meta int, ok bool)
}