diff --git a/common/mekanism/api/transmitters/DynamicNetwork.java b/common/mekanism/api/transmitters/DynamicNetwork.java index 3dd1fd8e9..76fbc5ef7 100644 --- a/common/mekanism/api/transmitters/DynamicNetwork.java +++ b/common/mekanism/api/transmitters/DynamicNetwork.java @@ -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> implemen TileEntity[] connectedBlocks = new TileEntity[6]; boolean[] dealtWith = {false, false, false, false, false, false}; + List newNetworks = new ArrayList(); - 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 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> newNetCables = new HashSet>(); 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> implemen } ITransmitterNetwork newNetwork = create(newNetCables); + newNetwork.onNewFromSplit(newNetworks.indexOf(finder), metaArray); newNetwork.refresh(); } } @@ -245,6 +261,15 @@ public abstract class DynamicNetwork> implemen } } + @Override + public Object[] getMetaArray(List networks) + { + return null; + } + + @Override + public void onNewFromSplit(int netIndex, Object[] metaArray) {} + @Override public void setFixed(boolean value) { diff --git a/common/mekanism/api/transmitters/ITransmitterNetwork.java b/common/mekanism/api/transmitters/ITransmitterNetwork.java index 1cf0c9524..4d463d513 100644 --- a/common/mekanism/api/transmitters/ITransmitterNetwork.java +++ b/common/mekanism/api/transmitters/ITransmitterNetwork.java @@ -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> { public void tick(); @@ -33,4 +36,21 @@ public interface ITransmitterNetwork> 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 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); } diff --git a/common/mekanism/common/multipart/PartTransmitter.java b/common/mekanism/common/multipart/PartTransmitter.java index 69b9366f1..bbe75aa66 100644 --- a/common/mekanism/common/multipart/PartTransmitter.java +++ b/common/mekanism/common/multipart/PartTransmitter.java @@ -102,13 +102,16 @@ public abstract class PartTransmitter> 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)getTransmitterNetwork()).split((ITransmitter)tile()); setTransmitterNetwork(null); - } + }*/ for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { @@ -201,7 +204,7 @@ public abstract class PartTransmitter> extends Pa { if(theNetwork != null) { - theNetwork.removeTransmitter((ITransmitter) tile()); + theNetwork.removeTransmitter((ITransmitter)tile()); } } @@ -253,9 +256,6 @@ public abstract class PartTransmitter> extends Pa super.preRemove(); } - - @Override - public void chunkLoad() {} @Override public void onAdded() diff --git a/common/mekanism/common/util/ListUtils.java b/common/mekanism/common/util/ListUtils.java index ef5bc4c7f..c8e003572 100644 --- a/common/mekanism/common/util/ListUtils.java +++ b/common/mekanism/common/util/ListUtils.java @@ -170,7 +170,7 @@ public class ListUtils return (List)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; + } }