mca: Fix calculation of needed sector count

With a data length of 4092, 2 sectors were required instead of 1
This commit is contained in:
Dmytro Manchynskyi
2022-05-28 15:00:49 +03:00
parent 0c9ea959a7
commit 9de1f4e9b3

View File

@ -4,6 +4,7 @@ import (
"encoding/binary"
"errors"
"io"
"math"
"os"
"time"
)
@ -152,7 +153,7 @@ func (r *Region) ReadSector(x, z int) (data []byte, err error) {
// WriteSector write Chunk data into region file
func (r *Region) WriteSector(x, z int, data []byte) error {
need := int32(len(data)+4)/4096 + 1
need := int32(math.Ceil(float64(len(data)+4) / 4096))
n, now := sectorLoc(r.offsets[z][x])
// maximum chunk size is 1MB