-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
141 lines (124 loc) · 2.65 KB
/
test.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
package main
import (
"fmt"
"math"
"os"
"strconv"
"github.com/crystalmine/levels/anvil"
"github.com/crystalmine/levels/bedrock"
"github.com/crystalmine/levels/convert"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
// zerolog.SetGlobalLevel(zerolog.InfoLevel)
// printmap()
// conv()
// return
if true {
if true {
if err := convert.PC2PE("maps/anvil-kathal", "maps/mcpe-conv"); err != nil {
panic(err)
}
} else {
cp := bedrock.Scan("maps/mcpe-conv/db")
draw(cp)
// bedrock.Scan("maps/mcpe-simple/db")
// bedrock.ReadNbtFile("maps/mcpe-simple/level.dat")
}
} else {
// anvil.Scan("maps/anvil-kathal")
l, err := anvil.LoadLevel("maps/anvil-kathal")
if err != nil {
panic(err)
}
_ = l
// pretty.Println(l)
r, err := l.LoadRegion(l.Regions[0])
if err != nil {
panic(err)
}
_ = r
// pretty.Println(r)
}
}
func conv() {
pe, err := bedrock.LoadLevel("maps/mcpe-conv")
if err != nil {
panic(err)
}
db, err := pe.OpenDB()
if err != nil {
panic(err)
}
defer func() {
err := db.Close()
if err != nil {
panic(err)
}
}()
for x := 0; x < 10; x++ {
for z := 0; z < 10; z++ {
if (x+z)&1 == 1 {
if err := convert.FillChunk(db, bedrock.ChunkPos{x, z}); err != nil {
panic(err)
}
}
}
}
}
func printmap() {
l, err := anvil.LoadLevel("maps/anvil-kathal")
if err != nil {
panic(err)
}
cp := make(map[anvil.ChunkPos]int)
for _, ri := range l.Regions {
r, err := l.LoadRegion(ri)
if err != nil {
panic(err)
}
log.Info().Interface("pos", r.RegionPos).Msgf("region loaded")
for pos, c := range r.Chunks {
cp[pos] = len(c.Data.Sections)
}
}
draw(cp)
}
func draw(cp map[anvil.ChunkPos]int) {
var minx, minz = math.MaxInt32, math.MaxInt32
var maxx, maxz = math.MinInt32, math.MinInt32
for pos := range cp {
if minx > pos.X {
minx = pos.X
}
if minz > pos.Z {
minz = pos.Z
}
if maxx < pos.X {
maxx = pos.X
}
if maxz < pos.Z {
maxz = pos.Z
}
}
log.Info().Int("minx", minx).Int("minz", minz).Msg("minimum")
log.Info().Int("maxx", maxx).Int("maxz", maxz).Msg("maximum")
dx, dz := maxx-minx+1, maxz-minz+1
p := make([]int, dx*dz)
for pos, v := range cp {
p[(pos.X-minx)*dz+(pos.Z-minz)] = v
}
for x := 0; x < dx; x++ {
fmt.Printf("%3d ", x+minx)
for z := 0; z < dz; z++ {
if p[x*dz+z] == 0 {
fmt.Print(".")
} else {
fmt.Print(strconv.FormatInt(int64(p[x*dz+z]-1), 16))
}
}
fmt.Println()
}
}