This is probably like punching any experienced programmer in the face, but it works.

This commit is contained in:
Ellpeck 2015-10-29 15:03:15 +01:00
parent cb22c4aa94
commit 41e2c7ce6a

View file

@ -21,6 +21,8 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList; import java.util.ArrayList;
//This is probably like punching any experienced programmer in the face, but it works.
@SuppressWarnings("ForLoopReplaceableByForEach")
public class LaserRelayConnectionHandler{ public class LaserRelayConnectionHandler{
private static LaserRelayConnectionHandler instance; private static LaserRelayConnectionHandler instance;
@ -68,10 +70,11 @@ public class LaserRelayConnectionHandler{
*/ */
public ArrayList<ConnectionPair> getConnectionsFor(WorldPos relay){ public ArrayList<ConnectionPair> getConnectionsFor(WorldPos relay){
ArrayList<ConnectionPair> allPairs = new ArrayList<ConnectionPair>(); ArrayList<ConnectionPair> allPairs = new ArrayList<ConnectionPair>();
ArrayList<ArrayList<ConnectionPair>> theNetworks = new ArrayList<ArrayList<ConnectionPair>>(this.networks); ArrayList<ArrayList<ConnectionPair>> networks1 = this.networks;
for(ArrayList<ConnectionPair> aNetwork : theNetworks){ for(int i = 0; i < networks1.size(); i++){
ArrayList<ConnectionPair> pairs = new ArrayList<ConnectionPair>(aNetwork); ArrayList<ConnectionPair> aNetwork = networks1.get(i);
for(ConnectionPair pair : pairs){ for(int i1 = 0; i1 < aNetwork.size(); i1++){
ConnectionPair pair = aNetwork.get(i1);
if(pair.contains(relay)){ if(pair.contains(relay)){
allPairs.add(pair); allPairs.add(pair);
} }
@ -88,8 +91,8 @@ public class LaserRelayConnectionHandler{
if(network != null){ if(network != null){
//Setup new network (so that splitting a network will cause it to break into two) //Setup new network (so that splitting a network will cause it to break into two)
this.networks.remove(network); this.networks.remove(network);
ArrayList<ConnectionPair> pairs = new ArrayList<ConnectionPair>(network); for(int i = 0; i < network.size(); i++){
for(ConnectionPair pair : pairs){ ConnectionPair pair = network.get(i);
if(!pair.contains(relay)){ if(!pair.contains(relay)){
this.addConnection(pair.firstRelay, pair.secondRelay); this.addConnection(pair.firstRelay, pair.secondRelay);
} }
@ -102,10 +105,11 @@ public class LaserRelayConnectionHandler{
* Gets a Network for a Relay * Gets a Network for a Relay
*/ */
public ArrayList<ConnectionPair> getNetworkFor(WorldPos relay){ public ArrayList<ConnectionPair> getNetworkFor(WorldPos relay){
ArrayList<ArrayList<ConnectionPair>> theNetworks = new ArrayList<ArrayList<ConnectionPair>>(this.networks); ArrayList<ArrayList<ConnectionPair>> networks1 = this.networks;
for(ArrayList<ConnectionPair> aNetwork : theNetworks){ for(int i = 0; i < networks1.size(); i++){
ArrayList<ConnectionPair> pairs = new ArrayList<ConnectionPair>(aNetwork); ArrayList<ConnectionPair> aNetwork = networks1.get(i);
for(ConnectionPair pair : pairs){ for(int i1 = 0; i1 < aNetwork.size(); i1++){
ConnectionPair pair = aNetwork.get(i1);
if(pair.contains(relay)){ if(pair.contains(relay)){
return aNetwork; return aNetwork;
} }
@ -161,8 +165,8 @@ public class LaserRelayConnectionHandler{
* (Actually puts everything from the second network into the first one and removes the second one) * (Actually puts everything from the second network into the first one and removes the second one)
*/ */
public void mergeNetworks(ArrayList<ConnectionPair> firstNetwork, ArrayList<ConnectionPair> secondNetwork){ public void mergeNetworks(ArrayList<ConnectionPair> firstNetwork, ArrayList<ConnectionPair> secondNetwork){
ArrayList<ConnectionPair> pairs = new ArrayList<ConnectionPair>(secondNetwork); for(int i = 0; i < secondNetwork.size(); i++){
for(ConnectionPair secondPair : pairs){ ConnectionPair secondPair = secondNetwork.get(i);
firstNetwork.add(secondPair); firstNetwork.add(secondPair);
} }
this.networks.remove(secondNetwork); this.networks.remove(secondNetwork);
@ -173,8 +177,8 @@ public class LaserRelayConnectionHandler{
public int transferEnergyToReceiverInNeed(ArrayList<ConnectionPair> network, int maxTransfer, boolean simulate){ public int transferEnergyToReceiverInNeed(ArrayList<ConnectionPair> network, int maxTransfer, boolean simulate){
int transmitted = 0; int transmitted = 0;
//Go through all of the connections in the network //Go through all of the connections in the network
ArrayList<ConnectionPair> pairs = new ArrayList<ConnectionPair>(network); for(int i1 = 0; i1 < network.size(); i1++){
for(ConnectionPair pair : pairs){ ConnectionPair pair = network.get(i1);
WorldPos[] relays = new WorldPos[]{pair.firstRelay, pair.secondRelay}; WorldPos[] relays = new WorldPos[]{pair.firstRelay, pair.secondRelay};
//Go through both relays in the connection //Go through both relays in the connection
for(WorldPos relay : relays){ for(WorldPos relay : relays){
@ -192,8 +196,8 @@ public class LaserRelayConnectionHandler{
//The amount of energy lost during a transfer //The amount of energy lost during a transfer
int deduct = (int)(theoreticalReceived*((double)ConfigIntValues.LASER_RELAY_LOSS.getValue()/100)); int deduct = (int)(theoreticalReceived*((double)ConfigIntValues.LASER_RELAY_LOSS.getValue()/100));
transmitted+=((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), theoreticalReceived-deduct, simulate); transmitted += ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), theoreticalReceived-deduct, simulate);
transmitted+=deduct; transmitted += deduct;
} }
} }
} }
@ -243,4 +247,4 @@ public class LaserRelayConnectionHandler{
} }
} }
} }
} }