fix: Added hack to find the chunk's position from the region file it is in
This commit is contained in:
parent
4fd4b6112f
commit
70879ec312
@ -1,6 +1,9 @@
|
||||
package loading
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||
"github.com/Tnze/go-mc/save"
|
||||
"github.com/Tnze/go-mc/save/region"
|
||||
@ -16,6 +19,17 @@ func LoadRegionFile(fileName string) ([]world.ChunkData, error) {
|
||||
}
|
||||
defer regionFile.Close()
|
||||
|
||||
// Parse the name of the region to find its position within the world
|
||||
nameParts := strings.Split(fileName, ".")
|
||||
regionX, err := strconv.Atoi(nameParts[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
regionY, err := strconv.Atoi(nameParts[2])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// A region file is a 32x32 grid of chunks
|
||||
chunks := []world.ChunkData{}
|
||||
|
||||
@ -37,6 +51,9 @@ func LoadRegionFile(fileName string) ([]world.ChunkData, error) {
|
||||
var chunkData world.ChunkData
|
||||
chunkData.FromMCAChunk(chunk)
|
||||
|
||||
chunkData.Pos.X = regionX*32 + i
|
||||
chunkData.Pos.Z = regionY*32 + j
|
||||
|
||||
chunks = append(chunks, chunkData)
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,10 @@ var LoadSaveDirCommand = &cobra.Command{
|
||||
|
||||
// Save each chunk to a separate file
|
||||
for _, chunk := range chunks {
|
||||
chunkFilename := chunk.Pos.ToFileName()
|
||||
|
||||
outfile, err := os.OpenFile(
|
||||
filepath.Join(saveOutputDir, chunk.Pos.ToFileName()),
|
||||
filepath.Join(saveOutputDir, chunkFilename),
|
||||
os.O_WRONLY|os.O_CREATE|os.O_APPEND,
|
||||
0664,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user