aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
diff options
context:
space:
mode:
authorJason Mitchell <mitchej@gmail.com>2023-04-22 22:33:35 -0700
committerGitHub <noreply@github.com>2023-04-23 07:33:35 +0200
commit56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b (patch)
tree745e6d92025ec4ef449fc59fa5fdd741200b0489 /src/main/java/gregtech/api/graphs/GenerateNodeMap.java
parentac0b7a7da46646d325def36eed811941dbfc5950 (diff)
downloadGT5-Unofficial-56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b.tar.gz
GT5-Unofficial-56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b.tar.bz2
GT5-Unofficial-56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b.zip
Forge direction (#1895)
* ForgeDirection Also refactor the clusterfuck that was `getCoordinateScan` Co-authored by: Jason Mitchell <mitchej@gmail.com> * Fix rendering of Frame Boxes Frame boxes needed their own implementation of getTexture with int connexion mask, which is returning an error texture for the MetaTileEntity, because pipes (FrameBox **is** a pipe) do use this method to return different textures based on connexion status. --------- Co-authored-by: Léa Gris <lea.gris@noiraude.net>
Diffstat (limited to 'src/main/java/gregtech/api/graphs/GenerateNodeMap.java')
-rw-r--r--src/main/java/gregtech/api/graphs/GenerateNodeMap.java85
1 files changed, 45 insertions, 40 deletions
diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
index bbdfa40a10..7289f0faad 100644
--- a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
+++ b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java
@@ -1,12 +1,12 @@
package gregtech.api.graphs;
import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES;
-import static gregtech.api.util.GT_Utility.getOppositeSide;
import java.util.ArrayList;
import java.util.HashSet;
import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.graphs.consumers.ConsumerNode;
import gregtech.api.graphs.paths.NodePath;
@@ -42,17 +42,17 @@ public abstract class GenerateNodeMap {
// get how many connections the pipe have
private static int getNumberOfConnections(MetaPipeEntity aPipe) {
int tCons = 0;
- for (byte side : ALL_VALID_SIDES) {
+ for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (aPipe.isConnectedAtSide(side)) tCons++;
}
return tCons;
}
// gets the next node
- protected void generateNextNode(BaseMetaPipeEntity aPipe, Node aPipeNode, byte aInvalidSide, int aNextNodeValue,
- ArrayList<ConsumerNode> tConsumers, HashSet<Node> tNodeMap) {
+ protected void generateNextNode(BaseMetaPipeEntity aPipe, Node aPipeNode, ForgeDirection aInvalidSide,
+ int aNextNodeValue, ArrayList<ConsumerNode> tConsumers, HashSet<Node> tNodeMap) {
final MetaPipeEntity tMetaPipe = (MetaPipeEntity) aPipe.getMetaTileEntity();
- for (byte side : ALL_VALID_SIDES) {
+ for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (side == aInvalidSide) {
continue;
}
@@ -70,12 +70,13 @@ public abstract class GenerateNodeMap {
tConsumers,
tNodeMap);
if (tNextNode != null) {
+ final int i = side.ordinal();
aNextNodeValue = tNextNode.mHighestNodeValue;
aPipeNode.mHighestNodeValue = tNextNode.mHighestNodeValue;
- aPipeNode.mNeighbourNodes[side] = tNextNode;
- aPipeNode.mNodePaths[side] = aPipeNode.returnValues.mReturnPath;
- aPipeNode.locks[side] = aPipeNode.returnValues.returnLock;
- aPipeNode.mNodePaths[side].reloadLocks();
+ aPipeNode.mNeighbourNodes[i] = tNextNode;
+ aPipeNode.mNodePaths[i] = aPipeNode.returnValues.mReturnPath;
+ aPipeNode.locks[i] = aPipeNode.returnValues.returnLock;
+ aPipeNode.mNodePaths[i].reloadLocks();
}
}
}
@@ -84,10 +85,11 @@ public abstract class GenerateNodeMap {
// on a valid tile entity create a new node
protected Node generateNode(TileEntity aTileEntity, Node aPreviousNode, int aNextNodeValue,
- ArrayList<MetaPipeEntity> aPipes, int aSide, ArrayList<ConsumerNode> aConsumers, HashSet<Node> aNodeMap) {
+ ArrayList<MetaPipeEntity> aPipes, ForgeDirection side, ArrayList<ConsumerNode> aConsumers,
+ HashSet<Node> aNodeMap) {
if (aTileEntity.isInvalid()) return null;
- final byte tSideOp = getOppositeSide(aSide);
- final byte tInvalidSide = aPreviousNode == null ? -1 : tSideOp;
+ final ForgeDirection oppositeSide = side.getOpposite();
+ final ForgeDirection tInvalidSide = aPreviousNode == null ? ForgeDirection.UNKNOWN : oppositeSide;
Node tThisNode = null;
if (isPipe(aTileEntity)) {
final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity;
@@ -95,33 +97,35 @@ public abstract class GenerateNodeMap {
final int tConnections = getNumberOfConnections(tMetaPipe);
final Node tPipeNode;
if (tConnections == 1) {
- tPipeNode = getEmptyNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers);
+ tPipeNode = getEmptyNode(aNextNodeValue, oppositeSide, aTileEntity, aConsumers);
if (tPipeNode == null) return null;
} else {
- tPipeNode = getPipeNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers);
+ tPipeNode = getPipeNode(aNextNodeValue, oppositeSide, aTileEntity, aConsumers);
}
tPipe.setNode(tPipeNode);
aNodeMap.add(tPipeNode);
tPipeNode.mSelfPath = getNewPath(new MetaPipeEntity[] { tMetaPipe });
tThisNode = tPipeNode;
- if (tInvalidSide > -1) {
- tPipeNode.mNeighbourNodes[tInvalidSide] = aPreviousNode;
- tPipeNode.mNodePaths[tInvalidSide] = getNewPath(aPipes.toArray(new MetaPipeEntity[0]));
+ if (tInvalidSide != ForgeDirection.UNKNOWN) {
+ final int iInvalid = tInvalidSide.ordinal();
+ tPipeNode.mNeighbourNodes[iInvalid] = aPreviousNode;
+ tPipeNode.mNodePaths[iInvalid] = getNewPath(aPipes.toArray(new MetaPipeEntity[0]));
final Lock lock = new Lock();
- tPipeNode.mNodePaths[tSideOp].lock = lock;
- tPipeNode.locks[tInvalidSide] = lock;
- aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[tInvalidSide];
+ tPipeNode.mNodePaths[oppositeSide.ordinal()].lock = lock;
+ tPipeNode.locks[iInvalid] = lock;
+ aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[iInvalid];
aPreviousNode.returnValues.returnLock = lock;
}
if (tConnections > 1)
generateNextNode(tPipe, tPipeNode, tInvalidSide, aNextNodeValue, aConsumers, aNodeMap);
- } else if (addConsumer(aTileEntity, tSideOp, aNextNodeValue, aConsumers)) {
+ } else if (addConsumer(aTileEntity, oppositeSide, aNextNodeValue, aConsumers)) {
+ final int oppositeSideOrdinal = oppositeSide.ordinal();
final ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size() - 1);
- tConsumeNode.mNeighbourNodes[tSideOp] = aPreviousNode;
- tConsumeNode.mNodePaths[tSideOp] = getNewPath(aPipes.toArray(new MetaPipeEntity[0]));
+ tConsumeNode.mNeighbourNodes[oppositeSideOrdinal] = aPreviousNode;
+ tConsumeNode.mNodePaths[oppositeSideOrdinal] = getNewPath(aPipes.toArray(new MetaPipeEntity[0]));
final Lock lock = new Lock();
- tConsumeNode.mNodePaths[tSideOp].lock = lock;
- aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[tSideOp];
+ tConsumeNode.mNodePaths[oppositeSideOrdinal].lock = lock;
+ aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[oppositeSideOrdinal];
aPreviousNode.returnValues.returnLock = lock;
tThisNode = tConsumeNode;
}
@@ -129,7 +133,7 @@ public abstract class GenerateNodeMap {
}
// go over the pipes until we see a valid tile entity that needs a node
- protected Pair getNextValidTileEntity(TileEntity aTileEntity, ArrayList<MetaPipeEntity> aPipes, byte aSide,
+ protected Pair getNextValidTileEntity(TileEntity aTileEntity, ArrayList<MetaPipeEntity> aPipes, ForgeDirection side,
HashSet<Node> aNodeMap) {
if (isPipe(aTileEntity)) {
final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity;
@@ -140,23 +144,23 @@ public abstract class GenerateNodeMap {
}
final int tConnections = getNumberOfConnections(tMetaPipe);
if (tConnections == 2) {
- final byte tSideOp = getOppositeSide(aSide);
- for (byte i : ALL_VALID_SIDES) {
- if (i == tSideOp || !(tMetaPipe.isConnectedAtSide(i))) continue;
- final TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(i);
+ final ForgeDirection tSideOp = side.getOpposite();
+ for (final ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) {
+ if (s == tSideOp || !(tMetaPipe.isConnectedAtSide(s))) continue;
+ final TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(s);
if (tNewTileEntity == null) continue;
if (isPipe(tNewTileEntity)) {
aPipes.add(tMetaPipe);
- return getNextValidTileEntity(tNewTileEntity, aPipes, i, aNodeMap);
+ return getNextValidTileEntity(tNewTileEntity, aPipes, s, aNodeMap);
} else {
- return new Pair(aTileEntity, i);
+ return new Pair(aTileEntity, s);
}
}
} else {
- return new Pair(aTileEntity, aSide);
+ return new Pair(aTileEntity, side);
}
} else {
- return new Pair(aTileEntity, aSide);
+ return new Pair(aTileEntity, side);
}
return null;
}
@@ -167,31 +171,32 @@ public abstract class GenerateNodeMap {
}
// checks if the tile entity is a consumer and add to the list
- protected abstract boolean addConsumer(TileEntity aTileEntity, byte aSide, int aNodeValue,
+ protected abstract boolean addConsumer(TileEntity aTileEntity, ForgeDirection side, int aNodeValue,
ArrayList<ConsumerNode> aConsumers);
// get correct pathClass that you need for your node network
protected abstract NodePath getNewPath(MetaPipeEntity[] aPipes);
// used for if you need to use dead ends for something can be null
- protected Node getEmptyNode(int aNodeValue, byte aSide, TileEntity aTileEntity,
+ protected Node getEmptyNode(int aNodeValue, ForgeDirection side, TileEntity aTileEntity,
ArrayList<ConsumerNode> aConsumers) {
return null;
}
// get correct node type you need for your network
- protected Node getPipeNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) {
+ protected Node getPipeNode(int aNodeValue, ForgeDirection side, TileEntity aTileEntity,
+ ArrayList<ConsumerNode> aConsumers) {
return new Node(aNodeValue, aTileEntity, aConsumers);
}
private static class Pair {
- public byte mSide;
+ public ForgeDirection mSide;
public TileEntity mTileEntity;
- public Pair(TileEntity aTileEntity, byte aSide) {
+ public Pair(TileEntity aTileEntity, ForgeDirection side) {
this.mTileEntity = aTileEntity;
- this.mSide = aSide;
+ this.mSide = side;
}
}
}