TODO fix EOF error worldPath is the base path of the world
(worldPath string)
| 136 | // TODO fix EOF error |
| 137 | // worldPath is the base path of the world |
| 138 | func Open(worldPath string) (Level, error) { |
| 139 | var level Level |
| 140 | file, err := os.Open(worldPath + "/level.dat") |
| 141 | if err != nil { |
| 142 | return level, err |
| 143 | } |
| 144 | rd, err := gzip.NewReader(file) |
| 145 | if err != nil { |
| 146 | return level, err |
| 147 | } |
| 148 | |
| 149 | var buf, _ = io.ReadAll(rd) |
| 150 | |
| 151 | rd.Close() |
| 152 | file.Close() |
| 153 | |
| 154 | _, err = nbt.Unmarshal(buf, &level) |
| 155 | level.basePath = worldPath |
| 156 | |
| 157 | return level, err |
| 158 | } |
| 159 | |
| 160 | func Create(l Level) error { |
| 161 | file, err := os.Create(l.basePath + "/level.dat") |