diff options
author | Jason Mitchell <mitchej+github@gmail.com> | 2021-12-10 05:25:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 14:25:29 +0100 |
commit | fe883d00df245c726dca6271978b8aed739d4a28 (patch) | |
tree | 376f627d3a36045914e9b26a232d810abf13fd4d /src/main/java/gregtech | |
parent | 3922d6ca26c6ce9cd8370ea59015224b48c0f204 (diff) | |
download | GT5-Unofficial-fe883d00df245c726dca6271978b8aed739d4a28.tar.gz GT5-Unofficial-fe883d00df245c726dca6271978b8aed739d4a28.tar.bz2 GT5-Unofficial-fe883d00df245c726dca6271978b8aed739d4a28.zip |
Overflows overflows everywhere (#791)
* Reformat
* Stop energy calcs from overflowing by switching int->long in several places in the new graph code to be consistent with how they're used elsewhere.
Diffstat (limited to 'src/main/java/gregtech')
15 files changed, 207 insertions, 199 deletions
diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java index 98c8215fc7..7ef57fa6d2 100644 --- a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java +++ b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java @@ -2,7 +2,8 @@ package gregtech.api.graphs; import gregtech.api.graphs.consumers.ConsumerNode; import gregtech.api.graphs.paths.NodePath; -import gregtech.api.metatileentity.*; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.MetaPipeEntity; import net.minecraft.tileentity.TileEntity; import java.util.ArrayList; @@ -11,10 +12,10 @@ import java.util.HashSet; import static gregtech.api.util.GT_Utility.getOppositeSide; -//generates the node map +// generates the node map abstract public class GenerateNodeMap { - //clearing the node map to make sure it is gone on reset - public static void clearNodeMap(Node aNode,int aReturnNodeValue) { + // 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; tPipe.setNode(null); @@ -24,7 +25,7 @@ abstract public class GenerateNodeMap { aNode.mSelfPath = null; } } - for (int i = 0;i<6;i++) { + for (int i = 0; i < 6; i++) { NodePath tPath = aNode.mNodePaths[i]; if (tPath != null) { tPath.clearPath(); @@ -33,26 +34,35 @@ abstract public class GenerateNodeMap { Node tNextNode = aNode.mNeighbourNodes[i]; if (tNextNode == null) continue; if (tNextNode.mNodeValue != aReturnNodeValue) - clearNodeMap(tNextNode,aNode.mNodeValue); + clearNodeMap(tNextNode, aNode.mNodeValue); aNode.mNeighbourNodes[i] = null; } } - //gets the next node + // 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++; + } + return tCons; + } + + // gets the next node protected void generateNextNode(BaseMetaPipeEntity aPipe, Node aPipeNode, byte aInvalidSide, int aNextNodeValue, - ArrayList<ConsumerNode> tConsumers, HashSet<Node> tNodeMap) { + ArrayList<ConsumerNode> tConsumers, HashSet<Node> tNodeMap) { MetaPipeEntity tMetaPipe = (MetaPipeEntity) aPipe.getMetaTileEntity(); - for (byte i = 0;i<6;i++) { - if (i==aInvalidSide) { + for (byte i = 0; i < 6; i++) { + if (i == aInvalidSide) { continue; } TileEntity tNextTileEntity = aPipe.getTileEntityAtSide(i); if (tNextTileEntity == null || (tMetaPipe != null && !tMetaPipe.isConnectedAtSide(i))) continue; - ArrayList<MetaPipeEntity> tNewPipes = new ArrayList<MetaPipeEntity>(); - Pair nextTileEntity = getNextValidTileEntity(tNextTileEntity,tNewPipes,i,tNodeMap); + ArrayList<MetaPipeEntity> tNewPipes = new ArrayList<>(); + Pair nextTileEntity = getNextValidTileEntity(tNextTileEntity, tNewPipes, i, tNodeMap); if (nextTileEntity != null) { - Node tNextNode = generateNode(nextTileEntity.mTileEntity,aPipeNode,aNextNodeValue+1,tNewPipes, - nextTileEntity.mSide,tConsumers,tNodeMap); + Node tNextNode = generateNode(nextTileEntity.mTileEntity, aPipeNode, aNextNodeValue + 1, tNewPipes, + nextTileEntity.mSide, tConsumers, tNodeMap); if (tNextNode != null) { aNextNodeValue = tNextNode.mHighestNodeValue; aPipeNode.mHighestNodeValue = tNextNode.mHighestNodeValue; @@ -63,37 +73,37 @@ abstract public class GenerateNodeMap { } } - //on a valid tile entity create a new node + // 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) { + int aSide, ArrayList<ConsumerNode> aConsumers, HashSet<Node> aNodeMap) { if (aTileEntity.isInvalid()) return null; byte tSideOp = getOppositeSide(aSide); byte tInvalidSide = aPreviousNode == null ? -1 : tSideOp; Node tThisNode = null; - if (isPipe(aTileEntity)){ + if (isPipe(aTileEntity)) { BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity; MetaPipeEntity tMetaPipe = (MetaPipeEntity) tPipe.getMetaTileEntity(); int tConnections = getNumberOfConnections(tMetaPipe); Node tPipeNode; if (tConnections == 1) { - tPipeNode = getEmptyNode(aNextNodeValue,tSideOp,aTileEntity,aConsumers); + tPipeNode = getEmptyNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers); if (tPipeNode == null) return null; } else { - tPipeNode = getPipeNode(aNextNodeValue,tSideOp,aTileEntity,aConsumers); + tPipeNode = getPipeNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers); } tPipe.setNode(tPipeNode); aNodeMap.add(tPipeNode); tPipeNode.mSelfPath = getNewPath(new MetaPipeEntity[]{tMetaPipe}); tThisNode = tPipeNode; - if (tInvalidSide>-1) { + if (tInvalidSide > -1) { tPipeNode.mNeighbourNodes[tInvalidSide] = aPreviousNode; tPipeNode.mNodePaths[tInvalidSide] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); aPreviousNode.mReturnPath = tPipeNode.mNodePaths[tInvalidSide]; } if (tConnections > 1) - generateNextNode(tPipe,tPipeNode,tInvalidSide,aNextNodeValue,aConsumers,aNodeMap); - } else if (addConsumer(aTileEntity,tSideOp,aNextNodeValue,aConsumers)) { - ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size()-1); + generateNextNode(tPipe, tPipeNode, tInvalidSide, aNextNodeValue, aConsumers, aNodeMap); + } else if (addConsumer(aTileEntity, tSideOp, aNextNodeValue, aConsumers)) { + 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]; @@ -102,7 +112,7 @@ abstract public class GenerateNodeMap { return tThisNode; } - //go over the pipes until we see a valid tile entity that needs a node + // 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, HashSet<Node> aNodeMap) { if (isPipe(aTileEntity)) { BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity; @@ -115,60 +125,54 @@ abstract public class GenerateNodeMap { int tConnections = getNumberOfConnections(tMetaPipe); if (tConnections == 2) { byte tSideOp = getOppositeSide(aSide); - for (byte i = 0;i<6;i++) { + for (byte i = 0; i < 6; i++) { if (i == tSideOp || !(tMetaPipe.isConnectedAtSide(i))) continue; TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(i); if (tNewTileEntity == null) continue; if (isPipe(tNewTileEntity)) { aPipes.add(tMetaPipe); - return getNextValidTileEntity(tNewTileEntity,aPipes,i,aNodeMap); + return getNextValidTileEntity(tNewTileEntity, aPipes, i, aNodeMap); } else { - return new Pair(aTileEntity,i); + return new Pair(aTileEntity, i); } } } else { - return new Pair(aTileEntity,aSide); + return new Pair(aTileEntity, aSide); } } else { - return new Pair(aTileEntity,aSide); + return new Pair(aTileEntity, aSide); } return null; } - private static class Pair { - public byte mSide; - public TileEntity mTileEntity; - public Pair(TileEntity aTileEntity, byte aSide) { - this.mTileEntity = aTileEntity; - this.mSide = aSide; - } - } - - //if check if the tile entity is the correct pipe + // check if the tile entity is the correct pipe protected boolean isPipe(TileEntity aTileEntity) { return aTileEntity instanceof BaseMetaPipeEntity; } - //checks if the tile entity is a consumer and add to the list + + // checks if the tile entity is a consumer and add to the list abstract protected boolean addConsumer(TileEntity aTileEntity, byte aSide, int aNodeValue, ArrayList<ConsumerNode> aConsumers); - //get correct pathClass that you need for your node network + + // get correct pathClass that you need for your node network protected abstract NodePath getNewPath(MetaPipeEntity[] aPipes); - //used for if you need to use death ends for something - //can be null + // used for if you need to use dead ends for something can be null protected Node getEmptyNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { return null; } - //get correct node type you need for your network + + // get correct node type you need for your network protected Node getPipeNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { - return new Node(aNodeValue,aTileEntity,aConsumers); + return new Node(aNodeValue, aTileEntity, aConsumers); } - //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++; + private static class Pair { + public byte mSide; + public TileEntity mTileEntity; + + public Pair(TileEntity aTileEntity, byte aSide) { + this.mTileEntity = aTileEntity; + this.mSide = aSide; } - return tCons; } } diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java b/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java index 76a24e8802..bb7a1f58e1 100644 --- a/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java +++ b/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java @@ -2,7 +2,12 @@ package gregtech.api.graphs; import cofh.api.energy.IEnergyReceiver; import gregtech.api.GregTech_API; -import gregtech.api.graphs.consumers.*; +import gregtech.api.graphs.consumers.ConsumerNode; +import gregtech.api.graphs.consumers.EmptyPowerConsumer; +import gregtech.api.graphs.consumers.NodeEnergyConnected; +import gregtech.api.graphs.consumers.NodeEnergyReceiver; +import gregtech.api.graphs.consumers.NodeEnergySink; +import gregtech.api.graphs.consumers.NodeGTBaseMetaTile; import gregtech.api.graphs.paths.NodePath; import gregtech.api.graphs.paths.PowerNodePath; import gregtech.api.interfaces.tileentity.IEnergyConnected; @@ -17,11 +22,10 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; import java.util.HashSet; -//node map generator for power distribution +// node map generator for power distribution public class GenerateNodeMapPower extends GenerateNodeMap { public GenerateNodeMapPower(BaseMetaPipeEntity aTileEntity) { - generateNode(aTileEntity,null,1,null, - -1,new ArrayList<>(),new HashSet<>()); + generateNode(aTileEntity, null, 1, null, -1, new ArrayList<>(), new HashSet<>()); } @Override @@ -30,24 +34,6 @@ public class GenerateNodeMapPower extends GenerateNodeMap { } @Override - protected NodePath getNewPath(MetaPipeEntity[] aPipes) { - return new PowerNodePath(aPipes); - } - - //used to apply voltage on death ends - @Override - protected Node getEmptyNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { - Node tNode = new EmptyPowerConsumer(aNodeValue, aTileEntity, aSide, aConsumers); - aConsumers.add((ConsumerNode) tNode); - return tNode; - } - - @Override - protected Node getPipeNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { - return new PowerNode(aNodeValue, aTileEntity, aConsumers); - } - - @Override protected boolean addConsumer(TileEntity aTileEntity, byte aSide, int aNodeValue, ArrayList<ConsumerNode> aConsumers) { if (aTileEntity instanceof BaseMetaTileEntity) { BaseMetaTileEntity tBaseTileEntity = (BaseMetaTileEntity) aTileEntity; @@ -59,14 +45,14 @@ public class GenerateNodeMapPower extends GenerateNodeMap { } else if (aTileEntity instanceof IEnergyConnected) { IEnergyConnected tTileEntity = (IEnergyConnected) aTileEntity; - if (tTileEntity.inputEnergyFrom(aSide,false)) { - ConsumerNode tConsumerNode = new NodeEnergyConnected(aNodeValue,tTileEntity,aSide,aConsumers); + if (tTileEntity.inputEnergyFrom(aSide, false)) { + ConsumerNode tConsumerNode = new NodeEnergyConnected(aNodeValue, tTileEntity, aSide, aConsumers); aConsumers.add(tConsumerNode); return true; } } else if (aTileEntity instanceof IEnergySink) { - //ic2 wants the tilentitty next to it of that side not going to add a bunch of arguments just for ic2 - //crossborder checks to not not load chuncks just to make sure + // ic2 wants the tilentity next to it of that side not going to add a bunch of arguments just for ic2 + // crossborder checks to not load chuncks just to make sure int dX = aTileEntity.xCoord + ForgeDirection.getOrientation(aSide).offsetX; int dY = aTileEntity.yCoord + ForgeDirection.getOrientation(aSide).offsetY; int dZ = aTileEntity.zCoord + ForgeDirection.getOrientation(aSide).offsetZ; @@ -76,15 +62,33 @@ public class GenerateNodeMapPower extends GenerateNodeMap { tNextTo = aTileEntity.getWorldObj().getTileEntity(dX, dY, dZ); if (((IEnergySink) aTileEntity).acceptsEnergyFrom(tNextTo, ForgeDirection.getOrientation(aSide))) { - ConsumerNode tConsumerNode = new NodeEnergySink(aNodeValue,(IEnergySink) aTileEntity, aSide, aConsumers); + ConsumerNode tConsumerNode = new NodeEnergySink(aNodeValue, (IEnergySink) aTileEntity, aSide, aConsumers); aConsumers.add(tConsumerNode); return true; } } else if (GregTech_API.mOutputRF && aTileEntity instanceof IEnergyReceiver) { - ConsumerNode tConsumerNode = new NodeEnergyReceiver(aNodeValue,(IEnergyReceiver) aTileEntity, aSide, aConsumers); + ConsumerNode tConsumerNode = new NodeEnergyReceiver(aNodeValue, (IEnergyReceiver) aTileEntity, aSide, aConsumers); aConsumers.add(tConsumerNode); return true; } return false; } + + @Override + protected NodePath getNewPath(MetaPipeEntity[] aPipes) { + return new PowerNodePath(aPipes); + } + + //used to apply voltage on dead ends + @Override + protected Node getEmptyNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { + Node tNode = new EmptyPowerConsumer(aNodeValue, aTileEntity, aSide, aConsumers); + aConsumers.add((ConsumerNode) tNode); + return tNode; + } + + @Override + protected Node getPipeNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { + return new PowerNode(aNodeValue, aTileEntity, aConsumers); + } } diff --git a/src/main/java/gregtech/api/graphs/Node.java b/src/main/java/gregtech/api/graphs/Node.java index 258915e473..815c7dd46e 100644 --- a/src/main/java/gregtech/api/graphs/Node.java +++ b/src/main/java/gregtech/api/graphs/Node.java @@ -6,14 +6,14 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import java.util.ArrayList; -//base Node class +// base Node class public class Node { public Node(int aNodeValue,TileEntity aTileEntity,ArrayList<ConsumerNode> aConsumers){ this.mNodeValue = aNodeValue; this.mTileEntity = aTileEntity; this.mConsumers = aConsumers; mHighestNodeValue = aNodeValue; - //you don't want to generate map multiple times in the same tick + // you don't want to generate map multiple times in the same tick mCreationTime = MinecraftServer.getServer().getTickCounter(); } diff --git a/src/main/java/gregtech/api/graphs/NodeList.java b/src/main/java/gregtech/api/graphs/NodeList.java index 36ebbc4f6f..fb8afe68fa 100644 --- a/src/main/java/gregtech/api/graphs/NodeList.java +++ b/src/main/java/gregtech/api/graphs/NodeList.java @@ -1,6 +1,6 @@ package gregtech.api.graphs; -//keep track on which node is being looked for across the recursive functions +// keep track on which node is being looked for across the recursive functions public class NodeList { Node[] mNodes; int mCounter = 0; diff --git a/src/main/java/gregtech/api/graphs/PowerNode.java b/src/main/java/gregtech/api/graphs/PowerNode.java index a92e3ea0ca..82c97d3901 100644 --- a/src/main/java/gregtech/api/graphs/PowerNode.java +++ b/src/main/java/gregtech/api/graphs/PowerNode.java @@ -5,7 +5,7 @@ import net.minecraft.tileentity.TileEntity; import java.util.ArrayList; -//base node for power networks +// base node for power networks public class PowerNode extends Node{ public boolean mHadVoltage = false; public PowerNode(int aNodeValue, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { diff --git a/src/main/java/gregtech/api/graphs/PowerNodes.java b/src/main/java/gregtech/api/graphs/PowerNodes.java index 411d690cca..7a3364648a 100644 --- a/src/main/java/gregtech/api/graphs/PowerNodes.java +++ b/src/main/java/gregtech/api/graphs/PowerNodes.java @@ -21,43 +21,43 @@ import gregtech.api.graphs.paths.PowerNodePath; * */ public class PowerNodes { - //check if the looked for node is next to or get the next node that is closer to it - static public int powerNode(Node aCurrentNode, Node aPreviousNode, NodeList aConsumers, int aVoltage, int aMaxAmps) { - int tAmpsUsed = 0; - ConsumerNode tConsumer =(ConsumerNode) aConsumers.getNode(); + // check if the looked for node is next to or get the next node that is closer to it + static public long powerNode(Node aCurrentNode, Node aPreviousNode, NodeList aConsumers, long aVoltage, long aMaxAmps) { + long tAmpsUsed = 0; + ConsumerNode tConsumer = (ConsumerNode) aConsumers.getNode(); int tLoopProtection = 0; while (tConsumer != null) { int tTargetNodeValue = tConsumer.mNodeValue; - //if the target node has a value less then the current node + // if the target node has a value less then the current node if (tTargetNodeValue < aCurrentNode.mNodeValue || tTargetNodeValue > aCurrentNode.mHighestNodeValue) { - for (int j = 0;j<6;j++) { - Node tNextNode = aCurrentNode.mNeighbourNodes[j]; + for (int j = 0; j < 6; j++) { + 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); - tConsumer =(ConsumerNode) aConsumers.getNextNode(); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, j, aMaxAmps - tAmpsUsed, aVoltage, false); + tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } else { if (aPreviousNode == tNextNode) return tAmpsUsed; - tAmpsUsed += processNextNode(aCurrentNode,tNextNode,aConsumers,j,aMaxAmps-tAmpsUsed,aVoltage); - tConsumer =(ConsumerNode) aConsumers.getNode(); + tAmpsUsed += processNextNode(aCurrentNode, tNextNode, aConsumers, j, aMaxAmps - tAmpsUsed, aVoltage); + tConsumer = (ConsumerNode) aConsumers.getNode(); break; } } } } else { - //if the target node has a node value greater then current node value - for (int side = 5;side>-1;side--) { - Node tNextNode = aCurrentNode.mNeighbourNodes[side]; + // if the target node has a node value greater then current node value + for (int side = 5; side > -1; side--) { + final Node tNextNode = aCurrentNode.mNeighbourNodes[side]; if (tNextNode == null) continue; if (tNextNode.mNodeValue > aCurrentNode.mNodeValue && tNextNode.mNodeValue < tTargetNodeValue) { if (tNextNode == aPreviousNode) return tAmpsUsed; - tAmpsUsed += processNextNodeAbove(aCurrentNode,tNextNode,aConsumers,side,aMaxAmps-tAmpsUsed,aVoltage); - tConsumer =(ConsumerNode) aConsumers.getNode(); + tAmpsUsed += processNextNodeAbove(aCurrentNode, tNextNode, aConsumers, side, aMaxAmps - tAmpsUsed, aVoltage); + tConsumer = (ConsumerNode) aConsumers.getNode(); break; } else if (tNextNode.mNodeValue == tTargetNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode,tConsumer,side,aMaxAmps-tAmpsUsed,aVoltage,true); - tConsumer =(ConsumerNode) aConsumers.getNextNode(); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage, true); + tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } } @@ -72,28 +72,28 @@ public class PowerNodes { return tAmpsUsed; } - //checking if target node is next to it or has a higher value then current node value - //these functions are different to either go down or up the stack - protected static int powerNodeAbove(Node aCurrentNode, Node aPreviousNode, NodeList aConsumers, int aVoltage, int aMaxAmps) { - int tAmpsUsed = 0; + // checking if target node is next to it or has a higher value then current node value + // these functions are different to either go down or up the stack + protected static long powerNodeAbove(Node aCurrentNode, Node aPreviousNode, NodeList aConsumers, long aVoltage, long aMaxAmps) { + long tAmpsUsed = 0; int tLoopProtection = 0; - ConsumerNode tConsumer =(ConsumerNode) aConsumers.getNode(); + ConsumerNode tConsumer = (ConsumerNode) aConsumers.getNode(); while (tConsumer != null) { int tTargetNodeValue = tConsumer.mNodeValue; if (tTargetNodeValue > aCurrentNode.mHighestNodeValue || tTargetNodeValue < aCurrentNode.mNodeValue) { return tAmpsUsed; } else { - for (int side = 5;side>-1;side--) { - Node tNextNode = aCurrentNode.mNeighbourNodes[side]; + for (int side = 5; side > -1; side--) { + final Node tNextNode = aCurrentNode.mNeighbourNodes[side]; if (tNextNode == null) continue; if (tNextNode.mNodeValue > aCurrentNode.mNodeValue && tNextNode.mNodeValue < tTargetNodeValue) { if (tNextNode == aPreviousNode) return tAmpsUsed; - tAmpsUsed += processNextNodeAbove(aCurrentNode,tNextNode,aConsumers,side,aMaxAmps-tAmpsUsed,aVoltage); - tConsumer =(ConsumerNode) aConsumers.getNode(); + tAmpsUsed += processNextNodeAbove(aCurrentNode, tNextNode, aConsumers, side, aMaxAmps - tAmpsUsed, aVoltage); + tConsumer = (ConsumerNode) aConsumers.getNode(); break; } else if (tNextNode.mNodeValue == tTargetNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode,tConsumer,side,aMaxAmps-tAmpsUsed,aVoltage,true); - tConsumer =(ConsumerNode) aConsumers.getNextNode(); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage, true); + tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } } @@ -108,52 +108,51 @@ public class PowerNodes { return tAmpsUsed; } - protected static int processNextNode(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, int aMaxAmps, int aVoltage) { - PowerNodePath tPath = (PowerNodePath)aCurrentNode.mNodePaths[aSide]; - PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; - int tVoltLoss = 0; + protected static long processNextNode(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, long aMaxAmps, long aVoltage) { + final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; + final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; + long tVoltLoss = 0; if (tSelfPath != null) { tVoltLoss += tSelfPath.getLoss(); - tSelfPath.applyVoltage(aVoltage,false); + tSelfPath.applyVoltage(aVoltage, false); } - tPath.applyVoltage(aVoltage - tVoltLoss,true); + tPath.applyVoltage(aVoltage - tVoltLoss, true); tVoltLoss += tPath.getLoss(); - int tAmps = powerNode(aNextNode,aCurrentNode,aConsumers,aVoltage - tVoltLoss,aMaxAmps ); + long tAmps = powerNode(aNextNode, aCurrentNode, aConsumers, aVoltage - tVoltLoss, aMaxAmps); tPath.addAmps(tAmps); if (tSelfPath != null) tSelfPath.addAmps(tAmps); return tAmps; } - protected static int processNextNodeAbove(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, int aMaxAmps, int aVoltage) { - PowerNodePath tPath = (PowerNodePath)aCurrentNode.mNodePaths[aSide]; - PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; - int tVoltLoss = 0; + protected static long processNextNodeAbove(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, long aMaxAmps, long aVoltage) { + final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; + final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; + long tVoltLoss = 0; if (tSelfPath != null) { tVoltLoss += tSelfPath.getLoss(); - tSelfPath.applyVoltage(aVoltage,false); + tSelfPath.applyVoltage(aVoltage, false); } - tPath.applyVoltage(aVoltage - tVoltLoss,true); + tPath.applyVoltage(aVoltage - tVoltLoss, true); tVoltLoss += tPath.getLoss(); - int tAmps = powerNodeAbove(aNextNode,aCurrentNode,aConsumers,aVoltage - tVoltLoss,aMaxAmps ); + long tAmps = powerNodeAbove(aNextNode, aCurrentNode, aConsumers, aVoltage - tVoltLoss, aMaxAmps); tPath.addAmps(tAmps); if (tSelfPath != null) tSelfPath.addAmps(tAmps); return tAmps; } - protected static int processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide,int aMaxAmps, int aVoltage, - boolean isUp) { - PowerNodePath tPath = (PowerNodePath)aCurrentNode.mNodePaths[aSide]; - PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; - int tVoltLoss = 0; + protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide, long aMaxAmps, long aVoltage, boolean isUp) { + final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; + final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; + long tVoltLoss = 0; if (tSelfPath != null) { tVoltLoss += tSelfPath.getLoss(); - tSelfPath.applyVoltage(aVoltage,false); + tSelfPath.applyVoltage(aVoltage, false); } - tPath.applyVoltage(aVoltage - tVoltLoss,true); + tPath.applyVoltage(aVoltage - tVoltLoss, true); tVoltLoss += tPath.getLoss(); - int tAmps = aConsumer.injectEnergy(aVoltage - tVoltLoss,aMaxAmps); + long tAmps = aConsumer.injectEnergy(aVoltage - tVoltLoss, aMaxAmps); tPath.addAmps(tAmps); if (tSelfPath != null) tSelfPath.addAmps(tAmps); diff --git a/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java b/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java index 87376008c4..e060c5c094 100644 --- a/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java +++ b/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java @@ -5,7 +5,7 @@ import net.minecraft.tileentity.TileEntity; import java.util.ArrayList; -//node attached to a tile entity that can consume stuff from the network +// node attached to a tile entity that can consume stuff from the network public class ConsumerNode extends Node { public byte mSide; public ConsumerNode(int aNodeValue, TileEntity aTileEntity, byte aSide, ArrayList<ConsumerNode> aConsumers) { @@ -17,7 +17,7 @@ public class ConsumerNode extends Node { return !mTileEntity.isInvalid(); } - public int injectEnergy(int aVoltage, int aMaxAmps) { + public int injectEnergy(long aVoltage, long aMaxAmps) { return 0; } } diff --git a/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java b/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java index da3d0a757b..29f4fe8893 100644 --- a/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java +++ b/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java @@ -6,7 +6,7 @@ import net.minecraft.tileentity.TileEntity; import java.util.ArrayList; -//this is here to apply voltage to death ends +//this is here to apply voltage to dead ends public class EmptyPowerConsumer extends ConsumerNode{ public EmptyPowerConsumer(int aNodeValue, TileEntity aTileEntity, byte aSide, ArrayList<ConsumerNode> aConsumers) { super(aNodeValue, aTileEntity, aSide, aConsumers); @@ -18,7 +18,7 @@ public class EmptyPowerConsumer extends ConsumerNode{ } @Override - public int injectEnergy(int aVoltage, int aMaxAmps) { + public int injectEnergy(long aVoltage, long aMaxAmps) { BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) mTileEntity; PowerNodePath tPath =(PowerNodePath) tPipe.getNodePath(); tPath.applyVoltage(aVoltage,true); diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java index baff232d94..0b3c8e31fa 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java @@ -16,7 +16,7 @@ public class NodeEnergyConnected extends ConsumerNode { } @Override - public int injectEnergy(int aVoltage, int aMaxAmps) { + public int injectEnergy(long aVoltage, long aMaxAmps) { return (int) ((IEnergyConnected)mTileEntity).injectEnergyUnits(mSide,aVoltage,aMaxAmps); } } diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java index e1f3c3f0e0..1b5e00773b 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java @@ -23,7 +23,7 @@ public class NodeEnergyReceiver extends ConsumerNode { } @Override - public int injectEnergy(int aVoltage, int aMaxAmps) { + public int injectEnergy(long aVoltage, long aMaxAmps) { ForgeDirection tDirection = ForgeDirection.getOrientation(mSide); int rfOut = GT_Utility.safeInt(aVoltage * GregTech_API.mEUtoRF / 100); int ampsUsed = 0; @@ -48,25 +48,25 @@ public class NodeEnergyReceiver extends ConsumerNode { if (aRfOut > 32L * GregTech_API.mEUtoRF / 100L) { int aExplosionPower = aRfOut; float tStrength = - aExplosionPower < V[0] ? 1.0F : - aExplosionPower < V[1] ? 2.0F : - aExplosionPower < V[2] ? 3.0F : - aExplosionPower < V[3] ? 4.0F : - aExplosionPower < V[4] ? 5.0F : - aExplosionPower < V[4] * 2 ? 6.0F : - aExplosionPower < V[5] ? 7.0F : - aExplosionPower < V[6] ? 8.0F : - aExplosionPower < V[7] ? 9.0F : - aExplosionPower < V[8] ? 10.0F : - aExplosionPower < V[8] * 2 ? 11.0F : - aExplosionPower < V[9] ? 12.0F : - aExplosionPower < V[10] ? 13.0F : - aExplosionPower < V[11] ? 14.0F : - aExplosionPower < V[12] ? 15.0F : - aExplosionPower < V[12] * 2 ? 16.0F : - aExplosionPower < V[13] ? 17.0F : - aExplosionPower < V[14] ? 18.0F : - aExplosionPower < V[15] ? 19.0F : 20.0F; + aExplosionPower < V[0] ? 1.0F : + aExplosionPower < V[1] ? 2.0F : + aExplosionPower < V[2] ? 3.0F : + aExplosionPower < V[3] ? 4.0F : + aExplosionPower < V[4] ? 5.0F : + aExplosionPower < V[4] * 2 ? 6.0F : + aExplosionPower < V[5] ? 7.0F : + aExplosionPower < V[6] ? 8.0F : + aExplosionPower < V[7] ? 9.0F : + aExplosionPower < V[8] ? 10.0F : + aExplosionPower < V[8] * 2 ? 11.0F : + aExplosionPower < V[9] ? 12.0F : + aExplosionPower < V[10] ? 13.0F : + aExplosionPower < V[11] ? 14.0F : + aExplosionPower < V[12] ? 15.0F : + aExplosionPower < V[12] * 2 ? 16.0F : + aExplosionPower < V[13] ? 17.0F : + aExplosionPower < V[14] ? 18.0F : + aExplosionPower < V[15] ? 19.0F : 20.0F; int tX = mTileEntity.xCoord, tY = mTileEntity.yCoord, tZ = mTileEntity.zCoord; World tWorld = mTileEntity.getWorldObj(); GT_Utility.sendSoundToPlayers(tWorld, GregTech_API.sSoundList.get(209), 1.0F, -1, tX, tY, tZ); diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java index 3f93c62010..d2c54e284f 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java @@ -6,7 +6,7 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; -//consumer for IC2 machines +// consumer for IC2 machines public class NodeEnergySink extends ConsumerNode { public NodeEnergySink(int nodeValue, IEnergySink tileEntity, byte side, ArrayList<ConsumerNode> consumers) { super(nodeValue, (TileEntity) tileEntity, side, consumers); @@ -18,7 +18,7 @@ public class NodeEnergySink extends ConsumerNode { } @Override - public int injectEnergy(int aVoltage, int aMaxAmps) { + public int injectEnergy(long aVoltage, long aMaxAmps) { int tUsedAmps = 0; while (aMaxAmps > tUsedAmps && ((IEnergySink) mTileEntity).getDemandedEnergy() > 0 && ((IEnergySink) mTileEntity).injectEnergy(ForgeDirection.getOrientation(mSide), aVoltage, aVoltage) < aVoltage) diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java b/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java index 5c54ee16f9..e9736df7f4 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java @@ -4,14 +4,14 @@ import gregtech.api.interfaces.tileentity.IEnergyConnected; import gregtech.api.metatileentity.BaseMetaTileEntity; import java.util.ArrayList; -//consumer for gt machines +// consumer for gt machines public class NodeGTBaseMetaTile extends ConsumerNode { public NodeGTBaseMetaTile(int aNodeValue, BaseMetaTileEntity aTileEntity, byte aSide, ArrayList<ConsumerNode> aConsumers) { super(aNodeValue, aTileEntity, aSide, aConsumers); } @Override - public int injectEnergy(int aVoltage, int aMaxAmps) { + public int injectEnergy(long aVoltage, long aMaxAmps) { return (int)((IEnergyConnected) mTileEntity).injectEnergyUnits(mSide,aVoltage, aMaxAmps); } diff --git a/src/main/java/gregtech/api/graphs/paths/NodePath.java b/src/main/java/gregtech/api/graphs/paths/NodePath.java index ddbd570af3..bdf82ec5b0 100644 --- a/src/main/java/gregtech/api/graphs/paths/NodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/NodePath.java @@ -12,18 +12,19 @@ public class NodePath { processPipes(); } + protected void processPipes() { + for (MetaPipeEntity tPipe : mPipes) { + BaseMetaPipeEntity basePipe = (BaseMetaPipeEntity) tPipe.getBaseMetaTileEntity(); + basePipe.setNodePath(this); + } + } + public void clearPath() { - for (int i = 0; i< mPipes.length; i++) { + for (int i = 0; i < mPipes.length; i++) { BaseMetaPipeEntity tBasePipe = (BaseMetaPipeEntity) mPipes[i].getBaseMetaTileEntity(); if (tBasePipe != null) { tBasePipe.setNodePath(null); } } } - protected void processPipes() { - for (MetaPipeEntity tPipe : mPipes) { - BaseMetaPipeEntity basePipe = (BaseMetaPipeEntity) tPipe.getBaseMetaTileEntity(); - basePipe.setNodePath(this); - } - } } diff --git a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java index df6f2671e4..72b2edb334 100644 --- a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java @@ -5,14 +5,14 @@ import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; import net.minecraft.server.MinecraftServer; -//path for cables -//all calculations like amp and voltage happens here +// path for cables +// all calculations like amp and voltage happens here public class PowerNodePath extends NodePath { - int mMaxAmps; - int mAmps = 0; - int mLoss; - int mVoltage = 0; - int mMaxVoltage; + long mMaxAmps; + long mAmps = 0; + long mLoss; + long mVoltage = 0; + long mMaxVoltage; int mTick = 0; boolean mCountUp = true; @@ -21,24 +21,24 @@ public class PowerNodePath extends NodePath { super(aCables); } - public int getLoss() { + public long getLoss() { return mLoss; } - public void applyVoltage(int aVoltage, boolean aCountUp) { + public void applyVoltage(long aVoltage, boolean aCountUp) { int tNewTime = MinecraftServer.getServer().getTickCounter(); if (mTick != tNewTime) { reset(tNewTime - mTick); mTick = tNewTime; this.mVoltage = aVoltage; this.mCountUp = aCountUp; - } else if (this.mCountUp != aCountUp && (aVoltage - mLoss)> this.mVoltage || aVoltage > this.mVoltage){ + } else if (this.mCountUp != aCountUp && (aVoltage - mLoss) > this.mVoltage || aVoltage > this.mVoltage) { this.mCountUp = aCountUp; this.mVoltage = aVoltage; } if (aVoltage > mMaxVoltage) { for (MetaPipeEntity tCable : mPipes) { - if (((GT_MetaPipeEntity_Cable)tCable).mVoltage < this.mVoltage) { + if (((GT_MetaPipeEntity_Cable) tCable).mVoltage < this.mVoltage) { BaseMetaPipeEntity tBaseCable = (BaseMetaPipeEntity) tCable.getBaseMetaTileEntity(); if (tBaseCable != null) { tBaseCable.setToFire(); @@ -48,11 +48,18 @@ public class PowerNodePath extends NodePath { } } - public void addAmps(int aAmps) { + private void reset(int aTimePassed) { + if (aTimePassed < 0 || aTimePassed > 100) { + mAmps = 0; + } + mAmps = Math.max(0, mAmps - (mMaxAmps * aTimePassed)); + } + + public void addAmps(long aAmps) { this.mAmps += aAmps; if (this.mAmps > mMaxAmps * 40) { for (MetaPipeEntity tCable : mPipes) { - if (((GT_MetaPipeEntity_Cable)tCable).mAmperage*40 < this.mAmps) { + if (((GT_MetaPipeEntity_Cable) tCable).mAmperage * 40 < this.mAmps) { BaseMetaPipeEntity tBaseCable = (BaseMetaPipeEntity) tCable.getBaseMetaTileEntity(); if (tBaseCable != null) { tBaseCable.setToFire(); @@ -62,9 +69,9 @@ public class PowerNodePath extends NodePath { } } - //if no amps pass trough for more then 0.5 second reduce them to minimize wrong results - //but still allow the player to see if activity is happening - public int getAmps() { + // if no amps pass through for more than 0.5 second reduce them to minimize wrong results + // but still allow the player to see if activity is happening + public long getAmps() { int tTime = MinecraftServer.getServer().getTickCounter() - 10; if (mTick < tTime) { reset(tTime - mTick); @@ -73,7 +80,7 @@ public class PowerNodePath extends NodePath { return mAmps; } - public int getVoltage(MetaPipeEntity aCable) { + public long getVoltage(MetaPipeEntity aCable) { int tLoss = 0; if (mCountUp) { for (int i = 0; i < mPipes.length; i++) { @@ -95,13 +102,6 @@ public class PowerNodePath extends NodePath { return -1; } - private void reset(int aTimePassed) { - if (aTimePassed < 0 || aTimePassed > 100) { - mAmps = 0; - } - mAmps = Math.max(0, mAmps - (mMaxAmps * aTimePassed)); - } - @Override protected void processPipes() { super.processPipes(); @@ -109,9 +109,9 @@ public class PowerNodePath extends NodePath { mMaxVoltage = Integer.MAX_VALUE; for (MetaPipeEntity tCable : mPipes) { if (tCable instanceof GT_MetaPipeEntity_Cable) { - mMaxAmps = Math.min((int)((GT_MetaPipeEntity_Cable) tCable).mAmperage, mMaxAmps); - mLoss += (int)((GT_MetaPipeEntity_Cable) tCable).mCableLossPerMeter; - mMaxVoltage = Math.min((int)((GT_MetaPipeEntity_Cable) tCable).mVoltage, mMaxVoltage); + mMaxAmps = Math.min(((GT_MetaPipeEntity_Cable) tCable).mAmperage, mMaxAmps); + mLoss += ((GT_MetaPipeEntity_Cable) tCable).mCableLossPerMeter; + mMaxVoltage = Math.min(((GT_MetaPipeEntity_Cable) tCable).mVoltage, mMaxVoltage); } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index 2764eeb07e..8666f609b6 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -372,8 +372,8 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile public String[] getInfoData() { BaseMetaPipeEntity base = (BaseMetaPipeEntity) getBaseMetaTileEntity(); PowerNodePath path =(PowerNodePath) base.getNodePath(); - int amps = 0; - int volts = 0; + long amps = 0; + long volts = 0; if (path != null) { amps = path.getAmps(); volts = path.getVoltage(this); |