-
Notifications
You must be signed in to change notification settings - Fork 497
/
ConnectionMatrix.java
54 lines (44 loc) · 1.19 KB
/
ConnectionMatrix.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
package buildcraft.transport.utils;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraftforge.common.ForgeDirection;
public class ConnectionMatrix {
private int mask = 0;
private boolean dirty = false;
public boolean isConnected(ForgeDirection direction) {
// test if the direction.ordinal()'th bit of mask is set
return (mask & (1 << direction.ordinal())) != 0;
}
public void setConnected(ForgeDirection direction, boolean value) {
if (isConnected(direction) != value) {
// invert the direction.ordinal()'th bit of mask
mask ^= 1 << direction.ordinal();
dirty = true;
}
}
/**
* Return a mask representing the connectivity for all sides.
*
* @return mask in ForgeDirection order, least significant bit = first entry
*/
public int getMask() {
return mask;
}
public boolean isDirty() {
return dirty;
}
public void clean() {
dirty = false;
}
public void writeData(DataOutputStream data) throws IOException {
data.writeByte(mask);
}
public void readData(DataInputStream data) throws IOException {
byte newMask = data.readByte();
if (newMask != mask) {
mask = newMask;
dirty = true;
}
}
}