This commit is contained in:
Aidan C. Brady 2015-04-06 11:08:57 -04:00
parent 841e358ce0
commit ec7b0555c9
6 changed files with 64 additions and 31 deletions

View file

@ -62,30 +62,39 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
if(transmitter.isValid())
{
if(worldObj == null) worldObj = transmitter.world();
if(worldObj == null)
{
worldObj = transmitter.world();
}
Coord4D coord = transmitter.coord();
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
A acceptor = transmitter.getAcceptor(side);
if(acceptor != null)
{
Coord4D acceptorCoord = coord.getFromSide(side);
possibleAcceptors.put(acceptorCoord, acceptor);
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
if(directions != null)
{
directions.add(side.getOpposite());
} else
{
}
else {
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
}
}
}
transmitter.setTransmitterNetwork((N)this);
absorbBuffer(transmitter);
transmitters.add(transmitter);
}
}
updateCapacity();
clampBuffer();
queueClientUpdate(new ArrayList<>(transmittersToAdd));
@ -104,22 +113,24 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
A acceptor = transmitter.getAcceptor(side);
Coord4D acceptorCoord = transmitter.coord().getFromSide(side);
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
if(acceptor != null)
{
possibleAcceptors.put(acceptorCoord, acceptor);
if(directions != null)
{
directions.add(side.getOpposite());
} else
{
}
else {
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
}
}
else
{
else {
if(directions != null)
{
directions.remove(side.getOpposite());
if(directions.isEmpty())
{
possibleAcceptors.remove(acceptorCoord);
@ -129,6 +140,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
}
}
}
changedAcceptors.clear();
}
}
@ -143,6 +155,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
invalidateTransmitter(transmitter);
}
transmitters.clear();
deregister();
}
@ -160,13 +173,15 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
public void acceptorChanged(IGridTransmitter<A, N> transmitter, ForgeDirection side)
{
EnumSet<ForgeDirection> directions = changedAcceptors.get(transmitter);
if(directions != null)
{
directions.add(side);
} else
{
}
else {
changedAcceptors.put(transmitter, EnumSet.of(side));
}
TransmitterNetworkRegistry.registerChangedNetwork(this);
}
@ -178,16 +193,18 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
transmitters.add(transmitter);
transmittersAdded.add(transmitter);
}
possibleAcceptors.putAll(net.possibleAcceptors);
for(Entry<Coord4D, EnumSet<ForgeDirection>> entry : net.acceptorDirections.entrySet())
{
Coord4D coord = entry.getKey();
if(acceptorDirections.containsKey(coord))
{
acceptorDirections.get(coord).addAll(entry.getValue());
}
else
{
else {
acceptorDirections.put(coord, entry.getValue());
}
}
@ -315,8 +332,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
Iterator<DelayQueue> i = updateQueue.iterator();
try
{
try {
while(i.hasNext())
{
DelayQueue q = i.next();
@ -324,16 +340,14 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
if(q.delay > 0)
{
q.delay--;
} else
{
}
else {
transmittersAdded.addAll(transmitters);
updateDelay = 1;
i.remove();
}
}
} catch(Exception e)
{
}
} catch(Exception e) {}
if(updateDelay > 0)
{

View file

@ -127,12 +127,14 @@ public class TransmitterNetworkRegistry
for(IGridTransmitter orphanTransmitter : orphanTransmitters.values())
{
DynamicNetwork network = getNetworkFromOrphan(orphanTransmitter);
if(network != null)
{
networksToChange.add(network);
network.register();
}
}
orphanTransmitters.clear();
}
@ -143,6 +145,7 @@ public class TransmitterNetworkRegistry
OrphanPathFinder<A, N> finder = new OrphanPathFinder<>(startOrphan);
finder.start();
N network;
switch(finder.networksFound.size())
{
case 0:
@ -157,9 +160,12 @@ public class TransmitterNetworkRegistry
Mekanism.logger.debug("Merging " + finder.networksFound.size() + " networks");
network = startOrphan.mergeNetworks(finder.networksFound);
}
network.addNewTransmitters(finder.connectedTransmitters);
return network;
}
return null;
}
@ -169,6 +175,7 @@ public class TransmitterNetworkRegistry
{
network.commit();
}
networksToChange.clear();
}
@ -185,8 +192,7 @@ public class TransmitterNetworkRegistry
for(DynamicNetwork network : networks)
{
strings[i] = network.toString();
++i;
strings[i++] = network.toString();
}
return strings;
@ -214,21 +220,27 @@ public class TransmitterNetworkRegistry
public void iterate(Coord4D from, ForgeDirection fromDirection)
{
if(iterated.contains(from))
{
return;
}
iterated.add(from);
if(orphanTransmitters.containsKey(from))
{
IGridTransmitter<A, N> transmitter = orphanTransmitters.get(from);
if(transmitter.isValid() && transmitter.isOrphan())
{
connectedTransmitters.add(transmitter);
transmitter.setOrphan(false);
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if(direction != fromDirection)
{
Coord4D directionCoord = transmitter.getAdjacentConnectableTransmitterCoord(direction);
if(!(directionCoord == null || iterated.contains(directionCoord)))
{
iterate(directionCoord, direction.getOpposite());
@ -236,8 +248,8 @@ public class TransmitterNetworkRegistry
}
}
}
} else
{
}
else {
addNetworkToIterated(from);
}
}

View file

@ -61,6 +61,7 @@ public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Tran
return sideCoord;
}
}
return null;
}
@ -86,14 +87,17 @@ public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Tran
public N getExternalNetwork(Coord4D from)
{
TileEntity tile = from.getTileEntity(world());
if(tile instanceof ITransmitterTile)
{
IGridTransmitter transmitter = ((ITransmitterTile)tile).getTransmitter();
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()));
{
return ((IGridTransmitter<A, N>)transmitter).getTransmitterNetwork();
}
}
return null;
}

View file

@ -295,5 +295,4 @@ public class PartPressurizedTube extends PartTransmitter<IGasHandler, GasNetwork
return buffer.receive(gasStack, doEmit);
}
}
}

View file

@ -254,7 +254,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
public boolean getPossibleAcceptorConnection(ForgeDirection side)
{
if(handlesRedstone() && redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())))
if(handlesRedstone() && redstoneReactive && redstonePowered)
{
return false;
}

View file

@ -29,12 +29,12 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
public void onWorldJoin()
{
super.onWorldJoin();
if(!world().isRemote)
{
TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
}
else
{
else {
MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(tile()));
}
}
@ -47,13 +47,13 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
public void onChunkUnload()
{
super.onChunkUnload();
if(!world().isRemote)
{
getTransmitter().takeShare();
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
else
{
else {
getTransmitter().setTransmitterNetwork(null);
}
}
@ -65,10 +65,10 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
{
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
else
{
else {
getTransmitter().setTransmitterNetwork(null);
}
super.preRemove();
}
@ -82,9 +82,10 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
public void markDirtyTransmitters()
{
super.markDirtyTransmitters();
if(getTransmitter().hasTransmitterNetwork())
{
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
}
@ -92,6 +93,7 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
public void markDirtyAcceptor(ForgeDirection side)
{
super.markDirtyAcceptor(side);
if(getTransmitter().hasTransmitterNetwork())
{
getTransmitter().getTransmitterNetwork().acceptorChanged(getTransmitter(), side);
@ -101,10 +103,12 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
public A getCachedAcceptor(ForgeDirection side)
{
ConnectionType type = connectionTypes[side.ordinal()];
if(type == ConnectionType.PULL || type == ConnectionType.NONE)
{
return null;
}
return connectionMapContainsSide(currentAcceptorConnections, side) ? (A)cachedAcceptors[side.ordinal()] : null;
}