-
Notifications
You must be signed in to change notification settings - Fork 497
/
WireMatrix.java
90 lines (71 loc) · 2.43 KB
/
WireMatrix.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
84
85
86
87
88
89
90
package buildcraft.transport.utils;
import buildcraft.api.transport.IPipe;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.BitSet;
import net.minecraftforge.common.ForgeDirection;
public class WireMatrix {
//private final boolean[] _hasWire = new boolean[IPipe.WireColor.values().length];
private final BitSet _hasWire = new BitSet(IPipe.WireColor.values().length);
private final BitSetCodec _bitSetCodec = new BitSetCodec();
private final ConnectionMatrix _wires[] = new ConnectionMatrix[IPipe.WireColor.values().length];
private final int[] _wireIconIndex = new int[IPipe.WireColor.values().length];
private boolean dirty = false;
public WireMatrix() {
for (int i = 0; i < IPipe.WireColor.values().length; i++) {
_wires[i] = new ConnectionMatrix();
}
}
public boolean hasWire(IPipe.WireColor color) {
return _hasWire.get(color.ordinal());
}
public void setWire(IPipe.WireColor color, boolean value) {
if (_hasWire.get(color.ordinal()) != value) {
_hasWire.set(color.ordinal(), value);
dirty = true;
}
}
public boolean isWireConnected(IPipe.WireColor color, ForgeDirection direction) {
return _wires[color.ordinal()].isConnected(direction);
}
public void setWireConnected(IPipe.WireColor color, ForgeDirection direction, boolean value) {
_wires[color.ordinal()].setConnected(direction, value);
}
public int getWireIconIndex(IPipe.WireColor color){
return _wireIconIndex[color.ordinal()];
}
public void setWireIndex(IPipe.WireColor color, int value){
if (_wireIconIndex[color.ordinal()] != value){
_wireIconIndex[color.ordinal()] = value;
dirty = true;
}
}
public boolean isDirty() {
for (int i = 0; i < IPipe.WireColor.values().length; i++) {
if (_wires[i].isDirty())
return true;
}
return dirty;
}
public void clean() {
for (int i = 0; i < IPipe.WireColor.values().length; i++) {
_wires[i].clean();
}
dirty = false;
}
public void writeData(DataOutputStream data) throws IOException {
data.writeByte(_bitSetCodec.encode(_hasWire));
for (int i = 0; i < IPipe.WireColor.values().length; i++) {
_wires[i].writeData(data);
data.writeInt(_wireIconIndex[i]);
}
}
public void readData(DataInputStream data) throws IOException {
_bitSetCodec.decode(data.readByte(), _hasWire);
for (int i = 0; i < IPipe.WireColor.values().length; i++) {
_wires[i].readData(data);
_wireIconIndex[i] = data.readInt();
}
}
}