/
chunkymonkey.go
54 lines (44 loc) · 1 KB
/
chunkymonkey.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
package main
import (
"os"
"path"
"flag"
"log"
"nbt"
)
// The player's starting position is loaded from level.dat for now
var StartPosition XYZ
func loadStartPosition(worldPath string) {
file, err := os.Open(path.Join(worldPath, "level.dat"), os.O_RDONLY, 0)
if err != nil {
log.Exit("loadStartPosition: ", err.String())
}
level, err := nbt.Read(file)
file.Close()
if err != nil {
log.Exit("loadStartPosition: ", err.String())
}
pos := level.Lookup("/Data/Player/Pos")
StartPosition = XYZ{
pos.(*nbt.List).Value[0].(*nbt.Double).Value,
pos.(*nbt.List).Value[1].(*nbt.Double).Value,
pos.(*nbt.List).Value[2].(*nbt.Double).Value,
}
}
func usage() {
os.Stderr.WriteString("usage: " + os.Args[0] + " <world>\n")
flag.PrintDefaults()
}
func main() {
flag.Usage = usage
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
worldPath := flag.Arg(0)
loadStartPosition(worldPath)
chunkManager := NewChunkManager(worldPath)
game := NewGame(chunkManager)
game.Serve(":25565")
}