aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/graphs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/graphs')
-rw-r--r--src/main/java/gregtech/api/graphs/GenerateNodeMap.java73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
index c0ee8b9490..8085421576 100644
--- a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
+++ b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
@@ -1,5 +1,6 @@
package gregtech.api.graphs;
+import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES;
import static gregtech.api.util.GT_Utility.getOppositeSide;
import gregtech.api.graphs.consumers.ConsumerNode;
@@ -15,7 +16,7 @@ public abstract class GenerateNodeMap {
// clearing the node map to make sure it is gone on reset
public static void clearNodeMap(Node aNode, int aReturnNodeValue) {
if (aNode.mTileEntity instanceof BaseMetaPipeEntity) {
- BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aNode.mTileEntity;
+ final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aNode.mTileEntity;
tPipe.setNode(null);
tPipe.setNodePath(null);
if (aNode.mSelfPath != null) {
@@ -23,24 +24,24 @@ public abstract class GenerateNodeMap {
aNode.mSelfPath = null;
}
}
- for (int i = 0; i < 6; i++) {
- NodePath tPath = aNode.mNodePaths[i];
+ for (byte side : ALL_VALID_SIDES) {
+ final NodePath tPath = aNode.mNodePaths[side];
if (tPath != null) {
tPath.clearPath();
- aNode.mNodePaths[i] = null;
+ aNode.mNodePaths[side] = null;
}
- Node tNextNode = aNode.mNeighbourNodes[i];
+ final Node tNextNode = aNode.mNeighbourNodes[side];
if (tNextNode == null) continue;
if (tNextNode.mNodeValue != aReturnNodeValue) clearNodeMap(tNextNode, aNode.mNodeValue);
- aNode.mNeighbourNodes[i] = null;
+ aNode.mNeighbourNodes[side] = null;
}
}
// get how many connections the pipe have
private static int getNumberOfConnections(MetaPipeEntity aPipe) {
int tCons = 0;
- for (int i = 0; i < 6; i++) {
- if (aPipe.isConnectedAtSide(i)) tCons++;
+ for (byte side : ALL_VALID_SIDES) {
+ if (aPipe.isConnectedAtSide(side)) tCons++;
}
return tCons;
}
@@ -53,17 +54,17 @@ public abstract class GenerateNodeMap {
int aNextNodeValue,
ArrayList<ConsumerNode> tConsumers,
HashSet<Node> tNodeMap) {
- MetaPipeEntity tMetaPipe = (MetaPipeEntity) aPipe.getMetaTileEntity();
- for (byte i = 0; i < 6; i++) {
- if (i == aInvalidSide) {
+ final MetaPipeEntity tMetaPipe = (MetaPipeEntity) aPipe.getMetaTileEntity();
+ for (byte side : ALL_VALID_SIDES) {
+ if (side == aInvalidSide) {
continue;
}
- TileEntity tNextTileEntity = aPipe.getTileEntityAtSide(i);
- if (tNextTileEntity == null || (tMetaPipe != null && !tMetaPipe.isConnectedAtSide(i))) continue;
- ArrayList<MetaPipeEntity> tNewPipes = new ArrayList<>();
- Pair nextTileEntity = getNextValidTileEntity(tNextTileEntity, tNewPipes, i, tNodeMap);
+ final TileEntity tNextTileEntity = aPipe.getTileEntityAtSide(side);
+ if (tNextTileEntity == null || (tMetaPipe != null && !tMetaPipe.isConnectedAtSide(side))) continue;
+ final ArrayList<MetaPipeEntity> tNewPipes = new ArrayList<>();
+ final Pair nextTileEntity = getNextValidTileEntity(tNextTileEntity, tNewPipes, side, tNodeMap);
if (nextTileEntity != null) {
- Node tNextNode = generateNode(
+ final Node tNextNode = generateNode(
nextTileEntity.mTileEntity,
aPipeNode,
aNextNodeValue + 1,
@@ -74,10 +75,10 @@ public abstract class GenerateNodeMap {
if (tNextNode != null) {
aNextNodeValue = tNextNode.mHighestNodeValue;
aPipeNode.mHighestNodeValue = tNextNode.mHighestNodeValue;
- aPipeNode.mNeighbourNodes[i] = tNextNode;
- aPipeNode.mNodePaths[i] = aPipeNode.returnValues.mReturnPath;
- aPipeNode.locks[i] = aPipeNode.returnValues.returnLock;
- aPipeNode.mNodePaths[i].reloadLocks();
+ aPipeNode.mNeighbourNodes[side] = tNextNode;
+ aPipeNode.mNodePaths[side] = aPipeNode.returnValues.mReturnPath;
+ aPipeNode.locks[side] = aPipeNode.returnValues.returnLock;
+ aPipeNode.mNodePaths[side].reloadLocks();
}
}
}
@@ -94,14 +95,14 @@ public abstract class GenerateNodeMap {
ArrayList<ConsumerNode> aConsumers,
HashSet<Node> aNodeMap) {
if (aTileEntity.isInvalid()) return null;
- byte tSideOp = getOppositeSide(aSide);
- byte tInvalidSide = aPreviousNode == null ? -1 : tSideOp;
+ final byte tSideOp = getOppositeSide(aSide);
+ final byte tInvalidSide = aPreviousNode == null ? -1 : tSideOp;
Node tThisNode = null;
if (isPipe(aTileEntity)) {
- BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity;
- MetaPipeEntity tMetaPipe = (MetaPipeEntity) tPipe.getMetaTileEntity();
- int tConnections = getNumberOfConnections(tMetaPipe);
- Node tPipeNode;
+ final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity;
+ final MetaPipeEntity tMetaPipe = (MetaPipeEntity) tPipe.getMetaTileEntity();
+ final int tConnections = getNumberOfConnections(tMetaPipe);
+ final Node tPipeNode;
if (tConnections == 1) {
tPipeNode = getEmptyNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers);
if (tPipeNode == null) return null;
@@ -115,7 +116,7 @@ public abstract class GenerateNodeMap {
if (tInvalidSide > -1) {
tPipeNode.mNeighbourNodes[tInvalidSide] = aPreviousNode;
tPipeNode.mNodePaths[tInvalidSide] = getNewPath(aPipes.toArray(new MetaPipeEntity[0]));
- Lock lock = new Lock();
+ final Lock lock = new Lock();
tPipeNode.mNodePaths[tSideOp].lock = lock;
tPipeNode.locks[tInvalidSide] = lock;
aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[tInvalidSide];
@@ -124,10 +125,10 @@ public abstract class GenerateNodeMap {
if (tConnections > 1)
generateNextNode(tPipe, tPipeNode, tInvalidSide, aNextNodeValue, aConsumers, aNodeMap);
} else if (addConsumer(aTileEntity, tSideOp, aNextNodeValue, aConsumers)) {
- ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size() - 1);
+ final ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size() - 1);
tConsumeNode.mNeighbourNodes[tSideOp] = aPreviousNode;
tConsumeNode.mNodePaths[tSideOp] = getNewPath(aPipes.toArray(new MetaPipeEntity[0]));
- Lock lock = new Lock();
+ final Lock lock = new Lock();
tConsumeNode.mNodePaths[tSideOp].lock = lock;
aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[tSideOp];
aPreviousNode.returnValues.returnLock = lock;
@@ -140,18 +141,18 @@ public abstract class GenerateNodeMap {
protected Pair getNextValidTileEntity(
TileEntity aTileEntity, ArrayList<MetaPipeEntity> aPipes, byte aSide, HashSet<Node> aNodeMap) {
if (isPipe(aTileEntity)) {
- BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity;
- MetaPipeEntity tMetaPipe = (MetaPipeEntity) tPipe.getMetaTileEntity();
- Node tNode = tPipe.getNode();
+ final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity;
+ final MetaPipeEntity tMetaPipe = (MetaPipeEntity) tPipe.getMetaTileEntity();
+ final Node tNode = tPipe.getNode();
if (tNode != null) {
if (aNodeMap.contains(tNode)) return null;
}
- int tConnections = getNumberOfConnections(tMetaPipe);
+ final int tConnections = getNumberOfConnections(tMetaPipe);
if (tConnections == 2) {
- byte tSideOp = getOppositeSide(aSide);
- for (byte i = 0; i < 6; i++) {
+ final byte tSideOp = getOppositeSide(aSide);
+ for (byte i : ALL_VALID_SIDES) {
if (i == tSideOp || !(tMetaPipe.isConnectedAtSide(i))) continue;
- TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(i);
+ final TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(i);
if (tNewTileEntity == null) continue;
if (isPipe(tNewTileEntity)) {
aPipes.add(tMetaPipe);