From 70879ec312cf9d42470dca7bec5fc5390aab60df Mon Sep 17 00:00:00 2001 From: Nicholas Novak <34256932+NickyBoy89@users.noreply.github.com> Date: Thu, 16 Nov 2023 00:24:09 -0800 Subject: [PATCH] fix: Added hack to find the chunk's position from the region file it is in --- loading/load_region.go | 17 +++++++++++++++++ loading/load_save.go | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) 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, )