-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockScanner.java
executable file
·83 lines (63 loc) · 1.39 KB
/
BlockScanner.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
75
76
77
78
79
80
81
82
83
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core;
import java.util.Iterator;
import net.minecraft.world.World;
public class BlockScanner implements Iterable<BlockWrapper> {
Box box;
World world;
int x, y, z;
int iterations;
class BlockIt implements Iterator<BlockWrapper> {
int it = 0;
@Override
public boolean hasNext() {
return it <= iterations;
}
@Override
public BlockWrapper next() {
if (x <= box.xMax) {
x++;
} else {
x = box.xMin;
if (y <= box.yMax) {
y++;
} else {
y = box.yMin;
if (z <= box.zMax) {
z++;
} else {
z = box.zMin;
}
}
}
it++;
BlockWrapper w = new BlockWrapper();
w.index = new BlockIndex(x, y, z);
w.block = world.getBlock (x, y, z);
w.tile = world.getTileEntity(x, y, z);
return w;
}
@Override
public void remove() {
}
}
public BlockScanner (Box box, World world, int iterations) {
this.box = box;
this.world = world;
this.iterations = iterations;
x = box.xMin;
y = box.yMin;
z = box.zMin;
}
@Override
public Iterator<BlockWrapper> iterator() {
return new BlockIt();
}
}