Fixed a few bugs in the split() method and added in some new functionality for splitting of energy/fluid/gas! Unpairedbracket, shouldn't hurt you unless you modified split()

This commit is contained in:
Aidan C. Brady 2013-12-16 15:00:57 -05:00
parent 869660d8bf
commit 5272d169c4
4 changed files with 81 additions and 19 deletions

View file

@ -1,7 +1,6 @@
package mekanism.api.transmitters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -188,45 +187,61 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
TileEntity[] connectedBlocks = new TileEntity[6];
boolean[] dealtWith = {false, false, false, false, false, false};
List<NetworkFinder> newNetworks = new ArrayList<NetworkFinder>();
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity sideTile = Object3D.get((TileEntity)splitPoint).getFromSide(direction).getTileEntity(((TileEntity)splitPoint).worldObj);
TileEntity sideTile = Object3D.get((TileEntity)splitPoint).getFromSide(side).getTileEntity(((TileEntity)splitPoint).worldObj);
if(sideTile != null)
{
connectedBlocks[Arrays.asList(ForgeDirection.values()).indexOf(direction)] = sideTile;
connectedBlocks[side.ordinal()] = sideTile;
}
}
for(int countOne = 0; countOne < connectedBlocks.length; countOne++)
for(int count = 0; count < connectedBlocks.length; count++)
{
TileEntity connectedBlockA = connectedBlocks[countOne];
TileEntity connectedBlockA = connectedBlocks[count];
if(TransmissionType.checkTransmissionType(connectedBlockA, getTransmissionType()) && !dealtWith[countOne])
if(TransmissionType.checkTransmissionType(connectedBlockA, getTransmissionType()) && !dealtWith[count])
{
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, getTransmissionType(), Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
List<Object3D> partNetwork = finder.exploreNetwork();
for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++)
for(int check = count; check < connectedBlocks.length; check++)
{
TileEntity connectedBlockB = connectedBlocks[countTwo];
if(check == count)
{
continue;
}
if(TransmissionType.checkTransmissionType(connectedBlockB, getTransmissionType()) && !dealtWith[countTwo])
TileEntity connectedBlockB = connectedBlocks[check];
if(TransmissionType.checkTransmissionType(connectedBlockB, getTransmissionType()) && !dealtWith[check])
{
if(partNetwork.contains(Object3D.get(connectedBlockB)))
{
dealtWith[countTwo] = true;
dealtWith[check] = true;
}
}
}
newNetworks.add(finder);
}
}
if(newNetworks.size() > 0)
{
Object[] metaArray = getMetaArray(newNetworks);
for(NetworkFinder finder : newNetworks)
{
Set<ITransmitter<N>> newNetCables = new HashSet<ITransmitter<N>>();
for(Object3D node : finder.iterated)
{
TileEntity nodeTile = node.getTileEntity(((TileEntity)splitPoint).worldObj);
if(TransmissionType.checkTransmissionType(nodeTile, getTransmissionType()))
{
if(nodeTile != splitPoint)
@ -237,6 +252,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
}
ITransmitterNetwork<A, N> newNetwork = create(newNetCables);
newNetwork.onNewFromSplit(newNetworks.indexOf(finder), metaArray);
newNetwork.refresh();
}
}
@ -245,6 +261,15 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
}
}
@Override
public Object[] getMetaArray(List<NetworkFinder> networks)
{
return null;
}
@Override
public void onNewFromSplit(int netIndex, Object[] metaArray) {}
@Override
public void setFixed(boolean value)
{

View file

@ -1,7 +1,10 @@
package mekanism.api.transmitters;
import java.util.List;
import java.util.Set;
import mekanism.api.transmitters.DynamicNetwork.NetworkFinder;
public interface ITransmitterNetwork<A, N extends DynamicNetwork<A, N>>
{
public void tick();
@ -33,4 +36,21 @@ public interface ITransmitterNetwork<A, N extends DynamicNetwork<A, N>>
public void setFixed(boolean value);
public TransmissionType getTransmissionType();
/**
* Gets a network's meta value right before it is split. This will then be passed onto "onNewFromSplit()" in
* every single new network that is created from the original split.
* @param size - the amount of new networks that are being created
* @return meta obj
*/
public Object[] getMetaArray(List<NetworkFinder> networks);
/**
* Called right after a new network is created after being split, before it is refreshed. Passes in it's index
* in the amount of networks being created, as well as the meta value that was retrieved on the original network
* by getMetaObj().
* @param netIndex - the index of the network being created
* @param meta - meta obj
*/
public void onNewFromSplit(int netIndex, Object[] metaArray);
}

View file

@ -102,13 +102,16 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
if(possibleTransmitters != currentTransmitterConnections)
{
byte or = (byte)(possibleTransmitters | currentTransmitterConnections);
//TODO @unpairedbracket, I don't think this is necessary; I couldn't tell a difference without it,
//and it results in many extra possible recursive calls on the network
/*byte or = (byte)(possibleTransmitters | currentTransmitterConnections);
if(or != possibleTransmitters)
{
((DynamicNetwork<?, N>)getTransmitterNetwork()).split((ITransmitter<N>)tile());
setTransmitterNetwork(null);
}
}*/
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
@ -201,7 +204,7 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
{
if(theNetwork != null)
{
theNetwork.removeTransmitter((ITransmitter<N>) tile());
theNetwork.removeTransmitter((ITransmitter<N>)tile());
}
}
@ -253,9 +256,6 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
super.preRemove();
}
@Override
public void chunkLoad() {}
@Override
public void onAdded()

View file

@ -170,7 +170,7 @@ public class ListUtils
return (List<V>)Arrays.asList(values);
}
public static double[] splitNum(int size, double num)
public static double[] splitDouble(int size, double num)
{
double[] split = new double[size];
@ -186,4 +186,21 @@ public class ListUtils
return split;
}
public static int[] splitInt(int size, int num)
{
int[] split = new int[size];
for(int i = 0; i < size; i++)
{
int remain = num%size;
int ret = (num-remain)/size;
ret += remain;
split[i] = ret;
num -= remain;
}
return split;
}
}