-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockScannerExpanding.java
74 lines (58 loc) · 1.45 KB
/
BlockScannerExpanding.java
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
package buildcraft.core.lib.utils;
import java.util.Iterator;
import buildcraft.api.core.BlockIndex;
public class BlockScannerExpanding implements Iterable<BlockIndex> {
private int searchRadius;
private int searchX;
private int searchY;
private int searchZ;
class BlockIt implements Iterator<BlockIndex> {
@Override
public boolean hasNext() {
return searchRadius < 64;
}
@Override
public BlockIndex next() {
// Step through each block in a hollow cube of size (searchRadius * 2 -1), if done
// add 1 to the radius and start over.
BlockIndex next = new BlockIndex(searchX, searchY, searchZ);
// Step to the next Y
if (Math.abs(searchX) == searchRadius || Math.abs(searchZ) == searchRadius) {
searchY += 1;
} else {
searchY += searchRadius * 2;
}
if (searchY > searchRadius) {
// Step to the next Z
searchY = -searchRadius;
searchZ += 1;
if (searchZ > searchRadius) {
// Step to the next X
searchZ = -searchRadius;
searchX += 1;
if (searchX > searchRadius) {
// Step to the next radius
searchRadius += 1;
searchX = -searchRadius;
searchY = -searchRadius;
searchZ = -searchRadius;
}
}
}
return next;
}
@Override
public void remove() {
}
}
public BlockScannerExpanding() {
searchRadius = 1;
searchX = -1;
searchY = -1;
searchZ = -1;
}
@Override
public Iterator<BlockIndex> iterator() {
return new BlockIt();
}
}