-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprocess_remove_unprotected.go
94 lines (78 loc) · 1.87 KB
/
process_remove_unprotected.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"time"
"github.com/sirupsen/logrus"
)
func ProcessRemoveUnprotected() error {
logrus.Info("pruning unprotected chunks from the database")
err := LoadProtectedNodes()
if err != nil {
return fmt.Errorf("can't load 'mapcleaner_protect.txt' because of '%v' (i'm refusing to work without that file!)", err)
}
err = LoadState()
if err != nil {
return err
}
for {
if state.ChunkX > state.ToX {
// move to next z stride
state.ChunkX = state.FromX
state.ChunkZ++
logrus.WithFields(logrus.Fields{
"chunk_y": state.ChunkY,
"chunk_z": state.ChunkZ,
}).Info("Processing next z-stride")
err := SaveState()
if err != nil {
return err
}
}
if state.ChunkZ > state.ToZ {
// move to next y stride
state.ChunkX = state.FromX
state.ChunkY++
state.ChunkZ = state.FromZ
logrus.WithFields(logrus.Fields{
"chunk_y": state.ChunkY,
}).Info("Processing next y-layer")
}
if state.ChunkY > state.ToY {
// done
return SaveState()
}
logrus.WithFields(logrus.Fields{
"chunk_x": state.ChunkX,
"chunk_y": state.ChunkY,
"chunk_z": state.ChunkZ,
}).Debug("Processing")
emerged, err := IsEmerged(state.ChunkX, state.ChunkY, state.ChunkZ)
if err != nil {
return err
}
if emerged {
protected, err := IsProtectedWithNeighbors(state.ChunkX, state.ChunkY, state.ChunkZ)
if err != nil {
return err
}
if !protected {
logrus.WithFields(logrus.Fields{
"chunk_x": state.ChunkX,
"chunk_y": state.ChunkY,
"chunk_z": state.ChunkZ,
}).Info("Removing chunk")
err = RemoveChunk(state.ChunkX, state.ChunkY, state.ChunkZ)
if err != nil {
return err
}
state.RemovedChunks++
} else {
state.RetainedChunks++
}
}
state.ProcessedChunks++
// shift to next chunk
state.ChunkX++
time.Sleep(time.Millisecond * time.Duration(state.Delay))
}
}