Skip to content

Commit

Permalink
Add proper support for chunk modification timestamps (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsupermanhd authored Jul 12, 2023
1 parent 1547869 commit fe34dbd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions save/region/mca.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ var (
)

// Region contain 32*32 chunks in one .mca file
// Not MT-Safe!
type Region struct {
f io.ReadWriteSeeker
offsets [32][32]int32
timestamps [32][32]int32
Timestamps [32][32]int32

// sectors record if a sector is in used.
// contrary to mojang's, because false is the default value in Go.
Expand Down Expand Up @@ -70,7 +71,7 @@ func Load(f io.ReadWriteSeeker) (r *Region, err error) {
r.sectors[0] = true

// read the timestamps
err = binary.Read(r.f, binary.BigEndian, &r.timestamps)
err = binary.Read(r.f, binary.BigEndian, &r.Timestamps)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,7 +115,7 @@ func CreateWriter(f io.ReadWriteSeeker) (r *Region, err error) {
r.sectors[0] = true

// write the timestamps
err = binary.Write(r.f, binary.BigEndian, &r.timestamps)
err = binary.Write(r.f, binary.BigEndian, &r.Timestamps)
if err != nil {
_ = r.Close()
return nil, err
Expand Down Expand Up @@ -207,6 +208,7 @@ func (r *Region) WriteSector(x, z int, data []byte) error {
if err != nil {
return err
}
r.Timestamps[x][z] = int32(time.Now().Unix())
}

_, err := r.f.Seek(4096*int64(n), 0)
Expand Down

0 comments on commit fe34dbd

Please sign in to comment.