diff options
Diffstat (limited to 'src/main/java/gregtech/api/graphs')
-rw-r--r-- | src/main/java/gregtech/api/graphs/GenerateNodeMap.java | 16 | ||||
-rw-r--r-- | src/main/java/gregtech/api/graphs/Lock.java | 37 | ||||
-rw-r--r-- | src/main/java/gregtech/api/graphs/Node.java | 19 | ||||
-rw-r--r-- | src/main/java/gregtech/api/graphs/PowerNodes.java | 17 | ||||
-rw-r--r-- | src/main/java/gregtech/api/graphs/paths/NodePath.java | 15 | ||||
-rw-r--r-- | src/main/java/gregtech/api/graphs/paths/PowerNodePath.java | 3 |
6 files changed, 92 insertions, 15 deletions
diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java index 7ef57fa6d2..4d1b7a7461 100644 --- a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java +++ b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java @@ -67,10 +67,13 @@ abstract public class GenerateNodeMap { aNextNodeValue = tNextNode.mHighestNodeValue; aPipeNode.mHighestNodeValue = tNextNode.mHighestNodeValue; aPipeNode.mNeighbourNodes[i] = tNextNode; - aPipeNode.mNodePaths[i] = aPipeNode.mReturnPath; + aPipeNode.mNodePaths[i] = aPipeNode.returnValues.mReturnPath; + aPipeNode.locks[i] = aPipeNode.returnValues.returnLock; + aPipeNode.mNodePaths[i].reloadLocks(); } } } + aPipe.reloadLocks(); } // on a valid tile entity create a new node @@ -98,7 +101,11 @@ abstract public class GenerateNodeMap { if (tInvalidSide > -1) { tPipeNode.mNeighbourNodes[tInvalidSide] = aPreviousNode; tPipeNode.mNodePaths[tInvalidSide] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); - aPreviousNode.mReturnPath = tPipeNode.mNodePaths[tInvalidSide]; + Lock lock = new Lock(); + tPipeNode.mNodePaths[tSideOp].lock = lock; + tPipeNode.locks[tInvalidSide] = lock; + aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[tInvalidSide]; + aPreviousNode.returnValues.returnLock = lock; } if (tConnections > 1) generateNextNode(tPipe, tPipeNode, tInvalidSide, aNextNodeValue, aConsumers, aNodeMap); @@ -106,7 +113,10 @@ abstract public class GenerateNodeMap { ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size() - 1); tConsumeNode.mNeighbourNodes[tSideOp] = aPreviousNode; tConsumeNode.mNodePaths[tSideOp] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); - aPreviousNode.mReturnPath = tConsumeNode.mNodePaths[tSideOp]; + Lock lock = new Lock(); + tConsumeNode.mNodePaths[tSideOp].lock = lock; + aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[tSideOp]; + aPreviousNode.returnValues.returnLock = lock; tThisNode = tConsumeNode; } return tThisNode; diff --git a/src/main/java/gregtech/api/graphs/Lock.java b/src/main/java/gregtech/api/graphs/Lock.java new file mode 100644 index 0000000000..0ba43b83de --- /dev/null +++ b/src/main/java/gregtech/api/graphs/Lock.java @@ -0,0 +1,37 @@ +package gregtech.api.graphs; + +import net.minecraft.tileentity.TileEntity; + +import java.util.ArrayList; + +public class Lock { + protected ArrayList<TileEntity> tiles = new ArrayList<>(); + + public void addTileEntity(TileEntity tileEntity) { + int i = contains(tileEntity); + if (i == -1) { + tiles.add(tileEntity); + } + } + + public void removeTileEntity(TileEntity tileEntity) { + int i = contains(tileEntity); + if (i > -1) { + tiles.remove(i); + } + } + + public boolean isLocked() { + return !tiles.isEmpty(); + } + + //i want to check for the exact object not equals + protected int contains(TileEntity tileEntity) { + for (int i = 0; i < tiles.size(); i++) { + if (tiles.get(i) == tileEntity) { + return i; + } + } + return -1; + } +} diff --git a/src/main/java/gregtech/api/graphs/Node.java b/src/main/java/gregtech/api/graphs/Node.java index 815c7dd46e..be499dea0d 100644 --- a/src/main/java/gregtech/api/graphs/Node.java +++ b/src/main/java/gregtech/api/graphs/Node.java @@ -4,11 +4,12 @@ import gregtech.api.graphs.consumers.ConsumerNode; import gregtech.api.graphs.paths.NodePath; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; + import java.util.ArrayList; // base Node class public class Node { - public Node(int aNodeValue,TileEntity aTileEntity,ArrayList<ConsumerNode> aConsumers){ + public Node(int aNodeValue, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { this.mNodeValue = aNodeValue; this.mTileEntity = aTileEntity; this.mConsumers = aConsumers; @@ -18,13 +19,19 @@ public class Node { } - public int mCreationTime; - public NodePath mSelfPath; - public ArrayList<ConsumerNode> mConsumers; - public int mNodeValue; public final TileEntity mTileEntity; public Node[] mNeighbourNodes = new Node[6]; public NodePath[] mNodePaths = new NodePath[6]; - public NodePath mReturnPath; + public Lock[] locks = new Lock[6]; + public ReturnPair returnValues = new ReturnPair(); + public NodePath mSelfPath; + public ArrayList<ConsumerNode> mConsumers; + public int mCreationTime; + public int mNodeValue; public int mHighestNodeValue; + + public class ReturnPair { + public NodePath mReturnPath; + public Lock returnLock; + } } diff --git a/src/main/java/gregtech/api/graphs/PowerNodes.java b/src/main/java/gregtech/api/graphs/PowerNodes.java index 7a3364648a..e5d0e56699 100644 --- a/src/main/java/gregtech/api/graphs/PowerNodes.java +++ b/src/main/java/gregtech/api/graphs/PowerNodes.java @@ -34,7 +34,7 @@ public class PowerNodes { final Node tNextNode = aCurrentNode.mNeighbourNodes[j]; if (tNextNode != null && tNextNode.mNodeValue < aCurrentNode.mNodeValue) { if (tNextNode.mNodeValue == tConsumer.mNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, j, aMaxAmps - tAmpsUsed, aVoltage, false); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, j, aMaxAmps - tAmpsUsed, aVoltage); tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } else { @@ -56,7 +56,7 @@ public class PowerNodes { tConsumer = (ConsumerNode) aConsumers.getNode(); break; } else if (tNextNode.mNodeValue == tTargetNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage, true); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage); tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } @@ -92,7 +92,7 @@ public class PowerNodes { tConsumer = (ConsumerNode) aConsumers.getNode(); break; } else if (tNextNode.mNodeValue == tTargetNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage, true); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage); tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } @@ -109,6 +109,10 @@ public class PowerNodes { } protected static long processNextNode(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, long aMaxAmps, long aVoltage) { + if (aCurrentNode.locks[aSide].isLocked()) { + aConsumers.getNextNode(); + return 0; + } final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; @@ -126,6 +130,10 @@ public class PowerNodes { } protected static long processNextNodeAbove(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, long aMaxAmps, long aVoltage) { + if (aCurrentNode.locks[aSide].isLocked()) { + aConsumers.getNextNode(); + return 0; + } final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; @@ -142,7 +150,8 @@ public class PowerNodes { return tAmps; } - protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide, long aMaxAmps, long aVoltage, boolean isUp) { + protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide, long aMaxAmps, long aVoltage) { + if (aCurrentNode.locks[aSide].isLocked()) return 0; final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; diff --git a/src/main/java/gregtech/api/graphs/paths/NodePath.java b/src/main/java/gregtech/api/graphs/paths/NodePath.java index bdf82ec5b0..efdcd1aecb 100644 --- a/src/main/java/gregtech/api/graphs/paths/NodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/NodePath.java @@ -1,11 +1,13 @@ package gregtech.api.graphs.paths; +import gregtech.api.graphs.Lock; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; //to contain all info about the path between nodes public class NodePath { protected MetaPipeEntity[] mPipes; + public Lock lock; public NodePath(MetaPipeEntity[] aCables) { this.mPipes = aCables; @@ -20,11 +22,20 @@ public class NodePath { } public void clearPath() { - for (int i = 0; i < mPipes.length; i++) { - BaseMetaPipeEntity tBasePipe = (BaseMetaPipeEntity) mPipes[i].getBaseMetaTileEntity(); + for (MetaPipeEntity mPipe : mPipes) { + BaseMetaPipeEntity tBasePipe = (BaseMetaPipeEntity) mPipe.getBaseMetaTileEntity(); if (tBasePipe != null) { tBasePipe.setNodePath(null); } } } + + public void reloadLocks() { + for (MetaPipeEntity pipe : mPipes) { + BaseMetaPipeEntity basePipe = (BaseMetaPipeEntity) pipe.getBaseMetaTileEntity(); + if (basePipe != null) { + basePipe.reloadLocks(); + } + } + } } diff --git a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java index 72b2edb334..d18d6bcdd3 100644 --- a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java @@ -37,6 +37,7 @@ public class PowerNodePath extends NodePath { this.mVoltage = aVoltage; } if (aVoltage > mMaxVoltage) { + lock.addTileEntity(null); for (MetaPipeEntity tCable : mPipes) { if (((GT_MetaPipeEntity_Cable) tCable).mVoltage < this.mVoltage) { BaseMetaPipeEntity tBaseCable = (BaseMetaPipeEntity) tCable.getBaseMetaTileEntity(); @@ -51,6 +52,7 @@ public class PowerNodePath extends NodePath { private void reset(int aTimePassed) { if (aTimePassed < 0 || aTimePassed > 100) { mAmps = 0; + return; } mAmps = Math.max(0, mAmps - (mMaxAmps * aTimePassed)); } @@ -58,6 +60,7 @@ public class PowerNodePath extends NodePath { public void addAmps(long aAmps) { this.mAmps += aAmps; if (this.mAmps > mMaxAmps * 40) { + lock.addTileEntity(null); for (MetaPipeEntity tCable : mPipes) { if (((GT_MetaPipeEntity_Cable) tCable).mAmperage * 40 < this.mAmps) { BaseMetaPipeEntity tBaseCable = (BaseMetaPipeEntity) tCable.getBaseMetaTileEntity(); |