diff --git a/loading/load_region.go b/loading/load_region.go index 5845555..96812d9 100644 --- a/loading/load_region.go +++ b/loading/load_region.go @@ -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) } } diff --git a/loading/load_save.go b/loading/load_save.go index f5e1a72..f393bf0 100644 --- a/loading/load_save.go +++ b/loading/load_save.go @@ -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, )