Skip to content

Commit

Permalink
fix: export surounding chunks of protected nodes.
Browse files Browse the repository at this point in the history
Avoid losing data when protected nodes
are at the mapblock/mapchunk edges.
  • Loading branch information
ronoaldo committed Dec 2, 2023
1 parent 702dede commit c49a4e7
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions process_export_protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,41 @@ func ProccessExportAllProtected() error {
}

if protected {
x, y, z := GetChunkPosFromMapblock(b.PosX, b.PosY, b.PosZ)
key := GetChunkKey(x, y, z)
if exported_chunks[key] {
D("chunk already exported, skipping", f{"key": key})
continue
}

logrus.WithFields(logrus.Fields{"x": x, "y": y, "z": z}).Info("exporting chunk")
err = ExportChunk(block_repo, export_db, x, y, z)
if err != nil {
return fmt.Errorf("export error in chunk %d/%d/%d: %v", x, y, z, err)
chunkx, chunky, chunkz := GetChunkPosFromMapblock(b.PosX, b.PosY, b.PosZ)

// Export surounding chunks as protected elements can be inside a construction that is
// at the edge of a mapblock/mapchunk.
for x := chunkx - 1; x <= chunkx+1; x++ {
for y := chunky - 1; y <= chunky+1; y++ {
for z := chunkz - 1; x <= chunkz+1; z++ {
key := GetChunkKey(x, y, z)
if exported_chunks[key] {
D("chunk already exported, skipping", f{"key": key})
continue
}

I("exporting chunk", f{"x": x, "y": y, "z": z})
err = ExportChunk(block_repo, export_db, x, y, z)
if err != nil {
return fmt.Errorf("export error in chunk %d/%d/%d: %v", x, y, z, err)
}

// mark as exported
exported_chunks[key] = true
chunk_count++
}
}
}

// mark as exported
exported_chunks[key] = true
chunk_count++
}

// Report progress every 100 blocks
if block_count%1000 == 0 {
progress := 100 * float64(block_count) / float64(total_blocks)
stats := f{
"exported_chunks": chunk_count,
"proc_blocks": block_count,
"progress": fmt.Sprintf("%.02f%%", progress),
"elapsed": time.Since(start).String(),
"expo_chunks": chunk_count,
"proc_blocks": block_count,
"progress": fmt.Sprintf("%.02f%%", progress),
"elapsed": time.Since(start).String(),
}
I("processing blocks", stats)
}
Expand Down

0 comments on commit c49a4e7

Please sign in to comment.