-
Notifications
You must be signed in to change notification settings - Fork 497
/
LensFilterHandler.java
69 lines (57 loc) · 2.1 KB
/
LensFilterHandler.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
package buildcraft.transport;
import java.util.LinkedList;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.pluggable.PipePluggable;
import buildcraft.transport.pipes.events.PipeEventItem;
import buildcraft.transport.pluggable.LensPluggable;
/**
* Created by asie on 12/18/14.
*/
public class LensFilterHandler {
private IPipe pipe;
public LensFilterHandler(IPipe pipe) {
this.pipe = pipe;
}
public void eventHandler(PipeEventItem.FindDest event) {
IPipeTile container = pipe.getTile();
LinkedList<ForgeDirection> correctColored = new LinkedList<ForgeDirection>();
LinkedList<ForgeDirection> notColored = new LinkedList<ForgeDirection>();
boolean encounteredColor = false;
int myColor = event.item.color == null ? -1 : event.item.color.ordinal();
for (ForgeDirection dir: event.destinations) {
int sideColor = -1;
// Get the side's color
// (1/2) From this pipe's outpost
PipePluggable pluggable = container.getPipePluggable(dir);
if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) {
sideColor = ((LensPluggable) pluggable).color;
}
// (2/2) From the other pipe's outpost
IPipe otherPipe = container.getNeighborPipe(dir);
if (otherPipe != null && otherPipe.getTile() != null) {
IPipeTile otherContainer = otherPipe.getTile();
pluggable = otherContainer.getPipePluggable(dir.getOpposite());
if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) {
int otherColor = ((LensPluggable) pluggable).color;
// Check if colors conflict - if so, the side is unpassable
if (sideColor >= 0 && otherColor != sideColor) {
continue;
} else {
sideColor = otherColor;
}
}
}
if (myColor == sideColor) {
encounteredColor = true;
correctColored.add(dir);
}
if (sideColor == -1) {
notColored.add(dir);
}
}
event.destinations.clear();
event.destinations.addAll(encounteredColor ? correctColored : notColored);
}
}